blob: 6f9610dd0f8866b48d44c6ff4d030d09d4204d4b [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
142#define PV_MA OPT_BUF(BV_MA)
143#define PV_ML OPT_BUF(BV_ML)
144#define PV_MOD OPT_BUF(BV_MOD)
145#define PV_MPS OPT_BUF(BV_MPS)
146#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000147#ifdef FEAT_COMPL_FUNC
148# define PV_OFU OPT_BUF(BV_OFU)
149#endif
150#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
151#define PV_PI OPT_BUF(BV_PI)
152#ifdef FEAT_TEXTOBJ
153# define PV_QE OPT_BUF(BV_QE)
154#endif
155#define PV_RO OPT_BUF(BV_RO)
156#ifdef FEAT_SMARTINDENT
157# define PV_SI OPT_BUF(BV_SI)
158#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100159#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000160#ifdef FEAT_SYN_HL
161# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000162# define PV_SYN OPT_BUF(BV_SYN)
163#endif
164#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000165# define PV_SPC OPT_BUF(BV_SPC)
166# define PV_SPF OPT_BUF(BV_SPF)
167# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168#endif
169#define PV_STS OPT_BUF(BV_STS)
170#ifdef FEAT_SEARCHPATH
171# define PV_SUA OPT_BUF(BV_SUA)
172#endif
173#define PV_SW OPT_BUF(BV_SW)
174#define PV_SWF OPT_BUF(BV_SWF)
175#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100176#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000177#define PV_TS OPT_BUF(BV_TS)
178#define PV_TW OPT_BUF(BV_TW)
179#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200180#ifdef FEAT_PERSISTENT_UNDO
181# define PV_UDF OPT_BUF(BV_UDF)
182#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000184
185/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186 * Definition of the PV_ values for window-local options.
187 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189#define PV_LIST OPT_WIN(WV_LIST)
190#ifdef FEAT_ARABIC
191# define PV_ARAB OPT_WIN(WV_ARAB)
192#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200193#ifdef FEAT_LINEBREAK
194# define PV_BRI OPT_WIN(WV_BRI)
195# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
196#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000197#ifdef FEAT_DIFF
198# define PV_DIFF OPT_WIN(WV_DIFF)
199#endif
200#ifdef FEAT_FOLDING
201# define PV_FDC OPT_WIN(WV_FDC)
202# define PV_FEN OPT_WIN(WV_FEN)
203# define PV_FDI OPT_WIN(WV_FDI)
204# define PV_FDL OPT_WIN(WV_FDL)
205# define PV_FDM OPT_WIN(WV_FDM)
206# define PV_FML OPT_WIN(WV_FML)
207# define PV_FDN OPT_WIN(WV_FDN)
208# ifdef FEAT_EVAL
209# define PV_FDE OPT_WIN(WV_FDE)
210# define PV_FDT OPT_WIN(WV_FDT)
211# endif
212# define PV_FMR OPT_WIN(WV_FMR)
213#endif
214#ifdef FEAT_LINEBREAK
215# define PV_LBR OPT_WIN(WV_LBR)
216#endif
217#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200218#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000219#ifdef FEAT_LINEBREAK
220# define PV_NUW OPT_WIN(WV_NUW)
221#endif
222#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
223# define PV_PVW OPT_WIN(WV_PVW)
224#endif
225#ifdef FEAT_RIGHTLEFT
226# define PV_RL OPT_WIN(WV_RL)
227# define PV_RLC OPT_WIN(WV_RLC)
228#endif
229#ifdef FEAT_SCROLLBIND
230# define PV_SCBIND OPT_WIN(WV_SCBIND)
231#endif
232#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000233#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000234# define PV_SPELL OPT_WIN(WV_SPELL)
235#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SYN_HL
237# define PV_CUC OPT_WIN(WV_CUC)
238# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200239# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000240#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000241#ifdef FEAT_STL_OPT
242# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
243#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100244#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000245#ifdef FEAT_WINDOWS
246# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000247# define PV_WFW OPT_WIN(WV_WFW)
248#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000249#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200250#ifdef FEAT_CURSORBIND
251# define PV_CRBIND OPT_WIN(WV_CRBIND)
252#endif
253#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200254# define PV_COCU OPT_WIN(WV_COCU)
255# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200256#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200257#ifdef FEAT_SIGNS
258# define PV_SCL OPT_WIN(WV_SCL)
259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000260
261/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262typedef enum
263{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000264 PV_NONE = 0,
265 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266} idopt_T;
267
268/*
269 * Options local to a window have a value local to a buffer and global to all
270 * buffers. Indicate this by setting "var" to VAR_WIN.
271 */
272#define VAR_WIN ((char_u *)-1)
273
274/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000275 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 * Only to be used in option.c!
277 */
278static int p_ai;
279static int p_bin;
280#ifdef FEAT_MBYTE
281static int p_bomb;
282#endif
283#if defined(FEAT_QUICKFIX)
284static char_u *p_bh;
285static char_u *p_bt;
286#endif
287static int p_bl;
288static int p_ci;
289#ifdef FEAT_CINDENT
290static int p_cin;
291static char_u *p_cink;
292static char_u *p_cino;
293#endif
294#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
295static char_u *p_cinw;
296#endif
297#ifdef FEAT_COMMENTS
298static char_u *p_com;
299#endif
300#ifdef FEAT_FOLDING
301static char_u *p_cms;
302#endif
303#ifdef FEAT_INS_EXPAND
304static char_u *p_cpt;
305#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#ifdef FEAT_COMPL_FUNC
307static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000308static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200311static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static int p_et;
313#ifdef FEAT_MBYTE
314static char_u *p_fenc;
315#endif
316static char_u *p_ff;
317static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000318static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319#ifdef FEAT_AUTOCMD
320static char_u *p_ft;
321#endif
322static long p_iminsert;
323static long p_imsearch;
324#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
325static char_u *p_inex;
326#endif
327#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
328static char_u *p_inde;
329static char_u *p_indk;
330#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000331#if defined(FEAT_EVAL)
332static char_u *p_fex;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_inf;
335static char_u *p_isk;
336#ifdef FEAT_CRYPT
337static char_u *p_key;
338#endif
339#ifdef FEAT_LISP
340static int p_lisp;
341#endif
342static int p_ml;
343static int p_ma;
344static int p_mod;
345static char_u *p_mps;
346static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000348#ifdef FEAT_TEXTOBJ
349static char_u *p_qe;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_ro;
352#ifdef FEAT_SMARTINDENT
353static int p_si;
354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static long p_sts;
357#if defined(FEAT_SEARCHPATH)
358static char_u *p_sua;
359#endif
360static long p_sw;
361static int p_swf;
362#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000363static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000365#endif
366#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000367static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000368static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000369static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370#endif
371static long p_ts;
372static long p_tw;
373static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200374#ifdef FEAT_PERSISTENT_UNDO
375static int p_udf;
376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377static long p_wm;
378#ifdef FEAT_KEYMAP
379static char_u *p_keymap;
380#endif
381
382/* Saved values for when 'bin' is set. */
383static int p_et_nobin;
384static int p_ml_nobin;
385static long p_tw_nobin;
386static long p_wm_nobin;
387
388/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200389static int p_ai_nopaste;
390static int p_et_nopaste;
391static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392static long p_tw_nopaste;
393static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394
395struct vimoption
396{
397 char *fullname; /* full option name */
398 char *shortname; /* permissible abbreviation */
399 long_u flags; /* see below */
400 char_u *var; /* global option: pointer to variable;
401 * window-local option: VAR_WIN;
402 * buffer-local option: global value */
403 idopt_T indir; /* global option: PV_NONE;
404 * local option: indirect option index */
405 char_u *def_val[2]; /* default values for variable (vi and vim) */
406#ifdef FEAT_EVAL
407 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000408# define SCRIPTID_INIT , 0
409#else
410# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411#endif
412};
413
414#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
415#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
416
417/*
418 * Flags
419 */
420#define P_BOOL 0x01 /* the option is boolean */
421#define P_NUM 0x02 /* the option is numeric */
422#define P_STRING 0x04 /* the option is a string */
423#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000424 must use free_string_option() when
425 assigning new value. Not set if default is
426 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
428 never be used for local or hidden options! */
429#define P_NODEFAULT 0x40 /* don't set to default value */
430#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
431 use vim_free() when assigning new value */
432#define P_WAS_SET 0x100 /* option has been set/reset */
433#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
434#define P_VI_DEF 0x400 /* Use Vi default for Vim */
435#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
436
437 /* when option changed, what to display: */
438#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100439#define P_RWIN 0x2000 /* redraw current window and recompute text */
440#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000441#define P_RALL 0x6000 /* redraw all windows */
442#define P_RCLR 0x7000 /* clear and redraw all */
443
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200444#define P_COMMA 0x8000 /* comma separated list */
445#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
446 * commas */
447#define P_NODUP 0x20000L /* don't allow duplicate strings */
448#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200450#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
451#define P_GETTEXT 0x100000L /* expand default value with _() */
452#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
453#define P_NFNAME 0x400000L /* only normal file name chars allowed */
454#define P_INSECURE 0x800000L /* option was set from a modeline */
455#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100456 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200457#define P_NO_ML 0x2000000L /* not allowed in modeline */
458#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200459 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100460#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100461#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000462
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000463#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
464
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000465/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
466 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100467#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000468# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000469#else
470# define ISP_LATIN1 (char_u *)"@,161-255"
471#endif
472
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100473/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000474#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100475 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200476 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar58b85342016-08-14 19:54:54 +0200477# 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 +0000478#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100479# 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 +0000480#endif
481
Bram Moolenaar071d4272004-06-13 20:20:40 +0000482/*
483 * options[] is initialized here.
484 * The order of the options MUST be alphabetic for ":set all" and findoption().
485 * All option names MUST start with a lowercase letter (for findoption()).
486 * Exception: "t_" options are at the end.
487 * The options with a NULL variable are 'hidden': a set command for them is
488 * ignored and they are not printed.
489 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100490static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000491{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200492 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000493#ifdef FEAT_RIGHTLEFT
494 (char_u *)&p_aleph, PV_NONE,
495#else
496 (char_u *)NULL, PV_NONE,
497#endif
498 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100499#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000500 (char_u *)128L,
501#else
502 (char_u *)224L,
503#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000504 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
506#if defined(FEAT_GUI) && defined(MACOS_X)
507 (char_u *)&p_antialias, PV_NONE,
508 {(char_u *)FALSE, (char_u *)FALSE}
509#else
510 (char_u *)NULL, PV_NONE,
511 {(char_u *)FALSE, (char_u *)FALSE}
512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000513 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200514 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515#ifdef FEAT_ARABIC
516 (char_u *)VAR_WIN, PV_ARAB,
517#else
518 (char_u *)NULL, PV_NONE,
519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000520 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000521 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
522#ifdef FEAT_ARABIC
523 (char_u *)&p_arshape, PV_NONE,
524#else
525 (char_u *)NULL, PV_NONE,
526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000527 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
529#ifdef FEAT_RIGHTLEFT
530 (char_u *)&p_ari, PV_NONE,
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 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
536#ifdef FEAT_FKMAP
537 (char_u *)&p_altkeymap, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
543#if defined(FEAT_MBYTE)
544 (char_u *)&p_ambw, PV_NONE,
545 {(char_u *)"single", (char_u *)0L}
546#else
547 (char_u *)NULL, PV_NONE,
548 {(char_u *)0L, (char_u *)0L}
549#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000550 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000551#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 {"autochdir", "acd", P_BOOL|P_VI_DEF,
553 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000554 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555#endif
556 {"autoindent", "ai", P_BOOL|P_VI_DEF,
557 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000558 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autoprint", "ap", P_BOOL|P_VI_DEF,
560 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000563 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000564 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autowrite", "aw", P_BOOL|P_VI_DEF,
566 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000567 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autowriteall","awa", P_BOOL|P_VI_DEF,
569 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000570 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
572 (char_u *)&p_bg, PV_NONE,
573 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100574#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 (char_u *)"dark",
576#else
577 (char_u *)"light",
578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200580 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
584 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200586 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200587 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000588#ifdef UNIX
589 {(char_u *)"yes", (char_u *)"auto"}
590#else
591 {(char_u *)"auto", (char_u *)"auto"}
592#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200594 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
595 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000597 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000598 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bex, PV_NONE,
600 {
601#ifdef VMS
602 (char_u *)"_",
603#else
604 (char_u *)"~",
605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000606 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200607 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608#ifdef FEAT_WILDIGN
609 (char_u *)&p_bsk, PV_NONE,
610 {(char_u *)"", (char_u *)0L}
611#else
612 (char_u *)NULL, PV_NONE,
613 {(char_u *)0L, (char_u *)0L}
614#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000615 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000616#ifdef FEAT_BEVAL
617 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
618 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000619 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000620 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
621 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000622 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000623# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000624 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000625 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000627# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628#endif
629 {"beautify", "bf", P_BOOL|P_VI_DEF,
630 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000631 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200632 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
633 (char_u *)&p_bo, PV_NONE,
634 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
636 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000640 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000641 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
642#ifdef FEAT_MBYTE
643 (char_u *)&p_bomb, PV_BOMB,
644#else
645 (char_u *)NULL, PV_NONE,
646#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000647 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000648 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
649#ifdef FEAT_LINEBREAK
650 (char_u *)&p_breakat, PV_NONE,
651 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
652#else
653 (char_u *)NULL, PV_NONE,
654 {(char_u *)0L, (char_u *)0L}
655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200657 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
658#ifdef FEAT_LINEBREAK
659 (char_u *)VAR_WIN, PV_BRI,
660 {(char_u *)FALSE, (char_u *)0L}
661#else
662 (char_u *)NULL, PV_NONE,
663 {(char_u *)0L, (char_u *)0L}
664#endif
665 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200666 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
667 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200668#ifdef FEAT_LINEBREAK
669 (char_u *)VAR_WIN, PV_BRIOPT,
670 {(char_u *)"", (char_u *)NULL}
671#else
672 (char_u *)NULL, PV_NONE,
673 {(char_u *)"", (char_u *)NULL}
674#endif
675 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
677#ifdef FEAT_BROWSE
678 (char_u *)&p_bsdir, PV_NONE,
679 {(char_u *)"last", (char_u *)0L}
680#else
681 (char_u *)NULL, PV_NONE,
682 {(char_u *)0L, (char_u *)0L}
683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000684 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000685 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
686#if defined(FEAT_QUICKFIX)
687 (char_u *)&p_bh, PV_BH,
688 {(char_u *)"", (char_u *)0L}
689#else
690 (char_u *)NULL, PV_NONE,
691 {(char_u *)0L, (char_u *)0L}
692#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000693 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000694 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
695 (char_u *)&p_bl, PV_BL,
696 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000697 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000698 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
699#if defined(FEAT_QUICKFIX)
700 (char_u *)&p_bt, PV_BT,
701 {(char_u *)"", (char_u *)0L}
702#else
703 (char_u *)NULL, PV_NONE,
704 {(char_u *)0L, (char_u *)0L}
705#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000706 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200707 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000708#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709 (char_u *)&p_cmp, PV_NONE,
710 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000711#else
712 (char_u *)NULL, PV_NONE,
713 {(char_u *)0L, (char_u *)0L}
714#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000715 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
717#ifdef FEAT_SEARCHPATH
718 (char_u *)&p_cdpath, PV_NONE,
719 {(char_u *)",,", (char_u *)0L}
720#else
721 (char_u *)NULL, PV_NONE,
722 {(char_u *)0L, (char_u *)0L}
723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000724 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 {"cedit", NULL, P_STRING,
726#ifdef FEAT_CMDWIN
727 (char_u *)&p_cedit, PV_NONE,
728 {(char_u *)"", (char_u *)CTRL_F_STR}
729#else
730 (char_u *)NULL, PV_NONE,
731 {(char_u *)0L, (char_u *)0L}
732#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000733 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
735#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
736 (char_u *)&p_ccv, PV_NONE,
737 {(char_u *)"", (char_u *)0L}
738#else
739 (char_u *)NULL, PV_NONE,
740 {(char_u *)0L, (char_u *)0L}
741#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000742 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000743 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
744#ifdef FEAT_CINDENT
745 (char_u *)&p_cin, PV_CIN,
746#else
747 (char_u *)NULL, PV_NONE,
748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000749 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200750 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751#ifdef FEAT_CINDENT
752 (char_u *)&p_cink, PV_CINK,
753 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
754#else
755 (char_u *)NULL, PV_NONE,
756 {(char_u *)0L, (char_u *)0L}
757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000758 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200759 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000760#ifdef FEAT_CINDENT
761 (char_u *)&p_cino, PV_CINO,
762#else
763 (char_u *)NULL, PV_NONE,
764#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000765 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200766 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
768 (char_u *)&p_cinw, PV_CINW,
769 {(char_u *)"if,else,while,do,for,switch",
770 (char_u *)0L}
771#else
772 (char_u *)NULL, PV_NONE,
773 {(char_u *)0L, (char_u *)0L}
774#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000775 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200776 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000777#ifdef FEAT_CLIPBOARD
778 (char_u *)&p_cb, PV_NONE,
779# ifdef FEAT_XCLIPBOARD
780 {(char_u *)"autoselect,exclude:cons\\|linux",
781 (char_u *)0L}
782# else
783 {(char_u *)"", (char_u *)0L}
784# endif
785#else
786 (char_u *)NULL, PV_NONE,
787 {(char_u *)"", (char_u *)0L}
788#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000789 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
791 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000792 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
794#ifdef FEAT_CMDWIN
795 (char_u *)&p_cwh, PV_NONE,
796#else
797 (char_u *)NULL, PV_NONE,
798#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000799 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200800 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200801#ifdef FEAT_SYN_HL
802 (char_u *)VAR_WIN, PV_CC,
803#else
804 (char_u *)NULL, PV_NONE,
805#endif
806 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000807 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
808 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000809 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200810 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
811 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000812#ifdef FEAT_COMMENTS
813 (char_u *)&p_com, PV_COM,
814 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
815 (char_u *)0L}
816#else
817 (char_u *)NULL, PV_NONE,
818 {(char_u *)0L, (char_u *)0L}
819#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000820 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200821 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822#ifdef FEAT_FOLDING
823 (char_u *)&p_cms, PV_CMS,
824 {(char_u *)"/*%s*/", (char_u *)0L}
825#else
826 (char_u *)NULL, PV_NONE,
827 {(char_u *)0L, (char_u *)0L}
828#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000829 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000830 /* P_PRI_MKRC isn't needed here, optval_default()
831 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832 {"compatible", "cp", P_BOOL|P_RALL,
833 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000834 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200835 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836#ifdef FEAT_INS_EXPAND
837 (char_u *)&p_cpt, PV_CPT,
838 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
839#else
840 (char_u *)NULL, PV_NONE,
841 {(char_u *)0L, (char_u *)0L}
842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000843 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200844 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200845#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200846 (char_u *)VAR_WIN, PV_COCU,
847 {(char_u *)"", (char_u *)NULL}
848#else
849 (char_u *)NULL, PV_NONE,
850 {(char_u *)NULL, (char_u *)0L}
851#endif
852 SCRIPTID_INIT},
853 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
854#ifdef FEAT_CONCEAL
855 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200856#else
857 (char_u *)NULL, PV_NONE,
858#endif
859 {(char_u *)0L, (char_u *)0L}
860 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000861 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
862#ifdef FEAT_COMPL_FUNC
863 (char_u *)&p_cfu, PV_CFU,
864 {(char_u *)"", (char_u *)0L}
865#else
866 (char_u *)NULL, PV_NONE,
867 {(char_u *)0L, (char_u *)0L}
868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000869 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200870 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000871#ifdef FEAT_INS_EXPAND
872 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000873 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)0L, (char_u *)0L}
877#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000878 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000879 {"confirm", "cf", P_BOOL|P_VI_DEF,
880#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
881 (char_u *)&p_confirm, PV_NONE,
882#else
883 (char_u *)NULL, PV_NONE,
884#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000885 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000888 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000889 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
890 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
893 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
895 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200896 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200897#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200898 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200899 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200900#else
901 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200902 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200903#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200904 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
906#ifdef FEAT_CSCOPE
907 (char_u *)&p_cspc, PV_NONE,
908#else
909 (char_u *)NULL, PV_NONE,
910#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000911 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
913#ifdef FEAT_CSCOPE
914 (char_u *)&p_csprg, PV_NONE,
915 {(char_u *)"cscope", (char_u *)0L}
916#else
917 (char_u *)NULL, PV_NONE,
918 {(char_u *)0L, (char_u *)0L}
919#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200921 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000922#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
923 (char_u *)&p_csqf, PV_NONE,
924 {(char_u *)"", (char_u *)0L}
925#else
926 (char_u *)NULL, PV_NONE,
927 {(char_u *)0L, (char_u *)0L}
928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000929 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200930 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
931#ifdef FEAT_CSCOPE
932 (char_u *)&p_csre, PV_NONE,
933#else
934 (char_u *)NULL, PV_NONE,
935#endif
936 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_cst, 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 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
945#ifdef FEAT_CSCOPE
946 (char_u *)&p_csto, PV_NONE,
947#else
948 (char_u *)NULL, PV_NONE,
949#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000950 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000951 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
952#ifdef FEAT_CSCOPE
953 (char_u *)&p_csverbose, PV_NONE,
954#else
955 (char_u *)NULL, PV_NONE,
956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000957 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200958 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
959#ifdef FEAT_CURSORBIND
960 (char_u *)VAR_WIN, PV_CRBIND,
961#else
962 (char_u *)NULL, PV_NONE,
963#endif
964 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000965 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
966#ifdef FEAT_SYN_HL
967 (char_u *)VAR_WIN, PV_CUC,
968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000971 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100972 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000973#ifdef FEAT_SYN_HL
974 (char_u *)VAR_WIN, PV_CUL,
975#else
976 (char_u *)NULL, PV_NONE,
977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000978 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000979 {"debug", NULL, P_STRING|P_VI_DEF,
980 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000981 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200982 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000983#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000984 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000985 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986#else
987 (char_u *)NULL, PV_NONE,
988 {(char_u *)NULL, (char_u *)0L}
989#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000990 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
992#ifdef FEAT_MBYTE
993 (char_u *)&p_deco, PV_NONE,
994#else
995 (char_u *)NULL, PV_NONE,
996#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000997 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +0100998 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000999#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001000 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001#else
1002 (char_u *)NULL, PV_NONE,
1003#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001004 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1006#ifdef FEAT_DIFF
1007 (char_u *)VAR_WIN, PV_DIFF,
1008#else
1009 (char_u *)NULL, PV_NONE,
1010#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001011 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001012 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1014 (char_u *)&p_dex, PV_NONE,
1015 {(char_u *)"", (char_u *)0L}
1016#else
1017 (char_u *)NULL, PV_NONE,
1018 {(char_u *)0L, (char_u *)0L}
1019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001020 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001021 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1022 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001023#ifdef FEAT_DIFF
1024 (char_u *)&p_dip, PV_NONE,
1025 {(char_u *)"filler", (char_u *)NULL}
1026#else
1027 (char_u *)NULL, PV_NONE,
1028 {(char_u *)"", (char_u *)NULL}
1029#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001030 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1032#ifdef FEAT_DIGRAPHS
1033 (char_u *)&p_dg, PV_NONE,
1034#else
1035 (char_u *)NULL, PV_NONE,
1036#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001037 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001038 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1039 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001042 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001044 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001046#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 (char_u *)&p_ead, PV_NONE,
1048 {(char_u *)"both", (char_u *)0L}
1049#else
1050 (char_u *)NULL, PV_NONE,
1051 {(char_u *)NULL, (char_u *)0L}
1052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001053 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1055 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001057 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1058#if defined(FEAT_MBYTE)
1059 (char_u *)&p_emoji, PV_NONE,
1060 {(char_u *)TRUE, (char_u *)0L}
1061#else
1062 (char_u *)NULL, PV_NONE,
1063 {(char_u *)0L, (char_u *)0L}
1064#endif
1065 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001066 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067#ifdef FEAT_MBYTE
1068 (char_u *)&p_enc, PV_NONE,
1069 {(char_u *)ENC_DFLT, (char_u *)0L}
1070#else
1071 (char_u *)NULL, PV_NONE,
1072 {(char_u *)0L, (char_u *)0L}
1073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001074 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1076 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001077 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1079 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001080 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001082 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1085 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001086 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001087 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1088#ifdef FEAT_QUICKFIX
1089 (char_u *)&p_ef, PV_NONE,
1090 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1091#else
1092 (char_u *)NULL, PV_NONE,
1093 {(char_u *)NULL, (char_u *)0L}
1094#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001095 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001096 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001098 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100#else
1101 (char_u *)NULL, PV_NONE,
1102 {(char_u *)NULL, (char_u *)0L}
1103#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001104 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"esckeys", "ek", P_BOOL|P_VIM,
1106 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001107 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001108 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109#ifdef FEAT_AUTOCMD
1110 (char_u *)&p_ei, PV_NONE,
1111#else
1112 (char_u *)NULL, PV_NONE,
1113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001114 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1116 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001117 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001118 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1119 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001120 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001121 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1122 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123#ifdef FEAT_MBYTE
1124 (char_u *)&p_fenc, PV_FENC,
1125 {(char_u *)"", (char_u *)0L}
1126#else
1127 (char_u *)NULL, PV_NONE,
1128 {(char_u *)0L, (char_u *)0L}
1129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001130 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001131 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132#ifdef FEAT_MBYTE
1133 (char_u *)&p_fencs, PV_NONE,
1134 {(char_u *)"ucs-bom", (char_u *)0L}
1135#else
1136 (char_u *)NULL, PV_NONE,
1137 {(char_u *)0L, (char_u *)0L}
1138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1141 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001144 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1147 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001148 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1149 (char_u *)&p_fic, PV_NONE,
1150 {
1151#ifdef CASE_INSENSITIVE_FILENAME
1152 (char_u *)TRUE,
1153#else
1154 (char_u *)FALSE,
1155#endif
1156 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001157 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158#ifdef FEAT_AUTOCMD
1159 (char_u *)&p_ft, PV_FT,
1160 {(char_u *)"", (char_u *)0L}
1161#else
1162 (char_u *)NULL, PV_NONE,
1163 {(char_u *)0L, (char_u *)0L}
1164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001165 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001166 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1168 (char_u *)&p_fcs, PV_NONE,
1169 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1170#else
1171 (char_u *)NULL, PV_NONE,
1172 {(char_u *)"", (char_u *)0L}
1173#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001174 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001175 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1176 (char_u *)&p_fixeol, PV_FIXEOL,
1177 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1179#ifdef FEAT_FKMAP
1180 (char_u *)&p_fkmap, PV_NONE,
1181#else
1182 (char_u *)NULL, PV_NONE,
1183#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001184 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001185 {"flash", "fl", P_BOOL|P_VI_DEF,
1186 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001187 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001188#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001189 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001191 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1193 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1196 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001197 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1199# ifdef FEAT_EVAL
1200 (char_u *)VAR_WIN, PV_FDE,
1201 {(char_u *)"0", (char_u *)NULL}
1202# else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)NULL, (char_u *)0L}
1205# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001206 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1208 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1211 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001213 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001215 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001216 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001217 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)"{{{,}}}", (char_u *)NULL}
1220 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1225 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1228 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001229 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001230 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 (char_u *)&p_fdo, PV_NONE,
1232 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001233 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001234 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1235# ifdef FEAT_EVAL
1236 (char_u *)VAR_WIN, PV_FDT,
1237 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001238# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239 (char_u *)NULL, PV_NONE,
1240 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001241# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001242 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001244 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001245#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001246 (char_u *)&p_fex, PV_FEX,
1247 {(char_u *)"", (char_u *)0L}
1248#else
1249 (char_u *)NULL, PV_NONE,
1250 {(char_u *)0L, (char_u *)0L}
1251#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001252 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1254 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001255 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1256 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001257 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1258 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001259 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1260 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001262 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001264 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1265#ifdef HAVE_FSYNC
1266 (char_u *)&p_fs, PV_NONE,
1267 {(char_u *)TRUE, (char_u *)0L}
1268#else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)FALSE, (char_u *)0L}
1271#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001272 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1274 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001275 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"graphic", "gr", P_BOOL|P_VI_DEF,
1277 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001278 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001279 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280#ifdef FEAT_QUICKFIX
1281 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001282 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283#else
1284 (char_u *)NULL, PV_NONE,
1285 {(char_u *)NULL, (char_u *)0L}
1286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1289#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001290 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291 {
1292# ifdef WIN3264
1293 /* may be changed to "grep -n" in os_win32.c */
1294 (char_u *)"findstr /n",
1295# else
1296# ifdef UNIX
1297 /* Add an extra file name so that grep will always
1298 * insert a file name in the match line. */
1299 (char_u *)"grep -n $* /dev/null",
1300# else
1301# ifdef VMS
1302 (char_u *)"SEARCH/NUMBERS ",
1303# else
1304 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001305# endif
1306# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001313 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001314 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315#ifdef CURSOR_SHAPE
1316 (char_u *)&p_guicursor, PV_NONE,
1317 {
1318# ifdef FEAT_GUI
1319 (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 +01001320# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1322# endif
1323 (char_u *)0L}
1324#else
1325 (char_u *)NULL, PV_NONE,
1326 {(char_u *)NULL, (char_u *)0L}
1327#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001328 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001329 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330#ifdef FEAT_GUI
1331 (char_u *)&p_guifont, PV_NONE,
1332 {(char_u *)"", (char_u *)0L}
1333#else
1334 (char_u *)NULL, PV_NONE,
1335 {(char_u *)NULL, (char_u *)0L}
1336#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001337 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001338 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001339#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1340 (char_u *)&p_guifontset, PV_NONE,
1341 {(char_u *)"", (char_u *)0L}
1342#else
1343 (char_u *)NULL, PV_NONE,
1344 {(char_u *)NULL, (char_u *)0L}
1345#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001346 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001347 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1349 (char_u *)&p_guifontwide, PV_NONE,
1350 {(char_u *)"", (char_u *)0L}
1351#else
1352 (char_u *)NULL, PV_NONE,
1353 {(char_u *)NULL, (char_u *)0L}
1354#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001357#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358 (char_u *)&p_ghr, PV_NONE,
1359#else
1360 (char_u *)NULL, PV_NONE,
1361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001362 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001363 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001364#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 (char_u *)&p_go, PV_NONE,
1366# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001367 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001369 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001370# endif
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001375 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 {"guipty", NULL, P_BOOL|P_VI_DEF,
1377#if defined(FEAT_GUI)
1378 (char_u *)&p_guipty, PV_NONE,
1379#else
1380 (char_u *)NULL, PV_NONE,
1381#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001382 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001383 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001384#if defined(FEAT_GUI_TABLINE)
1385 (char_u *)&p_gtl, PV_NONE,
1386 {(char_u *)"", (char_u *)0L}
1387#else
1388 (char_u *)NULL, PV_NONE,
1389 {(char_u *)NULL, (char_u *)0L}
1390#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001391 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001392 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001393#if defined(FEAT_GUI_TABLINE)
1394 (char_u *)&p_gtt, PV_NONE,
1395 {(char_u *)"", (char_u *)0L}
1396#else
1397 (char_u *)NULL, PV_NONE,
1398 {(char_u *)NULL, (char_u *)0L}
1399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1402 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001403 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1405 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001406 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1407 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001408 {"helpheight", "hh", P_NUM|P_VI_DEF,
1409#ifdef FEAT_WINDOWS
1410 (char_u *)&p_hh, PV_NONE,
1411#else
1412 (char_u *)NULL, PV_NONE,
1413#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001415 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001416#ifdef FEAT_MULTI_LANG
1417 (char_u *)&p_hlg, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)0L, (char_u *)0L}
1422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001423 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"hidden", "hid", P_BOOL|P_VI_DEF,
1425 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001426 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001427 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001429 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1430 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"history", "hi", P_NUM|P_VIM,
1432 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001433 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1435#ifdef FEAT_RIGHTLEFT
1436 (char_u *)&p_hkmap, PV_NONE,
1437#else
1438 (char_u *)NULL, PV_NONE,
1439#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001440 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1442#ifdef FEAT_RIGHTLEFT
1443 (char_u *)&p_hkmapp, PV_NONE,
1444#else
1445 (char_u *)NULL, PV_NONE,
1446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1449 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001450 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 {"icon", NULL, P_BOOL|P_VI_DEF,
1452#ifdef FEAT_TITLE
1453 (char_u *)&p_icon, PV_NONE,
1454#else
1455 (char_u *)NULL, PV_NONE,
1456#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001457 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"iconstring", NULL, P_STRING|P_VI_DEF,
1459#ifdef FEAT_TITLE
1460 (char_u *)&p_iconstring, PV_NONE,
1461#else
1462 (char_u *)NULL, PV_NONE,
1463#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001464 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1466 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001468 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1469# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1470 (char_u *)&p_imaf, PV_NONE,
1471 {(char_u *)"", (char_u *)NULL}
1472# else
1473 (char_u *)NULL, PV_NONE,
1474 {(char_u *)NULL, (char_u *)0L}
1475# endif
1476 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001478#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001479 (char_u *)&p_imak, PV_NONE,
1480#else
1481 (char_u *)NULL, PV_NONE,
1482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001483 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1485#ifdef USE_IM_CONTROL
1486 (char_u *)&p_imcmdline, PV_NONE,
1487#else
1488 (char_u *)NULL, PV_NONE,
1489#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001490 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001491 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1492#ifdef USE_IM_CONTROL
1493 (char_u *)&p_imdisable, PV_NONE,
1494#else
1495 (char_u *)NULL, PV_NONE,
1496#endif
1497#ifdef __sgi
1498 {(char_u *)TRUE, (char_u *)0L}
1499#else
1500 {(char_u *)FALSE, (char_u *)0L}
1501#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001502 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"iminsert", "imi", P_NUM|P_VI_DEF,
1504 (char_u *)&p_iminsert, PV_IMI,
1505#ifdef B_IMODE_IM
1506 {(char_u *)B_IMODE_IM, (char_u *)0L}
1507#else
1508 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1509#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001510 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"imsearch", "ims", P_NUM|P_VI_DEF,
1512 (char_u *)&p_imsearch, PV_IMS,
1513#ifdef B_IMODE_IM
1514 {(char_u *)B_IMODE_IM, (char_u *)0L}
1515#else
1516 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1517#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001519 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001520# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1521 (char_u *)&p_imsf, PV_NONE,
1522 {(char_u *)"", (char_u *)NULL}
1523# else
1524 (char_u *)NULL, PV_NONE,
1525 {(char_u *)NULL, (char_u *)0L}
1526# endif
1527 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1529#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001530 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001531 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1532#else
1533 (char_u *)NULL, PV_NONE,
1534 {(char_u *)0L, (char_u *)0L}
1535#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001536 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001537 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1538#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1539 (char_u *)&p_inex, PV_INEX,
1540 {(char_u *)"", (char_u *)0L}
1541#else
1542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)0L, (char_u *)0L}
1544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001545 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1547 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1550#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1551 (char_u *)&p_inde, PV_INDE,
1552 {(char_u *)"", (char_u *)0L}
1553#else
1554 (char_u *)NULL, PV_NONE,
1555 {(char_u *)0L, (char_u *)0L}
1556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001557 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001558 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001559#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1560 (char_u *)&p_indk, PV_INDK,
1561 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1562#else
1563 (char_u *)NULL, PV_NONE,
1564 {(char_u *)0L, (char_u *)0L}
1565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001566 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567 {"infercase", "inf", P_BOOL|P_VI_DEF,
1568 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1571 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001573 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1574 (char_u *)&p_isf, PV_NONE,
1575 {
1576#ifdef BACKSLASH_IN_FILENAME
1577 /* Excluded are: & and ^ are special in cmd.exe
1578 * ( and ) are used in text separating fnames */
1579 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1580#else
1581# ifdef AMIGA
1582 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1583# else
1584# ifdef VMS
1585 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1586# else /* UNIX et al. */
1587# ifdef EBCDIC
1588 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1589# else
1590 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1591# endif
1592# endif
1593# endif
1594#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001595 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1597 (char_u *)&p_isi, PV_NONE,
1598 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001599#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001600 (char_u *)"@,48-57,_,128-167,224-235",
1601#else
1602# ifdef EBCDIC
1603 /* TODO: EBCDIC Check this! @ == isalpha()*/
1604 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1605 "112-120,128,140-142,156,158,172,"
1606 "174,186,191,203-207,219-225,235-239,"
1607 "251-254",
1608# else
1609 (char_u *)"@,48-57,_,192-255",
1610# endif
1611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001612 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1614 (char_u *)&p_isk, PV_ISK,
1615 {
1616#ifdef EBCDIC
1617 (char_u *)"@,240-249,_",
1618 /* TODO: EBCDIC Check this! @ == isalpha()*/
1619 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1620 "112-120,128,140-142,156,158,172,"
1621 "174,186,191,203-207,219-225,235-239,"
1622 "251-254",
1623#else
1624 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001625# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 (char_u *)"@,48-57,_,128-167,224-235"
1627# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001628 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629# endif
1630#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001631 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001632 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1633 (char_u *)&p_isp, PV_NONE,
1634 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001635#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001636 || defined(VMS)
1637 (char_u *)"@,~-255",
1638#else
1639# ifdef EBCDIC
1640 /* all chars above 63 are printable */
1641 (char_u *)"63-255",
1642# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001643 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644# endif
1645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001646 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1648 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001649 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1651#ifdef FEAT_CRYPT
1652 (char_u *)&p_key, PV_KEY,
1653 {(char_u *)"", (char_u *)0L}
1654#else
1655 (char_u *)NULL, PV_NONE,
1656 {(char_u *)0L, (char_u *)0L}
1657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001659 {"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 +00001660#ifdef FEAT_KEYMAP
1661 (char_u *)&p_keymap, PV_KMAP,
1662 {(char_u *)"", (char_u *)0L}
1663#else
1664 (char_u *)NULL, PV_NONE,
1665 {(char_u *)"", (char_u *)0L}
1666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001667 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001668 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001670 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001672 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001673 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001674#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 (char_u *)":help",
1676#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001677# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001678 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001679# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001680# ifdef USEMAN_S
1681 (char_u *)"man -s",
1682# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001684# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685# endif
1686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001687 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001688 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689#ifdef FEAT_LANGMAP
1690 (char_u *)&p_langmap, PV_NONE,
1691 {(char_u *)"", /* unmatched } */
1692#else
1693 (char_u *)NULL, PV_NONE,
1694 {(char_u *)NULL,
1695#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001696 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001697 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1699 (char_u *)&p_lm, PV_NONE,
1700#else
1701 (char_u *)NULL, PV_NONE,
1702#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001703 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001704 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1705#ifdef FEAT_LANGMAP
1706 (char_u *)&p_lnr, PV_NONE,
1707#else
1708 (char_u *)NULL, PV_NONE,
1709#endif
1710 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001711 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1712#ifdef FEAT_LANGMAP
1713 (char_u *)&p_lrm, PV_NONE,
1714#else
1715 (char_u *)NULL, PV_NONE,
1716#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001717 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1719#ifdef FEAT_WINDOWS
1720 (char_u *)&p_ls, PV_NONE,
1721#else
1722 (char_u *)NULL, PV_NONE,
1723#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001724 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001725 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1726 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001727 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001728 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1729#ifdef FEAT_LINEBREAK
1730 (char_u *)VAR_WIN, PV_LBR,
1731#else
1732 (char_u *)NULL, PV_NONE,
1733#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001734 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1736 (char_u *)&Rows, PV_NONE,
1737 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001738#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 (char_u *)25L,
1740#else
1741 (char_u *)24L,
1742#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001743 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1745#ifdef FEAT_GUI
1746 (char_u *)&p_linespace, PV_NONE,
1747#else
1748 (char_u *)NULL, PV_NONE,
1749#endif
1750#ifdef FEAT_GUI_W32
1751 {(char_u *)1L, (char_u *)0L}
1752#else
1753 {(char_u *)0L, (char_u *)0L}
1754#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001755 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {"lisp", NULL, P_BOOL|P_VI_DEF,
1757#ifdef FEAT_LISP
1758 (char_u *)&p_lisp, PV_LISP,
1759#else
1760 (char_u *)NULL, PV_NONE,
1761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001762 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001763 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001765 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1767#else
1768 (char_u *)NULL, PV_NONE,
1769 {(char_u *)"", (char_u *)0L}
1770#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001771 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1773 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001774 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001775 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001777 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1779 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001781#if defined(DYNAMIC_LUA)
Bram Moolenaara6e42502016-04-20 16:19:52 +02001782 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001783 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001784 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1785 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001786#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001787#ifdef FEAT_GUI_MAC
1788 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1789 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001790 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001792 {"magic", NULL, P_BOOL|P_VI_DEF,
1793 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001794 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001795 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796#ifdef FEAT_QUICKFIX
1797 (char_u *)&p_mef, PV_NONE,
1798 {(char_u *)"", (char_u *)0L}
1799#else
1800 (char_u *)NULL, PV_NONE,
1801 {(char_u *)NULL, (char_u *)0L}
1802#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001803 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001804 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1805#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001806 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807# ifdef VMS
1808 {(char_u *)"MMS", (char_u *)0L}
1809# else
1810 {(char_u *)"make", (char_u *)0L}
1811# endif
1812#else
1813 (char_u *)NULL, PV_NONE,
1814 {(char_u *)NULL, (char_u *)0L}
1815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001817 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1820 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821 {"matchtime", "mat", P_NUM|P_VI_DEF,
1822 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001823 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001824 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001825#ifdef FEAT_MBYTE
1826 (char_u *)&p_mco, PV_NONE,
1827#else
1828 (char_u *)NULL, PV_NONE,
1829#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1832#ifdef FEAT_EVAL
1833 (char_u *)&p_mfd, PV_NONE,
1834#else
1835 (char_u *)NULL, PV_NONE,
1836#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001838 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1839 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 {"maxmem", "mm", P_NUM|P_VI_DEF,
1842 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1844 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001845 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1846 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1849 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001850 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1851 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"menuitems", "mis", P_NUM|P_VI_DEF,
1853#ifdef FEAT_MENU
1854 (char_u *)&p_mis, PV_NONE,
1855#else
1856 (char_u *)NULL, PV_NONE,
1857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"mesg", NULL, P_BOOL|P_VI_DEF,
1860 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001862 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001863#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001864 (char_u *)&p_msm, PV_NONE,
1865 {(char_u *)"460000,2000,500", (char_u *)0L}
1866#else
1867 (char_u *)NULL, PV_NONE,
1868 {(char_u *)0L, (char_u *)0L}
1869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"modeline", "ml", P_BOOL|P_VIM,
1872 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001873 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874 {"modelines", "mls", P_NUM|P_VI_DEF,
1875 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001876 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1878 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001879 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1881 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001882 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883 {"more", NULL, P_BOOL|P_VIM,
1884 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001885 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1887 (char_u *)&p_mouse, PV_NONE,
1888 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001889#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 (char_u *)"a",
1891#else
1892 (char_u *)"",
1893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001894 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1896#ifdef FEAT_GUI
1897 (char_u *)&p_mousef, PV_NONE,
1898#else
1899 (char_u *)NULL, PV_NONE,
1900#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1903#ifdef FEAT_GUI
1904 (char_u *)&p_mh, PV_NONE,
1905#else
1906 (char_u *)NULL, PV_NONE,
1907#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001908 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1910 (char_u *)&p_mousem, PV_NONE,
1911 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001912#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 (char_u *)"popup",
1914#else
1915# if defined(MACOS)
1916 (char_u *)"popup_setpos",
1917# else
1918 (char_u *)"extend",
1919# endif
1920#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001921 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001922 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923#ifdef FEAT_MOUSESHAPE
1924 (char_u *)&p_mouseshape, PV_NONE,
1925 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1926#else
1927 (char_u *)NULL, PV_NONE,
1928 {(char_u *)NULL, (char_u *)0L}
1929#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001930 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1932 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001933 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001934 {"mzquantum", "mzq", P_NUM,
1935#ifdef FEAT_MZSCHEME
1936 (char_u *)&p_mzq, PV_NONE,
1937#else
1938 (char_u *)NULL, PV_NONE,
1939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001940 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001941 {"novice", NULL, P_BOOL|P_VI_DEF,
1942 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001943 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001944 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001946 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001947 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1949 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001950 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001951 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1952#ifdef FEAT_LINEBREAK
1953 (char_u *)VAR_WIN, PV_NUW,
1954#else
1955 (char_u *)NULL, PV_NONE,
1956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001957 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001958 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001959#ifdef FEAT_COMPL_FUNC
1960 (char_u *)&p_ofu, PV_OFU,
1961 {(char_u *)"", (char_u *)0L}
1962#else
1963 (char_u *)NULL, PV_NONE,
1964 {(char_u *)0L, (char_u *)0L}
1965#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001966 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001967 {"open", NULL, P_BOOL|P_VI_DEF,
1968 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001970 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001971#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001972 (char_u *)&p_odev, PV_NONE,
1973#else
1974 (char_u *)NULL, PV_NONE,
1975#endif
1976 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001978 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1979 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"optimize", "opt", P_BOOL|P_VI_DEF,
1982 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001983 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001986 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001987 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1988 |P_SECURE,
1989 (char_u *)&p_pp, PV_NONE,
1990 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
1991 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"paragraphs", "para", P_STRING|P_VI_DEF,
1993 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00001994 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001995 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001996 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001997 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001998 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2000 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002001 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2003#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2004 (char_u *)&p_pex, PV_NONE,
2005 {(char_u *)"", (char_u *)0L}
2006#else
2007 (char_u *)NULL, PV_NONE,
2008 {(char_u *)0L, (char_u *)0L}
2009#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002010 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002011 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002012 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002013 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002014 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002015 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002017#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002018 (char_u *)".,,",
2019#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002022 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002023#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002024 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002025 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002026 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2027 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2030 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002031 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002032 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2034 (char_u *)&p_pvh, PV_NONE,
2035#else
2036 (char_u *)NULL, PV_NONE,
2037#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002038 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2040#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2041 (char_u *)VAR_WIN, PV_PVW,
2042#else
2043 (char_u *)NULL, PV_NONE,
2044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002045 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002046 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002047#ifdef FEAT_PRINTER
2048 (char_u *)&p_pdev, PV_NONE,
2049 {(char_u *)"", (char_u *)0L}
2050#else
2051 (char_u *)NULL, PV_NONE,
2052 {(char_u *)NULL, (char_u *)0L}
2053#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002054 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {"printencoding", "penc", P_STRING|P_VI_DEF,
2056#ifdef FEAT_POSTSCRIPT
2057 (char_u *)&p_penc, PV_NONE,
2058 {(char_u *)"", (char_u *)0L}
2059#else
2060 (char_u *)NULL, PV_NONE,
2061 {(char_u *)NULL, (char_u *)0L}
2062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002064 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002065#ifdef FEAT_POSTSCRIPT
2066 (char_u *)&p_pexpr, PV_NONE,
2067 {(char_u *)"", (char_u *)0L}
2068#else
2069 (char_u *)NULL, PV_NONE,
2070 {(char_u *)NULL, (char_u *)0L}
2071#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002072 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073 {"printfont", "pfn", P_STRING|P_VI_DEF,
2074#ifdef FEAT_PRINTER
2075 (char_u *)&p_pfn, PV_NONE,
2076 {
2077# ifdef MSWIN
2078 (char_u *)"Courier_New:h10",
2079# else
2080 (char_u *)"courier",
2081# endif
2082 (char_u *)0L}
2083#else
2084 (char_u *)NULL, PV_NONE,
2085 {(char_u *)NULL, (char_u *)0L}
2086#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002087 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002088 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2089#ifdef FEAT_PRINTER
2090 (char_u *)&p_header, PV_NONE,
2091 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2092#else
2093 (char_u *)NULL, PV_NONE,
2094 {(char_u *)NULL, (char_u *)0L}
2095#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002096 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002097 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2098#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2099 (char_u *)&p_pmcs, PV_NONE,
2100 {(char_u *)"", (char_u *)0L}
2101#else
2102 (char_u *)NULL, PV_NONE,
2103 {(char_u *)NULL, (char_u *)0L}
2104#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002105 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002106 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2107#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2108 (char_u *)&p_pmfn, PV_NONE,
2109 {(char_u *)"", (char_u *)0L}
2110#else
2111 (char_u *)NULL, PV_NONE,
2112 {(char_u *)NULL, (char_u *)0L}
2113#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002114 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002115 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116#ifdef FEAT_PRINTER
2117 (char_u *)&p_popt, PV_NONE,
2118 {(char_u *)"", (char_u *)0L}
2119#else
2120 (char_u *)NULL, PV_NONE,
2121 {(char_u *)NULL, (char_u *)0L}
2122#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002123 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002125 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002126 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002127 {"pumheight", "ph", P_NUM|P_VI_DEF,
2128#ifdef FEAT_INS_EXPAND
2129 (char_u *)&p_ph, PV_NONE,
2130#else
2131 (char_u *)NULL, PV_NONE,
2132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002134#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002135 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002136 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002137 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2138 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002139#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002140#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002141 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002142 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002143 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2144 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002145#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002146 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2147#ifdef FEAT_TEXTOBJ
2148 (char_u *)&p_qe, PV_QE,
2149 {(char_u *)"\\", (char_u *)0L}
2150#else
2151 (char_u *)NULL, PV_NONE,
2152 {(char_u *)NULL, (char_u *)0L}
2153#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002154 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2156 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002157 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002158 {"redraw", NULL, P_BOOL|P_VI_DEF,
2159 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002160 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002161 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2162#ifdef FEAT_RELTIME
2163 (char_u *)&p_rdt, PV_NONE,
2164#else
2165 (char_u *)NULL, PV_NONE,
2166#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002167 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002168 {"regexpengine", "re", P_NUM|P_VI_DEF,
2169 (char_u *)&p_re, PV_NONE,
2170 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002171 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2172 (char_u *)VAR_WIN, PV_RNU,
2173 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174 {"remap", NULL, P_BOOL|P_VI_DEF,
2175 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002177 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002178#ifdef FEAT_RENDER_OPTIONS
2179 (char_u *)&p_rop, PV_NONE,
2180 {(char_u *)"", (char_u *)0L}
2181#else
2182 (char_u *)NULL, PV_NONE,
2183 {(char_u *)NULL, (char_u *)0L}
2184#endif
2185 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002186 {"report", NULL, P_NUM|P_VI_DEF,
2187 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002188 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002189 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2190#ifdef WIN3264
2191 (char_u *)&p_rs, PV_NONE,
2192#else
2193 (char_u *)NULL, PV_NONE,
2194#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002195 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002196 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2197#ifdef FEAT_RIGHTLEFT
2198 (char_u *)&p_ri, PV_NONE,
2199#else
2200 (char_u *)NULL, PV_NONE,
2201#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002202 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002203 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2204#ifdef FEAT_RIGHTLEFT
2205 (char_u *)VAR_WIN, PV_RL,
2206#else
2207 (char_u *)NULL, PV_NONE,
2208#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002209 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002210 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2211#ifdef FEAT_RIGHTLEFT
2212 (char_u *)VAR_WIN, PV_RLC,
2213 {(char_u *)"search", (char_u *)NULL}
2214#else
2215 (char_u *)NULL, PV_NONE,
2216 {(char_u *)NULL, (char_u *)0L}
2217#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002218 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002219#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002220 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002221 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002222 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2223 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002225 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2226#ifdef FEAT_CMDL_INFO
2227 (char_u *)&p_ru, PV_NONE,
2228#else
2229 (char_u *)NULL, PV_NONE,
2230#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002231 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002232 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2233#ifdef FEAT_STL_OPT
2234 (char_u *)&p_ruf, PV_NONE,
2235#else
2236 (char_u *)NULL, PV_NONE,
2237#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002238 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002239 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2240 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2243 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2245 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002246 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002247 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2248#ifdef FEAT_SCROLLBIND
2249 (char_u *)VAR_WIN, PV_SCBIND,
2250#else
2251 (char_u *)NULL, PV_NONE,
2252#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002253 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002254 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2255 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002256 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002257 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2258 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002259 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002260 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002261#ifdef FEAT_SCROLLBIND
2262 (char_u *)&p_sbo, PV_NONE,
2263 {(char_u *)"ver,jump", (char_u *)0L}
2264#else
2265 (char_u *)NULL, PV_NONE,
2266 {(char_u *)0L, (char_u *)0L}
2267#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002268 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"sections", "sect", P_STRING|P_VI_DEF,
2270 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2272 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2274 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 {(char_u *)"inclusive", (char_u *)0L}
2279 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002280 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002281 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002282 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002283 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284#ifdef FEAT_SESSION
2285 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002286 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 (char_u *)0L}
2288#else
2289 (char_u *)NULL, PV_NONE,
2290 {(char_u *)0L, (char_u *)0L}
2291#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2294 (char_u *)&p_sh, PV_NONE,
2295 {
2296#ifdef VMS
2297 (char_u *)"-",
2298#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002299# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002301# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303# endif
2304#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002305 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2307 (char_u *)&p_shcf, PV_NONE,
2308 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002309#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 (char_u *)"/c",
2311#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002313#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002314 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002315 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2316#ifdef FEAT_QUICKFIX
2317 (char_u *)&p_sp, PV_NONE,
2318 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002319#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321#else
2322 (char_u *)">",
2323#endif
2324 (char_u *)0L}
2325#else
2326 (char_u *)NULL, PV_NONE,
2327 {(char_u *)0L, (char_u *)0L}
2328#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002329 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2331 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002332 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2334 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002335 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2337#ifdef BACKSLASH_IN_FILENAME
2338 (char_u *)&p_ssl, PV_NONE,
2339#else
2340 (char_u *)NULL, PV_NONE,
2341#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002342 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002343 {"shelltemp", "stmp", P_BOOL,
2344 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002345 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"shelltype", "st", P_NUM|P_VI_DEF,
2347#ifdef AMIGA
2348 (char_u *)&p_st, PV_NONE,
2349#else
2350 (char_u *)NULL, PV_NONE,
2351#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002352 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2354 (char_u *)&p_sxq, PV_NONE,
2355 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002356#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 (char_u *)"\"",
2358#else
2359 (char_u *)"",
2360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002362 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2363 (char_u *)&p_sxe, PV_NONE,
2364 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002365#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002366 (char_u *)"\"&|<>()@^",
2367#else
2368 (char_u *)"",
2369#endif
2370 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2372 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002373 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2375 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002376 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2378 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002379 {(char_u *)"", (char_u *)"filnxtToO"}
2380 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002383 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002384 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2385#ifdef FEAT_LINEBREAK
2386 (char_u *)&p_sbr, PV_NONE,
2387#else
2388 (char_u *)NULL, PV_NONE,
2389#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391 {"showcmd", "sc", P_BOOL|P_VIM,
2392#ifdef FEAT_CMDL_INFO
2393 (char_u *)&p_sc, PV_NONE,
2394#else
2395 (char_u *)NULL, PV_NONE,
2396#endif
2397 {(char_u *)FALSE,
2398#ifdef UNIX
2399 (char_u *)FALSE
2400#else
2401 (char_u *)TRUE
2402#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002403 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2405 (char_u *)&p_sft, 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 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2408 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"showmode", "smd", P_BOOL|P_VIM,
2411 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002413 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2414#ifdef FEAT_WINDOWS
2415 (char_u *)&p_stal, PV_NONE,
2416#else
2417 (char_u *)NULL, PV_NONE,
2418#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002419 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2421 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2424 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002426 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2427#ifdef FEAT_SIGNS
2428 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002429 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002430#else
2431 (char_u *)NULL, PV_NONE,
2432 {(char_u *)NULL, (char_u *)0L}
2433#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002434 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002435 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2436 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002438 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2439 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002440 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2442#ifdef FEAT_SMARTINDENT
2443 (char_u *)&p_si, PV_SI,
2444#else
2445 (char_u *)NULL, PV_NONE,
2446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002447 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2449 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002450 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2452 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002453 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2455 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002457 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002458#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002459 (char_u *)VAR_WIN, PV_SPELL,
2460#else
2461 (char_u *)NULL, PV_NONE,
2462#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002463 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002464 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002465#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002466 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002467 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002468#else
2469 (char_u *)NULL, PV_NONE,
2470 {(char_u *)0L, (char_u *)0L}
2471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002473 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2474 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002475#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002476 (char_u *)&p_spf, PV_SPF,
2477 {(char_u *)"", (char_u *)0L}
2478#else
2479 (char_u *)NULL, PV_NONE,
2480 {(char_u *)0L, (char_u *)0L}
2481#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002483 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2484 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002485#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002486 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002487 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002488#else
2489 (char_u *)NULL, PV_NONE,
2490 {(char_u *)0L, (char_u *)0L}
2491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002493 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002494#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002495 (char_u *)&p_sps, PV_NONE,
2496 {(char_u *)"best", (char_u *)0L}
2497#else
2498 (char_u *)NULL, PV_NONE,
2499 {(char_u *)0L, (char_u *)0L}
2500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002502 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2503#ifdef FEAT_WINDOWS
2504 (char_u *)&p_sb, PV_NONE,
2505#else
2506 (char_u *)NULL, PV_NONE,
2507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002508 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002509 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002510#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 (char_u *)&p_spr, PV_NONE,
2512#else
2513 (char_u *)NULL, PV_NONE,
2514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002516 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2517 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002518 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2520#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002521 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522#else
2523 (char_u *)NULL, PV_NONE,
2524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002526 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 (char_u *)&p_su, PV_NONE,
2528 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002529 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002530 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002531#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 (char_u *)&p_sua, PV_SUA,
2533 {(char_u *)"", (char_u *)0L}
2534#else
2535 (char_u *)NULL, PV_NONE,
2536 {(char_u *)0L, (char_u *)0L}
2537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2540 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"swapsync", "sws", P_STRING|P_VI_DEF,
2543 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002545 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002547 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002548 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2549#ifdef FEAT_SYN_HL
2550 (char_u *)&p_smc, PV_SMC,
2551 {(char_u *)3000L, (char_u *)0L}
2552#else
2553 (char_u *)NULL, PV_NONE,
2554 {(char_u *)0L, (char_u *)0L}
2555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002557 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558#ifdef FEAT_SYN_HL
2559 (char_u *)&p_syn, PV_SYN,
2560 {(char_u *)"", (char_u *)0L}
2561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)0L, (char_u *)0L}
2564#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002565 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002566 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2567#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002568 (char_u *)&p_tal, PV_NONE,
2569#else
2570 (char_u *)NULL, PV_NONE,
2571#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002573 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2574#ifdef FEAT_WINDOWS
2575 (char_u *)&p_tpm, PV_NONE,
2576#else
2577 (char_u *)NULL, PV_NONE,
2578#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002579 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2581 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2584 (char_u *)&p_tbs, PV_NONE,
2585#ifdef VMS /* binary searching doesn't appear to work on VMS */
2586 {(char_u *)0L, (char_u *)0L}
2587#else
2588 {(char_u *)TRUE, (char_u *)0L}
2589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002590 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002591 {"tagcase", "tc", P_STRING|P_VIM,
2592 (char_u *)&p_tc, PV_TC,
2593 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002594 {"taglength", "tl", P_NUM|P_VI_DEF,
2595 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002596 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"tagrelative", "tr", P_BOOL|P_VIM,
2598 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002599 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002600 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002601 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 {
2603#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2604 (char_u *)"./tags,./TAGS,tags,TAGS",
2605#else
2606 (char_u *)"./tags,tags",
2607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002608 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002609 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2610 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002612#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002613 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002614 (char_u *)&p_tcldll, PV_NONE,
2615 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2616 SCRIPTID_INIT},
2617#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2619 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2622#ifdef FEAT_ARABIC
2623 (char_u *)&p_tbidi, PV_NONE,
2624#else
2625 (char_u *)NULL, PV_NONE,
2626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2629#ifdef FEAT_MBYTE
2630 (char_u *)&p_tenc, PV_NONE,
2631 {(char_u *)"", (char_u *)0L}
2632#else
2633 (char_u *)NULL, PV_NONE,
2634 {(char_u *)0L, (char_u *)0L}
2635#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002636 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002637 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2638#ifdef FEAT_TERMGUICOLORS
2639 (char_u *)&p_tgc, PV_NONE,
2640 {(char_u *)FALSE, (char_u *)FALSE}
2641#else
2642 (char_u*)NULL, PV_NONE,
2643 {(char_u *)FALSE, (char_u *)FALSE}
2644#endif
2645 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 {"terse", NULL, P_BOOL|P_VI_DEF,
2647 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002649 {"textauto", "ta", P_BOOL|P_VIM,
2650 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002651 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2652 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002653 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2654 (char_u *)&p_tx, PV_TX,
2655 {
2656#ifdef USE_CRNL
2657 (char_u *)TRUE,
2658#else
2659 (char_u *)FALSE,
2660#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002661 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002662 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002664 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002665 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002666#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002667 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668#else
2669 (char_u *)NULL, PV_NONE,
2670#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002671 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2673 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002674 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"timeout", "to", P_BOOL|P_VI_DEF,
2676 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002677 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2679 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002681 {"title", NULL, P_BOOL|P_VI_DEF,
2682#ifdef FEAT_TITLE
2683 (char_u *)&p_title, PV_NONE,
2684#else
2685 (char_u *)NULL, PV_NONE,
2686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002687 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002688 {"titlelen", NULL, P_NUM|P_VI_DEF,
2689#ifdef FEAT_TITLE
2690 (char_u *)&p_titlelen, PV_NONE,
2691#else
2692 (char_u *)NULL, PV_NONE,
2693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002695 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696#ifdef FEAT_TITLE
2697 (char_u *)&p_titleold, PV_NONE,
2698 {(char_u *)N_("Thanks for flying Vim"),
2699 (char_u *)0L}
2700#else
2701 (char_u *)NULL, PV_NONE,
2702 {(char_u *)0L, (char_u *)0L}
2703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"titlestring", NULL, P_STRING|P_VI_DEF,
2706#ifdef FEAT_TITLE
2707 (char_u *)&p_titlestring, PV_NONE,
2708#else
2709 (char_u *)NULL, PV_NONE,
2710#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002711 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002713 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)"icons,tooltips", (char_u *)0L}
2716 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002717#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002718#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002719 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2720 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002721 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002722#endif
2723 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2724 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002725 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002726 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2727 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002728 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2730 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002731 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2733 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002735 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2736#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2737 (char_u *)&p_ttym, PV_NONE,
2738#else
2739 (char_u *)NULL, PV_NONE,
2740#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002741 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2743 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2746 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002748 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2749 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002750#ifdef FEAT_PERSISTENT_UNDO
2751 (char_u *)&p_udir, PV_NONE,
2752 {(char_u *)".", (char_u *)0L}
2753#else
2754 (char_u *)NULL, PV_NONE,
2755 {(char_u *)0L, (char_u *)0L}
2756#endif
2757 SCRIPTID_INIT},
2758 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2759#ifdef FEAT_PERSISTENT_UNDO
2760 (char_u *)&p_udf, PV_UDF,
2761#else
2762 (char_u *)NULL, PV_NONE,
2763#endif
2764 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002766 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002768#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002769 (char_u *)1000L,
2770#else
2771 (char_u *)100L,
2772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002774 {"undoreload", "ur", P_NUM|P_VI_DEF,
2775 (char_u *)&p_ur, PV_NONE,
2776 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 {"updatecount", "uc", P_NUM|P_VI_DEF,
2778 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002779 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780 {"updatetime", "ut", P_NUM|P_VI_DEF,
2781 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002782 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"verbose", "vbs", P_NUM|P_VI_DEF,
2784 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002785 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002786 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2787 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002788 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2790#ifdef FEAT_SESSION
2791 (char_u *)&p_vdir, PV_NONE,
2792 {(char_u *)DFLT_VDIR, (char_u *)0L}
2793#else
2794 (char_u *)NULL, PV_NONE,
2795 {(char_u *)0L, (char_u *)0L}
2796#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002797 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002798 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799#ifdef FEAT_SESSION
2800 (char_u *)&p_vop, PV_NONE,
2801 {(char_u *)"folds,options,cursor", (char_u *)0L}
2802#else
2803 (char_u *)NULL, PV_NONE,
2804 {(char_u *)0L, (char_u *)0L}
2805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002807 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808#ifdef FEAT_VIMINFO
2809 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002810#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002811 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812#else
2813# ifdef AMIGA
2814 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002815 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002817 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818# endif
2819#endif
2820#else
2821 (char_u *)NULL, PV_NONE,
2822 {(char_u *)0L, (char_u *)0L}
2823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002824 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002825 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2826 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827#ifdef FEAT_VIRTUALEDIT
2828 (char_u *)&p_ve, PV_NONE,
2829 {(char_u *)"", (char_u *)""}
2830#else
2831 (char_u *)NULL, PV_NONE,
2832 {(char_u *)0L, (char_u *)0L}
2833#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002834 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2836 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002838 {"w300", NULL, P_NUM|P_VI_DEF,
2839 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002840 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"w1200", NULL, P_NUM|P_VI_DEF,
2842 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"w9600", NULL, P_NUM|P_VI_DEF,
2845 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002846 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 {"warn", NULL, P_BOOL|P_VI_DEF,
2848 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002849 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2851 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002852 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002853 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002855 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"wildchar", "wc", P_NUM|P_VIM,
2857 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002858 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2859 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002860 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002863 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864#ifdef FEAT_WILDIGN
2865 (char_u *)&p_wig, PV_NONE,
2866#else
2867 (char_u *)NULL, PV_NONE,
2868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002869 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002870 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2871 (char_u *)&p_wic, PV_NONE,
2872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2874#ifdef FEAT_WILDMENU
2875 (char_u *)&p_wmnu, PV_NONE,
2876#else
2877 (char_u *)NULL, PV_NONE,
2878#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002880 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002881 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002883 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2884#ifdef FEAT_CMDL_COMPL
2885 (char_u *)&p_wop, PV_NONE,
2886 {(char_u *)"", (char_u *)0L}
2887#else
2888 (char_u *)NULL, PV_NONE,
2889 {(char_u *)NULL, (char_u *)0L}
2890#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2893#ifdef FEAT_WAK
2894 (char_u *)&p_wak, PV_NONE,
2895 {(char_u *)"menu", (char_u *)0L}
2896#else
2897 (char_u *)NULL, PV_NONE,
2898 {(char_u *)NULL, (char_u *)0L}
2899#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002900 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002902 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002903 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002904 {"winheight", "wh", P_NUM|P_VI_DEF,
2905#ifdef FEAT_WINDOWS
2906 (char_u *)&p_wh, PV_NONE,
2907#else
2908 (char_u *)NULL, PV_NONE,
2909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002912#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913 (char_u *)VAR_WIN, PV_WFH,
2914#else
2915 (char_u *)NULL, PV_NONE,
2916#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002918 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002919#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002920 (char_u *)VAR_WIN, PV_WFW,
2921#else
2922 (char_u *)NULL, PV_NONE,
2923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2926#ifdef FEAT_WINDOWS
2927 (char_u *)&p_wmh, PV_NONE,
2928#else
2929 (char_u *)NULL, PV_NONE,
2930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002931 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002933#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 (char_u *)&p_wmw, PV_NONE,
2935#else
2936 (char_u *)NULL, PV_NONE,
2937#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002938 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002940#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941 (char_u *)&p_wiw, PV_NONE,
2942#else
2943 (char_u *)NULL, PV_NONE,
2944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002945 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2947 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002948 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2950 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002951 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2953 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002954 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955 {"write", NULL, P_BOOL|P_VI_DEF,
2956 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"writeany", "wa", P_BOOL|P_VI_DEF,
2959 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002960 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002961 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2962 (char_u *)&p_wb, PV_NONE,
2963 {
2964#ifdef FEAT_WRITEBACKUP
2965 (char_u *)TRUE,
2966#else
2967 (char_u *)FALSE,
2968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002969 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 {"writedelay", "wd", P_NUM|P_VI_DEF,
2971 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002972 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973
2974/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002975#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002977 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978
2979 p_term("t_AB", T_CAB)
2980 p_term("t_AF", T_CAF)
2981 p_term("t_AL", T_CAL)
2982 p_term("t_al", T_AL)
2983 p_term("t_bc", T_BC)
2984 p_term("t_cd", T_CD)
2985 p_term("t_ce", T_CE)
2986 p_term("t_cl", T_CL)
2987 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002988 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 p_term("t_Co", T_CCO)
2990 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01002991 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002993#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 p_term("t_CV", T_CSV)
2995#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 p_term("t_da", T_DA)
2997 p_term("t_db", T_DB)
2998 p_term("t_DL", T_CDL)
2999 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003000 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 p_term("t_fs", T_FS)
3002 p_term("t_IE", T_CIE)
3003 p_term("t_IS", T_CIS)
3004 p_term("t_ke", T_KE)
3005 p_term("t_ks", T_KS)
3006 p_term("t_le", T_LE)
3007 p_term("t_mb", T_MB)
3008 p_term("t_md", T_MD)
3009 p_term("t_me", T_ME)
3010 p_term("t_mr", T_MR)
3011 p_term("t_ms", T_MS)
3012 p_term("t_nd", T_ND)
3013 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003014 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 p_term("t_RI", T_CRI)
3016 p_term("t_RV", T_CRV)
3017 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003019 p_term("t_Sf", T_CSF)
3020 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003022 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024 p_term("t_te", T_TE)
3025 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003026 p_term("t_ts", T_TS)
3027 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 p_term("t_ue", T_UE)
3029 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003030 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 p_term("t_vb", T_VB)
3032 p_term("t_ve", T_VE)
3033 p_term("t_vi", T_VI)
3034 p_term("t_vs", T_VS)
3035 p_term("t_WP", T_CWP)
3036 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003037 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 p_term("t_xs", T_XS)
3039 p_term("t_ZH", T_CZH)
3040 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003041 p_term("t_8f", T_8F)
3042 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043
3044/* terminal key codes are not in here */
3045
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003046 /* end marker */
3047 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048};
3049
3050#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3051
3052#ifdef FEAT_MBYTE
3053static char *(p_ambw_values[]) = {"single", "double", NULL};
3054#endif
3055static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003056static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003058#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003059static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003060#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003061#ifdef FEAT_CMDL_COMPL
3062static char *(p_wop_values[]) = {"tagfile", NULL};
3063#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064#ifdef FEAT_WAK
3065static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3066#endif
3067static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3069static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071#ifdef FEAT_BROWSE
3072static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3073#endif
3074#ifdef FEAT_SCROLLBIND
3075static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3076#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003077static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003078#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3080#endif
3081#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003082# ifdef FEAT_AUTOCMD
3083static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3084# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003086# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3088#endif
3089static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3090#ifdef FEAT_FOLDING
3091static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003092# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003094# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 NULL};
3096static char *(p_fcl_values[]) = {"all", NULL};
3097#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003098#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003099static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003100#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003101#ifdef FEAT_SIGNS
3102static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3103#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003105static void set_option_default(int, int opt_flags, int compatible);
3106static void set_options_default(int opt_flags);
3107static char_u *term_bg_default(void);
3108static void did_set_option(int opt_idx, int opt_flags, int new_value);
3109static char_u *illegal_char(char_u *, int);
3110static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003112static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113#endif
3114#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003115static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003117static char_u *option_expand(int opt_idx, char_u *val);
3118static void didset_options(void);
3119static void didset_options2(void);
3120static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003121#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003122static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003123#else
3124# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3125#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003126static void set_string_option_global(int opt_idx, char_u **varp);
3127static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3128static 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);
3129static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003130#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003131static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003134static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003136#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003137static char_u *did_set_spell_option(int is_spellfile);
3138static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003139#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003140#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003141static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003142#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003143static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3144static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3145static void check_redraw(long_u flags);
3146static int findoption(char_u *);
3147static int find_key_option(char_u *);
3148static void showoptions(int all, int opt_flags);
3149static int optval_default(struct vimoption *, char_u *varp);
3150static void showoneopt(struct vimoption *, int opt_flags);
3151static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3152static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3153static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3154static int istermoption(struct vimoption *);
3155static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3156static char_u *get_varp(struct vimoption *);
3157static void option_value2string(struct vimoption *, int opt_flags);
3158static void check_winopt(winopt_T *wop);
3159static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003161static void langmap_init(void);
3162static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003163#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003164static void paste_option_changed(void);
3165static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003167static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003169static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3170static int check_opt_strings(char_u *val, char **values, int);
3171static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003172#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003173static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003174#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175
3176/*
3177 * Initialize the options, first part.
3178 *
3179 * Called only once from main(), just after creating the first buffer.
3180 */
3181 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003182set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183{
3184 char_u *p;
3185 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003186 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187
3188#ifdef FEAT_LANGMAP
3189 langmap_init();
3190#endif
3191
3192 /* Be Vi compatible by default */
3193 p_cp = TRUE;
3194
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003195 /* Use POSIX compatibility when $VIM_POSIX is set. */
3196 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003197 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003198 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003199 set_string_default("shm", (char_u *)"A");
3200 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003201
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 /*
3203 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003204 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003206 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003207#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003208 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003210 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211# endif
3212#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003213 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003214 set_string_default("sh", p);
3215
3216#ifdef FEAT_WILDIGN
3217 /*
3218 * Set the default for 'backupskip' to include environment variables for
3219 * temp files.
3220 */
3221 {
3222# ifdef UNIX
3223 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3224# else
3225 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3226# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003227 int len;
3228 garray_T ga;
3229 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230
3231 ga_init2(&ga, 1, 100);
3232 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3233 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003234 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235# ifdef UNIX
3236 if (*names[n] == NUL)
3237 p = (char_u *)"/tmp";
3238 else
3239# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003240 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003241 if (p != NULL && *p != NUL)
3242 {
3243 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003244 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003245 if (ga_grow(&ga, len) == OK)
3246 {
3247 if (ga.ga_len > 0)
3248 STRCAT(ga.ga_data, ",");
3249 STRCAT(ga.ga_data, p);
3250 add_pathsep(ga.ga_data);
3251 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252 ga.ga_len += len;
3253 }
3254 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003255 if (mustfree)
3256 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003257 }
3258 if (ga.ga_data != NULL)
3259 {
3260 set_string_default("bsk", ga.ga_data);
3261 vim_free(ga.ga_data);
3262 }
3263 }
3264#endif
3265
3266 /*
3267 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3268 */
3269 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003270 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003271 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003272#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3273 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3274#endif
3275 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003277 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003278 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279#else
3280# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003281 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003282 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003284 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285# endif
3286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003288 opt_idx = findoption((char_u *)"maxmem");
3289 if (opt_idx >= 0)
3290 {
3291#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003292 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3293 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003294#endif
3295 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3296 }
3297 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298 }
3299
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#ifdef FEAT_SEARCHPATH
3301 {
3302 char_u *cdpath;
3303 char_u *buf;
3304 int i;
3305 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003306 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307
3308 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003309 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003310 if (cdpath != NULL)
3311 {
3312 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3313 if (buf != NULL)
3314 {
3315 buf[0] = ','; /* start with ",", current dir first */
3316 j = 1;
3317 for (i = 0; cdpath[i] != NUL; ++i)
3318 {
3319 if (vim_ispathlistsep(cdpath[i]))
3320 buf[j++] = ',';
3321 else
3322 {
3323 if (cdpath[i] == ' ' || cdpath[i] == ',')
3324 buf[j++] = '\\';
3325 buf[j++] = cdpath[i];
3326 }
3327 }
3328 buf[j] = NUL;
3329 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003330 if (opt_idx >= 0)
3331 {
3332 options[opt_idx].def_val[VI_DEFAULT] = buf;
3333 options[opt_idx].flags |= P_DEF_ALLOCED;
3334 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003335 else
3336 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003337 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003338 if (mustfree)
3339 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340 }
3341 }
3342#endif
3343
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003344#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 /* Set print encoding on platforms that don't default to latin1 */
3346 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003347# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348 (char_u *)"cp1252"
3349# else
3350# ifdef VMS
3351 (char_u *)"dec-mcs"
3352# else
3353# ifdef EBCDIC
3354 (char_u *)"ebcdic-uk"
3355# else
3356# ifdef MAC
3357 (char_u *)"mac-roman"
3358# else /* HPUX */
3359 (char_u *)"hp-roman8"
3360# endif
3361# endif
3362# endif
3363# endif
3364 );
3365#endif
3366
3367#ifdef FEAT_POSTSCRIPT
3368 /* 'printexpr' must be allocated to be able to evaluate it. */
3369 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003370# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003371 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372# else
3373# ifdef VMS
3374 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3375
3376# else
3377 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3378# endif
3379# endif
3380 );
3381#endif
3382
3383 /*
3384 * Set all the options (except the terminal options) to their default
3385 * value. Also set the global value for local options.
3386 */
3387 set_options_default(0);
3388
3389#ifdef FEAT_GUI
3390 if (found_reverse_arg)
3391 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3392#endif
3393
3394 curbuf->b_p_initialized = TRUE;
3395 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003396 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397 check_buf_options(curbuf);
3398 check_win_options(curwin);
3399 check_options();
3400
3401 /* Must be before option_expand(), because that one needs vim_isIDc() */
3402 didset_options();
3403
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003404#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003405 /* Use the current chartab for the generic chartab. This is not in
3406 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003407 init_spell_chartab();
3408#endif
3409
Bram Moolenaar071d4272004-06-13 20:20:40 +00003410 /*
3411 * Expand environment variables and things like "~" for the defaults.
3412 * If option_expand() returns non-NULL the variable is expanded. This can
3413 * only happen for non-indirect options.
3414 * Also set the default to the expanded value, so ":set" does not list
3415 * them.
3416 * Don't set the P_ALLOCED flag, because we don't want to free the
3417 * default.
3418 */
3419 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3420 {
3421 if ((options[opt_idx].flags & P_GETTEXT)
3422 && options[opt_idx].var != NULL)
3423 p = (char_u *)_(*(char **)options[opt_idx].var);
3424 else
3425 p = option_expand(opt_idx, NULL);
3426 if (p != NULL && (p = vim_strsave(p)) != NULL)
3427 {
3428 *(char_u **)options[opt_idx].var = p;
3429 /* VIMEXP
3430 * Defaults for all expanded options are currently the same for Vi
3431 * and Vim. When this changes, add some code here! Also need to
3432 * split P_DEF_ALLOCED in two.
3433 */
3434 if (options[opt_idx].flags & P_DEF_ALLOCED)
3435 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3436 options[opt_idx].def_val[VI_DEFAULT] = p;
3437 options[opt_idx].flags |= P_DEF_ALLOCED;
3438 }
3439 }
3440
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 save_file_ff(curbuf); /* Buffer is unchanged */
3442
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443#if defined(FEAT_ARABIC)
3444 /* Detect use of mlterm.
3445 * Mlterm is a terminal emulator akin to xterm that has some special
3446 * abilities (bidi namely).
3447 * NOTE: mlterm's author is being asked to 'set' a variable
3448 * instead of an environment variable due to inheritance.
3449 */
3450 if (mch_getenv((char_u *)"MLTERM") != NULL)
3451 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3452#endif
3453
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003454 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003455
3456#ifdef FEAT_MBYTE
3457# if defined(WIN3264) && defined(FEAT_GETTEXT)
3458 /*
3459 * If $LANG isn't set, try to get a good value for it. This makes the
3460 * right language be used automatically. Don't do this for English.
3461 */
3462 if (mch_getenv((char_u *)"LANG") == NULL)
3463 {
3464 char buf[20];
3465
3466 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3467 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3468 * only the first two. */
3469 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3470 (LPTSTR)buf, 20);
3471 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3472 {
3473 /* There are a few exceptions (probably more) */
3474 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3475 STRCPY(buf, "zh_TW");
3476 else if (STRNICMP(buf, "chs", 3) == 0
3477 || STRNICMP(buf, "zhc", 3) == 0)
3478 STRCPY(buf, "zh_CN");
3479 else if (STRNICMP(buf, "jp", 2) == 0)
3480 STRCPY(buf, "ja");
3481 else
3482 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003483 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003484 }
3485 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003486# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003487# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003488 /* Moved to os_mac_conv.c to avoid dependency problems. */
3489 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003490# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491# endif
3492
3493 /* enc_locale() will try to find the encoding of the current locale. */
3494 p = enc_locale();
3495 if (p != NULL)
3496 {
3497 char_u *save_enc;
3498
3499 /* Try setting 'encoding' and check if the value is valid.
3500 * If not, go back to the default "latin1". */
3501 save_enc = p_enc;
3502 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003503 if (STRCMP(p_enc, "gb18030") == 0)
3504 {
3505 /* We don't support "gb18030", but "cp936" is a good substitute
3506 * for practical purposes, thus use that. It's not an alias to
3507 * still support conversion between gb18030 and utf-8. */
3508 p_enc = vim_strsave((char_u *)"cp936");
3509 vim_free(p);
3510 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003511 if (mb_init() == NULL)
3512 {
3513 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003514 if (opt_idx >= 0)
3515 {
3516 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3517 options[opt_idx].flags |= P_DEF_ALLOCED;
3518 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003520#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003521 if (STRCMP(p_enc, "latin1") == 0
3522# ifdef FEAT_MBYTE
3523 || enc_utf8
3524# endif
3525 )
3526 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003527 /* Adjust the default for 'isprint' and 'iskeyword' to match
3528 * latin1. Also set the defaults for when 'nocompatible' is
3529 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003530 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003531 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003532 set_string_option_direct((char_u *)"isk", -1,
3533 ISK_LATIN1, OPT_FREE, SID_NONE);
3534 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003535 if (opt_idx >= 0)
3536 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003537 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003538 if (opt_idx >= 0)
3539 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003540 (void)init_chartab();
3541 }
3542#endif
3543
Bram Moolenaar071d4272004-06-13 20:20:40 +00003544# if defined(WIN3264) && !defined(FEAT_GUI)
3545 /* Win32 console: When GetACP() returns a different value from
3546 * GetConsoleCP() set 'termencoding'. */
3547 if (GetACP() != GetConsoleCP())
3548 {
3549 char buf[50];
3550
3551 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3552 p_tenc = vim_strsave((char_u *)buf);
3553 if (p_tenc != NULL)
3554 {
3555 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003556 if (opt_idx >= 0)
3557 {
3558 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3559 options[opt_idx].flags |= P_DEF_ALLOCED;
3560 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561 convert_setup(&input_conv, p_tenc, p_enc);
3562 convert_setup(&output_conv, p_enc, p_tenc);
3563 }
3564 else
3565 p_tenc = empty_option;
3566 }
3567# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003568# if defined(WIN3264) && defined(FEAT_MBYTE)
3569 /* $HOME may have characters in active code page. */
3570 init_homedir();
3571# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 }
3573 else
3574 {
3575 vim_free(p_enc);
3576 p_enc = save_enc;
3577 }
3578 }
3579#endif
3580
3581#ifdef FEAT_MULTI_LANG
3582 /* Set the default for 'helplang'. */
3583 set_helplang_default(get_mess_lang());
3584#endif
3585}
3586
3587/*
3588 * Set an option to its default value.
3589 * This does not take care of side effects!
3590 */
3591 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003592set_option_default(
3593 int opt_idx,
3594 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3595 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596{
3597 char_u *varp; /* pointer to variable for current option */
3598 int dvi; /* index in def_val[] */
3599 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003600 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3602
3603 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3604 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003605 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003606 {
3607 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3608 if (flags & P_STRING)
3609 {
3610 /* Use set_string_option_direct() for local options to handle
3611 * freeing and allocating the value. */
3612 if (options[opt_idx].indir != PV_NONE)
3613 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003614 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615 else
3616 {
3617 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3618 free_string_option(*(char_u **)(varp));
3619 *(char_u **)varp = options[opt_idx].def_val[dvi];
3620 options[opt_idx].flags &= ~P_ALLOCED;
3621 }
3622 }
3623 else if (flags & P_NUM)
3624 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003625 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003626 win_comp_scroll(curwin);
3627 else
3628 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003629 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630 /* May also set global value for local option. */
3631 if (both)
3632 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3633 *(long *)varp;
3634 }
3635 }
3636 else /* P_BOOL */
3637 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003638 /* the cast to long is required for Manx C, long_i is needed for
3639 * MSVC */
3640 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003641#ifdef UNIX
3642 /* 'modeline' defaults to off for root */
3643 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3644 *(int *)varp = FALSE;
3645#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003646 /* May also set global value for local option. */
3647 if (both)
3648 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3649 *(int *)varp;
3650 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003651
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003652 /* The default value is not insecure. */
3653 flagsp = insecure_flag(opt_idx, opt_flags);
3654 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655 }
3656
3657#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003658 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003659#endif
3660}
3661
3662/*
3663 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003664 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665 */
3666 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003667set_options_default(
3668 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003669{
3670 int i;
3671#ifdef FEAT_WINDOWS
3672 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003673 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674#endif
3675
3676 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003677 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003678#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003679 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003680 || (TRUE
3681# if defined(FEAT_MBYTE)
3682 && options[i].var != (char_u *)&p_enc
3683# endif
3684# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003685 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003686 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003687# endif
3688 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003689#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003690 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691 set_option_default(i, opt_flags, p_cp);
3692
3693#ifdef FEAT_WINDOWS
3694 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003695 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 win_comp_scroll(wp);
3697#else
3698 win_comp_scroll(curwin);
3699#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003700#ifdef FEAT_CINDENT
3701 parse_cino(curbuf);
3702#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703}
3704
3705/*
3706 * Set the Vi-default value of a string option.
3707 * Used for 'sh', 'backupskip' and 'term'.
3708 */
3709 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003710set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711{
3712 char_u *p;
3713 int opt_idx;
3714
3715 p = vim_strsave(val);
3716 if (p != NULL) /* we don't want a NULL */
3717 {
3718 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003719 if (opt_idx >= 0)
3720 {
3721 if (options[opt_idx].flags & P_DEF_ALLOCED)
3722 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3723 options[opt_idx].def_val[VI_DEFAULT] = p;
3724 options[opt_idx].flags |= P_DEF_ALLOCED;
3725 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003726 }
3727}
3728
3729/*
3730 * Set the Vi-default value of a number option.
3731 * Used for 'lines' and 'columns'.
3732 */
3733 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003734set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003735{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003736 int opt_idx;
3737
3738 opt_idx = findoption((char_u *)name);
3739 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003740 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003741}
3742
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003743#if defined(EXITFREE) || defined(PROTO)
3744/*
3745 * Free all options.
3746 */
3747 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003748free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003749{
3750 int i;
3751
3752 for (i = 0; !istermoption(&options[i]); i++)
3753 {
3754 if (options[i].indir == PV_NONE)
3755 {
3756 /* global option: free value and default value. */
3757 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3758 free_string_option(*(char_u **)options[i].var);
3759 if (options[i].flags & P_DEF_ALLOCED)
3760 free_string_option(options[i].def_val[VI_DEFAULT]);
3761 }
3762 else if (options[i].var != VAR_WIN
3763 && (options[i].flags & P_STRING))
3764 /* buffer-local option: free global value */
3765 free_string_option(*(char_u **)options[i].var);
3766 }
3767}
3768#endif
3769
3770
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771/*
3772 * Initialize the options, part two: After getting Rows and Columns and
3773 * setting 'term'.
3774 */
3775 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003776set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003778 int idx;
3779
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780 /*
3781 * 'scroll' defaults to half the window height. Note that this default is
3782 * wrong when the window height changes.
3783 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003784 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003785 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003786 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003787 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 comp_col();
3789
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003790 /*
3791 * 'window' is only for backwards compatibility with Vi.
3792 * Default is Rows - 1.
3793 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003794 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003795 p_window = Rows - 1;
3796 set_number_default("window", Rows - 1);
3797
Bram Moolenaarf740b292006-02-16 22:11:02 +00003798 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003799#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003800 /*
3801 * If 'background' wasn't set by the user, try guessing the value,
3802 * depending on the terminal name. Only need to check for terminals
3803 * with a dark background, that can handle color.
3804 */
3805 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003806 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3807 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003809 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003810 /* don't mark it as set, when starting the GUI it may be
3811 * changed again */
3812 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 }
3814#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003815
3816#ifdef CURSOR_SHAPE
3817 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3818#endif
3819#ifdef FEAT_MOUSESHAPE
3820 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3821#endif
3822#ifdef FEAT_PRINTER
3823 (void)parse_printoptions(); /* parse 'printoptions' default value */
3824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825}
3826
3827/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003828 * Return "dark" or "light" depending on the kind of terminal.
3829 * This is just guessing! Recognized are:
3830 * "linux" Linux console
3831 * "screen.linux" Linux console with screen
3832 * "cygwin" Cygwin shell
3833 * "putty" Putty program
3834 * We also check the COLORFGBG environment variable, which is set by
3835 * rxvt and derivatives. This variable contains either two or three
3836 * values separated by semicolons; we want the last value in either
3837 * case. If this value is 0-6 or 8, our background is dark.
3838 */
3839 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003840term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003841{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003842#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003843 /* DOS console nearly always black */
3844 return (char_u *)"dark";
3845#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003846 char_u *p;
3847
Bram Moolenaarf740b292006-02-16 22:11:02 +00003848 if (STRCMP(T_NAME, "linux") == 0
3849 || STRCMP(T_NAME, "screen.linux") == 0
3850 || STRCMP(T_NAME, "cygwin") == 0
3851 || STRCMP(T_NAME, "putty") == 0
3852 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3853 && (p = vim_strrchr(p, ';')) != NULL
3854 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3855 && p[2] == NUL))
3856 return (char_u *)"dark";
3857 return (char_u *)"light";
3858#endif
3859}
3860
3861/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 * Initialize the options, part three: After reading the .vimrc
3863 */
3864 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003865set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003866{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003867#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868/*
3869 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3870 * This is done after other initializations, where 'shell' might have been
3871 * set, but only if they have not been set before.
3872 */
3873 char_u *p;
3874 int idx_srr;
3875 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003876# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877 int idx_sp;
3878 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003879# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880
3881 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003882 if (idx_srr < 0)
3883 do_srr = FALSE;
3884 else
3885 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003886# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003888 if (idx_sp < 0)
3889 do_sp = FALSE;
3890 else
3891 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003892# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003893 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003894 if (p != NULL)
3895 {
3896 /*
3897 * Default for p_sp is "| tee", for p_srr is ">".
3898 * For known shells it is changed here to include stderr.
3899 */
3900 if ( fnamecmp(p, "csh") == 0
3901 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003902# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903 || fnamecmp(p, "csh.exe") == 0
3904 || fnamecmp(p, "tcsh.exe") == 0
3905# endif
3906 )
3907 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003908# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003909 if (do_sp)
3910 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003911# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003913# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003915# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3917 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003918# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 if (do_srr)
3920 {
3921 p_srr = (char_u *)">&";
3922 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3923 }
3924 }
3925 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003926 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927 if ( fnamecmp(p, "sh") == 0
3928 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003929 || fnamecmp(p, "mksh") == 0
3930 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003932 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003934 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003935# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003936 || fnamecmp(p, "cmd") == 0
3937 || fnamecmp(p, "sh.exe") == 0
3938 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003939 || fnamecmp(p, "mksh.exe") == 0
3940 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003941 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003942 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 || fnamecmp(p, "bash.exe") == 0
3944 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003946 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003948# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 if (do_sp)
3950 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003951# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003953# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003955# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3957 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003958# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959 if (do_srr)
3960 {
3961 p_srr = (char_u *)">%s 2>&1";
3962 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3963 }
3964 }
3965 vim_free(p);
3966 }
3967#endif
3968
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003969#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003971 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3972 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973 * This is done after other initializations, where 'shell' might have been
3974 * set, but only if they have not been set before. Default for p_shcf is
3975 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003976 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003978 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 {
3980 int idx3;
3981
3982 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003983 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 {
3985 p_shcf = (char_u *)"-c";
3986 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3987 }
3988
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003989# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990 /* Somehow Win32 requires the quotes around the redirection too */
3991 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003992 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993 {
3994 p_sxq = (char_u *)"\"";
3995 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3996 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003997# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003999 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 {
4001 p_shq = (char_u *)"\"";
4002 options[idx3].def_val[VI_DEFAULT] = p_shq;
4003 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004004# endif
4005 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004006 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4007 {
4008 int idx3;
4009
4010 /*
4011 * cmd.exe on Windows will strip the first and last double quote given
4012 * on the command line, e.g. most of the time things like:
4013 * cmd /c "my path/to/echo" "my args to echo"
4014 * become:
4015 * my path/to/echo" "my args to echo
4016 * when executed.
4017 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004018 * To avoid this, set shellxquote to surround the command in
4019 * parenthesis. This appears to make most commands work, without
4020 * breaking commands that worked previously, such as
4021 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004022 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004023 idx3 = findoption((char_u *)"sxq");
4024 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4025 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004026 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004027 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4028 }
4029
Bram Moolenaara64ba222012-02-12 23:23:31 +01004030 idx3 = findoption((char_u *)"shcf");
4031 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4032 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004033 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004034 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4035 }
4036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037#endif
4038
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004039 if (bufempty())
4040 {
4041 int idx_ffs = findoption((char_u *)"ffs");
4042
4043 /* Apply the first entry of 'fileformats' to the initial buffer. */
4044 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4045 set_fileformat(default_fileformat(), OPT_LOCAL);
4046 }
4047
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048#ifdef FEAT_TITLE
4049 set_title_defaults();
4050#endif
4051}
4052
4053#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4054/*
4055 * When 'helplang' is still at its default value, set it to "lang".
4056 * Only the first two characters of "lang" are used.
4057 */
4058 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004059set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060{
4061 int idx;
4062
4063 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4064 return;
4065 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004066 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 {
4068 if (options[idx].flags & P_ALLOCED)
4069 free_string_option(p_hlg);
4070 p_hlg = vim_strsave(lang);
4071 if (p_hlg == NULL)
4072 p_hlg = empty_option;
4073 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004074 {
4075 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4076 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4077 {
4078 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4079 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4080 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004082 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 options[idx].flags |= P_ALLOCED;
4084 }
4085}
4086#endif
4087
4088#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004089static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090
4091 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004092gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093{
4094 if (gui_get_lightness(gui.back_pixel) < 127)
4095 return (char_u *)"dark";
4096 return (char_u *)"light";
4097}
4098
4099/*
4100 * Option initializations that can only be done after opening the GUI window.
4101 */
4102 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004103init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104{
4105 /* Set the 'background' option according to the lightness of the
4106 * background color, unless the user has set it already. */
4107 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4108 {
4109 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4110 highlight_changed();
4111 }
4112}
4113#endif
4114
4115#ifdef FEAT_TITLE
4116/*
4117 * 'title' and 'icon' only default to true if they have not been set or reset
4118 * in .vimrc and we can read the old value.
4119 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4120 * they can be reset. This reduces startup time when using X on a remote
4121 * machine.
4122 */
4123 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004124set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125{
4126 int idx1;
4127 long val;
4128
4129 /*
4130 * If GUI is (going to be) used, we can always set the window title and
4131 * icon name. Saves a bit of time, because the X11 display server does
4132 * not need to be contacted.
4133 */
4134 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004135 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 {
4137#ifdef FEAT_GUI
4138 if (gui.starting || gui.in_use)
4139 val = TRUE;
4140 else
4141#endif
4142 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004143 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 p_title = val;
4145 }
4146 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004147 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 {
4149#ifdef FEAT_GUI
4150 if (gui.starting || gui.in_use)
4151 val = TRUE;
4152 else
4153#endif
4154 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004155 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004156 p_icon = val;
4157 }
4158}
4159#endif
4160
4161/*
4162 * Parse 'arg' for option settings.
4163 *
4164 * 'arg' may be IObuff, but only when no errors can be present and option
4165 * does not need to be expanded with option_expand().
4166 * "opt_flags":
4167 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004168 * OPT_GLOBAL for ":setglobal"
4169 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004170 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004171 * OPT_WINONLY to only set window-local options
4172 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004173 *
4174 * returns FAIL if an error is detected, OK otherwise
4175 */
4176 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004177do_set(
4178 char_u *arg, /* option string (may be written to!) */
4179 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180{
4181 int opt_idx;
4182 char_u *errmsg;
4183 char_u errbuf[80];
4184 char_u *startarg;
4185 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4186 int nextchar; /* next non-white char after option name */
4187 int afterchar; /* character just after option name */
4188 int len;
4189 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004190 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 int key;
4192 long_u flags; /* flags for current option */
4193 char_u *varp = NULL; /* pointer to variable for current option */
4194 int did_show = FALSE; /* already showed one value */
4195 int adding; /* "opt+=arg" */
4196 int prepending; /* "opt^=arg" */
4197 int removing; /* "opt-=arg" */
4198 int cp_val = 0;
4199 char_u key_name[2];
4200
4201 if (*arg == NUL)
4202 {
4203 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004204 did_show = TRUE;
4205 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206 }
4207
4208 while (*arg != NUL) /* loop to process all options */
4209 {
4210 errmsg = NULL;
4211 startarg = arg; /* remember for error message */
4212
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004213 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4214 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215 {
4216 /*
4217 * ":set all" show all options.
4218 * ":set all&" set all options to their default value.
4219 */
4220 arg += 3;
4221 if (*arg == '&')
4222 {
4223 ++arg;
4224 /* Only for :set command set global value of local options. */
4225 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004226 didset_options();
4227 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004228 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229 }
4230 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004231 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004232 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004233 did_show = TRUE;
4234 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004236 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004237 {
4238 showoptions(2, opt_flags);
4239 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004240 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004241 arg += 7;
4242 }
4243 else
4244 {
4245 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004246 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004247 {
4248 prefix = 0;
4249 arg += 2;
4250 }
4251 else if (STRNCMP(arg, "inv", 3) == 0)
4252 {
4253 prefix = 2;
4254 arg += 3;
4255 }
4256
4257 /* find end of name */
4258 key = 0;
4259 if (*arg == '<')
4260 {
4261 nextchar = 0;
4262 opt_idx = -1;
4263 /* look out for <t_>;> */
4264 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4265 len = 5;
4266 else
4267 {
4268 len = 1;
4269 while (arg[len] != NUL && arg[len] != '>')
4270 ++len;
4271 }
4272 if (arg[len] != '>')
4273 {
4274 errmsg = e_invarg;
4275 goto skip;
4276 }
4277 arg[len] = NUL; /* put NUL after name */
4278 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4279 opt_idx = findoption(arg + 1);
4280 arg[len++] = '>'; /* restore '>' */
4281 if (opt_idx == -1)
4282 key = find_key_option(arg + 1);
4283 }
4284 else
4285 {
4286 len = 0;
4287 /*
4288 * The two characters after "t_" may not be alphanumeric.
4289 */
4290 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4291 len = 4;
4292 else
4293 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4294 ++len;
4295 nextchar = arg[len];
4296 arg[len] = NUL; /* put NUL after name */
4297 opt_idx = findoption(arg);
4298 arg[len] = nextchar; /* restore nextchar */
4299 if (opt_idx == -1)
4300 key = find_key_option(arg);
4301 }
4302
4303 /* remember character after option name */
4304 afterchar = arg[len];
4305
4306 /* skip white space, allow ":set ai ?" */
4307 while (vim_iswhite(arg[len]))
4308 ++len;
4309
4310 adding = FALSE;
4311 prepending = FALSE;
4312 removing = FALSE;
4313 if (arg[len] != NUL && arg[len + 1] == '=')
4314 {
4315 if (arg[len] == '+')
4316 {
4317 adding = TRUE; /* "+=" */
4318 ++len;
4319 }
4320 else if (arg[len] == '^')
4321 {
4322 prepending = TRUE; /* "^=" */
4323 ++len;
4324 }
4325 else if (arg[len] == '-')
4326 {
4327 removing = TRUE; /* "-=" */
4328 ++len;
4329 }
4330 }
4331 nextchar = arg[len];
4332
4333 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4334 {
4335 errmsg = (char_u *)N_("E518: Unknown option");
4336 goto skip;
4337 }
4338
4339 if (opt_idx >= 0)
4340 {
4341 if (options[opt_idx].var == NULL) /* hidden option: skip */
4342 {
4343 /* Only give an error message when requesting the value of
4344 * a hidden option, ignore setting it. */
4345 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4346 && (!(options[opt_idx].flags & P_BOOL)
4347 || nextchar == '?'))
4348 errmsg = (char_u *)N_("E519: Option not supported");
4349 goto skip;
4350 }
4351
4352 flags = options[opt_idx].flags;
4353 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4354 }
4355 else
4356 {
4357 flags = P_STRING;
4358 if (key < 0)
4359 {
4360 key_name[0] = KEY2TERMCAP0(key);
4361 key_name[1] = KEY2TERMCAP1(key);
4362 }
4363 else
4364 {
4365 key_name[0] = KS_KEY;
4366 key_name[1] = (key & 0xff);
4367 }
4368 }
4369
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004370 /* Skip all options that are not window-local (used when showing
4371 * an already loaded buffer in a window). */
4372 if ((opt_flags & OPT_WINONLY)
4373 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4374 goto skip;
4375
Bram Moolenaara3227e22006-03-08 21:32:40 +00004376 /* Skip all options that are window-local (used for :vimgrep). */
4377 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4378 && options[opt_idx].var == VAR_WIN)
4379 goto skip;
4380
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004381 /* Disallow changing some options from modelines. */
4382 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004384 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004385 {
4386 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4387 goto skip;
4388 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004389#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004390 /* In diff mode some options are overruled. This avoids that
4391 * 'foldmethod' becomes "marker" instead of "diff" and that
4392 * "wrap" gets set. */
4393 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004394 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004395 && (options[opt_idx].indir == PV_FDM
4396 || options[opt_idx].indir == PV_WRAP))
4397 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399 }
4400
4401#ifdef HAVE_SANDBOX
4402 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004403 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 {
4405 errmsg = (char_u *)_(e_sandbox);
4406 goto skip;
4407 }
4408#endif
4409
4410 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4411 {
4412 arg += len;
4413 cp_val = p_cp;
4414 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4415 {
4416 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4417 {
4418 cp_val = FALSE;
4419 arg += 3;
4420 }
4421 else /* "opt&vi": set to Vi default */
4422 {
4423 cp_val = TRUE;
4424 arg += 2;
4425 }
4426 }
4427 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4428 && arg[1] != NUL && !vim_iswhite(arg[1]))
4429 {
4430 errmsg = e_trailing;
4431 goto skip;
4432 }
4433 }
4434
4435 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004436 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4437 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004438 */
4439 if (nextchar == '?'
4440 || (prefix == 1
4441 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4442 && !(flags & P_BOOL)))
4443 {
4444 /*
4445 * print value
4446 */
4447 if (did_show)
4448 msg_putchar('\n'); /* cursor below last one */
4449 else
4450 {
4451 gotocmdline(TRUE); /* cursor at status line */
4452 did_show = TRUE; /* remember that we did a line */
4453 }
4454 if (opt_idx >= 0)
4455 {
4456 showoneopt(&options[opt_idx], opt_flags);
4457#ifdef FEAT_EVAL
4458 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004459 {
4460 /* Mention where the option was last set. */
4461 if (varp == options[opt_idx].var)
4462 last_set_msg(options[opt_idx].scriptID);
4463 else if ((int)options[opt_idx].indir & PV_WIN)
4464 last_set_msg(curwin->w_p_scriptID[
4465 (int)options[opt_idx].indir & PV_MASK]);
4466 else if ((int)options[opt_idx].indir & PV_BUF)
4467 last_set_msg(curbuf->b_p_scriptID[
4468 (int)options[opt_idx].indir & PV_MASK]);
4469 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004470#endif
4471 }
4472 else
4473 {
4474 char_u *p;
4475
4476 p = find_termcode(key_name);
4477 if (p == NULL)
4478 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004479 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004480 goto skip;
4481 }
4482 else
4483 (void)show_one_termcode(key_name, p, TRUE);
4484 }
4485 if (nextchar != '?'
4486 && nextchar != NUL && !vim_iswhite(afterchar))
4487 errmsg = e_trailing;
4488 }
4489 else
4490 {
4491 if (flags & P_BOOL) /* boolean */
4492 {
4493 if (nextchar == '=' || nextchar == ':')
4494 {
4495 errmsg = e_invarg;
4496 goto skip;
4497 }
4498
4499 /*
4500 * ":set opt!": invert
4501 * ":set opt&": reset to default value
4502 * ":set opt<": reset to global value
4503 */
4504 if (nextchar == '!')
4505 value = *(int *)(varp) ^ 1;
4506 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004507 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004508 ((flags & P_VI_DEF) || cp_val)
4509 ? VI_DEFAULT : VIM_DEFAULT];
4510 else if (nextchar == '<')
4511 {
4512 /* For 'autoread' -1 means to use global value. */
4513 if ((int *)varp == &curbuf->b_p_ar
4514 && opt_flags == OPT_LOCAL)
4515 value = -1;
4516 else
4517 value = *(int *)get_varp_scope(&(options[opt_idx]),
4518 OPT_GLOBAL);
4519 }
4520 else
4521 {
4522 /*
4523 * ":set invopt": invert
4524 * ":set opt" or ":set noopt": set or reset
4525 */
4526 if (nextchar != NUL && !vim_iswhite(afterchar))
4527 {
4528 errmsg = e_trailing;
4529 goto skip;
4530 }
4531 if (prefix == 2) /* inv */
4532 value = *(int *)(varp) ^ 1;
4533 else
4534 value = prefix;
4535 }
4536
4537 errmsg = set_bool_option(opt_idx, varp, (int)value,
4538 opt_flags);
4539 }
4540 else /* numeric or string */
4541 {
4542 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4543 || prefix != 1)
4544 {
4545 errmsg = e_invarg;
4546 goto skip;
4547 }
4548
4549 if (flags & P_NUM) /* numeric */
4550 {
4551 /*
4552 * Different ways to set a number option:
4553 * & set to default value
4554 * < set to global value
4555 * <xx> accept special key codes for 'wildchar'
4556 * c accept any non-digit for 'wildchar'
4557 * [-]0-9 set number
4558 * other error
4559 */
4560 ++arg;
4561 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004562 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004563 ((flags & P_VI_DEF) || cp_val)
4564 ? VI_DEFAULT : VIM_DEFAULT];
4565 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004566 {
4567 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4568 * use the global value. */
4569 if ((long *)varp == &curbuf->b_p_ul
4570 && opt_flags == OPT_LOCAL)
4571 value = NO_LOCAL_UNDOLEVEL;
4572 else
4573 value = *(long *)get_varp_scope(
4574 &(options[opt_idx]), OPT_GLOBAL);
4575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004576 else if (((long *)varp == &p_wc
4577 || (long *)varp == &p_wcm)
4578 && (*arg == '<'
4579 || *arg == '^'
4580 || ((!arg[1] || vim_iswhite(arg[1]))
4581 && !VIM_ISDIGIT(*arg))))
4582 {
4583 value = string_to_key(arg);
4584 if (value == 0 && (long *)varp != &p_wcm)
4585 {
4586 errmsg = e_invarg;
4587 goto skip;
4588 }
4589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004590 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4591 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004592 /* Allow negative (for 'undolevels'), octal and
4593 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004594 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4595 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004596 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4597 {
4598 errmsg = e_invarg;
4599 goto skip;
4600 }
4601 }
4602 else
4603 {
4604 errmsg = (char_u *)N_("E521: Number required after =");
4605 goto skip;
4606 }
4607
4608 if (adding)
4609 value = *(long *)varp + value;
4610 if (prepending)
4611 value = *(long *)varp * value;
4612 if (removing)
4613 value = *(long *)varp - value;
4614 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004615 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004616 }
4617 else if (opt_idx >= 0) /* string */
4618 {
4619 char_u *save_arg = NULL;
4620 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004621 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004622 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004623 char_u *origval = NULL;
4624#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4625 char_u *saved_origval = NULL;
4626#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004627 unsigned newlen;
4628 int comma;
4629 int bs;
4630 int new_value_alloced; /* new string option
4631 was allocated */
4632
4633 /* When using ":set opt=val" for a global option
4634 * with a local value the local value will be
4635 * reset, use the global value here. */
4636 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004637 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004638 varp = options[opt_idx].var;
4639
4640 /* The old value is kept until we are sure that the
4641 * new value is valid. */
4642 oldval = *(char_u **)varp;
4643 if (nextchar == '&') /* set to default val */
4644 {
4645 newval = options[opt_idx].def_val[
4646 ((flags & P_VI_DEF) || cp_val)
4647 ? VI_DEFAULT : VIM_DEFAULT];
4648 if ((char_u **)varp == &p_bg)
4649 {
4650 /* guess the value of 'background' */
4651#ifdef FEAT_GUI
4652 if (gui.in_use)
4653 newval = gui_bg_default();
4654 else
4655#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004656 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004657 }
4658
4659 /* expand environment variables and ~ (since the
4660 * default value was already expanded, only
4661 * required when an environment variable was set
4662 * later */
4663 if (newval == NULL)
4664 newval = empty_option;
4665 else
4666 {
4667 s = option_expand(opt_idx, newval);
4668 if (s == NULL)
4669 s = newval;
4670 newval = vim_strsave(s);
4671 }
4672 new_value_alloced = TRUE;
4673 }
4674 else if (nextchar == '<') /* set to global val */
4675 {
4676 newval = vim_strsave(*(char_u **)get_varp_scope(
4677 &(options[opt_idx]), OPT_GLOBAL));
4678 new_value_alloced = TRUE;
4679 }
4680 else
4681 {
4682 ++arg; /* jump to after the '=' or ':' */
4683
4684 /*
4685 * Set 'keywordprg' to ":help" if an empty
4686 * value was passed to :set by the user.
4687 * Misuse errbuf[] for the resulting string.
4688 */
4689 if (varp == (char_u *)&p_kp
4690 && (*arg == NUL || *arg == ' '))
4691 {
4692 STRCPY(errbuf, ":help");
4693 save_arg = arg;
4694 arg = errbuf;
4695 }
4696 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004697 * Convert 'backspace' number to string, for
4698 * adding, prepending and removing string.
4699 */
4700 else if (varp == (char_u *)&p_bs
4701 && VIM_ISDIGIT(**(char_u **)varp))
4702 {
4703 i = getdigits((char_u **)varp);
4704 switch (i)
4705 {
4706 case 0:
4707 *(char_u **)varp = empty_option;
4708 break;
4709 case 1:
4710 *(char_u **)varp = vim_strsave(
4711 (char_u *)"indent,eol");
4712 break;
4713 case 2:
4714 *(char_u **)varp = vim_strsave(
4715 (char_u *)"indent,eol,start");
4716 break;
4717 }
4718 vim_free(oldval);
4719 oldval = *(char_u **)varp;
4720 }
4721 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004722 * Convert 'whichwrap' number to string, for
4723 * backwards compatibility with Vim 3.0.
4724 * Misuse errbuf[] for the resulting string.
4725 */
4726 else if (varp == (char_u *)&p_ww
4727 && VIM_ISDIGIT(*arg))
4728 {
4729 *errbuf = NUL;
4730 i = getdigits(&arg);
4731 if (i & 1)
4732 STRCAT(errbuf, "b,");
4733 if (i & 2)
4734 STRCAT(errbuf, "s,");
4735 if (i & 4)
4736 STRCAT(errbuf, "h,l,");
4737 if (i & 8)
4738 STRCAT(errbuf, "<,>,");
4739 if (i & 16)
4740 STRCAT(errbuf, "[,],");
4741 if (*errbuf != NUL) /* remove trailing , */
4742 errbuf[STRLEN(errbuf) - 1] = NUL;
4743 save_arg = arg;
4744 arg = errbuf;
4745 }
4746 /*
4747 * Remove '>' before 'dir' and 'bdir', for
4748 * backwards compatibility with version 3.0
4749 */
4750 else if ( *arg == '>'
4751 && (varp == (char_u *)&p_dir
4752 || varp == (char_u *)&p_bdir))
4753 {
4754 ++arg;
4755 }
4756
4757 /* When setting the local value of a global
4758 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004759 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760 && (opt_flags & OPT_LOCAL))
4761 origval = *(char_u **)get_varp(
4762 &options[opt_idx]);
4763 else
4764 origval = oldval;
4765
4766 /*
4767 * Copy the new string into allocated memory.
4768 * Can't use set_string_option_direct(), because
4769 * we need to remove the backslashes.
4770 */
4771 /* get a bit too much */
4772 newlen = (unsigned)STRLEN(arg) + 1;
4773 if (adding || prepending || removing)
4774 newlen += (unsigned)STRLEN(origval) + 1;
4775 newval = alloc(newlen);
4776 if (newval == NULL) /* out of mem, don't change */
4777 break;
4778 s = newval;
4779
4780 /*
4781 * Copy the string, skip over escaped chars.
4782 * For MS-DOS and WIN32 backslashes before normal
4783 * file name characters are not removed, and keep
4784 * backslash at start, for "\\machine\path", but
4785 * do remove it for "\\\\machine\\path".
4786 * The reverse is found in ExpandOldSetting().
4787 */
4788 while (*arg && !vim_iswhite(*arg))
4789 {
4790 if (*arg == '\\' && arg[1] != NUL
4791#ifdef BACKSLASH_IN_FILENAME
4792 && !((flags & P_EXPAND)
4793 && vim_isfilec(arg[1])
4794 && (arg[1] != '\\'
4795 || (s == newval
4796 && arg[2] != '\\')))
4797#endif
4798 )
4799 ++arg; /* remove backslash */
4800#ifdef FEAT_MBYTE
4801 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004802 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004803 {
4804 /* copy multibyte char */
4805 mch_memmove(s, arg, (size_t)i);
4806 arg += i;
4807 s += i;
4808 }
4809 else
4810#endif
4811 *s++ = *arg++;
4812 }
4813 *s = NUL;
4814
4815 /*
4816 * Expand environment variables and ~.
4817 * Don't do it when adding without inserting a
4818 * comma.
4819 */
4820 if (!(adding || prepending || removing)
4821 || (flags & P_COMMA))
4822 {
4823 s = option_expand(opt_idx, newval);
4824 if (s != NULL)
4825 {
4826 vim_free(newval);
4827 newlen = (unsigned)STRLEN(s) + 1;
4828 if (adding || prepending || removing)
4829 newlen += (unsigned)STRLEN(origval) + 1;
4830 newval = alloc(newlen);
4831 if (newval == NULL)
4832 break;
4833 STRCPY(newval, s);
4834 }
4835 }
4836
4837 /* locate newval[] in origval[] when removing it
4838 * and when adding to avoid duplicates */
4839 i = 0; /* init for GCC */
4840 if (removing || (flags & P_NODUP))
4841 {
4842 i = (int)STRLEN(newval);
4843 bs = 0;
4844 for (s = origval; *s; ++s)
4845 {
4846 if ((!(flags & P_COMMA)
4847 || s == origval
4848 || (s[-1] == ',' && !(bs & 1)))
4849 && STRNCMP(s, newval, i) == 0
4850 && (!(flags & P_COMMA)
4851 || s[i] == ','
4852 || s[i] == NUL))
4853 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004854 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004855 * even number of backslashes or a single
4856 * backslash preceded by a comma before it
4857 * is recognized as a separator */
4858 if ((s > origval + 1
4859 && s[-1] == '\\'
4860 && s[-2] != ',')
4861 || (s == origval + 1
4862 && s[-1] == '\\'))
4863
Bram Moolenaar071d4272004-06-13 20:20:40 +00004864 ++bs;
4865 else
4866 bs = 0;
4867 }
4868
4869 /* do not add if already there */
4870 if ((adding || prepending) && *s)
4871 {
4872 prepending = FALSE;
4873 adding = FALSE;
4874 STRCPY(newval, origval);
4875 }
4876 }
4877
4878 /* concatenate the two strings; add a ',' if
4879 * needed */
4880 if (adding || prepending)
4881 {
4882 comma = ((flags & P_COMMA) && *origval != NUL
4883 && *newval != NUL);
4884 if (adding)
4885 {
4886 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004887 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004888 if (comma && i > 1
4889 && (flags & P_ONECOMMA) == P_ONECOMMA
4890 && origval[i - 1] == ','
4891 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004892 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004893 mch_memmove(newval + i + comma, newval,
4894 STRLEN(newval) + 1);
4895 mch_memmove(newval, origval, (size_t)i);
4896 }
4897 else
4898 {
4899 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004900 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004901 }
4902 if (comma)
4903 newval[i] = ',';
4904 }
4905
4906 /* Remove newval[] from origval[]. (Note: "i" has
4907 * been set above and is used here). */
4908 if (removing)
4909 {
4910 STRCPY(newval, origval);
4911 if (*s)
4912 {
4913 /* may need to remove a comma */
4914 if (flags & P_COMMA)
4915 {
4916 if (s == origval)
4917 {
4918 /* include comma after string */
4919 if (s[i] == ',')
4920 ++i;
4921 }
4922 else
4923 {
4924 /* include comma before string */
4925 --s;
4926 ++i;
4927 }
4928 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004929 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004930 }
4931 }
4932
4933 if (flags & P_FLAGLIST)
4934 {
4935 /* Remove flags that appear twice. */
4936 for (s = newval; *s; ++s)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004937 {
4938 /* if options have P_FLAGLIST and
4939 * P_ONECOMMA such as 'whichwrap' */
4940 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004941 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004942 if (*s != ',' && *(s + 1) == ','
4943 && vim_strchr(s + 2, *s) != NULL)
4944 {
4945 /* Remove the duplicated value and
4946 * the next comma. */
4947 STRMOVE(s, s + 2);
4948 s -= 2;
4949 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004950 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004951 else
4952 {
4953 if ((!(flags & P_COMMA) || *s != ',')
4954 && vim_strchr(s + 1, *s) != NULL)
4955 {
4956 STRMOVE(s, s + 1);
4957 --s;
4958 }
4959 }
4960 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 }
4962
4963 if (save_arg != NULL) /* number for 'whichwrap' */
4964 arg = save_arg;
4965 new_value_alloced = TRUE;
4966 }
4967
4968 /* Set the new value. */
4969 *(char_u **)(varp) = newval;
4970
Bram Moolenaar53744302015-07-17 17:38:22 +02004971#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004972 if (!starting
4973# ifdef FEAT_CRYPT
4974 && options[opt_idx].indir != PV_KEY
4975# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004976 && origval != NULL)
4977 /* origval may be freed by
4978 * did_set_string_option(), make a copy. */
4979 saved_origval = vim_strsave(origval);
4980#endif
4981
Bram Moolenaar071d4272004-06-13 20:20:40 +00004982 /* Handle side effects, and set the global value for
4983 * ":set" on local options. */
4984 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4985 new_value_alloced, oldval, errbuf, opt_flags);
4986
4987 /* If error detected, print the error message. */
4988 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004989 {
4990#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4991 vim_free(saved_origval);
4992#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004993 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004994 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004995#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4996 if (saved_origval != NULL)
4997 {
4998 char_u buf_type[7];
4999
5000 sprintf((char *)buf_type, "%s",
5001 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005002 set_vim_var_string(VV_OPTION_NEW,
5003 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005004 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5005 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5006 apply_autocmds(EVENT_OPTIONSET,
5007 (char_u *)options[opt_idx].fullname,
5008 NULL, FALSE, NULL);
5009 reset_v_option_vars();
5010 vim_free(saved_origval);
5011 }
5012#endif
5013
Bram Moolenaar071d4272004-06-13 20:20:40 +00005014 }
5015 else /* key code option */
5016 {
5017 char_u *p;
5018
5019 if (nextchar == '&')
5020 {
5021 if (add_termcap_entry(key_name, TRUE) == FAIL)
5022 errmsg = (char_u *)N_("E522: Not found in termcap");
5023 }
5024 else
5025 {
5026 ++arg; /* jump to after the '=' or ':' */
5027 for (p = arg; *p && !vim_iswhite(*p); ++p)
5028 if (*p == '\\' && p[1] != NUL)
5029 ++p;
5030 nextchar = *p;
5031 *p = NUL;
5032 add_termcode(key_name, arg, FALSE);
5033 *p = nextchar;
5034 }
5035 if (full_screen)
5036 ttest(FALSE);
5037 redraw_all_later(CLEAR);
5038 }
5039 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005040
Bram Moolenaar071d4272004-06-13 20:20:40 +00005041 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005042 did_set_option(opt_idx, opt_flags,
5043 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005044 }
5045
5046skip:
5047 /*
5048 * Advance to next argument.
5049 * - skip until a blank found, taking care of backslashes
5050 * - skip blanks
5051 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5052 */
5053 for (i = 0; i < 2 ; ++i)
5054 {
5055 while (*arg != NUL && !vim_iswhite(*arg))
5056 if (*arg++ == '\\' && *arg != NUL)
5057 ++arg;
5058 arg = skipwhite(arg);
5059 if (*arg != '=')
5060 break;
5061 }
5062 }
5063
5064 if (errmsg != NULL)
5065 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005066 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005067 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005068 if (i + (arg - startarg) < IOSIZE)
5069 {
5070 /* append the argument with the error */
5071 STRCAT(IObuff, ": ");
5072 mch_memmove(IObuff + i, startarg, (arg - startarg));
5073 IObuff[i + (arg - startarg)] = NUL;
5074 }
5075 /* make sure all characters are printable */
5076 trans_characters(IObuff, IOSIZE);
5077
5078 ++no_wait_return; /* wait_return done later */
5079 emsg(IObuff); /* show error highlighted */
5080 --no_wait_return;
5081
5082 return FAIL;
5083 }
5084
5085 arg = skipwhite(arg);
5086 }
5087
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005088theend:
5089 if (silent_mode && did_show)
5090 {
5091 /* After displaying option values in silent mode. */
5092 silent_mode = FALSE;
5093 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5094 msg_putchar('\n');
5095 cursor_on(); /* msg_start() switches it off */
5096 out_flush();
5097 silent_mode = TRUE;
5098 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5099 }
5100
Bram Moolenaar071d4272004-06-13 20:20:40 +00005101 return OK;
5102}
5103
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005104/*
5105 * Call this when an option has been given a new value through a user command.
5106 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5107 */
5108 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005109did_set_option(
5110 int opt_idx,
5111 int opt_flags, /* possibly with OPT_MODELINE */
5112 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005113{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005114 long_u *p;
5115
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005116 options[opt_idx].flags |= P_WAS_SET;
5117
5118 /* When an option is set in the sandbox, from a modeline or in secure mode
5119 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005120 * flag. */
5121 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005122 if (secure
5123#ifdef HAVE_SANDBOX
5124 || sandbox != 0
5125#endif
5126 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005127 *p = *p | P_INSECURE;
5128 else if (new_value)
5129 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005130}
5131
Bram Moolenaar071d4272004-06-13 20:20:40 +00005132 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005133illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134{
5135 if (errbuf == NULL)
5136 return (char_u *)"";
5137 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005138 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005139 return errbuf;
5140}
5141
5142/*
5143 * Convert a key name or string into a key value.
5144 * Used for 'wildchar' and 'cedit' options.
5145 */
5146 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005147string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005148{
5149 if (*arg == '<')
5150 return find_key_option(arg + 1);
5151 if (*arg == '^')
5152 return Ctrl_chr(arg[1]);
5153 return *arg;
5154}
5155
5156#ifdef FEAT_CMDWIN
5157/*
5158 * Check value of 'cedit' and set cedit_key.
5159 * Returns NULL if value is OK, error message otherwise.
5160 */
5161 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005162check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005163{
5164 int n;
5165
5166 if (*p_cedit == NUL)
5167 cedit_key = -1;
5168 else
5169 {
5170 n = string_to_key(p_cedit);
5171 if (vim_isprintc(n))
5172 return e_invarg;
5173 cedit_key = n;
5174 }
5175 return NULL;
5176}
5177#endif
5178
5179#ifdef FEAT_TITLE
5180/*
5181 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5182 * maketitle() to create and display it.
5183 * When switching the title or icon off, call mch_restore_title() to get
5184 * the old value back.
5185 */
5186 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005187did_set_title(
5188 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005189{
5190 if (starting != NO_SCREEN
5191#ifdef FEAT_GUI
5192 && !gui.starting
5193#endif
5194 )
5195 {
5196 maketitle();
5197 if (icon)
5198 {
5199 if (!p_icon)
5200 mch_restore_title(2);
5201 }
5202 else
5203 {
5204 if (!p_title)
5205 mch_restore_title(1);
5206 }
5207 }
5208}
5209#endif
5210
5211/*
5212 * set_options_bin - called when 'bin' changes value.
5213 */
5214 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005215set_options_bin(
5216 int oldval,
5217 int newval,
5218 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005219{
5220 /*
5221 * The option values that are changed when 'bin' changes are
5222 * copied when 'bin is set and restored when 'bin' is reset.
5223 */
5224 if (newval)
5225 {
5226 if (!oldval) /* switched on */
5227 {
5228 if (!(opt_flags & OPT_GLOBAL))
5229 {
5230 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5231 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5232 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5233 curbuf->b_p_et_nobin = curbuf->b_p_et;
5234 }
5235 if (!(opt_flags & OPT_LOCAL))
5236 {
5237 p_tw_nobin = p_tw;
5238 p_wm_nobin = p_wm;
5239 p_ml_nobin = p_ml;
5240 p_et_nobin = p_et;
5241 }
5242 }
5243
5244 if (!(opt_flags & OPT_GLOBAL))
5245 {
5246 curbuf->b_p_tw = 0; /* no automatic line wrap */
5247 curbuf->b_p_wm = 0; /* no automatic line wrap */
5248 curbuf->b_p_ml = 0; /* no modelines */
5249 curbuf->b_p_et = 0; /* no expandtab */
5250 }
5251 if (!(opt_flags & OPT_LOCAL))
5252 {
5253 p_tw = 0;
5254 p_wm = 0;
5255 p_ml = FALSE;
5256 p_et = FALSE;
5257 p_bin = TRUE; /* needed when called for the "-b" argument */
5258 }
5259 }
5260 else if (oldval) /* switched off */
5261 {
5262 if (!(opt_flags & OPT_GLOBAL))
5263 {
5264 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5265 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5266 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5267 curbuf->b_p_et = curbuf->b_p_et_nobin;
5268 }
5269 if (!(opt_flags & OPT_LOCAL))
5270 {
5271 p_tw = p_tw_nobin;
5272 p_wm = p_wm_nobin;
5273 p_ml = p_ml_nobin;
5274 p_et = p_et_nobin;
5275 }
5276 }
5277}
5278
5279#ifdef FEAT_VIMINFO
5280/*
5281 * Find the parameter represented by the given character (eg ', :, ", or /),
5282 * and return its associated value in the 'viminfo' string.
5283 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005284 * If the parameter is not specified in the string or there is no following
5285 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005286 */
5287 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005288get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005289{
5290 char_u *p;
5291
5292 p = find_viminfo_parameter(type);
5293 if (p != NULL && VIM_ISDIGIT(*p))
5294 return atoi((char *)p);
5295 return -1;
5296}
5297
5298/*
5299 * Find the parameter represented by the given character (eg ''', ':', '"', or
5300 * '/') in the 'viminfo' option and return a pointer to the string after it.
5301 * Return NULL if the parameter is not specified in the string.
5302 */
5303 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005304find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005305{
5306 char_u *p;
5307
5308 for (p = p_viminfo; *p; ++p)
5309 {
5310 if (*p == type)
5311 return p + 1;
5312 if (*p == 'n') /* 'n' is always the last one */
5313 break;
5314 p = vim_strchr(p, ','); /* skip until next ',' */
5315 if (p == NULL) /* hit the end without finding parameter */
5316 break;
5317 }
5318 return NULL;
5319}
5320#endif
5321
5322/*
5323 * Expand environment variables for some string options.
5324 * These string options cannot be indirect!
5325 * If "val" is NULL expand the current value of the option.
5326 * Return pointer to NameBuff, or NULL when not expanded.
5327 */
5328 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005329option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330{
5331 /* if option doesn't need expansion nothing to do */
5332 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5333 return NULL;
5334
5335 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5336 * expand_env() would truncate the string. */
5337 if (val != NULL && STRLEN(val) > MAXPATHL)
5338 return NULL;
5339
5340 if (val == NULL)
5341 val = *(char_u **)options[opt_idx].var;
5342
5343 /*
5344 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5345 * Escape spaces when expanding 'tags', they are used to separate file
5346 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005347 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 */
5349 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005350 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005351#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005352 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5353#endif
5354 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005355 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5356 return NULL;
5357
5358 return NameBuff;
5359}
5360
5361/*
5362 * After setting various option values: recompute variables that depend on
5363 * option values.
5364 */
5365 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005366didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005367{
5368 /* initialize the table for 'iskeyword' et.al. */
5369 (void)init_chartab();
5370
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005371#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005375 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376#ifdef FEAT_SESSION
5377 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5378 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5379#endif
5380#ifdef FEAT_FOLDING
5381 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5382#endif
5383 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005384 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385#ifdef FEAT_VIRTUALEDIT
5386 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5387#endif
5388#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5389 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5390#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005391#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005392 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005393 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005394 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005395 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5398 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5399#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005400#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005401 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5402#endif
5403#ifdef FEAT_CMDWIN
5404 /* set cedit_key */
5405 (void)check_cedit();
5406#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005407#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005408 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005409#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005410#ifdef FEAT_LINEBREAK
5411 /* initialize the table for 'breakat'. */
5412 fill_breakat_flags();
5413#endif
5414
5415}
5416
5417/*
5418 * More side effects of setting options.
5419 */
5420 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005421didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005422{
5423 /* Initialize the highlight_attr[] table. */
5424 (void)highlight_changed();
5425
5426 /* Parse default for 'wildmode' */
5427 check_opt_wim();
5428
5429 (void)set_chars_option(&p_lcs);
5430#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5431 /* Parse default for 'fillchars'. */
5432 (void)set_chars_option(&p_fcs);
5433#endif
5434
5435#ifdef FEAT_CLIPBOARD
5436 /* Parse default for 'clipboard' */
5437 (void)check_clipboard_option();
5438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005439}
5440
5441/*
5442 * Check for string options that are NULL (normally only termcap options).
5443 */
5444 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005445check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446{
5447 int opt_idx;
5448
5449 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5450 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5451 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5452}
5453
5454/*
5455 * Check string options in a buffer for NULL value.
5456 */
5457 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005458check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459{
5460#if defined(FEAT_QUICKFIX)
5461 check_string_option(&buf->b_p_bh);
5462 check_string_option(&buf->b_p_bt);
5463#endif
5464#ifdef FEAT_MBYTE
5465 check_string_option(&buf->b_p_fenc);
5466#endif
5467 check_string_option(&buf->b_p_ff);
5468#ifdef FEAT_FIND_ID
5469 check_string_option(&buf->b_p_def);
5470 check_string_option(&buf->b_p_inc);
5471# ifdef FEAT_EVAL
5472 check_string_option(&buf->b_p_inex);
5473# endif
5474#endif
5475#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5476 check_string_option(&buf->b_p_inde);
5477 check_string_option(&buf->b_p_indk);
5478#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005479#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5480 check_string_option(&buf->b_p_bexpr);
5481#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005482#if defined(FEAT_CRYPT)
5483 check_string_option(&buf->b_p_cm);
5484#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005485 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005486#if defined(FEAT_EVAL)
5487 check_string_option(&buf->b_p_fex);
5488#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005489#ifdef FEAT_CRYPT
5490 check_string_option(&buf->b_p_key);
5491#endif
5492 check_string_option(&buf->b_p_kp);
5493 check_string_option(&buf->b_p_mps);
5494 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005495 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496 check_string_option(&buf->b_p_isk);
5497#ifdef FEAT_COMMENTS
5498 check_string_option(&buf->b_p_com);
5499#endif
5500#ifdef FEAT_FOLDING
5501 check_string_option(&buf->b_p_cms);
5502#endif
5503 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005504#ifdef FEAT_TEXTOBJ
5505 check_string_option(&buf->b_p_qe);
5506#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005507#ifdef FEAT_SYN_HL
5508 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005509 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005510#endif
5511#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005512 check_string_option(&buf->b_s.b_p_spc);
5513 check_string_option(&buf->b_s.b_p_spf);
5514 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005515#endif
5516#ifdef FEAT_SEARCHPATH
5517 check_string_option(&buf->b_p_sua);
5518#endif
5519#ifdef FEAT_CINDENT
5520 check_string_option(&buf->b_p_cink);
5521 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005522 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005523#endif
5524#ifdef FEAT_AUTOCMD
5525 check_string_option(&buf->b_p_ft);
5526#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005527#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5528 check_string_option(&buf->b_p_cinw);
5529#endif
5530#ifdef FEAT_INS_EXPAND
5531 check_string_option(&buf->b_p_cpt);
5532#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005533#ifdef FEAT_COMPL_FUNC
5534 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005535 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005536#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537#ifdef FEAT_KEYMAP
5538 check_string_option(&buf->b_p_keymap);
5539#endif
5540#ifdef FEAT_QUICKFIX
5541 check_string_option(&buf->b_p_gp);
5542 check_string_option(&buf->b_p_mp);
5543 check_string_option(&buf->b_p_efm);
5544#endif
5545 check_string_option(&buf->b_p_ep);
5546 check_string_option(&buf->b_p_path);
5547 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005548 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549#ifdef FEAT_INS_EXPAND
5550 check_string_option(&buf->b_p_dict);
5551 check_string_option(&buf->b_p_tsr);
5552#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005553#ifdef FEAT_LISP
5554 check_string_option(&buf->b_p_lw);
5555#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005556 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005557}
5558
5559/*
5560 * Free the string allocated for an option.
5561 * Checks for the string being empty_option. This may happen if we're out of
5562 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5563 * check_options().
5564 * Does NOT check for P_ALLOCED flag!
5565 */
5566 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005567free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005568{
5569 if (p != empty_option)
5570 vim_free(p);
5571}
5572
5573 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005574clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575{
5576 if (*pp != empty_option)
5577 vim_free(*pp);
5578 *pp = empty_option;
5579}
5580
5581 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005582check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583{
5584 if (*pp == NULL)
5585 *pp = empty_option;
5586}
5587
5588/*
5589 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5590 */
5591 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005592set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005593{
5594 int opt_idx;
5595
5596 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5597 if (options[opt_idx].var == (char_u *)p)
5598 {
5599 options[opt_idx].flags |= P_ALLOCED;
5600 return;
5601 }
5602 return; /* cannot happen: didn't find it! */
5603}
5604
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005605#if defined(FEAT_EVAL) || defined(PROTO)
5606/*
5607 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5608 * Return FALSE when it wasn't.
5609 * Return -1 for an unknown option.
5610 */
5611 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005612was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005613{
5614 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005615 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005616
5617 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005618 {
5619 flagp = insecure_flag(idx, opt_flags);
5620 return (*flagp & P_INSECURE) != 0;
5621 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005622 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005623 return -1;
5624}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005625
5626/*
5627 * Get a pointer to the flags used for the P_INSECURE flag of option
5628 * "opt_idx". For some local options a local flags field is used.
5629 */
5630 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005631insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005632{
5633 if (opt_flags & OPT_LOCAL)
5634 switch ((int)options[opt_idx].indir)
5635 {
5636#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005637 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005638#endif
5639#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005640# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005641 case PV_FDE: return &curwin->w_p_fde_flags;
5642 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005643# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005644# ifdef FEAT_BEVAL
5645 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5646# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005647# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005648 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005649# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005650 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005651# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005652 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005653# endif
5654#endif
5655 }
5656
5657 /* Nothing special, return global flags field. */
5658 return &options[opt_idx].flags;
5659}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005660#endif
5661
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005662#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005663static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005664
5665/*
5666 * Redraw the window title and/or tab page text later.
5667 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005668static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005669{
5670 need_maketitle = TRUE;
5671# ifdef FEAT_WINDOWS
5672 redraw_tabline = TRUE;
5673# endif
5674}
5675#endif
5676
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677/*
5678 * Set a string option to a new value (without checking the effect).
5679 * The string is copied into allocated memory.
5680 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005681 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005682 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005683 */
5684 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005685set_string_option_direct(
5686 char_u *name,
5687 int opt_idx,
5688 char_u *val,
5689 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5690 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691{
5692 char_u *s;
5693 char_u **varp;
5694 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005695 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696
Bram Moolenaar89d40322006-08-29 15:30:07 +00005697 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005699 idx = findoption(name);
5700 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005701 {
5702 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005703 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005705 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706 }
5707
Bram Moolenaar89d40322006-08-29 15:30:07 +00005708 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005709 return;
5710
5711 s = vim_strsave(val);
5712 if (s != NULL)
5713 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005714 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005716 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717 free_string_option(*varp);
5718 *varp = s;
5719
5720 /* For buffer/window local option may also set the global value. */
5721 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005722 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005723
Bram Moolenaar89d40322006-08-29 15:30:07 +00005724 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725
5726 /* When setting both values of a global option with a local value,
5727 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005728 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729 {
5730 free_string_option(*varp);
5731 *varp = empty_option;
5732 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005733# ifdef FEAT_EVAL
5734 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005735 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005736 set_sid == 0 ? current_SID : set_sid);
5737# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005738 }
5739}
5740
5741/*
5742 * Set global value for string option when it's a local option.
5743 */
5744 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005745set_string_option_global(
5746 int opt_idx, /* option index */
5747 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005748{
5749 char_u **p, *s;
5750
5751 /* the global value is always allocated */
5752 if (options[opt_idx].var == VAR_WIN)
5753 p = (char_u **)GLOBAL_WO(varp);
5754 else
5755 p = (char_u **)options[opt_idx].var;
5756 if (options[opt_idx].indir != PV_NONE
5757 && p != varp
5758 && (s = vim_strsave(*varp)) != NULL)
5759 {
5760 free_string_option(*p);
5761 *p = s;
5762 }
5763}
5764
5765/*
5766 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005767 *
5768 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005770 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005771set_string_option(
5772 int opt_idx,
5773 char_u *value,
5774 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005775{
5776 char_u *s;
5777 char_u **varp;
5778 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005779#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5780 char_u *saved_oldval = NULL;
5781#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005782 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783
5784 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005785 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005786
5787 s = vim_strsave(value);
5788 if (s != NULL)
5789 {
5790 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5791 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005792 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005793 ? OPT_GLOBAL : OPT_LOCAL)
5794 : opt_flags);
5795 oldval = *varp;
5796 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005797
5798#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005799 if (!starting
5800# ifdef FEAT_CRYPT
5801 && options[opt_idx].indir != PV_KEY
5802# endif
5803 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005804 saved_oldval = vim_strsave(oldval);
5805#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005806 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5807 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005808 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005809
5810 /* call autocomamnd after handling side effects */
5811#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5812 if (saved_oldval != NULL)
5813 {
5814 char_u buf_type[7];
5815 sprintf((char *)buf_type, "%s",
5816 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005817 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5818 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005819 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5820 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5821 reset_v_option_vars();
5822 vim_free(saved_oldval);
5823 }
5824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005825 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005826 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005827}
5828
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005829#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005830/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005831 * Return TRUE if "val" is a valid 'filetype' name.
5832 * Also used for 'syntax' and 'keymap'.
5833 */
5834 static int
5835valid_filetype(char_u *val)
5836{
5837 char_u *s;
5838
5839 for (s = val; *s != NUL; ++s)
5840 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5841 return FALSE;
5842 return TRUE;
5843}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005844#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005845
5846/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 * Handle string options that need some action to perform when changed.
5848 * Returns NULL for success, or an error message for an error.
5849 */
5850 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005851did_set_string_option(
5852 int opt_idx, /* index in options[] table */
5853 char_u **varp, /* pointer to the option variable */
5854 int new_value_alloced, /* new value was allocated */
5855 char_u *oldval, /* previous value of the option */
5856 char_u *errbuf, /* buffer for errors, or NULL */
5857 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858{
5859 char_u *errmsg = NULL;
5860 char_u *s, *p;
5861 int did_chartab = FALSE;
5862 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005863 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005864#ifdef FEAT_GUI
5865 /* set when changing an option that only requires a redraw in the GUI */
5866 int redraw_gui_only = FALSE;
5867#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868
5869 /* Get the global option to compare with, otherwise we would have to check
5870 * two values for all local options. */
5871 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5872
5873 /* Disallow changing some options from secure mode */
5874 if ((secure
5875#ifdef HAVE_SANDBOX
5876 || sandbox != 0
5877#endif
5878 ) && (options[opt_idx].flags & P_SECURE))
5879 {
5880 errmsg = e_secure;
5881 }
5882
Bram Moolenaar7554da42016-11-25 22:04:13 +01005883 /* Check for a "normal" directory or file name in some options. Disallow a
5884 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005885 * are often illegal in a file name. Be more permissive if "secure" is off.
5886 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01005887 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005888 && vim_strpbrk(*varp, (char_u *)(secure
5889 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01005890 || ((options[opt_idx].flags & P_NDNAME)
5891 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005892 {
5893 errmsg = e_invarg;
5894 }
5895
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 /* 'term' */
5897 else if (varp == &T_NAME)
5898 {
5899 if (T_NAME[0] == NUL)
5900 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5901#ifdef FEAT_GUI
5902 if (gui.in_use)
5903 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5904 else if (term_is_gui(T_NAME))
5905 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5906#endif
5907 else if (set_termname(T_NAME) == FAIL)
5908 errmsg = (char_u *)N_("E522: Not found in termcap");
5909 else
5910 /* Screen colors may have changed. */
5911 redraw_later_clear();
5912 }
5913
5914 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005915 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005917 char_u *bkc = p_bkc;
5918 unsigned int *flags = &bkc_flags;
5919
5920 if (opt_flags & OPT_LOCAL)
5921 {
5922 bkc = curbuf->b_p_bkc;
5923 flags = &curbuf->b_bkc_flags;
5924 }
5925
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005926 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5927 /* make the local value empty: use the global value */
5928 *flags = 0;
5929 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005930 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005931 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5932 errmsg = e_invarg;
5933 if ((((int)*flags & BKC_AUTO) != 0)
5934 + (((int)*flags & BKC_YES) != 0)
5935 + (((int)*flags & BKC_NO) != 0) != 1)
5936 {
5937 /* Must have exactly one of "auto", "yes" and "no". */
5938 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5939 errmsg = e_invarg;
5940 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941 }
5942 }
5943
5944 /* 'backupext' and 'patchmode' */
5945 else if (varp == &p_bex || varp == &p_pm)
5946 {
5947 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5948 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5949 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5950 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005951#ifdef FEAT_LINEBREAK
5952 /* 'breakindentopt' */
5953 else if (varp == &curwin->w_p_briopt)
5954 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005955 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005956 errmsg = e_invarg;
5957 }
5958#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959
5960 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005961 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005962 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005963 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964 */
5965 else if ( varp == &p_isi
5966 || varp == &(curbuf->b_p_isk)
5967 || varp == &p_isp
5968 || varp == &p_isf)
5969 {
5970 if (init_chartab() == FAIL)
5971 {
5972 did_chartab = TRUE; /* need to restore it below */
5973 errmsg = e_invarg; /* error in value */
5974 }
5975 }
5976
5977 /* 'helpfile' */
5978 else if (varp == &p_hf)
5979 {
5980 /* May compute new values for $VIM and $VIMRUNTIME */
5981 if (didset_vim)
5982 {
5983 vim_setenv((char_u *)"VIM", (char_u *)"");
5984 didset_vim = FALSE;
5985 }
5986 if (didset_vimruntime)
5987 {
5988 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5989 didset_vimruntime = FALSE;
5990 }
5991 }
5992
Bram Moolenaar1a384422010-07-14 19:53:30 +02005993#ifdef FEAT_SYN_HL
5994 /* 'colorcolumn' */
5995 else if (varp == &curwin->w_p_cc)
5996 errmsg = check_colorcolumn(curwin);
5997#endif
5998
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999#ifdef FEAT_MULTI_LANG
6000 /* 'helplang' */
6001 else if (varp == &p_hlg)
6002 {
6003 /* Check for "", "ab", "ab,cd", etc. */
6004 for (s = p_hlg; *s != NUL; s += 3)
6005 {
6006 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6007 {
6008 errmsg = e_invarg;
6009 break;
6010 }
6011 if (s[2] == NUL)
6012 break;
6013 }
6014 }
6015#endif
6016
6017 /* 'highlight' */
6018 else if (varp == &p_hl)
6019 {
6020 if (highlight_changed() == FAIL)
6021 errmsg = e_invarg; /* invalid flags */
6022 }
6023
6024 /* 'nrformats' */
6025 else if (gvarp == &p_nf)
6026 {
6027 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6028 errmsg = e_invarg;
6029 }
6030
6031#ifdef FEAT_SESSION
6032 /* 'sessionoptions' */
6033 else if (varp == &p_ssop)
6034 {
6035 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6036 errmsg = e_invarg;
6037 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6038 {
6039 /* Don't allow both "sesdir" and "curdir". */
6040 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6041 errmsg = e_invarg;
6042 }
6043 }
6044 /* 'viewoptions' */
6045 else if (varp == &p_vop)
6046 {
6047 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6048 errmsg = e_invarg;
6049 }
6050#endif
6051
6052 /* 'scrollopt' */
6053#ifdef FEAT_SCROLLBIND
6054 else if (varp == &p_sbo)
6055 {
6056 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6057 errmsg = e_invarg;
6058 }
6059#endif
6060
6061 /* 'ambiwidth' */
6062#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006063 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006064 {
6065 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6066 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006067 else if (set_chars_option(&p_lcs) != NULL)
6068 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6069# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6070 else if (set_chars_option(&p_fcs) != NULL)
6071 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6072# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006073 }
6074#endif
6075
6076 /* 'background' */
6077 else if (varp == &p_bg)
6078 {
6079 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6080 {
6081#ifdef FEAT_EVAL
6082 int dark = (*p_bg == 'd');
6083#endif
6084
6085 init_highlight(FALSE, FALSE);
6086
6087#ifdef FEAT_EVAL
6088 if (dark != (*p_bg == 'd')
6089 && get_var_value((char_u *)"g:colors_name") != NULL)
6090 {
6091 /* The color scheme must have set 'background' back to another
6092 * value, that's not what we want here. Disable the color
6093 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006094 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095 free_string_option(p_bg);
6096 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6097 check_string_option(&p_bg);
6098 init_highlight(FALSE, FALSE);
6099 }
6100#endif
6101 }
6102 else
6103 errmsg = e_invarg;
6104 }
6105
6106 /* 'wildmode' */
6107 else if (varp == &p_wim)
6108 {
6109 if (check_opt_wim() == FAIL)
6110 errmsg = e_invarg;
6111 }
6112
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006113#ifdef FEAT_CMDL_COMPL
6114 /* 'wildoptions' */
6115 else if (varp == &p_wop)
6116 {
6117 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6118 errmsg = e_invarg;
6119 }
6120#endif
6121
Bram Moolenaar071d4272004-06-13 20:20:40 +00006122#ifdef FEAT_WAK
6123 /* 'winaltkeys' */
6124 else if (varp == &p_wak)
6125 {
6126 if (*p_wak == NUL
6127 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6128 errmsg = e_invarg;
6129# ifdef FEAT_MENU
6130# ifdef FEAT_GUI_MOTIF
6131 else if (gui.in_use)
6132 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6133# else
6134# ifdef FEAT_GUI_GTK
6135 else if (gui.in_use)
6136 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6137# endif
6138# endif
6139# endif
6140 }
6141#endif
6142
6143#ifdef FEAT_AUTOCMD
6144 /* 'eventignore' */
6145 else if (varp == &p_ei)
6146 {
6147 if (check_ei() == FAIL)
6148 errmsg = e_invarg;
6149 }
6150#endif
6151
6152#ifdef FEAT_MBYTE
6153 /* 'encoding' and 'fileencoding' */
6154 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6155 {
6156 if (gvarp == &p_fenc)
6157 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006158 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006159 errmsg = e_modifiable;
6160 else if (vim_strchr(*varp, ',') != NULL)
6161 /* No comma allowed in 'fileencoding'; catches confusing it
6162 * with 'fileencodings'. */
6163 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006164 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006165 {
6166# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006167 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006168 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006169# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006170 /* Add 'fileencoding' to the swap file. */
6171 ml_setflags(curbuf);
6172 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006173 }
6174 if (errmsg == NULL)
6175 {
6176 /* canonize the value, so that STRCMP() can be used on it */
6177 p = enc_canonize(*varp);
6178 if (p != NULL)
6179 {
6180 vim_free(*varp);
6181 *varp = p;
6182 }
6183 if (varp == &p_enc)
6184 {
6185 errmsg = mb_init();
6186# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006187 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188# endif
6189 }
6190 }
6191
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006192# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006193 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6194 {
6195 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6196 if (STRCMP(p_tenc, "utf-8") != 0)
6197 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6198 }
6199# endif
6200
6201 if (errmsg == NULL)
6202 {
6203# ifdef FEAT_KEYMAP
6204 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6205 * (with another encoding). */
6206 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6207 (void)keymap_init();
6208# endif
6209
6210 /* When 'termencoding' is not empty and 'encoding' changes or when
6211 * 'termencoding' changes, need to setup for keyboard input and
6212 * display output conversion. */
6213 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6214 {
6215 convert_setup(&input_conv, p_tenc, p_enc);
6216 convert_setup(&output_conv, p_enc, p_tenc);
6217 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006218
6219# if defined(WIN3264) && defined(FEAT_MBYTE)
6220 /* $HOME may have characters in active code page. */
6221 if (varp == &p_enc)
6222 init_homedir();
6223# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006224 }
6225 }
6226#endif
6227
6228#if defined(FEAT_POSTSCRIPT)
6229 else if (varp == &p_penc)
6230 {
6231 /* Canonize printencoding if VIM standard one */
6232 p = enc_canonize(p_penc);
6233 if (p != NULL)
6234 {
6235 vim_free(p_penc);
6236 p_penc = p;
6237 }
6238 else
6239 {
6240 /* Ensure lower case and '-' for '_' */
6241 for (s = p_penc; *s != NUL; s++)
6242 {
6243 if (*s == '_')
6244 *s = '-';
6245 else
6246 *s = TOLOWER_ASC(*s);
6247 }
6248 }
6249 }
6250#endif
6251
Bram Moolenaar9372a112005-12-06 19:59:18 +00006252#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006253 else if (varp == &p_imak)
6254 {
6255 if (gui.in_use && !im_xim_isvalid_imactivate())
6256 errmsg = e_invarg;
6257 }
6258#endif
6259
6260#ifdef FEAT_KEYMAP
6261 else if (varp == &curbuf->b_p_keymap)
6262 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006263 if (!valid_filetype(*varp))
6264 errmsg = e_invarg;
6265 else
6266 /* load or unload key mapping tables */
6267 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006268
Bram Moolenaarfab06232009-03-04 03:13:35 +00006269 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006270 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006271 if (*curbuf->b_p_keymap != NUL)
6272 {
6273 /* Installed a new keymap, switch on using it. */
6274 curbuf->b_p_iminsert = B_IMODE_LMAP;
6275 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6276 curbuf->b_p_imsearch = B_IMODE_LMAP;
6277 }
6278 else
6279 {
6280 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6281 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6282 curbuf->b_p_iminsert = B_IMODE_NONE;
6283 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6284 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6285 }
6286 if ((opt_flags & OPT_LOCAL) == 0)
6287 {
6288 set_iminsert_global();
6289 set_imsearch_global();
6290 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006291# ifdef FEAT_WINDOWS
6292 status_redraw_curbuf();
6293# endif
6294 }
6295 }
6296#endif
6297
6298 /* 'fileformat' */
6299 else if (gvarp == &p_ff)
6300 {
6301 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6302 errmsg = e_modifiable;
6303 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6304 errmsg = e_invarg;
6305 else
6306 {
6307 /* may also change 'textmode' */
6308 if (get_fileformat(curbuf) == EOL_DOS)
6309 curbuf->b_p_tx = TRUE;
6310 else
6311 curbuf->b_p_tx = FALSE;
6312#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006313 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006314#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006315 /* update flag in swap file */
6316 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006317 /* Redraw needed when switching to/from "mac": a CR in the text
6318 * will be displayed differently. */
6319 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6320 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321 }
6322 }
6323
6324 /* 'fileformats' */
6325 else if (varp == &p_ffs)
6326 {
6327 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6328 errmsg = e_invarg;
6329 else
6330 {
6331 /* also change 'textauto' */
6332 if (*p_ffs == NUL)
6333 p_ta = FALSE;
6334 else
6335 p_ta = TRUE;
6336 }
6337 }
6338
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006339#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006340 /* 'cryptkey' */
6341 else if (gvarp == &p_key)
6342 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006343# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006344 /* Make sure the ":set" command doesn't show the new value in the
6345 * history. */
6346 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006347# endif
6348 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6349 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006350 ml_set_crypt_key(curbuf, oldval,
6351 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006352 }
6353
6354 else if (gvarp == &p_cm)
6355 {
6356 if (opt_flags & OPT_LOCAL)
6357 p = curbuf->b_p_cm;
6358 else
6359 p = p_cm;
6360 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6361 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006362 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006363 errmsg = e_invarg;
6364 else
6365 {
6366 /* When setting the global value to empty, make it "zip". */
6367 if (*p_cm == NUL)
6368 {
6369 if (new_value_alloced)
6370 free_string_option(p_cm);
6371 p_cm = vim_strsave((char_u *)"zip");
6372 new_value_alloced = TRUE;
6373 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006374 /* When using ":set cm=name" the local value is going to be empty.
6375 * Do that here, otherwise the crypt functions will still use the
6376 * local value. */
6377 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6378 {
6379 free_string_option(curbuf->b_p_cm);
6380 curbuf->b_p_cm = empty_option;
6381 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006382
6383 /* Need to update the swapfile when the effective method changed.
6384 * Set "s" to the effective old value, "p" to the effective new
6385 * method and compare. */
6386 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6387 s = p_cm; /* was previously using the global value */
6388 else
6389 s = oldval;
6390 if (*curbuf->b_p_cm == NUL)
6391 p = p_cm; /* is now using the global value */
6392 else
6393 p = curbuf->b_p_cm;
6394 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006395 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006396
6397 /* If the global value changes need to update the swapfile for all
6398 * buffers using that value. */
6399 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6400 {
6401 buf_T *buf;
6402
Bram Moolenaar29323592016-07-24 22:04:11 +02006403 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006404 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006405 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006406 }
6407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 }
6409#endif
6410
6411 /* 'matchpairs' */
6412 else if (gvarp == &p_mps)
6413 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006414#ifdef FEAT_MBYTE
6415 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006416 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006417 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006419 int x2 = -1;
6420 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006421
6422 if (*p != NUL)
6423 p += mb_ptr2len(p);
6424 if (*p != NUL)
6425 x2 = *p++;
6426 if (*p != NUL)
6427 {
6428 x3 = mb_ptr2char(p);
6429 p += mb_ptr2len(p);
6430 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006431 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006432 {
6433 errmsg = e_invarg;
6434 break;
6435 }
6436 if (*p == NUL)
6437 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006438 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006439 }
6440 else
6441#endif
6442 {
6443 /* Check for "x:y,x:y" */
6444 for (p = *varp; *p != NUL; p += 4)
6445 {
6446 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6447 {
6448 errmsg = e_invarg;
6449 break;
6450 }
6451 if (p[3] == NUL)
6452 break;
6453 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 }
6455 }
6456
6457#ifdef FEAT_COMMENTS
6458 /* 'comments' */
6459 else if (gvarp == &p_com)
6460 {
6461 for (s = *varp; *s; )
6462 {
6463 while (*s && *s != ':')
6464 {
6465 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6466 && !VIM_ISDIGIT(*s) && *s != '-')
6467 {
6468 errmsg = illegal_char(errbuf, *s);
6469 break;
6470 }
6471 ++s;
6472 }
6473 if (*s++ == NUL)
6474 errmsg = (char_u *)N_("E524: Missing colon");
6475 else if (*s == ',' || *s == NUL)
6476 errmsg = (char_u *)N_("E525: Zero length string");
6477 if (errmsg != NULL)
6478 break;
6479 while (*s && *s != ',')
6480 {
6481 if (*s == '\\' && s[1] != NUL)
6482 ++s;
6483 ++s;
6484 }
6485 s = skip_to_option_part(s);
6486 }
6487 }
6488#endif
6489
6490 /* 'listchars' */
6491 else if (varp == &p_lcs)
6492 {
6493 errmsg = set_chars_option(varp);
6494 }
6495
6496#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6497 /* 'fillchars' */
6498 else if (varp == &p_fcs)
6499 {
6500 errmsg = set_chars_option(varp);
6501 }
6502#endif
6503
6504#ifdef FEAT_CMDWIN
6505 /* 'cedit' */
6506 else if (varp == &p_cedit)
6507 {
6508 errmsg = check_cedit();
6509 }
6510#endif
6511
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006512 /* 'verbosefile' */
6513 else if (varp == &p_vfile)
6514 {
6515 verbose_stop();
6516 if (*p_vfile != NUL && verbose_open() == FAIL)
6517 errmsg = e_invarg;
6518 }
6519
Bram Moolenaar071d4272004-06-13 20:20:40 +00006520#ifdef FEAT_VIMINFO
6521 /* 'viminfo' */
6522 else if (varp == &p_viminfo)
6523 {
6524 for (s = p_viminfo; *s;)
6525 {
6526 /* Check it's a valid character */
6527 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6528 {
6529 errmsg = illegal_char(errbuf, *s);
6530 break;
6531 }
6532 if (*s == 'n') /* name is always last one */
6533 {
6534 break;
6535 }
6536 else if (*s == 'r') /* skip until next ',' */
6537 {
6538 while (*++s && *s != ',')
6539 ;
6540 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006541 else if (*s == '%')
6542 {
6543 /* optional number */
6544 while (vim_isdigit(*++s))
6545 ;
6546 }
6547 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 ++s; /* no extra chars */
6549 else /* must have a number */
6550 {
6551 while (vim_isdigit(*++s))
6552 ;
6553
6554 if (!VIM_ISDIGIT(*(s - 1)))
6555 {
6556 if (errbuf != NULL)
6557 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006558 sprintf((char *)errbuf,
6559 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006560 transchar_byte(*(s - 1)));
6561 errmsg = errbuf;
6562 }
6563 else
6564 errmsg = (char_u *)"";
6565 break;
6566 }
6567 }
6568 if (*s == ',')
6569 ++s;
6570 else if (*s)
6571 {
6572 if (errbuf != NULL)
6573 errmsg = (char_u *)N_("E527: Missing comma");
6574 else
6575 errmsg = (char_u *)"";
6576 break;
6577 }
6578 }
6579 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6580 errmsg = (char_u *)N_("E528: Must specify a ' value");
6581 }
6582#endif /* FEAT_VIMINFO */
6583
6584 /* terminal options */
6585 else if (istermoption(&options[opt_idx]) && full_screen)
6586 {
6587 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6588 if (varp == &T_CCO)
6589 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006590 int colors = atoi((char *)T_CCO);
6591
6592 /* Only reinitialize colors if t_Co value has really changed to
6593 * avoid expensive reload of colorscheme if t_Co is set to the
6594 * same value multiple times. */
6595 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006596 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006597 t_colors = colors;
6598 if (t_colors <= 1)
6599 {
6600 if (new_value_alloced)
6601 vim_free(T_CCO);
6602 T_CCO = empty_option;
6603 }
6604 /* We now have a different color setup, initialize it again. */
6605 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006606 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006607 }
6608 ttest(FALSE);
6609 if (varp == &T_ME)
6610 {
6611 out_str(T_ME);
6612 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006613#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006614 /* Since t_me has been set, this probably means that the user
6615 * wants to use this as default colors. Need to reset default
6616 * background/foreground colors. */
6617 mch_set_normal_colors();
6618#endif
6619 }
6620 }
6621
6622#ifdef FEAT_LINEBREAK
6623 /* 'showbreak' */
6624 else if (varp == &p_sbr)
6625 {
6626 for (s = p_sbr; *s; )
6627 {
6628 if (ptr2cells(s) != 1)
6629 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006630 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631 }
6632 }
6633#endif
6634
6635#ifdef FEAT_GUI
6636 /* 'guifont' */
6637 else if (varp == &p_guifont)
6638 {
6639 if (gui.in_use)
6640 {
6641 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006642# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006643 /*
6644 * Put up a font dialog and let the user select a new value.
6645 * If this is cancelled go back to the old value but don't
6646 * give an error message.
6647 */
6648 if (STRCMP(p, "*") == 0)
6649 {
6650 p = gui_mch_font_dialog(oldval);
6651
6652 if (new_value_alloced)
6653 free_string_option(p_guifont);
6654
6655 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6656 new_value_alloced = TRUE;
6657 }
6658# endif
6659 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6660 {
6661# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6662 if (STRCMP(p_guifont, "*") == 0)
6663 {
6664 /* Dialog was cancelled: Keep the old value without giving
6665 * an error message. */
6666 if (new_value_alloced)
6667 free_string_option(p_guifont);
6668 p_guifont = vim_strsave(oldval);
6669 new_value_alloced = TRUE;
6670 }
6671 else
6672# endif
6673 errmsg = (char_u *)N_("E596: Invalid font(s)");
6674 }
6675 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006676 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006677 }
6678# ifdef FEAT_XFONTSET
6679 else if (varp == &p_guifontset)
6680 {
6681 if (STRCMP(p_guifontset, "*") == 0)
6682 errmsg = (char_u *)N_("E597: can't select fontset");
6683 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6684 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006685 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006686 }
6687# endif
6688# ifdef FEAT_MBYTE
6689 else if (varp == &p_guifontwide)
6690 {
6691 if (STRCMP(p_guifontwide, "*") == 0)
6692 errmsg = (char_u *)N_("E533: can't select wide font");
6693 else if (gui_get_wide_font() == FAIL)
6694 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006695 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006696 }
6697# endif
6698#endif
6699
6700#ifdef CURSOR_SHAPE
6701 /* 'guicursor' */
6702 else if (varp == &p_guicursor)
6703 errmsg = parse_shape_opt(SHAPE_CURSOR);
6704#endif
6705
6706#ifdef FEAT_MOUSESHAPE
6707 /* 'mouseshape' */
6708 else if (varp == &p_mouseshape)
6709 {
6710 errmsg = parse_shape_opt(SHAPE_MOUSE);
6711 update_mouseshape(-1);
6712 }
6713#endif
6714
6715#ifdef FEAT_PRINTER
6716 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006717 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006718# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006719 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006720 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006721# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006722#endif
6723
6724#ifdef FEAT_LANGMAP
6725 /* 'langmap' */
6726 else if (varp == &p_langmap)
6727 langmap_set();
6728#endif
6729
6730#ifdef FEAT_LINEBREAK
6731 /* 'breakat' */
6732 else if (varp == &p_breakat)
6733 fill_breakat_flags();
6734#endif
6735
6736#ifdef FEAT_TITLE
6737 /* 'titlestring' and 'iconstring' */
6738 else if (varp == &p_titlestring || varp == &p_iconstring)
6739 {
6740# ifdef FEAT_STL_OPT
6741 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6742
6743 /* NULL => statusline syntax */
6744 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6745 stl_syntax |= flagval;
6746 else
6747 stl_syntax &= ~flagval;
6748# endif
6749 did_set_title(varp == &p_iconstring);
6750
6751 }
6752#endif
6753
6754#ifdef FEAT_GUI
6755 /* 'guioptions' */
6756 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006757 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006758 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006759 redraw_gui_only = TRUE;
6760 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006761#endif
6762
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006763#if defined(FEAT_GUI_TABLINE)
6764 /* 'guitablabel' */
6765 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006766 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006767 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006768 redraw_gui_only = TRUE;
6769 }
6770 /* 'guitabtooltip' */
6771 else if (varp == &p_gtt)
6772 {
6773 redraw_gui_only = TRUE;
6774 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006775#endif
6776
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6778 /* 'ttymouse' */
6779 else if (varp == &p_ttym)
6780 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006781 /* Switch the mouse off before changing the escape sequences used for
6782 * that. */
6783 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006784 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6785 errmsg = e_invarg;
6786 else
6787 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006788 if (termcap_active)
6789 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 }
6791#endif
6792
Bram Moolenaar071d4272004-06-13 20:20:40 +00006793 /* 'selection' */
6794 else if (varp == &p_sel)
6795 {
6796 if (*p_sel == NUL
6797 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6798 errmsg = e_invarg;
6799 }
6800
6801 /* 'selectmode' */
6802 else if (varp == &p_slm)
6803 {
6804 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6805 errmsg = e_invarg;
6806 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006807
6808#ifdef FEAT_BROWSE
6809 /* 'browsedir' */
6810 else if (varp == &p_bsdir)
6811 {
6812 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6813 && !mch_isdir(p_bsdir))
6814 errmsg = e_invarg;
6815 }
6816#endif
6817
Bram Moolenaar071d4272004-06-13 20:20:40 +00006818 /* 'keymodel' */
6819 else if (varp == &p_km)
6820 {
6821 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6822 errmsg = e_invarg;
6823 else
6824 {
6825 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6826 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6827 }
6828 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829
6830 /* 'mousemodel' */
6831 else if (varp == &p_mousem)
6832 {
6833 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6834 errmsg = e_invarg;
6835#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6836 else if (*p_mousem != *oldval)
6837 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6838 * to create or delete the popup menus. */
6839 gui_motif_update_mousemodel(root_menu);
6840#endif
6841 }
6842
6843 /* 'switchbuf' */
6844 else if (varp == &p_swb)
6845 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006846 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847 errmsg = e_invarg;
6848 }
6849
6850 /* 'debug' */
6851 else if (varp == &p_debug)
6852 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006853 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006854 errmsg = e_invarg;
6855 }
6856
6857 /* 'display' */
6858 else if (varp == &p_dy)
6859 {
6860 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6861 errmsg = e_invarg;
6862 else
6863 (void)init_chartab();
6864
6865 }
6866
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006867#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006868 /* 'eadirection' */
6869 else if (varp == &p_ead)
6870 {
6871 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6872 errmsg = e_invarg;
6873 }
6874#endif
6875
6876#ifdef FEAT_CLIPBOARD
6877 /* 'clipboard' */
6878 else if (varp == &p_cb)
6879 errmsg = check_clipboard_option();
6880#endif
6881
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006882#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006883 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6884 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006885 else if (varp == &(curwin->w_s->b_p_spl)
6886 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006887 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006888 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006889 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006890 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006891 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006892 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006893 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006894 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006895 /* 'spellsuggest' */
6896 else if (varp == &p_sps)
6897 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006898 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006899 errmsg = e_invarg;
6900 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006901 /* 'mkspellmem' */
6902 else if (varp == &p_msm)
6903 {
6904 if (spell_check_msm() != OK)
6905 errmsg = e_invarg;
6906 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006907#endif
6908
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909#ifdef FEAT_QUICKFIX
6910 /* When 'bufhidden' is set, check for valid value. */
6911 else if (gvarp == &p_bh)
6912 {
6913 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6914 errmsg = e_invarg;
6915 }
6916
6917 /* When 'buftype' is set, check for valid value. */
6918 else if (gvarp == &p_bt)
6919 {
6920 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6921 errmsg = e_invarg;
6922 else
6923 {
6924# ifdef FEAT_WINDOWS
6925 if (curwin->w_status_height)
6926 {
6927 curwin->w_redr_status = TRUE;
6928 redraw_later(VALID);
6929 }
6930# endif
6931 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006932# ifdef FEAT_TITLE
6933 redraw_titles();
6934# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006935 }
6936 }
6937#endif
6938
6939#ifdef FEAT_STL_OPT
6940 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006941 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006942 {
6943 int wid;
6944
6945 if (varp == &p_ruf) /* reset ru_wid first */
6946 ru_wid = 0;
6947 s = *varp;
6948 if (varp == &p_ruf && *s == '%')
6949 {
6950 /* set ru_wid if 'ruf' starts with "%99(" */
6951 if (*++s == '-') /* ignore a '-' */
6952 s++;
6953 wid = getdigits(&s);
6954 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6955 ru_wid = wid;
6956 else
6957 errmsg = check_stl_option(p_ruf);
6958 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006959 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006960 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006962 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006963 comp_col();
6964 }
6965#endif
6966
6967#ifdef FEAT_INS_EXPAND
6968 /* check if it is a valid value for 'complete' -- Acevedo */
6969 else if (gvarp == &p_cpt)
6970 {
6971 for (s = *varp; *s;)
6972 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006973 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006974 s++;
6975 if (!*s)
6976 break;
6977 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6978 {
6979 errmsg = illegal_char(errbuf, *s);
6980 break;
6981 }
6982 if (*++s != NUL && *s != ',' && *s != ' ')
6983 {
6984 if (s[-1] == 'k' || s[-1] == 's')
6985 {
6986 /* skip optional filename after 'k' and 's' */
6987 while (*s && *s != ',' && *s != ' ')
6988 {
6989 if (*s == '\\')
6990 ++s;
6991 ++s;
6992 }
6993 }
6994 else
6995 {
6996 if (errbuf != NULL)
6997 {
6998 sprintf((char *)errbuf,
6999 _("E535: Illegal character after <%c>"),
7000 *--s);
7001 errmsg = errbuf;
7002 }
7003 else
7004 errmsg = (char_u *)"";
7005 break;
7006 }
7007 }
7008 }
7009 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007010
7011 /* 'completeopt' */
7012 else if (varp == &p_cot)
7013 {
7014 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7015 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007016 else
7017 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007018 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007019#endif /* FEAT_INS_EXPAND */
7020
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007021#ifdef FEAT_SIGNS
7022 /* 'signcolumn' */
7023 else if (varp == &curwin->w_p_scl)
7024 {
7025 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7026 errmsg = e_invarg;
7027 }
7028#endif
7029
Bram Moolenaar071d4272004-06-13 20:20:40 +00007030
7031#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007032 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007033 else if (varp == &p_toolbar)
7034 {
7035 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7036 &toolbar_flags, TRUE) != OK)
7037 errmsg = e_invarg;
7038 else
7039 {
7040 out_flush();
7041 gui_mch_show_toolbar((toolbar_flags &
7042 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7043 }
7044 }
7045#endif
7046
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007047#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048 /* 'toolbariconsize': GTK+ 2 only */
7049 else if (varp == &p_tbis)
7050 {
7051 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7052 errmsg = e_invarg;
7053 else
7054 {
7055 out_flush();
7056 gui_mch_show_toolbar((toolbar_flags &
7057 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7058 }
7059 }
7060#endif
7061
7062 /* 'pastetoggle': translate key codes like in a mapping */
7063 else if (varp == &p_pt)
7064 {
7065 if (*p_pt)
7066 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007067 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068 if (p != NULL)
7069 {
7070 if (new_value_alloced)
7071 free_string_option(p_pt);
7072 p_pt = p;
7073 new_value_alloced = TRUE;
7074 }
7075 }
7076 }
7077
7078 /* 'backspace' */
7079 else if (varp == &p_bs)
7080 {
7081 if (VIM_ISDIGIT(*p_bs))
7082 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007083 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007084 errmsg = e_invarg;
7085 }
7086 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7087 errmsg = e_invarg;
7088 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007089 else if (varp == &p_bo)
7090 {
7091 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7092 errmsg = e_invarg;
7093 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007094
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007095 /* 'tagcase' */
7096 else if (gvarp == &p_tc)
7097 {
7098 unsigned int *flags;
7099
7100 if (opt_flags & OPT_LOCAL)
7101 {
7102 p = curbuf->b_p_tc;
7103 flags = &curbuf->b_tc_flags;
7104 }
7105 else
7106 {
7107 p = p_tc;
7108 flags = &tc_flags;
7109 }
7110
7111 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7112 /* make the local value empty: use the global value */
7113 *flags = 0;
7114 else if (*p == NUL
7115 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7116 errmsg = e_invarg;
7117 }
7118
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007119#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 /* 'casemap' */
7121 else if (varp == &p_cmp)
7122 {
7123 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7124 errmsg = e_invarg;
7125 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127
7128#ifdef FEAT_DIFF
7129 /* 'diffopt' */
7130 else if (varp == &p_dip)
7131 {
7132 if (diffopt_changed() == FAIL)
7133 errmsg = e_invarg;
7134 }
7135#endif
7136
7137#ifdef FEAT_FOLDING
7138 /* 'foldmethod' */
7139 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7140 {
7141 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7142 || *curwin->w_p_fdm == NUL)
7143 errmsg = e_invarg;
7144 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007145 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007146 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007147 if (foldmethodIsDiff(curwin))
7148 newFoldLevel();
7149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007150 }
7151# ifdef FEAT_EVAL
7152 /* 'foldexpr' */
7153 else if (varp == &curwin->w_p_fde)
7154 {
7155 if (foldmethodIsExpr(curwin))
7156 foldUpdateAll(curwin);
7157 }
7158# endif
7159 /* 'foldmarker' */
7160 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7161 {
7162 p = vim_strchr(*varp, ',');
7163 if (p == NULL)
7164 errmsg = (char_u *)N_("E536: comma required");
7165 else if (p == *varp || p[1] == NUL)
7166 errmsg = e_invarg;
7167 else if (foldmethodIsMarker(curwin))
7168 foldUpdateAll(curwin);
7169 }
7170 /* 'commentstring' */
7171 else if (gvarp == &p_cms)
7172 {
7173 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7174 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7175 }
7176 /* 'foldopen' */
7177 else if (varp == &p_fdo)
7178 {
7179 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7180 errmsg = e_invarg;
7181 }
7182 /* 'foldclose' */
7183 else if (varp == &p_fcl)
7184 {
7185 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7186 errmsg = e_invarg;
7187 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007188 /* 'foldignore' */
7189 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7190 {
7191 if (foldmethodIsIndent(curwin))
7192 foldUpdateAll(curwin);
7193 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007194#endif
7195
7196#ifdef FEAT_VIRTUALEDIT
7197 /* 'virtualedit' */
7198 else if (varp == &p_ve)
7199 {
7200 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7201 errmsg = e_invarg;
7202 else if (STRCMP(p_ve, oldval) != 0)
7203 {
7204 /* Recompute cursor position in case the new 've' setting
7205 * changes something. */
7206 validate_virtcol();
7207 coladvance(curwin->w_virtcol);
7208 }
7209 }
7210#endif
7211
7212#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7213 else if (varp == &p_csqf)
7214 {
7215 if (p_csqf != NULL)
7216 {
7217 p = p_csqf;
7218 while (*p != NUL)
7219 {
7220 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7221 || p[1] == NUL
7222 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7223 || (p[2] != NUL && p[2] != ','))
7224 {
7225 errmsg = e_invarg;
7226 break;
7227 }
7228 else if (p[2] == NUL)
7229 break;
7230 else
7231 p += 3;
7232 }
7233 }
7234 }
7235#endif
7236
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007237#ifdef FEAT_CINDENT
7238 /* 'cinoptions' */
7239 else if (gvarp == &p_cino)
7240 {
7241 /* TODO: recognize errors */
7242 parse_cino(curbuf);
7243 }
7244#endif
7245
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007246#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007247 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007248 else if (varp == &p_rop && gui.in_use)
7249 {
7250 if (!gui_mch_set_rendering_options(p_rop))
7251 errmsg = e_invarg;
7252 }
7253#endif
7254
Bram Moolenaard0b51382016-11-04 15:23:45 +01007255#ifdef FEAT_AUTOCMD
7256 else if (gvarp == &p_ft)
7257 {
7258 if (!valid_filetype(*varp))
7259 errmsg = e_invarg;
7260 }
7261#endif
7262
7263#ifdef FEAT_SYN_HL
7264 else if (gvarp == &p_syn)
7265 {
7266 if (!valid_filetype(*varp))
7267 errmsg = e_invarg;
7268 }
7269#endif
7270
Bram Moolenaar071d4272004-06-13 20:20:40 +00007271 /* Options that are a list of flags. */
7272 else
7273 {
7274 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007275 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007276 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007277 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007278 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007279 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007281 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007283#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007284 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007285 p = (char_u *)COCU_ALL;
7286#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007287 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007288 {
7289#ifdef FEAT_MOUSE
7290 p = (char_u *)MOUSE_ALL;
7291#else
7292 if (*p_mouse != NUL)
7293 errmsg = (char_u *)N_("E538: No mouse support");
7294#endif
7295 }
7296#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007297 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007298 p = (char_u *)GO_ALL;
7299#endif
7300 if (p != NULL)
7301 {
7302 for (s = *varp; *s; ++s)
7303 if (vim_strchr(p, *s) == NULL)
7304 {
7305 errmsg = illegal_char(errbuf, *s);
7306 break;
7307 }
7308 }
7309 }
7310
7311 /*
7312 * If error detected, restore the previous value.
7313 */
7314 if (errmsg != NULL)
7315 {
7316 if (new_value_alloced)
7317 free_string_option(*varp);
7318 *varp = oldval;
7319 /*
7320 * When resetting some values, need to act on it.
7321 */
7322 if (did_chartab)
7323 (void)init_chartab();
7324 if (varp == &p_hl)
7325 (void)highlight_changed();
7326 }
7327 else
7328 {
7329#ifdef FEAT_EVAL
7330 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007331 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007332#endif
7333 /*
7334 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007335 * Use "free_oldval", because recursiveness may change the flags under
7336 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007337 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007338 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007339 free_string_option(oldval);
7340 if (new_value_alloced)
7341 options[opt_idx].flags |= P_ALLOCED;
7342 else
7343 options[opt_idx].flags &= ~P_ALLOCED;
7344
7345 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007346 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007347 {
7348 /* global option with local value set to use global value; free
7349 * the local value and make it empty */
7350 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7351 free_string_option(*(char_u **)p);
7352 *(char_u **)p = empty_option;
7353 }
7354
7355 /* May set global value for local option. */
7356 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7357 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007358
7359#ifdef FEAT_AUTOCMD
7360 /*
7361 * Trigger the autocommand only after setting the flags.
7362 */
7363# ifdef FEAT_SYN_HL
7364 /* When 'syntax' is set, load the syntax of that name */
7365 if (varp == &(curbuf->b_p_syn))
7366 {
7367 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7368 curbuf->b_fname, TRUE, curbuf);
7369 }
7370# endif
7371 else if (varp == &(curbuf->b_p_ft))
7372 {
7373 /* 'filetype' is set, trigger the FileType autocommand */
7374 did_filetype = TRUE;
7375 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7376 curbuf->b_fname, TRUE, curbuf);
7377 }
7378#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007379#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007380 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007381 {
7382 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007383 char_u *q = curwin->w_s->b_p_spl;
7384
7385 /* Skip the first name if it is "cjk". */
7386 if (STRNCMP(q, "cjk,", 4) == 0)
7387 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007388
7389 /*
7390 * Source the spell/LANG.vim in 'runtimepath'.
7391 * They could set 'spellcapcheck' depending on the language.
7392 * Use the first name in 'spelllang' up to '_region' or
7393 * '.encoding'.
7394 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007395 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007396 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7397 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007398 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007399 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007400 }
7401#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007402 }
7403
7404#ifdef FEAT_MOUSE
7405 if (varp == &p_mouse)
7406 {
7407# ifdef FEAT_MOUSE_TTY
7408 if (*p_mouse == NUL)
7409 mch_setmouse(FALSE); /* switch mouse off */
7410 else
7411# endif
7412 setmouse(); /* in case 'mouse' changed */
7413 }
7414#endif
7415
Bram Moolenaar913077c2012-03-28 19:59:04 +02007416 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007417 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007418 curwin->w_set_curswant = TRUE;
7419
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007420#ifdef FEAT_GUI
7421 /* check redraw when it's not a GUI option or the GUI is active. */
7422 if (!redraw_gui_only || gui.in_use)
7423#endif
7424 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007425
7426 return errmsg;
7427}
7428
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007429#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007430/*
7431 * Simple int comparison function for use with qsort()
7432 */
7433 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007434int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007435{
7436 return *(const int *)a - *(const int *)b;
7437}
7438
7439/*
7440 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7441 * Returns error message, NULL if it's OK.
7442 */
7443 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007444check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007445{
7446 char_u *s;
7447 int col;
7448 int count = 0;
7449 int color_cols[256];
7450 int i;
7451 int j = 0;
7452
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007453 if (wp->w_buffer == NULL)
7454 return NULL; /* buffer was closed */
7455
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007456 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007457 {
7458 if (*s == '-' || *s == '+')
7459 {
7460 /* -N and +N: add to 'textwidth' */
7461 col = (*s == '-') ? -1 : 1;
7462 ++s;
7463 if (!VIM_ISDIGIT(*s))
7464 return e_invarg;
7465 col = col * getdigits(&s);
7466 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007467 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007468 col += wp->w_buffer->b_p_tw;
7469 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007470 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007471 }
7472 else if (VIM_ISDIGIT(*s))
7473 col = getdigits(&s);
7474 else
7475 return e_invarg;
7476 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007477skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007478 if (*s == NUL)
7479 break;
7480 if (*s != ',')
7481 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007482 if (*++s == NUL)
7483 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007484 }
7485
7486 vim_free(wp->w_p_cc_cols);
7487 if (count == 0)
7488 wp->w_p_cc_cols = NULL;
7489 else
7490 {
7491 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7492 if (wp->w_p_cc_cols != NULL)
7493 {
7494 /* sort the columns for faster usage on screen redraw inside
7495 * win_line() */
7496 qsort(color_cols, count, sizeof(int), int_cmp);
7497
7498 for (i = 0; i < count; ++i)
7499 /* skip duplicates */
7500 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7501 wp->w_p_cc_cols[j++] = color_cols[i];
7502 wp->w_p_cc_cols[j] = -1; /* end marker */
7503 }
7504 }
7505
7506 return NULL; /* no error */
7507}
7508#endif
7509
Bram Moolenaar071d4272004-06-13 20:20:40 +00007510/*
7511 * Handle setting 'listchars' or 'fillchars'.
7512 * Returns error message, NULL if it's OK.
7513 */
7514 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007515set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007516{
7517 int round, i, len, entries;
7518 char_u *p, *s;
7519 int c1, c2 = 0;
7520 struct charstab
7521 {
7522 int *cp;
7523 char *name;
7524 };
7525#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7526 static struct charstab filltab[] =
7527 {
7528 {&fill_stl, "stl"},
7529 {&fill_stlnc, "stlnc"},
7530 {&fill_vert, "vert"},
7531 {&fill_fold, "fold"},
7532 {&fill_diff, "diff"},
7533 };
7534#endif
7535 static struct charstab lcstab[] =
7536 {
7537 {&lcs_eol, "eol"},
7538 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007539 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007541 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007542 {&lcs_tab2, "tab"},
7543 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007544#ifdef FEAT_CONCEAL
7545 {&lcs_conceal, "conceal"},
7546#else
7547 {NULL, "conceal"},
7548#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007549 };
7550 struct charstab *tab;
7551
7552#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7553 if (varp == &p_lcs)
7554#endif
7555 {
7556 tab = lcstab;
7557 entries = sizeof(lcstab) / sizeof(struct charstab);
7558 }
7559#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7560 else
7561 {
7562 tab = filltab;
7563 entries = sizeof(filltab) / sizeof(struct charstab);
7564 }
7565#endif
7566
7567 /* first round: check for valid value, second round: assign values */
7568 for (round = 0; round <= 1; ++round)
7569 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007570 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571 {
7572 /* After checking that the value is valid: set defaults: space for
7573 * 'fillchars', NUL for 'listchars' */
7574 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007575 if (tab[i].cp != NULL)
7576 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577 if (varp == &p_lcs)
7578 lcs_tab1 = NUL;
7579#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7580 else
7581 fill_diff = '-';
7582#endif
7583 }
7584 p = *varp;
7585 while (*p)
7586 {
7587 for (i = 0; i < entries; ++i)
7588 {
7589 len = (int)STRLEN(tab[i].name);
7590 if (STRNCMP(p, tab[i].name, len) == 0
7591 && p[len] == ':'
7592 && p[len + 1] != NUL)
7593 {
7594 s = p + len + 1;
7595#ifdef FEAT_MBYTE
7596 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007597 if (mb_char2cells(c1) > 1)
7598 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007599#else
7600 c1 = *s++;
7601#endif
7602 if (tab[i].cp == &lcs_tab2)
7603 {
7604 if (*s == NUL)
7605 continue;
7606#ifdef FEAT_MBYTE
7607 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007608 if (mb_char2cells(c2) > 1)
7609 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007610#else
7611 c2 = *s++;
7612#endif
7613 }
7614 if (*s == ',' || *s == NUL)
7615 {
7616 if (round)
7617 {
7618 if (tab[i].cp == &lcs_tab2)
7619 {
7620 lcs_tab1 = c1;
7621 lcs_tab2 = c2;
7622 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007623 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007624 *(tab[i].cp) = c1;
7625
7626 }
7627 p = s;
7628 break;
7629 }
7630 }
7631 }
7632
7633 if (i == entries)
7634 return e_invarg;
7635 if (*p == ',')
7636 ++p;
7637 }
7638 }
7639
7640 return NULL; /* no error */
7641}
7642
7643#ifdef FEAT_STL_OPT
7644/*
7645 * Check validity of options with the 'statusline' format.
7646 * Return error message or NULL.
7647 */
7648 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007649check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650{
7651 int itemcnt = 0;
7652 int groupdepth = 0;
7653 static char_u errbuf[80];
7654
7655 while (*s && itemcnt < STL_MAX_ITEM)
7656 {
7657 /* Check for valid keys after % sequences */
7658 while (*s && *s != '%')
7659 s++;
7660 if (!*s)
7661 break;
7662 s++;
7663 if (*s != '%' && *s != ')')
7664 ++itemcnt;
7665 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7666 {
7667 s++;
7668 continue;
7669 }
7670 if (*s == ')')
7671 {
7672 s++;
7673 if (--groupdepth < 0)
7674 break;
7675 continue;
7676 }
7677 if (*s == '-')
7678 s++;
7679 while (VIM_ISDIGIT(*s))
7680 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007681 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682 continue;
7683 if (*s == '.')
7684 {
7685 s++;
7686 while (*s && VIM_ISDIGIT(*s))
7687 s++;
7688 }
7689 if (*s == '(')
7690 {
7691 groupdepth++;
7692 continue;
7693 }
7694 if (vim_strchr(STL_ALL, *s) == NULL)
7695 {
7696 return illegal_char(errbuf, *s);
7697 }
7698 if (*s == '{')
7699 {
7700 s++;
7701 while (*s != '}' && *s)
7702 s++;
7703 if (*s != '}')
7704 return (char_u *)N_("E540: Unclosed expression sequence");
7705 }
7706 }
7707 if (itemcnt >= STL_MAX_ITEM)
7708 return (char_u *)N_("E541: too many items");
7709 if (groupdepth != 0)
7710 return (char_u *)N_("E542: unbalanced groups");
7711 return NULL;
7712}
7713#endif
7714
7715#ifdef FEAT_CLIPBOARD
7716/*
7717 * Extract the items in the 'clipboard' option and set global values.
7718 */
7719 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007720check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007722 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007723 int new_autoselect_star = FALSE;
7724 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007725 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007726 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007727 regprog_T *new_exclude_prog = NULL;
7728 char_u *errmsg = NULL;
7729 char_u *p;
7730
7731 for (p = p_cb; *p != NUL; )
7732 {
7733 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7734 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007735 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 p += 7;
7737 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007738 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007739 && (p[11] == ',' || p[11] == NUL))
7740 {
7741 new_unnamed |= CLIP_UNNAMED_PLUS;
7742 p += 11;
7743 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007744 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007745 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007746 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007747 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 p += 10;
7749 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007750 else if (STRNCMP(p, "autoselectplus", 14) == 0
7751 && (p[14] == ',' || p[14] == NUL))
7752 {
7753 new_autoselect_plus = TRUE;
7754 p += 14;
7755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007756 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007757 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 {
7759 new_autoselectml = TRUE;
7760 p += 12;
7761 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007762 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7763 {
7764 new_html = TRUE;
7765 p += 4;
7766 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7768 {
7769 p += 8;
7770 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7771 if (new_exclude_prog == NULL)
7772 errmsg = e_invarg;
7773 break;
7774 }
7775 else
7776 {
7777 errmsg = e_invarg;
7778 break;
7779 }
7780 if (*p == ',')
7781 ++p;
7782 }
7783 if (errmsg == NULL)
7784 {
7785 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007786 clip_autoselect_star = new_autoselect_star;
7787 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007788 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007789 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007790 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007791 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007792#ifdef FEAT_GUI_GTK
7793 if (gui.in_use)
7794 {
7795 gui_gtk_set_selection_targets();
7796 gui_gtk_set_dnd_targets();
7797 }
7798#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799 }
7800 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007801 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007802
7803 return errmsg;
7804}
7805#endif
7806
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007807#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007808 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007809did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007810{
7811 char_u *errmsg = NULL;
7812 win_T *wp;
7813 int l;
7814
7815 if (is_spellfile)
7816 {
7817 l = (int)STRLEN(curwin->w_s->b_p_spf);
7818 if (l > 0 && (l < 4
7819 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7820 errmsg = e_invarg;
7821 }
7822
7823 if (errmsg == NULL)
7824 {
7825 FOR_ALL_WINDOWS(wp)
7826 if (wp->w_buffer == curbuf && wp->w_p_spell)
7827 {
7828 errmsg = did_set_spelllang(wp);
7829# ifdef FEAT_WINDOWS
7830 break;
7831# endif
7832 }
7833 }
7834 return errmsg;
7835}
7836
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007837/*
7838 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7839 * Return error message when failed, NULL when OK.
7840 */
7841 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007842compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007843{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007844 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007845 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007846
Bram Moolenaar860cae12010-06-05 23:22:07 +02007847 if (*synblock->b_p_spc == NUL)
7848 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007849 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007850 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007851 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007852 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007853 if (re != NULL)
7854 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007855 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007856 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007857 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007858 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007859 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007860 return e_invarg;
7861 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007862 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007863 }
7864
Bram Moolenaar473de612013-06-08 18:19:48 +02007865 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007866 return NULL;
7867}
7868#endif
7869
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007870#if defined(FEAT_EVAL) || defined(PROTO)
7871/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007872 * Set the scriptID for an option, taking care of setting the buffer- or
7873 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007874 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007875 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007876set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007877{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007878 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7879 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007880
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007881 /* Remember where the option was set. For local options need to do that
7882 * in the buffer or window structure. */
7883 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007884 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007885 if (both || (opt_flags & OPT_LOCAL))
7886 {
7887 if (indir & PV_BUF)
7888 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7889 else if (indir & PV_WIN)
7890 curwin->w_p_scriptID[indir & PV_MASK] = id;
7891 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007892}
7893#endif
7894
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895/*
7896 * Set the value of a boolean option, and take care of side effects.
7897 * Returns NULL for success, or an error message for an error.
7898 */
7899 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007900set_bool_option(
7901 int opt_idx, /* index in options[] table */
7902 char_u *varp, /* pointer to the option variable */
7903 int value, /* new value */
7904 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905{
7906 int old_value = *(int *)varp;
7907
Bram Moolenaar071d4272004-06-13 20:20:40 +00007908 /* Disallow changing some options from secure mode */
7909 if ((secure
7910#ifdef HAVE_SANDBOX
7911 || sandbox != 0
7912#endif
7913 ) && (options[opt_idx].flags & P_SECURE))
7914 return e_secure;
7915
7916 *(int *)varp = value; /* set the new value */
7917#ifdef FEAT_EVAL
7918 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007919 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007920#endif
7921
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007922#ifdef FEAT_GUI
7923 need_mouse_correct = TRUE;
7924#endif
7925
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926 /* May set global value for local option. */
7927 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7928 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7929
7930 /*
7931 * Handle side effects of changing a bool option.
7932 */
7933
7934 /* 'compatible' */
7935 if ((int *)varp == &p_cp)
7936 {
7937 compatible_set();
7938 }
7939
Bram Moolenaar920694c2016-08-21 17:45:02 +02007940#ifdef FEAT_LANGMAP
7941 if ((int *)varp == &p_lrm)
7942 /* 'langremap' -> !'langnoremap' */
7943 p_lnr = !p_lrm;
7944 else if ((int *)varp == &p_lnr)
7945 /* 'langnoremap' -> !'langremap' */
7946 p_lrm = !p_lnr;
7947#endif
7948
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007949#ifdef FEAT_PERSISTENT_UNDO
7950 /* 'undofile' */
7951 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7952 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007953 /* Only take action when the option was set. When reset we do not
7954 * delete the undo file, the option may be set again without making
7955 * any changes in between. */
7956 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007957 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007958 char_u hash[UNDO_HASH_SIZE];
7959 buf_T *save_curbuf = curbuf;
7960
Bram Moolenaar29323592016-07-24 22:04:11 +02007961 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007962 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007963 /* When 'undofile' is set globally: for every buffer, otherwise
7964 * only for the current buffer: Try to read in the undofile,
7965 * if one exists, the buffer wasn't changed and the buffer was
7966 * loaded */
7967 if ((curbuf == save_curbuf
7968 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7969 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7970 {
7971 u_compute_hash(hash);
7972 u_read_undo(NULL, hash, curbuf->b_fname);
7973 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007974 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007975 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007976 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007977 }
7978#endif
7979
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 else if ((int *)varp == &curbuf->b_p_ro)
7981 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007982 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7984 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007985
7986 /* when 'readonly' is set may give W10 again */
7987 if (curbuf->b_p_ro)
7988 curbuf->b_did_warn = FALSE;
7989
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007991 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007992#endif
7993 }
7994
Bram Moolenaar9c449722010-07-20 18:44:27 +02007995#ifdef FEAT_GUI
7996 else if ((int *)varp == &p_mh)
7997 {
7998 if (!p_mh)
7999 gui_mch_mousehide(FALSE);
8000 }
8001#endif
8002
Bram Moolenaara539df02010-08-01 14:35:05 +02008003#ifdef FEAT_TITLE
8004 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008005 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008006 {
8007 redraw_titles();
8008 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008009 /* when 'endofline' is changed, redraw the window title */
8010 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008011 {
8012 redraw_titles();
8013 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008014 /* when 'fixeol' is changed, redraw the window title */
8015 else if ((int *)varp == &curbuf->b_p_fixeol)
8016 {
8017 redraw_titles();
8018 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008019# ifdef FEAT_MBYTE
8020 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008021 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008022 {
8023 redraw_titles();
8024 }
8025# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008026#endif
8027
8028 /* when 'bin' is set also set some other options */
8029 else if ((int *)varp == &curbuf->b_p_bin)
8030 {
8031 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8032#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008033 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034#endif
8035 }
8036
8037#ifdef FEAT_AUTOCMD
8038 /* when 'buflisted' changes, trigger autocommands */
8039 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8040 {
8041 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8042 NULL, NULL, TRUE, curbuf);
8043 }
8044#endif
8045
8046 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8047 else if ((int *)varp == &curbuf->b_p_swf)
8048 {
8049 if (curbuf->b_p_swf && p_uc)
8050 ml_open_file(curbuf); /* create the swap file */
8051 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008052 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8053 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008054 mf_close_file(curbuf, TRUE); /* remove the swap file */
8055 }
8056
8057 /* when 'terse' is set change 'shortmess' */
8058 else if ((int *)varp == &p_terse)
8059 {
8060 char_u *p;
8061
8062 p = vim_strchr(p_shm, SHM_SEARCH);
8063
8064 /* insert 's' in p_shm */
8065 if (p_terse && p == NULL)
8066 {
8067 STRCPY(IObuff, p_shm);
8068 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008069 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 }
8071 /* remove 's' from p_shm */
8072 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008073 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008074 }
8075
8076 /* when 'paste' is set or reset also change other options */
8077 else if ((int *)varp == &p_paste)
8078 {
8079 paste_option_changed();
8080 }
8081
8082 /* when 'insertmode' is set from an autocommand need to do work here */
8083 else if ((int *)varp == &p_im)
8084 {
8085 if (p_im)
8086 {
8087 if ((State & INSERT) == 0)
8088 need_start_insertmode = TRUE;
8089 stop_insert_mode = FALSE;
8090 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008091 /* only reset if it was set previously */
8092 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 {
8094 need_start_insertmode = FALSE;
8095 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008096 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008097 clear_cmdline = TRUE; /* remove "(insert)" */
8098 restart_edit = 0;
8099 }
8100 }
8101
8102 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8103 else if ((int *)varp == &p_ic && p_hls)
8104 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008105 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008106 }
8107
8108#ifdef FEAT_SEARCH_EXTRA
8109 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8110 else if ((int *)varp == &p_hls)
8111 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008112 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008113 }
8114#endif
8115
8116#ifdef FEAT_SCROLLBIND
8117 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8118 * at the end of normal_cmd() */
8119 else if ((int *)varp == &curwin->w_p_scb)
8120 {
8121 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008122 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008124 curwin->w_scbind_pos = curwin->w_topline;
8125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126 }
8127#endif
8128
8129#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8130 /* There can be only one window with 'previewwindow' set. */
8131 else if ((int *)varp == &curwin->w_p_pvw)
8132 {
8133 if (curwin->w_p_pvw)
8134 {
8135 win_T *win;
8136
Bram Moolenaar29323592016-07-24 22:04:11 +02008137 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008138 if (win->w_p_pvw && win != curwin)
8139 {
8140 curwin->w_p_pvw = FALSE;
8141 return (char_u *)N_("E590: A preview window already exists");
8142 }
8143 }
8144 }
8145#endif
8146
8147 /* when 'textmode' is set or reset also change 'fileformat' */
8148 else if ((int *)varp == &curbuf->b_p_tx)
8149 {
8150 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8151 }
8152
8153 /* when 'textauto' is set or reset also change 'fileformats' */
8154 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 set_string_option_direct((char_u *)"ffs", -1,
8156 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008157 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158
8159 /*
8160 * When 'lisp' option changes include/exclude '-' in
8161 * keyword characters.
8162 */
8163#ifdef FEAT_LISP
8164 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8165 {
8166 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8167 }
8168#endif
8169
8170#ifdef FEAT_TITLE
8171 /* when 'title' changed, may need to change the title; same for 'icon' */
8172 else if ((int *)varp == &p_title)
8173 {
8174 did_set_title(FALSE);
8175 }
8176
8177 else if ((int *)varp == &p_icon)
8178 {
8179 did_set_title(TRUE);
8180 }
8181#endif
8182
8183 else if ((int *)varp == &curbuf->b_changed)
8184 {
8185 if (!value)
8186 save_file_ff(curbuf); /* Buffer is unchanged */
8187#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008188 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189#endif
8190#ifdef FEAT_AUTOCMD
8191 modified_was_set = value;
8192#endif
8193 }
8194
8195#ifdef BACKSLASH_IN_FILENAME
8196 else if ((int *)varp == &p_ssl)
8197 {
8198 if (p_ssl)
8199 {
8200 psepc = '/';
8201 psepcN = '\\';
8202 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008203 }
8204 else
8205 {
8206 psepc = '\\';
8207 psepcN = '/';
8208 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209 }
8210
8211 /* need to adjust the file name arguments and buffer names. */
8212 buflist_slash_adjust();
8213 alist_slash_adjust();
8214# ifdef FEAT_EVAL
8215 scriptnames_slash_adjust();
8216# endif
8217 }
8218#endif
8219
8220 /* If 'wrap' is set, set w_leftcol to zero. */
8221 else if ((int *)varp == &curwin->w_p_wrap)
8222 {
8223 if (curwin->w_p_wrap)
8224 curwin->w_leftcol = 0;
8225 }
8226
8227#ifdef FEAT_WINDOWS
8228 else if ((int *)varp == &p_ea)
8229 {
8230 if (p_ea && !old_value)
8231 win_equal(curwin, FALSE, 0);
8232 }
8233#endif
8234
8235 else if ((int *)varp == &p_wiv)
8236 {
8237 /*
8238 * When 'weirdinvert' changed, set/reset 't_xs'.
8239 * Then set 'weirdinvert' according to value of 't_xs'.
8240 */
8241 if (p_wiv && !old_value)
8242 T_XS = (char_u *)"y";
8243 else if (!p_wiv && old_value)
8244 T_XS = empty_option;
8245 p_wiv = (*T_XS != NUL);
8246 }
8247
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008248#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008249 else if ((int *)varp == &p_beval)
8250 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008251 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008252 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008253 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008254 gui_mch_disable_beval_area(balloonEval);
8255 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008256#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008257
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008258#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008259 else if ((int *)varp == &p_acd)
8260 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008261 /* Change directories when the 'acd' option is set now. */
8262 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263 }
8264#endif
8265
8266#ifdef FEAT_DIFF
8267 /* 'diff' */
8268 else if ((int *)varp == &curwin->w_p_diff)
8269 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008270 /* May add or remove the buffer from the list of diff buffers. */
8271 diff_buf_adjust(curwin);
8272# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008273 if (foldmethodIsDiff(curwin))
8274 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008275# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008276 }
8277#endif
8278
8279#ifdef USE_IM_CONTROL
8280 /* 'imdisable' */
8281 else if ((int *)varp == &p_imdisable)
8282 {
8283 /* Only de-activate it here, it will be enabled when changing mode. */
8284 if (p_imdisable)
8285 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008286 else if (State & INSERT)
8287 /* When the option is set from an autocommand, it may need to take
8288 * effect right away. */
8289 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 }
8291#endif
8292
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008293#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008294 /* 'spell' */
8295 else if ((int *)varp == &curwin->w_p_spell)
8296 {
8297 if (curwin->w_p_spell)
8298 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008299 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008300 if (errmsg != NULL)
8301 EMSG(_(errmsg));
8302 }
8303 }
8304#endif
8305
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306#ifdef FEAT_FKMAP
8307 else if ((int *)varp == &p_altkeymap)
8308 {
8309 if (old_value != p_altkeymap)
8310 {
8311 if (!p_altkeymap)
8312 {
8313 p_hkmap = p_fkmap;
8314 p_fkmap = 0;
8315 }
8316 else
8317 {
8318 p_fkmap = p_hkmap;
8319 p_hkmap = 0;
8320 }
8321 (void)init_chartab();
8322 }
8323 }
8324
8325 /*
8326 * In case some second language keymapping options have changed, check
8327 * and correct the setting in a consistent way.
8328 */
8329
8330 /*
8331 * If hkmap or fkmap are set, reset Arabic keymapping.
8332 */
8333 if ((p_hkmap || p_fkmap) && p_altkeymap)
8334 {
8335 p_altkeymap = p_fkmap;
8336# ifdef FEAT_ARABIC
8337 curwin->w_p_arab = FALSE;
8338# endif
8339 (void)init_chartab();
8340 }
8341
8342 /*
8343 * If hkmap set, reset Farsi keymapping.
8344 */
8345 if (p_hkmap && p_altkeymap)
8346 {
8347 p_altkeymap = 0;
8348 p_fkmap = 0;
8349# ifdef FEAT_ARABIC
8350 curwin->w_p_arab = FALSE;
8351# endif
8352 (void)init_chartab();
8353 }
8354
8355 /*
8356 * If fkmap set, reset Hebrew keymapping.
8357 */
8358 if (p_fkmap && !p_altkeymap)
8359 {
8360 p_altkeymap = 1;
8361 p_hkmap = 0;
8362# ifdef FEAT_ARABIC
8363 curwin->w_p_arab = FALSE;
8364# endif
8365 (void)init_chartab();
8366 }
8367#endif
8368
8369#ifdef FEAT_ARABIC
8370 if ((int *)varp == &curwin->w_p_arab)
8371 {
8372 if (curwin->w_p_arab)
8373 {
8374 /*
8375 * 'arabic' is set, handle various sub-settings.
8376 */
8377 if (!p_tbidi)
8378 {
8379 /* set rightleft mode */
8380 if (!curwin->w_p_rl)
8381 {
8382 curwin->w_p_rl = TRUE;
8383 changed_window_setting();
8384 }
8385
8386 /* Enable Arabic shaping (major part of what Arabic requires) */
8387 if (!p_arshape)
8388 {
8389 p_arshape = TRUE;
8390 redraw_later_clear();
8391 }
8392 }
8393
8394 /* Arabic requires a utf-8 encoding, inform the user if its not
8395 * set. */
8396 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008397 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008398 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8399
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008400 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008401 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8402#ifdef FEAT_EVAL
8403 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8404#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008405 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406
8407# ifdef FEAT_MBYTE
8408 /* set 'delcombine' */
8409 p_deco = TRUE;
8410# endif
8411
8412# ifdef FEAT_KEYMAP
8413 /* Force-set the necessary keymap for arabic */
8414 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8415 OPT_LOCAL);
8416# endif
8417# ifdef FEAT_FKMAP
8418 p_altkeymap = 0;
8419 p_hkmap = 0;
8420 p_fkmap = 0;
8421 (void)init_chartab();
8422# endif
8423 }
8424 else
8425 {
8426 /*
8427 * 'arabic' is reset, handle various sub-settings.
8428 */
8429 if (!p_tbidi)
8430 {
8431 /* reset rightleft mode */
8432 if (curwin->w_p_rl)
8433 {
8434 curwin->w_p_rl = FALSE;
8435 changed_window_setting();
8436 }
8437
8438 /* 'arabicshape' isn't reset, it is a global option and
8439 * another window may still need it "on". */
8440 }
8441
8442 /* 'delcombine' isn't reset, it is a global option and another
8443 * window may still want it "on". */
8444
8445# ifdef FEAT_KEYMAP
8446 /* Revert to the default keymap */
8447 curbuf->b_p_iminsert = B_IMODE_NONE;
8448 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8449# endif
8450 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008451 }
8452
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008453#endif
8454
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008455#ifdef FEAT_TERMGUICOLORS
8456 /* 'termguicolors' */
8457 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008458 {
8459# ifdef FEAT_GUI
8460 if (!gui.in_use && !gui.starting)
8461# endif
8462 highlight_gui_started();
8463 }
8464#endif
8465
Bram Moolenaar071d4272004-06-13 20:20:40 +00008466 /*
8467 * End of handling side effects for bool options.
8468 */
8469
Bram Moolenaar53744302015-07-17 17:38:22 +02008470 /* after handling side effects, call autocommand */
8471
Bram Moolenaar071d4272004-06-13 20:20:40 +00008472 options[opt_idx].flags |= P_WAS_SET;
8473
Bram Moolenaar53744302015-07-17 17:38:22 +02008474#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8475 if (!starting)
8476 {
8477 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008478 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8479 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8480 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008481 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8482 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8483 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8484 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8485 reset_v_option_vars();
8486 }
8487#endif
8488
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008490 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008491 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008492 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493 check_redraw(options[opt_idx].flags);
8494
8495 return NULL;
8496}
8497
8498/*
8499 * Set the value of a number option, and take care of side effects.
8500 * Returns NULL for success, or an error message for an error.
8501 */
8502 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008503set_num_option(
8504 int opt_idx, /* index in options[] table */
8505 char_u *varp, /* pointer to the option variable */
8506 long value, /* new value */
8507 char_u *errbuf, /* buffer for error messages */
8508 size_t errbuflen, /* length of "errbuf" */
8509 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510 OPT_MODELINE */
8511{
8512 char_u *errmsg = NULL;
8513 long old_value = *(long *)varp;
8514 long old_Rows = Rows; /* remember old Rows */
8515 long old_Columns = Columns; /* remember old Columns */
8516 long *pp = (long *)varp;
8517
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008518 /* Disallow changing some options from secure mode. */
8519 if ((secure
8520#ifdef HAVE_SANDBOX
8521 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008522#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008523 ) && (options[opt_idx].flags & P_SECURE))
8524 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008525
8526 *pp = value;
8527#ifdef FEAT_EVAL
8528 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008529 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008530#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008531#ifdef FEAT_GUI
8532 need_mouse_correct = TRUE;
8533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008534
Bram Moolenaar14f24742012-08-08 18:01:05 +02008535 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536 {
8537 errmsg = e_positive;
8538 curbuf->b_p_sw = curbuf->b_p_ts;
8539 }
8540
8541 /*
8542 * Number options that need some action when changed
8543 */
8544#ifdef FEAT_WINDOWS
8545 if (pp == &p_wh || pp == &p_hh)
8546 {
8547 if (p_wh < 1)
8548 {
8549 errmsg = e_positive;
8550 p_wh = 1;
8551 }
8552 if (p_wmh > p_wh)
8553 {
8554 errmsg = e_winheight;
8555 p_wh = p_wmh;
8556 }
8557 if (p_hh < 0)
8558 {
8559 errmsg = e_positive;
8560 p_hh = 0;
8561 }
8562
8563 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008564 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565 {
8566 if (pp == &p_wh && curwin->w_height < p_wh)
8567 win_setheight((int)p_wh);
8568 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8569 win_setheight((int)p_hh);
8570 }
8571 }
8572
8573 /* 'winminheight' */
8574 else if (pp == &p_wmh)
8575 {
8576 if (p_wmh < 0)
8577 {
8578 errmsg = e_positive;
8579 p_wmh = 0;
8580 }
8581 if (p_wmh > p_wh)
8582 {
8583 errmsg = e_winheight;
8584 p_wmh = p_wh;
8585 }
8586 win_setminheight();
8587 }
8588
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008589# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008590 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 {
8592 if (p_wiw < 1)
8593 {
8594 errmsg = e_positive;
8595 p_wiw = 1;
8596 }
8597 if (p_wmw > p_wiw)
8598 {
8599 errmsg = e_winwidth;
8600 p_wiw = p_wmw;
8601 }
8602
8603 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008604 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605 win_setwidth((int)p_wiw);
8606 }
8607
8608 /* 'winminwidth' */
8609 else if (pp == &p_wmw)
8610 {
8611 if (p_wmw < 0)
8612 {
8613 errmsg = e_positive;
8614 p_wmw = 0;
8615 }
8616 if (p_wmw > p_wiw)
8617 {
8618 errmsg = e_winwidth;
8619 p_wmw = p_wiw;
8620 }
8621 win_setminheight();
8622 }
8623# endif
8624
8625#endif
8626
8627#ifdef FEAT_WINDOWS
8628 /* (re)set last window status line */
8629 else if (pp == &p_ls)
8630 {
8631 last_status(FALSE);
8632 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008633
8634 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008635 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008636 {
8637 shell_new_rows(); /* recompute window positions and heights */
8638 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639#endif
8640
8641#ifdef FEAT_GUI
8642 else if (pp == &p_linespace)
8643 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008644 /* Recompute gui.char_height and resize the Vim window to keep the
8645 * same number of lines. */
8646 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008647 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648 }
8649#endif
8650
8651#ifdef FEAT_FOLDING
8652 /* 'foldlevel' */
8653 else if (pp == &curwin->w_p_fdl)
8654 {
8655 if (curwin->w_p_fdl < 0)
8656 curwin->w_p_fdl = 0;
8657 newFoldLevel();
8658 }
8659
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008660 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008661 else if (pp == &curwin->w_p_fml)
8662 {
8663 foldUpdateAll(curwin);
8664 }
8665
8666 /* 'foldnestmax' */
8667 else if (pp == &curwin->w_p_fdn)
8668 {
8669 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8670 foldUpdateAll(curwin);
8671 }
8672
8673 /* 'foldcolumn' */
8674 else if (pp == &curwin->w_p_fdc)
8675 {
8676 if (curwin->w_p_fdc < 0)
8677 {
8678 errmsg = e_positive;
8679 curwin->w_p_fdc = 0;
8680 }
8681 else if (curwin->w_p_fdc > 12)
8682 {
8683 errmsg = e_invarg;
8684 curwin->w_p_fdc = 12;
8685 }
8686 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008687#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008689#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008690 /* 'shiftwidth' or 'tabstop' */
8691 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8692 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008693# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008694 if (foldmethodIsIndent(curwin))
8695 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008696# endif
8697# ifdef FEAT_CINDENT
8698 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8699 * parse 'cinoptions'. */
8700 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8701 parse_cino(curbuf);
8702# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008703 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008706#ifdef FEAT_MBYTE
8707 /* 'maxcombine' */
8708 else if (pp == &p_mco)
8709 {
8710 if (p_mco > MAX_MCO)
8711 p_mco = MAX_MCO;
8712 else if (p_mco < 0)
8713 p_mco = 0;
8714 screenclear(); /* will re-allocate the screen */
8715 }
8716#endif
8717
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718 else if (pp == &curbuf->b_p_iminsert)
8719 {
8720 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8721 {
8722 errmsg = e_invarg;
8723 curbuf->b_p_iminsert = B_IMODE_NONE;
8724 }
8725 p_iminsert = curbuf->b_p_iminsert;
8726 if (termcap_active) /* don't do this in the alternate screen */
8727 showmode();
8728#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8729 /* Show/unshow value of 'keymap' in status lines. */
8730 status_redraw_curbuf();
8731#endif
8732 }
8733
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008734 else if (pp == &p_window)
8735 {
8736 if (p_window < 1)
8737 p_window = 1;
8738 else if (p_window >= Rows)
8739 p_window = Rows - 1;
8740 }
8741
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742 else if (pp == &curbuf->b_p_imsearch)
8743 {
8744 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8745 {
8746 errmsg = e_invarg;
8747 curbuf->b_p_imsearch = B_IMODE_NONE;
8748 }
8749 p_imsearch = curbuf->b_p_imsearch;
8750 }
8751
8752#ifdef FEAT_TITLE
8753 /* if 'titlelen' has changed, redraw the title */
8754 else if (pp == &p_titlelen)
8755 {
8756 if (p_titlelen < 0)
8757 {
8758 errmsg = e_positive;
8759 p_titlelen = 85;
8760 }
8761 if (starting != NO_SCREEN && old_value != p_titlelen)
8762 need_maketitle = TRUE;
8763 }
8764#endif
8765
8766 /* if p_ch changed value, change the command line height */
8767 else if (pp == &p_ch)
8768 {
8769 if (p_ch < 1)
8770 {
8771 errmsg = e_positive;
8772 p_ch = 1;
8773 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008774 if (p_ch > Rows - min_rows() + 1)
8775 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008776
8777 /* Only compute the new window layout when startup has been
8778 * completed. Otherwise the frame sizes may be wrong. */
8779 if (p_ch != old_value && full_screen
8780#ifdef FEAT_GUI
8781 && !gui.starting
8782#endif
8783 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008784 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008785 }
8786
8787 /* when 'updatecount' changes from zero to non-zero, open swap files */
8788 else if (pp == &p_uc)
8789 {
8790 if (p_uc < 0)
8791 {
8792 errmsg = e_positive;
8793 p_uc = 100;
8794 }
8795 if (p_uc && !old_value)
8796 ml_open_files();
8797 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008798#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008799 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008800 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008801 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008802 {
8803 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008804 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008805 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008806 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008807 {
8808 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008809 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008810 }
8811 }
8812#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008813#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008814 else if (pp == &p_mzq)
8815 mzvim_reset_timer();
8816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008817
8818 /* sync undo before 'undolevels' changes */
8819 else if (pp == &p_ul)
8820 {
8821 /* use the old value, otherwise u_sync() may not work properly */
8822 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008823 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008824 p_ul = value;
8825 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008826 else if (pp == &curbuf->b_p_ul)
8827 {
8828 /* use the old value, otherwise u_sync() may not work properly */
8829 curbuf->b_p_ul = old_value;
8830 u_sync(TRUE);
8831 curbuf->b_p_ul = value;
8832 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008834#ifdef FEAT_LINEBREAK
8835 /* 'numberwidth' must be positive */
8836 else if (pp == &curwin->w_p_nuw)
8837 {
8838 if (curwin->w_p_nuw < 1)
8839 {
8840 errmsg = e_positive;
8841 curwin->w_p_nuw = 1;
8842 }
8843 if (curwin->w_p_nuw > 10)
8844 {
8845 errmsg = e_invarg;
8846 curwin->w_p_nuw = 10;
8847 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008848 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008849 }
8850#endif
8851
Bram Moolenaar1a384422010-07-14 19:53:30 +02008852 else if (pp == &curbuf->b_p_tw)
8853 {
8854 if (curbuf->b_p_tw < 0)
8855 {
8856 errmsg = e_positive;
8857 curbuf->b_p_tw = 0;
8858 }
8859#ifdef FEAT_SYN_HL
8860# ifdef FEAT_WINDOWS
8861 {
8862 win_T *wp;
8863 tabpage_T *tp;
8864
8865 FOR_ALL_TAB_WINDOWS(tp, wp)
8866 check_colorcolumn(wp);
8867 }
8868# else
8869 check_colorcolumn(curwin);
8870# endif
8871#endif
8872 }
8873
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874 /*
8875 * Check the bounds for numeric options here
8876 */
8877 if (Rows < min_rows() && full_screen)
8878 {
8879 if (errbuf != NULL)
8880 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008881 vim_snprintf((char *)errbuf, errbuflen,
8882 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008883 errmsg = errbuf;
8884 }
8885 Rows = min_rows();
8886 }
8887 if (Columns < MIN_COLUMNS && full_screen)
8888 {
8889 if (errbuf != NULL)
8890 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008891 vim_snprintf((char *)errbuf, errbuflen,
8892 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008893 errmsg = errbuf;
8894 }
8895 Columns = MIN_COLUMNS;
8896 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008897 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898
Bram Moolenaar071d4272004-06-13 20:20:40 +00008899 /*
8900 * If the screen (shell) height has been changed, assume it is the
8901 * physical screenheight.
8902 */
8903 if (old_Rows != Rows || old_Columns != Columns)
8904 {
8905 /* Changing the screen size is not allowed while updating the screen. */
8906 if (updating_screen)
8907 *pp = old_value;
8908 else if (full_screen
8909#ifdef FEAT_GUI
8910 && !gui.starting
8911#endif
8912 )
8913 set_shellsize((int)Columns, (int)Rows, TRUE);
8914 else
8915 {
8916 /* Postpone the resizing; check the size and cmdline position for
8917 * messages. */
8918 check_shellsize();
8919 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8920 cmdline_row = Rows - p_ch;
8921 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008922 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008923 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924 }
8925
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 if (curbuf->b_p_ts <= 0)
8927 {
8928 errmsg = e_positive;
8929 curbuf->b_p_ts = 8;
8930 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008931 if (p_tm < 0)
8932 {
8933 errmsg = e_positive;
8934 p_tm = 0;
8935 }
8936 if ((curwin->w_p_scr <= 0
8937 || (curwin->w_p_scr > curwin->w_height
8938 && curwin->w_height > 0))
8939 && full_screen)
8940 {
8941 if (pp == &(curwin->w_p_scr))
8942 {
8943 if (curwin->w_p_scr != 0)
8944 errmsg = e_scroll;
8945 win_comp_scroll(curwin);
8946 }
8947 /* If 'scroll' became invalid because of a side effect silently adjust
8948 * it. */
8949 else if (curwin->w_p_scr <= 0)
8950 curwin->w_p_scr = 1;
8951 else /* curwin->w_p_scr > curwin->w_height */
8952 curwin->w_p_scr = curwin->w_height;
8953 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008954 if (p_hi < 0)
8955 {
8956 errmsg = e_positive;
8957 p_hi = 0;
8958 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008959 else if (p_hi > 10000)
8960 {
8961 errmsg = e_invarg;
8962 p_hi = 10000;
8963 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008964 if (p_re < 0 || p_re > 2)
8965 {
8966 errmsg = e_invarg;
8967 p_re = 0;
8968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008969 if (p_report < 0)
8970 {
8971 errmsg = e_positive;
8972 p_report = 1;
8973 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008974 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008975 {
8976 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8977 p_sj = Rows / 2;
8978 else
8979 {
8980 errmsg = e_scroll;
8981 p_sj = 1;
8982 }
8983 }
8984 if (p_so < 0 && full_screen)
8985 {
8986 errmsg = e_scroll;
8987 p_so = 0;
8988 }
8989 if (p_siso < 0 && full_screen)
8990 {
8991 errmsg = e_positive;
8992 p_siso = 0;
8993 }
8994#ifdef FEAT_CMDWIN
8995 if (p_cwh < 1)
8996 {
8997 errmsg = e_positive;
8998 p_cwh = 1;
8999 }
9000#endif
9001 if (p_ut < 0)
9002 {
9003 errmsg = e_positive;
9004 p_ut = 2000;
9005 }
9006 if (p_ss < 0)
9007 {
9008 errmsg = e_positive;
9009 p_ss = 0;
9010 }
9011
9012 /* May set global value for local option. */
9013 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9014 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9015
9016 options[opt_idx].flags |= P_WAS_SET;
9017
Bram Moolenaar53744302015-07-17 17:38:22 +02009018#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9019 if (!starting && errmsg == NULL)
9020 {
9021 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009022 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9023 vim_snprintf((char *)buf_new, 10, "%ld", value);
9024 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009025 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9026 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9027 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9028 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9029 reset_v_option_vars();
9030 }
9031#endif
9032
Bram Moolenaar071d4272004-06-13 20:20:40 +00009033 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009034 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009035 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009036 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037 check_redraw(options[opt_idx].flags);
9038
9039 return errmsg;
9040}
9041
9042/*
9043 * Called after an option changed: check if something needs to be redrawn.
9044 */
9045 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009046check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009047{
9048 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009049 int doclear = (flags & P_RCLR) == P_RCLR;
9050 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009051
9052#ifdef FEAT_WINDOWS
9053 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9054 status_redraw_all();
9055#endif
9056
9057 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9058 changed_window_setting();
9059 if (flags & P_RBUF)
9060 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009061 if (flags & P_RWINONLY)
9062 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009063 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009064 redraw_all_later(CLEAR);
9065 else if (all)
9066 redraw_all_later(NOT_VALID);
9067}
9068
9069/*
9070 * Find index for option 'arg'.
9071 * Return -1 if not found.
9072 */
9073 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009074findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075{
9076 int opt_idx;
9077 char *s, *p;
9078 static short quick_tab[27] = {0, 0}; /* quick access table */
9079 int is_term_opt;
9080
9081 /*
9082 * For first call: Initialize the quick-access table.
9083 * It contains the index for the first option that starts with a certain
9084 * letter. There are 26 letters, plus the first "t_" option.
9085 */
9086 if (quick_tab[1] == 0)
9087 {
9088 p = options[0].fullname;
9089 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9090 {
9091 if (s[0] != p[0])
9092 {
9093 if (s[0] == 't' && s[1] == '_')
9094 quick_tab[26] = opt_idx;
9095 else
9096 quick_tab[CharOrdLow(s[0])] = opt_idx;
9097 }
9098 p = s;
9099 }
9100 }
9101
9102 /*
9103 * Check for name starting with an illegal character.
9104 */
9105#ifdef EBCDIC
9106 if (!islower(arg[0]))
9107#else
9108 if (arg[0] < 'a' || arg[0] > 'z')
9109#endif
9110 return -1;
9111
9112 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9113 if (is_term_opt)
9114 opt_idx = quick_tab[26];
9115 else
9116 opt_idx = quick_tab[CharOrdLow(arg[0])];
9117 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9118 {
9119 if (STRCMP(arg, s) == 0) /* match full name */
9120 break;
9121 }
9122 if (s == NULL && !is_term_opt)
9123 {
9124 opt_idx = quick_tab[CharOrdLow(arg[0])];
9125 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9126 {
9127 s = options[opt_idx].shortname;
9128 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9129 break;
9130 s = NULL;
9131 }
9132 }
9133 if (s == NULL)
9134 opt_idx = -1;
9135 return opt_idx;
9136}
9137
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009138#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009139/*
9140 * Get the value for an option.
9141 *
9142 * Returns:
9143 * Number or Toggle option: 1, *numval gets value.
9144 * String option: 0, *stringval gets allocated string.
9145 * Hidden Number or Toggle option: -1.
9146 * hidden String option: -2.
9147 * unknown option: -3.
9148 */
9149 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009150get_option_value(
9151 char_u *name,
9152 long *numval,
9153 char_u **stringval, /* NULL when only checking existence */
9154 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009155{
9156 int opt_idx;
9157 char_u *varp;
9158
9159 opt_idx = findoption(name);
9160 if (opt_idx < 0) /* unknown option */
9161 return -3;
9162
9163 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9164
9165 if (options[opt_idx].flags & P_STRING)
9166 {
9167 if (varp == NULL) /* hidden option */
9168 return -2;
9169 if (stringval != NULL)
9170 {
9171#ifdef FEAT_CRYPT
9172 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009173 if ((char_u **)varp == &curbuf->b_p_key
9174 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009175 *stringval = vim_strsave((char_u *)"*****");
9176 else
9177#endif
9178 *stringval = vim_strsave(*(char_u **)(varp));
9179 }
9180 return 0;
9181 }
9182
9183 if (varp == NULL) /* hidden option */
9184 return -1;
9185 if (options[opt_idx].flags & P_NUM)
9186 *numval = *(long *)varp;
9187 else
9188 {
9189 /* Special case: 'modified' is b_changed, but we also want to consider
9190 * it set when 'ff' or 'fenc' changed. */
9191 if ((int *)varp == &curbuf->b_changed)
9192 *numval = curbufIsChanged();
9193 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009194 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009195 }
9196 return 1;
9197}
9198#endif
9199
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009200#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009201/*
9202 * Returns the option attributes and its value. Unlike the above function it
9203 * will return either global value or local value of the option depending on
9204 * what was requested, but it will never return global value if it was
9205 * requested to return local one and vice versa. Neither it will return
9206 * buffer-local value if it was requested to return window-local one.
9207 *
9208 * Pretends that option is absent if it is not present in the requested scope
9209 * (i.e. has no global, window-local or buffer-local value depending on
9210 * opt_type). Uses
9211 *
9212 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009213 * 0 hidden or unknown option, also option that does not have requested
9214 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009215 * see SOPT_* in vim.h for other flags
9216 *
9217 * Possible opt_type values: see SREQ_* in vim.h
9218 */
9219 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009220get_option_value_strict(
9221 char_u *name,
9222 long *numval,
9223 char_u **stringval, /* NULL when only obtaining attributes */
9224 int opt_type,
9225 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009226{
9227 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009228 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009229 struct vimoption *p;
9230 int r = 0;
9231
9232 opt_idx = findoption(name);
9233 if (opt_idx < 0)
9234 return 0;
9235
9236 p = &(options[opt_idx]);
9237
9238 /* Hidden option */
9239 if (p->var == NULL)
9240 return 0;
9241
9242 if (p->flags & P_BOOL)
9243 r |= SOPT_BOOL;
9244 else if (p->flags & P_NUM)
9245 r |= SOPT_NUM;
9246 else if (p->flags & P_STRING)
9247 r |= SOPT_STRING;
9248
9249 if (p->indir == PV_NONE)
9250 {
9251 if (opt_type == SREQ_GLOBAL)
9252 r |= SOPT_GLOBAL;
9253 else
9254 return 0; /* Did not request global-only option */
9255 }
9256 else
9257 {
9258 if (p->indir & PV_BOTH)
9259 r |= SOPT_GLOBAL;
9260 else if (opt_type == SREQ_GLOBAL)
9261 return 0; /* Requested global option */
9262
9263 if (p->indir & PV_WIN)
9264 {
9265 if (opt_type == SREQ_BUF)
9266 return 0; /* Did not request window-local option */
9267 else
9268 r |= SOPT_WIN;
9269 }
9270 else if (p->indir & PV_BUF)
9271 {
9272 if (opt_type == SREQ_WIN)
9273 return 0; /* Did not request buffer-local option */
9274 else
9275 r |= SOPT_BUF;
9276 }
9277 }
9278
9279 if (stringval == NULL)
9280 return r;
9281
9282 if (opt_type == SREQ_GLOBAL)
9283 varp = p->var;
9284 else
9285 {
9286 if (opt_type == SREQ_BUF)
9287 {
9288 /* Special case: 'modified' is b_changed, but we also want to
9289 * consider it set when 'ff' or 'fenc' changed. */
9290 if (p->indir == PV_MOD)
9291 {
9292 *numval = bufIsChanged((buf_T *) from);
9293 varp = NULL;
9294 }
9295#ifdef FEAT_CRYPT
9296 else if (p->indir == PV_KEY)
9297 {
9298 /* never return the value of the crypt key */
9299 *stringval = NULL;
9300 varp = NULL;
9301 }
9302#endif
9303 else
9304 {
9305 aco_save_T aco;
9306 aucmd_prepbuf(&aco, (buf_T *) from);
9307 varp = get_varp(p);
9308 aucmd_restbuf(&aco);
9309 }
9310 }
9311 else if (opt_type == SREQ_WIN)
9312 {
9313 win_T *save_curwin;
9314 save_curwin = curwin;
9315 curwin = (win_T *) from;
9316 curbuf = curwin->w_buffer;
9317 varp = get_varp(p);
9318 curwin = save_curwin;
9319 curbuf = curwin->w_buffer;
9320 }
9321 if (varp == p->var)
9322 return (r | SOPT_UNSET);
9323 }
9324
9325 if (varp != NULL)
9326 {
9327 if (p->flags & P_STRING)
9328 *stringval = vim_strsave(*(char_u **)(varp));
9329 else if (p->flags & P_NUM)
9330 *numval = *(long *) varp;
9331 else
9332 *numval = *(int *)varp;
9333 }
9334
9335 return r;
9336}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009337
9338/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009339 * Iterate over options. First argument is a pointer to a pointer to a
9340 * structure inside options[] array, second is option type like in the above
9341 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009342 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009343 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009344 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009345 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009346 * first argument to NULL.
9347 *
9348 * Returns full option name for current option on each call.
9349 */
9350 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009351option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009352{
9353 struct vimoption *ret = NULL;
9354 do
9355 {
9356 if (*option == NULL)
9357 *option = (void *) options;
9358 else if (((struct vimoption *) (*option))->fullname == NULL)
9359 {
9360 *option = NULL;
9361 return NULL;
9362 }
9363 else
9364 *option = (void *) (((struct vimoption *) (*option)) + 1);
9365
9366 ret = ((struct vimoption *) (*option));
9367
9368 /* Hidden option */
9369 if (ret->var == NULL)
9370 {
9371 ret = NULL;
9372 continue;
9373 }
9374
9375 switch (opt_type)
9376 {
9377 case SREQ_GLOBAL:
9378 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9379 ret = NULL;
9380 break;
9381 case SREQ_BUF:
9382 if (!(ret->indir & PV_BUF))
9383 ret = NULL;
9384 break;
9385 case SREQ_WIN:
9386 if (!(ret->indir & PV_WIN))
9387 ret = NULL;
9388 break;
9389 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009390 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009391 return NULL;
9392 }
9393 }
9394 while (ret == NULL);
9395
9396 return (char_u *)ret->fullname;
9397}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009398#endif
9399
Bram Moolenaar071d4272004-06-13 20:20:40 +00009400/*
9401 * Set the value of option "name".
9402 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009403 *
9404 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009405 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009406 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009407set_option_value(
9408 char_u *name,
9409 long number,
9410 char_u *string,
9411 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009412{
9413 int opt_idx;
9414 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009415 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416
9417 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009418 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009419 EMSG2(_("E355: Unknown option: %s"), name);
9420 else
9421 {
9422 flags = options[opt_idx].flags;
9423#ifdef HAVE_SANDBOX
9424 /* Disallow changing some options in the sandbox */
9425 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009426 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009427 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009428 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009429 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009430#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009431 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009432 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 else
9434 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009435 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009436 if (varp != NULL) /* hidden option is not changed */
9437 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009438 if (number == 0 && string != NULL)
9439 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009440 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009441
9442 /* Either we are given a string or we are setting option
9443 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009444 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009445 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009446 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009447 {
9448 /* There's another character after zeros or the string
9449 * is empty. In both cases, we are trying to set a
9450 * num option using a string. */
9451 EMSG3(_("E521: Number required: &%s = '%s'"),
9452 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009453 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009454
9455 }
9456 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009457 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009458 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009459 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009460 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009461 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009462 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009463 }
9464 }
9465 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009466 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009467}
9468
9469/*
9470 * Get the terminal code for a terminal option.
9471 * Returns NULL when not found.
9472 */
9473 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009474get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475{
9476 int opt_idx;
9477 char_u *varp;
9478
9479 if (tname[0] != 't' || tname[1] != '_' ||
9480 tname[2] == NUL || tname[3] == NUL)
9481 return NULL;
9482 if ((opt_idx = findoption(tname)) >= 0)
9483 {
9484 varp = get_varp(&(options[opt_idx]));
9485 if (varp != NULL)
9486 varp = *(char_u **)(varp);
9487 return varp;
9488 }
9489 return find_termcode(tname + 2);
9490}
9491
9492 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009493get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009494{
9495 int i;
9496
9497 i = findoption((char_u *)"hl");
9498 if (i >= 0)
9499 return options[i].def_val[VI_DEFAULT];
9500 return (char_u *)NULL;
9501}
9502
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009503#if defined(FEAT_MBYTE) || defined(PROTO)
9504 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009505get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009506{
9507 int i;
9508
9509 i = findoption((char_u *)"enc");
9510 if (i >= 0)
9511 return options[i].def_val[VI_DEFAULT];
9512 return (char_u *)NULL;
9513}
9514#endif
9515
Bram Moolenaar071d4272004-06-13 20:20:40 +00009516/*
9517 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9518 */
9519 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009520find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009521{
9522 int key;
9523 int modifiers;
9524
9525 /*
9526 * Don't use get_special_key_code() for t_xx, we don't want it to call
9527 * add_termcap_entry().
9528 */
9529 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9530 key = TERMCAP2KEY(arg[2], arg[3]);
9531 else
9532 {
9533 --arg; /* put arg at the '<' */
9534 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009535 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009536 if (modifiers) /* can't handle modifiers here */
9537 key = 0;
9538 }
9539 return key;
9540}
9541
9542/*
9543 * if 'all' == 0: show changed options
9544 * if 'all' == 1: show all normal options
9545 * if 'all' == 2: show all terminal options
9546 */
9547 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009548showoptions(
9549 int all,
9550 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551{
9552 struct vimoption *p;
9553 int col;
9554 int isterm;
9555 char_u *varp;
9556 struct vimoption **items;
9557 int item_count;
9558 int run;
9559 int row, rows;
9560 int cols;
9561 int i;
9562 int len;
9563
9564#define INC 20
9565#define GAP 3
9566
9567 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9568 PARAM_COUNT));
9569 if (items == NULL)
9570 return;
9571
9572 /* Highlight title */
9573 if (all == 2)
9574 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9575 else if (opt_flags & OPT_GLOBAL)
9576 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9577 else if (opt_flags & OPT_LOCAL)
9578 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9579 else
9580 MSG_PUTS_TITLE(_("\n--- Options ---"));
9581
9582 /*
9583 * do the loop two times:
9584 * 1. display the short items
9585 * 2. display the long items (only strings and numbers)
9586 */
9587 for (run = 1; run <= 2 && !got_int; ++run)
9588 {
9589 /*
9590 * collect the items in items[]
9591 */
9592 item_count = 0;
9593 for (p = &options[0]; p->fullname != NULL; p++)
9594 {
9595 varp = NULL;
9596 isterm = istermoption(p);
9597 if (opt_flags != 0)
9598 {
9599 if (p->indir != PV_NONE && !isterm)
9600 varp = get_varp_scope(p, opt_flags);
9601 }
9602 else
9603 varp = get_varp(p);
9604 if (varp != NULL
9605 && ((all == 2 && isterm)
9606 || (all == 1 && !isterm)
9607 || (all == 0 && !optval_default(p, varp))))
9608 {
9609 if (p->flags & P_BOOL)
9610 len = 1; /* a toggle option fits always */
9611 else
9612 {
9613 option_value2string(p, opt_flags);
9614 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9615 }
9616 if ((len <= INC - GAP && run == 1) ||
9617 (len > INC - GAP && run == 2))
9618 items[item_count++] = p;
9619 }
9620 }
9621
9622 /*
9623 * display the items
9624 */
9625 if (run == 1)
9626 {
9627 cols = (Columns + GAP - 3) / INC;
9628 if (cols == 0)
9629 cols = 1;
9630 rows = (item_count + cols - 1) / cols;
9631 }
9632 else /* run == 2 */
9633 rows = item_count;
9634 for (row = 0; row < rows && !got_int; ++row)
9635 {
9636 msg_putchar('\n'); /* go to next line */
9637 if (got_int) /* 'q' typed in more */
9638 break;
9639 col = 0;
9640 for (i = row; i < item_count; i += rows)
9641 {
9642 msg_col = col; /* make columns */
9643 showoneopt(items[i], opt_flags);
9644 col += INC;
9645 }
9646 out_flush();
9647 ui_breakcheck();
9648 }
9649 }
9650 vim_free(items);
9651}
9652
9653/*
9654 * Return TRUE if option "p" has its default value.
9655 */
9656 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009657optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009658{
9659 int dvi;
9660
9661 if (varp == NULL)
9662 return TRUE; /* hidden option is always at default */
9663 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9664 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009665 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009666 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009667 /* the cast to long is required for Manx C, long_i is
9668 * needed for MSVC */
9669 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009670 /* P_STRING */
9671 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9672}
9673
9674/*
9675 * showoneopt: show the value of one option
9676 * must not be called with a hidden option!
9677 */
9678 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009679showoneopt(
9680 struct vimoption *p,
9681 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009682{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009683 char_u *varp;
9684 int save_silent = silent_mode;
9685
9686 silent_mode = FALSE;
9687 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009688
9689 varp = get_varp_scope(p, opt_flags);
9690
9691 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9692 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9693 ? !curbufIsChanged() : !*(int *)varp))
9694 MSG_PUTS("no");
9695 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9696 MSG_PUTS("--");
9697 else
9698 MSG_PUTS(" ");
9699 MSG_PUTS(p->fullname);
9700 if (!(p->flags & P_BOOL))
9701 {
9702 msg_putchar('=');
9703 /* put value string in NameBuff */
9704 option_value2string(p, opt_flags);
9705 msg_outtrans(NameBuff);
9706 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009707
9708 silent_mode = save_silent;
9709 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009710}
9711
9712/*
9713 * Write modified options as ":set" commands to a file.
9714 *
9715 * There are three values for "opt_flags":
9716 * OPT_GLOBAL: Write global option values and fresh values of
9717 * buffer-local options (used for start of a session
9718 * file).
9719 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9720 * curwin (used for a vimrc file).
9721 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9722 * and local values for window-local options of
9723 * curwin. Local values are also written when at the
9724 * default value, because a modeline or autocommand
9725 * may have set them when doing ":edit file" and the
9726 * user has set them back at the default or fresh
9727 * value.
9728 * When "local_only" is TRUE, don't write fresh
9729 * values, only local values (for ":mkview").
9730 * (fresh value = value used for a new buffer or window for a local option).
9731 *
9732 * Return FAIL on error, OK otherwise.
9733 */
9734 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009735makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009736{
9737 struct vimoption *p;
9738 char_u *varp; /* currently used value */
9739 char_u *varp_fresh; /* local value */
9740 char_u *varp_local = NULL; /* fresh value */
9741 char *cmd;
9742 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009743 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009744
9745 /*
9746 * The options that don't have a default (terminal name, columns, lines)
9747 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009748 * Do the loop over "options[]" twice: once for options with the
9749 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009750 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009751 for (pri = 1; pri >= 0; --pri)
9752 {
9753 for (p = &options[0]; !istermoption(p); p++)
9754 if (!(p->flags & P_NO_MKRC)
9755 && !istermoption(p)
9756 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009757 {
9758 /* skip global option when only doing locals */
9759 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9760 continue;
9761
9762 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9763 * file, they are always buffer-specific. */
9764 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9765 continue;
9766
9767 /* Global values are only written when not at the default value. */
9768 varp = get_varp_scope(p, opt_flags);
9769 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9770 continue;
9771
9772 round = 2;
9773 if (p->indir != PV_NONE)
9774 {
9775 if (p->var == VAR_WIN)
9776 {
9777 /* skip window-local option when only doing globals */
9778 if (!(opt_flags & OPT_LOCAL))
9779 continue;
9780 /* When fresh value of window-local option is not at the
9781 * default, need to write it too. */
9782 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9783 {
9784 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9785 if (!optval_default(p, varp_fresh))
9786 {
9787 round = 1;
9788 varp_local = varp;
9789 varp = varp_fresh;
9790 }
9791 }
9792 }
9793 }
9794
9795 /* Round 1: fresh value for window-local options.
9796 * Round 2: other values */
9797 for ( ; round <= 2; varp = varp_local, ++round)
9798 {
9799 if (round == 1 || (opt_flags & OPT_GLOBAL))
9800 cmd = "set";
9801 else
9802 cmd = "setlocal";
9803
9804 if (p->flags & P_BOOL)
9805 {
9806 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9807 return FAIL;
9808 }
9809 else if (p->flags & P_NUM)
9810 {
9811 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9812 return FAIL;
9813 }
9814 else /* P_STRING */
9815 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009816#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9817 int do_endif = FALSE;
9818
Bram Moolenaar071d4272004-06-13 20:20:40 +00009819 /* Don't set 'syntax' and 'filetype' again if the value is
9820 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009821 if (
9822# if defined(FEAT_SYN_HL)
9823 p->indir == PV_SYN
9824# if defined(FEAT_AUTOCMD)
9825 ||
9826# endif
9827# endif
9828# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009829 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009830# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009831 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832 {
9833 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9834 *(char_u **)(varp)) < 0
9835 || put_eol(fd) < 0)
9836 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009837 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009838 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009839#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009840 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9841 (p->flags & P_EXPAND) != 0) == FAIL)
9842 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009843#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9844 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009845 {
9846 if (put_line(fd, "endif") == FAIL)
9847 return FAIL;
9848 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009849#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009850 }
9851 }
9852 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009853 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009854 return OK;
9855}
9856
9857#if defined(FEAT_FOLDING) || defined(PROTO)
9858/*
9859 * Generate set commands for the local fold options only. Used when
9860 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9861 */
9862 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009863makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009864{
9865 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9866# ifdef FEAT_EVAL
9867 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9868 == FAIL
9869# endif
9870 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9871 == FAIL
9872 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9873 == FAIL
9874 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9875 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9876 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9877 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9878 )
9879 return FAIL;
9880
9881 return OK;
9882}
9883#endif
9884
9885 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009886put_setstring(
9887 FILE *fd,
9888 char *cmd,
9889 char *name,
9890 char_u **valuep,
9891 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009892{
9893 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009894 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009895
9896 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9897 return FAIL;
9898 if (*valuep != NULL)
9899 {
9900 /* Output 'pastetoggle' as key names. For other
9901 * options some characters have to be escaped with
9902 * CTRL-V or backslash */
9903 if (valuep == &p_pt)
9904 {
9905 s = *valuep;
9906 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009907 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009908 return FAIL;
9909 }
9910 else if (expand)
9911 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009912 buf = alloc(MAXPATHL);
9913 if (buf == NULL)
9914 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9916 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009917 {
9918 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009919 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009920 }
9921 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009922 }
9923 else if (put_escstr(fd, *valuep, 2) == FAIL)
9924 return FAIL;
9925 }
9926 if (put_eol(fd) < 0)
9927 return FAIL;
9928 return OK;
9929}
9930
9931 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009932put_setnum(
9933 FILE *fd,
9934 char *cmd,
9935 char *name,
9936 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009937{
9938 long wc;
9939
9940 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9941 return FAIL;
9942 if (wc_use_keyname((char_u *)valuep, &wc))
9943 {
9944 /* print 'wildchar' and 'wildcharm' as a key name */
9945 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9946 return FAIL;
9947 }
9948 else if (fprintf(fd, "%ld", *valuep) < 0)
9949 return FAIL;
9950 if (put_eol(fd) < 0)
9951 return FAIL;
9952 return OK;
9953}
9954
9955 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009956put_setbool(
9957 FILE *fd,
9958 char *cmd,
9959 char *name,
9960 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961{
Bram Moolenaar893de922007-10-02 18:40:57 +00009962 if (value < 0) /* global/local option using global value */
9963 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009964 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9965 || put_eol(fd) < 0)
9966 return FAIL;
9967 return OK;
9968}
9969
9970/*
9971 * Clear all the terminal options.
9972 * If the option has been allocated, free the memory.
9973 * Terminal options are never hidden or indirect.
9974 */
9975 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009976clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009977{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978 /*
9979 * Reset a few things before clearing the old options. This may cause
9980 * outputting a few things that the terminal doesn't understand, but the
9981 * screen will be cleared later, so this is OK.
9982 */
9983#ifdef FEAT_MOUSE_TTY
9984 mch_setmouse(FALSE); /* switch mouse off */
9985#endif
9986#ifdef FEAT_TITLE
9987 mch_restore_title(3); /* restore window titles */
9988#endif
9989#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9990 /* When starting the GUI close the display opened for the clipboard.
9991 * After restoring the title, because that will need the display. */
9992 if (gui.starting)
9993 clear_xterm_clip();
9994#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +02009995 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009997 free_termoptions();
9998}
9999
10000 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010001free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010002{
10003 struct vimoption *p;
10004
Bram Moolenaar071d4272004-06-13 20:20:40 +000010005 for (p = &options[0]; p->fullname != NULL; p++)
10006 if (istermoption(p))
10007 {
10008 if (p->flags & P_ALLOCED)
10009 free_string_option(*(char_u **)(p->var));
10010 if (p->flags & P_DEF_ALLOCED)
10011 free_string_option(p->def_val[VI_DEFAULT]);
10012 *(char_u **)(p->var) = empty_option;
10013 p->def_val[VI_DEFAULT] = empty_option;
10014 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10015 }
10016 clear_termcodes();
10017}
10018
10019/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010020 * Free the string for one term option, if it was allocated.
10021 * Set the string to empty_option and clear allocated flag.
10022 * "var" points to the option value.
10023 */
10024 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010025free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010026{
10027 struct vimoption *p;
10028
10029 for (p = &options[0]; p->fullname != NULL; p++)
10030 if (p->var == var)
10031 {
10032 if (p->flags & P_ALLOCED)
10033 free_string_option(*(char_u **)(p->var));
10034 *(char_u **)(p->var) = empty_option;
10035 p->flags &= ~P_ALLOCED;
10036 break;
10037 }
10038}
10039
10040/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010041 * Set the terminal option defaults to the current value.
10042 * Used after setting the terminal name.
10043 */
10044 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010045set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046{
10047 struct vimoption *p;
10048
10049 for (p = &options[0]; p->fullname != NULL; p++)
10050 {
10051 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10052 {
10053 if (p->flags & P_DEF_ALLOCED)
10054 {
10055 free_string_option(p->def_val[VI_DEFAULT]);
10056 p->flags &= ~P_DEF_ALLOCED;
10057 }
10058 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10059 if (p->flags & P_ALLOCED)
10060 {
10061 p->flags |= P_DEF_ALLOCED;
10062 p->flags &= ~P_ALLOCED; /* don't free the value now */
10063 }
10064 }
10065 }
10066}
10067
10068/*
10069 * return TRUE if 'p' starts with 't_'
10070 */
10071 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010072istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010073{
10074 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10075}
10076
10077/*
10078 * Compute columns for ruler and shown command. 'sc_col' is also used to
10079 * decide what the maximum length of a message on the status line can be.
10080 * If there is a status line for the last window, 'sc_col' is independent
10081 * of 'ru_col'.
10082 */
10083
10084#define COL_RULER 17 /* columns needed by standard ruler */
10085
10086 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010087comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010088{
10089#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010090 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010091
10092 sc_col = 0;
10093 ru_col = 0;
10094 if (p_ru)
10095 {
10096#ifdef FEAT_STL_OPT
10097 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10098#else
10099 ru_col = COL_RULER + 1;
10100#endif
10101 /* no last status line, adjust sc_col */
10102 if (!last_has_status)
10103 sc_col = ru_col;
10104 }
10105 if (p_sc)
10106 {
10107 sc_col += SHOWCMD_COLS;
10108 if (!p_ru || last_has_status) /* no need for separating space */
10109 ++sc_col;
10110 }
10111 sc_col = Columns - sc_col;
10112 ru_col = Columns - ru_col;
10113 if (sc_col <= 0) /* screen too narrow, will become a mess */
10114 sc_col = 1;
10115 if (ru_col <= 0)
10116 ru_col = 1;
10117#else
10118 sc_col = Columns;
10119 ru_col = Columns;
10120#endif
10121}
10122
10123/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010124 * Unset local option value, similar to ":set opt<".
10125 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010126 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010127unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010128{
10129 struct vimoption *p;
10130 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010131 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010132
10133 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010134 if (opt_idx < 0)
10135 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010136 p = &(options[opt_idx]);
10137
10138 switch ((int)p->indir)
10139 {
10140 /* global option with local value: use local value if it's been set */
10141 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010142 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010143 break;
10144 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010145 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010146 break;
10147 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010148 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010149 break;
10150 case PV_AR:
10151 buf->b_p_ar = -1;
10152 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010153 case PV_BKC:
10154 clear_string_option(&buf->b_p_bkc);
10155 buf->b_bkc_flags = 0;
10156 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010157 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010158 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010159 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010160 case PV_TC:
10161 clear_string_option(&buf->b_p_tc);
10162 buf->b_tc_flags = 0;
10163 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010164#ifdef FEAT_FIND_ID
10165 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010166 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010167 break;
10168 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010169 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010170 break;
10171#endif
10172#ifdef FEAT_INS_EXPAND
10173 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010174 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010175 break;
10176 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010177 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010178 break;
10179#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010180 case PV_FP:
10181 clear_string_option(&buf->b_p_fp);
10182 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010183#ifdef FEAT_QUICKFIX
10184 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010185 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010186 break;
10187 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010188 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010189 break;
10190 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010191 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010192 break;
10193#endif
10194#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10195 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010196 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010197 break;
10198#endif
10199#if defined(FEAT_CRYPT)
10200 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010201 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010202 break;
10203#endif
10204#ifdef FEAT_STL_OPT
10205 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010206 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010207 break;
10208#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010209 case PV_UL:
10210 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10211 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010212#ifdef FEAT_LISP
10213 case PV_LW:
10214 clear_string_option(&buf->b_p_lw);
10215 break;
10216#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010217 }
10218}
10219
10220/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221 * Get pointer to option variable, depending on local or global scope.
10222 */
10223 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010224get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010225{
10226 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10227 {
10228 if (p->var == VAR_WIN)
10229 return (char_u *)GLOBAL_WO(get_varp(p));
10230 return p->var;
10231 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010232 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010233 {
10234 switch ((int)p->indir)
10235 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010236 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010237#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010238 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10239 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10240 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010242 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10243 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10244 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010245 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010246 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010247 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010249 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10250 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010251#endif
10252#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010253 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10254 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010256#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10257 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10258#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010259#if defined(FEAT_CRYPT)
10260 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10261#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010262#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010263 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010264#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010265 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010266#ifdef FEAT_LISP
10267 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10268#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010269 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010270 }
10271 return NULL; /* "cannot happen" */
10272 }
10273 return get_varp(p);
10274}
10275
10276/*
10277 * Get pointer to option variable.
10278 */
10279 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010280get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281{
10282 /* hidden option, always return NULL */
10283 if (p->var == NULL)
10284 return NULL;
10285
10286 switch ((int)p->indir)
10287 {
10288 case PV_NONE: return p->var;
10289
10290 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010291 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010293 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010295 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010296 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010297 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010298 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010299 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010301 case PV_TC: return *curbuf->b_p_tc != NUL
10302 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010303 case PV_BKC: return *curbuf->b_p_bkc != NUL
10304 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010306 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010308 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10310#endif
10311#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010312 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010313 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010314 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10316#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010317 case PV_FP: return *curbuf->b_p_fp != NUL
10318 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010320 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010322 case PV_GP: return *curbuf->b_p_gp != NUL
10323 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10324 case PV_MP: return *curbuf->b_p_mp != NUL
10325 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010327#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10328 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10329 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10330#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010331#if defined(FEAT_CRYPT)
10332 case PV_CM: return *curbuf->b_p_cm != NUL
10333 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10334#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010335#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010336 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010337 ? (char_u *)&(curwin->w_p_stl) : p->var;
10338#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010339 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10340 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010341#ifdef FEAT_LISP
10342 case PV_LW: return *curbuf->b_p_lw != NUL
10343 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345
10346#ifdef FEAT_ARABIC
10347 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10348#endif
10349 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010350#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010351 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10352#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010353#ifdef FEAT_SYN_HL
10354 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10355 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010356 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358#ifdef FEAT_DIFF
10359 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10360#endif
10361#ifdef FEAT_FOLDING
10362 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10363 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10364 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10365 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10366 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10367 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10368 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10369# ifdef FEAT_EVAL
10370 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10371 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10372# endif
10373 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10374#endif
10375 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010376 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010377#ifdef FEAT_LINEBREAK
10378 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10379#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010380#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010381 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010382 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10385 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10386#endif
10387#ifdef FEAT_RIGHTLEFT
10388 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10389 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10390#endif
10391 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10392 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10393#ifdef FEAT_LINEBREAK
10394 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010395 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10396 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010397#endif
10398#ifdef FEAT_SCROLLBIND
10399 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10400#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010401#ifdef FEAT_CURSORBIND
10402 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10403#endif
10404#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010405 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10406 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010407#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408
10409 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10410 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10411#ifdef FEAT_MBYTE
10412 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10413#endif
10414#if defined(FEAT_QUICKFIX)
10415 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10416 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10417#endif
10418 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10419 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10420#ifdef FEAT_CINDENT
10421 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10422 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10423 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10424#endif
10425#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10426 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10427#endif
10428#ifdef FEAT_COMMENTS
10429 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10430#endif
10431#ifdef FEAT_FOLDING
10432 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10433#endif
10434#ifdef FEAT_INS_EXPAND
10435 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10436#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010437#ifdef FEAT_COMPL_FUNC
10438 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010439 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010441 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010442 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010443 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10444#ifdef FEAT_MBYTE
10445 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10446#endif
10447 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10448#ifdef FEAT_AUTOCMD
10449 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10450#endif
10451 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010452 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010453 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10454 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10455 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10456 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10457#ifdef FEAT_FIND_ID
10458# ifdef FEAT_EVAL
10459 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10460# endif
10461#endif
10462#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10463 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10464 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10465#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010466#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010467 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10468#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010469#ifdef FEAT_CRYPT
10470 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10471#endif
10472#ifdef FEAT_LISP
10473 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10474#endif
10475 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10476 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10477 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10478 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10479 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010480 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010481#ifdef FEAT_TEXTOBJ
10482 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10485#ifdef FEAT_SMARTINDENT
10486 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10487#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010488 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010489 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10490#ifdef FEAT_SEARCHPATH
10491 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10492#endif
10493 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10494#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010495 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010496 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10497#endif
10498#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010499 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10500 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10501 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502#endif
10503 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10504 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10505 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10506 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010507#ifdef FEAT_PERSISTENT_UNDO
10508 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10511#ifdef FEAT_KEYMAP
10512 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10513#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010514#ifdef FEAT_SIGNS
10515 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10516#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010517 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010518 }
10519 /* always return a valid pointer to avoid a crash! */
10520 return (char_u *)&(curbuf->b_p_wm);
10521}
10522
10523/*
10524 * Get the value of 'equalprg', either the buffer-local one or the global one.
10525 */
10526 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010527get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528{
10529 if (*curbuf->b_p_ep == NUL)
10530 return p_ep;
10531 return curbuf->b_p_ep;
10532}
10533
10534#if defined(FEAT_WINDOWS) || defined(PROTO)
10535/*
10536 * Copy options from one window to another.
10537 * Used when splitting a window.
10538 */
10539 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010540win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541{
10542 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10543 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10544# ifdef FEAT_RIGHTLEFT
10545# ifdef FEAT_FKMAP
10546 /* Is this right? */
10547 wp_to->w_farsi = wp_from->w_farsi;
10548# endif
10549# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010550#if defined(FEAT_LINEBREAK)
10551 briopt_check(wp_to);
10552#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553}
10554#endif
10555
10556/*
10557 * Copy the options from one winopt_T to another.
10558 * Doesn't free the old option values in "to", use clear_winopt() for that.
10559 * The 'scroll' option is not copied, because it depends on the window height.
10560 * The 'previewwindow' option is reset, there can be only one preview window.
10561 */
10562 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010563copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564{
10565#ifdef FEAT_ARABIC
10566 to->wo_arab = from->wo_arab;
10567#endif
10568 to->wo_list = from->wo_list;
10569 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010570 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010571#ifdef FEAT_LINEBREAK
10572 to->wo_nuw = from->wo_nuw;
10573#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574#ifdef FEAT_RIGHTLEFT
10575 to->wo_rl = from->wo_rl;
10576 to->wo_rlc = vim_strsave(from->wo_rlc);
10577#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010578#ifdef FEAT_STL_OPT
10579 to->wo_stl = vim_strsave(from->wo_stl);
10580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010582#ifdef FEAT_DIFF
10583 to->wo_wrap_save = from->wo_wrap_save;
10584#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585#ifdef FEAT_LINEBREAK
10586 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010587 to->wo_bri = from->wo_bri;
10588 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589#endif
10590#ifdef FEAT_SCROLLBIND
10591 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010592 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010594#ifdef FEAT_CURSORBIND
10595 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010596 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010597#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010598#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010599 to->wo_spell = from->wo_spell;
10600#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010601#ifdef FEAT_SYN_HL
10602 to->wo_cuc = from->wo_cuc;
10603 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010604 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010605#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606#ifdef FEAT_DIFF
10607 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010608 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010609#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010610#ifdef FEAT_CONCEAL
10611 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010612 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010613#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010614#ifdef FEAT_FOLDING
10615 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010616 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010618 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619 to->wo_fdi = vim_strsave(from->wo_fdi);
10620 to->wo_fml = from->wo_fml;
10621 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010622 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010623 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010624 to->wo_fdm_save = from->wo_diff_saved
10625 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010626 to->wo_fdn = from->wo_fdn;
10627# ifdef FEAT_EVAL
10628 to->wo_fde = vim_strsave(from->wo_fde);
10629 to->wo_fdt = vim_strsave(from->wo_fdt);
10630# endif
10631 to->wo_fmr = vim_strsave(from->wo_fmr);
10632#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010633#ifdef FEAT_SIGNS
10634 to->wo_scl = vim_strsave(from->wo_scl);
10635#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010636 check_winopt(to); /* don't want NULL pointers */
10637}
10638
10639/*
10640 * Check string options in a window for a NULL value.
10641 */
10642 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010643check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644{
10645 check_winopt(&win->w_onebuf_opt);
10646 check_winopt(&win->w_allbuf_opt);
10647}
10648
10649/*
10650 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10651 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010652 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010653check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010654{
10655#ifdef FEAT_FOLDING
10656 check_string_option(&wop->wo_fdi);
10657 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010658 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010659# ifdef FEAT_EVAL
10660 check_string_option(&wop->wo_fde);
10661 check_string_option(&wop->wo_fdt);
10662# endif
10663 check_string_option(&wop->wo_fmr);
10664#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010665#ifdef FEAT_SIGNS
10666 check_string_option(&wop->wo_scl);
10667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010668#ifdef FEAT_RIGHTLEFT
10669 check_string_option(&wop->wo_rlc);
10670#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010671#ifdef FEAT_STL_OPT
10672 check_string_option(&wop->wo_stl);
10673#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010674#ifdef FEAT_SYN_HL
10675 check_string_option(&wop->wo_cc);
10676#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010677#ifdef FEAT_CONCEAL
10678 check_string_option(&wop->wo_cocu);
10679#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010680#ifdef FEAT_LINEBREAK
10681 check_string_option(&wop->wo_briopt);
10682#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010683}
10684
10685/*
10686 * Free the allocated memory inside a winopt_T.
10687 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010689clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010690{
10691#ifdef FEAT_FOLDING
10692 clear_string_option(&wop->wo_fdi);
10693 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010694 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010695# ifdef FEAT_EVAL
10696 clear_string_option(&wop->wo_fde);
10697 clear_string_option(&wop->wo_fdt);
10698# endif
10699 clear_string_option(&wop->wo_fmr);
10700#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010701#ifdef FEAT_SIGNS
10702 clear_string_option(&wop->wo_scl);
10703#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010704#ifdef FEAT_LINEBREAK
10705 clear_string_option(&wop->wo_briopt);
10706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707#ifdef FEAT_RIGHTLEFT
10708 clear_string_option(&wop->wo_rlc);
10709#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010710#ifdef FEAT_STL_OPT
10711 clear_string_option(&wop->wo_stl);
10712#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010713#ifdef FEAT_SYN_HL
10714 clear_string_option(&wop->wo_cc);
10715#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010716#ifdef FEAT_CONCEAL
10717 clear_string_option(&wop->wo_cocu);
10718#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719}
10720
10721/*
10722 * Copy global option values to local options for one buffer.
10723 * Used when creating a new buffer and sometimes when entering a buffer.
10724 * flags:
10725 * BCO_ENTER We will enter the buf buffer.
10726 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10727 * appropriate.
10728 * BCO_NOHELP Don't copy the values to a help buffer.
10729 */
10730 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010731buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732{
10733 int should_copy = TRUE;
10734 char_u *save_p_isk = NULL; /* init for GCC */
10735 int dont_do_help;
10736 int did_isk = FALSE;
10737
10738 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739 * Skip this when the option defaults have not been set yet. Happens when
10740 * main() allocates the first buffer.
10741 */
10742 if (p_cpo != NULL)
10743 {
10744 /*
10745 * Always copy when entering and 'cpo' contains 'S'.
10746 * Don't copy when already initialized.
10747 * Don't copy when 'cpo' contains 's' and not entering.
10748 * 'S' BCO_ENTER initialized 's' should_copy
10749 * yes yes X X TRUE
10750 * yes no yes X FALSE
10751 * no X yes X FALSE
10752 * X no no yes FALSE
10753 * X no no no TRUE
10754 * no yes no X TRUE
10755 */
10756 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10757 && (buf->b_p_initialized
10758 || (!(flags & BCO_ENTER)
10759 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10760 should_copy = FALSE;
10761
10762 if (should_copy || (flags & BCO_ALWAYS))
10763 {
10764 /* Don't copy the options specific to a help buffer when
10765 * BCO_NOHELP is given or the options were initialized already
10766 * (jumping back to a help file with CTRL-T or CTRL-O) */
10767 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10768 || buf->b_p_initialized;
10769 if (dont_do_help) /* don't free b_p_isk */
10770 {
10771 save_p_isk = buf->b_p_isk;
10772 buf->b_p_isk = NULL;
10773 }
10774 /*
10775 * Always free the allocated strings.
10776 * If not already initialized, set 'readonly' and copy 'fileformat'.
10777 */
10778 if (!buf->b_p_initialized)
10779 {
10780 free_buf_options(buf, TRUE);
10781 buf->b_p_ro = FALSE; /* don't copy readonly */
10782 buf->b_p_tx = p_tx;
10783#ifdef FEAT_MBYTE
10784 buf->b_p_fenc = vim_strsave(p_fenc);
10785#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020010786 switch (*p_ffs)
10787 {
10788 case 'm':
10789 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
10790 case 'd':
10791 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
10792 case 'u':
10793 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
10794 default:
10795 buf->b_p_ff = vim_strsave(p_ff);
10796 }
10797 if (buf->b_p_ff != NULL)
10798 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010799#if defined(FEAT_QUICKFIX)
10800 buf->b_p_bh = empty_option;
10801 buf->b_p_bt = empty_option;
10802#endif
10803 }
10804 else
10805 free_buf_options(buf, FALSE);
10806
10807 buf->b_p_ai = p_ai;
10808 buf->b_p_ai_nopaste = p_ai_nopaste;
10809 buf->b_p_sw = p_sw;
10810 buf->b_p_tw = p_tw;
10811 buf->b_p_tw_nopaste = p_tw_nopaste;
10812 buf->b_p_tw_nobin = p_tw_nobin;
10813 buf->b_p_wm = p_wm;
10814 buf->b_p_wm_nopaste = p_wm_nopaste;
10815 buf->b_p_wm_nobin = p_wm_nobin;
10816 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010817#ifdef FEAT_MBYTE
10818 buf->b_p_bomb = p_bomb;
10819#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010820 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821 buf->b_p_et = p_et;
10822 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010823 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010824 buf->b_p_ml = p_ml;
10825 buf->b_p_ml_nobin = p_ml_nobin;
10826 buf->b_p_inf = p_inf;
10827 buf->b_p_swf = p_swf;
10828#ifdef FEAT_INS_EXPAND
10829 buf->b_p_cpt = vim_strsave(p_cpt);
10830#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010831#ifdef FEAT_COMPL_FUNC
10832 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010833 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010834#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835 buf->b_p_sts = p_sts;
10836 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838#ifdef FEAT_COMMENTS
10839 buf->b_p_com = vim_strsave(p_com);
10840#endif
10841#ifdef FEAT_FOLDING
10842 buf->b_p_cms = vim_strsave(p_cms);
10843#endif
10844 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010845 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846 buf->b_p_nf = vim_strsave(p_nf);
10847 buf->b_p_mps = vim_strsave(p_mps);
10848#ifdef FEAT_SMARTINDENT
10849 buf->b_p_si = p_si;
10850#endif
10851 buf->b_p_ci = p_ci;
10852#ifdef FEAT_CINDENT
10853 buf->b_p_cin = p_cin;
10854 buf->b_p_cink = vim_strsave(p_cink);
10855 buf->b_p_cino = vim_strsave(p_cino);
10856#endif
10857#ifdef FEAT_AUTOCMD
10858 /* Don't copy 'filetype', it must be detected */
10859 buf->b_p_ft = empty_option;
10860#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010861 buf->b_p_pi = p_pi;
10862#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10863 buf->b_p_cinw = vim_strsave(p_cinw);
10864#endif
10865#ifdef FEAT_LISP
10866 buf->b_p_lisp = p_lisp;
10867#endif
10868#ifdef FEAT_SYN_HL
10869 /* Don't copy 'syntax', it must be set */
10870 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010871 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010872 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010873#endif
10874#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010875 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010876 (void)compile_cap_prog(&buf->b_s);
10877 buf->b_s.b_p_spf = vim_strsave(p_spf);
10878 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879#endif
10880#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10881 buf->b_p_inde = vim_strsave(p_inde);
10882 buf->b_p_indk = vim_strsave(p_indk);
10883#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010884 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010885#if defined(FEAT_EVAL)
10886 buf->b_p_fex = vim_strsave(p_fex);
10887#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010888#ifdef FEAT_CRYPT
10889 buf->b_p_key = vim_strsave(p_key);
10890#endif
10891#ifdef FEAT_SEARCHPATH
10892 buf->b_p_sua = vim_strsave(p_sua);
10893#endif
10894#ifdef FEAT_KEYMAP
10895 buf->b_p_keymap = vim_strsave(p_keymap);
10896 buf->b_kmap_state |= KEYMAP_INIT;
10897#endif
10898 /* This isn't really an option, but copying the langmap and IME
10899 * state from the current buffer is better than resetting it. */
10900 buf->b_p_iminsert = p_iminsert;
10901 buf->b_p_imsearch = p_imsearch;
10902
10903 /* options that are normally global but also have a local value
10904 * are not copied, start using the global value */
10905 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010906 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010907 buf->b_p_bkc = empty_option;
10908 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909#ifdef FEAT_QUICKFIX
10910 buf->b_p_gp = empty_option;
10911 buf->b_p_mp = empty_option;
10912 buf->b_p_efm = empty_option;
10913#endif
10914 buf->b_p_ep = empty_option;
10915 buf->b_p_kp = empty_option;
10916 buf->b_p_path = empty_option;
10917 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010918 buf->b_p_tc = empty_option;
10919 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920#ifdef FEAT_FIND_ID
10921 buf->b_p_def = empty_option;
10922 buf->b_p_inc = empty_option;
10923# ifdef FEAT_EVAL
10924 buf->b_p_inex = vim_strsave(p_inex);
10925# endif
10926#endif
10927#ifdef FEAT_INS_EXPAND
10928 buf->b_p_dict = empty_option;
10929 buf->b_p_tsr = empty_option;
10930#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010931#ifdef FEAT_TEXTOBJ
10932 buf->b_p_qe = vim_strsave(p_qe);
10933#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010934#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10935 buf->b_p_bexpr = empty_option;
10936#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010937#if defined(FEAT_CRYPT)
10938 buf->b_p_cm = empty_option;
10939#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010940#ifdef FEAT_PERSISTENT_UNDO
10941 buf->b_p_udf = p_udf;
10942#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010943#ifdef FEAT_LISP
10944 buf->b_p_lw = empty_option;
10945#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010946
10947 /*
10948 * Don't copy the options set by ex_help(), use the saved values,
10949 * when going from a help buffer to a non-help buffer.
10950 * Don't touch these at all when BCO_NOHELP is used and going from
10951 * or to a help buffer.
10952 */
10953 if (dont_do_help)
10954 buf->b_p_isk = save_p_isk;
10955 else
10956 {
10957 buf->b_p_isk = vim_strsave(p_isk);
10958 did_isk = TRUE;
10959 buf->b_p_ts = p_ts;
10960 buf->b_help = FALSE;
10961#ifdef FEAT_QUICKFIX
10962 if (buf->b_p_bt[0] == 'h')
10963 clear_string_option(&buf->b_p_bt);
10964#endif
10965 buf->b_p_ma = p_ma;
10966 }
10967 }
10968
10969 /*
10970 * When the options should be copied (ignoring BCO_ALWAYS), set the
10971 * flag that indicates that the options have been initialized.
10972 */
10973 if (should_copy)
10974 buf->b_p_initialized = TRUE;
10975 }
10976
10977 check_buf_options(buf); /* make sure we don't have NULLs */
10978 if (did_isk)
10979 (void)buf_init_chartab(buf, FALSE);
10980}
10981
10982/*
10983 * Reset the 'modifiable' option and its default value.
10984 */
10985 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010986reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010987{
10988 int opt_idx;
10989
10990 curbuf->b_p_ma = FALSE;
10991 p_ma = FALSE;
10992 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010993 if (opt_idx >= 0)
10994 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010995}
10996
10997/*
10998 * Set the global value for 'iminsert' to the local value.
10999 */
11000 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011001set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011002{
11003 p_iminsert = curbuf->b_p_iminsert;
11004}
11005
11006/*
11007 * Set the global value for 'imsearch' to the local value.
11008 */
11009 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011010set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011011{
11012 p_imsearch = curbuf->b_p_imsearch;
11013}
11014
11015#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11016static int expand_option_idx = -1;
11017static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11018static int expand_option_flags = 0;
11019
11020 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011021set_context_in_set_cmd(
11022 expand_T *xp,
11023 char_u *arg,
11024 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025{
11026 int nextchar;
11027 long_u flags = 0; /* init for GCC */
11028 int opt_idx = 0; /* init for GCC */
11029 char_u *p;
11030 char_u *s;
11031 int is_term_option = FALSE;
11032 int key;
11033
11034 expand_option_flags = opt_flags;
11035
11036 xp->xp_context = EXPAND_SETTINGS;
11037 if (*arg == NUL)
11038 {
11039 xp->xp_pattern = arg;
11040 return;
11041 }
11042 p = arg + STRLEN(arg) - 1;
11043 if (*p == ' ' && *(p - 1) != '\\')
11044 {
11045 xp->xp_pattern = p + 1;
11046 return;
11047 }
11048 while (p > arg)
11049 {
11050 s = p;
11051 /* count number of backslashes before ' ' or ',' */
11052 if (*p == ' ' || *p == ',')
11053 {
11054 while (s > arg && *(s - 1) == '\\')
11055 --s;
11056 }
11057 /* break at a space with an even number of backslashes */
11058 if (*p == ' ' && ((p - s) & 1) == 0)
11059 {
11060 ++p;
11061 break;
11062 }
11063 --p;
11064 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011065 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011066 {
11067 xp->xp_context = EXPAND_BOOL_SETTINGS;
11068 p += 2;
11069 }
11070 if (STRNCMP(p, "inv", 3) == 0)
11071 {
11072 xp->xp_context = EXPAND_BOOL_SETTINGS;
11073 p += 3;
11074 }
11075 xp->xp_pattern = arg = p;
11076 if (*arg == '<')
11077 {
11078 while (*p != '>')
11079 if (*p++ == NUL) /* expand terminal option name */
11080 return;
11081 key = get_special_key_code(arg + 1);
11082 if (key == 0) /* unknown name */
11083 {
11084 xp->xp_context = EXPAND_NOTHING;
11085 return;
11086 }
11087 nextchar = *++p;
11088 is_term_option = TRUE;
11089 expand_option_name[2] = KEY2TERMCAP0(key);
11090 expand_option_name[3] = KEY2TERMCAP1(key);
11091 }
11092 else
11093 {
11094 if (p[0] == 't' && p[1] == '_')
11095 {
11096 p += 2;
11097 if (*p != NUL)
11098 ++p;
11099 if (*p == NUL)
11100 return; /* expand option name */
11101 nextchar = *++p;
11102 is_term_option = TRUE;
11103 expand_option_name[2] = p[-2];
11104 expand_option_name[3] = p[-1];
11105 }
11106 else
11107 {
11108 /* Allow * wildcard */
11109 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11110 p++;
11111 if (*p == NUL)
11112 return;
11113 nextchar = *p;
11114 *p = NUL;
11115 opt_idx = findoption(arg);
11116 *p = nextchar;
11117 if (opt_idx == -1 || options[opt_idx].var == NULL)
11118 {
11119 xp->xp_context = EXPAND_NOTHING;
11120 return;
11121 }
11122 flags = options[opt_idx].flags;
11123 if (flags & P_BOOL)
11124 {
11125 xp->xp_context = EXPAND_NOTHING;
11126 return;
11127 }
11128 }
11129 }
11130 /* handle "-=" and "+=" */
11131 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11132 {
11133 ++p;
11134 nextchar = '=';
11135 }
11136 if ((nextchar != '=' && nextchar != ':')
11137 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11138 {
11139 xp->xp_context = EXPAND_UNSUCCESSFUL;
11140 return;
11141 }
11142 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11143 {
11144 xp->xp_context = EXPAND_OLD_SETTING;
11145 if (is_term_option)
11146 expand_option_idx = -1;
11147 else
11148 expand_option_idx = opt_idx;
11149 xp->xp_pattern = p + 1;
11150 return;
11151 }
11152 xp->xp_context = EXPAND_NOTHING;
11153 if (is_term_option || (flags & P_NUM))
11154 return;
11155
11156 xp->xp_pattern = p + 1;
11157
11158 if (flags & P_EXPAND)
11159 {
11160 p = options[opt_idx].var;
11161 if (p == (char_u *)&p_bdir
11162 || p == (char_u *)&p_dir
11163 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011164 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011165 || p == (char_u *)&p_rtp
11166#ifdef FEAT_SEARCHPATH
11167 || p == (char_u *)&p_cdpath
11168#endif
11169#ifdef FEAT_SESSION
11170 || p == (char_u *)&p_vdir
11171#endif
11172 )
11173 {
11174 xp->xp_context = EXPAND_DIRECTORIES;
11175 if (p == (char_u *)&p_path
11176#ifdef FEAT_SEARCHPATH
11177 || p == (char_u *)&p_cdpath
11178#endif
11179 )
11180 xp->xp_backslash = XP_BS_THREE;
11181 else
11182 xp->xp_backslash = XP_BS_ONE;
11183 }
11184 else
11185 {
11186 xp->xp_context = EXPAND_FILES;
11187 /* for 'tags' need three backslashes for a space */
11188 if (p == (char_u *)&p_tags)
11189 xp->xp_backslash = XP_BS_THREE;
11190 else
11191 xp->xp_backslash = XP_BS_ONE;
11192 }
11193 }
11194
11195 /* For an option that is a list of file names, find the start of the
11196 * last file name. */
11197 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11198 {
11199 /* count number of backslashes before ' ' or ',' */
11200 if (*p == ' ' || *p == ',')
11201 {
11202 s = p;
11203 while (s > xp->xp_pattern && *(s - 1) == '\\')
11204 --s;
11205 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11206 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11207 {
11208 xp->xp_pattern = p + 1;
11209 break;
11210 }
11211 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011212
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011213#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011214 /* for 'spellsuggest' start at "file:" */
11215 if (options[opt_idx].var == (char_u *)&p_sps
11216 && STRNCMP(p, "file:", 5) == 0)
11217 {
11218 xp->xp_pattern = p + 5;
11219 break;
11220 }
11221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011222 }
11223
11224 return;
11225}
11226
11227 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011228ExpandSettings(
11229 expand_T *xp,
11230 regmatch_T *regmatch,
11231 int *num_file,
11232 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011233{
11234 int num_normal = 0; /* Nr of matching non-term-code settings */
11235 int num_term = 0; /* Nr of matching terminal code settings */
11236 int opt_idx;
11237 int match;
11238 int count = 0;
11239 char_u *str;
11240 int loop;
11241 int is_term_opt;
11242 char_u name_buf[MAX_KEY_NAME_LEN];
11243 static char *(names[]) = {"all", "termcap"};
11244 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11245
11246 /* do this loop twice:
11247 * loop == 0: count the number of matching options
11248 * loop == 1: copy the matching options into allocated memory
11249 */
11250 for (loop = 0; loop <= 1; ++loop)
11251 {
11252 regmatch->rm_ic = ic;
11253 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11254 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011255 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11256 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011257 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11258 {
11259 if (loop == 0)
11260 num_normal++;
11261 else
11262 (*file)[count++] = vim_strsave((char_u *)names[match]);
11263 }
11264 }
11265 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11266 opt_idx++)
11267 {
11268 if (options[opt_idx].var == NULL)
11269 continue;
11270 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11271 && !(options[opt_idx].flags & P_BOOL))
11272 continue;
11273 is_term_opt = istermoption(&options[opt_idx]);
11274 if (is_term_opt && num_normal > 0)
11275 continue;
11276 match = FALSE;
11277 if (vim_regexec(regmatch, str, (colnr_T)0)
11278 || (options[opt_idx].shortname != NULL
11279 && vim_regexec(regmatch,
11280 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11281 match = TRUE;
11282 else if (is_term_opt)
11283 {
11284 name_buf[0] = '<';
11285 name_buf[1] = 't';
11286 name_buf[2] = '_';
11287 name_buf[3] = str[2];
11288 name_buf[4] = str[3];
11289 name_buf[5] = '>';
11290 name_buf[6] = NUL;
11291 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11292 {
11293 match = TRUE;
11294 str = name_buf;
11295 }
11296 }
11297 if (match)
11298 {
11299 if (loop == 0)
11300 {
11301 if (is_term_opt)
11302 num_term++;
11303 else
11304 num_normal++;
11305 }
11306 else
11307 (*file)[count++] = vim_strsave(str);
11308 }
11309 }
11310 /*
11311 * Check terminal key codes, these are not in the option table
11312 */
11313 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11314 {
11315 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11316 {
11317 if (!isprint(str[0]) || !isprint(str[1]))
11318 continue;
11319
11320 name_buf[0] = 't';
11321 name_buf[1] = '_';
11322 name_buf[2] = str[0];
11323 name_buf[3] = str[1];
11324 name_buf[4] = NUL;
11325
11326 match = FALSE;
11327 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11328 match = TRUE;
11329 else
11330 {
11331 name_buf[0] = '<';
11332 name_buf[1] = 't';
11333 name_buf[2] = '_';
11334 name_buf[3] = str[0];
11335 name_buf[4] = str[1];
11336 name_buf[5] = '>';
11337 name_buf[6] = NUL;
11338
11339 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11340 match = TRUE;
11341 }
11342 if (match)
11343 {
11344 if (loop == 0)
11345 num_term++;
11346 else
11347 (*file)[count++] = vim_strsave(name_buf);
11348 }
11349 }
11350
11351 /*
11352 * Check special key names.
11353 */
11354 regmatch->rm_ic = TRUE; /* ignore case here */
11355 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11356 {
11357 name_buf[0] = '<';
11358 STRCPY(name_buf + 1, str);
11359 STRCAT(name_buf, ">");
11360
11361 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11362 {
11363 if (loop == 0)
11364 num_term++;
11365 else
11366 (*file)[count++] = vim_strsave(name_buf);
11367 }
11368 }
11369 }
11370 if (loop == 0)
11371 {
11372 if (num_normal > 0)
11373 *num_file = num_normal;
11374 else if (num_term > 0)
11375 *num_file = num_term;
11376 else
11377 return OK;
11378 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11379 if (*file == NULL)
11380 {
11381 *file = (char_u **)"";
11382 return FAIL;
11383 }
11384 }
11385 }
11386 return OK;
11387}
11388
11389 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011390ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391{
11392 char_u *var = NULL; /* init for GCC */
11393 char_u *buf;
11394
11395 *num_file = 0;
11396 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11397 if (*file == NULL)
11398 return FAIL;
11399
11400 /*
11401 * For a terminal key code expand_option_idx is < 0.
11402 */
11403 if (expand_option_idx < 0)
11404 {
11405 var = find_termcode(expand_option_name + 2);
11406 if (var == NULL)
11407 expand_option_idx = findoption(expand_option_name);
11408 }
11409
11410 if (expand_option_idx >= 0)
11411 {
11412 /* put string of option value in NameBuff */
11413 option_value2string(&options[expand_option_idx], expand_option_flags);
11414 var = NameBuff;
11415 }
11416 else if (var == NULL)
11417 var = (char_u *)"";
11418
11419 /* A backslash is required before some characters. This is the reverse of
11420 * what happens in do_set(). */
11421 buf = vim_strsave_escaped(var, escape_chars);
11422
11423 if (buf == NULL)
11424 {
11425 vim_free(*file);
11426 *file = NULL;
11427 return FAIL;
11428 }
11429
11430#ifdef BACKSLASH_IN_FILENAME
11431 /* For MS-Windows et al. we don't double backslashes at the start and
11432 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011433 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011434 if (var[0] == '\\' && var[1] == '\\'
11435 && expand_option_idx >= 0
11436 && (options[expand_option_idx].flags & P_EXPAND)
11437 && vim_isfilec(var[2])
11438 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011439 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011440#endif
11441
11442 *file[0] = buf;
11443 *num_file = 1;
11444 return OK;
11445}
11446#endif
11447
11448/*
11449 * Get the value for the numeric or string option *opp in a nice format into
11450 * NameBuff[]. Must not be called with a hidden option!
11451 */
11452 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011453option_value2string(
11454 struct vimoption *opp,
11455 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011456{
11457 char_u *varp;
11458
11459 varp = get_varp_scope(opp, opt_flags);
11460
11461 if (opp->flags & P_NUM)
11462 {
11463 long wc = 0;
11464
11465 if (wc_use_keyname(varp, &wc))
11466 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11467 else if (wc != 0)
11468 STRCPY(NameBuff, transchar((int)wc));
11469 else
11470 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11471 }
11472 else /* P_STRING */
11473 {
11474 varp = *(char_u **)(varp);
11475 if (varp == NULL) /* just in case */
11476 NameBuff[0] = NUL;
11477#ifdef FEAT_CRYPT
11478 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011479 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011480 STRCPY(NameBuff, "*****");
11481#endif
11482 else if (opp->flags & P_EXPAND)
11483 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11484 /* Translate 'pastetoggle' into special key names */
11485 else if ((char_u **)opp->var == &p_pt)
11486 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11487 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011488 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011489 }
11490}
11491
11492/*
11493 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11494 * printed as a keyname.
11495 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11496 */
11497 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011498wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499{
11500 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11501 {
11502 *wcp = *(long *)varp;
11503 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11504 return TRUE;
11505 }
11506 return FALSE;
11507}
11508
Bram Moolenaar01615492015-02-03 13:00:38 +010011509#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011510/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011511 * Any character has an equivalent 'langmap' character. This is used for
11512 * keyboards that have a special language mode that sends characters above
11513 * 128 (although other characters can be translated too). The "to" field is a
11514 * Vim command character. This avoids having to switch the keyboard back to
11515 * ASCII mode when leaving Insert mode.
11516 *
11517 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11518 * commands.
11519 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11520 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11521 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011522 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011523# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011524/*
11525 * With multi-byte support use growarray for 'langmap' chars >= 256
11526 */
11527typedef struct
11528{
11529 int from;
11530 int to;
11531} langmap_entry_T;
11532
11533static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011534static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535
11536/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011537 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11538 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011539 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011540 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011541langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011542{
11543 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011544 int a = 0;
11545 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011546
11547 /* Do a binary search for an existing entry. */
11548 while (a != b)
11549 {
11550 int i = (a + b) / 2;
11551 int d = entries[i].from - from;
11552
11553 if (d == 0)
11554 {
11555 entries[i].to = to;
11556 return;
11557 }
11558 if (d < 0)
11559 a = i + 1;
11560 else
11561 b = i;
11562 }
11563
11564 if (ga_grow(&langmap_mapga, 1) != OK)
11565 return; /* out of memory */
11566
11567 /* insert new entry at position "a" */
11568 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11569 mch_memmove(entries + 1, entries,
11570 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11571 ++langmap_mapga.ga_len;
11572 entries[0].from = from;
11573 entries[0].to = to;
11574}
11575
11576/*
11577 * Apply 'langmap' to multi-byte character "c" and return the result.
11578 */
11579 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011580langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011581{
11582 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11583 int a = 0;
11584 int b = langmap_mapga.ga_len;
11585
11586 while (a != b)
11587 {
11588 int i = (a + b) / 2;
11589 int d = entries[i].from - c;
11590
11591 if (d == 0)
11592 return entries[i].to; /* found matching entry */
11593 if (d < 0)
11594 a = i + 1;
11595 else
11596 b = i;
11597 }
11598 return c; /* no entry found, return "c" unmodified */
11599}
11600# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011601
11602 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011603langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011604{
11605 int i;
11606
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011607 for (i = 0; i < 256; i++)
11608 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11609# ifdef FEAT_MBYTE
11610 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11611# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612}
11613
11614/*
11615 * Called when langmap option is set; the language map can be
11616 * changed at any time!
11617 */
11618 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011619langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011620{
11621 char_u *p;
11622 char_u *p2;
11623 int from, to;
11624
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011625#ifdef FEAT_MBYTE
11626 ga_clear(&langmap_mapga); /* clear the previous map first */
11627#endif
11628 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011629
11630 for (p = p_langmap; p[0] != NUL; )
11631 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011632 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11633 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011634 {
11635 if (p2[0] == '\\' && p2[1] != NUL)
11636 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011637 }
11638 if (p2[0] == ';')
11639 ++p2; /* abcd;ABCD form, p2 points to A */
11640 else
11641 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11642 while (p[0])
11643 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011644 if (p[0] == ',')
11645 {
11646 ++p;
11647 break;
11648 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011649 if (p[0] == '\\' && p[1] != NUL)
11650 ++p;
11651#ifdef FEAT_MBYTE
11652 from = (*mb_ptr2char)(p);
11653#else
11654 from = p[0];
11655#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011656 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011657 if (p2 == NULL)
11658 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011659 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011660 if (p[0] != ',')
11661 {
11662 if (p[0] == '\\')
11663 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011664#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011665 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011666#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011667 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011668#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011670 }
11671 else
11672 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011673 if (p2[0] != ',')
11674 {
11675 if (p2[0] == '\\')
11676 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011677#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011678 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011679#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011680 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011681#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011682 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011683 }
11684 if (to == NUL)
11685 {
11686 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11687 transchar(from));
11688 return;
11689 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011690
11691#ifdef FEAT_MBYTE
11692 if (from >= 256)
11693 langmap_set_entry(from, to);
11694 else
11695#endif
11696 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011697
11698 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011699 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011700 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011701 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011702 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011703 if (*p == ';')
11704 {
11705 p = p2;
11706 if (p[0] != NUL)
11707 {
11708 if (p[0] != ',')
11709 {
11710 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11711 return;
11712 }
11713 ++p;
11714 }
11715 break;
11716 }
11717 }
11718 }
11719 }
11720}
11721#endif
11722
11723/*
11724 * Return TRUE if format option 'x' is in effect.
11725 * Take care of no formatting when 'paste' is set.
11726 */
11727 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011728has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011729{
11730 if (p_paste)
11731 return FALSE;
11732 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11733}
11734
11735/*
11736 * Return TRUE if "x" is present in 'shortmess' option, or
11737 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11738 */
11739 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011740shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011742 return p_shm != NULL &&
11743 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011744 || (vim_strchr(p_shm, 'a') != NULL
11745 && vim_strchr((char_u *)SHM_A, x) != NULL));
11746}
11747
11748/*
11749 * paste_option_changed() - Called after p_paste was set or reset.
11750 */
11751 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011752paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011753{
11754 static int old_p_paste = FALSE;
11755 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011756 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011757#ifdef FEAT_CMDL_INFO
11758 static int save_ru = 0;
11759#endif
11760#ifdef FEAT_RIGHTLEFT
11761 static int save_ri = 0;
11762 static int save_hkmap = 0;
11763#endif
11764 buf_T *buf;
11765
11766 if (p_paste)
11767 {
11768 /*
11769 * Paste switched from off to on.
11770 * Save the current values, so they can be restored later.
11771 */
11772 if (!old_p_paste)
11773 {
11774 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011775 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776 {
11777 buf->b_p_tw_nopaste = buf->b_p_tw;
11778 buf->b_p_wm_nopaste = buf->b_p_wm;
11779 buf->b_p_sts_nopaste = buf->b_p_sts;
11780 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011781 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782 }
11783
11784 /* save global options */
11785 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011786 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011787#ifdef FEAT_CMDL_INFO
11788 save_ru = p_ru;
11789#endif
11790#ifdef FEAT_RIGHTLEFT
11791 save_ri = p_ri;
11792 save_hkmap = p_hkmap;
11793#endif
11794 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011795 p_ai_nopaste = p_ai;
11796 p_et_nopaste = p_et;
11797 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011798 p_tw_nopaste = p_tw;
11799 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011800 }
11801
11802 /*
11803 * Always set the option values, also when 'paste' is set when it is
11804 * already on.
11805 */
11806 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011807 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011808 {
11809 buf->b_p_tw = 0; /* textwidth is 0 */
11810 buf->b_p_wm = 0; /* wrapmargin is 0 */
11811 buf->b_p_sts = 0; /* softtabstop is 0 */
11812 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011813 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011814 }
11815
11816 /* set global options */
11817 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011818 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819#ifdef FEAT_CMDL_INFO
11820# ifdef FEAT_WINDOWS
11821 if (p_ru)
11822 status_redraw_all(); /* redraw to remove the ruler */
11823# endif
11824 p_ru = 0; /* no ruler */
11825#endif
11826#ifdef FEAT_RIGHTLEFT
11827 p_ri = 0; /* no reverse insert */
11828 p_hkmap = 0; /* no Hebrew keyboard */
11829#endif
11830 /* set global values for local buffer options */
11831 p_tw = 0;
11832 p_wm = 0;
11833 p_sts = 0;
11834 p_ai = 0;
11835 }
11836
11837 /*
11838 * Paste switched from on to off: Restore saved values.
11839 */
11840 else if (old_p_paste)
11841 {
11842 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011843 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011844 {
11845 buf->b_p_tw = buf->b_p_tw_nopaste;
11846 buf->b_p_wm = buf->b_p_wm_nopaste;
11847 buf->b_p_sts = buf->b_p_sts_nopaste;
11848 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011849 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011850 }
11851
11852 /* restore global options */
11853 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011854 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855#ifdef FEAT_CMDL_INFO
11856# ifdef FEAT_WINDOWS
11857 if (p_ru != save_ru)
11858 status_redraw_all(); /* redraw to draw the ruler */
11859# endif
11860 p_ru = save_ru;
11861#endif
11862#ifdef FEAT_RIGHTLEFT
11863 p_ri = save_ri;
11864 p_hkmap = save_hkmap;
11865#endif
11866 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011867 p_ai = p_ai_nopaste;
11868 p_et = p_et_nopaste;
11869 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011870 p_tw = p_tw_nopaste;
11871 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011872 }
11873
11874 old_p_paste = p_paste;
11875}
11876
11877/*
11878 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11879 *
11880 * Reset 'compatible' and set the values for options that didn't get set yet
11881 * to the Vim defaults.
11882 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011883 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011884 */
11885 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011886vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011888 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011889 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011890 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011891
11892 if (!option_was_set((char_u *)"cp"))
11893 {
11894 p_cp = FALSE;
11895 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11896 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11897 set_option_default(opt_idx, OPT_FREE, FALSE);
11898 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011899 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011901
11902 if (fname != NULL)
11903 {
11904 p = vim_getenv(envname, &dofree);
11905 if (p == NULL)
11906 {
11907 /* Set $MYVIMRC to the first vimrc file found. */
11908 p = FullName_save(fname, FALSE);
11909 if (p != NULL)
11910 {
11911 vim_setenv(envname, p);
11912 vim_free(p);
11913 }
11914 }
11915 else if (dofree)
11916 vim_free(p);
11917 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011918}
11919
11920/*
11921 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11922 */
11923 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011924change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011925{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011926 int opt_idx;
11927
Bram Moolenaar071d4272004-06-13 20:20:40 +000011928 if (p_cp != on)
11929 {
11930 p_cp = on;
11931 compatible_set();
11932 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011933 opt_idx = findoption((char_u *)"cp");
11934 if (opt_idx >= 0)
11935 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936}
11937
11938/*
11939 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011940 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011941 */
11942 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011943option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011944{
11945 int idx;
11946
11947 idx = findoption(name);
11948 if (idx < 0) /* unknown option */
11949 return FALSE;
11950 if (options[idx].flags & P_WAS_SET)
11951 return TRUE;
11952 return FALSE;
11953}
11954
11955/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011956 * Reset the flag indicating option "name" was set.
11957 */
11958 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011959reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011960{
11961 int idx = findoption(name);
11962
11963 if (idx >= 0)
11964 options[idx].flags &= ~P_WAS_SET;
11965}
11966
11967/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011968 * compatible_set() - Called when 'compatible' has been set or unset.
11969 *
11970 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11971 * flag) to a Vi compatible value.
11972 * When 'compatible' is unset: Set all options that have a different default
11973 * for Vim (without the P_VI_DEF flag) to that default.
11974 */
11975 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011976compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977{
11978 int opt_idx;
11979
11980 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11981 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11982 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11983 set_option_default(opt_idx, OPT_FREE, p_cp);
11984 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011985 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011986}
11987
11988#ifdef FEAT_LINEBREAK
11989
11990# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11991 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011992 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993# endif
11994
11995/*
11996 * fill_breakat_flags() -- called when 'breakat' changes value.
11997 */
11998 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011999fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012000{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012001 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002 int i;
12003
12004 for (i = 0; i < 256; i++)
12005 breakat_flags[i] = FALSE;
12006
12007 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012008 for (p = p_breakat; *p; p++)
12009 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012010}
12011
12012# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012013 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012014# endif
12015
12016#endif
12017
12018/*
12019 * Check an option that can be a range of string values.
12020 *
12021 * Return OK for correct value, FAIL otherwise.
12022 * Empty is always OK.
12023 */
12024 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012025check_opt_strings(
12026 char_u *val,
12027 char **values,
12028 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029{
12030 return opt_strings_flags(val, values, NULL, list);
12031}
12032
12033/*
12034 * Handle an option that can be a range of string values.
12035 * Set a flag in "*flagp" for each string present.
12036 *
12037 * Return OK for correct value, FAIL otherwise.
12038 * Empty is always OK.
12039 */
12040 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012041opt_strings_flags(
12042 char_u *val, /* new value */
12043 char **values, /* array of valid string values */
12044 unsigned *flagp,
12045 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012046{
12047 int i;
12048 int len;
12049 unsigned new_flags = 0;
12050
12051 while (*val)
12052 {
12053 for (i = 0; ; ++i)
12054 {
12055 if (values[i] == NULL) /* val not found in values[] */
12056 return FAIL;
12057
12058 len = (int)STRLEN(values[i]);
12059 if (STRNCMP(values[i], val, len) == 0
12060 && ((list && val[len] == ',') || val[len] == NUL))
12061 {
12062 val += len + (val[len] == ',');
12063 new_flags |= (1 << i);
12064 break; /* check next item in val list */
12065 }
12066 }
12067 }
12068 if (flagp != NULL)
12069 *flagp = new_flags;
12070
12071 return OK;
12072}
12073
12074/*
12075 * Read the 'wildmode' option, fill wim_flags[].
12076 */
12077 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012078check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012079{
12080 char_u new_wim_flags[4];
12081 char_u *p;
12082 int i;
12083 int idx = 0;
12084
12085 for (i = 0; i < 4; ++i)
12086 new_wim_flags[i] = 0;
12087
12088 for (p = p_wim; *p; ++p)
12089 {
12090 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12091 ;
12092 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12093 return FAIL;
12094 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12095 new_wim_flags[idx] |= WIM_LONGEST;
12096 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12097 new_wim_flags[idx] |= WIM_FULL;
12098 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12099 new_wim_flags[idx] |= WIM_LIST;
12100 else
12101 return FAIL;
12102 p += i;
12103 if (*p == NUL)
12104 break;
12105 if (*p == ',')
12106 {
12107 if (idx == 3)
12108 return FAIL;
12109 ++idx;
12110 }
12111 }
12112
12113 /* fill remaining entries with last flag */
12114 while (idx < 3)
12115 {
12116 new_wim_flags[idx + 1] = new_wim_flags[idx];
12117 ++idx;
12118 }
12119
12120 /* only when there are no errors, wim_flags[] is changed */
12121 for (i = 0; i < 4; ++i)
12122 wim_flags[i] = new_wim_flags[i];
12123 return OK;
12124}
12125
12126/*
12127 * Check if backspacing over something is allowed.
12128 */
12129 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012130can_bs(
12131 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012132{
12133 switch (*p_bs)
12134 {
12135 case '2': return TRUE;
12136 case '1': return (what != BS_START);
12137 case '0': return FALSE;
12138 }
12139 return vim_strchr(p_bs, what) != NULL;
12140}
12141
12142/*
12143 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12144 * the file must be considered changed when the value is different.
12145 */
12146 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012147save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012148{
12149 buf->b_start_ffc = *buf->b_p_ff;
12150 buf->b_start_eol = buf->b_p_eol;
12151#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012152 buf->b_start_bomb = buf->b_p_bomb;
12153
Bram Moolenaar071d4272004-06-13 20:20:40 +000012154 /* Only use free/alloc when necessary, they take time. */
12155 if (buf->b_start_fenc == NULL
12156 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12157 {
12158 vim_free(buf->b_start_fenc);
12159 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12160 }
12161#endif
12162}
12163
12164/*
12165 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12166 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012167 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12168 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012169 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012170 * When "ignore_empty" is true don't consider a new, empty buffer to be
12171 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012172 */
12173 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012174file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012176 /* In a buffer that was never loaded the options are not valid. */
12177 if (buf->b_flags & BF_NEVERLOADED)
12178 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012179 if (ignore_empty
12180 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012181 && buf->b_ml.ml_line_count == 1
12182 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12183 return FALSE;
12184 if (buf->b_start_ffc != *buf->b_p_ff)
12185 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012186 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012187 return TRUE;
12188#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012189 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12190 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012191 if (buf->b_start_fenc == NULL)
12192 return (*buf->b_p_fenc != NUL);
12193 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12194#else
12195 return FALSE;
12196#endif
12197}
12198
12199/*
12200 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12201 */
12202 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012203check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012204{
12205 return check_opt_strings(p, p_ff_values, FALSE);
12206}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012207
12208/*
12209 * Return the effective shiftwidth value for current buffer, using the
12210 * 'tabstop' value when 'shiftwidth' is zero.
12211 */
12212 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012213get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012214{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012215 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012216}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012217
12218/*
12219 * Return the effective softtabstop value for the current buffer, using the
12220 * 'tabstop' value when 'softtabstop' is negative.
12221 */
12222 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012223get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012224{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012225 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012226}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012227
12228/*
12229 * Check matchpairs option for "*initc".
12230 * If there is a match set "*initc" to the matching character and "*findc" to
12231 * the opposite character. Set "*backwards" to the direction.
12232 * When "switchit" is TRUE swap the direction.
12233 */
12234 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012235find_mps_values(
12236 int *initc,
12237 int *findc,
12238 int *backwards,
12239 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012240{
12241 char_u *ptr;
12242
12243 ptr = curbuf->b_p_mps;
12244 while (*ptr != NUL)
12245 {
12246#ifdef FEAT_MBYTE
12247 if (has_mbyte)
12248 {
12249 char_u *prev;
12250
12251 if (mb_ptr2char(ptr) == *initc)
12252 {
12253 if (switchit)
12254 {
12255 *findc = *initc;
12256 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12257 *backwards = TRUE;
12258 }
12259 else
12260 {
12261 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12262 *backwards = FALSE;
12263 }
12264 return;
12265 }
12266 prev = ptr;
12267 ptr += mb_ptr2len(ptr) + 1;
12268 if (mb_ptr2char(ptr) == *initc)
12269 {
12270 if (switchit)
12271 {
12272 *findc = *initc;
12273 *initc = mb_ptr2char(prev);
12274 *backwards = FALSE;
12275 }
12276 else
12277 {
12278 *findc = mb_ptr2char(prev);
12279 *backwards = TRUE;
12280 }
12281 return;
12282 }
12283 ptr += mb_ptr2len(ptr);
12284 }
12285 else
12286#endif
12287 {
12288 if (*ptr == *initc)
12289 {
12290 if (switchit)
12291 {
12292 *backwards = TRUE;
12293 *findc = *initc;
12294 *initc = ptr[2];
12295 }
12296 else
12297 {
12298 *backwards = FALSE;
12299 *findc = ptr[2];
12300 }
12301 return;
12302 }
12303 ptr += 2;
12304 if (*ptr == *initc)
12305 {
12306 if (switchit)
12307 {
12308 *backwards = FALSE;
12309 *findc = *initc;
12310 *initc = ptr[-2];
12311 }
12312 else
12313 {
12314 *backwards = TRUE;
12315 *findc = ptr[-2];
12316 }
12317 return;
12318 }
12319 ++ptr;
12320 }
12321 if (*ptr == ',')
12322 ++ptr;
12323 }
12324}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012325
12326#if defined(FEAT_LINEBREAK) || defined(PROTO)
12327/*
12328 * This is called when 'breakindentopt' is changed and when a window is
12329 * initialized.
12330 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012331 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012332briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012333{
12334 char_u *p;
12335 int bri_shift = 0;
12336 long bri_min = 20;
12337 int bri_sbr = FALSE;
12338
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012339 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012340 while (*p != NUL)
12341 {
12342 if (STRNCMP(p, "shift:", 6) == 0
12343 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12344 {
12345 p += 6;
12346 bri_shift = getdigits(&p);
12347 }
12348 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12349 {
12350 p += 4;
12351 bri_min = getdigits(&p);
12352 }
12353 else if (STRNCMP(p, "sbr", 3) == 0)
12354 {
12355 p += 3;
12356 bri_sbr = TRUE;
12357 }
12358 if (*p != ',' && *p != NUL)
12359 return FAIL;
12360 if (*p == ',')
12361 ++p;
12362 }
12363
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012364 wp->w_p_brishift = bri_shift;
12365 wp->w_p_brimin = bri_min;
12366 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012367
12368 return OK;
12369}
12370#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012371
12372/*
12373 * Get the local or global value of 'backupcopy'.
12374 */
12375 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012376get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012377{
12378 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12379}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012380
12381#if defined(FEAT_SIGNS) || defined(PROTO)
12382/*
12383 * Return TRUE when window "wp" has a column to draw signs in.
12384 */
12385 int
12386signcolumn_on(win_T *wp)
12387{
12388 if (*wp->w_p_scl == 'n')
12389 return FALSE;
12390 if (*wp->w_p_scl == 'y')
12391 return TRUE;
12392 return (wp->w_buffer->b_signlist != NULL
12393# ifdef FEAT_NETBEANS_INTG
12394 || wp->w_buffer->b_has_sign_column
12395# endif
12396 );
12397}
12398#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012399
12400#if defined(FEAT_EVAL) || defined(PROTO)
12401/*
12402 * Get window or buffer local options.
12403 */
12404 dict_T *
12405get_winbuf_options(int bufopt)
12406{
12407 dict_T *d;
12408 int opt_idx;
12409
12410 d = dict_alloc();
12411 if (d == NULL)
12412 return NULL;
12413
12414 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12415 {
12416 struct vimoption *opt = &options[opt_idx];
12417
12418 if ((bufopt && (opt->indir & PV_BUF))
12419 || (!bufopt && (opt->indir & PV_WIN)))
12420 {
12421 char_u *varp = get_varp(opt);
12422
12423 if (varp != NULL)
12424 {
12425 if (opt->flags & P_STRING)
12426 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012427 else if (opt->flags & P_NUM)
12428 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012429 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012430 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012431 }
12432 }
12433 }
12434
12435 return d;
12436}
12437#endif