blob: 2c4b1c247f246afba3c953d9a88decebf1128637 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +0100142#ifdef FEAT_MBYTE
143# define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
144#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000145#define PV_MA OPT_BUF(BV_MA)
146#define PV_ML OPT_BUF(BV_ML)
147#define PV_MOD OPT_BUF(BV_MOD)
148#define PV_MPS OPT_BUF(BV_MPS)
149#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000150#ifdef FEAT_COMPL_FUNC
151# define PV_OFU OPT_BUF(BV_OFU)
152#endif
153#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
154#define PV_PI OPT_BUF(BV_PI)
155#ifdef FEAT_TEXTOBJ
156# define PV_QE OPT_BUF(BV_QE)
157#endif
158#define PV_RO OPT_BUF(BV_RO)
159#ifdef FEAT_SMARTINDENT
160# define PV_SI OPT_BUF(BV_SI)
161#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100162#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#ifdef FEAT_SYN_HL
164# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000165# define PV_SYN OPT_BUF(BV_SYN)
166#endif
167#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168# define PV_SPC OPT_BUF(BV_SPC)
169# define PV_SPF OPT_BUF(BV_SPF)
170# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000171#endif
172#define PV_STS OPT_BUF(BV_STS)
173#ifdef FEAT_SEARCHPATH
174# define PV_SUA OPT_BUF(BV_SUA)
175#endif
176#define PV_SW OPT_BUF(BV_SW)
177#define PV_SWF OPT_BUF(BV_SWF)
178#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100179#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_TS OPT_BUF(BV_TS)
181#define PV_TW OPT_BUF(BV_TW)
182#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200183#ifdef FEAT_PERSISTENT_UNDO
184# define PV_UDF OPT_BUF(BV_UDF)
185#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187
188/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000189 * Definition of the PV_ values for window-local options.
190 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000192#define PV_LIST OPT_WIN(WV_LIST)
193#ifdef FEAT_ARABIC
194# define PV_ARAB OPT_WIN(WV_ARAB)
195#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200196#ifdef FEAT_LINEBREAK
197# define PV_BRI OPT_WIN(WV_BRI)
198# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
199#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
225#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
232#ifdef FEAT_SCROLLBIND
233# define PV_SCBIND OPT_WIN(WV_SCBIND)
234#endif
235#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248#ifdef FEAT_WINDOWS
249# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000250# define PV_WFW OPT_WIN(WV_WFW)
251#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000252#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200253#ifdef FEAT_CURSORBIND
254# define PV_CRBIND OPT_WIN(WV_CRBIND)
255#endif
256#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200257# define PV_COCU OPT_WIN(WV_COCU)
258# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200259#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200260#ifdef FEAT_SIGNS
261# define PV_SCL OPT_WIN(WV_SCL)
262#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000263
264/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265typedef enum
266{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000267 PV_NONE = 0,
268 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269} idopt_T;
270
271/*
272 * Options local to a window have a value local to a buffer and global to all
273 * buffers. Indicate this by setting "var" to VAR_WIN.
274 */
275#define VAR_WIN ((char_u *)-1)
276
277/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000278 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279 * Only to be used in option.c!
280 */
281static int p_ai;
282static int p_bin;
283#ifdef FEAT_MBYTE
284static int p_bomb;
285#endif
286#if defined(FEAT_QUICKFIX)
287static char_u *p_bh;
288static char_u *p_bt;
289#endif
290static int p_bl;
291static int p_ci;
292#ifdef FEAT_CINDENT
293static int p_cin;
294static char_u *p_cink;
295static char_u *p_cino;
296#endif
297#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
298static char_u *p_cinw;
299#endif
300#ifdef FEAT_COMMENTS
301static char_u *p_com;
302#endif
303#ifdef FEAT_FOLDING
304static char_u *p_cms;
305#endif
306#ifdef FEAT_INS_EXPAND
307static char_u *p_cpt;
308#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#ifdef FEAT_COMPL_FUNC
310static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000311static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
316#ifdef FEAT_MBYTE
317static char_u *p_fenc;
318#endif
319static char_u *p_ff;
320static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000321static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322#ifdef FEAT_AUTOCMD
323static char_u *p_ft;
324#endif
325static long p_iminsert;
326static long p_imsearch;
327#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
328static char_u *p_inex;
329#endif
330#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
331static char_u *p_inde;
332static char_u *p_indk;
333#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000334#if defined(FEAT_EVAL)
335static char_u *p_fex;
336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_inf;
338static char_u *p_isk;
339#ifdef FEAT_CRYPT
340static char_u *p_key;
341#endif
342#ifdef FEAT_LISP
343static int p_lisp;
344#endif
345static int p_ml;
346static int p_ma;
347static int p_mod;
348static char_u *p_mps;
349static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000351#ifdef FEAT_TEXTOBJ
352static char_u *p_qe;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_ro;
355#ifdef FEAT_SMARTINDENT
356static int p_si;
357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000358static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359static long p_sts;
360#if defined(FEAT_SEARCHPATH)
361static char_u *p_sua;
362#endif
363static long p_sw;
364static int p_swf;
365#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000366static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000368#endif
369#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000370static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000371static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000372static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373#endif
374static long p_ts;
375static long p_tw;
376static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200377#ifdef FEAT_PERSISTENT_UNDO
378static int p_udf;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380static long p_wm;
381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
384
385/* Saved values for when 'bin' is set. */
386static int p_et_nobin;
387static int p_ml_nobin;
388static long p_tw_nobin;
389static long p_wm_nobin;
390
391/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200392static int p_ai_nopaste;
393static int p_et_nopaste;
394static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395static long p_tw_nopaste;
396static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397
398struct vimoption
399{
400 char *fullname; /* full option name */
401 char *shortname; /* permissible abbreviation */
402 long_u flags; /* see below */
403 char_u *var; /* global option: pointer to variable;
404 * window-local option: VAR_WIN;
405 * buffer-local option: global value */
406 idopt_T indir; /* global option: PV_NONE;
407 * local option: indirect option index */
408 char_u *def_val[2]; /* default values for variable (vi and vim) */
409#ifdef FEAT_EVAL
410 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000411# define SCRIPTID_INIT , 0
412#else
413# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#endif
415};
416
417#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
418#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
419
420/*
421 * Flags
422 */
423#define P_BOOL 0x01 /* the option is boolean */
424#define P_NUM 0x02 /* the option is numeric */
425#define P_STRING 0x04 /* the option is a string */
426#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000427 must use free_string_option() when
428 assigning new value. Not set if default is
429 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000430#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
431 never be used for local or hidden options! */
432#define P_NODEFAULT 0x40 /* don't set to default value */
433#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
434 use vim_free() when assigning new value */
435#define P_WAS_SET 0x100 /* option has been set/reset */
436#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
437#define P_VI_DEF 0x400 /* Use Vi default for Vim */
438#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
439
440 /* when option changed, what to display: */
441#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100442#define P_RWIN 0x2000 /* redraw current window and recompute text */
443#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444#define P_RALL 0x6000 /* redraw all windows */
445#define P_RCLR 0x7000 /* clear and redraw all */
446
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200447#define P_COMMA 0x8000 /* comma separated list */
448#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
449 * commas */
450#define P_NODUP 0x20000L /* don't allow duplicate strings */
451#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
454#define P_GETTEXT 0x100000L /* expand default value with _() */
455#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
456#define P_NFNAME 0x400000L /* only normal file name chars allowed */
457#define P_INSECURE 0x800000L /* option was set from a modeline */
458#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100459 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200460#define P_NO_ML 0x2000000L /* not allowed in modeline */
461#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200462 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100464#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000465
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000466#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
467
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000468/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
469 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100470#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000471# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000472#else
473# define ISP_LATIN1 (char_u *)"@,161-255"
474#endif
475
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100476/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000477#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100478 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200479 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar58b85342016-08-14 19:54:54 +0200480# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000481#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100482# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000483#endif
484
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100485/* Default python version for pyx* commands */
486#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
487# define DEFAULT_PYTHON_VER 0
488#elif defined(FEAT_PYTHON3)
489# define DEFAULT_PYTHON_VER 3
490#elif defined(FEAT_PYTHON)
491# define DEFAULT_PYTHON_VER 2
492#else
493# define DEFAULT_PYTHON_VER 0
494#endif
495
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496/*
497 * options[] is initialized here.
498 * The order of the options MUST be alphabetic for ":set all" and findoption().
499 * All option names MUST start with a lowercase letter (for findoption()).
500 * Exception: "t_" options are at the end.
501 * The options with a NULL variable are 'hidden': a set command for them is
502 * ignored and they are not printed.
503 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100504static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200506 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507#ifdef FEAT_RIGHTLEFT
508 (char_u *)&p_aleph, PV_NONE,
509#else
510 (char_u *)NULL, PV_NONE,
511#endif
512 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100513#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (char_u *)128L,
515#else
516 (char_u *)224L,
517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000518 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
520#if defined(FEAT_GUI) && defined(MACOS_X)
521 (char_u *)&p_antialias, PV_NONE,
522 {(char_u *)FALSE, (char_u *)FALSE}
523#else
524 (char_u *)NULL, PV_NONE,
525 {(char_u *)FALSE, (char_u *)FALSE}
526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000527 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200528 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529#ifdef FEAT_ARABIC
530 (char_u *)VAR_WIN, PV_ARAB,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
536#ifdef FEAT_ARABIC
537 (char_u *)&p_arshape, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
543#ifdef FEAT_RIGHTLEFT
544 (char_u *)&p_ari, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
550#ifdef FEAT_FKMAP
551 (char_u *)&p_altkeymap, PV_NONE,
552#else
553 (char_u *)NULL, PV_NONE,
554#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000555 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
557#if defined(FEAT_MBYTE)
558 (char_u *)&p_ambw, PV_NONE,
559 {(char_u *)"single", (char_u *)0L}
560#else
561 (char_u *)NULL, PV_NONE,
562 {(char_u *)0L, (char_u *)0L}
563#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100566#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100568 {(char_u *)FALSE, (char_u *)0L}
569#else
570 (char_u *)NULL, PV_NONE,
571 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100573 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autoindent", "ai", P_BOOL|P_VI_DEF,
575 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autoprint", "ap", P_BOOL|P_VI_DEF,
578 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000581 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"autowrite", "aw", P_BOOL|P_VI_DEF,
584 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"autowriteall","awa", P_BOOL|P_VI_DEF,
587 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000588 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000589 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
590 (char_u *)&p_bg, PV_NONE,
591 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100592#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)"dark",
594#else
595 (char_u *)"light",
596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000597 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200598 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000601 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
602 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000603 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200604 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200605 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606#ifdef UNIX
607 {(char_u *)"yes", (char_u *)"auto"}
608#else
609 {(char_u *)"auto", (char_u *)"auto"}
610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000611 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200612 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
613 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000616 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617 (char_u *)&p_bex, PV_NONE,
618 {
619#ifdef VMS
620 (char_u *)"_",
621#else
622 (char_u *)"~",
623#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000624 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200625 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626#ifdef FEAT_WILDIGN
627 (char_u *)&p_bsk, PV_NONE,
628 {(char_u *)"", (char_u *)0L}
629#else
630 (char_u *)NULL, PV_NONE,
631 {(char_u *)0L, (char_u *)0L}
632#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000633 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000636 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100637 {(char_u *)600L, (char_u *)0L}
638#else
639 (char_u *)NULL, PV_NONE,
640 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000641#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100642 SCRIPTID_INIT},
643 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
644#ifdef FEAT_BEVAL
645 (char_u *)&p_beval, PV_NONE,
646 {(char_u *)FALSE, (char_u *)0L}
647#else
648 (char_u *)NULL, PV_NONE,
649 {(char_u *)0L, (char_u *)0L}
650#endif
651 SCRIPTID_INIT},
652 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
653#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
654 (char_u *)&p_bexpr, PV_BEXPR,
655 {(char_u *)"", (char_u *)0L}
656#else
657 (char_u *)NULL, PV_NONE,
658 {(char_u *)0L, (char_u *)0L}
659#endif
660 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 {"beautify", "bf", P_BOOL|P_VI_DEF,
662 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000663 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200664 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
665 (char_u *)&p_bo, PV_NONE,
666 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
668 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000669 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
674#ifdef FEAT_MBYTE
675 (char_u *)&p_bomb, PV_BOMB,
676#else
677 (char_u *)NULL, PV_NONE,
678#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000679 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000680 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
681#ifdef FEAT_LINEBREAK
682 (char_u *)&p_breakat, PV_NONE,
683 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
684#else
685 (char_u *)NULL, PV_NONE,
686 {(char_u *)0L, (char_u *)0L}
687#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000688 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200689 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
690#ifdef FEAT_LINEBREAK
691 (char_u *)VAR_WIN, PV_BRI,
692 {(char_u *)FALSE, (char_u *)0L}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)0L, (char_u *)0L}
696#endif
697 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200698 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
699 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200700#ifdef FEAT_LINEBREAK
701 (char_u *)VAR_WIN, PV_BRIOPT,
702 {(char_u *)"", (char_u *)NULL}
703#else
704 (char_u *)NULL, PV_NONE,
705 {(char_u *)"", (char_u *)NULL}
706#endif
707 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
709#ifdef FEAT_BROWSE
710 (char_u *)&p_bsdir, PV_NONE,
711 {(char_u *)"last", (char_u *)0L}
712#else
713 (char_u *)NULL, PV_NONE,
714 {(char_u *)0L, (char_u *)0L}
715#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000716 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
718#if defined(FEAT_QUICKFIX)
719 (char_u *)&p_bh, PV_BH,
720 {(char_u *)"", (char_u *)0L}
721#else
722 (char_u *)NULL, PV_NONE,
723 {(char_u *)0L, (char_u *)0L}
724#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000725 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
727 (char_u *)&p_bl, PV_BL,
728 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000729 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
731#if defined(FEAT_QUICKFIX)
732 (char_u *)&p_bt, PV_BT,
733 {(char_u *)"", (char_u *)0L}
734#else
735 (char_u *)NULL, PV_NONE,
736 {(char_u *)0L, (char_u *)0L}
737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000738 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200739 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000740#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 (char_u *)&p_cmp, PV_NONE,
742 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000743#else
744 (char_u *)NULL, PV_NONE,
745 {(char_u *)0L, (char_u *)0L}
746#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000747 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
749#ifdef FEAT_SEARCHPATH
750 (char_u *)&p_cdpath, PV_NONE,
751 {(char_u *)",,", (char_u *)0L}
752#else
753 (char_u *)NULL, PV_NONE,
754 {(char_u *)0L, (char_u *)0L}
755#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000756 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 {"cedit", NULL, P_STRING,
758#ifdef FEAT_CMDWIN
759 (char_u *)&p_cedit, PV_NONE,
760 {(char_u *)"", (char_u *)CTRL_F_STR}
761#else
762 (char_u *)NULL, PV_NONE,
763 {(char_u *)0L, (char_u *)0L}
764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
767#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
768 (char_u *)&p_ccv, PV_NONE,
769 {(char_u *)"", (char_u *)0L}
770#else
771 (char_u *)NULL, PV_NONE,
772 {(char_u *)0L, (char_u *)0L}
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
776#ifdef FEAT_CINDENT
777 (char_u *)&p_cin, PV_CIN,
778#else
779 (char_u *)NULL, PV_NONE,
780#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000781 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200782 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783#ifdef FEAT_CINDENT
784 (char_u *)&p_cink, PV_CINK,
785 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#ifdef FEAT_CINDENT
793 (char_u *)&p_cino, PV_CINO,
794#else
795 (char_u *)NULL, PV_NONE,
796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000797 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200798 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000799#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
800 (char_u *)&p_cinw, PV_CINW,
801 {(char_u *)"if,else,while,do,for,switch",
802 (char_u *)0L}
803#else
804 (char_u *)NULL, PV_NONE,
805 {(char_u *)0L, (char_u *)0L}
806#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000807 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200808 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809#ifdef FEAT_CLIPBOARD
810 (char_u *)&p_cb, PV_NONE,
811# ifdef FEAT_XCLIPBOARD
812 {(char_u *)"autoselect,exclude:cons\\|linux",
813 (char_u *)0L}
814# else
815 {(char_u *)"", (char_u *)0L}
816# endif
817#else
818 (char_u *)NULL, PV_NONE,
819 {(char_u *)"", (char_u *)0L}
820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000821 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
823 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000825 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
826#ifdef FEAT_CMDWIN
827 (char_u *)&p_cwh, PV_NONE,
828#else
829 (char_u *)NULL, PV_NONE,
830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200832 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200833#ifdef FEAT_SYN_HL
834 (char_u *)VAR_WIN, PV_CC,
835#else
836 (char_u *)NULL, PV_NONE,
837#endif
838 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
840 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000841 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200842 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
843 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000844#ifdef FEAT_COMMENTS
845 (char_u *)&p_com, PV_COM,
846 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
847 (char_u *)0L}
848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)0L, (char_u *)0L}
851#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000852 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200853 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000854#ifdef FEAT_FOLDING
855 (char_u *)&p_cms, PV_CMS,
856 {(char_u *)"/*%s*/", (char_u *)0L}
857#else
858 (char_u *)NULL, PV_NONE,
859 {(char_u *)0L, (char_u *)0L}
860#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000861 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000862 /* P_PRI_MKRC isn't needed here, optval_default()
863 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000864 {"compatible", "cp", P_BOOL|P_RALL,
865 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000866 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200867 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000868#ifdef FEAT_INS_EXPAND
869 (char_u *)&p_cpt, PV_CPT,
870 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
871#else
872 (char_u *)NULL, PV_NONE,
873 {(char_u *)0L, (char_u *)0L}
874#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000875 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200876 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200877#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200878 (char_u *)VAR_WIN, PV_COCU,
879 {(char_u *)"", (char_u *)NULL}
880#else
881 (char_u *)NULL, PV_NONE,
882 {(char_u *)NULL, (char_u *)0L}
883#endif
884 SCRIPTID_INIT},
885 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
886#ifdef FEAT_CONCEAL
887 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200888#else
889 (char_u *)NULL, PV_NONE,
890#endif
891 {(char_u *)0L, (char_u *)0L}
892 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000893 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
894#ifdef FEAT_COMPL_FUNC
895 (char_u *)&p_cfu, PV_CFU,
896 {(char_u *)"", (char_u *)0L}
897#else
898 (char_u *)NULL, PV_NONE,
899 {(char_u *)0L, (char_u *)0L}
900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200902 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000903#ifdef FEAT_INS_EXPAND
904 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000905 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000906#else
907 (char_u *)NULL, PV_NONE,
908 {(char_u *)0L, (char_u *)0L}
909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"confirm", "cf", P_BOOL|P_VI_DEF,
912#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
913 (char_u *)&p_confirm, PV_NONE,
914#else
915 (char_u *)NULL, PV_NONE,
916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
922 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000923 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
925 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000926 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
927 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200929#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200930 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200931 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200932#else
933 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200934 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200935#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200936 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_cspc, PV_NONE,
940#else
941 (char_u *)NULL, PV_NONE,
942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000943 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
945#ifdef FEAT_CSCOPE
946 (char_u *)&p_csprg, PV_NONE,
947 {(char_u *)"cscope", (char_u *)0L}
948#else
949 (char_u *)NULL, PV_NONE,
950 {(char_u *)0L, (char_u *)0L}
951#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000952 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200953 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000954#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
955 (char_u *)&p_csqf, PV_NONE,
956 {(char_u *)"", (char_u *)0L}
957#else
958 (char_u *)NULL, PV_NONE,
959 {(char_u *)0L, (char_u *)0L}
960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000961 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200962 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
963#ifdef FEAT_CSCOPE
964 (char_u *)&p_csre, PV_NONE,
965#else
966 (char_u *)NULL, PV_NONE,
967#endif
968 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
970#ifdef FEAT_CSCOPE
971 (char_u *)&p_cst, PV_NONE,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
977#ifdef FEAT_CSCOPE
978 (char_u *)&p_csto, PV_NONE,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
984#ifdef FEAT_CSCOPE
985 (char_u *)&p_csverbose, PV_NONE,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200990 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
991#ifdef FEAT_CURSORBIND
992 (char_u *)VAR_WIN, PV_CRBIND,
993#else
994 (char_u *)NULL, PV_NONE,
995#endif
996 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000997 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
998#ifdef FEAT_SYN_HL
999 (char_u *)VAR_WIN, PV_CUC,
1000#else
1001 (char_u *)NULL, PV_NONE,
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +01001004 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001005#ifdef FEAT_SYN_HL
1006 (char_u *)VAR_WIN, PV_CUL,
1007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 {"debug", NULL, P_STRING|P_VI_DEF,
1012 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001013 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001014 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001016 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001017 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001018#else
1019 (char_u *)NULL, PV_NONE,
1020 {(char_u *)NULL, (char_u *)0L}
1021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001022 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1024#ifdef FEAT_MBYTE
1025 (char_u *)&p_deco, PV_NONE,
1026#else
1027 (char_u *)NULL, PV_NONE,
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001030 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001032 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033#else
1034 (char_u *)NULL, PV_NONE,
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1038#ifdef FEAT_DIFF
1039 (char_u *)VAR_WIN, PV_DIFF,
1040#else
1041 (char_u *)NULL, PV_NONE,
1042#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001043 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001044 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1046 (char_u *)&p_dex, PV_NONE,
1047 {(char_u *)"", (char_u *)0L}
1048#else
1049 (char_u *)NULL, PV_NONE,
1050 {(char_u *)0L, (char_u *)0L}
1051#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1054 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055#ifdef FEAT_DIFF
1056 (char_u *)&p_dip, PV_NONE,
1057 {(char_u *)"filler", (char_u *)NULL}
1058#else
1059 (char_u *)NULL, PV_NONE,
1060 {(char_u *)"", (char_u *)NULL}
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1064#ifdef FEAT_DIGRAPHS
1065 (char_u *)&p_dg, PV_NONE,
1066#else
1067 (char_u *)NULL, PV_NONE,
1068#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001070 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1071 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001074 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001076 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001078#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 (char_u *)&p_ead, PV_NONE,
1080 {(char_u *)"both", (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)NULL, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1087 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001089 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1090#if defined(FEAT_MBYTE)
1091 (char_u *)&p_emoji, PV_NONE,
1092 {(char_u *)TRUE, (char_u *)0L}
1093#else
1094 (char_u *)NULL, PV_NONE,
1095 {(char_u *)0L, (char_u *)0L}
1096#endif
1097 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001098 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099#ifdef FEAT_MBYTE
1100 (char_u *)&p_enc, PV_NONE,
1101 {(char_u *)ENC_DFLT, (char_u *)0L}
1102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)0L, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1108 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1111 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001112 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001114 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1117 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1120#ifdef FEAT_QUICKFIX
1121 (char_u *)&p_ef, PV_NONE,
1122 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1123#else
1124 (char_u *)NULL, PV_NONE,
1125 {(char_u *)NULL, (char_u *)0L}
1126#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001127 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001128 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001130 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132#else
1133 (char_u *)NULL, PV_NONE,
1134 {(char_u *)NULL, (char_u *)0L}
1135#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 {"esckeys", "ek", P_BOOL|P_VIM,
1138 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141#ifdef FEAT_AUTOCMD
1142 (char_u *)&p_ei, PV_NONE,
1143#else
1144 (char_u *)NULL, PV_NONE,
1145#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1148 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1151 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001152 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001153 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1154 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155#ifdef FEAT_MBYTE
1156 (char_u *)&p_fenc, PV_FENC,
1157 {(char_u *)"", (char_u *)0L}
1158#else
1159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)0L, (char_u *)0L}
1161#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001162 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001163 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164#ifdef FEAT_MBYTE
1165 (char_u *)&p_fencs, PV_NONE,
1166 {(char_u *)"ucs-bom", (char_u *)0L}
1167#else
1168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)0L, (char_u *)0L}
1170#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001172 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1173 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001174 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001176 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001177 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001178 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1179 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001180 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1181 (char_u *)&p_fic, PV_NONE,
1182 {
1183#ifdef CASE_INSENSITIVE_FILENAME
1184 (char_u *)TRUE,
1185#else
1186 (char_u *)FALSE,
1187#endif
1188 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001189 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190#ifdef FEAT_AUTOCMD
1191 (char_u *)&p_ft, PV_FT,
1192 {(char_u *)"", (char_u *)0L}
1193#else
1194 (char_u *)NULL, PV_NONE,
1195 {(char_u *)0L, (char_u *)0L}
1196#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001198 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1200 (char_u *)&p_fcs, PV_NONE,
1201 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1202#else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)"", (char_u *)0L}
1205#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001207 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1208 (char_u *)&p_fixeol, PV_FIXEOL,
1209 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1211#ifdef FEAT_FKMAP
1212 (char_u *)&p_fkmap, PV_NONE,
1213#else
1214 (char_u *)NULL, PV_NONE,
1215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"flash", "fl", P_BOOL|P_VI_DEF,
1218 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001220 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001223 {(char_u *)"", (char_u *)0L}
1224#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 (char_u *)NULL, PV_NONE,
1226 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227#endif
1228 SCRIPTID_INIT},
1229 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1230#ifdef FEAT_FOLDING
1231 (char_u *)VAR_WIN, PV_FDC,
1232 {(char_u *)FALSE, (char_u *)0L}
1233#else
1234 (char_u *)NULL, PV_NONE,
1235 {(char_u *)NULL, (char_u *)0L}
1236#endif
1237 SCRIPTID_INIT},
1238 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1239#ifdef FEAT_FOLDING
1240 (char_u *)VAR_WIN, PV_FEN,
1241 {(char_u *)TRUE, (char_u *)0L}
1242#else
1243 (char_u *)NULL, PV_NONE,
1244 {(char_u *)NULL, (char_u *)0L}
1245#endif
1246 SCRIPTID_INIT},
1247 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1248#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1249 (char_u *)VAR_WIN, PV_FDE,
1250 {(char_u *)"0", (char_u *)NULL}
1251#else
1252 (char_u *)NULL, PV_NONE,
1253 {(char_u *)NULL, (char_u *)0L}
1254#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001255 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001257#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001258 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001259 {(char_u *)"#", (char_u *)NULL}
1260#else
1261 (char_u *)NULL, PV_NONE,
1262 {(char_u *)NULL, (char_u *)0L}
1263#endif
1264 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001265 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001266#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001268 {(char_u *)0L, (char_u *)0L}
1269#else
1270 (char_u *)NULL, PV_NONE,
1271 {(char_u *)NULL, (char_u *)0L}
1272#endif
1273 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001274 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001275#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001277 {(char_u *)-1L, (char_u *)0L}
1278#else
1279 (char_u *)NULL, PV_NONE,
1280 {(char_u *)NULL, (char_u *)0L}
1281#endif
1282 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001284 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001285#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001287 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001288#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001289 (char_u *)NULL, PV_NONE,
1290 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001292 SCRIPTID_INIT},
1293 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1294#ifdef FEAT_FOLDING
1295 (char_u *)VAR_WIN, PV_FDM,
1296 {(char_u *)"manual", (char_u *)NULL}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)NULL, (char_u *)0L}
1300#endif
1301 SCRIPTID_INIT},
1302 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1303#ifdef FEAT_FOLDING
1304 (char_u *)VAR_WIN, PV_FML,
1305 {(char_u *)1L, (char_u *)0L}
1306#else
1307 (char_u *)NULL, PV_NONE,
1308 {(char_u *)NULL, (char_u *)0L}
1309#endif
1310 SCRIPTID_INIT},
1311 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1312#ifdef FEAT_FOLDING
1313 (char_u *)VAR_WIN, PV_FDN,
1314 {(char_u *)20L, (char_u *)0L}
1315#else
1316 (char_u *)NULL, PV_NONE,
1317 {(char_u *)NULL, (char_u *)0L}
1318#endif
1319 SCRIPTID_INIT},
1320 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1321#ifdef FEAT_FOLDING
1322 (char_u *)&p_fdo, PV_NONE,
1323 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1324 (char_u *)0L}
1325#else
1326 (char_u *)NULL, PV_NONE,
1327 {(char_u *)NULL, (char_u *)0L}
1328#endif
1329 SCRIPTID_INIT},
1330 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1331#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1332 (char_u *)VAR_WIN, PV_FDT,
1333 {(char_u *)"foldtext()", (char_u *)NULL}
1334#else
1335 (char_u *)NULL, PV_NONE,
1336 {(char_u *)NULL, (char_u *)0L}
1337#endif
1338 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001339 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001340#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001341 (char_u *)&p_fex, PV_FEX,
1342 {(char_u *)"", (char_u *)0L}
1343#else
1344 (char_u *)NULL, PV_NONE,
1345 {(char_u *)0L, (char_u *)0L}
1346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001347 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1349 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001350 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1351 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001352 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1353 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001354 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1355 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001357 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001358 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001359 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1360#ifdef HAVE_FSYNC
1361 (char_u *)&p_fs, PV_NONE,
1362 {(char_u *)TRUE, (char_u *)0L}
1363#else
1364 (char_u *)NULL, PV_NONE,
1365 {(char_u *)FALSE, (char_u *)0L}
1366#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1369 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371 {"graphic", "gr", P_BOOL|P_VI_DEF,
1372 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001374 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375#ifdef FEAT_QUICKFIX
1376 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001377 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378#else
1379 (char_u *)NULL, PV_NONE,
1380 {(char_u *)NULL, (char_u *)0L}
1381#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1384#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001385 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {
1387# ifdef WIN3264
1388 /* may be changed to "grep -n" in os_win32.c */
1389 (char_u *)"findstr /n",
1390# else
1391# ifdef UNIX
1392 /* Add an extra file name so that grep will always
1393 * insert a file name in the match line. */
1394 (char_u *)"grep -n $* /dev/null",
1395# else
1396# ifdef VMS
1397 (char_u *)"SEARCH/NUMBERS ",
1398# else
1399 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400# endif
1401# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404#else
1405 (char_u *)NULL, PV_NONE,
1406 {(char_u *)NULL, (char_u *)0L}
1407#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001408 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001409 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001410#ifdef CURSOR_SHAPE
1411 (char_u *)&p_guicursor, PV_NONE,
1412 {
1413# ifdef FEAT_GUI
1414 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001415# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1417# endif
1418 (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001424 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001425#ifdef FEAT_GUI
1426 (char_u *)&p_guifont, PV_NONE,
1427 {(char_u *)"", (char_u *)0L}
1428#else
1429 (char_u *)NULL, PV_NONE,
1430 {(char_u *)NULL, (char_u *)0L}
1431#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001433 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1435 (char_u *)&p_guifontset, PV_NONE,
1436 {(char_u *)"", (char_u *)0L}
1437#else
1438 (char_u *)NULL, PV_NONE,
1439 {(char_u *)NULL, (char_u *)0L}
1440#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001441 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001442 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1444 (char_u *)&p_guifontwide, PV_NONE,
1445 {(char_u *)"", (char_u *)0L}
1446#else
1447 (char_u *)NULL, PV_NONE,
1448 {(char_u *)NULL, (char_u *)0L}
1449#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001452#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 (char_u *)&p_ghr, PV_NONE,
1454#else
1455 (char_u *)NULL, PV_NONE,
1456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001457 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001459#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460 (char_u *)&p_go, PV_NONE,
1461# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001462 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001464 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465# endif
1466#else
1467 (char_u *)NULL, PV_NONE,
1468 {(char_u *)NULL, (char_u *)0L}
1469#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001470 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {"guipty", NULL, P_BOOL|P_VI_DEF,
1472#if defined(FEAT_GUI)
1473 (char_u *)&p_guipty, PV_NONE,
1474#else
1475 (char_u *)NULL, PV_NONE,
1476#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001477 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001478 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001479#if defined(FEAT_GUI_TABLINE)
1480 (char_u *)&p_gtl, PV_NONE,
1481 {(char_u *)"", (char_u *)0L}
1482#else
1483 (char_u *)NULL, PV_NONE,
1484 {(char_u *)NULL, (char_u *)0L}
1485#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001486 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001487 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001488#if defined(FEAT_GUI_TABLINE)
1489 (char_u *)&p_gtt, PV_NONE,
1490 {(char_u *)"", (char_u *)0L}
1491#else
1492 (char_u *)NULL, PV_NONE,
1493 {(char_u *)NULL, (char_u *)0L}
1494#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1497 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001498 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1500 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001501 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1502 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"helpheight", "hh", P_NUM|P_VI_DEF,
1504#ifdef FEAT_WINDOWS
1505 (char_u *)&p_hh, PV_NONE,
1506#else
1507 (char_u *)NULL, PV_NONE,
1508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001509 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001510 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511#ifdef FEAT_MULTI_LANG
1512 (char_u *)&p_hlg, PV_NONE,
1513 {(char_u *)"", (char_u *)0L}
1514#else
1515 (char_u *)NULL, PV_NONE,
1516 {(char_u *)0L, (char_u *)0L}
1517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {"hidden", "hid", P_BOOL|P_VI_DEF,
1520 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001522 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001524 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1525 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001526 {"history", "hi", P_NUM|P_VIM,
1527 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001528 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001529 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1530#ifdef FEAT_RIGHTLEFT
1531 (char_u *)&p_hkmap, PV_NONE,
1532#else
1533 (char_u *)NULL, PV_NONE,
1534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001535 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1537#ifdef FEAT_RIGHTLEFT
1538 (char_u *)&p_hkmapp, PV_NONE,
1539#else
1540 (char_u *)NULL, PV_NONE,
1541#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1544 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"icon", NULL, P_BOOL|P_VI_DEF,
1547#ifdef FEAT_TITLE
1548 (char_u *)&p_icon, PV_NONE,
1549#else
1550 (char_u *)NULL, PV_NONE,
1551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {"iconstring", NULL, P_STRING|P_VI_DEF,
1554#ifdef FEAT_TITLE
1555 (char_u *)&p_iconstring, PV_NONE,
1556#else
1557 (char_u *)NULL, PV_NONE,
1558#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001559 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001560 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1561 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001562 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001563 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1564# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1565 (char_u *)&p_imaf, PV_NONE,
1566 {(char_u *)"", (char_u *)NULL}
1567# else
1568 (char_u *)NULL, PV_NONE,
1569 {(char_u *)NULL, (char_u *)0L}
1570# endif
1571 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001573#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 (char_u *)&p_imak, PV_NONE,
1575#else
1576 (char_u *)NULL, PV_NONE,
1577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001578 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1580#ifdef USE_IM_CONTROL
1581 (char_u *)&p_imcmdline, PV_NONE,
1582#else
1583 (char_u *)NULL, PV_NONE,
1584#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001586 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1587#ifdef USE_IM_CONTROL
1588 (char_u *)&p_imdisable, PV_NONE,
1589#else
1590 (char_u *)NULL, PV_NONE,
1591#endif
1592#ifdef __sgi
1593 {(char_u *)TRUE, (char_u *)0L}
1594#else
1595 {(char_u *)FALSE, (char_u *)0L}
1596#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {"iminsert", "imi", P_NUM|P_VI_DEF,
1599 (char_u *)&p_iminsert, PV_IMI,
1600#ifdef B_IMODE_IM
1601 {(char_u *)B_IMODE_IM, (char_u *)0L}
1602#else
1603 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001605 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001606 {"imsearch", "ims", P_NUM|P_VI_DEF,
1607 (char_u *)&p_imsearch, PV_IMS,
1608#ifdef B_IMODE_IM
1609 {(char_u *)B_IMODE_IM, (char_u *)0L}
1610#else
1611 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001613 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001614 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001615# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1616 (char_u *)&p_imsf, PV_NONE,
1617 {(char_u *)"", (char_u *)NULL}
1618# else
1619 (char_u *)NULL, PV_NONE,
1620 {(char_u *)NULL, (char_u *)0L}
1621# endif
1622 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1624#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001625 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1627#else
1628 (char_u *)NULL, PV_NONE,
1629 {(char_u *)0L, (char_u *)0L}
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1633#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1634 (char_u *)&p_inex, PV_INEX,
1635 {(char_u *)"", (char_u *)0L}
1636#else
1637 (char_u *)NULL, PV_NONE,
1638 {(char_u *)0L, (char_u *)0L}
1639#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1642 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001643 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1645#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1646 (char_u *)&p_inde, PV_INDE,
1647 {(char_u *)"", (char_u *)0L}
1648#else
1649 (char_u *)NULL, PV_NONE,
1650 {(char_u *)0L, (char_u *)0L}
1651#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001652 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001653 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1655 (char_u *)&p_indk, PV_INDK,
1656 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1657#else
1658 (char_u *)NULL, PV_NONE,
1659 {(char_u *)0L, (char_u *)0L}
1660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 {"infercase", "inf", P_BOOL|P_VI_DEF,
1663 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1666 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001668 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1669 (char_u *)&p_isf, PV_NONE,
1670 {
1671#ifdef BACKSLASH_IN_FILENAME
1672 /* Excluded are: & and ^ are special in cmd.exe
1673 * ( and ) are used in text separating fnames */
1674 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1675#else
1676# ifdef AMIGA
1677 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1678# else
1679# ifdef VMS
1680 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1681# else /* UNIX et al. */
1682# ifdef EBCDIC
1683 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1684# else
1685 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1686# endif
1687# endif
1688# endif
1689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001690 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1692 (char_u *)&p_isi, PV_NONE,
1693 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001694#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695 (char_u *)"@,48-57,_,128-167,224-235",
1696#else
1697# ifdef EBCDIC
1698 /* TODO: EBCDIC Check this! @ == isalpha()*/
1699 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1700 "112-120,128,140-142,156,158,172,"
1701 "174,186,191,203-207,219-225,235-239,"
1702 "251-254",
1703# else
1704 (char_u *)"@,48-57,_,192-255",
1705# endif
1706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1709 (char_u *)&p_isk, PV_ISK,
1710 {
1711#ifdef EBCDIC
1712 (char_u *)"@,240-249,_",
1713 /* TODO: EBCDIC Check this! @ == isalpha()*/
1714 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1715 "112-120,128,140-142,156,158,172,"
1716 "174,186,191,203-207,219-225,235-239,"
1717 "251-254",
1718#else
1719 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001720# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721 (char_u *)"@,48-57,_,128-167,224-235"
1722# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001723 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724# endif
1725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001726 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001727 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1728 (char_u *)&p_isp, PV_NONE,
1729 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001730#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001731 || defined(VMS)
1732 (char_u *)"@,~-255",
1733#else
1734# ifdef EBCDIC
1735 /* all chars above 63 are printable */
1736 (char_u *)"63-255",
1737# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001738 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739# endif
1740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1743 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001744 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1746#ifdef FEAT_CRYPT
1747 (char_u *)&p_key, PV_KEY,
1748 {(char_u *)"", (char_u *)0L}
1749#else
1750 (char_u *)NULL, PV_NONE,
1751 {(char_u *)0L, (char_u *)0L}
1752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001753 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001754 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755#ifdef FEAT_KEYMAP
1756 (char_u *)&p_keymap, PV_KMAP,
1757 {(char_u *)"", (char_u *)0L}
1758#else
1759 (char_u *)NULL, PV_NONE,
1760 {(char_u *)"", (char_u *)0L}
1761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001762 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001763 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001765 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001767 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001769#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 (char_u *)":help",
1771#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001772# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001774# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001775# ifdef USEMAN_S
1776 (char_u *)"man -s",
1777# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001779# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001780# endif
1781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001783 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784#ifdef FEAT_LANGMAP
1785 (char_u *)&p_langmap, PV_NONE,
1786 {(char_u *)"", /* unmatched } */
1787#else
1788 (char_u *)NULL, PV_NONE,
1789 {(char_u *)NULL,
1790#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001792 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1794 (char_u *)&p_lm, PV_NONE,
1795#else
1796 (char_u *)NULL, PV_NONE,
1797#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001798 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001799 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1800#ifdef FEAT_LANGMAP
1801 (char_u *)&p_lnr, PV_NONE,
1802#else
1803 (char_u *)NULL, PV_NONE,
1804#endif
1805 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001806 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1807#ifdef FEAT_LANGMAP
1808 (char_u *)&p_lrm, PV_NONE,
1809#else
1810 (char_u *)NULL, PV_NONE,
1811#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001812 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1814#ifdef FEAT_WINDOWS
1815 (char_u *)&p_ls, PV_NONE,
1816#else
1817 (char_u *)NULL, PV_NONE,
1818#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1821 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001822 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001823 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1824#ifdef FEAT_LINEBREAK
1825 (char_u *)VAR_WIN, PV_LBR,
1826#else
1827 (char_u *)NULL, PV_NONE,
1828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001829 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1831 (char_u *)&Rows, PV_NONE,
1832 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001833#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001834 (char_u *)25L,
1835#else
1836 (char_u *)24L,
1837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001838 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1840#ifdef FEAT_GUI
1841 (char_u *)&p_linespace, PV_NONE,
1842#else
1843 (char_u *)NULL, PV_NONE,
1844#endif
1845#ifdef FEAT_GUI_W32
1846 {(char_u *)1L, (char_u *)0L}
1847#else
1848 {(char_u *)0L, (char_u *)0L}
1849#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"lisp", NULL, P_BOOL|P_VI_DEF,
1852#ifdef FEAT_LISP
1853 (char_u *)&p_lisp, PV_LISP,
1854#else
1855 (char_u *)NULL, PV_NONE,
1856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001857 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001858 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001860 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1862#else
1863 (char_u *)NULL, PV_NONE,
1864 {(char_u *)"", (char_u *)0L}
1865#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1868 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001870 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1874 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001876 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001877#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001878 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001879 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001880#else
1881 (char_u *)NULL, PV_NONE,
1882 {(char_u *)"", (char_u *)0L}
1883#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001884 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001885 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001886#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001887 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001888 {(char_u *)TRUE, (char_u *)0L}
1889#else
1890 (char_u *)NULL, PV_NONE,
1891 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001892#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001893 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"magic", NULL, P_BOOL|P_VI_DEF,
1895 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001897 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898#ifdef FEAT_QUICKFIX
1899 (char_u *)&p_mef, PV_NONE,
1900 {(char_u *)"", (char_u *)0L}
1901#else
1902 (char_u *)NULL, PV_NONE,
1903 {(char_u *)NULL, (char_u *)0L}
1904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 SCRIPTID_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001906 {"makeencoding","menc", P_STRING|P_VI_DEF,
1907#ifdef FEAT_MBYTE
1908 (char_u *)&p_menc, PV_MENC,
1909 {(char_u *)"", (char_u *)0L}
1910#else
1911 (char_u *)NULL, PV_NONE,
1912 {(char_u *)0L, (char_u *)0L}
1913#endif
1914 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1916#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001917 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918# ifdef VMS
1919 {(char_u *)"MMS", (char_u *)0L}
1920# else
1921 {(char_u *)"make", (char_u *)0L}
1922# endif
1923#else
1924 (char_u *)NULL, PV_NONE,
1925 {(char_u *)NULL, (char_u *)0L}
1926#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001927 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001928 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001929 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1931 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 {"matchtime", "mat", P_NUM|P_VI_DEF,
1933 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001934 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001935 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001936#ifdef FEAT_MBYTE
1937 (char_u *)&p_mco, PV_NONE,
1938#else
1939 (char_u *)NULL, PV_NONE,
1940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1943#ifdef FEAT_EVAL
1944 (char_u *)&p_mfd, PV_NONE,
1945#else
1946 (char_u *)NULL, PV_NONE,
1947#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001948 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001949 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1950 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"maxmem", "mm", P_NUM|P_VI_DEF,
1953 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1955 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001956 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1957 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1960 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1962 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001963 {"menuitems", "mis", P_NUM|P_VI_DEF,
1964#ifdef FEAT_MENU
1965 (char_u *)&p_mis, PV_NONE,
1966#else
1967 (char_u *)NULL, PV_NONE,
1968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 {"mesg", NULL, P_BOOL|P_VI_DEF,
1971 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001973 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001974#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001975 (char_u *)&p_msm, PV_NONE,
1976 {(char_u *)"460000,2000,500", (char_u *)0L}
1977#else
1978 (char_u *)NULL, PV_NONE,
1979 {(char_u *)0L, (char_u *)0L}
1980#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"modeline", "ml", P_BOOL|P_VIM,
1983 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"modelines", "mls", P_NUM|P_VI_DEF,
1986 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001987 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001988 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1989 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001990 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001991 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1992 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"more", NULL, P_BOOL|P_VIM,
1995 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001996 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1998 (char_u *)&p_mouse, PV_NONE,
1999 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002000#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 (char_u *)"a",
2002#else
2003 (char_u *)"",
2004#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
2007#ifdef FEAT_GUI
2008 (char_u *)&p_mousef, PV_NONE,
2009#else
2010 (char_u *)NULL, PV_NONE,
2011#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2014#ifdef FEAT_GUI
2015 (char_u *)&p_mh, PV_NONE,
2016#else
2017 (char_u *)NULL, PV_NONE,
2018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002019 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2021 (char_u *)&p_mousem, PV_NONE,
2022 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002023#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 (char_u *)"popup",
2025#else
2026# if defined(MACOS)
2027 (char_u *)"popup_setpos",
2028# else
2029 (char_u *)"extend",
2030# endif
2031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002033 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034#ifdef FEAT_MOUSESHAPE
2035 (char_u *)&p_mouseshape, PV_NONE,
2036 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2037#else
2038 (char_u *)NULL, PV_NONE,
2039 {(char_u *)NULL, (char_u *)0L}
2040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2043 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002044 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002045 {"mzquantum", "mzq", P_NUM,
2046#ifdef FEAT_MZSCHEME
2047 (char_u *)&p_mzq, PV_NONE,
2048#else
2049 (char_u *)NULL, PV_NONE,
2050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002051 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 {"novice", NULL, P_BOOL|P_VI_DEF,
2053 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002055 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002057 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002058 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2060 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002061 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002062 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2063#ifdef FEAT_LINEBREAK
2064 (char_u *)VAR_WIN, PV_NUW,
2065#else
2066 (char_u *)NULL, PV_NONE,
2067#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002068 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002069 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002070#ifdef FEAT_COMPL_FUNC
2071 (char_u *)&p_ofu, PV_OFU,
2072 {(char_u *)"", (char_u *)0L}
2073#else
2074 (char_u *)NULL, PV_NONE,
2075 {(char_u *)0L, (char_u *)0L}
2076#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002077 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 {"open", NULL, P_BOOL|P_VI_DEF,
2079 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002080 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002081 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002082#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002083 (char_u *)&p_odev, PV_NONE,
2084#else
2085 (char_u *)NULL, PV_NONE,
2086#endif
2087 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002089 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2090 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002091 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 {"optimize", "opt", P_BOOL|P_VI_DEF,
2093 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002095 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002097 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002098 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2099 |P_SECURE,
2100 (char_u *)&p_pp, PV_NONE,
2101 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2102 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103 {"paragraphs", "para", P_STRING|P_VI_DEF,
2104 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002105 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002106 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002107 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002109 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002110 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2111 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2114#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2115 (char_u *)&p_pex, PV_NONE,
2116 {(char_u *)"", (char_u *)0L}
2117#else
2118 (char_u *)NULL, PV_NONE,
2119 {(char_u *)0L, (char_u *)0L}
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002122 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002124 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002125 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002126 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002128#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129 (char_u *)".,,",
2130#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002134 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002135#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002137 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002138#else
2139 (char_u *)NULL, PV_NONE,
2140 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002141#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002142 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002143 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2144 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002145 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002146 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2148 (char_u *)&p_pvh, PV_NONE,
2149#else
2150 (char_u *)NULL, PV_NONE,
2151#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002152 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2154#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2155 (char_u *)VAR_WIN, PV_PVW,
2156#else
2157 (char_u *)NULL, PV_NONE,
2158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002159 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002160 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161#ifdef FEAT_PRINTER
2162 (char_u *)&p_pdev, PV_NONE,
2163 {(char_u *)"", (char_u *)0L}
2164#else
2165 (char_u *)NULL, PV_NONE,
2166 {(char_u *)NULL, (char_u *)0L}
2167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002168 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002169 {"printencoding", "penc", P_STRING|P_VI_DEF,
2170#ifdef FEAT_POSTSCRIPT
2171 (char_u *)&p_penc, PV_NONE,
2172 {(char_u *)"", (char_u *)0L}
2173#else
2174 (char_u *)NULL, PV_NONE,
2175 {(char_u *)NULL, (char_u *)0L}
2176#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002177 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002178 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179#ifdef FEAT_POSTSCRIPT
2180 (char_u *)&p_pexpr, PV_NONE,
2181 {(char_u *)"", (char_u *)0L}
2182#else
2183 (char_u *)NULL, PV_NONE,
2184 {(char_u *)NULL, (char_u *)0L}
2185#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"printfont", "pfn", P_STRING|P_VI_DEF,
2188#ifdef FEAT_PRINTER
2189 (char_u *)&p_pfn, PV_NONE,
2190 {
2191# ifdef MSWIN
2192 (char_u *)"Courier_New:h10",
2193# else
2194 (char_u *)"courier",
2195# endif
2196 (char_u *)0L}
2197#else
2198 (char_u *)NULL, PV_NONE,
2199 {(char_u *)NULL, (char_u *)0L}
2200#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002201 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002202 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2203#ifdef FEAT_PRINTER
2204 (char_u *)&p_header, PV_NONE,
2205 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2206#else
2207 (char_u *)NULL, PV_NONE,
2208 {(char_u *)NULL, (char_u *)0L}
2209#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002210 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002211 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2212#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2213 (char_u *)&p_pmcs, PV_NONE,
2214 {(char_u *)"", (char_u *)0L}
2215#else
2216 (char_u *)NULL, PV_NONE,
2217 {(char_u *)NULL, (char_u *)0L}
2218#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002219 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002220 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2221#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2222 (char_u *)&p_pmfn, PV_NONE,
2223 {(char_u *)"", (char_u *)0L}
2224#else
2225 (char_u *)NULL, PV_NONE,
2226 {(char_u *)NULL, (char_u *)0L}
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002229 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002230#ifdef FEAT_PRINTER
2231 (char_u *)&p_popt, PV_NONE,
2232 {(char_u *)"", (char_u *)0L}
2233#else
2234 (char_u *)NULL, PV_NONE,
2235 {(char_u *)NULL, (char_u *)0L}
2236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002239 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002240 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002241 {"pumheight", "ph", P_NUM|P_VI_DEF,
2242#ifdef FEAT_INS_EXPAND
2243 (char_u *)&p_ph, PV_NONE,
2244#else
2245 (char_u *)NULL, PV_NONE,
2246#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002247 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002248 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002249#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002250 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002251 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002252#else
2253 (char_u *)NULL, PV_NONE,
2254 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002255#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002256 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002257 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002258#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002259 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002260 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002261#else
2262 (char_u *)NULL, PV_NONE,
2263 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002264#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002265 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002266 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2267#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2268 (char_u *)&p_pyx, PV_NONE,
2269#else
2270 (char_u *)NULL, PV_NONE,
2271#endif
2272 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2273 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002274 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2275#ifdef FEAT_TEXTOBJ
2276 (char_u *)&p_qe, PV_QE,
2277 {(char_u *)"\\", (char_u *)0L}
2278#else
2279 (char_u *)NULL, PV_NONE,
2280 {(char_u *)NULL, (char_u *)0L}
2281#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2284 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002285 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"redraw", NULL, P_BOOL|P_VI_DEF,
2287 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002288 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002289 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2290#ifdef FEAT_RELTIME
2291 (char_u *)&p_rdt, PV_NONE,
2292#else
2293 (char_u *)NULL, PV_NONE,
2294#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002295 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002296 {"regexpengine", "re", P_NUM|P_VI_DEF,
2297 (char_u *)&p_re, PV_NONE,
2298 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002299 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2300 (char_u *)VAR_WIN, PV_RNU,
2301 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"remap", NULL, P_BOOL|P_VI_DEF,
2303 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002305 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002306#ifdef FEAT_RENDER_OPTIONS
2307 (char_u *)&p_rop, PV_NONE,
2308 {(char_u *)"", (char_u *)0L}
2309#else
2310 (char_u *)NULL, PV_NONE,
2311 {(char_u *)NULL, (char_u *)0L}
2312#endif
2313 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"report", NULL, P_NUM|P_VI_DEF,
2315 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002316 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2318#ifdef WIN3264
2319 (char_u *)&p_rs, PV_NONE,
2320#else
2321 (char_u *)NULL, PV_NONE,
2322#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002323 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002324 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2325#ifdef FEAT_RIGHTLEFT
2326 (char_u *)&p_ri, PV_NONE,
2327#else
2328 (char_u *)NULL, PV_NONE,
2329#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002330 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2332#ifdef FEAT_RIGHTLEFT
2333 (char_u *)VAR_WIN, PV_RL,
2334#else
2335 (char_u *)NULL, PV_NONE,
2336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002337 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2339#ifdef FEAT_RIGHTLEFT
2340 (char_u *)VAR_WIN, PV_RLC,
2341 {(char_u *)"search", (char_u *)NULL}
2342#else
2343 (char_u *)NULL, PV_NONE,
2344 {(char_u *)NULL, (char_u *)0L}
2345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002346 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002347 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002348#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002349 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002350 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002351#else
2352 (char_u *)NULL, PV_NONE,
2353 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002354#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2357#ifdef FEAT_CMDL_INFO
2358 (char_u *)&p_ru, PV_NONE,
2359#else
2360 (char_u *)NULL, PV_NONE,
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2364#ifdef FEAT_STL_OPT
2365 (char_u *)&p_ruf, PV_NONE,
2366#else
2367 (char_u *)NULL, PV_NONE,
2368#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002369 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002370 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2371 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2374 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2376 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002377 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002378 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2379#ifdef FEAT_SCROLLBIND
2380 (char_u *)VAR_WIN, PV_SCBIND,
2381#else
2382 (char_u *)NULL, PV_NONE,
2383#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002384 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2386 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2389 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002391 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392#ifdef FEAT_SCROLLBIND
2393 (char_u *)&p_sbo, PV_NONE,
2394 {(char_u *)"ver,jump", (char_u *)0L}
2395#else
2396 (char_u *)NULL, PV_NONE,
2397 {(char_u *)0L, (char_u *)0L}
2398#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002399 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"sections", "sect", P_STRING|P_VI_DEF,
2401 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2403 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2405 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)"inclusive", (char_u *)0L}
2410 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002411 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002413 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002414 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415#ifdef FEAT_SESSION
2416 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002417 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 (char_u *)0L}
2419#else
2420 (char_u *)NULL, PV_NONE,
2421 {(char_u *)0L, (char_u *)0L}
2422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2425 (char_u *)&p_sh, PV_NONE,
2426 {
2427#ifdef VMS
2428 (char_u *)"-",
2429#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002430# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002432# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434# endif
2435#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2438 (char_u *)&p_shcf, PV_NONE,
2439 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002440#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 (char_u *)"/c",
2442#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002446 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2447#ifdef FEAT_QUICKFIX
2448 (char_u *)&p_sp, PV_NONE,
2449 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002450#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452#else
2453 (char_u *)">",
2454#endif
2455 (char_u *)0L}
2456#else
2457 (char_u *)NULL, PV_NONE,
2458 {(char_u *)0L, (char_u *)0L}
2459#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002460 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2462 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002463 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2465 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2468#ifdef BACKSLASH_IN_FILENAME
2469 (char_u *)&p_ssl, PV_NONE,
2470#else
2471 (char_u *)NULL, PV_NONE,
2472#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002474 {"shelltemp", "stmp", P_BOOL,
2475 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002476 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"shelltype", "st", P_NUM|P_VI_DEF,
2478#ifdef AMIGA
2479 (char_u *)&p_st, PV_NONE,
2480#else
2481 (char_u *)NULL, PV_NONE,
2482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2485 (char_u *)&p_sxq, PV_NONE,
2486 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002487#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002488 (char_u *)"\"",
2489#else
2490 (char_u *)"",
2491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002493 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2494 (char_u *)&p_sxe, PV_NONE,
2495 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002496#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002497 (char_u *)"\"&|<>()@^",
2498#else
2499 (char_u *)"",
2500#endif
2501 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2503 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002504 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002505 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2506 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002507 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2509 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002510 {(char_u *)"", (char_u *)"filnxtToO"}
2511 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002512 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002513 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002514 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002515 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2516#ifdef FEAT_LINEBREAK
2517 (char_u *)&p_sbr, PV_NONE,
2518#else
2519 (char_u *)NULL, PV_NONE,
2520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002521 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"showcmd", "sc", P_BOOL|P_VIM,
2523#ifdef FEAT_CMDL_INFO
2524 (char_u *)&p_sc, PV_NONE,
2525#else
2526 (char_u *)NULL, PV_NONE,
2527#endif
2528 {(char_u *)FALSE,
2529#ifdef UNIX
2530 (char_u *)FALSE
2531#else
2532 (char_u *)TRUE
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2536 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2539 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002540 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541 {"showmode", "smd", P_BOOL|P_VIM,
2542 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002543 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002544 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2545#ifdef FEAT_WINDOWS
2546 (char_u *)&p_stal, PV_NONE,
2547#else
2548 (char_u *)NULL, PV_NONE,
2549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002550 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2552 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002553 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2555 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002557 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2558#ifdef FEAT_SIGNS
2559 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002560 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)NULL, (char_u *)0L}
2564#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002565 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002566 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2567 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002568 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2570 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2573#ifdef FEAT_SMARTINDENT
2574 (char_u *)&p_si, PV_SI,
2575#else
2576 (char_u *)NULL, PV_NONE,
2577#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2580 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2583 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2586 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002587 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002588 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002589#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002590 (char_u *)VAR_WIN, PV_SPELL,
2591#else
2592 (char_u *)NULL, PV_NONE,
2593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002594 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002595 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002596#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002597 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002598 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002603 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002604 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2605 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002606#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002607 (char_u *)&p_spf, PV_SPF,
2608 {(char_u *)"", (char_u *)0L}
2609#else
2610 (char_u *)NULL, PV_NONE,
2611 {(char_u *)0L, (char_u *)0L}
2612#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002613 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002614 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2615 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002616#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002617 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002618 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002619#else
2620 (char_u *)NULL, PV_NONE,
2621 {(char_u *)0L, (char_u *)0L}
2622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002624 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002625#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002626 (char_u *)&p_sps, PV_NONE,
2627 {(char_u *)"best", (char_u *)0L}
2628#else
2629 (char_u *)NULL, PV_NONE,
2630 {(char_u *)0L, (char_u *)0L}
2631#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2634#ifdef FEAT_WINDOWS
2635 (char_u *)&p_sb, PV_NONE,
2636#else
2637 (char_u *)NULL, PV_NONE,
2638#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002641#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 (char_u *)&p_spr, PV_NONE,
2643#else
2644 (char_u *)NULL, PV_NONE,
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2648 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002650 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2651#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002652 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653#else
2654 (char_u *)NULL, PV_NONE,
2655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002656 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002657 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 (char_u *)&p_su, PV_NONE,
2659 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002661 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002662#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 (char_u *)&p_sua, PV_SUA,
2664 {(char_u *)"", (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2671 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002672 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002673 {"swapsync", "sws", P_STRING|P_VI_DEF,
2674 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002676 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002678 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002679 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2680#ifdef FEAT_SYN_HL
2681 (char_u *)&p_smc, PV_SMC,
2682 {(char_u *)3000L, (char_u *)0L}
2683#else
2684 (char_u *)NULL, PV_NONE,
2685 {(char_u *)0L, (char_u *)0L}
2686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002688 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689#ifdef FEAT_SYN_HL
2690 (char_u *)&p_syn, PV_SYN,
2691 {(char_u *)"", (char_u *)0L}
2692#else
2693 (char_u *)NULL, PV_NONE,
2694 {(char_u *)0L, (char_u *)0L}
2695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002697 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2698#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002699 (char_u *)&p_tal, PV_NONE,
2700#else
2701 (char_u *)NULL, PV_NONE,
2702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002703 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002704 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2705#ifdef FEAT_WINDOWS
2706 (char_u *)&p_tpm, PV_NONE,
2707#else
2708 (char_u *)NULL, PV_NONE,
2709#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2712 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2715 (char_u *)&p_tbs, PV_NONE,
2716#ifdef VMS /* binary searching doesn't appear to work on VMS */
2717 {(char_u *)0L, (char_u *)0L}
2718#else
2719 {(char_u *)TRUE, (char_u *)0L}
2720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002722 {"tagcase", "tc", P_STRING|P_VIM,
2723 (char_u *)&p_tc, PV_TC,
2724 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"taglength", "tl", P_NUM|P_VI_DEF,
2726 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"tagrelative", "tr", P_BOOL|P_VIM,
2729 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002731 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002732 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 {
2734#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2735 (char_u *)"./tags,./TAGS,tags,TAGS",
2736#else
2737 (char_u *)"./tags,tags",
2738#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002739 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2741 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002742 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002743 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002744#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002745 (char_u *)&p_tcldll, PV_NONE,
2746 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002747#else
2748 (char_u *)NULL, PV_NONE,
2749 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002750#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002751 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2753 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002754 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2756#ifdef FEAT_ARABIC
2757 (char_u *)&p_tbidi, PV_NONE,
2758#else
2759 (char_u *)NULL, PV_NONE,
2760#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2763#ifdef FEAT_MBYTE
2764 (char_u *)&p_tenc, PV_NONE,
2765 {(char_u *)"", (char_u *)0L}
2766#else
2767 (char_u *)NULL, PV_NONE,
2768 {(char_u *)0L, (char_u *)0L}
2769#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002771 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2772#ifdef FEAT_TERMGUICOLORS
2773 (char_u *)&p_tgc, PV_NONE,
2774 {(char_u *)FALSE, (char_u *)FALSE}
2775#else
2776 (char_u*)NULL, PV_NONE,
2777 {(char_u *)FALSE, (char_u *)FALSE}
2778#endif
2779 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"terse", NULL, P_BOOL|P_VI_DEF,
2781 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"textauto", "ta", P_BOOL|P_VIM,
2784 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2786 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002787 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2788 (char_u *)&p_tx, PV_TX,
2789 {
2790#ifdef USE_CRNL
2791 (char_u *)TRUE,
2792#else
2793 (char_u *)FALSE,
2794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002795 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002796 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002799 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002801 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802#else
2803 (char_u *)NULL, PV_NONE,
2804#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002805 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002806 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2807 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002808 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"timeout", "to", P_BOOL|P_VI_DEF,
2810 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002811 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2813 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002814 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"title", NULL, P_BOOL|P_VI_DEF,
2816#ifdef FEAT_TITLE
2817 (char_u *)&p_title, PV_NONE,
2818#else
2819 (char_u *)NULL, PV_NONE,
2820#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"titlelen", NULL, P_NUM|P_VI_DEF,
2823#ifdef FEAT_TITLE
2824 (char_u *)&p_titlelen, PV_NONE,
2825#else
2826 (char_u *)NULL, PV_NONE,
2827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002828 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002829 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830#ifdef FEAT_TITLE
2831 (char_u *)&p_titleold, PV_NONE,
2832 {(char_u *)N_("Thanks for flying Vim"),
2833 (char_u *)0L}
2834#else
2835 (char_u *)NULL, PV_NONE,
2836 {(char_u *)0L, (char_u *)0L}
2837#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002838 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"titlestring", NULL, P_STRING|P_VI_DEF,
2840#ifdef FEAT_TITLE
2841 (char_u *)&p_titlestring, PV_NONE,
2842#else
2843 (char_u *)NULL, PV_NONE,
2844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002845 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002846 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002847#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002848 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002850#else
2851 (char_u *)NULL, PV_NONE,
2852 {(char_u *)0L, (char_u *)0L}
2853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002854 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002856#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002858 {(char_u *)"small", (char_u *)0L}
2859#else
2860 (char_u *)NULL, PV_NONE,
2861 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002862#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002863 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2865 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002866 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002867 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2868 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002870 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2871 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002872 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2874 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002875 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2877#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2878 (char_u *)&p_ttym, PV_NONE,
2879#else
2880 (char_u *)NULL, PV_NONE,
2881#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2884 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2887 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002889 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2890 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002891#ifdef FEAT_PERSISTENT_UNDO
2892 (char_u *)&p_udir, PV_NONE,
2893 {(char_u *)".", (char_u *)0L}
2894#else
2895 (char_u *)NULL, PV_NONE,
2896 {(char_u *)0L, (char_u *)0L}
2897#endif
2898 SCRIPTID_INIT},
2899 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2900#ifdef FEAT_PERSISTENT_UNDO
2901 (char_u *)&p_udf, PV_UDF,
2902#else
2903 (char_u *)NULL, PV_NONE,
2904#endif
2905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002907 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002909#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002910 (char_u *)1000L,
2911#else
2912 (char_u *)100L,
2913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002915 {"undoreload", "ur", P_NUM|P_VI_DEF,
2916 (char_u *)&p_ur, PV_NONE,
2917 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"updatecount", "uc", P_NUM|P_VI_DEF,
2919 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002920 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921 {"updatetime", "ut", P_NUM|P_VI_DEF,
2922 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002923 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924 {"verbose", "vbs", P_NUM|P_VI_DEF,
2925 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002927 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2928 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2931#ifdef FEAT_SESSION
2932 (char_u *)&p_vdir, PV_NONE,
2933 {(char_u *)DFLT_VDIR, (char_u *)0L}
2934#else
2935 (char_u *)NULL, PV_NONE,
2936 {(char_u *)0L, (char_u *)0L}
2937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002939 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002940#ifdef FEAT_SESSION
2941 (char_u *)&p_vop, PV_NONE,
2942 {(char_u *)"folds,options,cursor", (char_u *)0L}
2943#else
2944 (char_u *)NULL, PV_NONE,
2945 {(char_u *)0L, (char_u *)0L}
2946#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002947 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002948 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949#ifdef FEAT_VIMINFO
2950 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002951#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002952 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953#else
2954# ifdef AMIGA
2955 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002956 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002958 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959# endif
2960#endif
2961#else
2962 (char_u *)NULL, PV_NONE,
2963 {(char_u *)0L, (char_u *)0L}
2964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002965 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002966 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2967 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968#ifdef FEAT_VIRTUALEDIT
2969 (char_u *)&p_ve, PV_NONE,
2970 {(char_u *)"", (char_u *)""}
2971#else
2972 (char_u *)NULL, PV_NONE,
2973 {(char_u *)0L, (char_u *)0L}
2974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002975 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2977 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 {"w300", NULL, P_NUM|P_VI_DEF,
2980 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002981 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 {"w1200", NULL, P_NUM|P_VI_DEF,
2983 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002984 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 {"w9600", NULL, P_NUM|P_VI_DEF,
2986 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 {"warn", NULL, P_BOOL|P_VI_DEF,
2989 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002990 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2992 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002994 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997 {"wildchar", "wc", P_NUM|P_VIM,
2998 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002999 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
3000 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003001 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003003 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003004 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003005#ifdef FEAT_WILDIGN
3006 (char_u *)&p_wig, PV_NONE,
3007#else
3008 (char_u *)NULL, PV_NONE,
3009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003010 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003011 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3012 (char_u *)&p_wic, PV_NONE,
3013 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3015#ifdef FEAT_WILDMENU
3016 (char_u *)&p_wmnu, PV_NONE,
3017#else
3018 (char_u *)NULL, PV_NONE,
3019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003021 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003023 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003024 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3025#ifdef FEAT_CMDL_COMPL
3026 (char_u *)&p_wop, PV_NONE,
3027 {(char_u *)"", (char_u *)0L}
3028#else
3029 (char_u *)NULL, PV_NONE,
3030 {(char_u *)NULL, (char_u *)0L}
3031#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003032 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3034#ifdef FEAT_WAK
3035 (char_u *)&p_wak, PV_NONE,
3036 {(char_u *)"menu", (char_u *)0L}
3037#else
3038 (char_u *)NULL, PV_NONE,
3039 {(char_u *)NULL, (char_u *)0L}
3040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003043 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003044 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 {"winheight", "wh", P_NUM|P_VI_DEF,
3046#ifdef FEAT_WINDOWS
3047 (char_u *)&p_wh, PV_NONE,
3048#else
3049 (char_u *)NULL, PV_NONE,
3050#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003051 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003053#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)VAR_WIN, PV_WFH,
3055#else
3056 (char_u *)NULL, PV_NONE,
3057#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003058 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003059 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003060#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003061 (char_u *)VAR_WIN, PV_WFW,
3062#else
3063 (char_u *)NULL, PV_NONE,
3064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003065 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3067#ifdef FEAT_WINDOWS
3068 (char_u *)&p_wmh, PV_NONE,
3069#else
3070 (char_u *)NULL, PV_NONE,
3071#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003072 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003074#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 (char_u *)&p_wmw, PV_NONE,
3076#else
3077 (char_u *)NULL, PV_NONE,
3078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003079 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003081#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 (char_u *)&p_wiw, PV_NONE,
3083#else
3084 (char_u *)NULL, PV_NONE,
3085#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003086 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3088 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003089 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3091 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003092 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3094 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003095 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 {"write", NULL, P_BOOL|P_VI_DEF,
3097 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003098 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 {"writeany", "wa", P_BOOL|P_VI_DEF,
3100 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003101 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3103 (char_u *)&p_wb, PV_NONE,
3104 {
3105#ifdef FEAT_WRITEBACKUP
3106 (char_u *)TRUE,
3107#else
3108 (char_u *)FALSE,
3109#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003110 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 {"writedelay", "wd", P_NUM|P_VI_DEF,
3112 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003113 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114
3115/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003116#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003118 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119
3120 p_term("t_AB", T_CAB)
3121 p_term("t_AF", T_CAF)
3122 p_term("t_AL", T_CAL)
3123 p_term("t_al", T_AL)
3124 p_term("t_bc", T_BC)
3125 p_term("t_cd", T_CD)
3126 p_term("t_ce", T_CE)
3127 p_term("t_cl", T_CL)
3128 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003129 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 p_term("t_Co", T_CCO)
3131 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003132 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003134#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 p_term("t_CV", T_CSV)
3136#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137 p_term("t_da", T_DA)
3138 p_term("t_db", T_DB)
3139 p_term("t_DL", T_CDL)
3140 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003141 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 p_term("t_fs", T_FS)
3143 p_term("t_IE", T_CIE)
3144 p_term("t_IS", T_CIS)
3145 p_term("t_ke", T_KE)
3146 p_term("t_ks", T_KS)
3147 p_term("t_le", T_LE)
3148 p_term("t_mb", T_MB)
3149 p_term("t_md", T_MD)
3150 p_term("t_me", T_ME)
3151 p_term("t_mr", T_MR)
3152 p_term("t_ms", T_MS)
3153 p_term("t_nd", T_ND)
3154 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003155 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_RI", T_CRI)
3157 p_term("t_RV", T_CRV)
3158 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003160 p_term("t_Sf", T_CSF)
3161 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003163 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_te", T_TE)
3166 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003167 p_term("t_ts", T_TS)
3168 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_ue", T_UE)
3170 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003171 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_vb", T_VB)
3173 p_term("t_ve", T_VE)
3174 p_term("t_vi", T_VI)
3175 p_term("t_vs", T_VS)
3176 p_term("t_WP", T_CWP)
3177 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003178 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_xs", T_XS)
3180 p_term("t_ZH", T_CZH)
3181 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003182 p_term("t_8f", T_8F)
3183 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003184 p_term("t_BE", T_BE)
3185 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186
3187/* terminal key codes are not in here */
3188
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003189 /* end marker */
3190 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191};
3192
3193#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3194
3195#ifdef FEAT_MBYTE
3196static char *(p_ambw_values[]) = {"single", "double", NULL};
3197#endif
3198static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003199static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003201#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003202static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003203#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003204#ifdef FEAT_CMDL_COMPL
3205static char *(p_wop_values[]) = {"tagfile", NULL};
3206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207#ifdef FEAT_WAK
3208static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3209#endif
3210static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3212static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003214#ifdef FEAT_BROWSE
3215static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3216#endif
3217#ifdef FEAT_SCROLLBIND
3218static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3219#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003220static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003221#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3223#endif
3224#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003225# ifdef FEAT_AUTOCMD
3226static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3227# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003229# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3231#endif
3232static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3233#ifdef FEAT_FOLDING
3234static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003235# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003237# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003238 NULL};
3239static char *(p_fcl_values[]) = {"all", NULL};
3240#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003241#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003242static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003243#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003244#ifdef FEAT_SIGNS
3245static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3246#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003248static void set_option_default(int, int opt_flags, int compatible);
3249static void set_options_default(int opt_flags);
3250static char_u *term_bg_default(void);
3251static void did_set_option(int opt_idx, int opt_flags, int new_value);
3252static char_u *illegal_char(char_u *, int);
3253static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003255static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#endif
3257#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003258static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003260static char_u *option_expand(int opt_idx, char_u *val);
3261static void didset_options(void);
3262static void didset_options2(void);
3263static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003264#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003265static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003266#else
3267# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3268#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003269static void set_string_option_global(int opt_idx, char_u **varp);
3270static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3271static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3272static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003273#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003275#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003279#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static char_u *did_set_spell_option(int is_spellfile);
3281static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003282#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003283#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003285#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003286static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3287static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3288static void check_redraw(long_u flags);
3289static int findoption(char_u *);
3290static int find_key_option(char_u *);
3291static void showoptions(int all, int opt_flags);
3292static int optval_default(struct vimoption *, char_u *varp);
3293static void showoneopt(struct vimoption *, int opt_flags);
3294static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3295static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3296static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3297static int istermoption(struct vimoption *);
3298static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3299static char_u *get_varp(struct vimoption *);
3300static void option_value2string(struct vimoption *, int opt_flags);
3301static void check_winopt(winopt_T *wop);
3302static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003304static void langmap_init(void);
3305static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003307static void paste_option_changed(void);
3308static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003310static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003312static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3313static int check_opt_strings(char_u *val, char **values, int);
3314static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003315#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003316static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318
3319/*
3320 * Initialize the options, first part.
3321 *
3322 * Called only once from main(), just after creating the first buffer.
3323 */
3324 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003325set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326{
3327 char_u *p;
3328 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003329 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330
3331#ifdef FEAT_LANGMAP
3332 langmap_init();
3333#endif
3334
3335 /* Be Vi compatible by default */
3336 p_cp = TRUE;
3337
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003338 /* Use POSIX compatibility when $VIM_POSIX is set. */
3339 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003340 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003341 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003342 set_string_default("shm", (char_u *)"A");
3343 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003344
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 /*
3346 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003347 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003349 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003350#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003351 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003353 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354# endif
3355#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003356 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 set_string_default("sh", p);
3358
3359#ifdef FEAT_WILDIGN
3360 /*
3361 * Set the default for 'backupskip' to include environment variables for
3362 * temp files.
3363 */
3364 {
3365# ifdef UNIX
3366 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3367# else
3368 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3369# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003370 int len;
3371 garray_T ga;
3372 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373
3374 ga_init2(&ga, 1, 100);
3375 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3376 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003377 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378# ifdef UNIX
3379 if (*names[n] == NUL)
3380 p = (char_u *)"/tmp";
3381 else
3382# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003383 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 if (p != NULL && *p != NUL)
3385 {
3386 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003387 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 if (ga_grow(&ga, len) == OK)
3389 {
3390 if (ga.ga_len > 0)
3391 STRCAT(ga.ga_data, ",");
3392 STRCAT(ga.ga_data, p);
3393 add_pathsep(ga.ga_data);
3394 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 ga.ga_len += len;
3396 }
3397 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003398 if (mustfree)
3399 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400 }
3401 if (ga.ga_data != NULL)
3402 {
3403 set_string_default("bsk", ga.ga_data);
3404 vim_free(ga.ga_data);
3405 }
3406 }
3407#endif
3408
3409 /*
3410 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3411 */
3412 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003413 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003415#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3416 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3417#endif
3418 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003420 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003421 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422#else
3423# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003424 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003425 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003427 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428# endif
3429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003430 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003431 opt_idx = findoption((char_u *)"maxmem");
3432 if (opt_idx >= 0)
3433 {
3434#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003435 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3436 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003437#endif
3438 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3439 }
3440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 }
3442
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443#ifdef FEAT_SEARCHPATH
3444 {
3445 char_u *cdpath;
3446 char_u *buf;
3447 int i;
3448 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003449 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450
3451 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003452 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453 if (cdpath != NULL)
3454 {
3455 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3456 if (buf != NULL)
3457 {
3458 buf[0] = ','; /* start with ",", current dir first */
3459 j = 1;
3460 for (i = 0; cdpath[i] != NUL; ++i)
3461 {
3462 if (vim_ispathlistsep(cdpath[i]))
3463 buf[j++] = ',';
3464 else
3465 {
3466 if (cdpath[i] == ' ' || cdpath[i] == ',')
3467 buf[j++] = '\\';
3468 buf[j++] = cdpath[i];
3469 }
3470 }
3471 buf[j] = NUL;
3472 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003473 if (opt_idx >= 0)
3474 {
3475 options[opt_idx].def_val[VI_DEFAULT] = buf;
3476 options[opt_idx].flags |= P_DEF_ALLOCED;
3477 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003478 else
3479 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003481 if (mustfree)
3482 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 }
3484 }
3485#endif
3486
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003487#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003488 /* Set print encoding on platforms that don't default to latin1 */
3489 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003490# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491 (char_u *)"cp1252"
3492# else
3493# ifdef VMS
3494 (char_u *)"dec-mcs"
3495# else
3496# ifdef EBCDIC
3497 (char_u *)"ebcdic-uk"
3498# else
3499# ifdef MAC
3500 (char_u *)"mac-roman"
3501# else /* HPUX */
3502 (char_u *)"hp-roman8"
3503# endif
3504# endif
3505# endif
3506# endif
3507 );
3508#endif
3509
3510#ifdef FEAT_POSTSCRIPT
3511 /* 'printexpr' must be allocated to be able to evaluate it. */
3512 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003513# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003514 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515# else
3516# ifdef VMS
3517 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3518
3519# else
3520 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3521# endif
3522# endif
3523 );
3524#endif
3525
3526 /*
3527 * Set all the options (except the terminal options) to their default
3528 * value. Also set the global value for local options.
3529 */
3530 set_options_default(0);
3531
3532#ifdef FEAT_GUI
3533 if (found_reverse_arg)
3534 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3535#endif
3536
3537 curbuf->b_p_initialized = TRUE;
3538 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003539 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540 check_buf_options(curbuf);
3541 check_win_options(curwin);
3542 check_options();
3543
3544 /* Must be before option_expand(), because that one needs vim_isIDc() */
3545 didset_options();
3546
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003547#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003548 /* Use the current chartab for the generic chartab. This is not in
3549 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003550 init_spell_chartab();
3551#endif
3552
Bram Moolenaar071d4272004-06-13 20:20:40 +00003553 /*
3554 * Expand environment variables and things like "~" for the defaults.
3555 * If option_expand() returns non-NULL the variable is expanded. This can
3556 * only happen for non-indirect options.
3557 * Also set the default to the expanded value, so ":set" does not list
3558 * them.
3559 * Don't set the P_ALLOCED flag, because we don't want to free the
3560 * default.
3561 */
3562 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3563 {
3564 if ((options[opt_idx].flags & P_GETTEXT)
3565 && options[opt_idx].var != NULL)
3566 p = (char_u *)_(*(char **)options[opt_idx].var);
3567 else
3568 p = option_expand(opt_idx, NULL);
3569 if (p != NULL && (p = vim_strsave(p)) != NULL)
3570 {
3571 *(char_u **)options[opt_idx].var = p;
3572 /* VIMEXP
3573 * Defaults for all expanded options are currently the same for Vi
3574 * and Vim. When this changes, add some code here! Also need to
3575 * split P_DEF_ALLOCED in two.
3576 */
3577 if (options[opt_idx].flags & P_DEF_ALLOCED)
3578 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3579 options[opt_idx].def_val[VI_DEFAULT] = p;
3580 options[opt_idx].flags |= P_DEF_ALLOCED;
3581 }
3582 }
3583
Bram Moolenaar071d4272004-06-13 20:20:40 +00003584 save_file_ff(curbuf); /* Buffer is unchanged */
3585
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586#if defined(FEAT_ARABIC)
3587 /* Detect use of mlterm.
3588 * Mlterm is a terminal emulator akin to xterm that has some special
3589 * abilities (bidi namely).
3590 * NOTE: mlterm's author is being asked to 'set' a variable
3591 * instead of an environment variable due to inheritance.
3592 */
3593 if (mch_getenv((char_u *)"MLTERM") != NULL)
3594 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3595#endif
3596
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003597 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598
3599#ifdef FEAT_MBYTE
3600# if defined(WIN3264) && defined(FEAT_GETTEXT)
3601 /*
3602 * If $LANG isn't set, try to get a good value for it. This makes the
3603 * right language be used automatically. Don't do this for English.
3604 */
3605 if (mch_getenv((char_u *)"LANG") == NULL)
3606 {
3607 char buf[20];
3608
3609 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3610 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3611 * only the first two. */
3612 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3613 (LPTSTR)buf, 20);
3614 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3615 {
3616 /* There are a few exceptions (probably more) */
3617 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3618 STRCPY(buf, "zh_TW");
3619 else if (STRNICMP(buf, "chs", 3) == 0
3620 || STRNICMP(buf, "zhc", 3) == 0)
3621 STRCPY(buf, "zh_CN");
3622 else if (STRNICMP(buf, "jp", 2) == 0)
3623 STRCPY(buf, "ja");
3624 else
3625 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003626 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 }
3628 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003629# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003630# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003631 /* Moved to os_mac_conv.c to avoid dependency problems. */
3632 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003633# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003634# endif
3635
3636 /* enc_locale() will try to find the encoding of the current locale. */
3637 p = enc_locale();
3638 if (p != NULL)
3639 {
3640 char_u *save_enc;
3641
3642 /* Try setting 'encoding' and check if the value is valid.
3643 * If not, go back to the default "latin1". */
3644 save_enc = p_enc;
3645 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003646 if (STRCMP(p_enc, "gb18030") == 0)
3647 {
3648 /* We don't support "gb18030", but "cp936" is a good substitute
3649 * for practical purposes, thus use that. It's not an alias to
3650 * still support conversion between gb18030 and utf-8. */
3651 p_enc = vim_strsave((char_u *)"cp936");
3652 vim_free(p);
3653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003654 if (mb_init() == NULL)
3655 {
3656 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003657 if (opt_idx >= 0)
3658 {
3659 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3660 options[opt_idx].flags |= P_DEF_ALLOCED;
3661 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003662
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003663#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003664 if (STRCMP(p_enc, "latin1") == 0
3665# ifdef FEAT_MBYTE
3666 || enc_utf8
3667# endif
3668 )
3669 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003670 /* Adjust the default for 'isprint' and 'iskeyword' to match
3671 * latin1. Also set the defaults for when 'nocompatible' is
3672 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003673 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003674 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003675 set_string_option_direct((char_u *)"isk", -1,
3676 ISK_LATIN1, OPT_FREE, SID_NONE);
3677 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003678 if (opt_idx >= 0)
3679 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003680 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003681 if (opt_idx >= 0)
3682 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003683 (void)init_chartab();
3684 }
3685#endif
3686
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687# if defined(WIN3264) && !defined(FEAT_GUI)
3688 /* Win32 console: When GetACP() returns a different value from
3689 * GetConsoleCP() set 'termencoding'. */
3690 if (GetACP() != GetConsoleCP())
3691 {
3692 char buf[50];
3693
3694 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3695 p_tenc = vim_strsave((char_u *)buf);
3696 if (p_tenc != NULL)
3697 {
3698 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 {
3701 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3702 options[opt_idx].flags |= P_DEF_ALLOCED;
3703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704 convert_setup(&input_conv, p_tenc, p_enc);
3705 convert_setup(&output_conv, p_enc, p_tenc);
3706 }
3707 else
3708 p_tenc = empty_option;
3709 }
3710# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003711# if defined(WIN3264) && defined(FEAT_MBYTE)
3712 /* $HOME may have characters in active code page. */
3713 init_homedir();
3714# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003715 }
3716 else
3717 {
3718 vim_free(p_enc);
3719 p_enc = save_enc;
3720 }
3721 }
3722#endif
3723
3724#ifdef FEAT_MULTI_LANG
3725 /* Set the default for 'helplang'. */
3726 set_helplang_default(get_mess_lang());
3727#endif
3728}
3729
3730/*
3731 * Set an option to its default value.
3732 * This does not take care of side effects!
3733 */
3734 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003735set_option_default(
3736 int opt_idx,
3737 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3738 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739{
3740 char_u *varp; /* pointer to variable for current option */
3741 int dvi; /* index in def_val[] */
3742 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003743 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3745
3746 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3747 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003748 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749 {
3750 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3751 if (flags & P_STRING)
3752 {
3753 /* Use set_string_option_direct() for local options to handle
3754 * freeing and allocating the value. */
3755 if (options[opt_idx].indir != PV_NONE)
3756 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003757 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758 else
3759 {
3760 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3761 free_string_option(*(char_u **)(varp));
3762 *(char_u **)varp = options[opt_idx].def_val[dvi];
3763 options[opt_idx].flags &= ~P_ALLOCED;
3764 }
3765 }
3766 else if (flags & P_NUM)
3767 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003768 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 win_comp_scroll(curwin);
3770 else
3771 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003772 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773 /* May also set global value for local option. */
3774 if (both)
3775 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3776 *(long *)varp;
3777 }
3778 }
3779 else /* P_BOOL */
3780 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003781 /* the cast to long is required for Manx C, long_i is needed for
3782 * MSVC */
3783 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003784#ifdef UNIX
3785 /* 'modeline' defaults to off for root */
3786 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3787 *(int *)varp = FALSE;
3788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003789 /* May also set global value for local option. */
3790 if (both)
3791 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3792 *(int *)varp;
3793 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003794
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003795 /* The default value is not insecure. */
3796 flagsp = insecure_flag(opt_idx, opt_flags);
3797 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798 }
3799
3800#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003801 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003802#endif
3803}
3804
3805/*
3806 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003807 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 */
3809 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003810set_options_default(
3811 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812{
3813 int i;
3814#ifdef FEAT_WINDOWS
3815 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003816 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817#endif
3818
3819 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003820 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003821#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003822 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003823 || (TRUE
3824# if defined(FEAT_MBYTE)
3825 && options[i].var != (char_u *)&p_enc
3826# endif
3827# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003828 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003829 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003830# endif
3831 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003832#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003833 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 set_option_default(i, opt_flags, p_cp);
3835
3836#ifdef FEAT_WINDOWS
3837 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003838 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 win_comp_scroll(wp);
3840#else
3841 win_comp_scroll(curwin);
3842#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003843#ifdef FEAT_CINDENT
3844 parse_cino(curbuf);
3845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846}
3847
3848/*
3849 * Set the Vi-default value of a string option.
3850 * Used for 'sh', 'backupskip' and 'term'.
3851 */
3852 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003853set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854{
3855 char_u *p;
3856 int opt_idx;
3857
3858 p = vim_strsave(val);
3859 if (p != NULL) /* we don't want a NULL */
3860 {
3861 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003862 if (opt_idx >= 0)
3863 {
3864 if (options[opt_idx].flags & P_DEF_ALLOCED)
3865 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3866 options[opt_idx].def_val[VI_DEFAULT] = p;
3867 options[opt_idx].flags |= P_DEF_ALLOCED;
3868 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 }
3870}
3871
3872/*
3873 * Set the Vi-default value of a number option.
3874 * Used for 'lines' and 'columns'.
3875 */
3876 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003877set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003879 int opt_idx;
3880
3881 opt_idx = findoption((char_u *)name);
3882 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003883 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884}
3885
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003886#if defined(EXITFREE) || defined(PROTO)
3887/*
3888 * Free all options.
3889 */
3890 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003891free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003892{
3893 int i;
3894
3895 for (i = 0; !istermoption(&options[i]); i++)
3896 {
3897 if (options[i].indir == PV_NONE)
3898 {
3899 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003900 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003901 free_string_option(*(char_u **)options[i].var);
3902 if (options[i].flags & P_DEF_ALLOCED)
3903 free_string_option(options[i].def_val[VI_DEFAULT]);
3904 }
3905 else if (options[i].var != VAR_WIN
3906 && (options[i].flags & P_STRING))
3907 /* buffer-local option: free global value */
3908 free_string_option(*(char_u **)options[i].var);
3909 }
3910}
3911#endif
3912
3913
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914/*
3915 * Initialize the options, part two: After getting Rows and Columns and
3916 * setting 'term'.
3917 */
3918 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003919set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003920{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003921 int idx;
3922
Bram Moolenaar071d4272004-06-13 20:20:40 +00003923 /*
3924 * 'scroll' defaults to half the window height. Note that this default is
3925 * wrong when the window height changes.
3926 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003927 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003928 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003929 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003930 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 comp_col();
3932
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003933 /*
3934 * 'window' is only for backwards compatibility with Vi.
3935 * Default is Rows - 1.
3936 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003937 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003938 p_window = Rows - 1;
3939 set_number_default("window", Rows - 1);
3940
Bram Moolenaarf740b292006-02-16 22:11:02 +00003941 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003942#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003943 /*
3944 * If 'background' wasn't set by the user, try guessing the value,
3945 * depending on the terminal name. Only need to check for terminals
3946 * with a dark background, that can handle color.
3947 */
3948 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003949 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3950 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003952 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003953 /* don't mark it as set, when starting the GUI it may be
3954 * changed again */
3955 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 }
3957#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003958
3959#ifdef CURSOR_SHAPE
3960 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3961#endif
3962#ifdef FEAT_MOUSESHAPE
3963 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3964#endif
3965#ifdef FEAT_PRINTER
3966 (void)parse_printoptions(); /* parse 'printoptions' default value */
3967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968}
3969
3970/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003971 * Return "dark" or "light" depending on the kind of terminal.
3972 * This is just guessing! Recognized are:
3973 * "linux" Linux console
3974 * "screen.linux" Linux console with screen
3975 * "cygwin" Cygwin shell
3976 * "putty" Putty program
3977 * We also check the COLORFGBG environment variable, which is set by
3978 * rxvt and derivatives. This variable contains either two or three
3979 * values separated by semicolons; we want the last value in either
3980 * case. If this value is 0-6 or 8, our background is dark.
3981 */
3982 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003983term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003984{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003985#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003986 /* DOS console nearly always black */
3987 return (char_u *)"dark";
3988#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003989 char_u *p;
3990
Bram Moolenaarf740b292006-02-16 22:11:02 +00003991 if (STRCMP(T_NAME, "linux") == 0
3992 || STRCMP(T_NAME, "screen.linux") == 0
3993 || STRCMP(T_NAME, "cygwin") == 0
3994 || STRCMP(T_NAME, "putty") == 0
3995 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3996 && (p = vim_strrchr(p, ';')) != NULL
3997 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3998 && p[2] == NUL))
3999 return (char_u *)"dark";
4000 return (char_u *)"light";
4001#endif
4002}
4003
4004/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 * Initialize the options, part three: After reading the .vimrc
4006 */
4007 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004008set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004010#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011/*
4012 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4013 * This is done after other initializations, where 'shell' might have been
4014 * set, but only if they have not been set before.
4015 */
4016 char_u *p;
4017 int idx_srr;
4018 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004019# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 int idx_sp;
4021 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004022# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023
4024 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004025 if (idx_srr < 0)
4026 do_srr = FALSE;
4027 else
4028 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004029# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004031 if (idx_sp < 0)
4032 do_sp = FALSE;
4033 else
4034 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004035# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004036 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 if (p != NULL)
4038 {
4039 /*
4040 * Default for p_sp is "| tee", for p_srr is ">".
4041 * For known shells it is changed here to include stderr.
4042 */
4043 if ( fnamecmp(p, "csh") == 0
4044 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004045# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046 || fnamecmp(p, "csh.exe") == 0
4047 || fnamecmp(p, "tcsh.exe") == 0
4048# endif
4049 )
4050 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004051# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 if (do_sp)
4053 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004058# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4060 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 if (do_srr)
4063 {
4064 p_srr = (char_u *)">&";
4065 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4066 }
4067 }
4068 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 if ( fnamecmp(p, "sh") == 0
4071 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004072 || fnamecmp(p, "mksh") == 0
4073 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004075 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004077 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004078# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 || fnamecmp(p, "cmd") == 0
4080 || fnamecmp(p, "sh.exe") == 0
4081 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004082 || fnamecmp(p, "mksh.exe") == 0
4083 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004085 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 || fnamecmp(p, "bash.exe") == 0
4087 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004091# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 if (do_sp)
4093 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004094# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4100 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004101# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 if (do_srr)
4103 {
4104 p_srr = (char_u *)">%s 2>&1";
4105 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4106 }
4107 }
4108 vim_free(p);
4109 }
4110#endif
4111
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004112#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004114 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4115 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 * This is done after other initializations, where 'shell' might have been
4117 * set, but only if they have not been set before. Default for p_shcf is
4118 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004119 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004121 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 {
4123 int idx3;
4124
4125 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004126 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
4128 p_shcf = (char_u *)"-c";
4129 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4130 }
4131
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 /* Somehow Win32 requires the quotes around the redirection too */
4133 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004134 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 {
4136 p_sxq = (char_u *)"\"";
4137 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004140 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4141 {
4142 int idx3;
4143
4144 /*
4145 * cmd.exe on Windows will strip the first and last double quote given
4146 * on the command line, e.g. most of the time things like:
4147 * cmd /c "my path/to/echo" "my args to echo"
4148 * become:
4149 * my path/to/echo" "my args to echo
4150 * when executed.
4151 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004152 * To avoid this, set shellxquote to surround the command in
4153 * parenthesis. This appears to make most commands work, without
4154 * breaking commands that worked previously, such as
4155 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004156 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004157 idx3 = findoption((char_u *)"sxq");
4158 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4159 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004160 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004161 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4162 }
4163
Bram Moolenaara64ba222012-02-12 23:23:31 +01004164 idx3 = findoption((char_u *)"shcf");
4165 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4166 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004167 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004168 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4169 }
4170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171#endif
4172
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004173 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004174 {
4175 int idx_ffs = findoption((char_u *)"ffs");
4176
4177 /* Apply the first entry of 'fileformats' to the initial buffer. */
4178 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4179 set_fileformat(default_fileformat(), OPT_LOCAL);
4180 }
4181
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182#ifdef FEAT_TITLE
4183 set_title_defaults();
4184#endif
4185}
4186
4187#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4188/*
4189 * When 'helplang' is still at its default value, set it to "lang".
4190 * Only the first two characters of "lang" are used.
4191 */
4192 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004193set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194{
4195 int idx;
4196
4197 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4198 return;
4199 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004200 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201 {
4202 if (options[idx].flags & P_ALLOCED)
4203 free_string_option(p_hlg);
4204 p_hlg = vim_strsave(lang);
4205 if (p_hlg == NULL)
4206 p_hlg = empty_option;
4207 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004208 {
4209 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4210 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4211 {
4212 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4213 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4214 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004216 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004217 options[idx].flags |= P_ALLOCED;
4218 }
4219}
4220#endif
4221
4222#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004223static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224
4225 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004226gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227{
4228 if (gui_get_lightness(gui.back_pixel) < 127)
4229 return (char_u *)"dark";
4230 return (char_u *)"light";
4231}
4232
4233/*
4234 * Option initializations that can only be done after opening the GUI window.
4235 */
4236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004237init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238{
4239 /* Set the 'background' option according to the lightness of the
4240 * background color, unless the user has set it already. */
4241 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4242 {
4243 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4244 highlight_changed();
4245 }
4246}
4247#endif
4248
4249#ifdef FEAT_TITLE
4250/*
4251 * 'title' and 'icon' only default to true if they have not been set or reset
4252 * in .vimrc and we can read the old value.
4253 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4254 * they can be reset. This reduces startup time when using X on a remote
4255 * machine.
4256 */
4257 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004258set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259{
4260 int idx1;
4261 long val;
4262
4263 /*
4264 * If GUI is (going to be) used, we can always set the window title and
4265 * icon name. Saves a bit of time, because the X11 display server does
4266 * not need to be contacted.
4267 */
4268 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004269 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270 {
4271#ifdef FEAT_GUI
4272 if (gui.starting || gui.in_use)
4273 val = TRUE;
4274 else
4275#endif
4276 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004277 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004278 p_title = val;
4279 }
4280 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004281 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282 {
4283#ifdef FEAT_GUI
4284 if (gui.starting || gui.in_use)
4285 val = TRUE;
4286 else
4287#endif
4288 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004289 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004290 p_icon = val;
4291 }
4292}
4293#endif
4294
4295/*
4296 * Parse 'arg' for option settings.
4297 *
4298 * 'arg' may be IObuff, but only when no errors can be present and option
4299 * does not need to be expanded with option_expand().
4300 * "opt_flags":
4301 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004302 * OPT_GLOBAL for ":setglobal"
4303 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004304 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004305 * OPT_WINONLY to only set window-local options
4306 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004307 *
4308 * returns FAIL if an error is detected, OK otherwise
4309 */
4310 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004311do_set(
4312 char_u *arg, /* option string (may be written to!) */
4313 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314{
4315 int opt_idx;
4316 char_u *errmsg;
4317 char_u errbuf[80];
4318 char_u *startarg;
4319 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4320 int nextchar; /* next non-white char after option name */
4321 int afterchar; /* character just after option name */
4322 int len;
4323 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004324 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325 int key;
4326 long_u flags; /* flags for current option */
4327 char_u *varp = NULL; /* pointer to variable for current option */
4328 int did_show = FALSE; /* already showed one value */
4329 int adding; /* "opt+=arg" */
4330 int prepending; /* "opt^=arg" */
4331 int removing; /* "opt-=arg" */
4332 int cp_val = 0;
4333 char_u key_name[2];
4334
4335 if (*arg == NUL)
4336 {
4337 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004338 did_show = TRUE;
4339 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340 }
4341
4342 while (*arg != NUL) /* loop to process all options */
4343 {
4344 errmsg = NULL;
4345 startarg = arg; /* remember for error message */
4346
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004347 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4348 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004349 {
4350 /*
4351 * ":set all" show all options.
4352 * ":set all&" set all options to their default value.
4353 */
4354 arg += 3;
4355 if (*arg == '&')
4356 {
4357 ++arg;
4358 /* Only for :set command set global value of local options. */
4359 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004360 didset_options();
4361 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004362 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004363 }
4364 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004365 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004366 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004367 did_show = TRUE;
4368 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004369 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004370 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371 {
4372 showoptions(2, opt_flags);
4373 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004374 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004375 arg += 7;
4376 }
4377 else
4378 {
4379 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004380 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004381 {
4382 prefix = 0;
4383 arg += 2;
4384 }
4385 else if (STRNCMP(arg, "inv", 3) == 0)
4386 {
4387 prefix = 2;
4388 arg += 3;
4389 }
4390
4391 /* find end of name */
4392 key = 0;
4393 if (*arg == '<')
4394 {
4395 nextchar = 0;
4396 opt_idx = -1;
4397 /* look out for <t_>;> */
4398 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4399 len = 5;
4400 else
4401 {
4402 len = 1;
4403 while (arg[len] != NUL && arg[len] != '>')
4404 ++len;
4405 }
4406 if (arg[len] != '>')
4407 {
4408 errmsg = e_invarg;
4409 goto skip;
4410 }
4411 arg[len] = NUL; /* put NUL after name */
4412 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4413 opt_idx = findoption(arg + 1);
4414 arg[len++] = '>'; /* restore '>' */
4415 if (opt_idx == -1)
4416 key = find_key_option(arg + 1);
4417 }
4418 else
4419 {
4420 len = 0;
4421 /*
4422 * The two characters after "t_" may not be alphanumeric.
4423 */
4424 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4425 len = 4;
4426 else
4427 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4428 ++len;
4429 nextchar = arg[len];
4430 arg[len] = NUL; /* put NUL after name */
4431 opt_idx = findoption(arg);
4432 arg[len] = nextchar; /* restore nextchar */
4433 if (opt_idx == -1)
4434 key = find_key_option(arg);
4435 }
4436
4437 /* remember character after option name */
4438 afterchar = arg[len];
4439
4440 /* skip white space, allow ":set ai ?" */
4441 while (vim_iswhite(arg[len]))
4442 ++len;
4443
4444 adding = FALSE;
4445 prepending = FALSE;
4446 removing = FALSE;
4447 if (arg[len] != NUL && arg[len + 1] == '=')
4448 {
4449 if (arg[len] == '+')
4450 {
4451 adding = TRUE; /* "+=" */
4452 ++len;
4453 }
4454 else if (arg[len] == '^')
4455 {
4456 prepending = TRUE; /* "^=" */
4457 ++len;
4458 }
4459 else if (arg[len] == '-')
4460 {
4461 removing = TRUE; /* "-=" */
4462 ++len;
4463 }
4464 }
4465 nextchar = arg[len];
4466
4467 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4468 {
4469 errmsg = (char_u *)N_("E518: Unknown option");
4470 goto skip;
4471 }
4472
4473 if (opt_idx >= 0)
4474 {
4475 if (options[opt_idx].var == NULL) /* hidden option: skip */
4476 {
4477 /* Only give an error message when requesting the value of
4478 * a hidden option, ignore setting it. */
4479 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4480 && (!(options[opt_idx].flags & P_BOOL)
4481 || nextchar == '?'))
4482 errmsg = (char_u *)N_("E519: Option not supported");
4483 goto skip;
4484 }
4485
4486 flags = options[opt_idx].flags;
4487 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4488 }
4489 else
4490 {
4491 flags = P_STRING;
4492 if (key < 0)
4493 {
4494 key_name[0] = KEY2TERMCAP0(key);
4495 key_name[1] = KEY2TERMCAP1(key);
4496 }
4497 else
4498 {
4499 key_name[0] = KS_KEY;
4500 key_name[1] = (key & 0xff);
4501 }
4502 }
4503
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004504 /* Skip all options that are not window-local (used when showing
4505 * an already loaded buffer in a window). */
4506 if ((opt_flags & OPT_WINONLY)
4507 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4508 goto skip;
4509
Bram Moolenaara3227e22006-03-08 21:32:40 +00004510 /* Skip all options that are window-local (used for :vimgrep). */
4511 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4512 && options[opt_idx].var == VAR_WIN)
4513 goto skip;
4514
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004515 /* Disallow changing some options from modelines. */
4516 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004517 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004518 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004519 {
4520 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4521 goto skip;
4522 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004523#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004524 /* In diff mode some options are overruled. This avoids that
4525 * 'foldmethod' becomes "marker" instead of "diff" and that
4526 * "wrap" gets set. */
4527 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004528 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004529 && (
4530#ifdef FEAT_FOLDING
4531 options[opt_idx].indir == PV_FDM ||
4532#endif
4533 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004534 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004535#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004536 }
4537
4538#ifdef HAVE_SANDBOX
4539 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004540 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004541 {
4542 errmsg = (char_u *)_(e_sandbox);
4543 goto skip;
4544 }
4545#endif
4546
4547 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4548 {
4549 arg += len;
4550 cp_val = p_cp;
4551 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4552 {
4553 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4554 {
4555 cp_val = FALSE;
4556 arg += 3;
4557 }
4558 else /* "opt&vi": set to Vi default */
4559 {
4560 cp_val = TRUE;
4561 arg += 2;
4562 }
4563 }
4564 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4565 && arg[1] != NUL && !vim_iswhite(arg[1]))
4566 {
4567 errmsg = e_trailing;
4568 goto skip;
4569 }
4570 }
4571
4572 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004573 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4574 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004575 */
4576 if (nextchar == '?'
4577 || (prefix == 1
4578 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4579 && !(flags & P_BOOL)))
4580 {
4581 /*
4582 * print value
4583 */
4584 if (did_show)
4585 msg_putchar('\n'); /* cursor below last one */
4586 else
4587 {
4588 gotocmdline(TRUE); /* cursor at status line */
4589 did_show = TRUE; /* remember that we did a line */
4590 }
4591 if (opt_idx >= 0)
4592 {
4593 showoneopt(&options[opt_idx], opt_flags);
4594#ifdef FEAT_EVAL
4595 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004596 {
4597 /* Mention where the option was last set. */
4598 if (varp == options[opt_idx].var)
4599 last_set_msg(options[opt_idx].scriptID);
4600 else if ((int)options[opt_idx].indir & PV_WIN)
4601 last_set_msg(curwin->w_p_scriptID[
4602 (int)options[opt_idx].indir & PV_MASK]);
4603 else if ((int)options[opt_idx].indir & PV_BUF)
4604 last_set_msg(curbuf->b_p_scriptID[
4605 (int)options[opt_idx].indir & PV_MASK]);
4606 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004607#endif
4608 }
4609 else
4610 {
4611 char_u *p;
4612
4613 p = find_termcode(key_name);
4614 if (p == NULL)
4615 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004616 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617 goto skip;
4618 }
4619 else
4620 (void)show_one_termcode(key_name, p, TRUE);
4621 }
4622 if (nextchar != '?'
4623 && nextchar != NUL && !vim_iswhite(afterchar))
4624 errmsg = e_trailing;
4625 }
4626 else
4627 {
4628 if (flags & P_BOOL) /* boolean */
4629 {
4630 if (nextchar == '=' || nextchar == ':')
4631 {
4632 errmsg = e_invarg;
4633 goto skip;
4634 }
4635
4636 /*
4637 * ":set opt!": invert
4638 * ":set opt&": reset to default value
4639 * ":set opt<": reset to global value
4640 */
4641 if (nextchar == '!')
4642 value = *(int *)(varp) ^ 1;
4643 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004644 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004645 ((flags & P_VI_DEF) || cp_val)
4646 ? VI_DEFAULT : VIM_DEFAULT];
4647 else if (nextchar == '<')
4648 {
4649 /* For 'autoread' -1 means to use global value. */
4650 if ((int *)varp == &curbuf->b_p_ar
4651 && opt_flags == OPT_LOCAL)
4652 value = -1;
4653 else
4654 value = *(int *)get_varp_scope(&(options[opt_idx]),
4655 OPT_GLOBAL);
4656 }
4657 else
4658 {
4659 /*
4660 * ":set invopt": invert
4661 * ":set opt" or ":set noopt": set or reset
4662 */
4663 if (nextchar != NUL && !vim_iswhite(afterchar))
4664 {
4665 errmsg = e_trailing;
4666 goto skip;
4667 }
4668 if (prefix == 2) /* inv */
4669 value = *(int *)(varp) ^ 1;
4670 else
4671 value = prefix;
4672 }
4673
4674 errmsg = set_bool_option(opt_idx, varp, (int)value,
4675 opt_flags);
4676 }
4677 else /* numeric or string */
4678 {
4679 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4680 || prefix != 1)
4681 {
4682 errmsg = e_invarg;
4683 goto skip;
4684 }
4685
4686 if (flags & P_NUM) /* numeric */
4687 {
4688 /*
4689 * Different ways to set a number option:
4690 * & set to default value
4691 * < set to global value
4692 * <xx> accept special key codes for 'wildchar'
4693 * c accept any non-digit for 'wildchar'
4694 * [-]0-9 set number
4695 * other error
4696 */
4697 ++arg;
4698 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004699 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004700 ((flags & P_VI_DEF) || cp_val)
4701 ? VI_DEFAULT : VIM_DEFAULT];
4702 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004703 {
4704 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4705 * use the global value. */
4706 if ((long *)varp == &curbuf->b_p_ul
4707 && opt_flags == OPT_LOCAL)
4708 value = NO_LOCAL_UNDOLEVEL;
4709 else
4710 value = *(long *)get_varp_scope(
4711 &(options[opt_idx]), OPT_GLOBAL);
4712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004713 else if (((long *)varp == &p_wc
4714 || (long *)varp == &p_wcm)
4715 && (*arg == '<'
4716 || *arg == '^'
Bram Moolenaara12e4032017-02-25 21:37:57 +01004717 || (*arg != NUL && (!arg[1] || vim_iswhite(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004718 && !VIM_ISDIGIT(*arg))))
4719 {
4720 value = string_to_key(arg);
4721 if (value == 0 && (long *)varp != &p_wcm)
4722 {
4723 errmsg = e_invarg;
4724 goto skip;
4725 }
4726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004727 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4728 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004729 /* Allow negative (for 'undolevels'), octal and
4730 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004731 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4732 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004733 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4734 {
4735 errmsg = e_invarg;
4736 goto skip;
4737 }
4738 }
4739 else
4740 {
4741 errmsg = (char_u *)N_("E521: Number required after =");
4742 goto skip;
4743 }
4744
4745 if (adding)
4746 value = *(long *)varp + value;
4747 if (prepending)
4748 value = *(long *)varp * value;
4749 if (removing)
4750 value = *(long *)varp - value;
4751 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004752 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004753 }
4754 else if (opt_idx >= 0) /* string */
4755 {
4756 char_u *save_arg = NULL;
4757 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004758 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004759 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004760 char_u *origval = NULL;
4761#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4762 char_u *saved_origval = NULL;
4763#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004764 unsigned newlen;
4765 int comma;
4766 int bs;
4767 int new_value_alloced; /* new string option
4768 was allocated */
4769
4770 /* When using ":set opt=val" for a global option
4771 * with a local value the local value will be
4772 * reset, use the global value here. */
4773 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004774 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004775 varp = options[opt_idx].var;
4776
4777 /* The old value is kept until we are sure that the
4778 * new value is valid. */
4779 oldval = *(char_u **)varp;
4780 if (nextchar == '&') /* set to default val */
4781 {
4782 newval = options[opt_idx].def_val[
4783 ((flags & P_VI_DEF) || cp_val)
4784 ? VI_DEFAULT : VIM_DEFAULT];
4785 if ((char_u **)varp == &p_bg)
4786 {
4787 /* guess the value of 'background' */
4788#ifdef FEAT_GUI
4789 if (gui.in_use)
4790 newval = gui_bg_default();
4791 else
4792#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004793 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004794 }
4795
4796 /* expand environment variables and ~ (since the
4797 * default value was already expanded, only
4798 * required when an environment variable was set
4799 * later */
4800 if (newval == NULL)
4801 newval = empty_option;
4802 else
4803 {
4804 s = option_expand(opt_idx, newval);
4805 if (s == NULL)
4806 s = newval;
4807 newval = vim_strsave(s);
4808 }
4809 new_value_alloced = TRUE;
4810 }
4811 else if (nextchar == '<') /* set to global val */
4812 {
4813 newval = vim_strsave(*(char_u **)get_varp_scope(
4814 &(options[opt_idx]), OPT_GLOBAL));
4815 new_value_alloced = TRUE;
4816 }
4817 else
4818 {
4819 ++arg; /* jump to after the '=' or ':' */
4820
4821 /*
4822 * Set 'keywordprg' to ":help" if an empty
4823 * value was passed to :set by the user.
4824 * Misuse errbuf[] for the resulting string.
4825 */
4826 if (varp == (char_u *)&p_kp
4827 && (*arg == NUL || *arg == ' '))
4828 {
4829 STRCPY(errbuf, ":help");
4830 save_arg = arg;
4831 arg = errbuf;
4832 }
4833 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004834 * Convert 'backspace' number to string, for
4835 * adding, prepending and removing string.
4836 */
4837 else if (varp == (char_u *)&p_bs
4838 && VIM_ISDIGIT(**(char_u **)varp))
4839 {
4840 i = getdigits((char_u **)varp);
4841 switch (i)
4842 {
4843 case 0:
4844 *(char_u **)varp = empty_option;
4845 break;
4846 case 1:
4847 *(char_u **)varp = vim_strsave(
4848 (char_u *)"indent,eol");
4849 break;
4850 case 2:
4851 *(char_u **)varp = vim_strsave(
4852 (char_u *)"indent,eol,start");
4853 break;
4854 }
4855 vim_free(oldval);
4856 oldval = *(char_u **)varp;
4857 }
4858 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004859 * Convert 'whichwrap' number to string, for
4860 * backwards compatibility with Vim 3.0.
4861 * Misuse errbuf[] for the resulting string.
4862 */
4863 else if (varp == (char_u *)&p_ww
4864 && VIM_ISDIGIT(*arg))
4865 {
4866 *errbuf = NUL;
4867 i = getdigits(&arg);
4868 if (i & 1)
4869 STRCAT(errbuf, "b,");
4870 if (i & 2)
4871 STRCAT(errbuf, "s,");
4872 if (i & 4)
4873 STRCAT(errbuf, "h,l,");
4874 if (i & 8)
4875 STRCAT(errbuf, "<,>,");
4876 if (i & 16)
4877 STRCAT(errbuf, "[,],");
4878 if (*errbuf != NUL) /* remove trailing , */
4879 errbuf[STRLEN(errbuf) - 1] = NUL;
4880 save_arg = arg;
4881 arg = errbuf;
4882 }
4883 /*
4884 * Remove '>' before 'dir' and 'bdir', for
4885 * backwards compatibility with version 3.0
4886 */
4887 else if ( *arg == '>'
4888 && (varp == (char_u *)&p_dir
4889 || varp == (char_u *)&p_bdir))
4890 {
4891 ++arg;
4892 }
4893
4894 /* When setting the local value of a global
4895 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004896 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004897 && (opt_flags & OPT_LOCAL))
4898 origval = *(char_u **)get_varp(
4899 &options[opt_idx]);
4900 else
4901 origval = oldval;
4902
4903 /*
4904 * Copy the new string into allocated memory.
4905 * Can't use set_string_option_direct(), because
4906 * we need to remove the backslashes.
4907 */
4908 /* get a bit too much */
4909 newlen = (unsigned)STRLEN(arg) + 1;
4910 if (adding || prepending || removing)
4911 newlen += (unsigned)STRLEN(origval) + 1;
4912 newval = alloc(newlen);
4913 if (newval == NULL) /* out of mem, don't change */
4914 break;
4915 s = newval;
4916
4917 /*
4918 * Copy the string, skip over escaped chars.
4919 * For MS-DOS and WIN32 backslashes before normal
4920 * file name characters are not removed, and keep
4921 * backslash at start, for "\\machine\path", but
4922 * do remove it for "\\\\machine\\path".
4923 * The reverse is found in ExpandOldSetting().
4924 */
4925 while (*arg && !vim_iswhite(*arg))
4926 {
4927 if (*arg == '\\' && arg[1] != NUL
4928#ifdef BACKSLASH_IN_FILENAME
4929 && !((flags & P_EXPAND)
4930 && vim_isfilec(arg[1])
4931 && (arg[1] != '\\'
4932 || (s == newval
4933 && arg[2] != '\\')))
4934#endif
4935 )
4936 ++arg; /* remove backslash */
4937#ifdef FEAT_MBYTE
4938 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004939 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004940 {
4941 /* copy multibyte char */
4942 mch_memmove(s, arg, (size_t)i);
4943 arg += i;
4944 s += i;
4945 }
4946 else
4947#endif
4948 *s++ = *arg++;
4949 }
4950 *s = NUL;
4951
4952 /*
4953 * Expand environment variables and ~.
4954 * Don't do it when adding without inserting a
4955 * comma.
4956 */
4957 if (!(adding || prepending || removing)
4958 || (flags & P_COMMA))
4959 {
4960 s = option_expand(opt_idx, newval);
4961 if (s != NULL)
4962 {
4963 vim_free(newval);
4964 newlen = (unsigned)STRLEN(s) + 1;
4965 if (adding || prepending || removing)
4966 newlen += (unsigned)STRLEN(origval) + 1;
4967 newval = alloc(newlen);
4968 if (newval == NULL)
4969 break;
4970 STRCPY(newval, s);
4971 }
4972 }
4973
4974 /* locate newval[] in origval[] when removing it
4975 * and when adding to avoid duplicates */
4976 i = 0; /* init for GCC */
4977 if (removing || (flags & P_NODUP))
4978 {
4979 i = (int)STRLEN(newval);
4980 bs = 0;
4981 for (s = origval; *s; ++s)
4982 {
4983 if ((!(flags & P_COMMA)
4984 || s == origval
4985 || (s[-1] == ',' && !(bs & 1)))
4986 && STRNCMP(s, newval, i) == 0
4987 && (!(flags & P_COMMA)
4988 || s[i] == ','
4989 || s[i] == NUL))
4990 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004991 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004992 * even number of backslashes or a single
4993 * backslash preceded by a comma before it
4994 * is recognized as a separator */
4995 if ((s > origval + 1
4996 && s[-1] == '\\'
4997 && s[-2] != ',')
4998 || (s == origval + 1
4999 && s[-1] == '\\'))
5000
Bram Moolenaar071d4272004-06-13 20:20:40 +00005001 ++bs;
5002 else
5003 bs = 0;
5004 }
5005
5006 /* do not add if already there */
5007 if ((adding || prepending) && *s)
5008 {
5009 prepending = FALSE;
5010 adding = FALSE;
5011 STRCPY(newval, origval);
5012 }
5013 }
5014
5015 /* concatenate the two strings; add a ',' if
5016 * needed */
5017 if (adding || prepending)
5018 {
5019 comma = ((flags & P_COMMA) && *origval != NUL
5020 && *newval != NUL);
5021 if (adding)
5022 {
5023 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005024 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005025 if (comma && i > 1
5026 && (flags & P_ONECOMMA) == P_ONECOMMA
5027 && origval[i - 1] == ','
5028 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005029 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005030 mch_memmove(newval + i + comma, newval,
5031 STRLEN(newval) + 1);
5032 mch_memmove(newval, origval, (size_t)i);
5033 }
5034 else
5035 {
5036 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005037 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005038 }
5039 if (comma)
5040 newval[i] = ',';
5041 }
5042
5043 /* Remove newval[] from origval[]. (Note: "i" has
5044 * been set above and is used here). */
5045 if (removing)
5046 {
5047 STRCPY(newval, origval);
5048 if (*s)
5049 {
5050 /* may need to remove a comma */
5051 if (flags & P_COMMA)
5052 {
5053 if (s == origval)
5054 {
5055 /* include comma after string */
5056 if (s[i] == ',')
5057 ++i;
5058 }
5059 else
5060 {
5061 /* include comma before string */
5062 --s;
5063 ++i;
5064 }
5065 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005066 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005067 }
5068 }
5069
5070 if (flags & P_FLAGLIST)
5071 {
5072 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005073 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005074 {
5075 /* if options have P_FLAGLIST and
5076 * P_ONECOMMA such as 'whichwrap' */
5077 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005078 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005079 if (*s != ',' && *(s + 1) == ','
5080 && vim_strchr(s + 2, *s) != NULL)
5081 {
5082 /* Remove the duplicated value and
5083 * the next comma. */
5084 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005085 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005086 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005087 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005088 else
5089 {
5090 if ((!(flags & P_COMMA) || *s != ',')
5091 && vim_strchr(s + 1, *s) != NULL)
5092 {
5093 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005094 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005095 }
5096 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005097 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005098 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005099 }
5100
5101 if (save_arg != NULL) /* number for 'whichwrap' */
5102 arg = save_arg;
5103 new_value_alloced = TRUE;
5104 }
5105
5106 /* Set the new value. */
5107 *(char_u **)(varp) = newval;
5108
Bram Moolenaar53744302015-07-17 17:38:22 +02005109#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005110 if (!starting
5111# ifdef FEAT_CRYPT
5112 && options[opt_idx].indir != PV_KEY
5113# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02005114 && origval != NULL)
5115 /* origval may be freed by
5116 * did_set_string_option(), make a copy. */
5117 saved_origval = vim_strsave(origval);
5118#endif
5119
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120 /* Handle side effects, and set the global value for
5121 * ":set" on local options. */
5122 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5123 new_value_alloced, oldval, errbuf, opt_flags);
5124
5125 /* If error detected, print the error message. */
5126 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005127 {
5128#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5129 vim_free(saved_origval);
5130#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005131 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005132 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005133#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5134 if (saved_origval != NULL)
5135 {
5136 char_u buf_type[7];
5137
5138 sprintf((char *)buf_type, "%s",
5139 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005140 set_vim_var_string(VV_OPTION_NEW,
5141 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005142 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5143 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5144 apply_autocmds(EVENT_OPTIONSET,
5145 (char_u *)options[opt_idx].fullname,
5146 NULL, FALSE, NULL);
5147 reset_v_option_vars();
5148 vim_free(saved_origval);
5149 }
5150#endif
5151
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152 }
5153 else /* key code option */
5154 {
5155 char_u *p;
5156
5157 if (nextchar == '&')
5158 {
5159 if (add_termcap_entry(key_name, TRUE) == FAIL)
5160 errmsg = (char_u *)N_("E522: Not found in termcap");
5161 }
5162 else
5163 {
5164 ++arg; /* jump to after the '=' or ':' */
5165 for (p = arg; *p && !vim_iswhite(*p); ++p)
5166 if (*p == '\\' && p[1] != NUL)
5167 ++p;
5168 nextchar = *p;
5169 *p = NUL;
5170 add_termcode(key_name, arg, FALSE);
5171 *p = nextchar;
5172 }
5173 if (full_screen)
5174 ttest(FALSE);
5175 redraw_all_later(CLEAR);
5176 }
5177 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005178
Bram Moolenaar071d4272004-06-13 20:20:40 +00005179 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005180 did_set_option(opt_idx, opt_flags,
5181 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005182 }
5183
5184skip:
5185 /*
5186 * Advance to next argument.
5187 * - skip until a blank found, taking care of backslashes
5188 * - skip blanks
5189 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5190 */
5191 for (i = 0; i < 2 ; ++i)
5192 {
5193 while (*arg != NUL && !vim_iswhite(*arg))
5194 if (*arg++ == '\\' && *arg != NUL)
5195 ++arg;
5196 arg = skipwhite(arg);
5197 if (*arg != '=')
5198 break;
5199 }
5200 }
5201
5202 if (errmsg != NULL)
5203 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005204 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005205 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005206 if (i + (arg - startarg) < IOSIZE)
5207 {
5208 /* append the argument with the error */
5209 STRCAT(IObuff, ": ");
5210 mch_memmove(IObuff + i, startarg, (arg - startarg));
5211 IObuff[i + (arg - startarg)] = NUL;
5212 }
5213 /* make sure all characters are printable */
5214 trans_characters(IObuff, IOSIZE);
5215
5216 ++no_wait_return; /* wait_return done later */
5217 emsg(IObuff); /* show error highlighted */
5218 --no_wait_return;
5219
5220 return FAIL;
5221 }
5222
5223 arg = skipwhite(arg);
5224 }
5225
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005226theend:
5227 if (silent_mode && did_show)
5228 {
5229 /* After displaying option values in silent mode. */
5230 silent_mode = FALSE;
5231 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5232 msg_putchar('\n');
5233 cursor_on(); /* msg_start() switches it off */
5234 out_flush();
5235 silent_mode = TRUE;
5236 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5237 }
5238
Bram Moolenaar071d4272004-06-13 20:20:40 +00005239 return OK;
5240}
5241
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005242/*
5243 * Call this when an option has been given a new value through a user command.
5244 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5245 */
5246 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005247did_set_option(
5248 int opt_idx,
5249 int opt_flags, /* possibly with OPT_MODELINE */
5250 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005251{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005252 long_u *p;
5253
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005254 options[opt_idx].flags |= P_WAS_SET;
5255
5256 /* When an option is set in the sandbox, from a modeline or in secure mode
5257 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005258 * flag. */
5259 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005260 if (secure
5261#ifdef HAVE_SANDBOX
5262 || sandbox != 0
5263#endif
5264 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005265 *p = *p | P_INSECURE;
5266 else if (new_value)
5267 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005268}
5269
Bram Moolenaar071d4272004-06-13 20:20:40 +00005270 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005271illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005272{
5273 if (errbuf == NULL)
5274 return (char_u *)"";
5275 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005276 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005277 return errbuf;
5278}
5279
5280/*
5281 * Convert a key name or string into a key value.
5282 * Used for 'wildchar' and 'cedit' options.
5283 */
5284 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005285string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005286{
5287 if (*arg == '<')
5288 return find_key_option(arg + 1);
5289 if (*arg == '^')
5290 return Ctrl_chr(arg[1]);
5291 return *arg;
5292}
5293
5294#ifdef FEAT_CMDWIN
5295/*
5296 * Check value of 'cedit' and set cedit_key.
5297 * Returns NULL if value is OK, error message otherwise.
5298 */
5299 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005300check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005301{
5302 int n;
5303
5304 if (*p_cedit == NUL)
5305 cedit_key = -1;
5306 else
5307 {
5308 n = string_to_key(p_cedit);
5309 if (vim_isprintc(n))
5310 return e_invarg;
5311 cedit_key = n;
5312 }
5313 return NULL;
5314}
5315#endif
5316
5317#ifdef FEAT_TITLE
5318/*
5319 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5320 * maketitle() to create and display it.
5321 * When switching the title or icon off, call mch_restore_title() to get
5322 * the old value back.
5323 */
5324 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005325did_set_title(
5326 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327{
5328 if (starting != NO_SCREEN
5329#ifdef FEAT_GUI
5330 && !gui.starting
5331#endif
5332 )
5333 {
5334 maketitle();
5335 if (icon)
5336 {
5337 if (!p_icon)
5338 mch_restore_title(2);
5339 }
5340 else
5341 {
5342 if (!p_title)
5343 mch_restore_title(1);
5344 }
5345 }
5346}
5347#endif
5348
5349/*
5350 * set_options_bin - called when 'bin' changes value.
5351 */
5352 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005353set_options_bin(
5354 int oldval,
5355 int newval,
5356 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357{
5358 /*
5359 * The option values that are changed when 'bin' changes are
5360 * copied when 'bin is set and restored when 'bin' is reset.
5361 */
5362 if (newval)
5363 {
5364 if (!oldval) /* switched on */
5365 {
5366 if (!(opt_flags & OPT_GLOBAL))
5367 {
5368 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5369 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5370 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5371 curbuf->b_p_et_nobin = curbuf->b_p_et;
5372 }
5373 if (!(opt_flags & OPT_LOCAL))
5374 {
5375 p_tw_nobin = p_tw;
5376 p_wm_nobin = p_wm;
5377 p_ml_nobin = p_ml;
5378 p_et_nobin = p_et;
5379 }
5380 }
5381
5382 if (!(opt_flags & OPT_GLOBAL))
5383 {
5384 curbuf->b_p_tw = 0; /* no automatic line wrap */
5385 curbuf->b_p_wm = 0; /* no automatic line wrap */
5386 curbuf->b_p_ml = 0; /* no modelines */
5387 curbuf->b_p_et = 0; /* no expandtab */
5388 }
5389 if (!(opt_flags & OPT_LOCAL))
5390 {
5391 p_tw = 0;
5392 p_wm = 0;
5393 p_ml = FALSE;
5394 p_et = FALSE;
5395 p_bin = TRUE; /* needed when called for the "-b" argument */
5396 }
5397 }
5398 else if (oldval) /* switched off */
5399 {
5400 if (!(opt_flags & OPT_GLOBAL))
5401 {
5402 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5403 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5404 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5405 curbuf->b_p_et = curbuf->b_p_et_nobin;
5406 }
5407 if (!(opt_flags & OPT_LOCAL))
5408 {
5409 p_tw = p_tw_nobin;
5410 p_wm = p_wm_nobin;
5411 p_ml = p_ml_nobin;
5412 p_et = p_et_nobin;
5413 }
5414 }
5415}
5416
5417#ifdef FEAT_VIMINFO
5418/*
5419 * Find the parameter represented by the given character (eg ', :, ", or /),
5420 * and return its associated value in the 'viminfo' string.
5421 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005422 * If the parameter is not specified in the string or there is no following
5423 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005424 */
5425 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005426get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005427{
5428 char_u *p;
5429
5430 p = find_viminfo_parameter(type);
5431 if (p != NULL && VIM_ISDIGIT(*p))
5432 return atoi((char *)p);
5433 return -1;
5434}
5435
5436/*
5437 * Find the parameter represented by the given character (eg ''', ':', '"', or
5438 * '/') in the 'viminfo' option and return a pointer to the string after it.
5439 * Return NULL if the parameter is not specified in the string.
5440 */
5441 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005442find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005443{
5444 char_u *p;
5445
5446 for (p = p_viminfo; *p; ++p)
5447 {
5448 if (*p == type)
5449 return p + 1;
5450 if (*p == 'n') /* 'n' is always the last one */
5451 break;
5452 p = vim_strchr(p, ','); /* skip until next ',' */
5453 if (p == NULL) /* hit the end without finding parameter */
5454 break;
5455 }
5456 return NULL;
5457}
5458#endif
5459
5460/*
5461 * Expand environment variables for some string options.
5462 * These string options cannot be indirect!
5463 * If "val" is NULL expand the current value of the option.
5464 * Return pointer to NameBuff, or NULL when not expanded.
5465 */
5466 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005467option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005468{
5469 /* if option doesn't need expansion nothing to do */
5470 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5471 return NULL;
5472
5473 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5474 * expand_env() would truncate the string. */
5475 if (val != NULL && STRLEN(val) > MAXPATHL)
5476 return NULL;
5477
5478 if (val == NULL)
5479 val = *(char_u **)options[opt_idx].var;
5480
5481 /*
5482 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5483 * Escape spaces when expanding 'tags', they are used to separate file
5484 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005485 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005486 */
5487 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005488 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005489#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005490 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5491#endif
5492 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005493 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5494 return NULL;
5495
5496 return NameBuff;
5497}
5498
5499/*
5500 * After setting various option values: recompute variables that depend on
5501 * option values.
5502 */
5503 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005504didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005505{
5506 /* initialize the table for 'iskeyword' et.al. */
5507 (void)init_chartab();
5508
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005509#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005510 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005511#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005512 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005513 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005514#ifdef FEAT_SESSION
5515 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5516 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5517#endif
5518#ifdef FEAT_FOLDING
5519 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5520#endif
5521 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005522 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005523#ifdef FEAT_VIRTUALEDIT
5524 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5525#endif
5526#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5527 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5528#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005529#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005530 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005531 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005532 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005533 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5536 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5537#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005538#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5540#endif
5541#ifdef FEAT_CMDWIN
5542 /* set cedit_key */
5543 (void)check_cedit();
5544#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005545#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005546 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005547#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005548#ifdef FEAT_LINEBREAK
5549 /* initialize the table for 'breakat'. */
5550 fill_breakat_flags();
5551#endif
5552
5553}
5554
5555/*
5556 * More side effects of setting options.
5557 */
5558 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005559didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005560{
5561 /* Initialize the highlight_attr[] table. */
5562 (void)highlight_changed();
5563
5564 /* Parse default for 'wildmode' */
5565 check_opt_wim();
5566
5567 (void)set_chars_option(&p_lcs);
5568#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5569 /* Parse default for 'fillchars'. */
5570 (void)set_chars_option(&p_fcs);
5571#endif
5572
5573#ifdef FEAT_CLIPBOARD
5574 /* Parse default for 'clipboard' */
5575 (void)check_clipboard_option();
5576#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577}
5578
5579/*
5580 * Check for string options that are NULL (normally only termcap options).
5581 */
5582 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005583check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584{
5585 int opt_idx;
5586
5587 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5588 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5589 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5590}
5591
5592/*
5593 * Check string options in a buffer for NULL value.
5594 */
5595 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005596check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005597{
5598#if defined(FEAT_QUICKFIX)
5599 check_string_option(&buf->b_p_bh);
5600 check_string_option(&buf->b_p_bt);
5601#endif
5602#ifdef FEAT_MBYTE
5603 check_string_option(&buf->b_p_fenc);
5604#endif
5605 check_string_option(&buf->b_p_ff);
5606#ifdef FEAT_FIND_ID
5607 check_string_option(&buf->b_p_def);
5608 check_string_option(&buf->b_p_inc);
5609# ifdef FEAT_EVAL
5610 check_string_option(&buf->b_p_inex);
5611# endif
5612#endif
5613#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5614 check_string_option(&buf->b_p_inde);
5615 check_string_option(&buf->b_p_indk);
5616#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005617#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5618 check_string_option(&buf->b_p_bexpr);
5619#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005620#if defined(FEAT_CRYPT)
5621 check_string_option(&buf->b_p_cm);
5622#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005623 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005624#if defined(FEAT_EVAL)
5625 check_string_option(&buf->b_p_fex);
5626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005627#ifdef FEAT_CRYPT
5628 check_string_option(&buf->b_p_key);
5629#endif
5630 check_string_option(&buf->b_p_kp);
5631 check_string_option(&buf->b_p_mps);
5632 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005633 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005634 check_string_option(&buf->b_p_isk);
5635#ifdef FEAT_COMMENTS
5636 check_string_option(&buf->b_p_com);
5637#endif
5638#ifdef FEAT_FOLDING
5639 check_string_option(&buf->b_p_cms);
5640#endif
5641 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005642#ifdef FEAT_TEXTOBJ
5643 check_string_option(&buf->b_p_qe);
5644#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645#ifdef FEAT_SYN_HL
5646 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005647 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005648#endif
5649#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005650 check_string_option(&buf->b_s.b_p_spc);
5651 check_string_option(&buf->b_s.b_p_spf);
5652 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005653#endif
5654#ifdef FEAT_SEARCHPATH
5655 check_string_option(&buf->b_p_sua);
5656#endif
5657#ifdef FEAT_CINDENT
5658 check_string_option(&buf->b_p_cink);
5659 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005660 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661#endif
5662#ifdef FEAT_AUTOCMD
5663 check_string_option(&buf->b_p_ft);
5664#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5666 check_string_option(&buf->b_p_cinw);
5667#endif
5668#ifdef FEAT_INS_EXPAND
5669 check_string_option(&buf->b_p_cpt);
5670#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005671#ifdef FEAT_COMPL_FUNC
5672 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005673 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005674#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005675#ifdef FEAT_KEYMAP
5676 check_string_option(&buf->b_p_keymap);
5677#endif
5678#ifdef FEAT_QUICKFIX
5679 check_string_option(&buf->b_p_gp);
5680 check_string_option(&buf->b_p_mp);
5681 check_string_option(&buf->b_p_efm);
5682#endif
5683 check_string_option(&buf->b_p_ep);
5684 check_string_option(&buf->b_p_path);
5685 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005686 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005687#ifdef FEAT_INS_EXPAND
5688 check_string_option(&buf->b_p_dict);
5689 check_string_option(&buf->b_p_tsr);
5690#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005691#ifdef FEAT_LISP
5692 check_string_option(&buf->b_p_lw);
5693#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005694 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005695#ifdef FEAT_MBYTE
5696 check_string_option(&buf->b_p_menc);
5697#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698}
5699
5700/*
5701 * Free the string allocated for an option.
5702 * Checks for the string being empty_option. This may happen if we're out of
5703 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5704 * check_options().
5705 * Does NOT check for P_ALLOCED flag!
5706 */
5707 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005708free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709{
5710 if (p != empty_option)
5711 vim_free(p);
5712}
5713
5714 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005715clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005716{
5717 if (*pp != empty_option)
5718 vim_free(*pp);
5719 *pp = empty_option;
5720}
5721
5722 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005723check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005724{
5725 if (*pp == NULL)
5726 *pp = empty_option;
5727}
5728
5729/*
5730 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5731 */
5732 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005733set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005734{
5735 int opt_idx;
5736
5737 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5738 if (options[opt_idx].var == (char_u *)p)
5739 {
5740 options[opt_idx].flags |= P_ALLOCED;
5741 return;
5742 }
5743 return; /* cannot happen: didn't find it! */
5744}
5745
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005746#if defined(FEAT_EVAL) || defined(PROTO)
5747/*
5748 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5749 * Return FALSE when it wasn't.
5750 * Return -1 for an unknown option.
5751 */
5752 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005753was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005754{
5755 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005756 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005757
5758 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005759 {
5760 flagp = insecure_flag(idx, opt_flags);
5761 return (*flagp & P_INSECURE) != 0;
5762 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005763 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005764 return -1;
5765}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005766
5767/*
5768 * Get a pointer to the flags used for the P_INSECURE flag of option
5769 * "opt_idx". For some local options a local flags field is used.
5770 */
5771 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005772insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005773{
5774 if (opt_flags & OPT_LOCAL)
5775 switch ((int)options[opt_idx].indir)
5776 {
5777#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005778 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005779#endif
5780#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005781# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005782 case PV_FDE: return &curwin->w_p_fde_flags;
5783 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005784# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005785# ifdef FEAT_BEVAL
5786 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5787# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005788# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005789 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005790# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005791 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005792# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005793 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005794# endif
5795#endif
5796 }
5797
5798 /* Nothing special, return global flags field. */
5799 return &options[opt_idx].flags;
5800}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005801#endif
5802
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005803#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005804static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005805
5806/*
5807 * Redraw the window title and/or tab page text later.
5808 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005809static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005810{
5811 need_maketitle = TRUE;
5812# ifdef FEAT_WINDOWS
5813 redraw_tabline = TRUE;
5814# endif
5815}
5816#endif
5817
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818/*
5819 * Set a string option to a new value (without checking the effect).
5820 * The string is copied into allocated memory.
5821 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005822 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005823 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005824 */
5825 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005826set_string_option_direct(
5827 char_u *name,
5828 int opt_idx,
5829 char_u *val,
5830 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5831 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005832{
5833 char_u *s;
5834 char_u **varp;
5835 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005836 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837
Bram Moolenaar89d40322006-08-29 15:30:07 +00005838 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005839 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005840 idx = findoption(name);
5841 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005842 {
5843 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005844 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005846 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 }
5848
Bram Moolenaar89d40322006-08-29 15:30:07 +00005849 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005850 return;
5851
5852 s = vim_strsave(val);
5853 if (s != NULL)
5854 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005855 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005857 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858 free_string_option(*varp);
5859 *varp = s;
5860
5861 /* For buffer/window local option may also set the global value. */
5862 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005863 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864
Bram Moolenaar89d40322006-08-29 15:30:07 +00005865 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866
5867 /* When setting both values of a global option with a local value,
5868 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005869 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870 {
5871 free_string_option(*varp);
5872 *varp = empty_option;
5873 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005874# ifdef FEAT_EVAL
5875 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005876 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005877 set_sid == 0 ? current_SID : set_sid);
5878# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879 }
5880}
5881
5882/*
5883 * Set global value for string option when it's a local option.
5884 */
5885 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005886set_string_option_global(
5887 int opt_idx, /* option index */
5888 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889{
5890 char_u **p, *s;
5891
5892 /* the global value is always allocated */
5893 if (options[opt_idx].var == VAR_WIN)
5894 p = (char_u **)GLOBAL_WO(varp);
5895 else
5896 p = (char_u **)options[opt_idx].var;
5897 if (options[opt_idx].indir != PV_NONE
5898 && p != varp
5899 && (s = vim_strsave(*varp)) != NULL)
5900 {
5901 free_string_option(*p);
5902 *p = s;
5903 }
5904}
5905
5906/*
5907 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005908 *
5909 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005911 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005912set_string_option(
5913 int opt_idx,
5914 char_u *value,
5915 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916{
5917 char_u *s;
5918 char_u **varp;
5919 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005920#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5921 char_u *saved_oldval = NULL;
5922#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005923 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924
5925 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005926 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927
5928 s = vim_strsave(value);
5929 if (s != NULL)
5930 {
5931 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5932 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005933 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934 ? OPT_GLOBAL : OPT_LOCAL)
5935 : opt_flags);
5936 oldval = *varp;
5937 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005938
5939#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005940 if (!starting
5941# ifdef FEAT_CRYPT
5942 && options[opt_idx].indir != PV_KEY
5943# endif
5944 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005945 saved_oldval = vim_strsave(oldval);
5946#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005947 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5948 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005949 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005950
Bram Moolenaara12e4032017-02-25 21:37:57 +01005951 /* call autocommand after handling side effects */
Bram Moolenaar53744302015-07-17 17:38:22 +02005952#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5953 if (saved_oldval != NULL)
5954 {
5955 char_u buf_type[7];
5956 sprintf((char *)buf_type, "%s",
5957 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005958 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5959 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005960 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5961 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5962 reset_v_option_vars();
5963 vim_free(saved_oldval);
5964 }
5965#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005967 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005968}
5969
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005970#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005971/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005972 * Return TRUE if "val" is a valid 'filetype' name.
5973 * Also used for 'syntax' and 'keymap'.
5974 */
5975 static int
5976valid_filetype(char_u *val)
5977{
5978 char_u *s;
5979
5980 for (s = val; *s != NUL; ++s)
5981 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5982 return FALSE;
5983 return TRUE;
5984}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005985#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005986
5987/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005988 * Handle string options that need some action to perform when changed.
5989 * Returns NULL for success, or an error message for an error.
5990 */
5991 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005992did_set_string_option(
5993 int opt_idx, /* index in options[] table */
5994 char_u **varp, /* pointer to the option variable */
5995 int new_value_alloced, /* new value was allocated */
5996 char_u *oldval, /* previous value of the option */
5997 char_u *errbuf, /* buffer for errors, or NULL */
5998 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999{
6000 char_u *errmsg = NULL;
6001 char_u *s, *p;
6002 int did_chartab = FALSE;
6003 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006004 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006005#ifdef FEAT_GUI
6006 /* set when changing an option that only requires a redraw in the GUI */
6007 int redraw_gui_only = FALSE;
6008#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006009
6010 /* Get the global option to compare with, otherwise we would have to check
6011 * two values for all local options. */
6012 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6013
6014 /* Disallow changing some options from secure mode */
6015 if ((secure
6016#ifdef HAVE_SANDBOX
6017 || sandbox != 0
6018#endif
6019 ) && (options[opt_idx].flags & P_SECURE))
6020 {
6021 errmsg = e_secure;
6022 }
6023
Bram Moolenaar7554da42016-11-25 22:04:13 +01006024 /* Check for a "normal" directory or file name in some options. Disallow a
6025 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006026 * are often illegal in a file name. Be more permissive if "secure" is off.
6027 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006028 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006029 && vim_strpbrk(*varp, (char_u *)(secure
6030 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006031 || ((options[opt_idx].flags & P_NDNAME)
6032 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006033 {
6034 errmsg = e_invarg;
6035 }
6036
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037 /* 'term' */
6038 else if (varp == &T_NAME)
6039 {
6040 if (T_NAME[0] == NUL)
6041 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6042#ifdef FEAT_GUI
6043 if (gui.in_use)
6044 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6045 else if (term_is_gui(T_NAME))
6046 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6047#endif
6048 else if (set_termname(T_NAME) == FAIL)
6049 errmsg = (char_u *)N_("E522: Not found in termcap");
6050 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006051 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006052 /* Screen colors may have changed. */
6053 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006054
6055 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6056 * P_ALLOCED flag on 'term'. */
6057 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006058 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006059 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006060 }
6061
6062 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006063 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006064 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006065 char_u *bkc = p_bkc;
6066 unsigned int *flags = &bkc_flags;
6067
6068 if (opt_flags & OPT_LOCAL)
6069 {
6070 bkc = curbuf->b_p_bkc;
6071 flags = &curbuf->b_bkc_flags;
6072 }
6073
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006074 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6075 /* make the local value empty: use the global value */
6076 *flags = 0;
6077 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006078 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006079 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6080 errmsg = e_invarg;
6081 if ((((int)*flags & BKC_AUTO) != 0)
6082 + (((int)*flags & BKC_YES) != 0)
6083 + (((int)*flags & BKC_NO) != 0) != 1)
6084 {
6085 /* Must have exactly one of "auto", "yes" and "no". */
6086 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6087 errmsg = e_invarg;
6088 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006089 }
6090 }
6091
6092 /* 'backupext' and 'patchmode' */
6093 else if (varp == &p_bex || varp == &p_pm)
6094 {
6095 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6096 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6097 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6098 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006099#ifdef FEAT_LINEBREAK
6100 /* 'breakindentopt' */
6101 else if (varp == &curwin->w_p_briopt)
6102 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006103 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006104 errmsg = e_invarg;
6105 }
6106#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107
6108 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006109 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006111 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 */
6113 else if ( varp == &p_isi
6114 || varp == &(curbuf->b_p_isk)
6115 || varp == &p_isp
6116 || varp == &p_isf)
6117 {
6118 if (init_chartab() == FAIL)
6119 {
6120 did_chartab = TRUE; /* need to restore it below */
6121 errmsg = e_invarg; /* error in value */
6122 }
6123 }
6124
6125 /* 'helpfile' */
6126 else if (varp == &p_hf)
6127 {
6128 /* May compute new values for $VIM and $VIMRUNTIME */
6129 if (didset_vim)
6130 {
6131 vim_setenv((char_u *)"VIM", (char_u *)"");
6132 didset_vim = FALSE;
6133 }
6134 if (didset_vimruntime)
6135 {
6136 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6137 didset_vimruntime = FALSE;
6138 }
6139 }
6140
Bram Moolenaar1a384422010-07-14 19:53:30 +02006141#ifdef FEAT_SYN_HL
6142 /* 'colorcolumn' */
6143 else if (varp == &curwin->w_p_cc)
6144 errmsg = check_colorcolumn(curwin);
6145#endif
6146
Bram Moolenaar071d4272004-06-13 20:20:40 +00006147#ifdef FEAT_MULTI_LANG
6148 /* 'helplang' */
6149 else if (varp == &p_hlg)
6150 {
6151 /* Check for "", "ab", "ab,cd", etc. */
6152 for (s = p_hlg; *s != NUL; s += 3)
6153 {
6154 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6155 {
6156 errmsg = e_invarg;
6157 break;
6158 }
6159 if (s[2] == NUL)
6160 break;
6161 }
6162 }
6163#endif
6164
6165 /* 'highlight' */
6166 else if (varp == &p_hl)
6167 {
6168 if (highlight_changed() == FAIL)
6169 errmsg = e_invarg; /* invalid flags */
6170 }
6171
6172 /* 'nrformats' */
6173 else if (gvarp == &p_nf)
6174 {
6175 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6176 errmsg = e_invarg;
6177 }
6178
6179#ifdef FEAT_SESSION
6180 /* 'sessionoptions' */
6181 else if (varp == &p_ssop)
6182 {
6183 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6184 errmsg = e_invarg;
6185 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6186 {
6187 /* Don't allow both "sesdir" and "curdir". */
6188 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6189 errmsg = e_invarg;
6190 }
6191 }
6192 /* 'viewoptions' */
6193 else if (varp == &p_vop)
6194 {
6195 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6196 errmsg = e_invarg;
6197 }
6198#endif
6199
6200 /* 'scrollopt' */
6201#ifdef FEAT_SCROLLBIND
6202 else if (varp == &p_sbo)
6203 {
6204 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6205 errmsg = e_invarg;
6206 }
6207#endif
6208
6209 /* 'ambiwidth' */
6210#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006211 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212 {
6213 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6214 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006215 else if (set_chars_option(&p_lcs) != NULL)
6216 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6217# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6218 else if (set_chars_option(&p_fcs) != NULL)
6219 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6220# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006221 }
6222#endif
6223
6224 /* 'background' */
6225 else if (varp == &p_bg)
6226 {
6227 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6228 {
6229#ifdef FEAT_EVAL
6230 int dark = (*p_bg == 'd');
6231#endif
6232
6233 init_highlight(FALSE, FALSE);
6234
6235#ifdef FEAT_EVAL
6236 if (dark != (*p_bg == 'd')
6237 && get_var_value((char_u *)"g:colors_name") != NULL)
6238 {
6239 /* The color scheme must have set 'background' back to another
6240 * value, that's not what we want here. Disable the color
6241 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006242 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006243 free_string_option(p_bg);
6244 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6245 check_string_option(&p_bg);
6246 init_highlight(FALSE, FALSE);
6247 }
6248#endif
6249 }
6250 else
6251 errmsg = e_invarg;
6252 }
6253
6254 /* 'wildmode' */
6255 else if (varp == &p_wim)
6256 {
6257 if (check_opt_wim() == FAIL)
6258 errmsg = e_invarg;
6259 }
6260
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006261#ifdef FEAT_CMDL_COMPL
6262 /* 'wildoptions' */
6263 else if (varp == &p_wop)
6264 {
6265 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6266 errmsg = e_invarg;
6267 }
6268#endif
6269
Bram Moolenaar071d4272004-06-13 20:20:40 +00006270#ifdef FEAT_WAK
6271 /* 'winaltkeys' */
6272 else if (varp == &p_wak)
6273 {
6274 if (*p_wak == NUL
6275 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6276 errmsg = e_invarg;
6277# ifdef FEAT_MENU
6278# ifdef FEAT_GUI_MOTIF
6279 else if (gui.in_use)
6280 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6281# else
6282# ifdef FEAT_GUI_GTK
6283 else if (gui.in_use)
6284 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6285# endif
6286# endif
6287# endif
6288 }
6289#endif
6290
6291#ifdef FEAT_AUTOCMD
6292 /* 'eventignore' */
6293 else if (varp == &p_ei)
6294 {
6295 if (check_ei() == FAIL)
6296 errmsg = e_invarg;
6297 }
6298#endif
6299
6300#ifdef FEAT_MBYTE
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006301 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6302 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6303 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006304 {
6305 if (gvarp == &p_fenc)
6306 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006307 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006308 errmsg = e_modifiable;
6309 else if (vim_strchr(*varp, ',') != NULL)
6310 /* No comma allowed in 'fileencoding'; catches confusing it
6311 * with 'fileencodings'. */
6312 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006314 {
6315# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006317 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006318# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006319 /* Add 'fileencoding' to the swap file. */
6320 ml_setflags(curbuf);
6321 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006322 }
6323 if (errmsg == NULL)
6324 {
6325 /* canonize the value, so that STRCMP() can be used on it */
6326 p = enc_canonize(*varp);
6327 if (p != NULL)
6328 {
6329 vim_free(*varp);
6330 *varp = p;
6331 }
6332 if (varp == &p_enc)
6333 {
6334 errmsg = mb_init();
6335# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006336 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006337# endif
6338 }
6339 }
6340
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006341# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6343 {
6344 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6345 if (STRCMP(p_tenc, "utf-8") != 0)
6346 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6347 }
6348# endif
6349
6350 if (errmsg == NULL)
6351 {
6352# ifdef FEAT_KEYMAP
6353 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6354 * (with another encoding). */
6355 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6356 (void)keymap_init();
6357# endif
6358
6359 /* When 'termencoding' is not empty and 'encoding' changes or when
6360 * 'termencoding' changes, need to setup for keyboard input and
6361 * display output conversion. */
6362 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6363 {
6364 convert_setup(&input_conv, p_tenc, p_enc);
6365 convert_setup(&output_conv, p_enc, p_tenc);
6366 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006367
6368# if defined(WIN3264) && defined(FEAT_MBYTE)
6369 /* $HOME may have characters in active code page. */
6370 if (varp == &p_enc)
6371 init_homedir();
6372# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006373 }
6374 }
6375#endif
6376
6377#if defined(FEAT_POSTSCRIPT)
6378 else if (varp == &p_penc)
6379 {
6380 /* Canonize printencoding if VIM standard one */
6381 p = enc_canonize(p_penc);
6382 if (p != NULL)
6383 {
6384 vim_free(p_penc);
6385 p_penc = p;
6386 }
6387 else
6388 {
6389 /* Ensure lower case and '-' for '_' */
6390 for (s = p_penc; *s != NUL; s++)
6391 {
6392 if (*s == '_')
6393 *s = '-';
6394 else
6395 *s = TOLOWER_ASC(*s);
6396 }
6397 }
6398 }
6399#endif
6400
Bram Moolenaar9372a112005-12-06 19:59:18 +00006401#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006402 else if (varp == &p_imak)
6403 {
6404 if (gui.in_use && !im_xim_isvalid_imactivate())
6405 errmsg = e_invarg;
6406 }
6407#endif
6408
6409#ifdef FEAT_KEYMAP
6410 else if (varp == &curbuf->b_p_keymap)
6411 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006412 if (!valid_filetype(*varp))
6413 errmsg = e_invarg;
6414 else
6415 /* load or unload key mapping tables */
6416 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006417
Bram Moolenaarfab06232009-03-04 03:13:35 +00006418 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006419 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006420 if (*curbuf->b_p_keymap != NUL)
6421 {
6422 /* Installed a new keymap, switch on using it. */
6423 curbuf->b_p_iminsert = B_IMODE_LMAP;
6424 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6425 curbuf->b_p_imsearch = B_IMODE_LMAP;
6426 }
6427 else
6428 {
6429 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6430 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6431 curbuf->b_p_iminsert = B_IMODE_NONE;
6432 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6433 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6434 }
6435 if ((opt_flags & OPT_LOCAL) == 0)
6436 {
6437 set_iminsert_global();
6438 set_imsearch_global();
6439 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440# ifdef FEAT_WINDOWS
6441 status_redraw_curbuf();
6442# endif
6443 }
6444 }
6445#endif
6446
6447 /* 'fileformat' */
6448 else if (gvarp == &p_ff)
6449 {
6450 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6451 errmsg = e_modifiable;
6452 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6453 errmsg = e_invarg;
6454 else
6455 {
6456 /* may also change 'textmode' */
6457 if (get_fileformat(curbuf) == EOL_DOS)
6458 curbuf->b_p_tx = TRUE;
6459 else
6460 curbuf->b_p_tx = FALSE;
6461#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006462 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006463#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006464 /* update flag in swap file */
6465 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006466 /* Redraw needed when switching to/from "mac": a CR in the text
6467 * will be displayed differently. */
6468 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6469 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006470 }
6471 }
6472
6473 /* 'fileformats' */
6474 else if (varp == &p_ffs)
6475 {
6476 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6477 errmsg = e_invarg;
6478 else
6479 {
6480 /* also change 'textauto' */
6481 if (*p_ffs == NUL)
6482 p_ta = FALSE;
6483 else
6484 p_ta = TRUE;
6485 }
6486 }
6487
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006488#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006489 /* 'cryptkey' */
6490 else if (gvarp == &p_key)
6491 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006492# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006493 /* Make sure the ":set" command doesn't show the new value in the
6494 * history. */
6495 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006496# endif
6497 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6498 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006499 ml_set_crypt_key(curbuf, oldval,
6500 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006501 }
6502
6503 else if (gvarp == &p_cm)
6504 {
6505 if (opt_flags & OPT_LOCAL)
6506 p = curbuf->b_p_cm;
6507 else
6508 p = p_cm;
6509 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6510 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006511 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006512 errmsg = e_invarg;
6513 else
6514 {
6515 /* When setting the global value to empty, make it "zip". */
6516 if (*p_cm == NUL)
6517 {
6518 if (new_value_alloced)
6519 free_string_option(p_cm);
6520 p_cm = vim_strsave((char_u *)"zip");
6521 new_value_alloced = TRUE;
6522 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006523 /* When using ":set cm=name" the local value is going to be empty.
6524 * Do that here, otherwise the crypt functions will still use the
6525 * local value. */
6526 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6527 {
6528 free_string_option(curbuf->b_p_cm);
6529 curbuf->b_p_cm = empty_option;
6530 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006531
6532 /* Need to update the swapfile when the effective method changed.
6533 * Set "s" to the effective old value, "p" to the effective new
6534 * method and compare. */
6535 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6536 s = p_cm; /* was previously using the global value */
6537 else
6538 s = oldval;
6539 if (*curbuf->b_p_cm == NUL)
6540 p = p_cm; /* is now using the global value */
6541 else
6542 p = curbuf->b_p_cm;
6543 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006544 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006545
6546 /* If the global value changes need to update the swapfile for all
6547 * buffers using that value. */
6548 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6549 {
6550 buf_T *buf;
6551
Bram Moolenaar29323592016-07-24 22:04:11 +02006552 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006553 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006554 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006555 }
6556 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557 }
6558#endif
6559
6560 /* 'matchpairs' */
6561 else if (gvarp == &p_mps)
6562 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006563#ifdef FEAT_MBYTE
6564 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006565 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006566 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006568 int x2 = -1;
6569 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006570
6571 if (*p != NUL)
6572 p += mb_ptr2len(p);
6573 if (*p != NUL)
6574 x2 = *p++;
6575 if (*p != NUL)
6576 {
6577 x3 = mb_ptr2char(p);
6578 p += mb_ptr2len(p);
6579 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006580 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006581 {
6582 errmsg = e_invarg;
6583 break;
6584 }
6585 if (*p == NUL)
6586 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006587 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006588 }
6589 else
6590#endif
6591 {
6592 /* Check for "x:y,x:y" */
6593 for (p = *varp; *p != NUL; p += 4)
6594 {
6595 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6596 {
6597 errmsg = e_invarg;
6598 break;
6599 }
6600 if (p[3] == NUL)
6601 break;
6602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006603 }
6604 }
6605
6606#ifdef FEAT_COMMENTS
6607 /* 'comments' */
6608 else if (gvarp == &p_com)
6609 {
6610 for (s = *varp; *s; )
6611 {
6612 while (*s && *s != ':')
6613 {
6614 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6615 && !VIM_ISDIGIT(*s) && *s != '-')
6616 {
6617 errmsg = illegal_char(errbuf, *s);
6618 break;
6619 }
6620 ++s;
6621 }
6622 if (*s++ == NUL)
6623 errmsg = (char_u *)N_("E524: Missing colon");
6624 else if (*s == ',' || *s == NUL)
6625 errmsg = (char_u *)N_("E525: Zero length string");
6626 if (errmsg != NULL)
6627 break;
6628 while (*s && *s != ',')
6629 {
6630 if (*s == '\\' && s[1] != NUL)
6631 ++s;
6632 ++s;
6633 }
6634 s = skip_to_option_part(s);
6635 }
6636 }
6637#endif
6638
6639 /* 'listchars' */
6640 else if (varp == &p_lcs)
6641 {
6642 errmsg = set_chars_option(varp);
6643 }
6644
6645#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6646 /* 'fillchars' */
6647 else if (varp == &p_fcs)
6648 {
6649 errmsg = set_chars_option(varp);
6650 }
6651#endif
6652
6653#ifdef FEAT_CMDWIN
6654 /* 'cedit' */
6655 else if (varp == &p_cedit)
6656 {
6657 errmsg = check_cedit();
6658 }
6659#endif
6660
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006661 /* 'verbosefile' */
6662 else if (varp == &p_vfile)
6663 {
6664 verbose_stop();
6665 if (*p_vfile != NUL && verbose_open() == FAIL)
6666 errmsg = e_invarg;
6667 }
6668
Bram Moolenaar071d4272004-06-13 20:20:40 +00006669#ifdef FEAT_VIMINFO
6670 /* 'viminfo' */
6671 else if (varp == &p_viminfo)
6672 {
6673 for (s = p_viminfo; *s;)
6674 {
6675 /* Check it's a valid character */
6676 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6677 {
6678 errmsg = illegal_char(errbuf, *s);
6679 break;
6680 }
6681 if (*s == 'n') /* name is always last one */
6682 {
6683 break;
6684 }
6685 else if (*s == 'r') /* skip until next ',' */
6686 {
6687 while (*++s && *s != ',')
6688 ;
6689 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006690 else if (*s == '%')
6691 {
6692 /* optional number */
6693 while (vim_isdigit(*++s))
6694 ;
6695 }
6696 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006697 ++s; /* no extra chars */
6698 else /* must have a number */
6699 {
6700 while (vim_isdigit(*++s))
6701 ;
6702
6703 if (!VIM_ISDIGIT(*(s - 1)))
6704 {
6705 if (errbuf != NULL)
6706 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006707 sprintf((char *)errbuf,
6708 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006709 transchar_byte(*(s - 1)));
6710 errmsg = errbuf;
6711 }
6712 else
6713 errmsg = (char_u *)"";
6714 break;
6715 }
6716 }
6717 if (*s == ',')
6718 ++s;
6719 else if (*s)
6720 {
6721 if (errbuf != NULL)
6722 errmsg = (char_u *)N_("E527: Missing comma");
6723 else
6724 errmsg = (char_u *)"";
6725 break;
6726 }
6727 }
6728 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6729 errmsg = (char_u *)N_("E528: Must specify a ' value");
6730 }
6731#endif /* FEAT_VIMINFO */
6732
6733 /* terminal options */
6734 else if (istermoption(&options[opt_idx]) && full_screen)
6735 {
6736 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6737 if (varp == &T_CCO)
6738 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006739 int colors = atoi((char *)T_CCO);
6740
6741 /* Only reinitialize colors if t_Co value has really changed to
6742 * avoid expensive reload of colorscheme if t_Co is set to the
6743 * same value multiple times. */
6744 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006746 t_colors = colors;
6747 if (t_colors <= 1)
6748 {
6749 if (new_value_alloced)
6750 vim_free(T_CCO);
6751 T_CCO = empty_option;
6752 }
6753 /* We now have a different color setup, initialize it again. */
6754 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 }
6757 ttest(FALSE);
6758 if (varp == &T_ME)
6759 {
6760 out_str(T_ME);
6761 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006762#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006763 /* Since t_me has been set, this probably means that the user
6764 * wants to use this as default colors. Need to reset default
6765 * background/foreground colors. */
6766 mch_set_normal_colors();
6767#endif
6768 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006769 if (varp == &T_BE && termcap_active)
6770 {
6771 if (*T_BE == NUL)
6772 /* When clearing t_BE we assume the user no longer wants
6773 * bracketed paste, thus disable it by writing t_BD. */
6774 out_str(T_BD);
6775 else
6776 out_str(T_BE);
6777 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778 }
6779
6780#ifdef FEAT_LINEBREAK
6781 /* 'showbreak' */
6782 else if (varp == &p_sbr)
6783 {
6784 for (s = p_sbr; *s; )
6785 {
6786 if (ptr2cells(s) != 1)
6787 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006788 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006789 }
6790 }
6791#endif
6792
6793#ifdef FEAT_GUI
6794 /* 'guifont' */
6795 else if (varp == &p_guifont)
6796 {
6797 if (gui.in_use)
6798 {
6799 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006800# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801 /*
6802 * Put up a font dialog and let the user select a new value.
6803 * If this is cancelled go back to the old value but don't
6804 * give an error message.
6805 */
6806 if (STRCMP(p, "*") == 0)
6807 {
6808 p = gui_mch_font_dialog(oldval);
6809
6810 if (new_value_alloced)
6811 free_string_option(p_guifont);
6812
6813 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6814 new_value_alloced = TRUE;
6815 }
6816# endif
6817 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6818 {
6819# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6820 if (STRCMP(p_guifont, "*") == 0)
6821 {
6822 /* Dialog was cancelled: Keep the old value without giving
6823 * an error message. */
6824 if (new_value_alloced)
6825 free_string_option(p_guifont);
6826 p_guifont = vim_strsave(oldval);
6827 new_value_alloced = TRUE;
6828 }
6829 else
6830# endif
6831 errmsg = (char_u *)N_("E596: Invalid font(s)");
6832 }
6833 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006834 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 }
6836# ifdef FEAT_XFONTSET
6837 else if (varp == &p_guifontset)
6838 {
6839 if (STRCMP(p_guifontset, "*") == 0)
6840 errmsg = (char_u *)N_("E597: can't select fontset");
6841 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6842 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006843 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006844 }
6845# endif
6846# ifdef FEAT_MBYTE
6847 else if (varp == &p_guifontwide)
6848 {
6849 if (STRCMP(p_guifontwide, "*") == 0)
6850 errmsg = (char_u *)N_("E533: can't select wide font");
6851 else if (gui_get_wide_font() == FAIL)
6852 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006853 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006854 }
6855# endif
6856#endif
6857
6858#ifdef CURSOR_SHAPE
6859 /* 'guicursor' */
6860 else if (varp == &p_guicursor)
6861 errmsg = parse_shape_opt(SHAPE_CURSOR);
6862#endif
6863
6864#ifdef FEAT_MOUSESHAPE
6865 /* 'mouseshape' */
6866 else if (varp == &p_mouseshape)
6867 {
6868 errmsg = parse_shape_opt(SHAPE_MOUSE);
6869 update_mouseshape(-1);
6870 }
6871#endif
6872
6873#ifdef FEAT_PRINTER
6874 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006875 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006876# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006877 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006878 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006879# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880#endif
6881
6882#ifdef FEAT_LANGMAP
6883 /* 'langmap' */
6884 else if (varp == &p_langmap)
6885 langmap_set();
6886#endif
6887
6888#ifdef FEAT_LINEBREAK
6889 /* 'breakat' */
6890 else if (varp == &p_breakat)
6891 fill_breakat_flags();
6892#endif
6893
6894#ifdef FEAT_TITLE
6895 /* 'titlestring' and 'iconstring' */
6896 else if (varp == &p_titlestring || varp == &p_iconstring)
6897 {
6898# ifdef FEAT_STL_OPT
6899 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6900
6901 /* NULL => statusline syntax */
6902 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6903 stl_syntax |= flagval;
6904 else
6905 stl_syntax &= ~flagval;
6906# endif
6907 did_set_title(varp == &p_iconstring);
6908
6909 }
6910#endif
6911
6912#ifdef FEAT_GUI
6913 /* 'guioptions' */
6914 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006915 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006916 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006917 redraw_gui_only = TRUE;
6918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006919#endif
6920
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006921#if defined(FEAT_GUI_TABLINE)
6922 /* 'guitablabel' */
6923 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006924 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006925 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006926 redraw_gui_only = TRUE;
6927 }
6928 /* 'guitabtooltip' */
6929 else if (varp == &p_gtt)
6930 {
6931 redraw_gui_only = TRUE;
6932 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006933#endif
6934
Bram Moolenaar071d4272004-06-13 20:20:40 +00006935#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6936 /* 'ttymouse' */
6937 else if (varp == &p_ttym)
6938 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006939 /* Switch the mouse off before changing the escape sequences used for
6940 * that. */
6941 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006942 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6943 errmsg = e_invarg;
6944 else
6945 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006946 if (termcap_active)
6947 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006948 }
6949#endif
6950
Bram Moolenaar071d4272004-06-13 20:20:40 +00006951 /* 'selection' */
6952 else if (varp == &p_sel)
6953 {
6954 if (*p_sel == NUL
6955 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6956 errmsg = e_invarg;
6957 }
6958
6959 /* 'selectmode' */
6960 else if (varp == &p_slm)
6961 {
6962 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6963 errmsg = e_invarg;
6964 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965
6966#ifdef FEAT_BROWSE
6967 /* 'browsedir' */
6968 else if (varp == &p_bsdir)
6969 {
6970 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6971 && !mch_isdir(p_bsdir))
6972 errmsg = e_invarg;
6973 }
6974#endif
6975
Bram Moolenaar071d4272004-06-13 20:20:40 +00006976 /* 'keymodel' */
6977 else if (varp == &p_km)
6978 {
6979 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6980 errmsg = e_invarg;
6981 else
6982 {
6983 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6984 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6985 }
6986 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006987
6988 /* 'mousemodel' */
6989 else if (varp == &p_mousem)
6990 {
6991 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6992 errmsg = e_invarg;
6993#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6994 else if (*p_mousem != *oldval)
6995 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6996 * to create or delete the popup menus. */
6997 gui_motif_update_mousemodel(root_menu);
6998#endif
6999 }
7000
7001 /* 'switchbuf' */
7002 else if (varp == &p_swb)
7003 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007004 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007005 errmsg = e_invarg;
7006 }
7007
7008 /* 'debug' */
7009 else if (varp == &p_debug)
7010 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007011 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007012 errmsg = e_invarg;
7013 }
7014
7015 /* 'display' */
7016 else if (varp == &p_dy)
7017 {
7018 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7019 errmsg = e_invarg;
7020 else
7021 (void)init_chartab();
7022
7023 }
7024
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007025#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026 /* 'eadirection' */
7027 else if (varp == &p_ead)
7028 {
7029 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7030 errmsg = e_invarg;
7031 }
7032#endif
7033
7034#ifdef FEAT_CLIPBOARD
7035 /* 'clipboard' */
7036 else if (varp == &p_cb)
7037 errmsg = check_clipboard_option();
7038#endif
7039
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007040#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007041 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7042 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007043 else if (varp == &(curwin->w_s->b_p_spl)
7044 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007045 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007046 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007047 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007048 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007049 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007050 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007051 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007052 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007053 /* 'spellsuggest' */
7054 else if (varp == &p_sps)
7055 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007056 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007057 errmsg = e_invarg;
7058 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007059 /* 'mkspellmem' */
7060 else if (varp == &p_msm)
7061 {
7062 if (spell_check_msm() != OK)
7063 errmsg = e_invarg;
7064 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007065#endif
7066
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067#ifdef FEAT_QUICKFIX
7068 /* When 'bufhidden' is set, check for valid value. */
7069 else if (gvarp == &p_bh)
7070 {
7071 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7072 errmsg = e_invarg;
7073 }
7074
7075 /* When 'buftype' is set, check for valid value. */
7076 else if (gvarp == &p_bt)
7077 {
7078 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7079 errmsg = e_invarg;
7080 else
7081 {
7082# ifdef FEAT_WINDOWS
7083 if (curwin->w_status_height)
7084 {
7085 curwin->w_redr_status = TRUE;
7086 redraw_later(VALID);
7087 }
7088# endif
7089 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007090# ifdef FEAT_TITLE
7091 redraw_titles();
7092# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007093 }
7094 }
7095#endif
7096
7097#ifdef FEAT_STL_OPT
7098 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007099 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100 {
7101 int wid;
7102
7103 if (varp == &p_ruf) /* reset ru_wid first */
7104 ru_wid = 0;
7105 s = *varp;
7106 if (varp == &p_ruf && *s == '%')
7107 {
7108 /* set ru_wid if 'ruf' starts with "%99(" */
7109 if (*++s == '-') /* ignore a '-' */
7110 s++;
7111 wid = getdigits(&s);
7112 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7113 ru_wid = wid;
7114 else
7115 errmsg = check_stl_option(p_ruf);
7116 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007117 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007118 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007120 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121 comp_col();
7122 }
7123#endif
7124
7125#ifdef FEAT_INS_EXPAND
7126 /* check if it is a valid value for 'complete' -- Acevedo */
7127 else if (gvarp == &p_cpt)
7128 {
7129 for (s = *varp; *s;)
7130 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007131 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007132 s++;
7133 if (!*s)
7134 break;
7135 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7136 {
7137 errmsg = illegal_char(errbuf, *s);
7138 break;
7139 }
7140 if (*++s != NUL && *s != ',' && *s != ' ')
7141 {
7142 if (s[-1] == 'k' || s[-1] == 's')
7143 {
7144 /* skip optional filename after 'k' and 's' */
7145 while (*s && *s != ',' && *s != ' ')
7146 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007147 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148 ++s;
7149 ++s;
7150 }
7151 }
7152 else
7153 {
7154 if (errbuf != NULL)
7155 {
7156 sprintf((char *)errbuf,
7157 _("E535: Illegal character after <%c>"),
7158 *--s);
7159 errmsg = errbuf;
7160 }
7161 else
7162 errmsg = (char_u *)"";
7163 break;
7164 }
7165 }
7166 }
7167 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007168
7169 /* 'completeopt' */
7170 else if (varp == &p_cot)
7171 {
7172 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7173 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007174 else
7175 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007176 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007177#endif /* FEAT_INS_EXPAND */
7178
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007179#ifdef FEAT_SIGNS
7180 /* 'signcolumn' */
7181 else if (varp == &curwin->w_p_scl)
7182 {
7183 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7184 errmsg = e_invarg;
7185 }
7186#endif
7187
Bram Moolenaar071d4272004-06-13 20:20:40 +00007188
7189#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007190 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007191 else if (varp == &p_toolbar)
7192 {
7193 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7194 &toolbar_flags, TRUE) != OK)
7195 errmsg = e_invarg;
7196 else
7197 {
7198 out_flush();
7199 gui_mch_show_toolbar((toolbar_flags &
7200 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7201 }
7202 }
7203#endif
7204
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007205#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007206 /* 'toolbariconsize': GTK+ 2 only */
7207 else if (varp == &p_tbis)
7208 {
7209 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7210 errmsg = e_invarg;
7211 else
7212 {
7213 out_flush();
7214 gui_mch_show_toolbar((toolbar_flags &
7215 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7216 }
7217 }
7218#endif
7219
7220 /* 'pastetoggle': translate key codes like in a mapping */
7221 else if (varp == &p_pt)
7222 {
7223 if (*p_pt)
7224 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007225 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007226 if (p != NULL)
7227 {
7228 if (new_value_alloced)
7229 free_string_option(p_pt);
7230 p_pt = p;
7231 new_value_alloced = TRUE;
7232 }
7233 }
7234 }
7235
7236 /* 'backspace' */
7237 else if (varp == &p_bs)
7238 {
7239 if (VIM_ISDIGIT(*p_bs))
7240 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007241 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242 errmsg = e_invarg;
7243 }
7244 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7245 errmsg = e_invarg;
7246 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007247 else if (varp == &p_bo)
7248 {
7249 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7250 errmsg = e_invarg;
7251 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007252
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007253 /* 'tagcase' */
7254 else if (gvarp == &p_tc)
7255 {
7256 unsigned int *flags;
7257
7258 if (opt_flags & OPT_LOCAL)
7259 {
7260 p = curbuf->b_p_tc;
7261 flags = &curbuf->b_tc_flags;
7262 }
7263 else
7264 {
7265 p = p_tc;
7266 flags = &tc_flags;
7267 }
7268
7269 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7270 /* make the local value empty: use the global value */
7271 *flags = 0;
7272 else if (*p == NUL
7273 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7274 errmsg = e_invarg;
7275 }
7276
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007277#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007278 /* 'casemap' */
7279 else if (varp == &p_cmp)
7280 {
7281 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7282 errmsg = e_invarg;
7283 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007284#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285
7286#ifdef FEAT_DIFF
7287 /* 'diffopt' */
7288 else if (varp == &p_dip)
7289 {
7290 if (diffopt_changed() == FAIL)
7291 errmsg = e_invarg;
7292 }
7293#endif
7294
7295#ifdef FEAT_FOLDING
7296 /* 'foldmethod' */
7297 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7298 {
7299 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7300 || *curwin->w_p_fdm == NUL)
7301 errmsg = e_invarg;
7302 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007303 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007304 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007305 if (foldmethodIsDiff(curwin))
7306 newFoldLevel();
7307 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007308 }
7309# ifdef FEAT_EVAL
7310 /* 'foldexpr' */
7311 else if (varp == &curwin->w_p_fde)
7312 {
7313 if (foldmethodIsExpr(curwin))
7314 foldUpdateAll(curwin);
7315 }
7316# endif
7317 /* 'foldmarker' */
7318 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7319 {
7320 p = vim_strchr(*varp, ',');
7321 if (p == NULL)
7322 errmsg = (char_u *)N_("E536: comma required");
7323 else if (p == *varp || p[1] == NUL)
7324 errmsg = e_invarg;
7325 else if (foldmethodIsMarker(curwin))
7326 foldUpdateAll(curwin);
7327 }
7328 /* 'commentstring' */
7329 else if (gvarp == &p_cms)
7330 {
7331 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7332 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7333 }
7334 /* 'foldopen' */
7335 else if (varp == &p_fdo)
7336 {
7337 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7338 errmsg = e_invarg;
7339 }
7340 /* 'foldclose' */
7341 else if (varp == &p_fcl)
7342 {
7343 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7344 errmsg = e_invarg;
7345 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007346 /* 'foldignore' */
7347 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7348 {
7349 if (foldmethodIsIndent(curwin))
7350 foldUpdateAll(curwin);
7351 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007352#endif
7353
7354#ifdef FEAT_VIRTUALEDIT
7355 /* 'virtualedit' */
7356 else if (varp == &p_ve)
7357 {
7358 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7359 errmsg = e_invarg;
7360 else if (STRCMP(p_ve, oldval) != 0)
7361 {
7362 /* Recompute cursor position in case the new 've' setting
7363 * changes something. */
7364 validate_virtcol();
7365 coladvance(curwin->w_virtcol);
7366 }
7367 }
7368#endif
7369
7370#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7371 else if (varp == &p_csqf)
7372 {
7373 if (p_csqf != NULL)
7374 {
7375 p = p_csqf;
7376 while (*p != NUL)
7377 {
7378 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7379 || p[1] == NUL
7380 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7381 || (p[2] != NUL && p[2] != ','))
7382 {
7383 errmsg = e_invarg;
7384 break;
7385 }
7386 else if (p[2] == NUL)
7387 break;
7388 else
7389 p += 3;
7390 }
7391 }
7392 }
7393#endif
7394
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007395#ifdef FEAT_CINDENT
7396 /* 'cinoptions' */
7397 else if (gvarp == &p_cino)
7398 {
7399 /* TODO: recognize errors */
7400 parse_cino(curbuf);
7401 }
7402#endif
7403
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007404#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007405 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007406 else if (varp == &p_rop && gui.in_use)
7407 {
7408 if (!gui_mch_set_rendering_options(p_rop))
7409 errmsg = e_invarg;
7410 }
7411#endif
7412
Bram Moolenaard0b51382016-11-04 15:23:45 +01007413#ifdef FEAT_AUTOCMD
7414 else if (gvarp == &p_ft)
7415 {
7416 if (!valid_filetype(*varp))
7417 errmsg = e_invarg;
7418 }
7419#endif
7420
7421#ifdef FEAT_SYN_HL
7422 else if (gvarp == &p_syn)
7423 {
7424 if (!valid_filetype(*varp))
7425 errmsg = e_invarg;
7426 }
7427#endif
7428
Bram Moolenaar071d4272004-06-13 20:20:40 +00007429 /* Options that are a list of flags. */
7430 else
7431 {
7432 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007433 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007434 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007435 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007436 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007437 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007438 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007439 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007440 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007441#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007442 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007443 p = (char_u *)COCU_ALL;
7444#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007445 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007446 {
7447#ifdef FEAT_MOUSE
7448 p = (char_u *)MOUSE_ALL;
7449#else
7450 if (*p_mouse != NUL)
7451 errmsg = (char_u *)N_("E538: No mouse support");
7452#endif
7453 }
7454#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007455 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007456 p = (char_u *)GO_ALL;
7457#endif
7458 if (p != NULL)
7459 {
7460 for (s = *varp; *s; ++s)
7461 if (vim_strchr(p, *s) == NULL)
7462 {
7463 errmsg = illegal_char(errbuf, *s);
7464 break;
7465 }
7466 }
7467 }
7468
7469 /*
7470 * If error detected, restore the previous value.
7471 */
7472 if (errmsg != NULL)
7473 {
7474 if (new_value_alloced)
7475 free_string_option(*varp);
7476 *varp = oldval;
7477 /*
7478 * When resetting some values, need to act on it.
7479 */
7480 if (did_chartab)
7481 (void)init_chartab();
7482 if (varp == &p_hl)
7483 (void)highlight_changed();
7484 }
7485 else
7486 {
7487#ifdef FEAT_EVAL
7488 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007489 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007490#endif
7491 /*
7492 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007493 * Use "free_oldval", because recursiveness may change the flags under
7494 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007495 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007496 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007497 free_string_option(oldval);
7498 if (new_value_alloced)
7499 options[opt_idx].flags |= P_ALLOCED;
7500 else
7501 options[opt_idx].flags &= ~P_ALLOCED;
7502
7503 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007504 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007505 {
7506 /* global option with local value set to use global value; free
7507 * the local value and make it empty */
7508 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7509 free_string_option(*(char_u **)p);
7510 *(char_u **)p = empty_option;
7511 }
7512
7513 /* May set global value for local option. */
7514 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7515 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007516
7517#ifdef FEAT_AUTOCMD
7518 /*
7519 * Trigger the autocommand only after setting the flags.
7520 */
7521# ifdef FEAT_SYN_HL
7522 /* When 'syntax' is set, load the syntax of that name */
7523 if (varp == &(curbuf->b_p_syn))
7524 {
7525 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7526 curbuf->b_fname, TRUE, curbuf);
7527 }
7528# endif
7529 else if (varp == &(curbuf->b_p_ft))
7530 {
7531 /* 'filetype' is set, trigger the FileType autocommand */
7532 did_filetype = TRUE;
7533 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7534 curbuf->b_fname, TRUE, curbuf);
7535 }
7536#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007537#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007538 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007539 {
7540 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007541 char_u *q = curwin->w_s->b_p_spl;
7542
7543 /* Skip the first name if it is "cjk". */
7544 if (STRNCMP(q, "cjk,", 4) == 0)
7545 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007546
7547 /*
7548 * Source the spell/LANG.vim in 'runtimepath'.
7549 * They could set 'spellcapcheck' depending on the language.
7550 * Use the first name in 'spelllang' up to '_region' or
7551 * '.encoding'.
7552 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007553 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007554 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7555 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007556 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007557 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007558 }
7559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007560 }
7561
7562#ifdef FEAT_MOUSE
7563 if (varp == &p_mouse)
7564 {
7565# ifdef FEAT_MOUSE_TTY
7566 if (*p_mouse == NUL)
7567 mch_setmouse(FALSE); /* switch mouse off */
7568 else
7569# endif
7570 setmouse(); /* in case 'mouse' changed */
7571 }
7572#endif
7573
Bram Moolenaar913077c2012-03-28 19:59:04 +02007574 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007575 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007576 curwin->w_set_curswant = TRUE;
7577
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007578#ifdef FEAT_GUI
7579 /* check redraw when it's not a GUI option or the GUI is active. */
7580 if (!redraw_gui_only || gui.in_use)
7581#endif
7582 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007583
7584 return errmsg;
7585}
7586
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007587#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007588/*
7589 * Simple int comparison function for use with qsort()
7590 */
7591 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007592int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007593{
7594 return *(const int *)a - *(const int *)b;
7595}
7596
7597/*
7598 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7599 * Returns error message, NULL if it's OK.
7600 */
7601 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007602check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007603{
7604 char_u *s;
7605 int col;
7606 int count = 0;
7607 int color_cols[256];
7608 int i;
7609 int j = 0;
7610
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007611 if (wp->w_buffer == NULL)
7612 return NULL; /* buffer was closed */
7613
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007614 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007615 {
7616 if (*s == '-' || *s == '+')
7617 {
7618 /* -N and +N: add to 'textwidth' */
7619 col = (*s == '-') ? -1 : 1;
7620 ++s;
7621 if (!VIM_ISDIGIT(*s))
7622 return e_invarg;
7623 col = col * getdigits(&s);
7624 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007625 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007626 col += wp->w_buffer->b_p_tw;
7627 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007628 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007629 }
7630 else if (VIM_ISDIGIT(*s))
7631 col = getdigits(&s);
7632 else
7633 return e_invarg;
7634 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007635skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007636 if (*s == NUL)
7637 break;
7638 if (*s != ',')
7639 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007640 if (*++s == NUL)
7641 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007642 }
7643
7644 vim_free(wp->w_p_cc_cols);
7645 if (count == 0)
7646 wp->w_p_cc_cols = NULL;
7647 else
7648 {
7649 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7650 if (wp->w_p_cc_cols != NULL)
7651 {
7652 /* sort the columns for faster usage on screen redraw inside
7653 * win_line() */
7654 qsort(color_cols, count, sizeof(int), int_cmp);
7655
7656 for (i = 0; i < count; ++i)
7657 /* skip duplicates */
7658 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7659 wp->w_p_cc_cols[j++] = color_cols[i];
7660 wp->w_p_cc_cols[j] = -1; /* end marker */
7661 }
7662 }
7663
7664 return NULL; /* no error */
7665}
7666#endif
7667
Bram Moolenaar071d4272004-06-13 20:20:40 +00007668/*
7669 * Handle setting 'listchars' or 'fillchars'.
7670 * Returns error message, NULL if it's OK.
7671 */
7672 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007673set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007674{
7675 int round, i, len, entries;
7676 char_u *p, *s;
7677 int c1, c2 = 0;
7678 struct charstab
7679 {
7680 int *cp;
7681 char *name;
7682 };
7683#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7684 static struct charstab filltab[] =
7685 {
7686 {&fill_stl, "stl"},
7687 {&fill_stlnc, "stlnc"},
7688 {&fill_vert, "vert"},
7689 {&fill_fold, "fold"},
7690 {&fill_diff, "diff"},
7691 };
7692#endif
7693 static struct charstab lcstab[] =
7694 {
7695 {&lcs_eol, "eol"},
7696 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007697 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007698 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007699 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007700 {&lcs_tab2, "tab"},
7701 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007702#ifdef FEAT_CONCEAL
7703 {&lcs_conceal, "conceal"},
7704#else
7705 {NULL, "conceal"},
7706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007707 };
7708 struct charstab *tab;
7709
7710#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7711 if (varp == &p_lcs)
7712#endif
7713 {
7714 tab = lcstab;
7715 entries = sizeof(lcstab) / sizeof(struct charstab);
7716 }
7717#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7718 else
7719 {
7720 tab = filltab;
7721 entries = sizeof(filltab) / sizeof(struct charstab);
7722 }
7723#endif
7724
7725 /* first round: check for valid value, second round: assign values */
7726 for (round = 0; round <= 1; ++round)
7727 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007728 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729 {
7730 /* After checking that the value is valid: set defaults: space for
7731 * 'fillchars', NUL for 'listchars' */
7732 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007733 if (tab[i].cp != NULL)
7734 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735 if (varp == &p_lcs)
7736 lcs_tab1 = NUL;
7737#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7738 else
7739 fill_diff = '-';
7740#endif
7741 }
7742 p = *varp;
7743 while (*p)
7744 {
7745 for (i = 0; i < entries; ++i)
7746 {
7747 len = (int)STRLEN(tab[i].name);
7748 if (STRNCMP(p, tab[i].name, len) == 0
7749 && p[len] == ':'
7750 && p[len + 1] != NUL)
7751 {
7752 s = p + len + 1;
7753#ifdef FEAT_MBYTE
7754 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007755 if (mb_char2cells(c1) > 1)
7756 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007757#else
7758 c1 = *s++;
7759#endif
7760 if (tab[i].cp == &lcs_tab2)
7761 {
7762 if (*s == NUL)
7763 continue;
7764#ifdef FEAT_MBYTE
7765 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007766 if (mb_char2cells(c2) > 1)
7767 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007768#else
7769 c2 = *s++;
7770#endif
7771 }
7772 if (*s == ',' || *s == NUL)
7773 {
7774 if (round)
7775 {
7776 if (tab[i].cp == &lcs_tab2)
7777 {
7778 lcs_tab1 = c1;
7779 lcs_tab2 = c2;
7780 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007781 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007782 *(tab[i].cp) = c1;
7783
7784 }
7785 p = s;
7786 break;
7787 }
7788 }
7789 }
7790
7791 if (i == entries)
7792 return e_invarg;
7793 if (*p == ',')
7794 ++p;
7795 }
7796 }
7797
7798 return NULL; /* no error */
7799}
7800
7801#ifdef FEAT_STL_OPT
7802/*
7803 * Check validity of options with the 'statusline' format.
7804 * Return error message or NULL.
7805 */
7806 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007807check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007808{
7809 int itemcnt = 0;
7810 int groupdepth = 0;
7811 static char_u errbuf[80];
7812
7813 while (*s && itemcnt < STL_MAX_ITEM)
7814 {
7815 /* Check for valid keys after % sequences */
7816 while (*s && *s != '%')
7817 s++;
7818 if (!*s)
7819 break;
7820 s++;
7821 if (*s != '%' && *s != ')')
7822 ++itemcnt;
7823 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7824 {
7825 s++;
7826 continue;
7827 }
7828 if (*s == ')')
7829 {
7830 s++;
7831 if (--groupdepth < 0)
7832 break;
7833 continue;
7834 }
7835 if (*s == '-')
7836 s++;
7837 while (VIM_ISDIGIT(*s))
7838 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007839 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007840 continue;
7841 if (*s == '.')
7842 {
7843 s++;
7844 while (*s && VIM_ISDIGIT(*s))
7845 s++;
7846 }
7847 if (*s == '(')
7848 {
7849 groupdepth++;
7850 continue;
7851 }
7852 if (vim_strchr(STL_ALL, *s) == NULL)
7853 {
7854 return illegal_char(errbuf, *s);
7855 }
7856 if (*s == '{')
7857 {
7858 s++;
7859 while (*s != '}' && *s)
7860 s++;
7861 if (*s != '}')
7862 return (char_u *)N_("E540: Unclosed expression sequence");
7863 }
7864 }
7865 if (itemcnt >= STL_MAX_ITEM)
7866 return (char_u *)N_("E541: too many items");
7867 if (groupdepth != 0)
7868 return (char_u *)N_("E542: unbalanced groups");
7869 return NULL;
7870}
7871#endif
7872
7873#ifdef FEAT_CLIPBOARD
7874/*
7875 * Extract the items in the 'clipboard' option and set global values.
7876 */
7877 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007878check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007879{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007880 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007881 int new_autoselect_star = FALSE;
7882 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007883 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007884 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007885 regprog_T *new_exclude_prog = NULL;
7886 char_u *errmsg = NULL;
7887 char_u *p;
7888
7889 for (p = p_cb; *p != NUL; )
7890 {
7891 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7892 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007893 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 p += 7;
7895 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007896 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007897 && (p[11] == ',' || p[11] == NUL))
7898 {
7899 new_unnamed |= CLIP_UNNAMED_PLUS;
7900 p += 11;
7901 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007902 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007903 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007905 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007906 p += 10;
7907 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007908 else if (STRNCMP(p, "autoselectplus", 14) == 0
7909 && (p[14] == ',' || p[14] == NUL))
7910 {
7911 new_autoselect_plus = TRUE;
7912 p += 14;
7913 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007915 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007916 {
7917 new_autoselectml = TRUE;
7918 p += 12;
7919 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007920 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7921 {
7922 new_html = TRUE;
7923 p += 4;
7924 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7926 {
7927 p += 8;
7928 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7929 if (new_exclude_prog == NULL)
7930 errmsg = e_invarg;
7931 break;
7932 }
7933 else
7934 {
7935 errmsg = e_invarg;
7936 break;
7937 }
7938 if (*p == ',')
7939 ++p;
7940 }
7941 if (errmsg == NULL)
7942 {
7943 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007944 clip_autoselect_star = new_autoselect_star;
7945 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007947 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007948 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007950#ifdef FEAT_GUI_GTK
7951 if (gui.in_use)
7952 {
7953 gui_gtk_set_selection_targets();
7954 gui_gtk_set_dnd_targets();
7955 }
7956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957 }
7958 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007959 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007960
7961 return errmsg;
7962}
7963#endif
7964
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007965#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007966 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007967did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007968{
7969 char_u *errmsg = NULL;
7970 win_T *wp;
7971 int l;
7972
7973 if (is_spellfile)
7974 {
7975 l = (int)STRLEN(curwin->w_s->b_p_spf);
7976 if (l > 0 && (l < 4
7977 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7978 errmsg = e_invarg;
7979 }
7980
7981 if (errmsg == NULL)
7982 {
7983 FOR_ALL_WINDOWS(wp)
7984 if (wp->w_buffer == curbuf && wp->w_p_spell)
7985 {
7986 errmsg = did_set_spelllang(wp);
7987# ifdef FEAT_WINDOWS
7988 break;
7989# endif
7990 }
7991 }
7992 return errmsg;
7993}
7994
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007995/*
7996 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7997 * Return error message when failed, NULL when OK.
7998 */
7999 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008000compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008001{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008002 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008003 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008004
Bram Moolenaar860cae12010-06-05 23:22:07 +02008005 if (*synblock->b_p_spc == NUL)
8006 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008007 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008008 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008009 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008010 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008011 if (re != NULL)
8012 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008013 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008014 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008015 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008016 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008017 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008018 return e_invarg;
8019 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008020 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008021 }
8022
Bram Moolenaar473de612013-06-08 18:19:48 +02008023 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008024 return NULL;
8025}
8026#endif
8027
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008028#if defined(FEAT_EVAL) || defined(PROTO)
8029/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008030 * Set the scriptID for an option, taking care of setting the buffer- or
8031 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008032 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008033 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008034set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008035{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008036 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8037 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008038
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008039 /* Remember where the option was set. For local options need to do that
8040 * in the buffer or window structure. */
8041 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008042 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008043 if (both || (opt_flags & OPT_LOCAL))
8044 {
8045 if (indir & PV_BUF)
8046 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8047 else if (indir & PV_WIN)
8048 curwin->w_p_scriptID[indir & PV_MASK] = id;
8049 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008050}
8051#endif
8052
Bram Moolenaar071d4272004-06-13 20:20:40 +00008053/*
8054 * Set the value of a boolean option, and take care of side effects.
8055 * Returns NULL for success, or an error message for an error.
8056 */
8057 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008058set_bool_option(
8059 int opt_idx, /* index in options[] table */
8060 char_u *varp, /* pointer to the option variable */
8061 int value, /* new value */
8062 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008063{
8064 int old_value = *(int *)varp;
8065
Bram Moolenaar071d4272004-06-13 20:20:40 +00008066 /* Disallow changing some options from secure mode */
8067 if ((secure
8068#ifdef HAVE_SANDBOX
8069 || sandbox != 0
8070#endif
8071 ) && (options[opt_idx].flags & P_SECURE))
8072 return e_secure;
8073
8074 *(int *)varp = value; /* set the new value */
8075#ifdef FEAT_EVAL
8076 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008077 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008078#endif
8079
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008080#ifdef FEAT_GUI
8081 need_mouse_correct = TRUE;
8082#endif
8083
Bram Moolenaar071d4272004-06-13 20:20:40 +00008084 /* May set global value for local option. */
8085 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8086 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8087
8088 /*
8089 * Handle side effects of changing a bool option.
8090 */
8091
8092 /* 'compatible' */
8093 if ((int *)varp == &p_cp)
8094 {
8095 compatible_set();
8096 }
8097
Bram Moolenaar920694c2016-08-21 17:45:02 +02008098#ifdef FEAT_LANGMAP
8099 if ((int *)varp == &p_lrm)
8100 /* 'langremap' -> !'langnoremap' */
8101 p_lnr = !p_lrm;
8102 else if ((int *)varp == &p_lnr)
8103 /* 'langnoremap' -> !'langremap' */
8104 p_lrm = !p_lnr;
8105#endif
8106
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008107#ifdef FEAT_PERSISTENT_UNDO
8108 /* 'undofile' */
8109 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8110 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008111 /* Only take action when the option was set. When reset we do not
8112 * delete the undo file, the option may be set again without making
8113 * any changes in between. */
8114 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008115 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008116 char_u hash[UNDO_HASH_SIZE];
8117 buf_T *save_curbuf = curbuf;
8118
Bram Moolenaar29323592016-07-24 22:04:11 +02008119 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008120 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008121 /* When 'undofile' is set globally: for every buffer, otherwise
8122 * only for the current buffer: Try to read in the undofile,
8123 * if one exists, the buffer wasn't changed and the buffer was
8124 * loaded */
8125 if ((curbuf == save_curbuf
8126 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8127 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8128 {
8129 u_compute_hash(hash);
8130 u_read_undo(NULL, hash, curbuf->b_fname);
8131 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008132 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008133 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008134 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008135 }
8136#endif
8137
Bram Moolenaar071d4272004-06-13 20:20:40 +00008138 else if ((int *)varp == &curbuf->b_p_ro)
8139 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008140 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8142 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008143
8144 /* when 'readonly' is set may give W10 again */
8145 if (curbuf->b_p_ro)
8146 curbuf->b_did_warn = FALSE;
8147
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008149 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150#endif
8151 }
8152
Bram Moolenaar9c449722010-07-20 18:44:27 +02008153#ifdef FEAT_GUI
8154 else if ((int *)varp == &p_mh)
8155 {
8156 if (!p_mh)
8157 gui_mch_mousehide(FALSE);
8158 }
8159#endif
8160
Bram Moolenaara539df02010-08-01 14:35:05 +02008161#ifdef FEAT_TITLE
8162 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008164 {
8165 redraw_titles();
8166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 /* when 'endofline' is changed, redraw the window title */
8168 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008169 {
8170 redraw_titles();
8171 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008172 /* when 'fixeol' is changed, redraw the window title */
8173 else if ((int *)varp == &curbuf->b_p_fixeol)
8174 {
8175 redraw_titles();
8176 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008177# ifdef FEAT_MBYTE
8178 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008179 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008180 {
8181 redraw_titles();
8182 }
8183# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184#endif
8185
8186 /* when 'bin' is set also set some other options */
8187 else if ((int *)varp == &curbuf->b_p_bin)
8188 {
8189 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8190#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008191 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192#endif
8193 }
8194
8195#ifdef FEAT_AUTOCMD
8196 /* when 'buflisted' changes, trigger autocommands */
8197 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8198 {
8199 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8200 NULL, NULL, TRUE, curbuf);
8201 }
8202#endif
8203
8204 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8205 else if ((int *)varp == &curbuf->b_p_swf)
8206 {
8207 if (curbuf->b_p_swf && p_uc)
8208 ml_open_file(curbuf); /* create the swap file */
8209 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008210 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8211 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008212 mf_close_file(curbuf, TRUE); /* remove the swap file */
8213 }
8214
8215 /* when 'terse' is set change 'shortmess' */
8216 else if ((int *)varp == &p_terse)
8217 {
8218 char_u *p;
8219
8220 p = vim_strchr(p_shm, SHM_SEARCH);
8221
8222 /* insert 's' in p_shm */
8223 if (p_terse && p == NULL)
8224 {
8225 STRCPY(IObuff, p_shm);
8226 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008227 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008228 }
8229 /* remove 's' from p_shm */
8230 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008231 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008232 }
8233
8234 /* when 'paste' is set or reset also change other options */
8235 else if ((int *)varp == &p_paste)
8236 {
8237 paste_option_changed();
8238 }
8239
8240 /* when 'insertmode' is set from an autocommand need to do work here */
8241 else if ((int *)varp == &p_im)
8242 {
8243 if (p_im)
8244 {
8245 if ((State & INSERT) == 0)
8246 need_start_insertmode = TRUE;
8247 stop_insert_mode = FALSE;
8248 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008249 /* only reset if it was set previously */
8250 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251 {
8252 need_start_insertmode = FALSE;
8253 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008254 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255 clear_cmdline = TRUE; /* remove "(insert)" */
8256 restart_edit = 0;
8257 }
8258 }
8259
8260 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8261 else if ((int *)varp == &p_ic && p_hls)
8262 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008263 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008264 }
8265
8266#ifdef FEAT_SEARCH_EXTRA
8267 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8268 else if ((int *)varp == &p_hls)
8269 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008270 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008271 }
8272#endif
8273
8274#ifdef FEAT_SCROLLBIND
8275 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8276 * at the end of normal_cmd() */
8277 else if ((int *)varp == &curwin->w_p_scb)
8278 {
8279 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008280 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008281 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008282 curwin->w_scbind_pos = curwin->w_topline;
8283 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 }
8285#endif
8286
8287#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8288 /* There can be only one window with 'previewwindow' set. */
8289 else if ((int *)varp == &curwin->w_p_pvw)
8290 {
8291 if (curwin->w_p_pvw)
8292 {
8293 win_T *win;
8294
Bram Moolenaar29323592016-07-24 22:04:11 +02008295 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008296 if (win->w_p_pvw && win != curwin)
8297 {
8298 curwin->w_p_pvw = FALSE;
8299 return (char_u *)N_("E590: A preview window already exists");
8300 }
8301 }
8302 }
8303#endif
8304
8305 /* when 'textmode' is set or reset also change 'fileformat' */
8306 else if ((int *)varp == &curbuf->b_p_tx)
8307 {
8308 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8309 }
8310
8311 /* when 'textauto' is set or reset also change 'fileformats' */
8312 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008313 set_string_option_direct((char_u *)"ffs", -1,
8314 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008315 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316
8317 /*
8318 * When 'lisp' option changes include/exclude '-' in
8319 * keyword characters.
8320 */
8321#ifdef FEAT_LISP
8322 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8323 {
8324 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8325 }
8326#endif
8327
8328#ifdef FEAT_TITLE
8329 /* when 'title' changed, may need to change the title; same for 'icon' */
8330 else if ((int *)varp == &p_title)
8331 {
8332 did_set_title(FALSE);
8333 }
8334
8335 else if ((int *)varp == &p_icon)
8336 {
8337 did_set_title(TRUE);
8338 }
8339#endif
8340
8341 else if ((int *)varp == &curbuf->b_changed)
8342 {
8343 if (!value)
8344 save_file_ff(curbuf); /* Buffer is unchanged */
8345#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008346 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008347#endif
8348#ifdef FEAT_AUTOCMD
8349 modified_was_set = value;
8350#endif
8351 }
8352
8353#ifdef BACKSLASH_IN_FILENAME
8354 else if ((int *)varp == &p_ssl)
8355 {
8356 if (p_ssl)
8357 {
8358 psepc = '/';
8359 psepcN = '\\';
8360 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008361 }
8362 else
8363 {
8364 psepc = '\\';
8365 psepcN = '/';
8366 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008367 }
8368
8369 /* need to adjust the file name arguments and buffer names. */
8370 buflist_slash_adjust();
8371 alist_slash_adjust();
8372# ifdef FEAT_EVAL
8373 scriptnames_slash_adjust();
8374# endif
8375 }
8376#endif
8377
8378 /* If 'wrap' is set, set w_leftcol to zero. */
8379 else if ((int *)varp == &curwin->w_p_wrap)
8380 {
8381 if (curwin->w_p_wrap)
8382 curwin->w_leftcol = 0;
8383 }
8384
8385#ifdef FEAT_WINDOWS
8386 else if ((int *)varp == &p_ea)
8387 {
8388 if (p_ea && !old_value)
8389 win_equal(curwin, FALSE, 0);
8390 }
8391#endif
8392
8393 else if ((int *)varp == &p_wiv)
8394 {
8395 /*
8396 * When 'weirdinvert' changed, set/reset 't_xs'.
8397 * Then set 'weirdinvert' according to value of 't_xs'.
8398 */
8399 if (p_wiv && !old_value)
8400 T_XS = (char_u *)"y";
8401 else if (!p_wiv && old_value)
8402 T_XS = empty_option;
8403 p_wiv = (*T_XS != NUL);
8404 }
8405
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008406#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 else if ((int *)varp == &p_beval)
8408 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008409 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008410 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008411 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412 gui_mch_disable_beval_area(balloonEval);
8413 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008414#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008416#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417 else if ((int *)varp == &p_acd)
8418 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008419 /* Change directories when the 'acd' option is set now. */
8420 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421 }
8422#endif
8423
8424#ifdef FEAT_DIFF
8425 /* 'diff' */
8426 else if ((int *)varp == &curwin->w_p_diff)
8427 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008428 /* May add or remove the buffer from the list of diff buffers. */
8429 diff_buf_adjust(curwin);
8430# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431 if (foldmethodIsDiff(curwin))
8432 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008433# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008434 }
8435#endif
8436
8437#ifdef USE_IM_CONTROL
8438 /* 'imdisable' */
8439 else if ((int *)varp == &p_imdisable)
8440 {
8441 /* Only de-activate it here, it will be enabled when changing mode. */
8442 if (p_imdisable)
8443 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008444 else if (State & INSERT)
8445 /* When the option is set from an autocommand, it may need to take
8446 * effect right away. */
8447 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008448 }
8449#endif
8450
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008451#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008452 /* 'spell' */
8453 else if ((int *)varp == &curwin->w_p_spell)
8454 {
8455 if (curwin->w_p_spell)
8456 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008457 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008458 if (errmsg != NULL)
8459 EMSG(_(errmsg));
8460 }
8461 }
8462#endif
8463
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464#ifdef FEAT_FKMAP
8465 else if ((int *)varp == &p_altkeymap)
8466 {
8467 if (old_value != p_altkeymap)
8468 {
8469 if (!p_altkeymap)
8470 {
8471 p_hkmap = p_fkmap;
8472 p_fkmap = 0;
8473 }
8474 else
8475 {
8476 p_fkmap = p_hkmap;
8477 p_hkmap = 0;
8478 }
8479 (void)init_chartab();
8480 }
8481 }
8482
8483 /*
8484 * In case some second language keymapping options have changed, check
8485 * and correct the setting in a consistent way.
8486 */
8487
8488 /*
8489 * If hkmap or fkmap are set, reset Arabic keymapping.
8490 */
8491 if ((p_hkmap || p_fkmap) && p_altkeymap)
8492 {
8493 p_altkeymap = p_fkmap;
8494# ifdef FEAT_ARABIC
8495 curwin->w_p_arab = FALSE;
8496# endif
8497 (void)init_chartab();
8498 }
8499
8500 /*
8501 * If hkmap set, reset Farsi keymapping.
8502 */
8503 if (p_hkmap && p_altkeymap)
8504 {
8505 p_altkeymap = 0;
8506 p_fkmap = 0;
8507# ifdef FEAT_ARABIC
8508 curwin->w_p_arab = FALSE;
8509# endif
8510 (void)init_chartab();
8511 }
8512
8513 /*
8514 * If fkmap set, reset Hebrew keymapping.
8515 */
8516 if (p_fkmap && !p_altkeymap)
8517 {
8518 p_altkeymap = 1;
8519 p_hkmap = 0;
8520# ifdef FEAT_ARABIC
8521 curwin->w_p_arab = FALSE;
8522# endif
8523 (void)init_chartab();
8524 }
8525#endif
8526
8527#ifdef FEAT_ARABIC
8528 if ((int *)varp == &curwin->w_p_arab)
8529 {
8530 if (curwin->w_p_arab)
8531 {
8532 /*
8533 * 'arabic' is set, handle various sub-settings.
8534 */
8535 if (!p_tbidi)
8536 {
8537 /* set rightleft mode */
8538 if (!curwin->w_p_rl)
8539 {
8540 curwin->w_p_rl = TRUE;
8541 changed_window_setting();
8542 }
8543
8544 /* Enable Arabic shaping (major part of what Arabic requires) */
8545 if (!p_arshape)
8546 {
8547 p_arshape = TRUE;
8548 redraw_later_clear();
8549 }
8550 }
8551
8552 /* Arabic requires a utf-8 encoding, inform the user if its not
8553 * set. */
8554 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008555 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008556 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8557
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008558 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008559 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8560#ifdef FEAT_EVAL
8561 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8562#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008563 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008564
8565# ifdef FEAT_MBYTE
8566 /* set 'delcombine' */
8567 p_deco = TRUE;
8568# endif
8569
8570# ifdef FEAT_KEYMAP
8571 /* Force-set the necessary keymap for arabic */
8572 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8573 OPT_LOCAL);
8574# endif
8575# ifdef FEAT_FKMAP
8576 p_altkeymap = 0;
8577 p_hkmap = 0;
8578 p_fkmap = 0;
8579 (void)init_chartab();
8580# endif
8581 }
8582 else
8583 {
8584 /*
8585 * 'arabic' is reset, handle various sub-settings.
8586 */
8587 if (!p_tbidi)
8588 {
8589 /* reset rightleft mode */
8590 if (curwin->w_p_rl)
8591 {
8592 curwin->w_p_rl = FALSE;
8593 changed_window_setting();
8594 }
8595
8596 /* 'arabicshape' isn't reset, it is a global option and
8597 * another window may still need it "on". */
8598 }
8599
8600 /* 'delcombine' isn't reset, it is a global option and another
8601 * window may still want it "on". */
8602
8603# ifdef FEAT_KEYMAP
8604 /* Revert to the default keymap */
8605 curbuf->b_p_iminsert = B_IMODE_NONE;
8606 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8607# endif
8608 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008609 }
8610
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008611#endif
8612
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008613#ifdef FEAT_TERMGUICOLORS
8614 /* 'termguicolors' */
8615 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008616 {
8617# ifdef FEAT_GUI
8618 if (!gui.in_use && !gui.starting)
8619# endif
8620 highlight_gui_started();
8621 }
8622#endif
8623
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624 /*
8625 * End of handling side effects for bool options.
8626 */
8627
Bram Moolenaar53744302015-07-17 17:38:22 +02008628 /* after handling side effects, call autocommand */
8629
Bram Moolenaar071d4272004-06-13 20:20:40 +00008630 options[opt_idx].flags |= P_WAS_SET;
8631
Bram Moolenaar53744302015-07-17 17:38:22 +02008632#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8633 if (!starting)
8634 {
8635 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008636 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8637 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8638 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008639 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8640 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8641 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8642 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8643 reset_v_option_vars();
8644 }
8645#endif
8646
Bram Moolenaar071d4272004-06-13 20:20:40 +00008647 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008648 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008649 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008650 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008651 check_redraw(options[opt_idx].flags);
8652
8653 return NULL;
8654}
8655
8656/*
8657 * Set the value of a number option, and take care of side effects.
8658 * Returns NULL for success, or an error message for an error.
8659 */
8660 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008661set_num_option(
8662 int opt_idx, /* index in options[] table */
8663 char_u *varp, /* pointer to the option variable */
8664 long value, /* new value */
8665 char_u *errbuf, /* buffer for error messages */
8666 size_t errbuflen, /* length of "errbuf" */
8667 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668 OPT_MODELINE */
8669{
8670 char_u *errmsg = NULL;
8671 long old_value = *(long *)varp;
8672 long old_Rows = Rows; /* remember old Rows */
8673 long old_Columns = Columns; /* remember old Columns */
8674 long *pp = (long *)varp;
8675
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008676 /* Disallow changing some options from secure mode. */
8677 if ((secure
8678#ifdef HAVE_SANDBOX
8679 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008680#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008681 ) && (options[opt_idx].flags & P_SECURE))
8682 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008683
8684 *pp = value;
8685#ifdef FEAT_EVAL
8686 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008687 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008689#ifdef FEAT_GUI
8690 need_mouse_correct = TRUE;
8691#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008692
Bram Moolenaar14f24742012-08-08 18:01:05 +02008693 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008694 {
8695 errmsg = e_positive;
8696 curbuf->b_p_sw = curbuf->b_p_ts;
8697 }
8698
8699 /*
8700 * Number options that need some action when changed
8701 */
8702#ifdef FEAT_WINDOWS
8703 if (pp == &p_wh || pp == &p_hh)
8704 {
8705 if (p_wh < 1)
8706 {
8707 errmsg = e_positive;
8708 p_wh = 1;
8709 }
8710 if (p_wmh > p_wh)
8711 {
8712 errmsg = e_winheight;
8713 p_wh = p_wmh;
8714 }
8715 if (p_hh < 0)
8716 {
8717 errmsg = e_positive;
8718 p_hh = 0;
8719 }
8720
8721 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008722 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723 {
8724 if (pp == &p_wh && curwin->w_height < p_wh)
8725 win_setheight((int)p_wh);
8726 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8727 win_setheight((int)p_hh);
8728 }
8729 }
8730
8731 /* 'winminheight' */
8732 else if (pp == &p_wmh)
8733 {
8734 if (p_wmh < 0)
8735 {
8736 errmsg = e_positive;
8737 p_wmh = 0;
8738 }
8739 if (p_wmh > p_wh)
8740 {
8741 errmsg = e_winheight;
8742 p_wmh = p_wh;
8743 }
8744 win_setminheight();
8745 }
8746
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008747# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008748 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008749 {
8750 if (p_wiw < 1)
8751 {
8752 errmsg = e_positive;
8753 p_wiw = 1;
8754 }
8755 if (p_wmw > p_wiw)
8756 {
8757 errmsg = e_winwidth;
8758 p_wiw = p_wmw;
8759 }
8760
8761 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008762 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763 win_setwidth((int)p_wiw);
8764 }
8765
8766 /* 'winminwidth' */
8767 else if (pp == &p_wmw)
8768 {
8769 if (p_wmw < 0)
8770 {
8771 errmsg = e_positive;
8772 p_wmw = 0;
8773 }
8774 if (p_wmw > p_wiw)
8775 {
8776 errmsg = e_winwidth;
8777 p_wmw = p_wiw;
8778 }
8779 win_setminheight();
8780 }
8781# endif
8782
8783#endif
8784
8785#ifdef FEAT_WINDOWS
8786 /* (re)set last window status line */
8787 else if (pp == &p_ls)
8788 {
8789 last_status(FALSE);
8790 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008791
8792 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008793 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008794 {
8795 shell_new_rows(); /* recompute window positions and heights */
8796 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797#endif
8798
8799#ifdef FEAT_GUI
8800 else if (pp == &p_linespace)
8801 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008802 /* Recompute gui.char_height and resize the Vim window to keep the
8803 * same number of lines. */
8804 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008805 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806 }
8807#endif
8808
8809#ifdef FEAT_FOLDING
8810 /* 'foldlevel' */
8811 else if (pp == &curwin->w_p_fdl)
8812 {
8813 if (curwin->w_p_fdl < 0)
8814 curwin->w_p_fdl = 0;
8815 newFoldLevel();
8816 }
8817
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008818 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819 else if (pp == &curwin->w_p_fml)
8820 {
8821 foldUpdateAll(curwin);
8822 }
8823
8824 /* 'foldnestmax' */
8825 else if (pp == &curwin->w_p_fdn)
8826 {
8827 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8828 foldUpdateAll(curwin);
8829 }
8830
8831 /* 'foldcolumn' */
8832 else if (pp == &curwin->w_p_fdc)
8833 {
8834 if (curwin->w_p_fdc < 0)
8835 {
8836 errmsg = e_positive;
8837 curwin->w_p_fdc = 0;
8838 }
8839 else if (curwin->w_p_fdc > 12)
8840 {
8841 errmsg = e_invarg;
8842 curwin->w_p_fdc = 12;
8843 }
8844 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008845#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008847#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848 /* 'shiftwidth' or 'tabstop' */
8849 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8850 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008851# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852 if (foldmethodIsIndent(curwin))
8853 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008854# endif
8855# ifdef FEAT_CINDENT
8856 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8857 * parse 'cinoptions'. */
8858 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8859 parse_cino(curbuf);
8860# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008861 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008862#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008863
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008864#ifdef FEAT_MBYTE
8865 /* 'maxcombine' */
8866 else if (pp == &p_mco)
8867 {
8868 if (p_mco > MAX_MCO)
8869 p_mco = MAX_MCO;
8870 else if (p_mco < 0)
8871 p_mco = 0;
8872 screenclear(); /* will re-allocate the screen */
8873 }
8874#endif
8875
Bram Moolenaar071d4272004-06-13 20:20:40 +00008876 else if (pp == &curbuf->b_p_iminsert)
8877 {
8878 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8879 {
8880 errmsg = e_invarg;
8881 curbuf->b_p_iminsert = B_IMODE_NONE;
8882 }
8883 p_iminsert = curbuf->b_p_iminsert;
8884 if (termcap_active) /* don't do this in the alternate screen */
8885 showmode();
8886#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8887 /* Show/unshow value of 'keymap' in status lines. */
8888 status_redraw_curbuf();
8889#endif
8890 }
8891
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008892 else if (pp == &p_window)
8893 {
8894 if (p_window < 1)
8895 p_window = 1;
8896 else if (p_window >= Rows)
8897 p_window = Rows - 1;
8898 }
8899
Bram Moolenaar071d4272004-06-13 20:20:40 +00008900 else if (pp == &curbuf->b_p_imsearch)
8901 {
8902 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8903 {
8904 errmsg = e_invarg;
8905 curbuf->b_p_imsearch = B_IMODE_NONE;
8906 }
8907 p_imsearch = curbuf->b_p_imsearch;
8908 }
8909
8910#ifdef FEAT_TITLE
8911 /* if 'titlelen' has changed, redraw the title */
8912 else if (pp == &p_titlelen)
8913 {
8914 if (p_titlelen < 0)
8915 {
8916 errmsg = e_positive;
8917 p_titlelen = 85;
8918 }
8919 if (starting != NO_SCREEN && old_value != p_titlelen)
8920 need_maketitle = TRUE;
8921 }
8922#endif
8923
8924 /* if p_ch changed value, change the command line height */
8925 else if (pp == &p_ch)
8926 {
8927 if (p_ch < 1)
8928 {
8929 errmsg = e_positive;
8930 p_ch = 1;
8931 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008932 if (p_ch > Rows - min_rows() + 1)
8933 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008934
8935 /* Only compute the new window layout when startup has been
8936 * completed. Otherwise the frame sizes may be wrong. */
8937 if (p_ch != old_value && full_screen
8938#ifdef FEAT_GUI
8939 && !gui.starting
8940#endif
8941 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008942 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008943 }
8944
8945 /* when 'updatecount' changes from zero to non-zero, open swap files */
8946 else if (pp == &p_uc)
8947 {
8948 if (p_uc < 0)
8949 {
8950 errmsg = e_positive;
8951 p_uc = 100;
8952 }
8953 if (p_uc && !old_value)
8954 ml_open_files();
8955 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008956#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008957 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008958 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008959 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008960 {
8961 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008962 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008963 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008964 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008965 {
8966 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008967 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008968 }
8969 }
8970#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008971#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008972 else if (pp == &p_mzq)
8973 mzvim_reset_timer();
8974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008975
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008976#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8977 /* 'pyxversion' */
8978 else if (pp == &p_pyx)
8979 {
8980 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8981 errmsg = e_invarg;
8982 }
8983#endif
8984
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985 /* sync undo before 'undolevels' changes */
8986 else if (pp == &p_ul)
8987 {
8988 /* use the old value, otherwise u_sync() may not work properly */
8989 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008990 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008991 p_ul = value;
8992 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008993 else if (pp == &curbuf->b_p_ul)
8994 {
8995 /* use the old value, otherwise u_sync() may not work properly */
8996 curbuf->b_p_ul = old_value;
8997 u_sync(TRUE);
8998 curbuf->b_p_ul = value;
8999 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009000
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009001#ifdef FEAT_LINEBREAK
9002 /* 'numberwidth' must be positive */
9003 else if (pp == &curwin->w_p_nuw)
9004 {
9005 if (curwin->w_p_nuw < 1)
9006 {
9007 errmsg = e_positive;
9008 curwin->w_p_nuw = 1;
9009 }
9010 if (curwin->w_p_nuw > 10)
9011 {
9012 errmsg = e_invarg;
9013 curwin->w_p_nuw = 10;
9014 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009015 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009016 }
9017#endif
9018
Bram Moolenaar1a384422010-07-14 19:53:30 +02009019 else if (pp == &curbuf->b_p_tw)
9020 {
9021 if (curbuf->b_p_tw < 0)
9022 {
9023 errmsg = e_positive;
9024 curbuf->b_p_tw = 0;
9025 }
9026#ifdef FEAT_SYN_HL
9027# ifdef FEAT_WINDOWS
9028 {
9029 win_T *wp;
9030 tabpage_T *tp;
9031
9032 FOR_ALL_TAB_WINDOWS(tp, wp)
9033 check_colorcolumn(wp);
9034 }
9035# else
9036 check_colorcolumn(curwin);
9037# endif
9038#endif
9039 }
9040
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041 /*
9042 * Check the bounds for numeric options here
9043 */
9044 if (Rows < min_rows() && full_screen)
9045 {
9046 if (errbuf != NULL)
9047 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009048 vim_snprintf((char *)errbuf, errbuflen,
9049 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050 errmsg = errbuf;
9051 }
9052 Rows = min_rows();
9053 }
9054 if (Columns < MIN_COLUMNS && full_screen)
9055 {
9056 if (errbuf != NULL)
9057 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009058 vim_snprintf((char *)errbuf, errbuflen,
9059 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009060 errmsg = errbuf;
9061 }
9062 Columns = MIN_COLUMNS;
9063 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009064 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009065
Bram Moolenaar071d4272004-06-13 20:20:40 +00009066 /*
9067 * If the screen (shell) height has been changed, assume it is the
9068 * physical screenheight.
9069 */
9070 if (old_Rows != Rows || old_Columns != Columns)
9071 {
9072 /* Changing the screen size is not allowed while updating the screen. */
9073 if (updating_screen)
9074 *pp = old_value;
9075 else if (full_screen
9076#ifdef FEAT_GUI
9077 && !gui.starting
9078#endif
9079 )
9080 set_shellsize((int)Columns, (int)Rows, TRUE);
9081 else
9082 {
9083 /* Postpone the resizing; check the size and cmdline position for
9084 * messages. */
9085 check_shellsize();
9086 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9087 cmdline_row = Rows - p_ch;
9088 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009089 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009090 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009091 }
9092
Bram Moolenaar071d4272004-06-13 20:20:40 +00009093 if (curbuf->b_p_ts <= 0)
9094 {
9095 errmsg = e_positive;
9096 curbuf->b_p_ts = 8;
9097 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009098 if (p_tm < 0)
9099 {
9100 errmsg = e_positive;
9101 p_tm = 0;
9102 }
9103 if ((curwin->w_p_scr <= 0
9104 || (curwin->w_p_scr > curwin->w_height
9105 && curwin->w_height > 0))
9106 && full_screen)
9107 {
9108 if (pp == &(curwin->w_p_scr))
9109 {
9110 if (curwin->w_p_scr != 0)
9111 errmsg = e_scroll;
9112 win_comp_scroll(curwin);
9113 }
9114 /* If 'scroll' became invalid because of a side effect silently adjust
9115 * it. */
9116 else if (curwin->w_p_scr <= 0)
9117 curwin->w_p_scr = 1;
9118 else /* curwin->w_p_scr > curwin->w_height */
9119 curwin->w_p_scr = curwin->w_height;
9120 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009121 if (p_hi < 0)
9122 {
9123 errmsg = e_positive;
9124 p_hi = 0;
9125 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009126 else if (p_hi > 10000)
9127 {
9128 errmsg = e_invarg;
9129 p_hi = 10000;
9130 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009131 if (p_re < 0 || p_re > 2)
9132 {
9133 errmsg = e_invarg;
9134 p_re = 0;
9135 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136 if (p_report < 0)
9137 {
9138 errmsg = e_positive;
9139 p_report = 1;
9140 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009141 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 {
9143 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9144 p_sj = Rows / 2;
9145 else
9146 {
9147 errmsg = e_scroll;
9148 p_sj = 1;
9149 }
9150 }
9151 if (p_so < 0 && full_screen)
9152 {
9153 errmsg = e_scroll;
9154 p_so = 0;
9155 }
9156 if (p_siso < 0 && full_screen)
9157 {
9158 errmsg = e_positive;
9159 p_siso = 0;
9160 }
9161#ifdef FEAT_CMDWIN
9162 if (p_cwh < 1)
9163 {
9164 errmsg = e_positive;
9165 p_cwh = 1;
9166 }
9167#endif
9168 if (p_ut < 0)
9169 {
9170 errmsg = e_positive;
9171 p_ut = 2000;
9172 }
9173 if (p_ss < 0)
9174 {
9175 errmsg = e_positive;
9176 p_ss = 0;
9177 }
9178
9179 /* May set global value for local option. */
9180 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9181 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9182
9183 options[opt_idx].flags |= P_WAS_SET;
9184
Bram Moolenaar53744302015-07-17 17:38:22 +02009185#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9186 if (!starting && errmsg == NULL)
9187 {
9188 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009189 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9190 vim_snprintf((char *)buf_new, 10, "%ld", value);
9191 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009192 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9193 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9194 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9195 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9196 reset_v_option_vars();
9197 }
9198#endif
9199
Bram Moolenaar071d4272004-06-13 20:20:40 +00009200 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009201 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009202 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009203 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009204 check_redraw(options[opt_idx].flags);
9205
9206 return errmsg;
9207}
9208
9209/*
9210 * Called after an option changed: check if something needs to be redrawn.
9211 */
9212 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009213check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009214{
9215 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009216 int doclear = (flags & P_RCLR) == P_RCLR;
9217 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009218
9219#ifdef FEAT_WINDOWS
9220 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9221 status_redraw_all();
9222#endif
9223
9224 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9225 changed_window_setting();
9226 if (flags & P_RBUF)
9227 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009228 if (flags & P_RWINONLY)
9229 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009230 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231 redraw_all_later(CLEAR);
9232 else if (all)
9233 redraw_all_later(NOT_VALID);
9234}
9235
9236/*
9237 * Find index for option 'arg'.
9238 * Return -1 if not found.
9239 */
9240 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009241findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009242{
9243 int opt_idx;
9244 char *s, *p;
9245 static short quick_tab[27] = {0, 0}; /* quick access table */
9246 int is_term_opt;
9247
9248 /*
9249 * For first call: Initialize the quick-access table.
9250 * It contains the index for the first option that starts with a certain
9251 * letter. There are 26 letters, plus the first "t_" option.
9252 */
9253 if (quick_tab[1] == 0)
9254 {
9255 p = options[0].fullname;
9256 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9257 {
9258 if (s[0] != p[0])
9259 {
9260 if (s[0] == 't' && s[1] == '_')
9261 quick_tab[26] = opt_idx;
9262 else
9263 quick_tab[CharOrdLow(s[0])] = opt_idx;
9264 }
9265 p = s;
9266 }
9267 }
9268
9269 /*
9270 * Check for name starting with an illegal character.
9271 */
9272#ifdef EBCDIC
9273 if (!islower(arg[0]))
9274#else
9275 if (arg[0] < 'a' || arg[0] > 'z')
9276#endif
9277 return -1;
9278
9279 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9280 if (is_term_opt)
9281 opt_idx = quick_tab[26];
9282 else
9283 opt_idx = quick_tab[CharOrdLow(arg[0])];
9284 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9285 {
9286 if (STRCMP(arg, s) == 0) /* match full name */
9287 break;
9288 }
9289 if (s == NULL && !is_term_opt)
9290 {
9291 opt_idx = quick_tab[CharOrdLow(arg[0])];
9292 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9293 {
9294 s = options[opt_idx].shortname;
9295 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9296 break;
9297 s = NULL;
9298 }
9299 }
9300 if (s == NULL)
9301 opt_idx = -1;
9302 return opt_idx;
9303}
9304
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009305#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306/*
9307 * Get the value for an option.
9308 *
9309 * Returns:
9310 * Number or Toggle option: 1, *numval gets value.
9311 * String option: 0, *stringval gets allocated string.
9312 * Hidden Number or Toggle option: -1.
9313 * hidden String option: -2.
9314 * unknown option: -3.
9315 */
9316 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009317get_option_value(
9318 char_u *name,
9319 long *numval,
9320 char_u **stringval, /* NULL when only checking existence */
9321 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009322{
9323 int opt_idx;
9324 char_u *varp;
9325
9326 opt_idx = findoption(name);
9327 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009328 {
9329 int key;
9330
9331 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9332 && (key = find_key_option(name)) != 0)
9333 {
9334 char_u key_name[2];
9335 char_u *p;
9336
9337 if (key < 0)
9338 {
9339 key_name[0] = KEY2TERMCAP0(key);
9340 key_name[1] = KEY2TERMCAP1(key);
9341 }
9342 else
9343 {
9344 key_name[0] = KS_KEY;
9345 key_name[1] = (key & 0xff);
9346 }
9347 p = find_termcode(key_name);
9348 if (p != NULL)
9349 {
9350 if (stringval != NULL)
9351 *stringval = vim_strsave(p);
9352 return 0;
9353 }
9354 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009356 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009357
9358 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9359
9360 if (options[opt_idx].flags & P_STRING)
9361 {
9362 if (varp == NULL) /* hidden option */
9363 return -2;
9364 if (stringval != NULL)
9365 {
9366#ifdef FEAT_CRYPT
9367 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009368 if ((char_u **)varp == &curbuf->b_p_key
9369 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009370 *stringval = vim_strsave((char_u *)"*****");
9371 else
9372#endif
9373 *stringval = vim_strsave(*(char_u **)(varp));
9374 }
9375 return 0;
9376 }
9377
9378 if (varp == NULL) /* hidden option */
9379 return -1;
9380 if (options[opt_idx].flags & P_NUM)
9381 *numval = *(long *)varp;
9382 else
9383 {
9384 /* Special case: 'modified' is b_changed, but we also want to consider
9385 * it set when 'ff' or 'fenc' changed. */
9386 if ((int *)varp == &curbuf->b_changed)
9387 *numval = curbufIsChanged();
9388 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009389 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009390 }
9391 return 1;
9392}
9393#endif
9394
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009395#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009396/*
9397 * Returns the option attributes and its value. Unlike the above function it
9398 * will return either global value or local value of the option depending on
9399 * what was requested, but it will never return global value if it was
9400 * requested to return local one and vice versa. Neither it will return
9401 * buffer-local value if it was requested to return window-local one.
9402 *
9403 * Pretends that option is absent if it is not present in the requested scope
9404 * (i.e. has no global, window-local or buffer-local value depending on
9405 * opt_type). Uses
9406 *
9407 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009408 * 0 hidden or unknown option, also option that does not have requested
9409 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009410 * see SOPT_* in vim.h for other flags
9411 *
9412 * Possible opt_type values: see SREQ_* in vim.h
9413 */
9414 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009415get_option_value_strict(
9416 char_u *name,
9417 long *numval,
9418 char_u **stringval, /* NULL when only obtaining attributes */
9419 int opt_type,
9420 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009421{
9422 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009423 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009424 struct vimoption *p;
9425 int r = 0;
9426
9427 opt_idx = findoption(name);
9428 if (opt_idx < 0)
9429 return 0;
9430
9431 p = &(options[opt_idx]);
9432
9433 /* Hidden option */
9434 if (p->var == NULL)
9435 return 0;
9436
9437 if (p->flags & P_BOOL)
9438 r |= SOPT_BOOL;
9439 else if (p->flags & P_NUM)
9440 r |= SOPT_NUM;
9441 else if (p->flags & P_STRING)
9442 r |= SOPT_STRING;
9443
9444 if (p->indir == PV_NONE)
9445 {
9446 if (opt_type == SREQ_GLOBAL)
9447 r |= SOPT_GLOBAL;
9448 else
9449 return 0; /* Did not request global-only option */
9450 }
9451 else
9452 {
9453 if (p->indir & PV_BOTH)
9454 r |= SOPT_GLOBAL;
9455 else if (opt_type == SREQ_GLOBAL)
9456 return 0; /* Requested global option */
9457
9458 if (p->indir & PV_WIN)
9459 {
9460 if (opt_type == SREQ_BUF)
9461 return 0; /* Did not request window-local option */
9462 else
9463 r |= SOPT_WIN;
9464 }
9465 else if (p->indir & PV_BUF)
9466 {
9467 if (opt_type == SREQ_WIN)
9468 return 0; /* Did not request buffer-local option */
9469 else
9470 r |= SOPT_BUF;
9471 }
9472 }
9473
9474 if (stringval == NULL)
9475 return r;
9476
9477 if (opt_type == SREQ_GLOBAL)
9478 varp = p->var;
9479 else
9480 {
9481 if (opt_type == SREQ_BUF)
9482 {
9483 /* Special case: 'modified' is b_changed, but we also want to
9484 * consider it set when 'ff' or 'fenc' changed. */
9485 if (p->indir == PV_MOD)
9486 {
9487 *numval = bufIsChanged((buf_T *) from);
9488 varp = NULL;
9489 }
9490#ifdef FEAT_CRYPT
9491 else if (p->indir == PV_KEY)
9492 {
9493 /* never return the value of the crypt key */
9494 *stringval = NULL;
9495 varp = NULL;
9496 }
9497#endif
9498 else
9499 {
9500 aco_save_T aco;
9501 aucmd_prepbuf(&aco, (buf_T *) from);
9502 varp = get_varp(p);
9503 aucmd_restbuf(&aco);
9504 }
9505 }
9506 else if (opt_type == SREQ_WIN)
9507 {
9508 win_T *save_curwin;
9509 save_curwin = curwin;
9510 curwin = (win_T *) from;
9511 curbuf = curwin->w_buffer;
9512 varp = get_varp(p);
9513 curwin = save_curwin;
9514 curbuf = curwin->w_buffer;
9515 }
9516 if (varp == p->var)
9517 return (r | SOPT_UNSET);
9518 }
9519
9520 if (varp != NULL)
9521 {
9522 if (p->flags & P_STRING)
9523 *stringval = vim_strsave(*(char_u **)(varp));
9524 else if (p->flags & P_NUM)
9525 *numval = *(long *) varp;
9526 else
9527 *numval = *(int *)varp;
9528 }
9529
9530 return r;
9531}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009532
9533/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009534 * Iterate over options. First argument is a pointer to a pointer to a
9535 * structure inside options[] array, second is option type like in the above
9536 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009537 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009538 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009539 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009540 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009541 * first argument to NULL.
9542 *
9543 * Returns full option name for current option on each call.
9544 */
9545 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009546option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009547{
9548 struct vimoption *ret = NULL;
9549 do
9550 {
9551 if (*option == NULL)
9552 *option = (void *) options;
9553 else if (((struct vimoption *) (*option))->fullname == NULL)
9554 {
9555 *option = NULL;
9556 return NULL;
9557 }
9558 else
9559 *option = (void *) (((struct vimoption *) (*option)) + 1);
9560
9561 ret = ((struct vimoption *) (*option));
9562
9563 /* Hidden option */
9564 if (ret->var == NULL)
9565 {
9566 ret = NULL;
9567 continue;
9568 }
9569
9570 switch (opt_type)
9571 {
9572 case SREQ_GLOBAL:
9573 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9574 ret = NULL;
9575 break;
9576 case SREQ_BUF:
9577 if (!(ret->indir & PV_BUF))
9578 ret = NULL;
9579 break;
9580 case SREQ_WIN:
9581 if (!(ret->indir & PV_WIN))
9582 ret = NULL;
9583 break;
9584 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009585 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009586 return NULL;
9587 }
9588 }
9589 while (ret == NULL);
9590
9591 return (char_u *)ret->fullname;
9592}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009593#endif
9594
Bram Moolenaar071d4272004-06-13 20:20:40 +00009595/*
9596 * Set the value of option "name".
9597 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009598 *
9599 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009600 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009601 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009602set_option_value(
9603 char_u *name,
9604 long number,
9605 char_u *string,
9606 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009607{
9608 int opt_idx;
9609 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009610 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611
9612 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009613 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009614 {
9615 int key;
9616
9617 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9618 && (key = find_key_option(name)) != 0)
9619 {
9620 char_u key_name[2];
9621
9622 if (key < 0)
9623 {
9624 key_name[0] = KEY2TERMCAP0(key);
9625 key_name[1] = KEY2TERMCAP1(key);
9626 }
9627 else
9628 {
9629 key_name[0] = KS_KEY;
9630 key_name[1] = (key & 0xff);
9631 }
9632 add_termcode(key_name, string, FALSE);
9633 if (full_screen)
9634 ttest(FALSE);
9635 redraw_all_later(CLEAR);
9636 return NULL;
9637 }
9638
Bram Moolenaar071d4272004-06-13 20:20:40 +00009639 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009640 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009641 else
9642 {
9643 flags = options[opt_idx].flags;
9644#ifdef HAVE_SANDBOX
9645 /* Disallow changing some options in the sandbox */
9646 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009647 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009648 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009649 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009652 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009653 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009654 else
9655 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009656 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009657 if (varp != NULL) /* hidden option is not changed */
9658 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009659 if (number == 0 && string != NULL)
9660 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009661 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009662
9663 /* Either we are given a string or we are setting option
9664 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009665 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009666 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009667 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009668 {
9669 /* There's another character after zeros or the string
9670 * is empty. In both cases, we are trying to set a
9671 * num option using a string. */
9672 EMSG3(_("E521: Number required: &%s = '%s'"),
9673 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009674 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009675
9676 }
9677 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009678 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009679 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009680 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009682 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009683 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009684 }
9685 }
9686 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009687 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009688}
9689
9690/*
9691 * Get the terminal code for a terminal option.
9692 * Returns NULL when not found.
9693 */
9694 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009695get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009696{
9697 int opt_idx;
9698 char_u *varp;
9699
9700 if (tname[0] != 't' || tname[1] != '_' ||
9701 tname[2] == NUL || tname[3] == NUL)
9702 return NULL;
9703 if ((opt_idx = findoption(tname)) >= 0)
9704 {
9705 varp = get_varp(&(options[opt_idx]));
9706 if (varp != NULL)
9707 varp = *(char_u **)(varp);
9708 return varp;
9709 }
9710 return find_termcode(tname + 2);
9711}
9712
9713 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009714get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009715{
9716 int i;
9717
9718 i = findoption((char_u *)"hl");
9719 if (i >= 0)
9720 return options[i].def_val[VI_DEFAULT];
9721 return (char_u *)NULL;
9722}
9723
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009724#if defined(FEAT_MBYTE) || defined(PROTO)
9725 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009726get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009727{
9728 int i;
9729
9730 i = findoption((char_u *)"enc");
9731 if (i >= 0)
9732 return options[i].def_val[VI_DEFAULT];
9733 return (char_u *)NULL;
9734}
9735#endif
9736
Bram Moolenaar071d4272004-06-13 20:20:40 +00009737/*
9738 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9739 */
9740 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009741find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742{
9743 int key;
9744 int modifiers;
9745
9746 /*
9747 * Don't use get_special_key_code() for t_xx, we don't want it to call
9748 * add_termcap_entry().
9749 */
9750 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9751 key = TERMCAP2KEY(arg[2], arg[3]);
9752 else
9753 {
9754 --arg; /* put arg at the '<' */
9755 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009756 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009757 if (modifiers) /* can't handle modifiers here */
9758 key = 0;
9759 }
9760 return key;
9761}
9762
9763/*
9764 * if 'all' == 0: show changed options
9765 * if 'all' == 1: show all normal options
9766 * if 'all' == 2: show all terminal options
9767 */
9768 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009769showoptions(
9770 int all,
9771 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009772{
9773 struct vimoption *p;
9774 int col;
9775 int isterm;
9776 char_u *varp;
9777 struct vimoption **items;
9778 int item_count;
9779 int run;
9780 int row, rows;
9781 int cols;
9782 int i;
9783 int len;
9784
9785#define INC 20
9786#define GAP 3
9787
9788 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9789 PARAM_COUNT));
9790 if (items == NULL)
9791 return;
9792
9793 /* Highlight title */
9794 if (all == 2)
9795 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9796 else if (opt_flags & OPT_GLOBAL)
9797 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9798 else if (opt_flags & OPT_LOCAL)
9799 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9800 else
9801 MSG_PUTS_TITLE(_("\n--- Options ---"));
9802
9803 /*
9804 * do the loop two times:
9805 * 1. display the short items
9806 * 2. display the long items (only strings and numbers)
9807 */
9808 for (run = 1; run <= 2 && !got_int; ++run)
9809 {
9810 /*
9811 * collect the items in items[]
9812 */
9813 item_count = 0;
9814 for (p = &options[0]; p->fullname != NULL; p++)
9815 {
9816 varp = NULL;
9817 isterm = istermoption(p);
9818 if (opt_flags != 0)
9819 {
9820 if (p->indir != PV_NONE && !isterm)
9821 varp = get_varp_scope(p, opt_flags);
9822 }
9823 else
9824 varp = get_varp(p);
9825 if (varp != NULL
9826 && ((all == 2 && isterm)
9827 || (all == 1 && !isterm)
9828 || (all == 0 && !optval_default(p, varp))))
9829 {
9830 if (p->flags & P_BOOL)
9831 len = 1; /* a toggle option fits always */
9832 else
9833 {
9834 option_value2string(p, opt_flags);
9835 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9836 }
9837 if ((len <= INC - GAP && run == 1) ||
9838 (len > INC - GAP && run == 2))
9839 items[item_count++] = p;
9840 }
9841 }
9842
9843 /*
9844 * display the items
9845 */
9846 if (run == 1)
9847 {
9848 cols = (Columns + GAP - 3) / INC;
9849 if (cols == 0)
9850 cols = 1;
9851 rows = (item_count + cols - 1) / cols;
9852 }
9853 else /* run == 2 */
9854 rows = item_count;
9855 for (row = 0; row < rows && !got_int; ++row)
9856 {
9857 msg_putchar('\n'); /* go to next line */
9858 if (got_int) /* 'q' typed in more */
9859 break;
9860 col = 0;
9861 for (i = row; i < item_count; i += rows)
9862 {
9863 msg_col = col; /* make columns */
9864 showoneopt(items[i], opt_flags);
9865 col += INC;
9866 }
9867 out_flush();
9868 ui_breakcheck();
9869 }
9870 }
9871 vim_free(items);
9872}
9873
9874/*
9875 * Return TRUE if option "p" has its default value.
9876 */
9877 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009878optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009879{
9880 int dvi;
9881
9882 if (varp == NULL)
9883 return TRUE; /* hidden option is always at default */
9884 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9885 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009886 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009887 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009888 /* the cast to long is required for Manx C, long_i is
9889 * needed for MSVC */
9890 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009891 /* P_STRING */
9892 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9893}
9894
9895/*
9896 * showoneopt: show the value of one option
9897 * must not be called with a hidden option!
9898 */
9899 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009900showoneopt(
9901 struct vimoption *p,
9902 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009903{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009904 char_u *varp;
9905 int save_silent = silent_mode;
9906
9907 silent_mode = FALSE;
9908 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909
9910 varp = get_varp_scope(p, opt_flags);
9911
9912 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9913 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9914 ? !curbufIsChanged() : !*(int *)varp))
9915 MSG_PUTS("no");
9916 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9917 MSG_PUTS("--");
9918 else
9919 MSG_PUTS(" ");
9920 MSG_PUTS(p->fullname);
9921 if (!(p->flags & P_BOOL))
9922 {
9923 msg_putchar('=');
9924 /* put value string in NameBuff */
9925 option_value2string(p, opt_flags);
9926 msg_outtrans(NameBuff);
9927 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009928
9929 silent_mode = save_silent;
9930 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009931}
9932
9933/*
9934 * Write modified options as ":set" commands to a file.
9935 *
9936 * There are three values for "opt_flags":
9937 * OPT_GLOBAL: Write global option values and fresh values of
9938 * buffer-local options (used for start of a session
9939 * file).
9940 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9941 * curwin (used for a vimrc file).
9942 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9943 * and local values for window-local options of
9944 * curwin. Local values are also written when at the
9945 * default value, because a modeline or autocommand
9946 * may have set them when doing ":edit file" and the
9947 * user has set them back at the default or fresh
9948 * value.
9949 * When "local_only" is TRUE, don't write fresh
9950 * values, only local values (for ":mkview").
9951 * (fresh value = value used for a new buffer or window for a local option).
9952 *
9953 * Return FAIL on error, OK otherwise.
9954 */
9955 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009956makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009957{
9958 struct vimoption *p;
9959 char_u *varp; /* currently used value */
9960 char_u *varp_fresh; /* local value */
9961 char_u *varp_local = NULL; /* fresh value */
9962 char *cmd;
9963 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009964 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965
9966 /*
9967 * The options that don't have a default (terminal name, columns, lines)
9968 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009969 * Do the loop over "options[]" twice: once for options with the
9970 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009971 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009972 for (pri = 1; pri >= 0; --pri)
9973 {
9974 for (p = &options[0]; !istermoption(p); p++)
9975 if (!(p->flags & P_NO_MKRC)
9976 && !istermoption(p)
9977 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978 {
9979 /* skip global option when only doing locals */
9980 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9981 continue;
9982
9983 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9984 * file, they are always buffer-specific. */
9985 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9986 continue;
9987
9988 /* Global values are only written when not at the default value. */
9989 varp = get_varp_scope(p, opt_flags);
9990 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9991 continue;
9992
9993 round = 2;
9994 if (p->indir != PV_NONE)
9995 {
9996 if (p->var == VAR_WIN)
9997 {
9998 /* skip window-local option when only doing globals */
9999 if (!(opt_flags & OPT_LOCAL))
10000 continue;
10001 /* When fresh value of window-local option is not at the
10002 * default, need to write it too. */
10003 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10004 {
10005 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10006 if (!optval_default(p, varp_fresh))
10007 {
10008 round = 1;
10009 varp_local = varp;
10010 varp = varp_fresh;
10011 }
10012 }
10013 }
10014 }
10015
10016 /* Round 1: fresh value for window-local options.
10017 * Round 2: other values */
10018 for ( ; round <= 2; varp = varp_local, ++round)
10019 {
10020 if (round == 1 || (opt_flags & OPT_GLOBAL))
10021 cmd = "set";
10022 else
10023 cmd = "setlocal";
10024
10025 if (p->flags & P_BOOL)
10026 {
10027 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10028 return FAIL;
10029 }
10030 else if (p->flags & P_NUM)
10031 {
10032 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10033 return FAIL;
10034 }
10035 else /* P_STRING */
10036 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010037#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10038 int do_endif = FALSE;
10039
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040 /* Don't set 'syntax' and 'filetype' again if the value is
10041 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010042 if (
10043# if defined(FEAT_SYN_HL)
10044 p->indir == PV_SYN
10045# if defined(FEAT_AUTOCMD)
10046 ||
10047# endif
10048# endif
10049# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010050 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010051# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010052 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010053 {
10054 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10055 *(char_u **)(varp)) < 0
10056 || put_eol(fd) < 0)
10057 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010058 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010059 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010060#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010061 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10062 (p->flags & P_EXPAND) != 0) == FAIL)
10063 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010064#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10065 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066 {
10067 if (put_line(fd, "endif") == FAIL)
10068 return FAIL;
10069 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010070#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010071 }
10072 }
10073 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010074 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010075 return OK;
10076}
10077
10078#if defined(FEAT_FOLDING) || defined(PROTO)
10079/*
10080 * Generate set commands for the local fold options only. Used when
10081 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10082 */
10083 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010084makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010085{
10086 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10087# ifdef FEAT_EVAL
10088 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10089 == FAIL
10090# endif
10091 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10092 == FAIL
10093 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10094 == FAIL
10095 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10096 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10097 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10098 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10099 )
10100 return FAIL;
10101
10102 return OK;
10103}
10104#endif
10105
10106 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010107put_setstring(
10108 FILE *fd,
10109 char *cmd,
10110 char *name,
10111 char_u **valuep,
10112 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010113{
10114 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010115 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116
10117 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10118 return FAIL;
10119 if (*valuep != NULL)
10120 {
10121 /* Output 'pastetoggle' as key names. For other
10122 * options some characters have to be escaped with
10123 * CTRL-V or backslash */
10124 if (valuep == &p_pt)
10125 {
10126 s = *valuep;
10127 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010128 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129 return FAIL;
10130 }
10131 else if (expand)
10132 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010133 buf = alloc(MAXPATHL);
10134 if (buf == NULL)
10135 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010136 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10137 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010138 {
10139 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010141 }
10142 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010143 }
10144 else if (put_escstr(fd, *valuep, 2) == FAIL)
10145 return FAIL;
10146 }
10147 if (put_eol(fd) < 0)
10148 return FAIL;
10149 return OK;
10150}
10151
10152 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010153put_setnum(
10154 FILE *fd,
10155 char *cmd,
10156 char *name,
10157 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010158{
10159 long wc;
10160
10161 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10162 return FAIL;
10163 if (wc_use_keyname((char_u *)valuep, &wc))
10164 {
10165 /* print 'wildchar' and 'wildcharm' as a key name */
10166 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10167 return FAIL;
10168 }
10169 else if (fprintf(fd, "%ld", *valuep) < 0)
10170 return FAIL;
10171 if (put_eol(fd) < 0)
10172 return FAIL;
10173 return OK;
10174}
10175
10176 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010177put_setbool(
10178 FILE *fd,
10179 char *cmd,
10180 char *name,
10181 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182{
Bram Moolenaar893de922007-10-02 18:40:57 +000010183 if (value < 0) /* global/local option using global value */
10184 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10186 || put_eol(fd) < 0)
10187 return FAIL;
10188 return OK;
10189}
10190
10191/*
10192 * Clear all the terminal options.
10193 * If the option has been allocated, free the memory.
10194 * Terminal options are never hidden or indirect.
10195 */
10196 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010197clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010199 /*
10200 * Reset a few things before clearing the old options. This may cause
10201 * outputting a few things that the terminal doesn't understand, but the
10202 * screen will be cleared later, so this is OK.
10203 */
10204#ifdef FEAT_MOUSE_TTY
10205 mch_setmouse(FALSE); /* switch mouse off */
10206#endif
10207#ifdef FEAT_TITLE
10208 mch_restore_title(3); /* restore window titles */
10209#endif
10210#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10211 /* When starting the GUI close the display opened for the clipboard.
10212 * After restoring the title, because that will need the display. */
10213 if (gui.starting)
10214 clear_xterm_clip();
10215#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010216 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010217
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010218 free_termoptions();
10219}
10220
10221 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010222free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010223{
10224 struct vimoption *p;
10225
Bram Moolenaar071d4272004-06-13 20:20:40 +000010226 for (p = &options[0]; p->fullname != NULL; p++)
10227 if (istermoption(p))
10228 {
10229 if (p->flags & P_ALLOCED)
10230 free_string_option(*(char_u **)(p->var));
10231 if (p->flags & P_DEF_ALLOCED)
10232 free_string_option(p->def_val[VI_DEFAULT]);
10233 *(char_u **)(p->var) = empty_option;
10234 p->def_val[VI_DEFAULT] = empty_option;
10235 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10236 }
10237 clear_termcodes();
10238}
10239
10240/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010241 * Free the string for one term option, if it was allocated.
10242 * Set the string to empty_option and clear allocated flag.
10243 * "var" points to the option value.
10244 */
10245 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010246free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010247{
10248 struct vimoption *p;
10249
10250 for (p = &options[0]; p->fullname != NULL; p++)
10251 if (p->var == var)
10252 {
10253 if (p->flags & P_ALLOCED)
10254 free_string_option(*(char_u **)(p->var));
10255 *(char_u **)(p->var) = empty_option;
10256 p->flags &= ~P_ALLOCED;
10257 break;
10258 }
10259}
10260
10261/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 * Set the terminal option defaults to the current value.
10263 * Used after setting the terminal name.
10264 */
10265 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010266set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010267{
10268 struct vimoption *p;
10269
10270 for (p = &options[0]; p->fullname != NULL; p++)
10271 {
10272 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10273 {
10274 if (p->flags & P_DEF_ALLOCED)
10275 {
10276 free_string_option(p->def_val[VI_DEFAULT]);
10277 p->flags &= ~P_DEF_ALLOCED;
10278 }
10279 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10280 if (p->flags & P_ALLOCED)
10281 {
10282 p->flags |= P_DEF_ALLOCED;
10283 p->flags &= ~P_ALLOCED; /* don't free the value now */
10284 }
10285 }
10286 }
10287}
10288
10289/*
10290 * return TRUE if 'p' starts with 't_'
10291 */
10292 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010293istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294{
10295 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10296}
10297
10298/*
10299 * Compute columns for ruler and shown command. 'sc_col' is also used to
10300 * decide what the maximum length of a message on the status line can be.
10301 * If there is a status line for the last window, 'sc_col' is independent
10302 * of 'ru_col'.
10303 */
10304
10305#define COL_RULER 17 /* columns needed by standard ruler */
10306
10307 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010308comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309{
10310#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010311 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312
10313 sc_col = 0;
10314 ru_col = 0;
10315 if (p_ru)
10316 {
10317#ifdef FEAT_STL_OPT
10318 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10319#else
10320 ru_col = COL_RULER + 1;
10321#endif
10322 /* no last status line, adjust sc_col */
10323 if (!last_has_status)
10324 sc_col = ru_col;
10325 }
10326 if (p_sc)
10327 {
10328 sc_col += SHOWCMD_COLS;
10329 if (!p_ru || last_has_status) /* no need for separating space */
10330 ++sc_col;
10331 }
10332 sc_col = Columns - sc_col;
10333 ru_col = Columns - ru_col;
10334 if (sc_col <= 0) /* screen too narrow, will become a mess */
10335 sc_col = 1;
10336 if (ru_col <= 0)
10337 ru_col = 1;
10338#else
10339 sc_col = Columns;
10340 ru_col = Columns;
10341#endif
10342}
10343
10344/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010345 * Unset local option value, similar to ":set opt<".
10346 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010347 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010348unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010349{
10350 struct vimoption *p;
10351 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010352 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010353
10354 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010355 if (opt_idx < 0)
10356 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010357 p = &(options[opt_idx]);
10358
10359 switch ((int)p->indir)
10360 {
10361 /* global option with local value: use local value if it's been set */
10362 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010363 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010364 break;
10365 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010366 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010367 break;
10368 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010369 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010370 break;
10371 case PV_AR:
10372 buf->b_p_ar = -1;
10373 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010374 case PV_BKC:
10375 clear_string_option(&buf->b_p_bkc);
10376 buf->b_bkc_flags = 0;
10377 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010378 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010379 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010380 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010381 case PV_TC:
10382 clear_string_option(&buf->b_p_tc);
10383 buf->b_tc_flags = 0;
10384 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010385#ifdef FEAT_FIND_ID
10386 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010387 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010388 break;
10389 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010390 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010391 break;
10392#endif
10393#ifdef FEAT_INS_EXPAND
10394 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010395 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010396 break;
10397 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010398 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010399 break;
10400#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010401 case PV_FP:
10402 clear_string_option(&buf->b_p_fp);
10403 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010404#ifdef FEAT_QUICKFIX
10405 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010406 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010407 break;
10408 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010409 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010410 break;
10411 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010412 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413 break;
10414#endif
10415#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10416 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010417 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010418 break;
10419#endif
10420#if defined(FEAT_CRYPT)
10421 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010422 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010423 break;
10424#endif
10425#ifdef FEAT_STL_OPT
10426 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010427 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010428 break;
10429#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010430 case PV_UL:
10431 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10432 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010433#ifdef FEAT_LISP
10434 case PV_LW:
10435 clear_string_option(&buf->b_p_lw);
10436 break;
10437#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010438#ifdef FEAT_MBYTE
10439 case PV_MENC:
10440 clear_string_option(&buf->b_p_menc);
10441 break;
10442#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010443 }
10444}
10445
10446/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010447 * Get pointer to option variable, depending on local or global scope.
10448 */
10449 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010450get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451{
10452 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10453 {
10454 if (p->var == VAR_WIN)
10455 return (char_u *)GLOBAL_WO(get_varp(p));
10456 return p->var;
10457 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010458 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459 {
10460 switch ((int)p->indir)
10461 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010462 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010463#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010464 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10465 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10466 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010467#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010468 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10469 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10470 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010471 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010472 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010473 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010474#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010475 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10476 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010477#endif
10478#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010479 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10480 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010482#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10483 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10484#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010485#if defined(FEAT_CRYPT)
10486 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10487#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010488#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010489 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010490#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010491 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010492#ifdef FEAT_LISP
10493 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10494#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010495 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010496#ifdef FEAT_MBYTE
10497 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
10498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499 }
10500 return NULL; /* "cannot happen" */
10501 }
10502 return get_varp(p);
10503}
10504
10505/*
10506 * Get pointer to option variable.
10507 */
10508 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010509get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510{
10511 /* hidden option, always return NULL */
10512 if (p->var == NULL)
10513 return NULL;
10514
10515 switch ((int)p->indir)
10516 {
10517 case PV_NONE: return p->var;
10518
10519 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010520 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010522 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010524 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010525 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010526 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010528 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010530 case PV_TC: return *curbuf->b_p_tc != NUL
10531 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010532 case PV_BKC: return *curbuf->b_p_bkc != NUL
10533 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010535 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010537 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10539#endif
10540#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010541 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010543 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10545#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010546 case PV_FP: return *curbuf->b_p_fp != NUL
10547 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010549 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010550 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010551 case PV_GP: return *curbuf->b_p_gp != NUL
10552 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10553 case PV_MP: return *curbuf->b_p_mp != NUL
10554 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010556#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10557 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10558 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10559#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010560#if defined(FEAT_CRYPT)
10561 case PV_CM: return *curbuf->b_p_cm != NUL
10562 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10563#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010564#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010565 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010566 ? (char_u *)&(curwin->w_p_stl) : p->var;
10567#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010568 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10569 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010570#ifdef FEAT_LISP
10571 case PV_LW: return *curbuf->b_p_lw != NUL
10572 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10573#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010574#ifdef FEAT_MBYTE
10575 case PV_MENC: return *curbuf->b_p_menc != NUL
10576 ? (char_u *)&(curbuf->b_p_menc) : p->var;
10577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578
10579#ifdef FEAT_ARABIC
10580 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10581#endif
10582 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010583#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010584 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10585#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010586#ifdef FEAT_SYN_HL
10587 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10588 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010589 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010590#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591#ifdef FEAT_DIFF
10592 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10593#endif
10594#ifdef FEAT_FOLDING
10595 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10596 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10597 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10598 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10599 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10600 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10601 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10602# ifdef FEAT_EVAL
10603 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10604 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10605# endif
10606 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10607#endif
10608 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010609 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010610#ifdef FEAT_LINEBREAK
10611 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10612#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010613#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010614 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010615 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10618 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10619#endif
10620#ifdef FEAT_RIGHTLEFT
10621 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10622 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10623#endif
10624 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10625 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10626#ifdef FEAT_LINEBREAK
10627 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010628 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10629 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630#endif
10631#ifdef FEAT_SCROLLBIND
10632 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10633#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010634#ifdef FEAT_CURSORBIND
10635 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10636#endif
10637#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010638 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10639 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010640#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010641
10642 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10643 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10644#ifdef FEAT_MBYTE
10645 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10646#endif
10647#if defined(FEAT_QUICKFIX)
10648 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10649 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10650#endif
10651 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10652 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10653#ifdef FEAT_CINDENT
10654 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10655 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10656 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10657#endif
10658#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10659 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10660#endif
10661#ifdef FEAT_COMMENTS
10662 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10663#endif
10664#ifdef FEAT_FOLDING
10665 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10666#endif
10667#ifdef FEAT_INS_EXPAND
10668 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10669#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010670#ifdef FEAT_COMPL_FUNC
10671 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010672 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010673#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010674 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010675 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010676 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10677#ifdef FEAT_MBYTE
10678 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10679#endif
10680 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10681#ifdef FEAT_AUTOCMD
10682 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10683#endif
10684 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010685 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10687 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10688 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10689 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10690#ifdef FEAT_FIND_ID
10691# ifdef FEAT_EVAL
10692 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10693# endif
10694#endif
10695#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10696 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10697 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10698#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010699#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010700 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010702#ifdef FEAT_CRYPT
10703 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10704#endif
10705#ifdef FEAT_LISP
10706 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10707#endif
10708 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10709 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10710 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10711 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10712 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010714#ifdef FEAT_TEXTOBJ
10715 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10716#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010717 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10718#ifdef FEAT_SMARTINDENT
10719 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10720#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010722 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10723#ifdef FEAT_SEARCHPATH
10724 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10725#endif
10726 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10727#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010728 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010729 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10730#endif
10731#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010732 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10733 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10734 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735#endif
10736 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10737 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10738 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10739 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010740#ifdef FEAT_PERSISTENT_UNDO
10741 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10742#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10744#ifdef FEAT_KEYMAP
10745 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10746#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010747#ifdef FEAT_SIGNS
10748 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10749#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010750 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751 }
10752 /* always return a valid pointer to avoid a crash! */
10753 return (char_u *)&(curbuf->b_p_wm);
10754}
10755
10756/*
10757 * Get the value of 'equalprg', either the buffer-local one or the global one.
10758 */
10759 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010760get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761{
10762 if (*curbuf->b_p_ep == NUL)
10763 return p_ep;
10764 return curbuf->b_p_ep;
10765}
10766
10767#if defined(FEAT_WINDOWS) || defined(PROTO)
10768/*
10769 * Copy options from one window to another.
10770 * Used when splitting a window.
10771 */
10772 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010773win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774{
10775 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10776 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10777# ifdef FEAT_RIGHTLEFT
10778# ifdef FEAT_FKMAP
10779 /* Is this right? */
10780 wp_to->w_farsi = wp_from->w_farsi;
10781# endif
10782# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010783#if defined(FEAT_LINEBREAK)
10784 briopt_check(wp_to);
10785#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786}
10787#endif
10788
10789/*
10790 * Copy the options from one winopt_T to another.
10791 * Doesn't free the old option values in "to", use clear_winopt() for that.
10792 * The 'scroll' option is not copied, because it depends on the window height.
10793 * The 'previewwindow' option is reset, there can be only one preview window.
10794 */
10795 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010796copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010797{
10798#ifdef FEAT_ARABIC
10799 to->wo_arab = from->wo_arab;
10800#endif
10801 to->wo_list = from->wo_list;
10802 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010803 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010804#ifdef FEAT_LINEBREAK
10805 to->wo_nuw = from->wo_nuw;
10806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807#ifdef FEAT_RIGHTLEFT
10808 to->wo_rl = from->wo_rl;
10809 to->wo_rlc = vim_strsave(from->wo_rlc);
10810#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010811#ifdef FEAT_STL_OPT
10812 to->wo_stl = vim_strsave(from->wo_stl);
10813#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010814 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010815#ifdef FEAT_DIFF
10816 to->wo_wrap_save = from->wo_wrap_save;
10817#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010818#ifdef FEAT_LINEBREAK
10819 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010820 to->wo_bri = from->wo_bri;
10821 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822#endif
10823#ifdef FEAT_SCROLLBIND
10824 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010825 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010826#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010827#ifdef FEAT_CURSORBIND
10828 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010829 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010830#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010831#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010832 to->wo_spell = from->wo_spell;
10833#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010834#ifdef FEAT_SYN_HL
10835 to->wo_cuc = from->wo_cuc;
10836 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010837 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010838#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839#ifdef FEAT_DIFF
10840 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010841 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010843#ifdef FEAT_CONCEAL
10844 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010845 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010846#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010847#ifdef FEAT_FOLDING
10848 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010849 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010851 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852 to->wo_fdi = vim_strsave(from->wo_fdi);
10853 to->wo_fml = from->wo_fml;
10854 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010855 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010857 to->wo_fdm_save = from->wo_diff_saved
10858 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010859 to->wo_fdn = from->wo_fdn;
10860# ifdef FEAT_EVAL
10861 to->wo_fde = vim_strsave(from->wo_fde);
10862 to->wo_fdt = vim_strsave(from->wo_fdt);
10863# endif
10864 to->wo_fmr = vim_strsave(from->wo_fmr);
10865#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010866#ifdef FEAT_SIGNS
10867 to->wo_scl = vim_strsave(from->wo_scl);
10868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869 check_winopt(to); /* don't want NULL pointers */
10870}
10871
10872/*
10873 * Check string options in a window for a NULL value.
10874 */
10875 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010876check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010877{
10878 check_winopt(&win->w_onebuf_opt);
10879 check_winopt(&win->w_allbuf_opt);
10880}
10881
10882/*
10883 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10884 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010885 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010886check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887{
10888#ifdef FEAT_FOLDING
10889 check_string_option(&wop->wo_fdi);
10890 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010891 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892# ifdef FEAT_EVAL
10893 check_string_option(&wop->wo_fde);
10894 check_string_option(&wop->wo_fdt);
10895# endif
10896 check_string_option(&wop->wo_fmr);
10897#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010898#ifdef FEAT_SIGNS
10899 check_string_option(&wop->wo_scl);
10900#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901#ifdef FEAT_RIGHTLEFT
10902 check_string_option(&wop->wo_rlc);
10903#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010904#ifdef FEAT_STL_OPT
10905 check_string_option(&wop->wo_stl);
10906#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010907#ifdef FEAT_SYN_HL
10908 check_string_option(&wop->wo_cc);
10909#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010910#ifdef FEAT_CONCEAL
10911 check_string_option(&wop->wo_cocu);
10912#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010913#ifdef FEAT_LINEBREAK
10914 check_string_option(&wop->wo_briopt);
10915#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010916}
10917
10918/*
10919 * Free the allocated memory inside a winopt_T.
10920 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010922clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010923{
10924#ifdef FEAT_FOLDING
10925 clear_string_option(&wop->wo_fdi);
10926 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010927 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010928# ifdef FEAT_EVAL
10929 clear_string_option(&wop->wo_fde);
10930 clear_string_option(&wop->wo_fdt);
10931# endif
10932 clear_string_option(&wop->wo_fmr);
10933#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010934#ifdef FEAT_SIGNS
10935 clear_string_option(&wop->wo_scl);
10936#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010937#ifdef FEAT_LINEBREAK
10938 clear_string_option(&wop->wo_briopt);
10939#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940#ifdef FEAT_RIGHTLEFT
10941 clear_string_option(&wop->wo_rlc);
10942#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010943#ifdef FEAT_STL_OPT
10944 clear_string_option(&wop->wo_stl);
10945#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010946#ifdef FEAT_SYN_HL
10947 clear_string_option(&wop->wo_cc);
10948#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010949#ifdef FEAT_CONCEAL
10950 clear_string_option(&wop->wo_cocu);
10951#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010952}
10953
10954/*
10955 * Copy global option values to local options for one buffer.
10956 * Used when creating a new buffer and sometimes when entering a buffer.
10957 * flags:
10958 * BCO_ENTER We will enter the buf buffer.
10959 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10960 * appropriate.
10961 * BCO_NOHELP Don't copy the values to a help buffer.
10962 */
10963 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010964buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010965{
10966 int should_copy = TRUE;
10967 char_u *save_p_isk = NULL; /* init for GCC */
10968 int dont_do_help;
10969 int did_isk = FALSE;
10970
10971 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010972 * Skip this when the option defaults have not been set yet. Happens when
10973 * main() allocates the first buffer.
10974 */
10975 if (p_cpo != NULL)
10976 {
10977 /*
10978 * Always copy when entering and 'cpo' contains 'S'.
10979 * Don't copy when already initialized.
10980 * Don't copy when 'cpo' contains 's' and not entering.
10981 * 'S' BCO_ENTER initialized 's' should_copy
10982 * yes yes X X TRUE
10983 * yes no yes X FALSE
10984 * no X yes X FALSE
10985 * X no no yes FALSE
10986 * X no no no TRUE
10987 * no yes no X TRUE
10988 */
10989 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10990 && (buf->b_p_initialized
10991 || (!(flags & BCO_ENTER)
10992 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10993 should_copy = FALSE;
10994
10995 if (should_copy || (flags & BCO_ALWAYS))
10996 {
10997 /* Don't copy the options specific to a help buffer when
10998 * BCO_NOHELP is given or the options were initialized already
10999 * (jumping back to a help file with CTRL-T or CTRL-O) */
11000 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11001 || buf->b_p_initialized;
11002 if (dont_do_help) /* don't free b_p_isk */
11003 {
11004 save_p_isk = buf->b_p_isk;
11005 buf->b_p_isk = NULL;
11006 }
11007 /*
11008 * Always free the allocated strings.
11009 * If not already initialized, set 'readonly' and copy 'fileformat'.
11010 */
11011 if (!buf->b_p_initialized)
11012 {
11013 free_buf_options(buf, TRUE);
11014 buf->b_p_ro = FALSE; /* don't copy readonly */
11015 buf->b_p_tx = p_tx;
11016#ifdef FEAT_MBYTE
11017 buf->b_p_fenc = vim_strsave(p_fenc);
11018#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011019 switch (*p_ffs)
11020 {
11021 case 'm':
11022 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11023 case 'd':
11024 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11025 case 'u':
11026 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11027 default:
11028 buf->b_p_ff = vim_strsave(p_ff);
11029 }
11030 if (buf->b_p_ff != NULL)
11031 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011032#if defined(FEAT_QUICKFIX)
11033 buf->b_p_bh = empty_option;
11034 buf->b_p_bt = empty_option;
11035#endif
11036 }
11037 else
11038 free_buf_options(buf, FALSE);
11039
11040 buf->b_p_ai = p_ai;
11041 buf->b_p_ai_nopaste = p_ai_nopaste;
11042 buf->b_p_sw = p_sw;
11043 buf->b_p_tw = p_tw;
11044 buf->b_p_tw_nopaste = p_tw_nopaste;
11045 buf->b_p_tw_nobin = p_tw_nobin;
11046 buf->b_p_wm = p_wm;
11047 buf->b_p_wm_nopaste = p_wm_nopaste;
11048 buf->b_p_wm_nobin = p_wm_nobin;
11049 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011050#ifdef FEAT_MBYTE
11051 buf->b_p_bomb = p_bomb;
11052#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011053 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054 buf->b_p_et = p_et;
11055 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011056 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011057 buf->b_p_ml = p_ml;
11058 buf->b_p_ml_nobin = p_ml_nobin;
11059 buf->b_p_inf = p_inf;
11060 buf->b_p_swf = p_swf;
11061#ifdef FEAT_INS_EXPAND
11062 buf->b_p_cpt = vim_strsave(p_cpt);
11063#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011064#ifdef FEAT_COMPL_FUNC
11065 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011066 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011067#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011068 buf->b_p_sts = p_sts;
11069 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011070 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011071#ifdef FEAT_COMMENTS
11072 buf->b_p_com = vim_strsave(p_com);
11073#endif
11074#ifdef FEAT_FOLDING
11075 buf->b_p_cms = vim_strsave(p_cms);
11076#endif
11077 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011078 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079 buf->b_p_nf = vim_strsave(p_nf);
11080 buf->b_p_mps = vim_strsave(p_mps);
11081#ifdef FEAT_SMARTINDENT
11082 buf->b_p_si = p_si;
11083#endif
11084 buf->b_p_ci = p_ci;
11085#ifdef FEAT_CINDENT
11086 buf->b_p_cin = p_cin;
11087 buf->b_p_cink = vim_strsave(p_cink);
11088 buf->b_p_cino = vim_strsave(p_cino);
11089#endif
11090#ifdef FEAT_AUTOCMD
11091 /* Don't copy 'filetype', it must be detected */
11092 buf->b_p_ft = empty_option;
11093#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011094 buf->b_p_pi = p_pi;
11095#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11096 buf->b_p_cinw = vim_strsave(p_cinw);
11097#endif
11098#ifdef FEAT_LISP
11099 buf->b_p_lisp = p_lisp;
11100#endif
11101#ifdef FEAT_SYN_HL
11102 /* Don't copy 'syntax', it must be set */
11103 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011104 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011105 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011106#endif
11107#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011108 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011109 (void)compile_cap_prog(&buf->b_s);
11110 buf->b_s.b_p_spf = vim_strsave(p_spf);
11111 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011112#endif
11113#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11114 buf->b_p_inde = vim_strsave(p_inde);
11115 buf->b_p_indk = vim_strsave(p_indk);
11116#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011117 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011118#if defined(FEAT_EVAL)
11119 buf->b_p_fex = vim_strsave(p_fex);
11120#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011121#ifdef FEAT_CRYPT
11122 buf->b_p_key = vim_strsave(p_key);
11123#endif
11124#ifdef FEAT_SEARCHPATH
11125 buf->b_p_sua = vim_strsave(p_sua);
11126#endif
11127#ifdef FEAT_KEYMAP
11128 buf->b_p_keymap = vim_strsave(p_keymap);
11129 buf->b_kmap_state |= KEYMAP_INIT;
11130#endif
11131 /* This isn't really an option, but copying the langmap and IME
11132 * state from the current buffer is better than resetting it. */
11133 buf->b_p_iminsert = p_iminsert;
11134 buf->b_p_imsearch = p_imsearch;
11135
11136 /* options that are normally global but also have a local value
11137 * are not copied, start using the global value */
11138 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011139 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011140 buf->b_p_bkc = empty_option;
11141 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142#ifdef FEAT_QUICKFIX
11143 buf->b_p_gp = empty_option;
11144 buf->b_p_mp = empty_option;
11145 buf->b_p_efm = empty_option;
11146#endif
11147 buf->b_p_ep = empty_option;
11148 buf->b_p_kp = empty_option;
11149 buf->b_p_path = empty_option;
11150 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011151 buf->b_p_tc = empty_option;
11152 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011153#ifdef FEAT_FIND_ID
11154 buf->b_p_def = empty_option;
11155 buf->b_p_inc = empty_option;
11156# ifdef FEAT_EVAL
11157 buf->b_p_inex = vim_strsave(p_inex);
11158# endif
11159#endif
11160#ifdef FEAT_INS_EXPAND
11161 buf->b_p_dict = empty_option;
11162 buf->b_p_tsr = empty_option;
11163#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011164#ifdef FEAT_TEXTOBJ
11165 buf->b_p_qe = vim_strsave(p_qe);
11166#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011167#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11168 buf->b_p_bexpr = empty_option;
11169#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011170#if defined(FEAT_CRYPT)
11171 buf->b_p_cm = empty_option;
11172#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011173#ifdef FEAT_PERSISTENT_UNDO
11174 buf->b_p_udf = p_udf;
11175#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011176#ifdef FEAT_LISP
11177 buf->b_p_lw = empty_option;
11178#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011179#ifdef FEAT_MBYTE
11180 buf->b_p_menc = empty_option;
11181#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011182
11183 /*
11184 * Don't copy the options set by ex_help(), use the saved values,
11185 * when going from a help buffer to a non-help buffer.
11186 * Don't touch these at all when BCO_NOHELP is used and going from
11187 * or to a help buffer.
11188 */
11189 if (dont_do_help)
11190 buf->b_p_isk = save_p_isk;
11191 else
11192 {
11193 buf->b_p_isk = vim_strsave(p_isk);
11194 did_isk = TRUE;
11195 buf->b_p_ts = p_ts;
11196 buf->b_help = FALSE;
11197#ifdef FEAT_QUICKFIX
11198 if (buf->b_p_bt[0] == 'h')
11199 clear_string_option(&buf->b_p_bt);
11200#endif
11201 buf->b_p_ma = p_ma;
11202 }
11203 }
11204
11205 /*
11206 * When the options should be copied (ignoring BCO_ALWAYS), set the
11207 * flag that indicates that the options have been initialized.
11208 */
11209 if (should_copy)
11210 buf->b_p_initialized = TRUE;
11211 }
11212
11213 check_buf_options(buf); /* make sure we don't have NULLs */
11214 if (did_isk)
11215 (void)buf_init_chartab(buf, FALSE);
11216}
11217
11218/*
11219 * Reset the 'modifiable' option and its default value.
11220 */
11221 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011222reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011223{
11224 int opt_idx;
11225
11226 curbuf->b_p_ma = FALSE;
11227 p_ma = FALSE;
11228 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011229 if (opt_idx >= 0)
11230 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011231}
11232
11233/*
11234 * Set the global value for 'iminsert' to the local value.
11235 */
11236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011237set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011238{
11239 p_iminsert = curbuf->b_p_iminsert;
11240}
11241
11242/*
11243 * Set the global value for 'imsearch' to the local value.
11244 */
11245 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011246set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247{
11248 p_imsearch = curbuf->b_p_imsearch;
11249}
11250
11251#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11252static int expand_option_idx = -1;
11253static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11254static int expand_option_flags = 0;
11255
11256 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011257set_context_in_set_cmd(
11258 expand_T *xp,
11259 char_u *arg,
11260 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011261{
11262 int nextchar;
11263 long_u flags = 0; /* init for GCC */
11264 int opt_idx = 0; /* init for GCC */
11265 char_u *p;
11266 char_u *s;
11267 int is_term_option = FALSE;
11268 int key;
11269
11270 expand_option_flags = opt_flags;
11271
11272 xp->xp_context = EXPAND_SETTINGS;
11273 if (*arg == NUL)
11274 {
11275 xp->xp_pattern = arg;
11276 return;
11277 }
11278 p = arg + STRLEN(arg) - 1;
11279 if (*p == ' ' && *(p - 1) != '\\')
11280 {
11281 xp->xp_pattern = p + 1;
11282 return;
11283 }
11284 while (p > arg)
11285 {
11286 s = p;
11287 /* count number of backslashes before ' ' or ',' */
11288 if (*p == ' ' || *p == ',')
11289 {
11290 while (s > arg && *(s - 1) == '\\')
11291 --s;
11292 }
11293 /* break at a space with an even number of backslashes */
11294 if (*p == ' ' && ((p - s) & 1) == 0)
11295 {
11296 ++p;
11297 break;
11298 }
11299 --p;
11300 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011301 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011302 {
11303 xp->xp_context = EXPAND_BOOL_SETTINGS;
11304 p += 2;
11305 }
11306 if (STRNCMP(p, "inv", 3) == 0)
11307 {
11308 xp->xp_context = EXPAND_BOOL_SETTINGS;
11309 p += 3;
11310 }
11311 xp->xp_pattern = arg = p;
11312 if (*arg == '<')
11313 {
11314 while (*p != '>')
11315 if (*p++ == NUL) /* expand terminal option name */
11316 return;
11317 key = get_special_key_code(arg + 1);
11318 if (key == 0) /* unknown name */
11319 {
11320 xp->xp_context = EXPAND_NOTHING;
11321 return;
11322 }
11323 nextchar = *++p;
11324 is_term_option = TRUE;
11325 expand_option_name[2] = KEY2TERMCAP0(key);
11326 expand_option_name[3] = KEY2TERMCAP1(key);
11327 }
11328 else
11329 {
11330 if (p[0] == 't' && p[1] == '_')
11331 {
11332 p += 2;
11333 if (*p != NUL)
11334 ++p;
11335 if (*p == NUL)
11336 return; /* expand option name */
11337 nextchar = *++p;
11338 is_term_option = TRUE;
11339 expand_option_name[2] = p[-2];
11340 expand_option_name[3] = p[-1];
11341 }
11342 else
11343 {
11344 /* Allow * wildcard */
11345 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11346 p++;
11347 if (*p == NUL)
11348 return;
11349 nextchar = *p;
11350 *p = NUL;
11351 opt_idx = findoption(arg);
11352 *p = nextchar;
11353 if (opt_idx == -1 || options[opt_idx].var == NULL)
11354 {
11355 xp->xp_context = EXPAND_NOTHING;
11356 return;
11357 }
11358 flags = options[opt_idx].flags;
11359 if (flags & P_BOOL)
11360 {
11361 xp->xp_context = EXPAND_NOTHING;
11362 return;
11363 }
11364 }
11365 }
11366 /* handle "-=" and "+=" */
11367 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11368 {
11369 ++p;
11370 nextchar = '=';
11371 }
11372 if ((nextchar != '=' && nextchar != ':')
11373 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11374 {
11375 xp->xp_context = EXPAND_UNSUCCESSFUL;
11376 return;
11377 }
11378 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11379 {
11380 xp->xp_context = EXPAND_OLD_SETTING;
11381 if (is_term_option)
11382 expand_option_idx = -1;
11383 else
11384 expand_option_idx = opt_idx;
11385 xp->xp_pattern = p + 1;
11386 return;
11387 }
11388 xp->xp_context = EXPAND_NOTHING;
11389 if (is_term_option || (flags & P_NUM))
11390 return;
11391
11392 xp->xp_pattern = p + 1;
11393
11394 if (flags & P_EXPAND)
11395 {
11396 p = options[opt_idx].var;
11397 if (p == (char_u *)&p_bdir
11398 || p == (char_u *)&p_dir
11399 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011400 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401 || p == (char_u *)&p_rtp
11402#ifdef FEAT_SEARCHPATH
11403 || p == (char_u *)&p_cdpath
11404#endif
11405#ifdef FEAT_SESSION
11406 || p == (char_u *)&p_vdir
11407#endif
11408 )
11409 {
11410 xp->xp_context = EXPAND_DIRECTORIES;
11411 if (p == (char_u *)&p_path
11412#ifdef FEAT_SEARCHPATH
11413 || p == (char_u *)&p_cdpath
11414#endif
11415 )
11416 xp->xp_backslash = XP_BS_THREE;
11417 else
11418 xp->xp_backslash = XP_BS_ONE;
11419 }
11420 else
11421 {
11422 xp->xp_context = EXPAND_FILES;
11423 /* for 'tags' need three backslashes for a space */
11424 if (p == (char_u *)&p_tags)
11425 xp->xp_backslash = XP_BS_THREE;
11426 else
11427 xp->xp_backslash = XP_BS_ONE;
11428 }
11429 }
11430
11431 /* For an option that is a list of file names, find the start of the
11432 * last file name. */
11433 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11434 {
11435 /* count number of backslashes before ' ' or ',' */
11436 if (*p == ' ' || *p == ',')
11437 {
11438 s = p;
11439 while (s > xp->xp_pattern && *(s - 1) == '\\')
11440 --s;
11441 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11442 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11443 {
11444 xp->xp_pattern = p + 1;
11445 break;
11446 }
11447 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011448
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011449#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011450 /* for 'spellsuggest' start at "file:" */
11451 if (options[opt_idx].var == (char_u *)&p_sps
11452 && STRNCMP(p, "file:", 5) == 0)
11453 {
11454 xp->xp_pattern = p + 5;
11455 break;
11456 }
11457#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011458 }
11459
11460 return;
11461}
11462
11463 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011464ExpandSettings(
11465 expand_T *xp,
11466 regmatch_T *regmatch,
11467 int *num_file,
11468 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011469{
11470 int num_normal = 0; /* Nr of matching non-term-code settings */
11471 int num_term = 0; /* Nr of matching terminal code settings */
11472 int opt_idx;
11473 int match;
11474 int count = 0;
11475 char_u *str;
11476 int loop;
11477 int is_term_opt;
11478 char_u name_buf[MAX_KEY_NAME_LEN];
11479 static char *(names[]) = {"all", "termcap"};
11480 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11481
11482 /* do this loop twice:
11483 * loop == 0: count the number of matching options
11484 * loop == 1: copy the matching options into allocated memory
11485 */
11486 for (loop = 0; loop <= 1; ++loop)
11487 {
11488 regmatch->rm_ic = ic;
11489 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11490 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011491 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11492 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011493 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11494 {
11495 if (loop == 0)
11496 num_normal++;
11497 else
11498 (*file)[count++] = vim_strsave((char_u *)names[match]);
11499 }
11500 }
11501 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11502 opt_idx++)
11503 {
11504 if (options[opt_idx].var == NULL)
11505 continue;
11506 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11507 && !(options[opt_idx].flags & P_BOOL))
11508 continue;
11509 is_term_opt = istermoption(&options[opt_idx]);
11510 if (is_term_opt && num_normal > 0)
11511 continue;
11512 match = FALSE;
11513 if (vim_regexec(regmatch, str, (colnr_T)0)
11514 || (options[opt_idx].shortname != NULL
11515 && vim_regexec(regmatch,
11516 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11517 match = TRUE;
11518 else if (is_term_opt)
11519 {
11520 name_buf[0] = '<';
11521 name_buf[1] = 't';
11522 name_buf[2] = '_';
11523 name_buf[3] = str[2];
11524 name_buf[4] = str[3];
11525 name_buf[5] = '>';
11526 name_buf[6] = NUL;
11527 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11528 {
11529 match = TRUE;
11530 str = name_buf;
11531 }
11532 }
11533 if (match)
11534 {
11535 if (loop == 0)
11536 {
11537 if (is_term_opt)
11538 num_term++;
11539 else
11540 num_normal++;
11541 }
11542 else
11543 (*file)[count++] = vim_strsave(str);
11544 }
11545 }
11546 /*
11547 * Check terminal key codes, these are not in the option table
11548 */
11549 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11550 {
11551 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11552 {
11553 if (!isprint(str[0]) || !isprint(str[1]))
11554 continue;
11555
11556 name_buf[0] = 't';
11557 name_buf[1] = '_';
11558 name_buf[2] = str[0];
11559 name_buf[3] = str[1];
11560 name_buf[4] = NUL;
11561
11562 match = FALSE;
11563 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11564 match = TRUE;
11565 else
11566 {
11567 name_buf[0] = '<';
11568 name_buf[1] = 't';
11569 name_buf[2] = '_';
11570 name_buf[3] = str[0];
11571 name_buf[4] = str[1];
11572 name_buf[5] = '>';
11573 name_buf[6] = NUL;
11574
11575 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11576 match = TRUE;
11577 }
11578 if (match)
11579 {
11580 if (loop == 0)
11581 num_term++;
11582 else
11583 (*file)[count++] = vim_strsave(name_buf);
11584 }
11585 }
11586
11587 /*
11588 * Check special key names.
11589 */
11590 regmatch->rm_ic = TRUE; /* ignore case here */
11591 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11592 {
11593 name_buf[0] = '<';
11594 STRCPY(name_buf + 1, str);
11595 STRCAT(name_buf, ">");
11596
11597 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11598 {
11599 if (loop == 0)
11600 num_term++;
11601 else
11602 (*file)[count++] = vim_strsave(name_buf);
11603 }
11604 }
11605 }
11606 if (loop == 0)
11607 {
11608 if (num_normal > 0)
11609 *num_file = num_normal;
11610 else if (num_term > 0)
11611 *num_file = num_term;
11612 else
11613 return OK;
11614 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11615 if (*file == NULL)
11616 {
11617 *file = (char_u **)"";
11618 return FAIL;
11619 }
11620 }
11621 }
11622 return OK;
11623}
11624
11625 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011626ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011627{
11628 char_u *var = NULL; /* init for GCC */
11629 char_u *buf;
11630
11631 *num_file = 0;
11632 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11633 if (*file == NULL)
11634 return FAIL;
11635
11636 /*
11637 * For a terminal key code expand_option_idx is < 0.
11638 */
11639 if (expand_option_idx < 0)
11640 {
11641 var = find_termcode(expand_option_name + 2);
11642 if (var == NULL)
11643 expand_option_idx = findoption(expand_option_name);
11644 }
11645
11646 if (expand_option_idx >= 0)
11647 {
11648 /* put string of option value in NameBuff */
11649 option_value2string(&options[expand_option_idx], expand_option_flags);
11650 var = NameBuff;
11651 }
11652 else if (var == NULL)
11653 var = (char_u *)"";
11654
11655 /* A backslash is required before some characters. This is the reverse of
11656 * what happens in do_set(). */
11657 buf = vim_strsave_escaped(var, escape_chars);
11658
11659 if (buf == NULL)
11660 {
11661 vim_free(*file);
11662 *file = NULL;
11663 return FAIL;
11664 }
11665
11666#ifdef BACKSLASH_IN_FILENAME
11667 /* For MS-Windows et al. we don't double backslashes at the start and
11668 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011669 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011670 if (var[0] == '\\' && var[1] == '\\'
11671 && expand_option_idx >= 0
11672 && (options[expand_option_idx].flags & P_EXPAND)
11673 && vim_isfilec(var[2])
11674 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011675 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011676#endif
11677
11678 *file[0] = buf;
11679 *num_file = 1;
11680 return OK;
11681}
11682#endif
11683
11684/*
11685 * Get the value for the numeric or string option *opp in a nice format into
11686 * NameBuff[]. Must not be called with a hidden option!
11687 */
11688 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011689option_value2string(
11690 struct vimoption *opp,
11691 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011692{
11693 char_u *varp;
11694
11695 varp = get_varp_scope(opp, opt_flags);
11696
11697 if (opp->flags & P_NUM)
11698 {
11699 long wc = 0;
11700
11701 if (wc_use_keyname(varp, &wc))
11702 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11703 else if (wc != 0)
11704 STRCPY(NameBuff, transchar((int)wc));
11705 else
11706 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11707 }
11708 else /* P_STRING */
11709 {
11710 varp = *(char_u **)(varp);
11711 if (varp == NULL) /* just in case */
11712 NameBuff[0] = NUL;
11713#ifdef FEAT_CRYPT
11714 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011715 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011716 STRCPY(NameBuff, "*****");
11717#endif
11718 else if (opp->flags & P_EXPAND)
11719 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11720 /* Translate 'pastetoggle' into special key names */
11721 else if ((char_u **)opp->var == &p_pt)
11722 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11723 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011724 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011725 }
11726}
11727
11728/*
11729 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11730 * printed as a keyname.
11731 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11732 */
11733 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011734wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735{
11736 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11737 {
11738 *wcp = *(long *)varp;
11739 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11740 return TRUE;
11741 }
11742 return FALSE;
11743}
11744
Bram Moolenaar01615492015-02-03 13:00:38 +010011745#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011747 * Any character has an equivalent 'langmap' character. This is used for
11748 * keyboards that have a special language mode that sends characters above
11749 * 128 (although other characters can be translated too). The "to" field is a
11750 * Vim command character. This avoids having to switch the keyboard back to
11751 * ASCII mode when leaving Insert mode.
11752 *
11753 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11754 * commands.
11755 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11756 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11757 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011758 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011759# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011760/*
11761 * With multi-byte support use growarray for 'langmap' chars >= 256
11762 */
11763typedef struct
11764{
11765 int from;
11766 int to;
11767} langmap_entry_T;
11768
11769static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011770static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771
11772/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011773 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11774 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011775 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011776 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011777langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011778{
11779 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011780 int a = 0;
11781 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011782
11783 /* Do a binary search for an existing entry. */
11784 while (a != b)
11785 {
11786 int i = (a + b) / 2;
11787 int d = entries[i].from - from;
11788
11789 if (d == 0)
11790 {
11791 entries[i].to = to;
11792 return;
11793 }
11794 if (d < 0)
11795 a = i + 1;
11796 else
11797 b = i;
11798 }
11799
11800 if (ga_grow(&langmap_mapga, 1) != OK)
11801 return; /* out of memory */
11802
11803 /* insert new entry at position "a" */
11804 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11805 mch_memmove(entries + 1, entries,
11806 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11807 ++langmap_mapga.ga_len;
11808 entries[0].from = from;
11809 entries[0].to = to;
11810}
11811
11812/*
11813 * Apply 'langmap' to multi-byte character "c" and return the result.
11814 */
11815 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011816langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011817{
11818 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11819 int a = 0;
11820 int b = langmap_mapga.ga_len;
11821
11822 while (a != b)
11823 {
11824 int i = (a + b) / 2;
11825 int d = entries[i].from - c;
11826
11827 if (d == 0)
11828 return entries[i].to; /* found matching entry */
11829 if (d < 0)
11830 a = i + 1;
11831 else
11832 b = i;
11833 }
11834 return c; /* no entry found, return "c" unmodified */
11835}
11836# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837
11838 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011839langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840{
11841 int i;
11842
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011843 for (i = 0; i < 256; i++)
11844 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11845# ifdef FEAT_MBYTE
11846 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11847# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011848}
11849
11850/*
11851 * Called when langmap option is set; the language map can be
11852 * changed at any time!
11853 */
11854 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011855langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856{
11857 char_u *p;
11858 char_u *p2;
11859 int from, to;
11860
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011861#ifdef FEAT_MBYTE
11862 ga_clear(&langmap_mapga); /* clear the previous map first */
11863#endif
11864 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011865
11866 for (p = p_langmap; p[0] != NUL; )
11867 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011868 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11869 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011870 {
11871 if (p2[0] == '\\' && p2[1] != NUL)
11872 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011873 }
11874 if (p2[0] == ';')
11875 ++p2; /* abcd;ABCD form, p2 points to A */
11876 else
11877 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11878 while (p[0])
11879 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011880 if (p[0] == ',')
11881 {
11882 ++p;
11883 break;
11884 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011885 if (p[0] == '\\' && p[1] != NUL)
11886 ++p;
11887#ifdef FEAT_MBYTE
11888 from = (*mb_ptr2char)(p);
11889#else
11890 from = p[0];
11891#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011892 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893 if (p2 == NULL)
11894 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011895 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011896 if (p[0] != ',')
11897 {
11898 if (p[0] == '\\')
11899 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011901 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011903 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011904#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011905 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011906 }
11907 else
11908 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011909 if (p2[0] != ',')
11910 {
11911 if (p2[0] == '\\')
11912 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011913#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011914 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011916 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011917#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919 }
11920 if (to == NUL)
11921 {
11922 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11923 transchar(from));
11924 return;
11925 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011926
11927#ifdef FEAT_MBYTE
11928 if (from >= 256)
11929 langmap_set_entry(from, to);
11930 else
11931#endif
11932 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011933
11934 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011935 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011936 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011937 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011938 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011939 if (*p == ';')
11940 {
11941 p = p2;
11942 if (p[0] != NUL)
11943 {
11944 if (p[0] != ',')
11945 {
11946 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11947 return;
11948 }
11949 ++p;
11950 }
11951 break;
11952 }
11953 }
11954 }
11955 }
11956}
11957#endif
11958
11959/*
11960 * Return TRUE if format option 'x' is in effect.
11961 * Take care of no formatting when 'paste' is set.
11962 */
11963 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011964has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965{
11966 if (p_paste)
11967 return FALSE;
11968 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11969}
11970
11971/*
11972 * Return TRUE if "x" is present in 'shortmess' option, or
11973 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11974 */
11975 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011976shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011978 return p_shm != NULL &&
11979 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980 || (vim_strchr(p_shm, 'a') != NULL
11981 && vim_strchr((char_u *)SHM_A, x) != NULL));
11982}
11983
11984/*
11985 * paste_option_changed() - Called after p_paste was set or reset.
11986 */
11987 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011988paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011989{
11990 static int old_p_paste = FALSE;
11991 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011992 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993#ifdef FEAT_CMDL_INFO
11994 static int save_ru = 0;
11995#endif
11996#ifdef FEAT_RIGHTLEFT
11997 static int save_ri = 0;
11998 static int save_hkmap = 0;
11999#endif
12000 buf_T *buf;
12001
12002 if (p_paste)
12003 {
12004 /*
12005 * Paste switched from off to on.
12006 * Save the current values, so they can be restored later.
12007 */
12008 if (!old_p_paste)
12009 {
12010 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012011 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012 {
12013 buf->b_p_tw_nopaste = buf->b_p_tw;
12014 buf->b_p_wm_nopaste = buf->b_p_wm;
12015 buf->b_p_sts_nopaste = buf->b_p_sts;
12016 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012017 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012018 }
12019
12020 /* save global options */
12021 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012022 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012023#ifdef FEAT_CMDL_INFO
12024 save_ru = p_ru;
12025#endif
12026#ifdef FEAT_RIGHTLEFT
12027 save_ri = p_ri;
12028 save_hkmap = p_hkmap;
12029#endif
12030 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012031 p_ai_nopaste = p_ai;
12032 p_et_nopaste = p_et;
12033 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012034 p_tw_nopaste = p_tw;
12035 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036 }
12037
12038 /*
12039 * Always set the option values, also when 'paste' is set when it is
12040 * already on.
12041 */
12042 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012043 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012044 {
12045 buf->b_p_tw = 0; /* textwidth is 0 */
12046 buf->b_p_wm = 0; /* wrapmargin is 0 */
12047 buf->b_p_sts = 0; /* softtabstop is 0 */
12048 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012049 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012050 }
12051
12052 /* set global options */
12053 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012054 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055#ifdef FEAT_CMDL_INFO
12056# ifdef FEAT_WINDOWS
12057 if (p_ru)
12058 status_redraw_all(); /* redraw to remove the ruler */
12059# endif
12060 p_ru = 0; /* no ruler */
12061#endif
12062#ifdef FEAT_RIGHTLEFT
12063 p_ri = 0; /* no reverse insert */
12064 p_hkmap = 0; /* no Hebrew keyboard */
12065#endif
12066 /* set global values for local buffer options */
12067 p_tw = 0;
12068 p_wm = 0;
12069 p_sts = 0;
12070 p_ai = 0;
12071 }
12072
12073 /*
12074 * Paste switched from on to off: Restore saved values.
12075 */
12076 else if (old_p_paste)
12077 {
12078 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012079 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012080 {
12081 buf->b_p_tw = buf->b_p_tw_nopaste;
12082 buf->b_p_wm = buf->b_p_wm_nopaste;
12083 buf->b_p_sts = buf->b_p_sts_nopaste;
12084 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012085 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086 }
12087
12088 /* restore global options */
12089 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012090 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012091#ifdef FEAT_CMDL_INFO
12092# ifdef FEAT_WINDOWS
12093 if (p_ru != save_ru)
12094 status_redraw_all(); /* redraw to draw the ruler */
12095# endif
12096 p_ru = save_ru;
12097#endif
12098#ifdef FEAT_RIGHTLEFT
12099 p_ri = save_ri;
12100 p_hkmap = save_hkmap;
12101#endif
12102 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012103 p_ai = p_ai_nopaste;
12104 p_et = p_et_nopaste;
12105 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012106 p_tw = p_tw_nopaste;
12107 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108 }
12109
12110 old_p_paste = p_paste;
12111}
12112
12113/*
12114 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12115 *
12116 * Reset 'compatible' and set the values for options that didn't get set yet
12117 * to the Vim defaults.
12118 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012119 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120 */
12121 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012122vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012123{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012124 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012125 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012126 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012127
12128 if (!option_was_set((char_u *)"cp"))
12129 {
12130 p_cp = FALSE;
12131 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12132 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12133 set_option_default(opt_idx, OPT_FREE, FALSE);
12134 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012135 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012137
12138 if (fname != NULL)
12139 {
12140 p = vim_getenv(envname, &dofree);
12141 if (p == NULL)
12142 {
12143 /* Set $MYVIMRC to the first vimrc file found. */
12144 p = FullName_save(fname, FALSE);
12145 if (p != NULL)
12146 {
12147 vim_setenv(envname, p);
12148 vim_free(p);
12149 }
12150 }
12151 else if (dofree)
12152 vim_free(p);
12153 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012154}
12155
12156/*
12157 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12158 */
12159 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012160change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012162 int opt_idx;
12163
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164 if (p_cp != on)
12165 {
12166 p_cp = on;
12167 compatible_set();
12168 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012169 opt_idx = findoption((char_u *)"cp");
12170 if (opt_idx >= 0)
12171 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012172}
12173
12174/*
12175 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012176 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012177 */
12178 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012179option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012180{
12181 int idx;
12182
12183 idx = findoption(name);
12184 if (idx < 0) /* unknown option */
12185 return FALSE;
12186 if (options[idx].flags & P_WAS_SET)
12187 return TRUE;
12188 return FALSE;
12189}
12190
12191/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012192 * Reset the flag indicating option "name" was set.
12193 */
12194 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012195reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012196{
12197 int idx = findoption(name);
12198
12199 if (idx >= 0)
12200 options[idx].flags &= ~P_WAS_SET;
12201}
12202
12203/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012204 * compatible_set() - Called when 'compatible' has been set or unset.
12205 *
12206 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12207 * flag) to a Vi compatible value.
12208 * When 'compatible' is unset: Set all options that have a different default
12209 * for Vim (without the P_VI_DEF flag) to that default.
12210 */
12211 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012212compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012213{
12214 int opt_idx;
12215
12216 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12217 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12218 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12219 set_option_default(opt_idx, OPT_FREE, p_cp);
12220 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012221 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012222}
12223
12224#ifdef FEAT_LINEBREAK
12225
12226# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12227 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012228 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012229# endif
12230
12231/*
12232 * fill_breakat_flags() -- called when 'breakat' changes value.
12233 */
12234 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012235fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012237 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012238 int i;
12239
12240 for (i = 0; i < 256; i++)
12241 breakat_flags[i] = FALSE;
12242
12243 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012244 for (p = p_breakat; *p; p++)
12245 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246}
12247
12248# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012249 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012250# endif
12251
12252#endif
12253
12254/*
12255 * Check an option that can be a range of string values.
12256 *
12257 * Return OK for correct value, FAIL otherwise.
12258 * Empty is always OK.
12259 */
12260 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012261check_opt_strings(
12262 char_u *val,
12263 char **values,
12264 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012265{
12266 return opt_strings_flags(val, values, NULL, list);
12267}
12268
12269/*
12270 * Handle an option that can be a range of string values.
12271 * Set a flag in "*flagp" for each string present.
12272 *
12273 * Return OK for correct value, FAIL otherwise.
12274 * Empty is always OK.
12275 */
12276 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012277opt_strings_flags(
12278 char_u *val, /* new value */
12279 char **values, /* array of valid string values */
12280 unsigned *flagp,
12281 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012282{
12283 int i;
12284 int len;
12285 unsigned new_flags = 0;
12286
12287 while (*val)
12288 {
12289 for (i = 0; ; ++i)
12290 {
12291 if (values[i] == NULL) /* val not found in values[] */
12292 return FAIL;
12293
12294 len = (int)STRLEN(values[i]);
12295 if (STRNCMP(values[i], val, len) == 0
12296 && ((list && val[len] == ',') || val[len] == NUL))
12297 {
12298 val += len + (val[len] == ',');
12299 new_flags |= (1 << i);
12300 break; /* check next item in val list */
12301 }
12302 }
12303 }
12304 if (flagp != NULL)
12305 *flagp = new_flags;
12306
12307 return OK;
12308}
12309
12310/*
12311 * Read the 'wildmode' option, fill wim_flags[].
12312 */
12313 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012314check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012315{
12316 char_u new_wim_flags[4];
12317 char_u *p;
12318 int i;
12319 int idx = 0;
12320
12321 for (i = 0; i < 4; ++i)
12322 new_wim_flags[i] = 0;
12323
12324 for (p = p_wim; *p; ++p)
12325 {
12326 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12327 ;
12328 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12329 return FAIL;
12330 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12331 new_wim_flags[idx] |= WIM_LONGEST;
12332 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12333 new_wim_flags[idx] |= WIM_FULL;
12334 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12335 new_wim_flags[idx] |= WIM_LIST;
12336 else
12337 return FAIL;
12338 p += i;
12339 if (*p == NUL)
12340 break;
12341 if (*p == ',')
12342 {
12343 if (idx == 3)
12344 return FAIL;
12345 ++idx;
12346 }
12347 }
12348
12349 /* fill remaining entries with last flag */
12350 while (idx < 3)
12351 {
12352 new_wim_flags[idx + 1] = new_wim_flags[idx];
12353 ++idx;
12354 }
12355
12356 /* only when there are no errors, wim_flags[] is changed */
12357 for (i = 0; i < 4; ++i)
12358 wim_flags[i] = new_wim_flags[i];
12359 return OK;
12360}
12361
12362/*
12363 * Check if backspacing over something is allowed.
12364 */
12365 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012366can_bs(
12367 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012368{
12369 switch (*p_bs)
12370 {
12371 case '2': return TRUE;
12372 case '1': return (what != BS_START);
12373 case '0': return FALSE;
12374 }
12375 return vim_strchr(p_bs, what) != NULL;
12376}
12377
12378/*
12379 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12380 * the file must be considered changed when the value is different.
12381 */
12382 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012383save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012384{
12385 buf->b_start_ffc = *buf->b_p_ff;
12386 buf->b_start_eol = buf->b_p_eol;
12387#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012388 buf->b_start_bomb = buf->b_p_bomb;
12389
Bram Moolenaar071d4272004-06-13 20:20:40 +000012390 /* Only use free/alloc when necessary, they take time. */
12391 if (buf->b_start_fenc == NULL
12392 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12393 {
12394 vim_free(buf->b_start_fenc);
12395 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12396 }
12397#endif
12398}
12399
12400/*
12401 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12402 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012403 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12404 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012405 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012406 * When "ignore_empty" is true don't consider a new, empty buffer to be
12407 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012408 */
12409 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012410file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012411{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012412 /* In a buffer that was never loaded the options are not valid. */
12413 if (buf->b_flags & BF_NEVERLOADED)
12414 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012415 if (ignore_empty
12416 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012417 && buf->b_ml.ml_line_count == 1
12418 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12419 return FALSE;
12420 if (buf->b_start_ffc != *buf->b_p_ff)
12421 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012422 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012423 return TRUE;
12424#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012425 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12426 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012427 if (buf->b_start_fenc == NULL)
12428 return (*buf->b_p_fenc != NUL);
12429 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12430#else
12431 return FALSE;
12432#endif
12433}
12434
12435/*
12436 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12437 */
12438 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012439check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440{
12441 return check_opt_strings(p, p_ff_values, FALSE);
12442}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012443
12444/*
12445 * Return the effective shiftwidth value for current buffer, using the
12446 * 'tabstop' value when 'shiftwidth' is zero.
12447 */
12448 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012449get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012450{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012451 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012452}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012453
12454/*
12455 * Return the effective softtabstop value for the current buffer, using the
12456 * 'tabstop' value when 'softtabstop' is negative.
12457 */
12458 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012459get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012460{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012461 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012462}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012463
12464/*
12465 * Check matchpairs option for "*initc".
12466 * If there is a match set "*initc" to the matching character and "*findc" to
12467 * the opposite character. Set "*backwards" to the direction.
12468 * When "switchit" is TRUE swap the direction.
12469 */
12470 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012471find_mps_values(
12472 int *initc,
12473 int *findc,
12474 int *backwards,
12475 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012476{
12477 char_u *ptr;
12478
12479 ptr = curbuf->b_p_mps;
12480 while (*ptr != NUL)
12481 {
12482#ifdef FEAT_MBYTE
12483 if (has_mbyte)
12484 {
12485 char_u *prev;
12486
12487 if (mb_ptr2char(ptr) == *initc)
12488 {
12489 if (switchit)
12490 {
12491 *findc = *initc;
12492 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12493 *backwards = TRUE;
12494 }
12495 else
12496 {
12497 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12498 *backwards = FALSE;
12499 }
12500 return;
12501 }
12502 prev = ptr;
12503 ptr += mb_ptr2len(ptr) + 1;
12504 if (mb_ptr2char(ptr) == *initc)
12505 {
12506 if (switchit)
12507 {
12508 *findc = *initc;
12509 *initc = mb_ptr2char(prev);
12510 *backwards = FALSE;
12511 }
12512 else
12513 {
12514 *findc = mb_ptr2char(prev);
12515 *backwards = TRUE;
12516 }
12517 return;
12518 }
12519 ptr += mb_ptr2len(ptr);
12520 }
12521 else
12522#endif
12523 {
12524 if (*ptr == *initc)
12525 {
12526 if (switchit)
12527 {
12528 *backwards = TRUE;
12529 *findc = *initc;
12530 *initc = ptr[2];
12531 }
12532 else
12533 {
12534 *backwards = FALSE;
12535 *findc = ptr[2];
12536 }
12537 return;
12538 }
12539 ptr += 2;
12540 if (*ptr == *initc)
12541 {
12542 if (switchit)
12543 {
12544 *backwards = FALSE;
12545 *findc = *initc;
12546 *initc = ptr[-2];
12547 }
12548 else
12549 {
12550 *backwards = TRUE;
12551 *findc = ptr[-2];
12552 }
12553 return;
12554 }
12555 ++ptr;
12556 }
12557 if (*ptr == ',')
12558 ++ptr;
12559 }
12560}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012561
12562#if defined(FEAT_LINEBREAK) || defined(PROTO)
12563/*
12564 * This is called when 'breakindentopt' is changed and when a window is
12565 * initialized.
12566 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012567 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012568briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012569{
12570 char_u *p;
12571 int bri_shift = 0;
12572 long bri_min = 20;
12573 int bri_sbr = FALSE;
12574
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012575 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012576 while (*p != NUL)
12577 {
12578 if (STRNCMP(p, "shift:", 6) == 0
12579 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12580 {
12581 p += 6;
12582 bri_shift = getdigits(&p);
12583 }
12584 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12585 {
12586 p += 4;
12587 bri_min = getdigits(&p);
12588 }
12589 else if (STRNCMP(p, "sbr", 3) == 0)
12590 {
12591 p += 3;
12592 bri_sbr = TRUE;
12593 }
12594 if (*p != ',' && *p != NUL)
12595 return FAIL;
12596 if (*p == ',')
12597 ++p;
12598 }
12599
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012600 wp->w_p_brishift = bri_shift;
12601 wp->w_p_brimin = bri_min;
12602 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012603
12604 return OK;
12605}
12606#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012607
12608/*
12609 * Get the local or global value of 'backupcopy'.
12610 */
12611 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012612get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012613{
12614 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12615}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012616
12617#if defined(FEAT_SIGNS) || defined(PROTO)
12618/*
12619 * Return TRUE when window "wp" has a column to draw signs in.
12620 */
12621 int
12622signcolumn_on(win_T *wp)
12623{
12624 if (*wp->w_p_scl == 'n')
12625 return FALSE;
12626 if (*wp->w_p_scl == 'y')
12627 return TRUE;
12628 return (wp->w_buffer->b_signlist != NULL
12629# ifdef FEAT_NETBEANS_INTG
12630 || wp->w_buffer->b_has_sign_column
12631# endif
12632 );
12633}
12634#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012635
12636#if defined(FEAT_EVAL) || defined(PROTO)
12637/*
12638 * Get window or buffer local options.
12639 */
12640 dict_T *
12641get_winbuf_options(int bufopt)
12642{
12643 dict_T *d;
12644 int opt_idx;
12645
12646 d = dict_alloc();
12647 if (d == NULL)
12648 return NULL;
12649
12650 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12651 {
12652 struct vimoption *opt = &options[opt_idx];
12653
12654 if ((bufopt && (opt->indir & PV_BUF))
12655 || (!bufopt && (opt->indir & PV_WIN)))
12656 {
12657 char_u *varp = get_varp(opt);
12658
12659 if (varp != NULL)
12660 {
12661 if (opt->flags & P_STRING)
12662 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012663 else if (opt->flags & P_NUM)
12664 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012665 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012666 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012667 }
12668 }
12669 }
12670
12671 return d;
12672}
12673#endif