blob: a987a4cdf88540752ca0901d496e552bcf63e5a0 [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 Moolenaarec2da362017-01-21 20:04:22 +01003043 p_term("t_BE", T_BE)
3044 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045
3046/* terminal key codes are not in here */
3047
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003048 /* end marker */
3049 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050};
3051
3052#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3053
3054#ifdef FEAT_MBYTE
3055static char *(p_ambw_values[]) = {"single", "double", NULL};
3056#endif
3057static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003058static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003059static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003060#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003061static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003062#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003063#ifdef FEAT_CMDL_COMPL
3064static char *(p_wop_values[]) = {"tagfile", NULL};
3065#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066#ifdef FEAT_WAK
3067static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3068#endif
3069static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3071static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073#ifdef FEAT_BROWSE
3074static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3075#endif
3076#ifdef FEAT_SCROLLBIND
3077static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3078#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003079static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003080#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3082#endif
3083#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003084# ifdef FEAT_AUTOCMD
3085static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3086# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003088# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3090#endif
3091static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3092#ifdef FEAT_FOLDING
3093static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003094# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003096# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 NULL};
3098static char *(p_fcl_values[]) = {"all", NULL};
3099#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003100#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003101static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003102#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003103#ifdef FEAT_SIGNS
3104static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3105#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003107static void set_option_default(int, int opt_flags, int compatible);
3108static void set_options_default(int opt_flags);
3109static char_u *term_bg_default(void);
3110static void did_set_option(int opt_idx, int opt_flags, int new_value);
3111static char_u *illegal_char(char_u *, int);
3112static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003113#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003114static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115#endif
3116#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003117static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003119static char_u *option_expand(int opt_idx, char_u *val);
3120static void didset_options(void);
3121static void didset_options2(void);
3122static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003123#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003124static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003125#else
3126# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3127#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003128static void set_string_option_global(int opt_idx, char_u **varp);
3129static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3130static 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);
3131static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003132#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003133static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003134#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003136static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003138#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003139static char_u *did_set_spell_option(int is_spellfile);
3140static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003141#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003142#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003143static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003144#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003145static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3146static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3147static void check_redraw(long_u flags);
3148static int findoption(char_u *);
3149static int find_key_option(char_u *);
3150static void showoptions(int all, int opt_flags);
3151static int optval_default(struct vimoption *, char_u *varp);
3152static void showoneopt(struct vimoption *, int opt_flags);
3153static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3154static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3155static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3156static int istermoption(struct vimoption *);
3157static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3158static char_u *get_varp(struct vimoption *);
3159static void option_value2string(struct vimoption *, int opt_flags);
3160static void check_winopt(winopt_T *wop);
3161static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003163static void langmap_init(void);
3164static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003166static void paste_option_changed(void);
3167static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003169static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003171static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3172static int check_opt_strings(char_u *val, char **values, int);
3173static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003174#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003175static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003176#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177
3178/*
3179 * Initialize the options, first part.
3180 *
3181 * Called only once from main(), just after creating the first buffer.
3182 */
3183 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003184set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185{
3186 char_u *p;
3187 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003188 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189
3190#ifdef FEAT_LANGMAP
3191 langmap_init();
3192#endif
3193
3194 /* Be Vi compatible by default */
3195 p_cp = TRUE;
3196
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003197 /* Use POSIX compatibility when $VIM_POSIX is set. */
3198 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003199 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003200 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003201 set_string_default("shm", (char_u *)"A");
3202 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003203
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204 /*
3205 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003206 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003208 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003209#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003210 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003212 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213# endif
3214#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003215 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 set_string_default("sh", p);
3217
3218#ifdef FEAT_WILDIGN
3219 /*
3220 * Set the default for 'backupskip' to include environment variables for
3221 * temp files.
3222 */
3223 {
3224# ifdef UNIX
3225 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3226# else
3227 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3228# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003229 int len;
3230 garray_T ga;
3231 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232
3233 ga_init2(&ga, 1, 100);
3234 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3235 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003236 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237# ifdef UNIX
3238 if (*names[n] == NUL)
3239 p = (char_u *)"/tmp";
3240 else
3241# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003242 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003243 if (p != NULL && *p != NUL)
3244 {
3245 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003246 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247 if (ga_grow(&ga, len) == OK)
3248 {
3249 if (ga.ga_len > 0)
3250 STRCAT(ga.ga_data, ",");
3251 STRCAT(ga.ga_data, p);
3252 add_pathsep(ga.ga_data);
3253 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003254 ga.ga_len += len;
3255 }
3256 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003257 if (mustfree)
3258 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003259 }
3260 if (ga.ga_data != NULL)
3261 {
3262 set_string_default("bsk", ga.ga_data);
3263 vim_free(ga.ga_data);
3264 }
3265 }
3266#endif
3267
3268 /*
3269 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3270 */
3271 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003272 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003274#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3275 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3276#endif
3277 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003279 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003280 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281#else
3282# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003283 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003284 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003286 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287# endif
3288#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003290 opt_idx = findoption((char_u *)"maxmem");
3291 if (opt_idx >= 0)
3292 {
3293#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003294 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3295 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003296#endif
3297 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3298 }
3299 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300 }
3301
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302#ifdef FEAT_SEARCHPATH
3303 {
3304 char_u *cdpath;
3305 char_u *buf;
3306 int i;
3307 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003308 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309
3310 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003311 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003312 if (cdpath != NULL)
3313 {
3314 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3315 if (buf != NULL)
3316 {
3317 buf[0] = ','; /* start with ",", current dir first */
3318 j = 1;
3319 for (i = 0; cdpath[i] != NUL; ++i)
3320 {
3321 if (vim_ispathlistsep(cdpath[i]))
3322 buf[j++] = ',';
3323 else
3324 {
3325 if (cdpath[i] == ' ' || cdpath[i] == ',')
3326 buf[j++] = '\\';
3327 buf[j++] = cdpath[i];
3328 }
3329 }
3330 buf[j] = NUL;
3331 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003332 if (opt_idx >= 0)
3333 {
3334 options[opt_idx].def_val[VI_DEFAULT] = buf;
3335 options[opt_idx].flags |= P_DEF_ALLOCED;
3336 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003337 else
3338 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003340 if (mustfree)
3341 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342 }
3343 }
3344#endif
3345
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003346#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 /* Set print encoding on platforms that don't default to latin1 */
3348 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003349# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350 (char_u *)"cp1252"
3351# else
3352# ifdef VMS
3353 (char_u *)"dec-mcs"
3354# else
3355# ifdef EBCDIC
3356 (char_u *)"ebcdic-uk"
3357# else
3358# ifdef MAC
3359 (char_u *)"mac-roman"
3360# else /* HPUX */
3361 (char_u *)"hp-roman8"
3362# endif
3363# endif
3364# endif
3365# endif
3366 );
3367#endif
3368
3369#ifdef FEAT_POSTSCRIPT
3370 /* 'printexpr' must be allocated to be able to evaluate it. */
3371 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003372# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003373 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374# else
3375# ifdef VMS
3376 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3377
3378# else
3379 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3380# endif
3381# endif
3382 );
3383#endif
3384
3385 /*
3386 * Set all the options (except the terminal options) to their default
3387 * value. Also set the global value for local options.
3388 */
3389 set_options_default(0);
3390
3391#ifdef FEAT_GUI
3392 if (found_reverse_arg)
3393 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3394#endif
3395
3396 curbuf->b_p_initialized = TRUE;
3397 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003398 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003399 check_buf_options(curbuf);
3400 check_win_options(curwin);
3401 check_options();
3402
3403 /* Must be before option_expand(), because that one needs vim_isIDc() */
3404 didset_options();
3405
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003406#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003407 /* Use the current chartab for the generic chartab. This is not in
3408 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003409 init_spell_chartab();
3410#endif
3411
Bram Moolenaar071d4272004-06-13 20:20:40 +00003412 /*
3413 * Expand environment variables and things like "~" for the defaults.
3414 * If option_expand() returns non-NULL the variable is expanded. This can
3415 * only happen for non-indirect options.
3416 * Also set the default to the expanded value, so ":set" does not list
3417 * them.
3418 * Don't set the P_ALLOCED flag, because we don't want to free the
3419 * default.
3420 */
3421 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3422 {
3423 if ((options[opt_idx].flags & P_GETTEXT)
3424 && options[opt_idx].var != NULL)
3425 p = (char_u *)_(*(char **)options[opt_idx].var);
3426 else
3427 p = option_expand(opt_idx, NULL);
3428 if (p != NULL && (p = vim_strsave(p)) != NULL)
3429 {
3430 *(char_u **)options[opt_idx].var = p;
3431 /* VIMEXP
3432 * Defaults for all expanded options are currently the same for Vi
3433 * and Vim. When this changes, add some code here! Also need to
3434 * split P_DEF_ALLOCED in two.
3435 */
3436 if (options[opt_idx].flags & P_DEF_ALLOCED)
3437 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3438 options[opt_idx].def_val[VI_DEFAULT] = p;
3439 options[opt_idx].flags |= P_DEF_ALLOCED;
3440 }
3441 }
3442
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 save_file_ff(curbuf); /* Buffer is unchanged */
3444
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445#if defined(FEAT_ARABIC)
3446 /* Detect use of mlterm.
3447 * Mlterm is a terminal emulator akin to xterm that has some special
3448 * abilities (bidi namely).
3449 * NOTE: mlterm's author is being asked to 'set' a variable
3450 * instead of an environment variable due to inheritance.
3451 */
3452 if (mch_getenv((char_u *)"MLTERM") != NULL)
3453 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3454#endif
3455
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003456 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457
3458#ifdef FEAT_MBYTE
3459# if defined(WIN3264) && defined(FEAT_GETTEXT)
3460 /*
3461 * If $LANG isn't set, try to get a good value for it. This makes the
3462 * right language be used automatically. Don't do this for English.
3463 */
3464 if (mch_getenv((char_u *)"LANG") == NULL)
3465 {
3466 char buf[20];
3467
3468 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3469 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3470 * only the first two. */
3471 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3472 (LPTSTR)buf, 20);
3473 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3474 {
3475 /* There are a few exceptions (probably more) */
3476 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3477 STRCPY(buf, "zh_TW");
3478 else if (STRNICMP(buf, "chs", 3) == 0
3479 || STRNICMP(buf, "zhc", 3) == 0)
3480 STRCPY(buf, "zh_CN");
3481 else if (STRNICMP(buf, "jp", 2) == 0)
3482 STRCPY(buf, "ja");
3483 else
3484 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003485 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003486 }
3487 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003488# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003489# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003490 /* Moved to os_mac_conv.c to avoid dependency problems. */
3491 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003492# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493# endif
3494
3495 /* enc_locale() will try to find the encoding of the current locale. */
3496 p = enc_locale();
3497 if (p != NULL)
3498 {
3499 char_u *save_enc;
3500
3501 /* Try setting 'encoding' and check if the value is valid.
3502 * If not, go back to the default "latin1". */
3503 save_enc = p_enc;
3504 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003505 if (STRCMP(p_enc, "gb18030") == 0)
3506 {
3507 /* We don't support "gb18030", but "cp936" is a good substitute
3508 * for practical purposes, thus use that. It's not an alias to
3509 * still support conversion between gb18030 and utf-8. */
3510 p_enc = vim_strsave((char_u *)"cp936");
3511 vim_free(p);
3512 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003513 if (mb_init() == NULL)
3514 {
3515 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003516 if (opt_idx >= 0)
3517 {
3518 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3519 options[opt_idx].flags |= P_DEF_ALLOCED;
3520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003521
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003522#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003523 if (STRCMP(p_enc, "latin1") == 0
3524# ifdef FEAT_MBYTE
3525 || enc_utf8
3526# endif
3527 )
3528 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003529 /* Adjust the default for 'isprint' and 'iskeyword' to match
3530 * latin1. Also set the defaults for when 'nocompatible' is
3531 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003532 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003533 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003534 set_string_option_direct((char_u *)"isk", -1,
3535 ISK_LATIN1, OPT_FREE, SID_NONE);
3536 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003537 if (opt_idx >= 0)
3538 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003539 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003540 if (opt_idx >= 0)
3541 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003542 (void)init_chartab();
3543 }
3544#endif
3545
Bram Moolenaar071d4272004-06-13 20:20:40 +00003546# if defined(WIN3264) && !defined(FEAT_GUI)
3547 /* Win32 console: When GetACP() returns a different value from
3548 * GetConsoleCP() set 'termencoding'. */
3549 if (GetACP() != GetConsoleCP())
3550 {
3551 char buf[50];
3552
3553 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3554 p_tenc = vim_strsave((char_u *)buf);
3555 if (p_tenc != NULL)
3556 {
3557 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003558 if (opt_idx >= 0)
3559 {
3560 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3561 options[opt_idx].flags |= P_DEF_ALLOCED;
3562 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003563 convert_setup(&input_conv, p_tenc, p_enc);
3564 convert_setup(&output_conv, p_enc, p_tenc);
3565 }
3566 else
3567 p_tenc = empty_option;
3568 }
3569# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003570# if defined(WIN3264) && defined(FEAT_MBYTE)
3571 /* $HOME may have characters in active code page. */
3572 init_homedir();
3573# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574 }
3575 else
3576 {
3577 vim_free(p_enc);
3578 p_enc = save_enc;
3579 }
3580 }
3581#endif
3582
3583#ifdef FEAT_MULTI_LANG
3584 /* Set the default for 'helplang'. */
3585 set_helplang_default(get_mess_lang());
3586#endif
3587}
3588
3589/*
3590 * Set an option to its default value.
3591 * This does not take care of side effects!
3592 */
3593 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003594set_option_default(
3595 int opt_idx,
3596 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3597 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003598{
3599 char_u *varp; /* pointer to variable for current option */
3600 int dvi; /* index in def_val[] */
3601 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003602 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3604
3605 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3606 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003607 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608 {
3609 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3610 if (flags & P_STRING)
3611 {
3612 /* Use set_string_option_direct() for local options to handle
3613 * freeing and allocating the value. */
3614 if (options[opt_idx].indir != PV_NONE)
3615 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003616 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617 else
3618 {
3619 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3620 free_string_option(*(char_u **)(varp));
3621 *(char_u **)varp = options[opt_idx].def_val[dvi];
3622 options[opt_idx].flags &= ~P_ALLOCED;
3623 }
3624 }
3625 else if (flags & P_NUM)
3626 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003627 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003628 win_comp_scroll(curwin);
3629 else
3630 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003631 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632 /* May also set global value for local option. */
3633 if (both)
3634 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3635 *(long *)varp;
3636 }
3637 }
3638 else /* P_BOOL */
3639 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003640 /* the cast to long is required for Manx C, long_i is needed for
3641 * MSVC */
3642 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003643#ifdef UNIX
3644 /* 'modeline' defaults to off for root */
3645 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3646 *(int *)varp = FALSE;
3647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003648 /* May also set global value for local option. */
3649 if (both)
3650 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3651 *(int *)varp;
3652 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003653
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003654 /* The default value is not insecure. */
3655 flagsp = insecure_flag(opt_idx, opt_flags);
3656 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003657 }
3658
3659#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003660 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661#endif
3662}
3663
3664/*
3665 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003666 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003667 */
3668 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003669set_options_default(
3670 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671{
3672 int i;
3673#ifdef FEAT_WINDOWS
3674 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003675 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676#endif
3677
3678 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003679 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003680#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003681 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003682 || (TRUE
3683# if defined(FEAT_MBYTE)
3684 && options[i].var != (char_u *)&p_enc
3685# endif
3686# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003687 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003688 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003689# endif
3690 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003691#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003692 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693 set_option_default(i, opt_flags, p_cp);
3694
3695#ifdef FEAT_WINDOWS
3696 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003697 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698 win_comp_scroll(wp);
3699#else
3700 win_comp_scroll(curwin);
3701#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003702#ifdef FEAT_CINDENT
3703 parse_cino(curbuf);
3704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705}
3706
3707/*
3708 * Set the Vi-default value of a string option.
3709 * Used for 'sh', 'backupskip' and 'term'.
3710 */
3711 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003712set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713{
3714 char_u *p;
3715 int opt_idx;
3716
3717 p = vim_strsave(val);
3718 if (p != NULL) /* we don't want a NULL */
3719 {
3720 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003721 if (opt_idx >= 0)
3722 {
3723 if (options[opt_idx].flags & P_DEF_ALLOCED)
3724 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3725 options[opt_idx].def_val[VI_DEFAULT] = p;
3726 options[opt_idx].flags |= P_DEF_ALLOCED;
3727 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 }
3729}
3730
3731/*
3732 * Set the Vi-default value of a number option.
3733 * Used for 'lines' and 'columns'.
3734 */
3735 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003736set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003738 int opt_idx;
3739
3740 opt_idx = findoption((char_u *)name);
3741 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003742 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743}
3744
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003745#if defined(EXITFREE) || defined(PROTO)
3746/*
3747 * Free all options.
3748 */
3749 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003750free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003751{
3752 int i;
3753
3754 for (i = 0; !istermoption(&options[i]); i++)
3755 {
3756 if (options[i].indir == PV_NONE)
3757 {
3758 /* global option: free value and default value. */
3759 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3760 free_string_option(*(char_u **)options[i].var);
3761 if (options[i].flags & P_DEF_ALLOCED)
3762 free_string_option(options[i].def_val[VI_DEFAULT]);
3763 }
3764 else if (options[i].var != VAR_WIN
3765 && (options[i].flags & P_STRING))
3766 /* buffer-local option: free global value */
3767 free_string_option(*(char_u **)options[i].var);
3768 }
3769}
3770#endif
3771
3772
Bram Moolenaar071d4272004-06-13 20:20:40 +00003773/*
3774 * Initialize the options, part two: After getting Rows and Columns and
3775 * setting 'term'.
3776 */
3777 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003778set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003779{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003780 int idx;
3781
Bram Moolenaar071d4272004-06-13 20:20:40 +00003782 /*
3783 * 'scroll' defaults to half the window height. Note that this default is
3784 * wrong when the window height changes.
3785 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003786 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003787 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003788 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003789 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790 comp_col();
3791
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003792 /*
3793 * 'window' is only for backwards compatibility with Vi.
3794 * Default is Rows - 1.
3795 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003796 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003797 p_window = Rows - 1;
3798 set_number_default("window", Rows - 1);
3799
Bram Moolenaarf740b292006-02-16 22:11:02 +00003800 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003801#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003802 /*
3803 * If 'background' wasn't set by the user, try guessing the value,
3804 * depending on the terminal name. Only need to check for terminals
3805 * with a dark background, that can handle color.
3806 */
3807 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003808 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3809 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003811 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003812 /* don't mark it as set, when starting the GUI it may be
3813 * changed again */
3814 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 }
3816#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003817
3818#ifdef CURSOR_SHAPE
3819 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3820#endif
3821#ifdef FEAT_MOUSESHAPE
3822 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3823#endif
3824#ifdef FEAT_PRINTER
3825 (void)parse_printoptions(); /* parse 'printoptions' default value */
3826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003827}
3828
3829/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003830 * Return "dark" or "light" depending on the kind of terminal.
3831 * This is just guessing! Recognized are:
3832 * "linux" Linux console
3833 * "screen.linux" Linux console with screen
3834 * "cygwin" Cygwin shell
3835 * "putty" Putty program
3836 * We also check the COLORFGBG environment variable, which is set by
3837 * rxvt and derivatives. This variable contains either two or three
3838 * values separated by semicolons; we want the last value in either
3839 * case. If this value is 0-6 or 8, our background is dark.
3840 */
3841 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003842term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003843{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003844#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003845 /* DOS console nearly always black */
3846 return (char_u *)"dark";
3847#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003848 char_u *p;
3849
Bram Moolenaarf740b292006-02-16 22:11:02 +00003850 if (STRCMP(T_NAME, "linux") == 0
3851 || STRCMP(T_NAME, "screen.linux") == 0
3852 || STRCMP(T_NAME, "cygwin") == 0
3853 || STRCMP(T_NAME, "putty") == 0
3854 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3855 && (p = vim_strrchr(p, ';')) != NULL
3856 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3857 && p[2] == NUL))
3858 return (char_u *)"dark";
3859 return (char_u *)"light";
3860#endif
3861}
3862
3863/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864 * Initialize the options, part three: After reading the .vimrc
3865 */
3866 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003867set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003869#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003870/*
3871 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3872 * This is done after other initializations, where 'shell' might have been
3873 * set, but only if they have not been set before.
3874 */
3875 char_u *p;
3876 int idx_srr;
3877 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003878# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879 int idx_sp;
3880 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003881# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882
3883 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003884 if (idx_srr < 0)
3885 do_srr = FALSE;
3886 else
3887 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003888# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003890 if (idx_sp < 0)
3891 do_sp = FALSE;
3892 else
3893 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003894# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003895 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003896 if (p != NULL)
3897 {
3898 /*
3899 * Default for p_sp is "| tee", for p_srr is ">".
3900 * For known shells it is changed here to include stderr.
3901 */
3902 if ( fnamecmp(p, "csh") == 0
3903 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003904# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003905 || fnamecmp(p, "csh.exe") == 0
3906 || fnamecmp(p, "tcsh.exe") == 0
3907# endif
3908 )
3909 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003910# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 if (do_sp)
3912 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003913# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003914 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003915# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003916 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003917# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003918 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3919 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003920# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003921 if (do_srr)
3922 {
3923 p_srr = (char_u *)">&";
3924 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3925 }
3926 }
3927 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003928 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929 if ( fnamecmp(p, "sh") == 0
3930 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003931 || fnamecmp(p, "mksh") == 0
3932 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003934 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003936 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003937# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 || fnamecmp(p, "cmd") == 0
3939 || fnamecmp(p, "sh.exe") == 0
3940 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003941 || fnamecmp(p, "mksh.exe") == 0
3942 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003944 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003945 || fnamecmp(p, "bash.exe") == 0
3946 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003948 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003950# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 if (do_sp)
3952 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003953# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003955# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003957# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3959 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003960# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 if (do_srr)
3962 {
3963 p_srr = (char_u *)">%s 2>&1";
3964 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3965 }
3966 }
3967 vim_free(p);
3968 }
3969#endif
3970
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003971#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003973 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3974 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 * This is done after other initializations, where 'shell' might have been
3976 * set, but only if they have not been set before. Default for p_shcf is
3977 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003978 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003980 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 {
3982 int idx3;
3983
3984 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003985 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986 {
3987 p_shcf = (char_u *)"-c";
3988 options[idx3].def_val[VI_DEFAULT] = p_shcf;
3989 }
3990
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003991# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003992 /* Somehow Win32 requires the quotes around the redirection too */
3993 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003994 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 {
3996 p_sxq = (char_u *)"\"";
3997 options[idx3].def_val[VI_DEFAULT] = p_sxq;
3998 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003999# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004001 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004002 {
4003 p_shq = (char_u *)"\"";
4004 options[idx3].def_val[VI_DEFAULT] = p_shq;
4005 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004006# endif
4007 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004008 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4009 {
4010 int idx3;
4011
4012 /*
4013 * cmd.exe on Windows will strip the first and last double quote given
4014 * on the command line, e.g. most of the time things like:
4015 * cmd /c "my path/to/echo" "my args to echo"
4016 * become:
4017 * my path/to/echo" "my args to echo
4018 * when executed.
4019 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004020 * To avoid this, set shellxquote to surround the command in
4021 * parenthesis. This appears to make most commands work, without
4022 * breaking commands that worked previously, such as
4023 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004024 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004025 idx3 = findoption((char_u *)"sxq");
4026 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4027 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004028 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004029 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4030 }
4031
Bram Moolenaara64ba222012-02-12 23:23:31 +01004032 idx3 = findoption((char_u *)"shcf");
4033 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4034 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004035 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004036 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4037 }
4038 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039#endif
4040
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004041 if (bufempty())
4042 {
4043 int idx_ffs = findoption((char_u *)"ffs");
4044
4045 /* Apply the first entry of 'fileformats' to the initial buffer. */
4046 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4047 set_fileformat(default_fileformat(), OPT_LOCAL);
4048 }
4049
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050#ifdef FEAT_TITLE
4051 set_title_defaults();
4052#endif
4053}
4054
4055#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4056/*
4057 * When 'helplang' is still at its default value, set it to "lang".
4058 * Only the first two characters of "lang" are used.
4059 */
4060 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004061set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062{
4063 int idx;
4064
4065 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4066 return;
4067 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004068 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 {
4070 if (options[idx].flags & P_ALLOCED)
4071 free_string_option(p_hlg);
4072 p_hlg = vim_strsave(lang);
4073 if (p_hlg == NULL)
4074 p_hlg = empty_option;
4075 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004076 {
4077 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4078 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4079 {
4080 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4081 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4082 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004084 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 options[idx].flags |= P_ALLOCED;
4086 }
4087}
4088#endif
4089
4090#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004091static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092
4093 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004094gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095{
4096 if (gui_get_lightness(gui.back_pixel) < 127)
4097 return (char_u *)"dark";
4098 return (char_u *)"light";
4099}
4100
4101/*
4102 * Option initializations that can only be done after opening the GUI window.
4103 */
4104 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004105init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106{
4107 /* Set the 'background' option according to the lightness of the
4108 * background color, unless the user has set it already. */
4109 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4110 {
4111 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4112 highlight_changed();
4113 }
4114}
4115#endif
4116
4117#ifdef FEAT_TITLE
4118/*
4119 * 'title' and 'icon' only default to true if they have not been set or reset
4120 * in .vimrc and we can read the old value.
4121 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4122 * they can be reset. This reduces startup time when using X on a remote
4123 * machine.
4124 */
4125 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004126set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127{
4128 int idx1;
4129 long val;
4130
4131 /*
4132 * If GUI is (going to be) used, we can always set the window title and
4133 * icon name. Saves a bit of time, because the X11 display server does
4134 * not need to be contacted.
4135 */
4136 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004137 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 {
4139#ifdef FEAT_GUI
4140 if (gui.starting || gui.in_use)
4141 val = TRUE;
4142 else
4143#endif
4144 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004145 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146 p_title = val;
4147 }
4148 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004149 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 {
4151#ifdef FEAT_GUI
4152 if (gui.starting || gui.in_use)
4153 val = TRUE;
4154 else
4155#endif
4156 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004157 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004158 p_icon = val;
4159 }
4160}
4161#endif
4162
4163/*
4164 * Parse 'arg' for option settings.
4165 *
4166 * 'arg' may be IObuff, but only when no errors can be present and option
4167 * does not need to be expanded with option_expand().
4168 * "opt_flags":
4169 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004170 * OPT_GLOBAL for ":setglobal"
4171 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004173 * OPT_WINONLY to only set window-local options
4174 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004175 *
4176 * returns FAIL if an error is detected, OK otherwise
4177 */
4178 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004179do_set(
4180 char_u *arg, /* option string (may be written to!) */
4181 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182{
4183 int opt_idx;
4184 char_u *errmsg;
4185 char_u errbuf[80];
4186 char_u *startarg;
4187 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4188 int nextchar; /* next non-white char after option name */
4189 int afterchar; /* character just after option name */
4190 int len;
4191 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004192 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004193 int key;
4194 long_u flags; /* flags for current option */
4195 char_u *varp = NULL; /* pointer to variable for current option */
4196 int did_show = FALSE; /* already showed one value */
4197 int adding; /* "opt+=arg" */
4198 int prepending; /* "opt^=arg" */
4199 int removing; /* "opt-=arg" */
4200 int cp_val = 0;
4201 char_u key_name[2];
4202
4203 if (*arg == NUL)
4204 {
4205 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004206 did_show = TRUE;
4207 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004208 }
4209
4210 while (*arg != NUL) /* loop to process all options */
4211 {
4212 errmsg = NULL;
4213 startarg = arg; /* remember for error message */
4214
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004215 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4216 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004217 {
4218 /*
4219 * ":set all" show all options.
4220 * ":set all&" set all options to their default value.
4221 */
4222 arg += 3;
4223 if (*arg == '&')
4224 {
4225 ++arg;
4226 /* Only for :set command set global value of local options. */
4227 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004228 didset_options();
4229 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004230 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004231 }
4232 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004233 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004234 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004235 did_show = TRUE;
4236 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004237 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004238 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004239 {
4240 showoptions(2, opt_flags);
4241 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004242 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004243 arg += 7;
4244 }
4245 else
4246 {
4247 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004248 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004249 {
4250 prefix = 0;
4251 arg += 2;
4252 }
4253 else if (STRNCMP(arg, "inv", 3) == 0)
4254 {
4255 prefix = 2;
4256 arg += 3;
4257 }
4258
4259 /* find end of name */
4260 key = 0;
4261 if (*arg == '<')
4262 {
4263 nextchar = 0;
4264 opt_idx = -1;
4265 /* look out for <t_>;> */
4266 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4267 len = 5;
4268 else
4269 {
4270 len = 1;
4271 while (arg[len] != NUL && arg[len] != '>')
4272 ++len;
4273 }
4274 if (arg[len] != '>')
4275 {
4276 errmsg = e_invarg;
4277 goto skip;
4278 }
4279 arg[len] = NUL; /* put NUL after name */
4280 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4281 opt_idx = findoption(arg + 1);
4282 arg[len++] = '>'; /* restore '>' */
4283 if (opt_idx == -1)
4284 key = find_key_option(arg + 1);
4285 }
4286 else
4287 {
4288 len = 0;
4289 /*
4290 * The two characters after "t_" may not be alphanumeric.
4291 */
4292 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4293 len = 4;
4294 else
4295 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4296 ++len;
4297 nextchar = arg[len];
4298 arg[len] = NUL; /* put NUL after name */
4299 opt_idx = findoption(arg);
4300 arg[len] = nextchar; /* restore nextchar */
4301 if (opt_idx == -1)
4302 key = find_key_option(arg);
4303 }
4304
4305 /* remember character after option name */
4306 afterchar = arg[len];
4307
4308 /* skip white space, allow ":set ai ?" */
4309 while (vim_iswhite(arg[len]))
4310 ++len;
4311
4312 adding = FALSE;
4313 prepending = FALSE;
4314 removing = FALSE;
4315 if (arg[len] != NUL && arg[len + 1] == '=')
4316 {
4317 if (arg[len] == '+')
4318 {
4319 adding = TRUE; /* "+=" */
4320 ++len;
4321 }
4322 else if (arg[len] == '^')
4323 {
4324 prepending = TRUE; /* "^=" */
4325 ++len;
4326 }
4327 else if (arg[len] == '-')
4328 {
4329 removing = TRUE; /* "-=" */
4330 ++len;
4331 }
4332 }
4333 nextchar = arg[len];
4334
4335 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4336 {
4337 errmsg = (char_u *)N_("E518: Unknown option");
4338 goto skip;
4339 }
4340
4341 if (opt_idx >= 0)
4342 {
4343 if (options[opt_idx].var == NULL) /* hidden option: skip */
4344 {
4345 /* Only give an error message when requesting the value of
4346 * a hidden option, ignore setting it. */
4347 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4348 && (!(options[opt_idx].flags & P_BOOL)
4349 || nextchar == '?'))
4350 errmsg = (char_u *)N_("E519: Option not supported");
4351 goto skip;
4352 }
4353
4354 flags = options[opt_idx].flags;
4355 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4356 }
4357 else
4358 {
4359 flags = P_STRING;
4360 if (key < 0)
4361 {
4362 key_name[0] = KEY2TERMCAP0(key);
4363 key_name[1] = KEY2TERMCAP1(key);
4364 }
4365 else
4366 {
4367 key_name[0] = KS_KEY;
4368 key_name[1] = (key & 0xff);
4369 }
4370 }
4371
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004372 /* Skip all options that are not window-local (used when showing
4373 * an already loaded buffer in a window). */
4374 if ((opt_flags & OPT_WINONLY)
4375 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4376 goto skip;
4377
Bram Moolenaara3227e22006-03-08 21:32:40 +00004378 /* Skip all options that are window-local (used for :vimgrep). */
4379 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4380 && options[opt_idx].var == VAR_WIN)
4381 goto skip;
4382
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004383 /* Disallow changing some options from modelines. */
4384 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004385 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004386 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004387 {
4388 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4389 goto skip;
4390 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004391#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004392 /* In diff mode some options are overruled. This avoids that
4393 * 'foldmethod' becomes "marker" instead of "diff" and that
4394 * "wrap" gets set. */
4395 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004396 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004397 && (options[opt_idx].indir == PV_FDM
4398 || options[opt_idx].indir == PV_WRAP))
4399 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004401 }
4402
4403#ifdef HAVE_SANDBOX
4404 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004405 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004406 {
4407 errmsg = (char_u *)_(e_sandbox);
4408 goto skip;
4409 }
4410#endif
4411
4412 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4413 {
4414 arg += len;
4415 cp_val = p_cp;
4416 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4417 {
4418 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4419 {
4420 cp_val = FALSE;
4421 arg += 3;
4422 }
4423 else /* "opt&vi": set to Vi default */
4424 {
4425 cp_val = TRUE;
4426 arg += 2;
4427 }
4428 }
4429 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4430 && arg[1] != NUL && !vim_iswhite(arg[1]))
4431 {
4432 errmsg = e_trailing;
4433 goto skip;
4434 }
4435 }
4436
4437 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004438 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4439 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004440 */
4441 if (nextchar == '?'
4442 || (prefix == 1
4443 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4444 && !(flags & P_BOOL)))
4445 {
4446 /*
4447 * print value
4448 */
4449 if (did_show)
4450 msg_putchar('\n'); /* cursor below last one */
4451 else
4452 {
4453 gotocmdline(TRUE); /* cursor at status line */
4454 did_show = TRUE; /* remember that we did a line */
4455 }
4456 if (opt_idx >= 0)
4457 {
4458 showoneopt(&options[opt_idx], opt_flags);
4459#ifdef FEAT_EVAL
4460 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004461 {
4462 /* Mention where the option was last set. */
4463 if (varp == options[opt_idx].var)
4464 last_set_msg(options[opt_idx].scriptID);
4465 else if ((int)options[opt_idx].indir & PV_WIN)
4466 last_set_msg(curwin->w_p_scriptID[
4467 (int)options[opt_idx].indir & PV_MASK]);
4468 else if ((int)options[opt_idx].indir & PV_BUF)
4469 last_set_msg(curbuf->b_p_scriptID[
4470 (int)options[opt_idx].indir & PV_MASK]);
4471 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004472#endif
4473 }
4474 else
4475 {
4476 char_u *p;
4477
4478 p = find_termcode(key_name);
4479 if (p == NULL)
4480 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004481 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004482 goto skip;
4483 }
4484 else
4485 (void)show_one_termcode(key_name, p, TRUE);
4486 }
4487 if (nextchar != '?'
4488 && nextchar != NUL && !vim_iswhite(afterchar))
4489 errmsg = e_trailing;
4490 }
4491 else
4492 {
4493 if (flags & P_BOOL) /* boolean */
4494 {
4495 if (nextchar == '=' || nextchar == ':')
4496 {
4497 errmsg = e_invarg;
4498 goto skip;
4499 }
4500
4501 /*
4502 * ":set opt!": invert
4503 * ":set opt&": reset to default value
4504 * ":set opt<": reset to global value
4505 */
4506 if (nextchar == '!')
4507 value = *(int *)(varp) ^ 1;
4508 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004509 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004510 ((flags & P_VI_DEF) || cp_val)
4511 ? VI_DEFAULT : VIM_DEFAULT];
4512 else if (nextchar == '<')
4513 {
4514 /* For 'autoread' -1 means to use global value. */
4515 if ((int *)varp == &curbuf->b_p_ar
4516 && opt_flags == OPT_LOCAL)
4517 value = -1;
4518 else
4519 value = *(int *)get_varp_scope(&(options[opt_idx]),
4520 OPT_GLOBAL);
4521 }
4522 else
4523 {
4524 /*
4525 * ":set invopt": invert
4526 * ":set opt" or ":set noopt": set or reset
4527 */
4528 if (nextchar != NUL && !vim_iswhite(afterchar))
4529 {
4530 errmsg = e_trailing;
4531 goto skip;
4532 }
4533 if (prefix == 2) /* inv */
4534 value = *(int *)(varp) ^ 1;
4535 else
4536 value = prefix;
4537 }
4538
4539 errmsg = set_bool_option(opt_idx, varp, (int)value,
4540 opt_flags);
4541 }
4542 else /* numeric or string */
4543 {
4544 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4545 || prefix != 1)
4546 {
4547 errmsg = e_invarg;
4548 goto skip;
4549 }
4550
4551 if (flags & P_NUM) /* numeric */
4552 {
4553 /*
4554 * Different ways to set a number option:
4555 * & set to default value
4556 * < set to global value
4557 * <xx> accept special key codes for 'wildchar'
4558 * c accept any non-digit for 'wildchar'
4559 * [-]0-9 set number
4560 * other error
4561 */
4562 ++arg;
4563 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004564 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565 ((flags & P_VI_DEF) || cp_val)
4566 ? VI_DEFAULT : VIM_DEFAULT];
4567 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004568 {
4569 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4570 * use the global value. */
4571 if ((long *)varp == &curbuf->b_p_ul
4572 && opt_flags == OPT_LOCAL)
4573 value = NO_LOCAL_UNDOLEVEL;
4574 else
4575 value = *(long *)get_varp_scope(
4576 &(options[opt_idx]), OPT_GLOBAL);
4577 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004578 else if (((long *)varp == &p_wc
4579 || (long *)varp == &p_wcm)
4580 && (*arg == '<'
4581 || *arg == '^'
4582 || ((!arg[1] || vim_iswhite(arg[1]))
4583 && !VIM_ISDIGIT(*arg))))
4584 {
4585 value = string_to_key(arg);
4586 if (value == 0 && (long *)varp != &p_wcm)
4587 {
4588 errmsg = e_invarg;
4589 goto skip;
4590 }
4591 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004592 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4593 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004594 /* Allow negative (for 'undolevels'), octal and
4595 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004596 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4597 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004598 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4599 {
4600 errmsg = e_invarg;
4601 goto skip;
4602 }
4603 }
4604 else
4605 {
4606 errmsg = (char_u *)N_("E521: Number required after =");
4607 goto skip;
4608 }
4609
4610 if (adding)
4611 value = *(long *)varp + value;
4612 if (prepending)
4613 value = *(long *)varp * value;
4614 if (removing)
4615 value = *(long *)varp - value;
4616 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004617 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004618 }
4619 else if (opt_idx >= 0) /* string */
4620 {
4621 char_u *save_arg = NULL;
4622 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004623 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004624 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004625 char_u *origval = NULL;
4626#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4627 char_u *saved_origval = NULL;
4628#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004629 unsigned newlen;
4630 int comma;
4631 int bs;
4632 int new_value_alloced; /* new string option
4633 was allocated */
4634
4635 /* When using ":set opt=val" for a global option
4636 * with a local value the local value will be
4637 * reset, use the global value here. */
4638 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004639 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004640 varp = options[opt_idx].var;
4641
4642 /* The old value is kept until we are sure that the
4643 * new value is valid. */
4644 oldval = *(char_u **)varp;
4645 if (nextchar == '&') /* set to default val */
4646 {
4647 newval = options[opt_idx].def_val[
4648 ((flags & P_VI_DEF) || cp_val)
4649 ? VI_DEFAULT : VIM_DEFAULT];
4650 if ((char_u **)varp == &p_bg)
4651 {
4652 /* guess the value of 'background' */
4653#ifdef FEAT_GUI
4654 if (gui.in_use)
4655 newval = gui_bg_default();
4656 else
4657#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004658 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004659 }
4660
4661 /* expand environment variables and ~ (since the
4662 * default value was already expanded, only
4663 * required when an environment variable was set
4664 * later */
4665 if (newval == NULL)
4666 newval = empty_option;
4667 else
4668 {
4669 s = option_expand(opt_idx, newval);
4670 if (s == NULL)
4671 s = newval;
4672 newval = vim_strsave(s);
4673 }
4674 new_value_alloced = TRUE;
4675 }
4676 else if (nextchar == '<') /* set to global val */
4677 {
4678 newval = vim_strsave(*(char_u **)get_varp_scope(
4679 &(options[opt_idx]), OPT_GLOBAL));
4680 new_value_alloced = TRUE;
4681 }
4682 else
4683 {
4684 ++arg; /* jump to after the '=' or ':' */
4685
4686 /*
4687 * Set 'keywordprg' to ":help" if an empty
4688 * value was passed to :set by the user.
4689 * Misuse errbuf[] for the resulting string.
4690 */
4691 if (varp == (char_u *)&p_kp
4692 && (*arg == NUL || *arg == ' '))
4693 {
4694 STRCPY(errbuf, ":help");
4695 save_arg = arg;
4696 arg = errbuf;
4697 }
4698 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004699 * Convert 'backspace' number to string, for
4700 * adding, prepending and removing string.
4701 */
4702 else if (varp == (char_u *)&p_bs
4703 && VIM_ISDIGIT(**(char_u **)varp))
4704 {
4705 i = getdigits((char_u **)varp);
4706 switch (i)
4707 {
4708 case 0:
4709 *(char_u **)varp = empty_option;
4710 break;
4711 case 1:
4712 *(char_u **)varp = vim_strsave(
4713 (char_u *)"indent,eol");
4714 break;
4715 case 2:
4716 *(char_u **)varp = vim_strsave(
4717 (char_u *)"indent,eol,start");
4718 break;
4719 }
4720 vim_free(oldval);
4721 oldval = *(char_u **)varp;
4722 }
4723 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004724 * Convert 'whichwrap' number to string, for
4725 * backwards compatibility with Vim 3.0.
4726 * Misuse errbuf[] for the resulting string.
4727 */
4728 else if (varp == (char_u *)&p_ww
4729 && VIM_ISDIGIT(*arg))
4730 {
4731 *errbuf = NUL;
4732 i = getdigits(&arg);
4733 if (i & 1)
4734 STRCAT(errbuf, "b,");
4735 if (i & 2)
4736 STRCAT(errbuf, "s,");
4737 if (i & 4)
4738 STRCAT(errbuf, "h,l,");
4739 if (i & 8)
4740 STRCAT(errbuf, "<,>,");
4741 if (i & 16)
4742 STRCAT(errbuf, "[,],");
4743 if (*errbuf != NUL) /* remove trailing , */
4744 errbuf[STRLEN(errbuf) - 1] = NUL;
4745 save_arg = arg;
4746 arg = errbuf;
4747 }
4748 /*
4749 * Remove '>' before 'dir' and 'bdir', for
4750 * backwards compatibility with version 3.0
4751 */
4752 else if ( *arg == '>'
4753 && (varp == (char_u *)&p_dir
4754 || varp == (char_u *)&p_bdir))
4755 {
4756 ++arg;
4757 }
4758
4759 /* When setting the local value of a global
4760 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004761 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004762 && (opt_flags & OPT_LOCAL))
4763 origval = *(char_u **)get_varp(
4764 &options[opt_idx]);
4765 else
4766 origval = oldval;
4767
4768 /*
4769 * Copy the new string into allocated memory.
4770 * Can't use set_string_option_direct(), because
4771 * we need to remove the backslashes.
4772 */
4773 /* get a bit too much */
4774 newlen = (unsigned)STRLEN(arg) + 1;
4775 if (adding || prepending || removing)
4776 newlen += (unsigned)STRLEN(origval) + 1;
4777 newval = alloc(newlen);
4778 if (newval == NULL) /* out of mem, don't change */
4779 break;
4780 s = newval;
4781
4782 /*
4783 * Copy the string, skip over escaped chars.
4784 * For MS-DOS and WIN32 backslashes before normal
4785 * file name characters are not removed, and keep
4786 * backslash at start, for "\\machine\path", but
4787 * do remove it for "\\\\machine\\path".
4788 * The reverse is found in ExpandOldSetting().
4789 */
4790 while (*arg && !vim_iswhite(*arg))
4791 {
4792 if (*arg == '\\' && arg[1] != NUL
4793#ifdef BACKSLASH_IN_FILENAME
4794 && !((flags & P_EXPAND)
4795 && vim_isfilec(arg[1])
4796 && (arg[1] != '\\'
4797 || (s == newval
4798 && arg[2] != '\\')))
4799#endif
4800 )
4801 ++arg; /* remove backslash */
4802#ifdef FEAT_MBYTE
4803 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004804 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004805 {
4806 /* copy multibyte char */
4807 mch_memmove(s, arg, (size_t)i);
4808 arg += i;
4809 s += i;
4810 }
4811 else
4812#endif
4813 *s++ = *arg++;
4814 }
4815 *s = NUL;
4816
4817 /*
4818 * Expand environment variables and ~.
4819 * Don't do it when adding without inserting a
4820 * comma.
4821 */
4822 if (!(adding || prepending || removing)
4823 || (flags & P_COMMA))
4824 {
4825 s = option_expand(opt_idx, newval);
4826 if (s != NULL)
4827 {
4828 vim_free(newval);
4829 newlen = (unsigned)STRLEN(s) + 1;
4830 if (adding || prepending || removing)
4831 newlen += (unsigned)STRLEN(origval) + 1;
4832 newval = alloc(newlen);
4833 if (newval == NULL)
4834 break;
4835 STRCPY(newval, s);
4836 }
4837 }
4838
4839 /* locate newval[] in origval[] when removing it
4840 * and when adding to avoid duplicates */
4841 i = 0; /* init for GCC */
4842 if (removing || (flags & P_NODUP))
4843 {
4844 i = (int)STRLEN(newval);
4845 bs = 0;
4846 for (s = origval; *s; ++s)
4847 {
4848 if ((!(flags & P_COMMA)
4849 || s == origval
4850 || (s[-1] == ',' && !(bs & 1)))
4851 && STRNCMP(s, newval, i) == 0
4852 && (!(flags & P_COMMA)
4853 || s[i] == ','
4854 || s[i] == NUL))
4855 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004856 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004857 * even number of backslashes or a single
4858 * backslash preceded by a comma before it
4859 * is recognized as a separator */
4860 if ((s > origval + 1
4861 && s[-1] == '\\'
4862 && s[-2] != ',')
4863 || (s == origval + 1
4864 && s[-1] == '\\'))
4865
Bram Moolenaar071d4272004-06-13 20:20:40 +00004866 ++bs;
4867 else
4868 bs = 0;
4869 }
4870
4871 /* do not add if already there */
4872 if ((adding || prepending) && *s)
4873 {
4874 prepending = FALSE;
4875 adding = FALSE;
4876 STRCPY(newval, origval);
4877 }
4878 }
4879
4880 /* concatenate the two strings; add a ',' if
4881 * needed */
4882 if (adding || prepending)
4883 {
4884 comma = ((flags & P_COMMA) && *origval != NUL
4885 && *newval != NUL);
4886 if (adding)
4887 {
4888 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004889 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004890 if (comma && i > 1
4891 && (flags & P_ONECOMMA) == P_ONECOMMA
4892 && origval[i - 1] == ','
4893 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004894 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004895 mch_memmove(newval + i + comma, newval,
4896 STRLEN(newval) + 1);
4897 mch_memmove(newval, origval, (size_t)i);
4898 }
4899 else
4900 {
4901 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004902 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004903 }
4904 if (comma)
4905 newval[i] = ',';
4906 }
4907
4908 /* Remove newval[] from origval[]. (Note: "i" has
4909 * been set above and is used here). */
4910 if (removing)
4911 {
4912 STRCPY(newval, origval);
4913 if (*s)
4914 {
4915 /* may need to remove a comma */
4916 if (flags & P_COMMA)
4917 {
4918 if (s == origval)
4919 {
4920 /* include comma after string */
4921 if (s[i] == ',')
4922 ++i;
4923 }
4924 else
4925 {
4926 /* include comma before string */
4927 --s;
4928 ++i;
4929 }
4930 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004931 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004932 }
4933 }
4934
4935 if (flags & P_FLAGLIST)
4936 {
4937 /* Remove flags that appear twice. */
4938 for (s = newval; *s; ++s)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004939 {
4940 /* if options have P_FLAGLIST and
4941 * P_ONECOMMA such as 'whichwrap' */
4942 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004943 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004944 if (*s != ',' && *(s + 1) == ','
4945 && vim_strchr(s + 2, *s) != NULL)
4946 {
4947 /* Remove the duplicated value and
4948 * the next comma. */
4949 STRMOVE(s, s + 2);
4950 s -= 2;
4951 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004952 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004953 else
4954 {
4955 if ((!(flags & P_COMMA) || *s != ',')
4956 && vim_strchr(s + 1, *s) != NULL)
4957 {
4958 STRMOVE(s, s + 1);
4959 --s;
4960 }
4961 }
4962 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004963 }
4964
4965 if (save_arg != NULL) /* number for 'whichwrap' */
4966 arg = save_arg;
4967 new_value_alloced = TRUE;
4968 }
4969
4970 /* Set the new value. */
4971 *(char_u **)(varp) = newval;
4972
Bram Moolenaar53744302015-07-17 17:38:22 +02004973#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004974 if (!starting
4975# ifdef FEAT_CRYPT
4976 && options[opt_idx].indir != PV_KEY
4977# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004978 && origval != NULL)
4979 /* origval may be freed by
4980 * did_set_string_option(), make a copy. */
4981 saved_origval = vim_strsave(origval);
4982#endif
4983
Bram Moolenaar071d4272004-06-13 20:20:40 +00004984 /* Handle side effects, and set the global value for
4985 * ":set" on local options. */
4986 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
4987 new_value_alloced, oldval, errbuf, opt_flags);
4988
4989 /* If error detected, print the error message. */
4990 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01004991 {
4992#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4993 vim_free(saved_origval);
4994#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004995 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01004996 }
Bram Moolenaar53744302015-07-17 17:38:22 +02004997#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4998 if (saved_origval != NULL)
4999 {
5000 char_u buf_type[7];
5001
5002 sprintf((char *)buf_type, "%s",
5003 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005004 set_vim_var_string(VV_OPTION_NEW,
5005 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005006 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5007 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5008 apply_autocmds(EVENT_OPTIONSET,
5009 (char_u *)options[opt_idx].fullname,
5010 NULL, FALSE, NULL);
5011 reset_v_option_vars();
5012 vim_free(saved_origval);
5013 }
5014#endif
5015
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016 }
5017 else /* key code option */
5018 {
5019 char_u *p;
5020
5021 if (nextchar == '&')
5022 {
5023 if (add_termcap_entry(key_name, TRUE) == FAIL)
5024 errmsg = (char_u *)N_("E522: Not found in termcap");
5025 }
5026 else
5027 {
5028 ++arg; /* jump to after the '=' or ':' */
5029 for (p = arg; *p && !vim_iswhite(*p); ++p)
5030 if (*p == '\\' && p[1] != NUL)
5031 ++p;
5032 nextchar = *p;
5033 *p = NUL;
5034 add_termcode(key_name, arg, FALSE);
5035 *p = nextchar;
5036 }
5037 if (full_screen)
5038 ttest(FALSE);
5039 redraw_all_later(CLEAR);
5040 }
5041 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005042
Bram Moolenaar071d4272004-06-13 20:20:40 +00005043 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005044 did_set_option(opt_idx, opt_flags,
5045 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005046 }
5047
5048skip:
5049 /*
5050 * Advance to next argument.
5051 * - skip until a blank found, taking care of backslashes
5052 * - skip blanks
5053 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5054 */
5055 for (i = 0; i < 2 ; ++i)
5056 {
5057 while (*arg != NUL && !vim_iswhite(*arg))
5058 if (*arg++ == '\\' && *arg != NUL)
5059 ++arg;
5060 arg = skipwhite(arg);
5061 if (*arg != '=')
5062 break;
5063 }
5064 }
5065
5066 if (errmsg != NULL)
5067 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005068 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005069 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005070 if (i + (arg - startarg) < IOSIZE)
5071 {
5072 /* append the argument with the error */
5073 STRCAT(IObuff, ": ");
5074 mch_memmove(IObuff + i, startarg, (arg - startarg));
5075 IObuff[i + (arg - startarg)] = NUL;
5076 }
5077 /* make sure all characters are printable */
5078 trans_characters(IObuff, IOSIZE);
5079
5080 ++no_wait_return; /* wait_return done later */
5081 emsg(IObuff); /* show error highlighted */
5082 --no_wait_return;
5083
5084 return FAIL;
5085 }
5086
5087 arg = skipwhite(arg);
5088 }
5089
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005090theend:
5091 if (silent_mode && did_show)
5092 {
5093 /* After displaying option values in silent mode. */
5094 silent_mode = FALSE;
5095 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5096 msg_putchar('\n');
5097 cursor_on(); /* msg_start() switches it off */
5098 out_flush();
5099 silent_mode = TRUE;
5100 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5101 }
5102
Bram Moolenaar071d4272004-06-13 20:20:40 +00005103 return OK;
5104}
5105
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005106/*
5107 * Call this when an option has been given a new value through a user command.
5108 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5109 */
5110 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005111did_set_option(
5112 int opt_idx,
5113 int opt_flags, /* possibly with OPT_MODELINE */
5114 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005115{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005116 long_u *p;
5117
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005118 options[opt_idx].flags |= P_WAS_SET;
5119
5120 /* When an option is set in the sandbox, from a modeline or in secure mode
5121 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005122 * flag. */
5123 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005124 if (secure
5125#ifdef HAVE_SANDBOX
5126 || sandbox != 0
5127#endif
5128 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005129 *p = *p | P_INSECURE;
5130 else if (new_value)
5131 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005132}
5133
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005135illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005136{
5137 if (errbuf == NULL)
5138 return (char_u *)"";
5139 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005140 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005141 return errbuf;
5142}
5143
5144/*
5145 * Convert a key name or string into a key value.
5146 * Used for 'wildchar' and 'cedit' options.
5147 */
5148 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005149string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005150{
5151 if (*arg == '<')
5152 return find_key_option(arg + 1);
5153 if (*arg == '^')
5154 return Ctrl_chr(arg[1]);
5155 return *arg;
5156}
5157
5158#ifdef FEAT_CMDWIN
5159/*
5160 * Check value of 'cedit' and set cedit_key.
5161 * Returns NULL if value is OK, error message otherwise.
5162 */
5163 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005164check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005165{
5166 int n;
5167
5168 if (*p_cedit == NUL)
5169 cedit_key = -1;
5170 else
5171 {
5172 n = string_to_key(p_cedit);
5173 if (vim_isprintc(n))
5174 return e_invarg;
5175 cedit_key = n;
5176 }
5177 return NULL;
5178}
5179#endif
5180
5181#ifdef FEAT_TITLE
5182/*
5183 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5184 * maketitle() to create and display it.
5185 * When switching the title or icon off, call mch_restore_title() to get
5186 * the old value back.
5187 */
5188 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005189did_set_title(
5190 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005191{
5192 if (starting != NO_SCREEN
5193#ifdef FEAT_GUI
5194 && !gui.starting
5195#endif
5196 )
5197 {
5198 maketitle();
5199 if (icon)
5200 {
5201 if (!p_icon)
5202 mch_restore_title(2);
5203 }
5204 else
5205 {
5206 if (!p_title)
5207 mch_restore_title(1);
5208 }
5209 }
5210}
5211#endif
5212
5213/*
5214 * set_options_bin - called when 'bin' changes value.
5215 */
5216 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005217set_options_bin(
5218 int oldval,
5219 int newval,
5220 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005221{
5222 /*
5223 * The option values that are changed when 'bin' changes are
5224 * copied when 'bin is set and restored when 'bin' is reset.
5225 */
5226 if (newval)
5227 {
5228 if (!oldval) /* switched on */
5229 {
5230 if (!(opt_flags & OPT_GLOBAL))
5231 {
5232 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5233 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5234 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5235 curbuf->b_p_et_nobin = curbuf->b_p_et;
5236 }
5237 if (!(opt_flags & OPT_LOCAL))
5238 {
5239 p_tw_nobin = p_tw;
5240 p_wm_nobin = p_wm;
5241 p_ml_nobin = p_ml;
5242 p_et_nobin = p_et;
5243 }
5244 }
5245
5246 if (!(opt_flags & OPT_GLOBAL))
5247 {
5248 curbuf->b_p_tw = 0; /* no automatic line wrap */
5249 curbuf->b_p_wm = 0; /* no automatic line wrap */
5250 curbuf->b_p_ml = 0; /* no modelines */
5251 curbuf->b_p_et = 0; /* no expandtab */
5252 }
5253 if (!(opt_flags & OPT_LOCAL))
5254 {
5255 p_tw = 0;
5256 p_wm = 0;
5257 p_ml = FALSE;
5258 p_et = FALSE;
5259 p_bin = TRUE; /* needed when called for the "-b" argument */
5260 }
5261 }
5262 else if (oldval) /* switched off */
5263 {
5264 if (!(opt_flags & OPT_GLOBAL))
5265 {
5266 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5267 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5268 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5269 curbuf->b_p_et = curbuf->b_p_et_nobin;
5270 }
5271 if (!(opt_flags & OPT_LOCAL))
5272 {
5273 p_tw = p_tw_nobin;
5274 p_wm = p_wm_nobin;
5275 p_ml = p_ml_nobin;
5276 p_et = p_et_nobin;
5277 }
5278 }
5279}
5280
5281#ifdef FEAT_VIMINFO
5282/*
5283 * Find the parameter represented by the given character (eg ', :, ", or /),
5284 * and return its associated value in the 'viminfo' string.
5285 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005286 * If the parameter is not specified in the string or there is no following
5287 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005288 */
5289 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005290get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005291{
5292 char_u *p;
5293
5294 p = find_viminfo_parameter(type);
5295 if (p != NULL && VIM_ISDIGIT(*p))
5296 return atoi((char *)p);
5297 return -1;
5298}
5299
5300/*
5301 * Find the parameter represented by the given character (eg ''', ':', '"', or
5302 * '/') in the 'viminfo' option and return a pointer to the string after it.
5303 * Return NULL if the parameter is not specified in the string.
5304 */
5305 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005306find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307{
5308 char_u *p;
5309
5310 for (p = p_viminfo; *p; ++p)
5311 {
5312 if (*p == type)
5313 return p + 1;
5314 if (*p == 'n') /* 'n' is always the last one */
5315 break;
5316 p = vim_strchr(p, ','); /* skip until next ',' */
5317 if (p == NULL) /* hit the end without finding parameter */
5318 break;
5319 }
5320 return NULL;
5321}
5322#endif
5323
5324/*
5325 * Expand environment variables for some string options.
5326 * These string options cannot be indirect!
5327 * If "val" is NULL expand the current value of the option.
5328 * Return pointer to NameBuff, or NULL when not expanded.
5329 */
5330 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005331option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005332{
5333 /* if option doesn't need expansion nothing to do */
5334 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5335 return NULL;
5336
5337 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5338 * expand_env() would truncate the string. */
5339 if (val != NULL && STRLEN(val) > MAXPATHL)
5340 return NULL;
5341
5342 if (val == NULL)
5343 val = *(char_u **)options[opt_idx].var;
5344
5345 /*
5346 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5347 * Escape spaces when expanding 'tags', they are used to separate file
5348 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005349 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350 */
5351 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005352 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005353#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005354 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5355#endif
5356 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005357 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5358 return NULL;
5359
5360 return NameBuff;
5361}
5362
5363/*
5364 * After setting various option values: recompute variables that depend on
5365 * option values.
5366 */
5367 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005368didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369{
5370 /* initialize the table for 'iskeyword' et.al. */
5371 (void)init_chartab();
5372
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005373#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005377 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005378#ifdef FEAT_SESSION
5379 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5380 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5381#endif
5382#ifdef FEAT_FOLDING
5383 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5384#endif
5385 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005386 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005387#ifdef FEAT_VIRTUALEDIT
5388 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5389#endif
5390#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5391 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5392#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005393#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005394 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005395 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005396 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005397 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005399#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5400 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5401#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005402#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005403 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5404#endif
5405#ifdef FEAT_CMDWIN
5406 /* set cedit_key */
5407 (void)check_cedit();
5408#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005409#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005410 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005411#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005412#ifdef FEAT_LINEBREAK
5413 /* initialize the table for 'breakat'. */
5414 fill_breakat_flags();
5415#endif
5416
5417}
5418
5419/*
5420 * More side effects of setting options.
5421 */
5422 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005423didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005424{
5425 /* Initialize the highlight_attr[] table. */
5426 (void)highlight_changed();
5427
5428 /* Parse default for 'wildmode' */
5429 check_opt_wim();
5430
5431 (void)set_chars_option(&p_lcs);
5432#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5433 /* Parse default for 'fillchars'. */
5434 (void)set_chars_option(&p_fcs);
5435#endif
5436
5437#ifdef FEAT_CLIPBOARD
5438 /* Parse default for 'clipboard' */
5439 (void)check_clipboard_option();
5440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005441}
5442
5443/*
5444 * Check for string options that are NULL (normally only termcap options).
5445 */
5446 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005447check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005448{
5449 int opt_idx;
5450
5451 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5452 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5453 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5454}
5455
5456/*
5457 * Check string options in a buffer for NULL value.
5458 */
5459 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005460check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005461{
5462#if defined(FEAT_QUICKFIX)
5463 check_string_option(&buf->b_p_bh);
5464 check_string_option(&buf->b_p_bt);
5465#endif
5466#ifdef FEAT_MBYTE
5467 check_string_option(&buf->b_p_fenc);
5468#endif
5469 check_string_option(&buf->b_p_ff);
5470#ifdef FEAT_FIND_ID
5471 check_string_option(&buf->b_p_def);
5472 check_string_option(&buf->b_p_inc);
5473# ifdef FEAT_EVAL
5474 check_string_option(&buf->b_p_inex);
5475# endif
5476#endif
5477#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5478 check_string_option(&buf->b_p_inde);
5479 check_string_option(&buf->b_p_indk);
5480#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005481#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5482 check_string_option(&buf->b_p_bexpr);
5483#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005484#if defined(FEAT_CRYPT)
5485 check_string_option(&buf->b_p_cm);
5486#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005487 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005488#if defined(FEAT_EVAL)
5489 check_string_option(&buf->b_p_fex);
5490#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005491#ifdef FEAT_CRYPT
5492 check_string_option(&buf->b_p_key);
5493#endif
5494 check_string_option(&buf->b_p_kp);
5495 check_string_option(&buf->b_p_mps);
5496 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005497 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005498 check_string_option(&buf->b_p_isk);
5499#ifdef FEAT_COMMENTS
5500 check_string_option(&buf->b_p_com);
5501#endif
5502#ifdef FEAT_FOLDING
5503 check_string_option(&buf->b_p_cms);
5504#endif
5505 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005506#ifdef FEAT_TEXTOBJ
5507 check_string_option(&buf->b_p_qe);
5508#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005509#ifdef FEAT_SYN_HL
5510 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005511 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005512#endif
5513#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005514 check_string_option(&buf->b_s.b_p_spc);
5515 check_string_option(&buf->b_s.b_p_spf);
5516 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517#endif
5518#ifdef FEAT_SEARCHPATH
5519 check_string_option(&buf->b_p_sua);
5520#endif
5521#ifdef FEAT_CINDENT
5522 check_string_option(&buf->b_p_cink);
5523 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005524 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005525#endif
5526#ifdef FEAT_AUTOCMD
5527 check_string_option(&buf->b_p_ft);
5528#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5530 check_string_option(&buf->b_p_cinw);
5531#endif
5532#ifdef FEAT_INS_EXPAND
5533 check_string_option(&buf->b_p_cpt);
5534#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005535#ifdef FEAT_COMPL_FUNC
5536 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005537 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005538#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005539#ifdef FEAT_KEYMAP
5540 check_string_option(&buf->b_p_keymap);
5541#endif
5542#ifdef FEAT_QUICKFIX
5543 check_string_option(&buf->b_p_gp);
5544 check_string_option(&buf->b_p_mp);
5545 check_string_option(&buf->b_p_efm);
5546#endif
5547 check_string_option(&buf->b_p_ep);
5548 check_string_option(&buf->b_p_path);
5549 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005550 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551#ifdef FEAT_INS_EXPAND
5552 check_string_option(&buf->b_p_dict);
5553 check_string_option(&buf->b_p_tsr);
5554#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005555#ifdef FEAT_LISP
5556 check_string_option(&buf->b_p_lw);
5557#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005558 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559}
5560
5561/*
5562 * Free the string allocated for an option.
5563 * Checks for the string being empty_option. This may happen if we're out of
5564 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5565 * check_options().
5566 * Does NOT check for P_ALLOCED flag!
5567 */
5568 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005569free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005570{
5571 if (p != empty_option)
5572 vim_free(p);
5573}
5574
5575 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005576clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005577{
5578 if (*pp != empty_option)
5579 vim_free(*pp);
5580 *pp = empty_option;
5581}
5582
5583 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005584check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585{
5586 if (*pp == NULL)
5587 *pp = empty_option;
5588}
5589
5590/*
5591 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5592 */
5593 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005594set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005595{
5596 int opt_idx;
5597
5598 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5599 if (options[opt_idx].var == (char_u *)p)
5600 {
5601 options[opt_idx].flags |= P_ALLOCED;
5602 return;
5603 }
5604 return; /* cannot happen: didn't find it! */
5605}
5606
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005607#if defined(FEAT_EVAL) || defined(PROTO)
5608/*
5609 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5610 * Return FALSE when it wasn't.
5611 * Return -1 for an unknown option.
5612 */
5613 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005614was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005615{
5616 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005617 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005618
5619 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005620 {
5621 flagp = insecure_flag(idx, opt_flags);
5622 return (*flagp & P_INSECURE) != 0;
5623 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005624 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005625 return -1;
5626}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005627
5628/*
5629 * Get a pointer to the flags used for the P_INSECURE flag of option
5630 * "opt_idx". For some local options a local flags field is used.
5631 */
5632 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005633insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005634{
5635 if (opt_flags & OPT_LOCAL)
5636 switch ((int)options[opt_idx].indir)
5637 {
5638#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005639 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005640#endif
5641#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005642# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005643 case PV_FDE: return &curwin->w_p_fde_flags;
5644 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005645# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005646# ifdef FEAT_BEVAL
5647 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5648# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005649# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005650 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005651# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005652 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005653# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005654 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005655# endif
5656#endif
5657 }
5658
5659 /* Nothing special, return global flags field. */
5660 return &options[opt_idx].flags;
5661}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005662#endif
5663
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005664#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005665static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005666
5667/*
5668 * Redraw the window title and/or tab page text later.
5669 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005670static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005671{
5672 need_maketitle = TRUE;
5673# ifdef FEAT_WINDOWS
5674 redraw_tabline = TRUE;
5675# endif
5676}
5677#endif
5678
Bram Moolenaar071d4272004-06-13 20:20:40 +00005679/*
5680 * Set a string option to a new value (without checking the effect).
5681 * The string is copied into allocated memory.
5682 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005683 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005684 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005685 */
5686 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005687set_string_option_direct(
5688 char_u *name,
5689 int opt_idx,
5690 char_u *val,
5691 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5692 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693{
5694 char_u *s;
5695 char_u **varp;
5696 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005697 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698
Bram Moolenaar89d40322006-08-29 15:30:07 +00005699 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005701 idx = findoption(name);
5702 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005703 {
5704 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005705 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005707 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708 }
5709
Bram Moolenaar89d40322006-08-29 15:30:07 +00005710 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005711 return;
5712
5713 s = vim_strsave(val);
5714 if (s != NULL)
5715 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005716 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005718 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719 free_string_option(*varp);
5720 *varp = s;
5721
5722 /* For buffer/window local option may also set the global value. */
5723 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005724 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725
Bram Moolenaar89d40322006-08-29 15:30:07 +00005726 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727
5728 /* When setting both values of a global option with a local value,
5729 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005730 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731 {
5732 free_string_option(*varp);
5733 *varp = empty_option;
5734 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005735# ifdef FEAT_EVAL
5736 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005737 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005738 set_sid == 0 ? current_SID : set_sid);
5739# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005740 }
5741}
5742
5743/*
5744 * Set global value for string option when it's a local option.
5745 */
5746 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005747set_string_option_global(
5748 int opt_idx, /* option index */
5749 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005750{
5751 char_u **p, *s;
5752
5753 /* the global value is always allocated */
5754 if (options[opt_idx].var == VAR_WIN)
5755 p = (char_u **)GLOBAL_WO(varp);
5756 else
5757 p = (char_u **)options[opt_idx].var;
5758 if (options[opt_idx].indir != PV_NONE
5759 && p != varp
5760 && (s = vim_strsave(*varp)) != NULL)
5761 {
5762 free_string_option(*p);
5763 *p = s;
5764 }
5765}
5766
5767/*
5768 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005769 *
5770 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005771 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005772 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005773set_string_option(
5774 int opt_idx,
5775 char_u *value,
5776 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005777{
5778 char_u *s;
5779 char_u **varp;
5780 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005781#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5782 char_u *saved_oldval = NULL;
5783#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005784 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785
5786 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005787 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005788
5789 s = vim_strsave(value);
5790 if (s != NULL)
5791 {
5792 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5793 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005794 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005795 ? OPT_GLOBAL : OPT_LOCAL)
5796 : opt_flags);
5797 oldval = *varp;
5798 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005799
5800#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005801 if (!starting
5802# ifdef FEAT_CRYPT
5803 && options[opt_idx].indir != PV_KEY
5804# endif
5805 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005806 saved_oldval = vim_strsave(oldval);
5807#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005808 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5809 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005810 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005811
5812 /* call autocomamnd after handling side effects */
5813#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5814 if (saved_oldval != NULL)
5815 {
5816 char_u buf_type[7];
5817 sprintf((char *)buf_type, "%s",
5818 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005819 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5820 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005821 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5822 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5823 reset_v_option_vars();
5824 vim_free(saved_oldval);
5825 }
5826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005827 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005828 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005829}
5830
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005831#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005832/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005833 * Return TRUE if "val" is a valid 'filetype' name.
5834 * Also used for 'syntax' and 'keymap'.
5835 */
5836 static int
5837valid_filetype(char_u *val)
5838{
5839 char_u *s;
5840
5841 for (s = val; *s != NUL; ++s)
5842 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5843 return FALSE;
5844 return TRUE;
5845}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005846#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005847
5848/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849 * Handle string options that need some action to perform when changed.
5850 * Returns NULL for success, or an error message for an error.
5851 */
5852 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005853did_set_string_option(
5854 int opt_idx, /* index in options[] table */
5855 char_u **varp, /* pointer to the option variable */
5856 int new_value_alloced, /* new value was allocated */
5857 char_u *oldval, /* previous value of the option */
5858 char_u *errbuf, /* buffer for errors, or NULL */
5859 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860{
5861 char_u *errmsg = NULL;
5862 char_u *s, *p;
5863 int did_chartab = FALSE;
5864 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005865 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005866#ifdef FEAT_GUI
5867 /* set when changing an option that only requires a redraw in the GUI */
5868 int redraw_gui_only = FALSE;
5869#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870
5871 /* Get the global option to compare with, otherwise we would have to check
5872 * two values for all local options. */
5873 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5874
5875 /* Disallow changing some options from secure mode */
5876 if ((secure
5877#ifdef HAVE_SANDBOX
5878 || sandbox != 0
5879#endif
5880 ) && (options[opt_idx].flags & P_SECURE))
5881 {
5882 errmsg = e_secure;
5883 }
5884
Bram Moolenaar7554da42016-11-25 22:04:13 +01005885 /* Check for a "normal" directory or file name in some options. Disallow a
5886 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005887 * are often illegal in a file name. Be more permissive if "secure" is off.
5888 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01005889 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005890 && vim_strpbrk(*varp, (char_u *)(secure
5891 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01005892 || ((options[opt_idx].flags & P_NDNAME)
5893 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005894 {
5895 errmsg = e_invarg;
5896 }
5897
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 /* 'term' */
5899 else if (varp == &T_NAME)
5900 {
5901 if (T_NAME[0] == NUL)
5902 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5903#ifdef FEAT_GUI
5904 if (gui.in_use)
5905 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5906 else if (term_is_gui(T_NAME))
5907 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5908#endif
5909 else if (set_termname(T_NAME) == FAIL)
5910 errmsg = (char_u *)N_("E522: Not found in termcap");
5911 else
5912 /* Screen colors may have changed. */
5913 redraw_later_clear();
5914 }
5915
5916 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005917 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005919 char_u *bkc = p_bkc;
5920 unsigned int *flags = &bkc_flags;
5921
5922 if (opt_flags & OPT_LOCAL)
5923 {
5924 bkc = curbuf->b_p_bkc;
5925 flags = &curbuf->b_bkc_flags;
5926 }
5927
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005928 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5929 /* make the local value empty: use the global value */
5930 *flags = 0;
5931 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005933 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5934 errmsg = e_invarg;
5935 if ((((int)*flags & BKC_AUTO) != 0)
5936 + (((int)*flags & BKC_YES) != 0)
5937 + (((int)*flags & BKC_NO) != 0) != 1)
5938 {
5939 /* Must have exactly one of "auto", "yes" and "no". */
5940 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5941 errmsg = e_invarg;
5942 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005943 }
5944 }
5945
5946 /* 'backupext' and 'patchmode' */
5947 else if (varp == &p_bex || varp == &p_pm)
5948 {
5949 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5950 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5951 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5952 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005953#ifdef FEAT_LINEBREAK
5954 /* 'breakindentopt' */
5955 else if (varp == &curwin->w_p_briopt)
5956 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005957 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005958 errmsg = e_invarg;
5959 }
5960#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005961
5962 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005963 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005965 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966 */
5967 else if ( varp == &p_isi
5968 || varp == &(curbuf->b_p_isk)
5969 || varp == &p_isp
5970 || varp == &p_isf)
5971 {
5972 if (init_chartab() == FAIL)
5973 {
5974 did_chartab = TRUE; /* need to restore it below */
5975 errmsg = e_invarg; /* error in value */
5976 }
5977 }
5978
5979 /* 'helpfile' */
5980 else if (varp == &p_hf)
5981 {
5982 /* May compute new values for $VIM and $VIMRUNTIME */
5983 if (didset_vim)
5984 {
5985 vim_setenv((char_u *)"VIM", (char_u *)"");
5986 didset_vim = FALSE;
5987 }
5988 if (didset_vimruntime)
5989 {
5990 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
5991 didset_vimruntime = FALSE;
5992 }
5993 }
5994
Bram Moolenaar1a384422010-07-14 19:53:30 +02005995#ifdef FEAT_SYN_HL
5996 /* 'colorcolumn' */
5997 else if (varp == &curwin->w_p_cc)
5998 errmsg = check_colorcolumn(curwin);
5999#endif
6000
Bram Moolenaar071d4272004-06-13 20:20:40 +00006001#ifdef FEAT_MULTI_LANG
6002 /* 'helplang' */
6003 else if (varp == &p_hlg)
6004 {
6005 /* Check for "", "ab", "ab,cd", etc. */
6006 for (s = p_hlg; *s != NUL; s += 3)
6007 {
6008 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6009 {
6010 errmsg = e_invarg;
6011 break;
6012 }
6013 if (s[2] == NUL)
6014 break;
6015 }
6016 }
6017#endif
6018
6019 /* 'highlight' */
6020 else if (varp == &p_hl)
6021 {
6022 if (highlight_changed() == FAIL)
6023 errmsg = e_invarg; /* invalid flags */
6024 }
6025
6026 /* 'nrformats' */
6027 else if (gvarp == &p_nf)
6028 {
6029 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6030 errmsg = e_invarg;
6031 }
6032
6033#ifdef FEAT_SESSION
6034 /* 'sessionoptions' */
6035 else if (varp == &p_ssop)
6036 {
6037 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6038 errmsg = e_invarg;
6039 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6040 {
6041 /* Don't allow both "sesdir" and "curdir". */
6042 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6043 errmsg = e_invarg;
6044 }
6045 }
6046 /* 'viewoptions' */
6047 else if (varp == &p_vop)
6048 {
6049 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6050 errmsg = e_invarg;
6051 }
6052#endif
6053
6054 /* 'scrollopt' */
6055#ifdef FEAT_SCROLLBIND
6056 else if (varp == &p_sbo)
6057 {
6058 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6059 errmsg = e_invarg;
6060 }
6061#endif
6062
6063 /* 'ambiwidth' */
6064#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006065 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006066 {
6067 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6068 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006069 else if (set_chars_option(&p_lcs) != NULL)
6070 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6071# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6072 else if (set_chars_option(&p_fcs) != NULL)
6073 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6074# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006075 }
6076#endif
6077
6078 /* 'background' */
6079 else if (varp == &p_bg)
6080 {
6081 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6082 {
6083#ifdef FEAT_EVAL
6084 int dark = (*p_bg == 'd');
6085#endif
6086
6087 init_highlight(FALSE, FALSE);
6088
6089#ifdef FEAT_EVAL
6090 if (dark != (*p_bg == 'd')
6091 && get_var_value((char_u *)"g:colors_name") != NULL)
6092 {
6093 /* The color scheme must have set 'background' back to another
6094 * value, that's not what we want here. Disable the color
6095 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006096 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006097 free_string_option(p_bg);
6098 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6099 check_string_option(&p_bg);
6100 init_highlight(FALSE, FALSE);
6101 }
6102#endif
6103 }
6104 else
6105 errmsg = e_invarg;
6106 }
6107
6108 /* 'wildmode' */
6109 else if (varp == &p_wim)
6110 {
6111 if (check_opt_wim() == FAIL)
6112 errmsg = e_invarg;
6113 }
6114
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006115#ifdef FEAT_CMDL_COMPL
6116 /* 'wildoptions' */
6117 else if (varp == &p_wop)
6118 {
6119 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6120 errmsg = e_invarg;
6121 }
6122#endif
6123
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124#ifdef FEAT_WAK
6125 /* 'winaltkeys' */
6126 else if (varp == &p_wak)
6127 {
6128 if (*p_wak == NUL
6129 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6130 errmsg = e_invarg;
6131# ifdef FEAT_MENU
6132# ifdef FEAT_GUI_MOTIF
6133 else if (gui.in_use)
6134 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6135# else
6136# ifdef FEAT_GUI_GTK
6137 else if (gui.in_use)
6138 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6139# endif
6140# endif
6141# endif
6142 }
6143#endif
6144
6145#ifdef FEAT_AUTOCMD
6146 /* 'eventignore' */
6147 else if (varp == &p_ei)
6148 {
6149 if (check_ei() == FAIL)
6150 errmsg = e_invarg;
6151 }
6152#endif
6153
6154#ifdef FEAT_MBYTE
6155 /* 'encoding' and 'fileencoding' */
6156 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6157 {
6158 if (gvarp == &p_fenc)
6159 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006160 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006161 errmsg = e_modifiable;
6162 else if (vim_strchr(*varp, ',') != NULL)
6163 /* No comma allowed in 'fileencoding'; catches confusing it
6164 * with 'fileencodings'. */
6165 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006166 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006167 {
6168# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006169 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006170 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006171# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006172 /* Add 'fileencoding' to the swap file. */
6173 ml_setflags(curbuf);
6174 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006175 }
6176 if (errmsg == NULL)
6177 {
6178 /* canonize the value, so that STRCMP() can be used on it */
6179 p = enc_canonize(*varp);
6180 if (p != NULL)
6181 {
6182 vim_free(*varp);
6183 *varp = p;
6184 }
6185 if (varp == &p_enc)
6186 {
6187 errmsg = mb_init();
6188# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006189 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006190# endif
6191 }
6192 }
6193
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006194# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006195 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6196 {
6197 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6198 if (STRCMP(p_tenc, "utf-8") != 0)
6199 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6200 }
6201# endif
6202
6203 if (errmsg == NULL)
6204 {
6205# ifdef FEAT_KEYMAP
6206 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6207 * (with another encoding). */
6208 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6209 (void)keymap_init();
6210# endif
6211
6212 /* When 'termencoding' is not empty and 'encoding' changes or when
6213 * 'termencoding' changes, need to setup for keyboard input and
6214 * display output conversion. */
6215 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6216 {
6217 convert_setup(&input_conv, p_tenc, p_enc);
6218 convert_setup(&output_conv, p_enc, p_tenc);
6219 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006220
6221# if defined(WIN3264) && defined(FEAT_MBYTE)
6222 /* $HOME may have characters in active code page. */
6223 if (varp == &p_enc)
6224 init_homedir();
6225# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006226 }
6227 }
6228#endif
6229
6230#if defined(FEAT_POSTSCRIPT)
6231 else if (varp == &p_penc)
6232 {
6233 /* Canonize printencoding if VIM standard one */
6234 p = enc_canonize(p_penc);
6235 if (p != NULL)
6236 {
6237 vim_free(p_penc);
6238 p_penc = p;
6239 }
6240 else
6241 {
6242 /* Ensure lower case and '-' for '_' */
6243 for (s = p_penc; *s != NUL; s++)
6244 {
6245 if (*s == '_')
6246 *s = '-';
6247 else
6248 *s = TOLOWER_ASC(*s);
6249 }
6250 }
6251 }
6252#endif
6253
Bram Moolenaar9372a112005-12-06 19:59:18 +00006254#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006255 else if (varp == &p_imak)
6256 {
6257 if (gui.in_use && !im_xim_isvalid_imactivate())
6258 errmsg = e_invarg;
6259 }
6260#endif
6261
6262#ifdef FEAT_KEYMAP
6263 else if (varp == &curbuf->b_p_keymap)
6264 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006265 if (!valid_filetype(*varp))
6266 errmsg = e_invarg;
6267 else
6268 /* load or unload key mapping tables */
6269 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006270
Bram Moolenaarfab06232009-03-04 03:13:35 +00006271 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006272 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006273 if (*curbuf->b_p_keymap != NUL)
6274 {
6275 /* Installed a new keymap, switch on using it. */
6276 curbuf->b_p_iminsert = B_IMODE_LMAP;
6277 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6278 curbuf->b_p_imsearch = B_IMODE_LMAP;
6279 }
6280 else
6281 {
6282 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6283 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6284 curbuf->b_p_iminsert = B_IMODE_NONE;
6285 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6286 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6287 }
6288 if ((opt_flags & OPT_LOCAL) == 0)
6289 {
6290 set_iminsert_global();
6291 set_imsearch_global();
6292 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293# ifdef FEAT_WINDOWS
6294 status_redraw_curbuf();
6295# endif
6296 }
6297 }
6298#endif
6299
6300 /* 'fileformat' */
6301 else if (gvarp == &p_ff)
6302 {
6303 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6304 errmsg = e_modifiable;
6305 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6306 errmsg = e_invarg;
6307 else
6308 {
6309 /* may also change 'textmode' */
6310 if (get_fileformat(curbuf) == EOL_DOS)
6311 curbuf->b_p_tx = TRUE;
6312 else
6313 curbuf->b_p_tx = FALSE;
6314#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006315 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006317 /* update flag in swap file */
6318 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006319 /* Redraw needed when switching to/from "mac": a CR in the text
6320 * will be displayed differently. */
6321 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6322 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006323 }
6324 }
6325
6326 /* 'fileformats' */
6327 else if (varp == &p_ffs)
6328 {
6329 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6330 errmsg = e_invarg;
6331 else
6332 {
6333 /* also change 'textauto' */
6334 if (*p_ffs == NUL)
6335 p_ta = FALSE;
6336 else
6337 p_ta = TRUE;
6338 }
6339 }
6340
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006341#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342 /* 'cryptkey' */
6343 else if (gvarp == &p_key)
6344 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006345# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006346 /* Make sure the ":set" command doesn't show the new value in the
6347 * history. */
6348 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006349# endif
6350 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6351 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006352 ml_set_crypt_key(curbuf, oldval,
6353 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006354 }
6355
6356 else if (gvarp == &p_cm)
6357 {
6358 if (opt_flags & OPT_LOCAL)
6359 p = curbuf->b_p_cm;
6360 else
6361 p = p_cm;
6362 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6363 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006364 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006365 errmsg = e_invarg;
6366 else
6367 {
6368 /* When setting the global value to empty, make it "zip". */
6369 if (*p_cm == NUL)
6370 {
6371 if (new_value_alloced)
6372 free_string_option(p_cm);
6373 p_cm = vim_strsave((char_u *)"zip");
6374 new_value_alloced = TRUE;
6375 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006376 /* When using ":set cm=name" the local value is going to be empty.
6377 * Do that here, otherwise the crypt functions will still use the
6378 * local value. */
6379 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6380 {
6381 free_string_option(curbuf->b_p_cm);
6382 curbuf->b_p_cm = empty_option;
6383 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006384
6385 /* Need to update the swapfile when the effective method changed.
6386 * Set "s" to the effective old value, "p" to the effective new
6387 * method and compare. */
6388 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6389 s = p_cm; /* was previously using the global value */
6390 else
6391 s = oldval;
6392 if (*curbuf->b_p_cm == NUL)
6393 p = p_cm; /* is now using the global value */
6394 else
6395 p = curbuf->b_p_cm;
6396 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006397 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006398
6399 /* If the global value changes need to update the swapfile for all
6400 * buffers using that value. */
6401 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6402 {
6403 buf_T *buf;
6404
Bram Moolenaar29323592016-07-24 22:04:11 +02006405 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006406 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006407 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006408 }
6409 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006410 }
6411#endif
6412
6413 /* 'matchpairs' */
6414 else if (gvarp == &p_mps)
6415 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006416#ifdef FEAT_MBYTE
6417 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006419 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006421 int x2 = -1;
6422 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006423
6424 if (*p != NUL)
6425 p += mb_ptr2len(p);
6426 if (*p != NUL)
6427 x2 = *p++;
6428 if (*p != NUL)
6429 {
6430 x3 = mb_ptr2char(p);
6431 p += mb_ptr2len(p);
6432 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006433 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006434 {
6435 errmsg = e_invarg;
6436 break;
6437 }
6438 if (*p == NUL)
6439 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006441 }
6442 else
6443#endif
6444 {
6445 /* Check for "x:y,x:y" */
6446 for (p = *varp; *p != NUL; p += 4)
6447 {
6448 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6449 {
6450 errmsg = e_invarg;
6451 break;
6452 }
6453 if (p[3] == NUL)
6454 break;
6455 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006456 }
6457 }
6458
6459#ifdef FEAT_COMMENTS
6460 /* 'comments' */
6461 else if (gvarp == &p_com)
6462 {
6463 for (s = *varp; *s; )
6464 {
6465 while (*s && *s != ':')
6466 {
6467 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6468 && !VIM_ISDIGIT(*s) && *s != '-')
6469 {
6470 errmsg = illegal_char(errbuf, *s);
6471 break;
6472 }
6473 ++s;
6474 }
6475 if (*s++ == NUL)
6476 errmsg = (char_u *)N_("E524: Missing colon");
6477 else if (*s == ',' || *s == NUL)
6478 errmsg = (char_u *)N_("E525: Zero length string");
6479 if (errmsg != NULL)
6480 break;
6481 while (*s && *s != ',')
6482 {
6483 if (*s == '\\' && s[1] != NUL)
6484 ++s;
6485 ++s;
6486 }
6487 s = skip_to_option_part(s);
6488 }
6489 }
6490#endif
6491
6492 /* 'listchars' */
6493 else if (varp == &p_lcs)
6494 {
6495 errmsg = set_chars_option(varp);
6496 }
6497
6498#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6499 /* 'fillchars' */
6500 else if (varp == &p_fcs)
6501 {
6502 errmsg = set_chars_option(varp);
6503 }
6504#endif
6505
6506#ifdef FEAT_CMDWIN
6507 /* 'cedit' */
6508 else if (varp == &p_cedit)
6509 {
6510 errmsg = check_cedit();
6511 }
6512#endif
6513
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006514 /* 'verbosefile' */
6515 else if (varp == &p_vfile)
6516 {
6517 verbose_stop();
6518 if (*p_vfile != NUL && verbose_open() == FAIL)
6519 errmsg = e_invarg;
6520 }
6521
Bram Moolenaar071d4272004-06-13 20:20:40 +00006522#ifdef FEAT_VIMINFO
6523 /* 'viminfo' */
6524 else if (varp == &p_viminfo)
6525 {
6526 for (s = p_viminfo; *s;)
6527 {
6528 /* Check it's a valid character */
6529 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6530 {
6531 errmsg = illegal_char(errbuf, *s);
6532 break;
6533 }
6534 if (*s == 'n') /* name is always last one */
6535 {
6536 break;
6537 }
6538 else if (*s == 'r') /* skip until next ',' */
6539 {
6540 while (*++s && *s != ',')
6541 ;
6542 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006543 else if (*s == '%')
6544 {
6545 /* optional number */
6546 while (vim_isdigit(*++s))
6547 ;
6548 }
6549 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006550 ++s; /* no extra chars */
6551 else /* must have a number */
6552 {
6553 while (vim_isdigit(*++s))
6554 ;
6555
6556 if (!VIM_ISDIGIT(*(s - 1)))
6557 {
6558 if (errbuf != NULL)
6559 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006560 sprintf((char *)errbuf,
6561 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006562 transchar_byte(*(s - 1)));
6563 errmsg = errbuf;
6564 }
6565 else
6566 errmsg = (char_u *)"";
6567 break;
6568 }
6569 }
6570 if (*s == ',')
6571 ++s;
6572 else if (*s)
6573 {
6574 if (errbuf != NULL)
6575 errmsg = (char_u *)N_("E527: Missing comma");
6576 else
6577 errmsg = (char_u *)"";
6578 break;
6579 }
6580 }
6581 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6582 errmsg = (char_u *)N_("E528: Must specify a ' value");
6583 }
6584#endif /* FEAT_VIMINFO */
6585
6586 /* terminal options */
6587 else if (istermoption(&options[opt_idx]) && full_screen)
6588 {
6589 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6590 if (varp == &T_CCO)
6591 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006592 int colors = atoi((char *)T_CCO);
6593
6594 /* Only reinitialize colors if t_Co value has really changed to
6595 * avoid expensive reload of colorscheme if t_Co is set to the
6596 * same value multiple times. */
6597 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006598 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006599 t_colors = colors;
6600 if (t_colors <= 1)
6601 {
6602 if (new_value_alloced)
6603 vim_free(T_CCO);
6604 T_CCO = empty_option;
6605 }
6606 /* We now have a different color setup, initialize it again. */
6607 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006608 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006609 }
6610 ttest(FALSE);
6611 if (varp == &T_ME)
6612 {
6613 out_str(T_ME);
6614 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006615#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006616 /* Since t_me has been set, this probably means that the user
6617 * wants to use this as default colors. Need to reset default
6618 * background/foreground colors. */
6619 mch_set_normal_colors();
6620#endif
6621 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006622 if (varp == &T_BE && termcap_active)
6623 {
6624 if (*T_BE == NUL)
6625 /* When clearing t_BE we assume the user no longer wants
6626 * bracketed paste, thus disable it by writing t_BD. */
6627 out_str(T_BD);
6628 else
6629 out_str(T_BE);
6630 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006631 }
6632
6633#ifdef FEAT_LINEBREAK
6634 /* 'showbreak' */
6635 else if (varp == &p_sbr)
6636 {
6637 for (s = p_sbr; *s; )
6638 {
6639 if (ptr2cells(s) != 1)
6640 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006641 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006642 }
6643 }
6644#endif
6645
6646#ifdef FEAT_GUI
6647 /* 'guifont' */
6648 else if (varp == &p_guifont)
6649 {
6650 if (gui.in_use)
6651 {
6652 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006653# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 /*
6655 * Put up a font dialog and let the user select a new value.
6656 * If this is cancelled go back to the old value but don't
6657 * give an error message.
6658 */
6659 if (STRCMP(p, "*") == 0)
6660 {
6661 p = gui_mch_font_dialog(oldval);
6662
6663 if (new_value_alloced)
6664 free_string_option(p_guifont);
6665
6666 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6667 new_value_alloced = TRUE;
6668 }
6669# endif
6670 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6671 {
6672# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6673 if (STRCMP(p_guifont, "*") == 0)
6674 {
6675 /* Dialog was cancelled: Keep the old value without giving
6676 * an error message. */
6677 if (new_value_alloced)
6678 free_string_option(p_guifont);
6679 p_guifont = vim_strsave(oldval);
6680 new_value_alloced = TRUE;
6681 }
6682 else
6683# endif
6684 errmsg = (char_u *)N_("E596: Invalid font(s)");
6685 }
6686 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006687 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006688 }
6689# ifdef FEAT_XFONTSET
6690 else if (varp == &p_guifontset)
6691 {
6692 if (STRCMP(p_guifontset, "*") == 0)
6693 errmsg = (char_u *)N_("E597: can't select fontset");
6694 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6695 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006696 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006697 }
6698# endif
6699# ifdef FEAT_MBYTE
6700 else if (varp == &p_guifontwide)
6701 {
6702 if (STRCMP(p_guifontwide, "*") == 0)
6703 errmsg = (char_u *)N_("E533: can't select wide font");
6704 else if (gui_get_wide_font() == FAIL)
6705 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006706 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006707 }
6708# endif
6709#endif
6710
6711#ifdef CURSOR_SHAPE
6712 /* 'guicursor' */
6713 else if (varp == &p_guicursor)
6714 errmsg = parse_shape_opt(SHAPE_CURSOR);
6715#endif
6716
6717#ifdef FEAT_MOUSESHAPE
6718 /* 'mouseshape' */
6719 else if (varp == &p_mouseshape)
6720 {
6721 errmsg = parse_shape_opt(SHAPE_MOUSE);
6722 update_mouseshape(-1);
6723 }
6724#endif
6725
6726#ifdef FEAT_PRINTER
6727 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006728 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006729# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006730 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006731 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006732# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733#endif
6734
6735#ifdef FEAT_LANGMAP
6736 /* 'langmap' */
6737 else if (varp == &p_langmap)
6738 langmap_set();
6739#endif
6740
6741#ifdef FEAT_LINEBREAK
6742 /* 'breakat' */
6743 else if (varp == &p_breakat)
6744 fill_breakat_flags();
6745#endif
6746
6747#ifdef FEAT_TITLE
6748 /* 'titlestring' and 'iconstring' */
6749 else if (varp == &p_titlestring || varp == &p_iconstring)
6750 {
6751# ifdef FEAT_STL_OPT
6752 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6753
6754 /* NULL => statusline syntax */
6755 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6756 stl_syntax |= flagval;
6757 else
6758 stl_syntax &= ~flagval;
6759# endif
6760 did_set_title(varp == &p_iconstring);
6761
6762 }
6763#endif
6764
6765#ifdef FEAT_GUI
6766 /* 'guioptions' */
6767 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006768 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006769 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006770 redraw_gui_only = TRUE;
6771 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772#endif
6773
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006774#if defined(FEAT_GUI_TABLINE)
6775 /* 'guitablabel' */
6776 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006777 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006778 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006779 redraw_gui_only = TRUE;
6780 }
6781 /* 'guitabtooltip' */
6782 else if (varp == &p_gtt)
6783 {
6784 redraw_gui_only = TRUE;
6785 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006786#endif
6787
Bram Moolenaar071d4272004-06-13 20:20:40 +00006788#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6789 /* 'ttymouse' */
6790 else if (varp == &p_ttym)
6791 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006792 /* Switch the mouse off before changing the escape sequences used for
6793 * that. */
6794 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6796 errmsg = e_invarg;
6797 else
6798 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006799 if (termcap_active)
6800 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801 }
6802#endif
6803
Bram Moolenaar071d4272004-06-13 20:20:40 +00006804 /* 'selection' */
6805 else if (varp == &p_sel)
6806 {
6807 if (*p_sel == NUL
6808 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6809 errmsg = e_invarg;
6810 }
6811
6812 /* 'selectmode' */
6813 else if (varp == &p_slm)
6814 {
6815 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6816 errmsg = e_invarg;
6817 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006818
6819#ifdef FEAT_BROWSE
6820 /* 'browsedir' */
6821 else if (varp == &p_bsdir)
6822 {
6823 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6824 && !mch_isdir(p_bsdir))
6825 errmsg = e_invarg;
6826 }
6827#endif
6828
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829 /* 'keymodel' */
6830 else if (varp == &p_km)
6831 {
6832 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6833 errmsg = e_invarg;
6834 else
6835 {
6836 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6837 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6838 }
6839 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006840
6841 /* 'mousemodel' */
6842 else if (varp == &p_mousem)
6843 {
6844 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6845 errmsg = e_invarg;
6846#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6847 else if (*p_mousem != *oldval)
6848 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6849 * to create or delete the popup menus. */
6850 gui_motif_update_mousemodel(root_menu);
6851#endif
6852 }
6853
6854 /* 'switchbuf' */
6855 else if (varp == &p_swb)
6856 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006857 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006858 errmsg = e_invarg;
6859 }
6860
6861 /* 'debug' */
6862 else if (varp == &p_debug)
6863 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006864 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006865 errmsg = e_invarg;
6866 }
6867
6868 /* 'display' */
6869 else if (varp == &p_dy)
6870 {
6871 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6872 errmsg = e_invarg;
6873 else
6874 (void)init_chartab();
6875
6876 }
6877
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006878#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006879 /* 'eadirection' */
6880 else if (varp == &p_ead)
6881 {
6882 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6883 errmsg = e_invarg;
6884 }
6885#endif
6886
6887#ifdef FEAT_CLIPBOARD
6888 /* 'clipboard' */
6889 else if (varp == &p_cb)
6890 errmsg = check_clipboard_option();
6891#endif
6892
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006893#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006894 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6895 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006896 else if (varp == &(curwin->w_s->b_p_spl)
6897 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006898 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006899 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006900 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006901 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006902 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006903 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006904 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006905 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006906 /* 'spellsuggest' */
6907 else if (varp == &p_sps)
6908 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006909 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006910 errmsg = e_invarg;
6911 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006912 /* 'mkspellmem' */
6913 else if (varp == &p_msm)
6914 {
6915 if (spell_check_msm() != OK)
6916 errmsg = e_invarg;
6917 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006918#endif
6919
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920#ifdef FEAT_QUICKFIX
6921 /* When 'bufhidden' is set, check for valid value. */
6922 else if (gvarp == &p_bh)
6923 {
6924 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6925 errmsg = e_invarg;
6926 }
6927
6928 /* When 'buftype' is set, check for valid value. */
6929 else if (gvarp == &p_bt)
6930 {
6931 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6932 errmsg = e_invarg;
6933 else
6934 {
6935# ifdef FEAT_WINDOWS
6936 if (curwin->w_status_height)
6937 {
6938 curwin->w_redr_status = TRUE;
6939 redraw_later(VALID);
6940 }
6941# endif
6942 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006943# ifdef FEAT_TITLE
6944 redraw_titles();
6945# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 }
6947 }
6948#endif
6949
6950#ifdef FEAT_STL_OPT
6951 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006952 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006953 {
6954 int wid;
6955
6956 if (varp == &p_ruf) /* reset ru_wid first */
6957 ru_wid = 0;
6958 s = *varp;
6959 if (varp == &p_ruf && *s == '%')
6960 {
6961 /* set ru_wid if 'ruf' starts with "%99(" */
6962 if (*++s == '-') /* ignore a '-' */
6963 s++;
6964 wid = getdigits(&s);
6965 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6966 ru_wid = wid;
6967 else
6968 errmsg = check_stl_option(p_ruf);
6969 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006970 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006971 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006973 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006974 comp_col();
6975 }
6976#endif
6977
6978#ifdef FEAT_INS_EXPAND
6979 /* check if it is a valid value for 'complete' -- Acevedo */
6980 else if (gvarp == &p_cpt)
6981 {
6982 for (s = *varp; *s;)
6983 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006984 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006985 s++;
6986 if (!*s)
6987 break;
6988 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6989 {
6990 errmsg = illegal_char(errbuf, *s);
6991 break;
6992 }
6993 if (*++s != NUL && *s != ',' && *s != ' ')
6994 {
6995 if (s[-1] == 'k' || s[-1] == 's')
6996 {
6997 /* skip optional filename after 'k' and 's' */
6998 while (*s && *s != ',' && *s != ' ')
6999 {
7000 if (*s == '\\')
7001 ++s;
7002 ++s;
7003 }
7004 }
7005 else
7006 {
7007 if (errbuf != NULL)
7008 {
7009 sprintf((char *)errbuf,
7010 _("E535: Illegal character after <%c>"),
7011 *--s);
7012 errmsg = errbuf;
7013 }
7014 else
7015 errmsg = (char_u *)"";
7016 break;
7017 }
7018 }
7019 }
7020 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007021
7022 /* 'completeopt' */
7023 else if (varp == &p_cot)
7024 {
7025 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7026 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007027 else
7028 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007029 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007030#endif /* FEAT_INS_EXPAND */
7031
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007032#ifdef FEAT_SIGNS
7033 /* 'signcolumn' */
7034 else if (varp == &curwin->w_p_scl)
7035 {
7036 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7037 errmsg = e_invarg;
7038 }
7039#endif
7040
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041
7042#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007043 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044 else if (varp == &p_toolbar)
7045 {
7046 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7047 &toolbar_flags, TRUE) != OK)
7048 errmsg = e_invarg;
7049 else
7050 {
7051 out_flush();
7052 gui_mch_show_toolbar((toolbar_flags &
7053 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7054 }
7055 }
7056#endif
7057
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007058#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059 /* 'toolbariconsize': GTK+ 2 only */
7060 else if (varp == &p_tbis)
7061 {
7062 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7063 errmsg = e_invarg;
7064 else
7065 {
7066 out_flush();
7067 gui_mch_show_toolbar((toolbar_flags &
7068 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7069 }
7070 }
7071#endif
7072
7073 /* 'pastetoggle': translate key codes like in a mapping */
7074 else if (varp == &p_pt)
7075 {
7076 if (*p_pt)
7077 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007078 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007079 if (p != NULL)
7080 {
7081 if (new_value_alloced)
7082 free_string_option(p_pt);
7083 p_pt = p;
7084 new_value_alloced = TRUE;
7085 }
7086 }
7087 }
7088
7089 /* 'backspace' */
7090 else if (varp == &p_bs)
7091 {
7092 if (VIM_ISDIGIT(*p_bs))
7093 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007094 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007095 errmsg = e_invarg;
7096 }
7097 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7098 errmsg = e_invarg;
7099 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007100 else if (varp == &p_bo)
7101 {
7102 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7103 errmsg = e_invarg;
7104 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007105
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007106 /* 'tagcase' */
7107 else if (gvarp == &p_tc)
7108 {
7109 unsigned int *flags;
7110
7111 if (opt_flags & OPT_LOCAL)
7112 {
7113 p = curbuf->b_p_tc;
7114 flags = &curbuf->b_tc_flags;
7115 }
7116 else
7117 {
7118 p = p_tc;
7119 flags = &tc_flags;
7120 }
7121
7122 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7123 /* make the local value empty: use the global value */
7124 *flags = 0;
7125 else if (*p == NUL
7126 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7127 errmsg = e_invarg;
7128 }
7129
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007130#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007131 /* 'casemap' */
7132 else if (varp == &p_cmp)
7133 {
7134 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7135 errmsg = e_invarg;
7136 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007137#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007138
7139#ifdef FEAT_DIFF
7140 /* 'diffopt' */
7141 else if (varp == &p_dip)
7142 {
7143 if (diffopt_changed() == FAIL)
7144 errmsg = e_invarg;
7145 }
7146#endif
7147
7148#ifdef FEAT_FOLDING
7149 /* 'foldmethod' */
7150 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7151 {
7152 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7153 || *curwin->w_p_fdm == NUL)
7154 errmsg = e_invarg;
7155 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007156 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007158 if (foldmethodIsDiff(curwin))
7159 newFoldLevel();
7160 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007161 }
7162# ifdef FEAT_EVAL
7163 /* 'foldexpr' */
7164 else if (varp == &curwin->w_p_fde)
7165 {
7166 if (foldmethodIsExpr(curwin))
7167 foldUpdateAll(curwin);
7168 }
7169# endif
7170 /* 'foldmarker' */
7171 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7172 {
7173 p = vim_strchr(*varp, ',');
7174 if (p == NULL)
7175 errmsg = (char_u *)N_("E536: comma required");
7176 else if (p == *varp || p[1] == NUL)
7177 errmsg = e_invarg;
7178 else if (foldmethodIsMarker(curwin))
7179 foldUpdateAll(curwin);
7180 }
7181 /* 'commentstring' */
7182 else if (gvarp == &p_cms)
7183 {
7184 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7185 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7186 }
7187 /* 'foldopen' */
7188 else if (varp == &p_fdo)
7189 {
7190 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7191 errmsg = e_invarg;
7192 }
7193 /* 'foldclose' */
7194 else if (varp == &p_fcl)
7195 {
7196 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7197 errmsg = e_invarg;
7198 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007199 /* 'foldignore' */
7200 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7201 {
7202 if (foldmethodIsIndent(curwin))
7203 foldUpdateAll(curwin);
7204 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007205#endif
7206
7207#ifdef FEAT_VIRTUALEDIT
7208 /* 'virtualedit' */
7209 else if (varp == &p_ve)
7210 {
7211 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7212 errmsg = e_invarg;
7213 else if (STRCMP(p_ve, oldval) != 0)
7214 {
7215 /* Recompute cursor position in case the new 've' setting
7216 * changes something. */
7217 validate_virtcol();
7218 coladvance(curwin->w_virtcol);
7219 }
7220 }
7221#endif
7222
7223#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7224 else if (varp == &p_csqf)
7225 {
7226 if (p_csqf != NULL)
7227 {
7228 p = p_csqf;
7229 while (*p != NUL)
7230 {
7231 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7232 || p[1] == NUL
7233 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7234 || (p[2] != NUL && p[2] != ','))
7235 {
7236 errmsg = e_invarg;
7237 break;
7238 }
7239 else if (p[2] == NUL)
7240 break;
7241 else
7242 p += 3;
7243 }
7244 }
7245 }
7246#endif
7247
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007248#ifdef FEAT_CINDENT
7249 /* 'cinoptions' */
7250 else if (gvarp == &p_cino)
7251 {
7252 /* TODO: recognize errors */
7253 parse_cino(curbuf);
7254 }
7255#endif
7256
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007257#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007258 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007259 else if (varp == &p_rop && gui.in_use)
7260 {
7261 if (!gui_mch_set_rendering_options(p_rop))
7262 errmsg = e_invarg;
7263 }
7264#endif
7265
Bram Moolenaard0b51382016-11-04 15:23:45 +01007266#ifdef FEAT_AUTOCMD
7267 else if (gvarp == &p_ft)
7268 {
7269 if (!valid_filetype(*varp))
7270 errmsg = e_invarg;
7271 }
7272#endif
7273
7274#ifdef FEAT_SYN_HL
7275 else if (gvarp == &p_syn)
7276 {
7277 if (!valid_filetype(*varp))
7278 errmsg = e_invarg;
7279 }
7280#endif
7281
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 /* Options that are a list of flags. */
7283 else
7284 {
7285 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007286 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007287 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007288 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007289 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007290 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007291 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007292 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007293 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007294#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007295 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007296 p = (char_u *)COCU_ALL;
7297#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007298 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007299 {
7300#ifdef FEAT_MOUSE
7301 p = (char_u *)MOUSE_ALL;
7302#else
7303 if (*p_mouse != NUL)
7304 errmsg = (char_u *)N_("E538: No mouse support");
7305#endif
7306 }
7307#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007308 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007309 p = (char_u *)GO_ALL;
7310#endif
7311 if (p != NULL)
7312 {
7313 for (s = *varp; *s; ++s)
7314 if (vim_strchr(p, *s) == NULL)
7315 {
7316 errmsg = illegal_char(errbuf, *s);
7317 break;
7318 }
7319 }
7320 }
7321
7322 /*
7323 * If error detected, restore the previous value.
7324 */
7325 if (errmsg != NULL)
7326 {
7327 if (new_value_alloced)
7328 free_string_option(*varp);
7329 *varp = oldval;
7330 /*
7331 * When resetting some values, need to act on it.
7332 */
7333 if (did_chartab)
7334 (void)init_chartab();
7335 if (varp == &p_hl)
7336 (void)highlight_changed();
7337 }
7338 else
7339 {
7340#ifdef FEAT_EVAL
7341 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007342 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007343#endif
7344 /*
7345 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007346 * Use "free_oldval", because recursiveness may change the flags under
7347 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007348 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007349 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350 free_string_option(oldval);
7351 if (new_value_alloced)
7352 options[opt_idx].flags |= P_ALLOCED;
7353 else
7354 options[opt_idx].flags &= ~P_ALLOCED;
7355
7356 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007357 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358 {
7359 /* global option with local value set to use global value; free
7360 * the local value and make it empty */
7361 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7362 free_string_option(*(char_u **)p);
7363 *(char_u **)p = empty_option;
7364 }
7365
7366 /* May set global value for local option. */
7367 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7368 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007369
7370#ifdef FEAT_AUTOCMD
7371 /*
7372 * Trigger the autocommand only after setting the flags.
7373 */
7374# ifdef FEAT_SYN_HL
7375 /* When 'syntax' is set, load the syntax of that name */
7376 if (varp == &(curbuf->b_p_syn))
7377 {
7378 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7379 curbuf->b_fname, TRUE, curbuf);
7380 }
7381# endif
7382 else if (varp == &(curbuf->b_p_ft))
7383 {
7384 /* 'filetype' is set, trigger the FileType autocommand */
7385 did_filetype = TRUE;
7386 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7387 curbuf->b_fname, TRUE, curbuf);
7388 }
7389#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007390#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007391 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007392 {
7393 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007394 char_u *q = curwin->w_s->b_p_spl;
7395
7396 /* Skip the first name if it is "cjk". */
7397 if (STRNCMP(q, "cjk,", 4) == 0)
7398 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007399
7400 /*
7401 * Source the spell/LANG.vim in 'runtimepath'.
7402 * They could set 'spellcapcheck' depending on the language.
7403 * Use the first name in 'spelllang' up to '_region' or
7404 * '.encoding'.
7405 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007406 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007407 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7408 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007409 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007410 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007411 }
7412#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007413 }
7414
7415#ifdef FEAT_MOUSE
7416 if (varp == &p_mouse)
7417 {
7418# ifdef FEAT_MOUSE_TTY
7419 if (*p_mouse == NUL)
7420 mch_setmouse(FALSE); /* switch mouse off */
7421 else
7422# endif
7423 setmouse(); /* in case 'mouse' changed */
7424 }
7425#endif
7426
Bram Moolenaar913077c2012-03-28 19:59:04 +02007427 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007428 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007429 curwin->w_set_curswant = TRUE;
7430
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007431#ifdef FEAT_GUI
7432 /* check redraw when it's not a GUI option or the GUI is active. */
7433 if (!redraw_gui_only || gui.in_use)
7434#endif
7435 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007436
7437 return errmsg;
7438}
7439
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007440#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007441/*
7442 * Simple int comparison function for use with qsort()
7443 */
7444 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007445int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007446{
7447 return *(const int *)a - *(const int *)b;
7448}
7449
7450/*
7451 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7452 * Returns error message, NULL if it's OK.
7453 */
7454 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007455check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007456{
7457 char_u *s;
7458 int col;
7459 int count = 0;
7460 int color_cols[256];
7461 int i;
7462 int j = 0;
7463
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007464 if (wp->w_buffer == NULL)
7465 return NULL; /* buffer was closed */
7466
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007467 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007468 {
7469 if (*s == '-' || *s == '+')
7470 {
7471 /* -N and +N: add to 'textwidth' */
7472 col = (*s == '-') ? -1 : 1;
7473 ++s;
7474 if (!VIM_ISDIGIT(*s))
7475 return e_invarg;
7476 col = col * getdigits(&s);
7477 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007478 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007479 col += wp->w_buffer->b_p_tw;
7480 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007481 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007482 }
7483 else if (VIM_ISDIGIT(*s))
7484 col = getdigits(&s);
7485 else
7486 return e_invarg;
7487 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007488skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007489 if (*s == NUL)
7490 break;
7491 if (*s != ',')
7492 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007493 if (*++s == NUL)
7494 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007495 }
7496
7497 vim_free(wp->w_p_cc_cols);
7498 if (count == 0)
7499 wp->w_p_cc_cols = NULL;
7500 else
7501 {
7502 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7503 if (wp->w_p_cc_cols != NULL)
7504 {
7505 /* sort the columns for faster usage on screen redraw inside
7506 * win_line() */
7507 qsort(color_cols, count, sizeof(int), int_cmp);
7508
7509 for (i = 0; i < count; ++i)
7510 /* skip duplicates */
7511 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7512 wp->w_p_cc_cols[j++] = color_cols[i];
7513 wp->w_p_cc_cols[j] = -1; /* end marker */
7514 }
7515 }
7516
7517 return NULL; /* no error */
7518}
7519#endif
7520
Bram Moolenaar071d4272004-06-13 20:20:40 +00007521/*
7522 * Handle setting 'listchars' or 'fillchars'.
7523 * Returns error message, NULL if it's OK.
7524 */
7525 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007526set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527{
7528 int round, i, len, entries;
7529 char_u *p, *s;
7530 int c1, c2 = 0;
7531 struct charstab
7532 {
7533 int *cp;
7534 char *name;
7535 };
7536#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7537 static struct charstab filltab[] =
7538 {
7539 {&fill_stl, "stl"},
7540 {&fill_stlnc, "stlnc"},
7541 {&fill_vert, "vert"},
7542 {&fill_fold, "fold"},
7543 {&fill_diff, "diff"},
7544 };
7545#endif
7546 static struct charstab lcstab[] =
7547 {
7548 {&lcs_eol, "eol"},
7549 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007550 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007551 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007552 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007553 {&lcs_tab2, "tab"},
7554 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007555#ifdef FEAT_CONCEAL
7556 {&lcs_conceal, "conceal"},
7557#else
7558 {NULL, "conceal"},
7559#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007560 };
7561 struct charstab *tab;
7562
7563#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7564 if (varp == &p_lcs)
7565#endif
7566 {
7567 tab = lcstab;
7568 entries = sizeof(lcstab) / sizeof(struct charstab);
7569 }
7570#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7571 else
7572 {
7573 tab = filltab;
7574 entries = sizeof(filltab) / sizeof(struct charstab);
7575 }
7576#endif
7577
7578 /* first round: check for valid value, second round: assign values */
7579 for (round = 0; round <= 1; ++round)
7580 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007581 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007582 {
7583 /* After checking that the value is valid: set defaults: space for
7584 * 'fillchars', NUL for 'listchars' */
7585 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007586 if (tab[i].cp != NULL)
7587 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007588 if (varp == &p_lcs)
7589 lcs_tab1 = NUL;
7590#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7591 else
7592 fill_diff = '-';
7593#endif
7594 }
7595 p = *varp;
7596 while (*p)
7597 {
7598 for (i = 0; i < entries; ++i)
7599 {
7600 len = (int)STRLEN(tab[i].name);
7601 if (STRNCMP(p, tab[i].name, len) == 0
7602 && p[len] == ':'
7603 && p[len + 1] != NUL)
7604 {
7605 s = p + len + 1;
7606#ifdef FEAT_MBYTE
7607 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007608 if (mb_char2cells(c1) > 1)
7609 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007610#else
7611 c1 = *s++;
7612#endif
7613 if (tab[i].cp == &lcs_tab2)
7614 {
7615 if (*s == NUL)
7616 continue;
7617#ifdef FEAT_MBYTE
7618 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007619 if (mb_char2cells(c2) > 1)
7620 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007621#else
7622 c2 = *s++;
7623#endif
7624 }
7625 if (*s == ',' || *s == NUL)
7626 {
7627 if (round)
7628 {
7629 if (tab[i].cp == &lcs_tab2)
7630 {
7631 lcs_tab1 = c1;
7632 lcs_tab2 = c2;
7633 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007634 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007635 *(tab[i].cp) = c1;
7636
7637 }
7638 p = s;
7639 break;
7640 }
7641 }
7642 }
7643
7644 if (i == entries)
7645 return e_invarg;
7646 if (*p == ',')
7647 ++p;
7648 }
7649 }
7650
7651 return NULL; /* no error */
7652}
7653
7654#ifdef FEAT_STL_OPT
7655/*
7656 * Check validity of options with the 'statusline' format.
7657 * Return error message or NULL.
7658 */
7659 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007660check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661{
7662 int itemcnt = 0;
7663 int groupdepth = 0;
7664 static char_u errbuf[80];
7665
7666 while (*s && itemcnt < STL_MAX_ITEM)
7667 {
7668 /* Check for valid keys after % sequences */
7669 while (*s && *s != '%')
7670 s++;
7671 if (!*s)
7672 break;
7673 s++;
7674 if (*s != '%' && *s != ')')
7675 ++itemcnt;
7676 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7677 {
7678 s++;
7679 continue;
7680 }
7681 if (*s == ')')
7682 {
7683 s++;
7684 if (--groupdepth < 0)
7685 break;
7686 continue;
7687 }
7688 if (*s == '-')
7689 s++;
7690 while (VIM_ISDIGIT(*s))
7691 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007692 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007693 continue;
7694 if (*s == '.')
7695 {
7696 s++;
7697 while (*s && VIM_ISDIGIT(*s))
7698 s++;
7699 }
7700 if (*s == '(')
7701 {
7702 groupdepth++;
7703 continue;
7704 }
7705 if (vim_strchr(STL_ALL, *s) == NULL)
7706 {
7707 return illegal_char(errbuf, *s);
7708 }
7709 if (*s == '{')
7710 {
7711 s++;
7712 while (*s != '}' && *s)
7713 s++;
7714 if (*s != '}')
7715 return (char_u *)N_("E540: Unclosed expression sequence");
7716 }
7717 }
7718 if (itemcnt >= STL_MAX_ITEM)
7719 return (char_u *)N_("E541: too many items");
7720 if (groupdepth != 0)
7721 return (char_u *)N_("E542: unbalanced groups");
7722 return NULL;
7723}
7724#endif
7725
7726#ifdef FEAT_CLIPBOARD
7727/*
7728 * Extract the items in the 'clipboard' option and set global values.
7729 */
7730 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007731check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007732{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007733 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007734 int new_autoselect_star = FALSE;
7735 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007736 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007737 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007738 regprog_T *new_exclude_prog = NULL;
7739 char_u *errmsg = NULL;
7740 char_u *p;
7741
7742 for (p = p_cb; *p != NUL; )
7743 {
7744 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7745 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007746 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747 p += 7;
7748 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007749 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007750 && (p[11] == ',' || p[11] == NUL))
7751 {
7752 new_unnamed |= CLIP_UNNAMED_PLUS;
7753 p += 11;
7754 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007756 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007757 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007758 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759 p += 10;
7760 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007761 else if (STRNCMP(p, "autoselectplus", 14) == 0
7762 && (p[14] == ',' || p[14] == NUL))
7763 {
7764 new_autoselect_plus = TRUE;
7765 p += 14;
7766 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007768 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007769 {
7770 new_autoselectml = TRUE;
7771 p += 12;
7772 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007773 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7774 {
7775 new_html = TRUE;
7776 p += 4;
7777 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7779 {
7780 p += 8;
7781 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7782 if (new_exclude_prog == NULL)
7783 errmsg = e_invarg;
7784 break;
7785 }
7786 else
7787 {
7788 errmsg = e_invarg;
7789 break;
7790 }
7791 if (*p == ',')
7792 ++p;
7793 }
7794 if (errmsg == NULL)
7795 {
7796 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007797 clip_autoselect_star = new_autoselect_star;
7798 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007799 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007800 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007801 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007802 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007803#ifdef FEAT_GUI_GTK
7804 if (gui.in_use)
7805 {
7806 gui_gtk_set_selection_targets();
7807 gui_gtk_set_dnd_targets();
7808 }
7809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810 }
7811 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007812 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007813
7814 return errmsg;
7815}
7816#endif
7817
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007818#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007819 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007820did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007821{
7822 char_u *errmsg = NULL;
7823 win_T *wp;
7824 int l;
7825
7826 if (is_spellfile)
7827 {
7828 l = (int)STRLEN(curwin->w_s->b_p_spf);
7829 if (l > 0 && (l < 4
7830 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7831 errmsg = e_invarg;
7832 }
7833
7834 if (errmsg == NULL)
7835 {
7836 FOR_ALL_WINDOWS(wp)
7837 if (wp->w_buffer == curbuf && wp->w_p_spell)
7838 {
7839 errmsg = did_set_spelllang(wp);
7840# ifdef FEAT_WINDOWS
7841 break;
7842# endif
7843 }
7844 }
7845 return errmsg;
7846}
7847
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007848/*
7849 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7850 * Return error message when failed, NULL when OK.
7851 */
7852 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007853compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007854{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007855 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007856 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007857
Bram Moolenaar860cae12010-06-05 23:22:07 +02007858 if (*synblock->b_p_spc == NUL)
7859 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007860 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007861 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007862 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007863 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007864 if (re != NULL)
7865 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007866 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007867 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007868 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007869 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007870 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007871 return e_invarg;
7872 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007873 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007874 }
7875
Bram Moolenaar473de612013-06-08 18:19:48 +02007876 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007877 return NULL;
7878}
7879#endif
7880
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007881#if defined(FEAT_EVAL) || defined(PROTO)
7882/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007883 * Set the scriptID for an option, taking care of setting the buffer- or
7884 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007885 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007886 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007887set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007888{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007889 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7890 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007891
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007892 /* Remember where the option was set. For local options need to do that
7893 * in the buffer or window structure. */
7894 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007895 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007896 if (both || (opt_flags & OPT_LOCAL))
7897 {
7898 if (indir & PV_BUF)
7899 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7900 else if (indir & PV_WIN)
7901 curwin->w_p_scriptID[indir & PV_MASK] = id;
7902 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007903}
7904#endif
7905
Bram Moolenaar071d4272004-06-13 20:20:40 +00007906/*
7907 * Set the value of a boolean option, and take care of side effects.
7908 * Returns NULL for success, or an error message for an error.
7909 */
7910 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007911set_bool_option(
7912 int opt_idx, /* index in options[] table */
7913 char_u *varp, /* pointer to the option variable */
7914 int value, /* new value */
7915 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007916{
7917 int old_value = *(int *)varp;
7918
Bram Moolenaar071d4272004-06-13 20:20:40 +00007919 /* Disallow changing some options from secure mode */
7920 if ((secure
7921#ifdef HAVE_SANDBOX
7922 || sandbox != 0
7923#endif
7924 ) && (options[opt_idx].flags & P_SECURE))
7925 return e_secure;
7926
7927 *(int *)varp = value; /* set the new value */
7928#ifdef FEAT_EVAL
7929 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007930 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007931#endif
7932
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007933#ifdef FEAT_GUI
7934 need_mouse_correct = TRUE;
7935#endif
7936
Bram Moolenaar071d4272004-06-13 20:20:40 +00007937 /* May set global value for local option. */
7938 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7939 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7940
7941 /*
7942 * Handle side effects of changing a bool option.
7943 */
7944
7945 /* 'compatible' */
7946 if ((int *)varp == &p_cp)
7947 {
7948 compatible_set();
7949 }
7950
Bram Moolenaar920694c2016-08-21 17:45:02 +02007951#ifdef FEAT_LANGMAP
7952 if ((int *)varp == &p_lrm)
7953 /* 'langremap' -> !'langnoremap' */
7954 p_lnr = !p_lrm;
7955 else if ((int *)varp == &p_lnr)
7956 /* 'langnoremap' -> !'langremap' */
7957 p_lrm = !p_lnr;
7958#endif
7959
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007960#ifdef FEAT_PERSISTENT_UNDO
7961 /* 'undofile' */
7962 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7963 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007964 /* Only take action when the option was set. When reset we do not
7965 * delete the undo file, the option may be set again without making
7966 * any changes in between. */
7967 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007968 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007969 char_u hash[UNDO_HASH_SIZE];
7970 buf_T *save_curbuf = curbuf;
7971
Bram Moolenaar29323592016-07-24 22:04:11 +02007972 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007973 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007974 /* When 'undofile' is set globally: for every buffer, otherwise
7975 * only for the current buffer: Try to read in the undofile,
7976 * if one exists, the buffer wasn't changed and the buffer was
7977 * loaded */
7978 if ((curbuf == save_curbuf
7979 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7980 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7981 {
7982 u_compute_hash(hash);
7983 u_read_undo(NULL, hash, curbuf->b_fname);
7984 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007985 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007986 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007987 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007988 }
7989#endif
7990
Bram Moolenaar071d4272004-06-13 20:20:40 +00007991 else if ((int *)varp == &curbuf->b_p_ro)
7992 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007993 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007994 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7995 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007996
7997 /* when 'readonly' is set may give W10 again */
7998 if (curbuf->b_p_ro)
7999 curbuf->b_did_warn = FALSE;
8000
Bram Moolenaar071d4272004-06-13 20:20:40 +00008001#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008002 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003#endif
8004 }
8005
Bram Moolenaar9c449722010-07-20 18:44:27 +02008006#ifdef FEAT_GUI
8007 else if ((int *)varp == &p_mh)
8008 {
8009 if (!p_mh)
8010 gui_mch_mousehide(FALSE);
8011 }
8012#endif
8013
Bram Moolenaara539df02010-08-01 14:35:05 +02008014#ifdef FEAT_TITLE
8015 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008017 {
8018 redraw_titles();
8019 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008020 /* when 'endofline' is changed, redraw the window title */
8021 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008022 {
8023 redraw_titles();
8024 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008025 /* when 'fixeol' is changed, redraw the window title */
8026 else if ((int *)varp == &curbuf->b_p_fixeol)
8027 {
8028 redraw_titles();
8029 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008030# ifdef FEAT_MBYTE
8031 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008032 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008033 {
8034 redraw_titles();
8035 }
8036# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037#endif
8038
8039 /* when 'bin' is set also set some other options */
8040 else if ((int *)varp == &curbuf->b_p_bin)
8041 {
8042 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8043#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008044 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045#endif
8046 }
8047
8048#ifdef FEAT_AUTOCMD
8049 /* when 'buflisted' changes, trigger autocommands */
8050 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8051 {
8052 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8053 NULL, NULL, TRUE, curbuf);
8054 }
8055#endif
8056
8057 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8058 else if ((int *)varp == &curbuf->b_p_swf)
8059 {
8060 if (curbuf->b_p_swf && p_uc)
8061 ml_open_file(curbuf); /* create the swap file */
8062 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008063 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8064 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008065 mf_close_file(curbuf, TRUE); /* remove the swap file */
8066 }
8067
8068 /* when 'terse' is set change 'shortmess' */
8069 else if ((int *)varp == &p_terse)
8070 {
8071 char_u *p;
8072
8073 p = vim_strchr(p_shm, SHM_SEARCH);
8074
8075 /* insert 's' in p_shm */
8076 if (p_terse && p == NULL)
8077 {
8078 STRCPY(IObuff, p_shm);
8079 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008080 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008081 }
8082 /* remove 's' from p_shm */
8083 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008084 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 }
8086
8087 /* when 'paste' is set or reset also change other options */
8088 else if ((int *)varp == &p_paste)
8089 {
8090 paste_option_changed();
8091 }
8092
8093 /* when 'insertmode' is set from an autocommand need to do work here */
8094 else if ((int *)varp == &p_im)
8095 {
8096 if (p_im)
8097 {
8098 if ((State & INSERT) == 0)
8099 need_start_insertmode = TRUE;
8100 stop_insert_mode = FALSE;
8101 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008102 /* only reset if it was set previously */
8103 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 {
8105 need_start_insertmode = FALSE;
8106 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008107 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008108 clear_cmdline = TRUE; /* remove "(insert)" */
8109 restart_edit = 0;
8110 }
8111 }
8112
8113 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8114 else if ((int *)varp == &p_ic && p_hls)
8115 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008116 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 }
8118
8119#ifdef FEAT_SEARCH_EXTRA
8120 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8121 else if ((int *)varp == &p_hls)
8122 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008123 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 }
8125#endif
8126
8127#ifdef FEAT_SCROLLBIND
8128 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8129 * at the end of normal_cmd() */
8130 else if ((int *)varp == &curwin->w_p_scb)
8131 {
8132 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008133 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008134 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008135 curwin->w_scbind_pos = curwin->w_topline;
8136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137 }
8138#endif
8139
8140#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8141 /* There can be only one window with 'previewwindow' set. */
8142 else if ((int *)varp == &curwin->w_p_pvw)
8143 {
8144 if (curwin->w_p_pvw)
8145 {
8146 win_T *win;
8147
Bram Moolenaar29323592016-07-24 22:04:11 +02008148 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 if (win->w_p_pvw && win != curwin)
8150 {
8151 curwin->w_p_pvw = FALSE;
8152 return (char_u *)N_("E590: A preview window already exists");
8153 }
8154 }
8155 }
8156#endif
8157
8158 /* when 'textmode' is set or reset also change 'fileformat' */
8159 else if ((int *)varp == &curbuf->b_p_tx)
8160 {
8161 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8162 }
8163
8164 /* when 'textauto' is set or reset also change 'fileformats' */
8165 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008166 set_string_option_direct((char_u *)"ffs", -1,
8167 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008168 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169
8170 /*
8171 * When 'lisp' option changes include/exclude '-' in
8172 * keyword characters.
8173 */
8174#ifdef FEAT_LISP
8175 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8176 {
8177 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8178 }
8179#endif
8180
8181#ifdef FEAT_TITLE
8182 /* when 'title' changed, may need to change the title; same for 'icon' */
8183 else if ((int *)varp == &p_title)
8184 {
8185 did_set_title(FALSE);
8186 }
8187
8188 else if ((int *)varp == &p_icon)
8189 {
8190 did_set_title(TRUE);
8191 }
8192#endif
8193
8194 else if ((int *)varp == &curbuf->b_changed)
8195 {
8196 if (!value)
8197 save_file_ff(curbuf); /* Buffer is unchanged */
8198#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008199 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200#endif
8201#ifdef FEAT_AUTOCMD
8202 modified_was_set = value;
8203#endif
8204 }
8205
8206#ifdef BACKSLASH_IN_FILENAME
8207 else if ((int *)varp == &p_ssl)
8208 {
8209 if (p_ssl)
8210 {
8211 psepc = '/';
8212 psepcN = '\\';
8213 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214 }
8215 else
8216 {
8217 psepc = '\\';
8218 psepcN = '/';
8219 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220 }
8221
8222 /* need to adjust the file name arguments and buffer names. */
8223 buflist_slash_adjust();
8224 alist_slash_adjust();
8225# ifdef FEAT_EVAL
8226 scriptnames_slash_adjust();
8227# endif
8228 }
8229#endif
8230
8231 /* If 'wrap' is set, set w_leftcol to zero. */
8232 else if ((int *)varp == &curwin->w_p_wrap)
8233 {
8234 if (curwin->w_p_wrap)
8235 curwin->w_leftcol = 0;
8236 }
8237
8238#ifdef FEAT_WINDOWS
8239 else if ((int *)varp == &p_ea)
8240 {
8241 if (p_ea && !old_value)
8242 win_equal(curwin, FALSE, 0);
8243 }
8244#endif
8245
8246 else if ((int *)varp == &p_wiv)
8247 {
8248 /*
8249 * When 'weirdinvert' changed, set/reset 't_xs'.
8250 * Then set 'weirdinvert' according to value of 't_xs'.
8251 */
8252 if (p_wiv && !old_value)
8253 T_XS = (char_u *)"y";
8254 else if (!p_wiv && old_value)
8255 T_XS = empty_option;
8256 p_wiv = (*T_XS != NUL);
8257 }
8258
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008259#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008260 else if ((int *)varp == &p_beval)
8261 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008262 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008264 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008265 gui_mch_disable_beval_area(balloonEval);
8266 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008267#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008268
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008269#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008270 else if ((int *)varp == &p_acd)
8271 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008272 /* Change directories when the 'acd' option is set now. */
8273 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008274 }
8275#endif
8276
8277#ifdef FEAT_DIFF
8278 /* 'diff' */
8279 else if ((int *)varp == &curwin->w_p_diff)
8280 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008281 /* May add or remove the buffer from the list of diff buffers. */
8282 diff_buf_adjust(curwin);
8283# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 if (foldmethodIsDiff(curwin))
8285 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008286# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008287 }
8288#endif
8289
8290#ifdef USE_IM_CONTROL
8291 /* 'imdisable' */
8292 else if ((int *)varp == &p_imdisable)
8293 {
8294 /* Only de-activate it here, it will be enabled when changing mode. */
8295 if (p_imdisable)
8296 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008297 else if (State & INSERT)
8298 /* When the option is set from an autocommand, it may need to take
8299 * effect right away. */
8300 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301 }
8302#endif
8303
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008304#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008305 /* 'spell' */
8306 else if ((int *)varp == &curwin->w_p_spell)
8307 {
8308 if (curwin->w_p_spell)
8309 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008310 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008311 if (errmsg != NULL)
8312 EMSG(_(errmsg));
8313 }
8314 }
8315#endif
8316
Bram Moolenaar071d4272004-06-13 20:20:40 +00008317#ifdef FEAT_FKMAP
8318 else if ((int *)varp == &p_altkeymap)
8319 {
8320 if (old_value != p_altkeymap)
8321 {
8322 if (!p_altkeymap)
8323 {
8324 p_hkmap = p_fkmap;
8325 p_fkmap = 0;
8326 }
8327 else
8328 {
8329 p_fkmap = p_hkmap;
8330 p_hkmap = 0;
8331 }
8332 (void)init_chartab();
8333 }
8334 }
8335
8336 /*
8337 * In case some second language keymapping options have changed, check
8338 * and correct the setting in a consistent way.
8339 */
8340
8341 /*
8342 * If hkmap or fkmap are set, reset Arabic keymapping.
8343 */
8344 if ((p_hkmap || p_fkmap) && p_altkeymap)
8345 {
8346 p_altkeymap = p_fkmap;
8347# ifdef FEAT_ARABIC
8348 curwin->w_p_arab = FALSE;
8349# endif
8350 (void)init_chartab();
8351 }
8352
8353 /*
8354 * If hkmap set, reset Farsi keymapping.
8355 */
8356 if (p_hkmap && p_altkeymap)
8357 {
8358 p_altkeymap = 0;
8359 p_fkmap = 0;
8360# ifdef FEAT_ARABIC
8361 curwin->w_p_arab = FALSE;
8362# endif
8363 (void)init_chartab();
8364 }
8365
8366 /*
8367 * If fkmap set, reset Hebrew keymapping.
8368 */
8369 if (p_fkmap && !p_altkeymap)
8370 {
8371 p_altkeymap = 1;
8372 p_hkmap = 0;
8373# ifdef FEAT_ARABIC
8374 curwin->w_p_arab = FALSE;
8375# endif
8376 (void)init_chartab();
8377 }
8378#endif
8379
8380#ifdef FEAT_ARABIC
8381 if ((int *)varp == &curwin->w_p_arab)
8382 {
8383 if (curwin->w_p_arab)
8384 {
8385 /*
8386 * 'arabic' is set, handle various sub-settings.
8387 */
8388 if (!p_tbidi)
8389 {
8390 /* set rightleft mode */
8391 if (!curwin->w_p_rl)
8392 {
8393 curwin->w_p_rl = TRUE;
8394 changed_window_setting();
8395 }
8396
8397 /* Enable Arabic shaping (major part of what Arabic requires) */
8398 if (!p_arshape)
8399 {
8400 p_arshape = TRUE;
8401 redraw_later_clear();
8402 }
8403 }
8404
8405 /* Arabic requires a utf-8 encoding, inform the user if its not
8406 * set. */
8407 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008408 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008409 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8410
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008411 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008412 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8413#ifdef FEAT_EVAL
8414 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8415#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008416 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008417
8418# ifdef FEAT_MBYTE
8419 /* set 'delcombine' */
8420 p_deco = TRUE;
8421# endif
8422
8423# ifdef FEAT_KEYMAP
8424 /* Force-set the necessary keymap for arabic */
8425 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8426 OPT_LOCAL);
8427# endif
8428# ifdef FEAT_FKMAP
8429 p_altkeymap = 0;
8430 p_hkmap = 0;
8431 p_fkmap = 0;
8432 (void)init_chartab();
8433# endif
8434 }
8435 else
8436 {
8437 /*
8438 * 'arabic' is reset, handle various sub-settings.
8439 */
8440 if (!p_tbidi)
8441 {
8442 /* reset rightleft mode */
8443 if (curwin->w_p_rl)
8444 {
8445 curwin->w_p_rl = FALSE;
8446 changed_window_setting();
8447 }
8448
8449 /* 'arabicshape' isn't reset, it is a global option and
8450 * another window may still need it "on". */
8451 }
8452
8453 /* 'delcombine' isn't reset, it is a global option and another
8454 * window may still want it "on". */
8455
8456# ifdef FEAT_KEYMAP
8457 /* Revert to the default keymap */
8458 curbuf->b_p_iminsert = B_IMODE_NONE;
8459 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8460# endif
8461 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008462 }
8463
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008464#endif
8465
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008466#ifdef FEAT_TERMGUICOLORS
8467 /* 'termguicolors' */
8468 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008469 {
8470# ifdef FEAT_GUI
8471 if (!gui.in_use && !gui.starting)
8472# endif
8473 highlight_gui_started();
8474 }
8475#endif
8476
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477 /*
8478 * End of handling side effects for bool options.
8479 */
8480
Bram Moolenaar53744302015-07-17 17:38:22 +02008481 /* after handling side effects, call autocommand */
8482
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 options[opt_idx].flags |= P_WAS_SET;
8484
Bram Moolenaar53744302015-07-17 17:38:22 +02008485#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8486 if (!starting)
8487 {
8488 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008489 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8490 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8491 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008492 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8493 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8494 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8495 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8496 reset_v_option_vars();
8497 }
8498#endif
8499
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008501 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008502 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008503 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008504 check_redraw(options[opt_idx].flags);
8505
8506 return NULL;
8507}
8508
8509/*
8510 * Set the value of a number option, and take care of side effects.
8511 * Returns NULL for success, or an error message for an error.
8512 */
8513 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008514set_num_option(
8515 int opt_idx, /* index in options[] table */
8516 char_u *varp, /* pointer to the option variable */
8517 long value, /* new value */
8518 char_u *errbuf, /* buffer for error messages */
8519 size_t errbuflen, /* length of "errbuf" */
8520 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 OPT_MODELINE */
8522{
8523 char_u *errmsg = NULL;
8524 long old_value = *(long *)varp;
8525 long old_Rows = Rows; /* remember old Rows */
8526 long old_Columns = Columns; /* remember old Columns */
8527 long *pp = (long *)varp;
8528
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008529 /* Disallow changing some options from secure mode. */
8530 if ((secure
8531#ifdef HAVE_SANDBOX
8532 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008534 ) && (options[opt_idx].flags & P_SECURE))
8535 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536
8537 *pp = value;
8538#ifdef FEAT_EVAL
8539 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008540 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008541#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008542#ifdef FEAT_GUI
8543 need_mouse_correct = TRUE;
8544#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545
Bram Moolenaar14f24742012-08-08 18:01:05 +02008546 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008547 {
8548 errmsg = e_positive;
8549 curbuf->b_p_sw = curbuf->b_p_ts;
8550 }
8551
8552 /*
8553 * Number options that need some action when changed
8554 */
8555#ifdef FEAT_WINDOWS
8556 if (pp == &p_wh || pp == &p_hh)
8557 {
8558 if (p_wh < 1)
8559 {
8560 errmsg = e_positive;
8561 p_wh = 1;
8562 }
8563 if (p_wmh > p_wh)
8564 {
8565 errmsg = e_winheight;
8566 p_wh = p_wmh;
8567 }
8568 if (p_hh < 0)
8569 {
8570 errmsg = e_positive;
8571 p_hh = 0;
8572 }
8573
8574 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008575 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576 {
8577 if (pp == &p_wh && curwin->w_height < p_wh)
8578 win_setheight((int)p_wh);
8579 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8580 win_setheight((int)p_hh);
8581 }
8582 }
8583
8584 /* 'winminheight' */
8585 else if (pp == &p_wmh)
8586 {
8587 if (p_wmh < 0)
8588 {
8589 errmsg = e_positive;
8590 p_wmh = 0;
8591 }
8592 if (p_wmh > p_wh)
8593 {
8594 errmsg = e_winheight;
8595 p_wmh = p_wh;
8596 }
8597 win_setminheight();
8598 }
8599
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008600# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008601 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008602 {
8603 if (p_wiw < 1)
8604 {
8605 errmsg = e_positive;
8606 p_wiw = 1;
8607 }
8608 if (p_wmw > p_wiw)
8609 {
8610 errmsg = e_winwidth;
8611 p_wiw = p_wmw;
8612 }
8613
8614 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008615 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008616 win_setwidth((int)p_wiw);
8617 }
8618
8619 /* 'winminwidth' */
8620 else if (pp == &p_wmw)
8621 {
8622 if (p_wmw < 0)
8623 {
8624 errmsg = e_positive;
8625 p_wmw = 0;
8626 }
8627 if (p_wmw > p_wiw)
8628 {
8629 errmsg = e_winwidth;
8630 p_wmw = p_wiw;
8631 }
8632 win_setminheight();
8633 }
8634# endif
8635
8636#endif
8637
8638#ifdef FEAT_WINDOWS
8639 /* (re)set last window status line */
8640 else if (pp == &p_ls)
8641 {
8642 last_status(FALSE);
8643 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008644
8645 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008646 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008647 {
8648 shell_new_rows(); /* recompute window positions and heights */
8649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008650#endif
8651
8652#ifdef FEAT_GUI
8653 else if (pp == &p_linespace)
8654 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008655 /* Recompute gui.char_height and resize the Vim window to keep the
8656 * same number of lines. */
8657 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008658 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659 }
8660#endif
8661
8662#ifdef FEAT_FOLDING
8663 /* 'foldlevel' */
8664 else if (pp == &curwin->w_p_fdl)
8665 {
8666 if (curwin->w_p_fdl < 0)
8667 curwin->w_p_fdl = 0;
8668 newFoldLevel();
8669 }
8670
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008671 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008672 else if (pp == &curwin->w_p_fml)
8673 {
8674 foldUpdateAll(curwin);
8675 }
8676
8677 /* 'foldnestmax' */
8678 else if (pp == &curwin->w_p_fdn)
8679 {
8680 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8681 foldUpdateAll(curwin);
8682 }
8683
8684 /* 'foldcolumn' */
8685 else if (pp == &curwin->w_p_fdc)
8686 {
8687 if (curwin->w_p_fdc < 0)
8688 {
8689 errmsg = e_positive;
8690 curwin->w_p_fdc = 0;
8691 }
8692 else if (curwin->w_p_fdc > 12)
8693 {
8694 errmsg = e_invarg;
8695 curwin->w_p_fdc = 12;
8696 }
8697 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008698#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008700#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008701 /* 'shiftwidth' or 'tabstop' */
8702 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8703 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008704# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705 if (foldmethodIsIndent(curwin))
8706 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008707# endif
8708# ifdef FEAT_CINDENT
8709 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8710 * parse 'cinoptions'. */
8711 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8712 parse_cino(curbuf);
8713# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008716
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008717#ifdef FEAT_MBYTE
8718 /* 'maxcombine' */
8719 else if (pp == &p_mco)
8720 {
8721 if (p_mco > MAX_MCO)
8722 p_mco = MAX_MCO;
8723 else if (p_mco < 0)
8724 p_mco = 0;
8725 screenclear(); /* will re-allocate the screen */
8726 }
8727#endif
8728
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729 else if (pp == &curbuf->b_p_iminsert)
8730 {
8731 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8732 {
8733 errmsg = e_invarg;
8734 curbuf->b_p_iminsert = B_IMODE_NONE;
8735 }
8736 p_iminsert = curbuf->b_p_iminsert;
8737 if (termcap_active) /* don't do this in the alternate screen */
8738 showmode();
8739#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8740 /* Show/unshow value of 'keymap' in status lines. */
8741 status_redraw_curbuf();
8742#endif
8743 }
8744
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008745 else if (pp == &p_window)
8746 {
8747 if (p_window < 1)
8748 p_window = 1;
8749 else if (p_window >= Rows)
8750 p_window = Rows - 1;
8751 }
8752
Bram Moolenaar071d4272004-06-13 20:20:40 +00008753 else if (pp == &curbuf->b_p_imsearch)
8754 {
8755 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8756 {
8757 errmsg = e_invarg;
8758 curbuf->b_p_imsearch = B_IMODE_NONE;
8759 }
8760 p_imsearch = curbuf->b_p_imsearch;
8761 }
8762
8763#ifdef FEAT_TITLE
8764 /* if 'titlelen' has changed, redraw the title */
8765 else if (pp == &p_titlelen)
8766 {
8767 if (p_titlelen < 0)
8768 {
8769 errmsg = e_positive;
8770 p_titlelen = 85;
8771 }
8772 if (starting != NO_SCREEN && old_value != p_titlelen)
8773 need_maketitle = TRUE;
8774 }
8775#endif
8776
8777 /* if p_ch changed value, change the command line height */
8778 else if (pp == &p_ch)
8779 {
8780 if (p_ch < 1)
8781 {
8782 errmsg = e_positive;
8783 p_ch = 1;
8784 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008785 if (p_ch > Rows - min_rows() + 1)
8786 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787
8788 /* Only compute the new window layout when startup has been
8789 * completed. Otherwise the frame sizes may be wrong. */
8790 if (p_ch != old_value && full_screen
8791#ifdef FEAT_GUI
8792 && !gui.starting
8793#endif
8794 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008795 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796 }
8797
8798 /* when 'updatecount' changes from zero to non-zero, open swap files */
8799 else if (pp == &p_uc)
8800 {
8801 if (p_uc < 0)
8802 {
8803 errmsg = e_positive;
8804 p_uc = 100;
8805 }
8806 if (p_uc && !old_value)
8807 ml_open_files();
8808 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008809#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008810 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008811 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008812 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008813 {
8814 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008815 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008816 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008817 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008818 {
8819 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008820 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008821 }
8822 }
8823#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008824#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008825 else if (pp == &p_mzq)
8826 mzvim_reset_timer();
8827#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828
8829 /* sync undo before 'undolevels' changes */
8830 else if (pp == &p_ul)
8831 {
8832 /* use the old value, otherwise u_sync() may not work properly */
8833 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008834 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008835 p_ul = value;
8836 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008837 else if (pp == &curbuf->b_p_ul)
8838 {
8839 /* use the old value, otherwise u_sync() may not work properly */
8840 curbuf->b_p_ul = old_value;
8841 u_sync(TRUE);
8842 curbuf->b_p_ul = value;
8843 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008844
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008845#ifdef FEAT_LINEBREAK
8846 /* 'numberwidth' must be positive */
8847 else if (pp == &curwin->w_p_nuw)
8848 {
8849 if (curwin->w_p_nuw < 1)
8850 {
8851 errmsg = e_positive;
8852 curwin->w_p_nuw = 1;
8853 }
8854 if (curwin->w_p_nuw > 10)
8855 {
8856 errmsg = e_invarg;
8857 curwin->w_p_nuw = 10;
8858 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008859 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008860 }
8861#endif
8862
Bram Moolenaar1a384422010-07-14 19:53:30 +02008863 else if (pp == &curbuf->b_p_tw)
8864 {
8865 if (curbuf->b_p_tw < 0)
8866 {
8867 errmsg = e_positive;
8868 curbuf->b_p_tw = 0;
8869 }
8870#ifdef FEAT_SYN_HL
8871# ifdef FEAT_WINDOWS
8872 {
8873 win_T *wp;
8874 tabpage_T *tp;
8875
8876 FOR_ALL_TAB_WINDOWS(tp, wp)
8877 check_colorcolumn(wp);
8878 }
8879# else
8880 check_colorcolumn(curwin);
8881# endif
8882#endif
8883 }
8884
Bram Moolenaar071d4272004-06-13 20:20:40 +00008885 /*
8886 * Check the bounds for numeric options here
8887 */
8888 if (Rows < min_rows() && full_screen)
8889 {
8890 if (errbuf != NULL)
8891 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008892 vim_snprintf((char *)errbuf, errbuflen,
8893 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008894 errmsg = errbuf;
8895 }
8896 Rows = min_rows();
8897 }
8898 if (Columns < MIN_COLUMNS && full_screen)
8899 {
8900 if (errbuf != NULL)
8901 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008902 vim_snprintf((char *)errbuf, errbuflen,
8903 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008904 errmsg = errbuf;
8905 }
8906 Columns = MIN_COLUMNS;
8907 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008908 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008909
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910 /*
8911 * If the screen (shell) height has been changed, assume it is the
8912 * physical screenheight.
8913 */
8914 if (old_Rows != Rows || old_Columns != Columns)
8915 {
8916 /* Changing the screen size is not allowed while updating the screen. */
8917 if (updating_screen)
8918 *pp = old_value;
8919 else if (full_screen
8920#ifdef FEAT_GUI
8921 && !gui.starting
8922#endif
8923 )
8924 set_shellsize((int)Columns, (int)Rows, TRUE);
8925 else
8926 {
8927 /* Postpone the resizing; check the size and cmdline position for
8928 * messages. */
8929 check_shellsize();
8930 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8931 cmdline_row = Rows - p_ch;
8932 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008933 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008934 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935 }
8936
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937 if (curbuf->b_p_ts <= 0)
8938 {
8939 errmsg = e_positive;
8940 curbuf->b_p_ts = 8;
8941 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942 if (p_tm < 0)
8943 {
8944 errmsg = e_positive;
8945 p_tm = 0;
8946 }
8947 if ((curwin->w_p_scr <= 0
8948 || (curwin->w_p_scr > curwin->w_height
8949 && curwin->w_height > 0))
8950 && full_screen)
8951 {
8952 if (pp == &(curwin->w_p_scr))
8953 {
8954 if (curwin->w_p_scr != 0)
8955 errmsg = e_scroll;
8956 win_comp_scroll(curwin);
8957 }
8958 /* If 'scroll' became invalid because of a side effect silently adjust
8959 * it. */
8960 else if (curwin->w_p_scr <= 0)
8961 curwin->w_p_scr = 1;
8962 else /* curwin->w_p_scr > curwin->w_height */
8963 curwin->w_p_scr = curwin->w_height;
8964 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008965 if (p_hi < 0)
8966 {
8967 errmsg = e_positive;
8968 p_hi = 0;
8969 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008970 else if (p_hi > 10000)
8971 {
8972 errmsg = e_invarg;
8973 p_hi = 10000;
8974 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008975 if (p_re < 0 || p_re > 2)
8976 {
8977 errmsg = e_invarg;
8978 p_re = 0;
8979 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 if (p_report < 0)
8981 {
8982 errmsg = e_positive;
8983 p_report = 1;
8984 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008985 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008986 {
8987 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8988 p_sj = Rows / 2;
8989 else
8990 {
8991 errmsg = e_scroll;
8992 p_sj = 1;
8993 }
8994 }
8995 if (p_so < 0 && full_screen)
8996 {
8997 errmsg = e_scroll;
8998 p_so = 0;
8999 }
9000 if (p_siso < 0 && full_screen)
9001 {
9002 errmsg = e_positive;
9003 p_siso = 0;
9004 }
9005#ifdef FEAT_CMDWIN
9006 if (p_cwh < 1)
9007 {
9008 errmsg = e_positive;
9009 p_cwh = 1;
9010 }
9011#endif
9012 if (p_ut < 0)
9013 {
9014 errmsg = e_positive;
9015 p_ut = 2000;
9016 }
9017 if (p_ss < 0)
9018 {
9019 errmsg = e_positive;
9020 p_ss = 0;
9021 }
9022
9023 /* May set global value for local option. */
9024 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9025 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9026
9027 options[opt_idx].flags |= P_WAS_SET;
9028
Bram Moolenaar53744302015-07-17 17:38:22 +02009029#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9030 if (!starting && errmsg == NULL)
9031 {
9032 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009033 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9034 vim_snprintf((char *)buf_new, 10, "%ld", value);
9035 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009036 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9037 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9038 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9039 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9040 reset_v_option_vars();
9041 }
9042#endif
9043
Bram Moolenaar071d4272004-06-13 20:20:40 +00009044 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009045 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009046 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009047 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009048 check_redraw(options[opt_idx].flags);
9049
9050 return errmsg;
9051}
9052
9053/*
9054 * Called after an option changed: check if something needs to be redrawn.
9055 */
9056 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009057check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009058{
9059 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009060 int doclear = (flags & P_RCLR) == P_RCLR;
9061 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009062
9063#ifdef FEAT_WINDOWS
9064 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9065 status_redraw_all();
9066#endif
9067
9068 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9069 changed_window_setting();
9070 if (flags & P_RBUF)
9071 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009072 if (flags & P_RWINONLY)
9073 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009074 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009075 redraw_all_later(CLEAR);
9076 else if (all)
9077 redraw_all_later(NOT_VALID);
9078}
9079
9080/*
9081 * Find index for option 'arg'.
9082 * Return -1 if not found.
9083 */
9084 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009085findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009086{
9087 int opt_idx;
9088 char *s, *p;
9089 static short quick_tab[27] = {0, 0}; /* quick access table */
9090 int is_term_opt;
9091
9092 /*
9093 * For first call: Initialize the quick-access table.
9094 * It contains the index for the first option that starts with a certain
9095 * letter. There are 26 letters, plus the first "t_" option.
9096 */
9097 if (quick_tab[1] == 0)
9098 {
9099 p = options[0].fullname;
9100 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9101 {
9102 if (s[0] != p[0])
9103 {
9104 if (s[0] == 't' && s[1] == '_')
9105 quick_tab[26] = opt_idx;
9106 else
9107 quick_tab[CharOrdLow(s[0])] = opt_idx;
9108 }
9109 p = s;
9110 }
9111 }
9112
9113 /*
9114 * Check for name starting with an illegal character.
9115 */
9116#ifdef EBCDIC
9117 if (!islower(arg[0]))
9118#else
9119 if (arg[0] < 'a' || arg[0] > 'z')
9120#endif
9121 return -1;
9122
9123 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9124 if (is_term_opt)
9125 opt_idx = quick_tab[26];
9126 else
9127 opt_idx = quick_tab[CharOrdLow(arg[0])];
9128 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9129 {
9130 if (STRCMP(arg, s) == 0) /* match full name */
9131 break;
9132 }
9133 if (s == NULL && !is_term_opt)
9134 {
9135 opt_idx = quick_tab[CharOrdLow(arg[0])];
9136 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9137 {
9138 s = options[opt_idx].shortname;
9139 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9140 break;
9141 s = NULL;
9142 }
9143 }
9144 if (s == NULL)
9145 opt_idx = -1;
9146 return opt_idx;
9147}
9148
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009149#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009150/*
9151 * Get the value for an option.
9152 *
9153 * Returns:
9154 * Number or Toggle option: 1, *numval gets value.
9155 * String option: 0, *stringval gets allocated string.
9156 * Hidden Number or Toggle option: -1.
9157 * hidden String option: -2.
9158 * unknown option: -3.
9159 */
9160 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009161get_option_value(
9162 char_u *name,
9163 long *numval,
9164 char_u **stringval, /* NULL when only checking existence */
9165 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009166{
9167 int opt_idx;
9168 char_u *varp;
9169
9170 opt_idx = findoption(name);
9171 if (opt_idx < 0) /* unknown option */
9172 return -3;
9173
9174 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9175
9176 if (options[opt_idx].flags & P_STRING)
9177 {
9178 if (varp == NULL) /* hidden option */
9179 return -2;
9180 if (stringval != NULL)
9181 {
9182#ifdef FEAT_CRYPT
9183 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009184 if ((char_u **)varp == &curbuf->b_p_key
9185 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186 *stringval = vim_strsave((char_u *)"*****");
9187 else
9188#endif
9189 *stringval = vim_strsave(*(char_u **)(varp));
9190 }
9191 return 0;
9192 }
9193
9194 if (varp == NULL) /* hidden option */
9195 return -1;
9196 if (options[opt_idx].flags & P_NUM)
9197 *numval = *(long *)varp;
9198 else
9199 {
9200 /* Special case: 'modified' is b_changed, but we also want to consider
9201 * it set when 'ff' or 'fenc' changed. */
9202 if ((int *)varp == &curbuf->b_changed)
9203 *numval = curbufIsChanged();
9204 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009205 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206 }
9207 return 1;
9208}
9209#endif
9210
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009211#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009212/*
9213 * Returns the option attributes and its value. Unlike the above function it
9214 * will return either global value or local value of the option depending on
9215 * what was requested, but it will never return global value if it was
9216 * requested to return local one and vice versa. Neither it will return
9217 * buffer-local value if it was requested to return window-local one.
9218 *
9219 * Pretends that option is absent if it is not present in the requested scope
9220 * (i.e. has no global, window-local or buffer-local value depending on
9221 * opt_type). Uses
9222 *
9223 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009224 * 0 hidden or unknown option, also option that does not have requested
9225 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009226 * see SOPT_* in vim.h for other flags
9227 *
9228 * Possible opt_type values: see SREQ_* in vim.h
9229 */
9230 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009231get_option_value_strict(
9232 char_u *name,
9233 long *numval,
9234 char_u **stringval, /* NULL when only obtaining attributes */
9235 int opt_type,
9236 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009237{
9238 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009239 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009240 struct vimoption *p;
9241 int r = 0;
9242
9243 opt_idx = findoption(name);
9244 if (opt_idx < 0)
9245 return 0;
9246
9247 p = &(options[opt_idx]);
9248
9249 /* Hidden option */
9250 if (p->var == NULL)
9251 return 0;
9252
9253 if (p->flags & P_BOOL)
9254 r |= SOPT_BOOL;
9255 else if (p->flags & P_NUM)
9256 r |= SOPT_NUM;
9257 else if (p->flags & P_STRING)
9258 r |= SOPT_STRING;
9259
9260 if (p->indir == PV_NONE)
9261 {
9262 if (opt_type == SREQ_GLOBAL)
9263 r |= SOPT_GLOBAL;
9264 else
9265 return 0; /* Did not request global-only option */
9266 }
9267 else
9268 {
9269 if (p->indir & PV_BOTH)
9270 r |= SOPT_GLOBAL;
9271 else if (opt_type == SREQ_GLOBAL)
9272 return 0; /* Requested global option */
9273
9274 if (p->indir & PV_WIN)
9275 {
9276 if (opt_type == SREQ_BUF)
9277 return 0; /* Did not request window-local option */
9278 else
9279 r |= SOPT_WIN;
9280 }
9281 else if (p->indir & PV_BUF)
9282 {
9283 if (opt_type == SREQ_WIN)
9284 return 0; /* Did not request buffer-local option */
9285 else
9286 r |= SOPT_BUF;
9287 }
9288 }
9289
9290 if (stringval == NULL)
9291 return r;
9292
9293 if (opt_type == SREQ_GLOBAL)
9294 varp = p->var;
9295 else
9296 {
9297 if (opt_type == SREQ_BUF)
9298 {
9299 /* Special case: 'modified' is b_changed, but we also want to
9300 * consider it set when 'ff' or 'fenc' changed. */
9301 if (p->indir == PV_MOD)
9302 {
9303 *numval = bufIsChanged((buf_T *) from);
9304 varp = NULL;
9305 }
9306#ifdef FEAT_CRYPT
9307 else if (p->indir == PV_KEY)
9308 {
9309 /* never return the value of the crypt key */
9310 *stringval = NULL;
9311 varp = NULL;
9312 }
9313#endif
9314 else
9315 {
9316 aco_save_T aco;
9317 aucmd_prepbuf(&aco, (buf_T *) from);
9318 varp = get_varp(p);
9319 aucmd_restbuf(&aco);
9320 }
9321 }
9322 else if (opt_type == SREQ_WIN)
9323 {
9324 win_T *save_curwin;
9325 save_curwin = curwin;
9326 curwin = (win_T *) from;
9327 curbuf = curwin->w_buffer;
9328 varp = get_varp(p);
9329 curwin = save_curwin;
9330 curbuf = curwin->w_buffer;
9331 }
9332 if (varp == p->var)
9333 return (r | SOPT_UNSET);
9334 }
9335
9336 if (varp != NULL)
9337 {
9338 if (p->flags & P_STRING)
9339 *stringval = vim_strsave(*(char_u **)(varp));
9340 else if (p->flags & P_NUM)
9341 *numval = *(long *) varp;
9342 else
9343 *numval = *(int *)varp;
9344 }
9345
9346 return r;
9347}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009348
9349/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009350 * Iterate over options. First argument is a pointer to a pointer to a
9351 * structure inside options[] array, second is option type like in the above
9352 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009353 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009354 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009355 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009356 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009357 * first argument to NULL.
9358 *
9359 * Returns full option name for current option on each call.
9360 */
9361 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009362option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009363{
9364 struct vimoption *ret = NULL;
9365 do
9366 {
9367 if (*option == NULL)
9368 *option = (void *) options;
9369 else if (((struct vimoption *) (*option))->fullname == NULL)
9370 {
9371 *option = NULL;
9372 return NULL;
9373 }
9374 else
9375 *option = (void *) (((struct vimoption *) (*option)) + 1);
9376
9377 ret = ((struct vimoption *) (*option));
9378
9379 /* Hidden option */
9380 if (ret->var == NULL)
9381 {
9382 ret = NULL;
9383 continue;
9384 }
9385
9386 switch (opt_type)
9387 {
9388 case SREQ_GLOBAL:
9389 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9390 ret = NULL;
9391 break;
9392 case SREQ_BUF:
9393 if (!(ret->indir & PV_BUF))
9394 ret = NULL;
9395 break;
9396 case SREQ_WIN:
9397 if (!(ret->indir & PV_WIN))
9398 ret = NULL;
9399 break;
9400 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009401 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009402 return NULL;
9403 }
9404 }
9405 while (ret == NULL);
9406
9407 return (char_u *)ret->fullname;
9408}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009409#endif
9410
Bram Moolenaar071d4272004-06-13 20:20:40 +00009411/*
9412 * Set the value of option "name".
9413 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009414 *
9415 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009417 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009418set_option_value(
9419 char_u *name,
9420 long number,
9421 char_u *string,
9422 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423{
9424 int opt_idx;
9425 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009426 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009427
9428 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009429 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009430 EMSG2(_("E355: Unknown option: %s"), name);
9431 else
9432 {
9433 flags = options[opt_idx].flags;
9434#ifdef HAVE_SANDBOX
9435 /* Disallow changing some options in the sandbox */
9436 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009437 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009438 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009439 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009441#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009442 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009443 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009444 else
9445 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009446 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009447 if (varp != NULL) /* hidden option is not changed */
9448 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009449 if (number == 0 && string != NULL)
9450 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009451 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009452
9453 /* Either we are given a string or we are setting option
9454 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009455 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009456 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009457 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009458 {
9459 /* There's another character after zeros or the string
9460 * is empty. In both cases, we are trying to set a
9461 * num option using a string. */
9462 EMSG3(_("E521: Number required: &%s = '%s'"),
9463 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009464 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009465
9466 }
9467 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009468 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009469 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009470 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009471 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009472 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009473 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009474 }
9475 }
9476 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009477 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009478}
9479
9480/*
9481 * Get the terminal code for a terminal option.
9482 * Returns NULL when not found.
9483 */
9484 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009485get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009486{
9487 int opt_idx;
9488 char_u *varp;
9489
9490 if (tname[0] != 't' || tname[1] != '_' ||
9491 tname[2] == NUL || tname[3] == NUL)
9492 return NULL;
9493 if ((opt_idx = findoption(tname)) >= 0)
9494 {
9495 varp = get_varp(&(options[opt_idx]));
9496 if (varp != NULL)
9497 varp = *(char_u **)(varp);
9498 return varp;
9499 }
9500 return find_termcode(tname + 2);
9501}
9502
9503 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009504get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009505{
9506 int i;
9507
9508 i = findoption((char_u *)"hl");
9509 if (i >= 0)
9510 return options[i].def_val[VI_DEFAULT];
9511 return (char_u *)NULL;
9512}
9513
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009514#if defined(FEAT_MBYTE) || defined(PROTO)
9515 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009516get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009517{
9518 int i;
9519
9520 i = findoption((char_u *)"enc");
9521 if (i >= 0)
9522 return options[i].def_val[VI_DEFAULT];
9523 return (char_u *)NULL;
9524}
9525#endif
9526
Bram Moolenaar071d4272004-06-13 20:20:40 +00009527/*
9528 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9529 */
9530 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009531find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009532{
9533 int key;
9534 int modifiers;
9535
9536 /*
9537 * Don't use get_special_key_code() for t_xx, we don't want it to call
9538 * add_termcap_entry().
9539 */
9540 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9541 key = TERMCAP2KEY(arg[2], arg[3]);
9542 else
9543 {
9544 --arg; /* put arg at the '<' */
9545 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009546 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 if (modifiers) /* can't handle modifiers here */
9548 key = 0;
9549 }
9550 return key;
9551}
9552
9553/*
9554 * if 'all' == 0: show changed options
9555 * if 'all' == 1: show all normal options
9556 * if 'all' == 2: show all terminal options
9557 */
9558 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009559showoptions(
9560 int all,
9561 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009562{
9563 struct vimoption *p;
9564 int col;
9565 int isterm;
9566 char_u *varp;
9567 struct vimoption **items;
9568 int item_count;
9569 int run;
9570 int row, rows;
9571 int cols;
9572 int i;
9573 int len;
9574
9575#define INC 20
9576#define GAP 3
9577
9578 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9579 PARAM_COUNT));
9580 if (items == NULL)
9581 return;
9582
9583 /* Highlight title */
9584 if (all == 2)
9585 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9586 else if (opt_flags & OPT_GLOBAL)
9587 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9588 else if (opt_flags & OPT_LOCAL)
9589 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9590 else
9591 MSG_PUTS_TITLE(_("\n--- Options ---"));
9592
9593 /*
9594 * do the loop two times:
9595 * 1. display the short items
9596 * 2. display the long items (only strings and numbers)
9597 */
9598 for (run = 1; run <= 2 && !got_int; ++run)
9599 {
9600 /*
9601 * collect the items in items[]
9602 */
9603 item_count = 0;
9604 for (p = &options[0]; p->fullname != NULL; p++)
9605 {
9606 varp = NULL;
9607 isterm = istermoption(p);
9608 if (opt_flags != 0)
9609 {
9610 if (p->indir != PV_NONE && !isterm)
9611 varp = get_varp_scope(p, opt_flags);
9612 }
9613 else
9614 varp = get_varp(p);
9615 if (varp != NULL
9616 && ((all == 2 && isterm)
9617 || (all == 1 && !isterm)
9618 || (all == 0 && !optval_default(p, varp))))
9619 {
9620 if (p->flags & P_BOOL)
9621 len = 1; /* a toggle option fits always */
9622 else
9623 {
9624 option_value2string(p, opt_flags);
9625 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9626 }
9627 if ((len <= INC - GAP && run == 1) ||
9628 (len > INC - GAP && run == 2))
9629 items[item_count++] = p;
9630 }
9631 }
9632
9633 /*
9634 * display the items
9635 */
9636 if (run == 1)
9637 {
9638 cols = (Columns + GAP - 3) / INC;
9639 if (cols == 0)
9640 cols = 1;
9641 rows = (item_count + cols - 1) / cols;
9642 }
9643 else /* run == 2 */
9644 rows = item_count;
9645 for (row = 0; row < rows && !got_int; ++row)
9646 {
9647 msg_putchar('\n'); /* go to next line */
9648 if (got_int) /* 'q' typed in more */
9649 break;
9650 col = 0;
9651 for (i = row; i < item_count; i += rows)
9652 {
9653 msg_col = col; /* make columns */
9654 showoneopt(items[i], opt_flags);
9655 col += INC;
9656 }
9657 out_flush();
9658 ui_breakcheck();
9659 }
9660 }
9661 vim_free(items);
9662}
9663
9664/*
9665 * Return TRUE if option "p" has its default value.
9666 */
9667 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009668optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009669{
9670 int dvi;
9671
9672 if (varp == NULL)
9673 return TRUE; /* hidden option is always at default */
9674 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9675 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009676 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009677 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009678 /* the cast to long is required for Manx C, long_i is
9679 * needed for MSVC */
9680 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009681 /* P_STRING */
9682 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9683}
9684
9685/*
9686 * showoneopt: show the value of one option
9687 * must not be called with a hidden option!
9688 */
9689 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009690showoneopt(
9691 struct vimoption *p,
9692 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009693{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009694 char_u *varp;
9695 int save_silent = silent_mode;
9696
9697 silent_mode = FALSE;
9698 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009699
9700 varp = get_varp_scope(p, opt_flags);
9701
9702 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9703 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9704 ? !curbufIsChanged() : !*(int *)varp))
9705 MSG_PUTS("no");
9706 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9707 MSG_PUTS("--");
9708 else
9709 MSG_PUTS(" ");
9710 MSG_PUTS(p->fullname);
9711 if (!(p->flags & P_BOOL))
9712 {
9713 msg_putchar('=');
9714 /* put value string in NameBuff */
9715 option_value2string(p, opt_flags);
9716 msg_outtrans(NameBuff);
9717 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009718
9719 silent_mode = save_silent;
9720 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009721}
9722
9723/*
9724 * Write modified options as ":set" commands to a file.
9725 *
9726 * There are three values for "opt_flags":
9727 * OPT_GLOBAL: Write global option values and fresh values of
9728 * buffer-local options (used for start of a session
9729 * file).
9730 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9731 * curwin (used for a vimrc file).
9732 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9733 * and local values for window-local options of
9734 * curwin. Local values are also written when at the
9735 * default value, because a modeline or autocommand
9736 * may have set them when doing ":edit file" and the
9737 * user has set them back at the default or fresh
9738 * value.
9739 * When "local_only" is TRUE, don't write fresh
9740 * values, only local values (for ":mkview").
9741 * (fresh value = value used for a new buffer or window for a local option).
9742 *
9743 * Return FAIL on error, OK otherwise.
9744 */
9745 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009746makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747{
9748 struct vimoption *p;
9749 char_u *varp; /* currently used value */
9750 char_u *varp_fresh; /* local value */
9751 char_u *varp_local = NULL; /* fresh value */
9752 char *cmd;
9753 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009754 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009755
9756 /*
9757 * The options that don't have a default (terminal name, columns, lines)
9758 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009759 * Do the loop over "options[]" twice: once for options with the
9760 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009761 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009762 for (pri = 1; pri >= 0; --pri)
9763 {
9764 for (p = &options[0]; !istermoption(p); p++)
9765 if (!(p->flags & P_NO_MKRC)
9766 && !istermoption(p)
9767 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009768 {
9769 /* skip global option when only doing locals */
9770 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9771 continue;
9772
9773 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9774 * file, they are always buffer-specific. */
9775 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9776 continue;
9777
9778 /* Global values are only written when not at the default value. */
9779 varp = get_varp_scope(p, opt_flags);
9780 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9781 continue;
9782
9783 round = 2;
9784 if (p->indir != PV_NONE)
9785 {
9786 if (p->var == VAR_WIN)
9787 {
9788 /* skip window-local option when only doing globals */
9789 if (!(opt_flags & OPT_LOCAL))
9790 continue;
9791 /* When fresh value of window-local option is not at the
9792 * default, need to write it too. */
9793 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9794 {
9795 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9796 if (!optval_default(p, varp_fresh))
9797 {
9798 round = 1;
9799 varp_local = varp;
9800 varp = varp_fresh;
9801 }
9802 }
9803 }
9804 }
9805
9806 /* Round 1: fresh value for window-local options.
9807 * Round 2: other values */
9808 for ( ; round <= 2; varp = varp_local, ++round)
9809 {
9810 if (round == 1 || (opt_flags & OPT_GLOBAL))
9811 cmd = "set";
9812 else
9813 cmd = "setlocal";
9814
9815 if (p->flags & P_BOOL)
9816 {
9817 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9818 return FAIL;
9819 }
9820 else if (p->flags & P_NUM)
9821 {
9822 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9823 return FAIL;
9824 }
9825 else /* P_STRING */
9826 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009827#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9828 int do_endif = FALSE;
9829
Bram Moolenaar071d4272004-06-13 20:20:40 +00009830 /* Don't set 'syntax' and 'filetype' again if the value is
9831 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009832 if (
9833# if defined(FEAT_SYN_HL)
9834 p->indir == PV_SYN
9835# if defined(FEAT_AUTOCMD)
9836 ||
9837# endif
9838# endif
9839# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009840 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009841# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009842 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009843 {
9844 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9845 *(char_u **)(varp)) < 0
9846 || put_eol(fd) < 0)
9847 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009848 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009849 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009850#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009851 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9852 (p->flags & P_EXPAND) != 0) == FAIL)
9853 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009854#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9855 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009856 {
9857 if (put_line(fd, "endif") == FAIL)
9858 return FAIL;
9859 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009860#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009861 }
9862 }
9863 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009864 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865 return OK;
9866}
9867
9868#if defined(FEAT_FOLDING) || defined(PROTO)
9869/*
9870 * Generate set commands for the local fold options only. Used when
9871 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9872 */
9873 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009874makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009875{
9876 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9877# ifdef FEAT_EVAL
9878 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9879 == FAIL
9880# endif
9881 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9882 == FAIL
9883 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9884 == FAIL
9885 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9886 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9887 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9888 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9889 )
9890 return FAIL;
9891
9892 return OK;
9893}
9894#endif
9895
9896 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009897put_setstring(
9898 FILE *fd,
9899 char *cmd,
9900 char *name,
9901 char_u **valuep,
9902 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009903{
9904 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009905 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009906
9907 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9908 return FAIL;
9909 if (*valuep != NULL)
9910 {
9911 /* Output 'pastetoggle' as key names. For other
9912 * options some characters have to be escaped with
9913 * CTRL-V or backslash */
9914 if (valuep == &p_pt)
9915 {
9916 s = *valuep;
9917 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009918 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009919 return FAIL;
9920 }
9921 else if (expand)
9922 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009923 buf = alloc(MAXPATHL);
9924 if (buf == NULL)
9925 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009926 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9927 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009928 {
9929 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009930 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009931 }
9932 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009933 }
9934 else if (put_escstr(fd, *valuep, 2) == FAIL)
9935 return FAIL;
9936 }
9937 if (put_eol(fd) < 0)
9938 return FAIL;
9939 return OK;
9940}
9941
9942 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009943put_setnum(
9944 FILE *fd,
9945 char *cmd,
9946 char *name,
9947 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009948{
9949 long wc;
9950
9951 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9952 return FAIL;
9953 if (wc_use_keyname((char_u *)valuep, &wc))
9954 {
9955 /* print 'wildchar' and 'wildcharm' as a key name */
9956 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9957 return FAIL;
9958 }
9959 else if (fprintf(fd, "%ld", *valuep) < 0)
9960 return FAIL;
9961 if (put_eol(fd) < 0)
9962 return FAIL;
9963 return OK;
9964}
9965
9966 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009967put_setbool(
9968 FILE *fd,
9969 char *cmd,
9970 char *name,
9971 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009972{
Bram Moolenaar893de922007-10-02 18:40:57 +00009973 if (value < 0) /* global/local option using global value */
9974 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009975 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9976 || put_eol(fd) < 0)
9977 return FAIL;
9978 return OK;
9979}
9980
9981/*
9982 * Clear all the terminal options.
9983 * If the option has been allocated, free the memory.
9984 * Terminal options are never hidden or indirect.
9985 */
9986 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009987clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989 /*
9990 * Reset a few things before clearing the old options. This may cause
9991 * outputting a few things that the terminal doesn't understand, but the
9992 * screen will be cleared later, so this is OK.
9993 */
9994#ifdef FEAT_MOUSE_TTY
9995 mch_setmouse(FALSE); /* switch mouse off */
9996#endif
9997#ifdef FEAT_TITLE
9998 mch_restore_title(3); /* restore window titles */
9999#endif
10000#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10001 /* When starting the GUI close the display opened for the clipboard.
10002 * After restoring the title, because that will need the display. */
10003 if (gui.starting)
10004 clear_xterm_clip();
10005#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010006 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010007
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010008 free_termoptions();
10009}
10010
10011 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010012free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010013{
10014 struct vimoption *p;
10015
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016 for (p = &options[0]; p->fullname != NULL; p++)
10017 if (istermoption(p))
10018 {
10019 if (p->flags & P_ALLOCED)
10020 free_string_option(*(char_u **)(p->var));
10021 if (p->flags & P_DEF_ALLOCED)
10022 free_string_option(p->def_val[VI_DEFAULT]);
10023 *(char_u **)(p->var) = empty_option;
10024 p->def_val[VI_DEFAULT] = empty_option;
10025 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10026 }
10027 clear_termcodes();
10028}
10029
10030/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010031 * Free the string for one term option, if it was allocated.
10032 * Set the string to empty_option and clear allocated flag.
10033 * "var" points to the option value.
10034 */
10035 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010036free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010037{
10038 struct vimoption *p;
10039
10040 for (p = &options[0]; p->fullname != NULL; p++)
10041 if (p->var == var)
10042 {
10043 if (p->flags & P_ALLOCED)
10044 free_string_option(*(char_u **)(p->var));
10045 *(char_u **)(p->var) = empty_option;
10046 p->flags &= ~P_ALLOCED;
10047 break;
10048 }
10049}
10050
10051/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052 * Set the terminal option defaults to the current value.
10053 * Used after setting the terminal name.
10054 */
10055 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010056set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010057{
10058 struct vimoption *p;
10059
10060 for (p = &options[0]; p->fullname != NULL; p++)
10061 {
10062 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10063 {
10064 if (p->flags & P_DEF_ALLOCED)
10065 {
10066 free_string_option(p->def_val[VI_DEFAULT]);
10067 p->flags &= ~P_DEF_ALLOCED;
10068 }
10069 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10070 if (p->flags & P_ALLOCED)
10071 {
10072 p->flags |= P_DEF_ALLOCED;
10073 p->flags &= ~P_ALLOCED; /* don't free the value now */
10074 }
10075 }
10076 }
10077}
10078
10079/*
10080 * return TRUE if 'p' starts with 't_'
10081 */
10082 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010083istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010084{
10085 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10086}
10087
10088/*
10089 * Compute columns for ruler and shown command. 'sc_col' is also used to
10090 * decide what the maximum length of a message on the status line can be.
10091 * If there is a status line for the last window, 'sc_col' is independent
10092 * of 'ru_col'.
10093 */
10094
10095#define COL_RULER 17 /* columns needed by standard ruler */
10096
10097 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010098comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099{
10100#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010101 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010102
10103 sc_col = 0;
10104 ru_col = 0;
10105 if (p_ru)
10106 {
10107#ifdef FEAT_STL_OPT
10108 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10109#else
10110 ru_col = COL_RULER + 1;
10111#endif
10112 /* no last status line, adjust sc_col */
10113 if (!last_has_status)
10114 sc_col = ru_col;
10115 }
10116 if (p_sc)
10117 {
10118 sc_col += SHOWCMD_COLS;
10119 if (!p_ru || last_has_status) /* no need for separating space */
10120 ++sc_col;
10121 }
10122 sc_col = Columns - sc_col;
10123 ru_col = Columns - ru_col;
10124 if (sc_col <= 0) /* screen too narrow, will become a mess */
10125 sc_col = 1;
10126 if (ru_col <= 0)
10127 ru_col = 1;
10128#else
10129 sc_col = Columns;
10130 ru_col = Columns;
10131#endif
10132}
10133
10134/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010135 * Unset local option value, similar to ":set opt<".
10136 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010137 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010138unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010139{
10140 struct vimoption *p;
10141 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010142 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010143
10144 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010145 if (opt_idx < 0)
10146 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010147 p = &(options[opt_idx]);
10148
10149 switch ((int)p->indir)
10150 {
10151 /* global option with local value: use local value if it's been set */
10152 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010153 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010154 break;
10155 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010156 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010157 break;
10158 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010159 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010160 break;
10161 case PV_AR:
10162 buf->b_p_ar = -1;
10163 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010164 case PV_BKC:
10165 clear_string_option(&buf->b_p_bkc);
10166 buf->b_bkc_flags = 0;
10167 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010168 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010169 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010170 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010171 case PV_TC:
10172 clear_string_option(&buf->b_p_tc);
10173 buf->b_tc_flags = 0;
10174 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010175#ifdef FEAT_FIND_ID
10176 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010177 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010178 break;
10179 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010180 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010181 break;
10182#endif
10183#ifdef FEAT_INS_EXPAND
10184 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010185 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010186 break;
10187 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010188 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010189 break;
10190#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010191 case PV_FP:
10192 clear_string_option(&buf->b_p_fp);
10193 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010194#ifdef FEAT_QUICKFIX
10195 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010196 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010197 break;
10198 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010199 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010200 break;
10201 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010202 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010203 break;
10204#endif
10205#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10206 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010207 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010208 break;
10209#endif
10210#if defined(FEAT_CRYPT)
10211 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010212 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010213 break;
10214#endif
10215#ifdef FEAT_STL_OPT
10216 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010217 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010218 break;
10219#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010220 case PV_UL:
10221 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10222 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010223#ifdef FEAT_LISP
10224 case PV_LW:
10225 clear_string_option(&buf->b_p_lw);
10226 break;
10227#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010228 }
10229}
10230
10231/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232 * Get pointer to option variable, depending on local or global scope.
10233 */
10234 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010235get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010236{
10237 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10238 {
10239 if (p->var == VAR_WIN)
10240 return (char_u *)GLOBAL_WO(get_varp(p));
10241 return p->var;
10242 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010243 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010244 {
10245 switch ((int)p->indir)
10246 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010247 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010249 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10250 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10251 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010253 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10254 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10255 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010256 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010257 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010258 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010260 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10261 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262#endif
10263#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010264 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10265 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010267#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10268 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10269#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010270#if defined(FEAT_CRYPT)
10271 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10272#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010273#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010274 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010275#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010276 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010277#ifdef FEAT_LISP
10278 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10279#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010280 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010281 }
10282 return NULL; /* "cannot happen" */
10283 }
10284 return get_varp(p);
10285}
10286
10287/*
10288 * Get pointer to option variable.
10289 */
10290 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010291get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292{
10293 /* hidden option, always return NULL */
10294 if (p->var == NULL)
10295 return NULL;
10296
10297 switch ((int)p->indir)
10298 {
10299 case PV_NONE: return p->var;
10300
10301 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010302 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010304 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010306 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010308 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010310 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010312 case PV_TC: return *curbuf->b_p_tc != NUL
10313 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010314 case PV_BKC: return *curbuf->b_p_bkc != NUL
10315 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010317 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010319 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10321#endif
10322#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010323 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010325 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10327#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010328 case PV_FP: return *curbuf->b_p_fp != NUL
10329 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010331 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010332 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010333 case PV_GP: return *curbuf->b_p_gp != NUL
10334 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10335 case PV_MP: return *curbuf->b_p_mp != NUL
10336 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010338#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10339 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10340 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10341#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010342#if defined(FEAT_CRYPT)
10343 case PV_CM: return *curbuf->b_p_cm != NUL
10344 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10345#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010346#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010347 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010348 ? (char_u *)&(curwin->w_p_stl) : p->var;
10349#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010350 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10351 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010352#ifdef FEAT_LISP
10353 case PV_LW: return *curbuf->b_p_lw != NUL
10354 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356
10357#ifdef FEAT_ARABIC
10358 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10359#endif
10360 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010361#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010362 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10363#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010364#ifdef FEAT_SYN_HL
10365 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10366 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010367 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010369#ifdef FEAT_DIFF
10370 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10371#endif
10372#ifdef FEAT_FOLDING
10373 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10374 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10375 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10376 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10377 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10378 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10379 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10380# ifdef FEAT_EVAL
10381 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10382 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10383# endif
10384 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10385#endif
10386 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010387 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010388#ifdef FEAT_LINEBREAK
10389 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10390#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010391#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010392 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010393 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10394#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10396 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10397#endif
10398#ifdef FEAT_RIGHTLEFT
10399 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10400 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10401#endif
10402 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10403 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10404#ifdef FEAT_LINEBREAK
10405 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010406 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10407 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408#endif
10409#ifdef FEAT_SCROLLBIND
10410 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10411#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010412#ifdef FEAT_CURSORBIND
10413 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10414#endif
10415#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010416 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10417 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010419
10420 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10421 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10422#ifdef FEAT_MBYTE
10423 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10424#endif
10425#if defined(FEAT_QUICKFIX)
10426 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10427 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10428#endif
10429 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10430 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10431#ifdef FEAT_CINDENT
10432 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10433 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10434 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10435#endif
10436#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10437 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10438#endif
10439#ifdef FEAT_COMMENTS
10440 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10441#endif
10442#ifdef FEAT_FOLDING
10443 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10444#endif
10445#ifdef FEAT_INS_EXPAND
10446 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10447#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010448#ifdef FEAT_COMPL_FUNC
10449 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010450 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010451#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010453 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010454 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10455#ifdef FEAT_MBYTE
10456 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10457#endif
10458 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10459#ifdef FEAT_AUTOCMD
10460 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10461#endif
10462 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010463 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010464 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10465 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10466 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10467 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10468#ifdef FEAT_FIND_ID
10469# ifdef FEAT_EVAL
10470 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10471# endif
10472#endif
10473#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10474 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10475 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10476#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010477#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010478 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10479#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010480#ifdef FEAT_CRYPT
10481 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10482#endif
10483#ifdef FEAT_LISP
10484 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10485#endif
10486 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10487 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10488 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10489 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10490 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010492#ifdef FEAT_TEXTOBJ
10493 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10494#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010495 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10496#ifdef FEAT_SMARTINDENT
10497 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10501#ifdef FEAT_SEARCHPATH
10502 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10503#endif
10504 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10505#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010506 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010507 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10508#endif
10509#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010510 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10511 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10512 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010513#endif
10514 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10515 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10516 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10517 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010518#ifdef FEAT_PERSISTENT_UNDO
10519 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10520#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10522#ifdef FEAT_KEYMAP
10523 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10524#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010525#ifdef FEAT_SIGNS
10526 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10527#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010528 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 }
10530 /* always return a valid pointer to avoid a crash! */
10531 return (char_u *)&(curbuf->b_p_wm);
10532}
10533
10534/*
10535 * Get the value of 'equalprg', either the buffer-local one or the global one.
10536 */
10537 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010538get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010539{
10540 if (*curbuf->b_p_ep == NUL)
10541 return p_ep;
10542 return curbuf->b_p_ep;
10543}
10544
10545#if defined(FEAT_WINDOWS) || defined(PROTO)
10546/*
10547 * Copy options from one window to another.
10548 * Used when splitting a window.
10549 */
10550 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010551win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552{
10553 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10554 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10555# ifdef FEAT_RIGHTLEFT
10556# ifdef FEAT_FKMAP
10557 /* Is this right? */
10558 wp_to->w_farsi = wp_from->w_farsi;
10559# endif
10560# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010561#if defined(FEAT_LINEBREAK)
10562 briopt_check(wp_to);
10563#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564}
10565#endif
10566
10567/*
10568 * Copy the options from one winopt_T to another.
10569 * Doesn't free the old option values in "to", use clear_winopt() for that.
10570 * The 'scroll' option is not copied, because it depends on the window height.
10571 * The 'previewwindow' option is reset, there can be only one preview window.
10572 */
10573 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010574copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575{
10576#ifdef FEAT_ARABIC
10577 to->wo_arab = from->wo_arab;
10578#endif
10579 to->wo_list = from->wo_list;
10580 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010581 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010582#ifdef FEAT_LINEBREAK
10583 to->wo_nuw = from->wo_nuw;
10584#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585#ifdef FEAT_RIGHTLEFT
10586 to->wo_rl = from->wo_rl;
10587 to->wo_rlc = vim_strsave(from->wo_rlc);
10588#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010589#ifdef FEAT_STL_OPT
10590 to->wo_stl = vim_strsave(from->wo_stl);
10591#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010593#ifdef FEAT_DIFF
10594 to->wo_wrap_save = from->wo_wrap_save;
10595#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596#ifdef FEAT_LINEBREAK
10597 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010598 to->wo_bri = from->wo_bri;
10599 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600#endif
10601#ifdef FEAT_SCROLLBIND
10602 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010603 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010605#ifdef FEAT_CURSORBIND
10606 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010607 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010608#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010609#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010610 to->wo_spell = from->wo_spell;
10611#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010612#ifdef FEAT_SYN_HL
10613 to->wo_cuc = from->wo_cuc;
10614 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010615 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617#ifdef FEAT_DIFF
10618 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010619 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010621#ifdef FEAT_CONCEAL
10622 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010623 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010624#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625#ifdef FEAT_FOLDING
10626 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010627 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010629 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010630 to->wo_fdi = vim_strsave(from->wo_fdi);
10631 to->wo_fml = from->wo_fml;
10632 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010633 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010635 to->wo_fdm_save = from->wo_diff_saved
10636 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010637 to->wo_fdn = from->wo_fdn;
10638# ifdef FEAT_EVAL
10639 to->wo_fde = vim_strsave(from->wo_fde);
10640 to->wo_fdt = vim_strsave(from->wo_fdt);
10641# endif
10642 to->wo_fmr = vim_strsave(from->wo_fmr);
10643#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010644#ifdef FEAT_SIGNS
10645 to->wo_scl = vim_strsave(from->wo_scl);
10646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647 check_winopt(to); /* don't want NULL pointers */
10648}
10649
10650/*
10651 * Check string options in a window for a NULL value.
10652 */
10653 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010654check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655{
10656 check_winopt(&win->w_onebuf_opt);
10657 check_winopt(&win->w_allbuf_opt);
10658}
10659
10660/*
10661 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10662 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010663 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010664check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010665{
10666#ifdef FEAT_FOLDING
10667 check_string_option(&wop->wo_fdi);
10668 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010669 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010670# ifdef FEAT_EVAL
10671 check_string_option(&wop->wo_fde);
10672 check_string_option(&wop->wo_fdt);
10673# endif
10674 check_string_option(&wop->wo_fmr);
10675#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010676#ifdef FEAT_SIGNS
10677 check_string_option(&wop->wo_scl);
10678#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679#ifdef FEAT_RIGHTLEFT
10680 check_string_option(&wop->wo_rlc);
10681#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010682#ifdef FEAT_STL_OPT
10683 check_string_option(&wop->wo_stl);
10684#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010685#ifdef FEAT_SYN_HL
10686 check_string_option(&wop->wo_cc);
10687#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010688#ifdef FEAT_CONCEAL
10689 check_string_option(&wop->wo_cocu);
10690#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010691#ifdef FEAT_LINEBREAK
10692 check_string_option(&wop->wo_briopt);
10693#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010694}
10695
10696/*
10697 * Free the allocated memory inside a winopt_T.
10698 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010700clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010701{
10702#ifdef FEAT_FOLDING
10703 clear_string_option(&wop->wo_fdi);
10704 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010705 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010706# ifdef FEAT_EVAL
10707 clear_string_option(&wop->wo_fde);
10708 clear_string_option(&wop->wo_fdt);
10709# endif
10710 clear_string_option(&wop->wo_fmr);
10711#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010712#ifdef FEAT_SIGNS
10713 clear_string_option(&wop->wo_scl);
10714#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010715#ifdef FEAT_LINEBREAK
10716 clear_string_option(&wop->wo_briopt);
10717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718#ifdef FEAT_RIGHTLEFT
10719 clear_string_option(&wop->wo_rlc);
10720#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010721#ifdef FEAT_STL_OPT
10722 clear_string_option(&wop->wo_stl);
10723#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010724#ifdef FEAT_SYN_HL
10725 clear_string_option(&wop->wo_cc);
10726#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010727#ifdef FEAT_CONCEAL
10728 clear_string_option(&wop->wo_cocu);
10729#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730}
10731
10732/*
10733 * Copy global option values to local options for one buffer.
10734 * Used when creating a new buffer and sometimes when entering a buffer.
10735 * flags:
10736 * BCO_ENTER We will enter the buf buffer.
10737 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10738 * appropriate.
10739 * BCO_NOHELP Don't copy the values to a help buffer.
10740 */
10741 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010742buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010743{
10744 int should_copy = TRUE;
10745 char_u *save_p_isk = NULL; /* init for GCC */
10746 int dont_do_help;
10747 int did_isk = FALSE;
10748
10749 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750 * Skip this when the option defaults have not been set yet. Happens when
10751 * main() allocates the first buffer.
10752 */
10753 if (p_cpo != NULL)
10754 {
10755 /*
10756 * Always copy when entering and 'cpo' contains 'S'.
10757 * Don't copy when already initialized.
10758 * Don't copy when 'cpo' contains 's' and not entering.
10759 * 'S' BCO_ENTER initialized 's' should_copy
10760 * yes yes X X TRUE
10761 * yes no yes X FALSE
10762 * no X yes X FALSE
10763 * X no no yes FALSE
10764 * X no no no TRUE
10765 * no yes no X TRUE
10766 */
10767 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10768 && (buf->b_p_initialized
10769 || (!(flags & BCO_ENTER)
10770 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10771 should_copy = FALSE;
10772
10773 if (should_copy || (flags & BCO_ALWAYS))
10774 {
10775 /* Don't copy the options specific to a help buffer when
10776 * BCO_NOHELP is given or the options were initialized already
10777 * (jumping back to a help file with CTRL-T or CTRL-O) */
10778 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10779 || buf->b_p_initialized;
10780 if (dont_do_help) /* don't free b_p_isk */
10781 {
10782 save_p_isk = buf->b_p_isk;
10783 buf->b_p_isk = NULL;
10784 }
10785 /*
10786 * Always free the allocated strings.
10787 * If not already initialized, set 'readonly' and copy 'fileformat'.
10788 */
10789 if (!buf->b_p_initialized)
10790 {
10791 free_buf_options(buf, TRUE);
10792 buf->b_p_ro = FALSE; /* don't copy readonly */
10793 buf->b_p_tx = p_tx;
10794#ifdef FEAT_MBYTE
10795 buf->b_p_fenc = vim_strsave(p_fenc);
10796#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020010797 switch (*p_ffs)
10798 {
10799 case 'm':
10800 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
10801 case 'd':
10802 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
10803 case 'u':
10804 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
10805 default:
10806 buf->b_p_ff = vim_strsave(p_ff);
10807 }
10808 if (buf->b_p_ff != NULL)
10809 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010810#if defined(FEAT_QUICKFIX)
10811 buf->b_p_bh = empty_option;
10812 buf->b_p_bt = empty_option;
10813#endif
10814 }
10815 else
10816 free_buf_options(buf, FALSE);
10817
10818 buf->b_p_ai = p_ai;
10819 buf->b_p_ai_nopaste = p_ai_nopaste;
10820 buf->b_p_sw = p_sw;
10821 buf->b_p_tw = p_tw;
10822 buf->b_p_tw_nopaste = p_tw_nopaste;
10823 buf->b_p_tw_nobin = p_tw_nobin;
10824 buf->b_p_wm = p_wm;
10825 buf->b_p_wm_nopaste = p_wm_nopaste;
10826 buf->b_p_wm_nobin = p_wm_nobin;
10827 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010828#ifdef FEAT_MBYTE
10829 buf->b_p_bomb = p_bomb;
10830#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010831 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832 buf->b_p_et = p_et;
10833 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010834 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835 buf->b_p_ml = p_ml;
10836 buf->b_p_ml_nobin = p_ml_nobin;
10837 buf->b_p_inf = p_inf;
10838 buf->b_p_swf = p_swf;
10839#ifdef FEAT_INS_EXPAND
10840 buf->b_p_cpt = vim_strsave(p_cpt);
10841#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010842#ifdef FEAT_COMPL_FUNC
10843 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010844 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846 buf->b_p_sts = p_sts;
10847 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849#ifdef FEAT_COMMENTS
10850 buf->b_p_com = vim_strsave(p_com);
10851#endif
10852#ifdef FEAT_FOLDING
10853 buf->b_p_cms = vim_strsave(p_cms);
10854#endif
10855 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010856 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857 buf->b_p_nf = vim_strsave(p_nf);
10858 buf->b_p_mps = vim_strsave(p_mps);
10859#ifdef FEAT_SMARTINDENT
10860 buf->b_p_si = p_si;
10861#endif
10862 buf->b_p_ci = p_ci;
10863#ifdef FEAT_CINDENT
10864 buf->b_p_cin = p_cin;
10865 buf->b_p_cink = vim_strsave(p_cink);
10866 buf->b_p_cino = vim_strsave(p_cino);
10867#endif
10868#ifdef FEAT_AUTOCMD
10869 /* Don't copy 'filetype', it must be detected */
10870 buf->b_p_ft = empty_option;
10871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010872 buf->b_p_pi = p_pi;
10873#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10874 buf->b_p_cinw = vim_strsave(p_cinw);
10875#endif
10876#ifdef FEAT_LISP
10877 buf->b_p_lisp = p_lisp;
10878#endif
10879#ifdef FEAT_SYN_HL
10880 /* Don't copy 'syntax', it must be set */
10881 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010882 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010883 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010884#endif
10885#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010886 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010887 (void)compile_cap_prog(&buf->b_s);
10888 buf->b_s.b_p_spf = vim_strsave(p_spf);
10889 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890#endif
10891#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10892 buf->b_p_inde = vim_strsave(p_inde);
10893 buf->b_p_indk = vim_strsave(p_indk);
10894#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010895 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010896#if defined(FEAT_EVAL)
10897 buf->b_p_fex = vim_strsave(p_fex);
10898#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899#ifdef FEAT_CRYPT
10900 buf->b_p_key = vim_strsave(p_key);
10901#endif
10902#ifdef FEAT_SEARCHPATH
10903 buf->b_p_sua = vim_strsave(p_sua);
10904#endif
10905#ifdef FEAT_KEYMAP
10906 buf->b_p_keymap = vim_strsave(p_keymap);
10907 buf->b_kmap_state |= KEYMAP_INIT;
10908#endif
10909 /* This isn't really an option, but copying the langmap and IME
10910 * state from the current buffer is better than resetting it. */
10911 buf->b_p_iminsert = p_iminsert;
10912 buf->b_p_imsearch = p_imsearch;
10913
10914 /* options that are normally global but also have a local value
10915 * are not copied, start using the global value */
10916 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010917 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010918 buf->b_p_bkc = empty_option;
10919 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920#ifdef FEAT_QUICKFIX
10921 buf->b_p_gp = empty_option;
10922 buf->b_p_mp = empty_option;
10923 buf->b_p_efm = empty_option;
10924#endif
10925 buf->b_p_ep = empty_option;
10926 buf->b_p_kp = empty_option;
10927 buf->b_p_path = empty_option;
10928 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010929 buf->b_p_tc = empty_option;
10930 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010931#ifdef FEAT_FIND_ID
10932 buf->b_p_def = empty_option;
10933 buf->b_p_inc = empty_option;
10934# ifdef FEAT_EVAL
10935 buf->b_p_inex = vim_strsave(p_inex);
10936# endif
10937#endif
10938#ifdef FEAT_INS_EXPAND
10939 buf->b_p_dict = empty_option;
10940 buf->b_p_tsr = empty_option;
10941#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010942#ifdef FEAT_TEXTOBJ
10943 buf->b_p_qe = vim_strsave(p_qe);
10944#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010945#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10946 buf->b_p_bexpr = empty_option;
10947#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010948#if defined(FEAT_CRYPT)
10949 buf->b_p_cm = empty_option;
10950#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010951#ifdef FEAT_PERSISTENT_UNDO
10952 buf->b_p_udf = p_udf;
10953#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010954#ifdef FEAT_LISP
10955 buf->b_p_lw = empty_option;
10956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957
10958 /*
10959 * Don't copy the options set by ex_help(), use the saved values,
10960 * when going from a help buffer to a non-help buffer.
10961 * Don't touch these at all when BCO_NOHELP is used and going from
10962 * or to a help buffer.
10963 */
10964 if (dont_do_help)
10965 buf->b_p_isk = save_p_isk;
10966 else
10967 {
10968 buf->b_p_isk = vim_strsave(p_isk);
10969 did_isk = TRUE;
10970 buf->b_p_ts = p_ts;
10971 buf->b_help = FALSE;
10972#ifdef FEAT_QUICKFIX
10973 if (buf->b_p_bt[0] == 'h')
10974 clear_string_option(&buf->b_p_bt);
10975#endif
10976 buf->b_p_ma = p_ma;
10977 }
10978 }
10979
10980 /*
10981 * When the options should be copied (ignoring BCO_ALWAYS), set the
10982 * flag that indicates that the options have been initialized.
10983 */
10984 if (should_copy)
10985 buf->b_p_initialized = TRUE;
10986 }
10987
10988 check_buf_options(buf); /* make sure we don't have NULLs */
10989 if (did_isk)
10990 (void)buf_init_chartab(buf, FALSE);
10991}
10992
10993/*
10994 * Reset the 'modifiable' option and its default value.
10995 */
10996 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010997reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010998{
10999 int opt_idx;
11000
11001 curbuf->b_p_ma = FALSE;
11002 p_ma = FALSE;
11003 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011004 if (opt_idx >= 0)
11005 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011006}
11007
11008/*
11009 * Set the global value for 'iminsert' to the local value.
11010 */
11011 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011012set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013{
11014 p_iminsert = curbuf->b_p_iminsert;
11015}
11016
11017/*
11018 * Set the global value for 'imsearch' to the local value.
11019 */
11020 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011021set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011022{
11023 p_imsearch = curbuf->b_p_imsearch;
11024}
11025
11026#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11027static int expand_option_idx = -1;
11028static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11029static int expand_option_flags = 0;
11030
11031 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011032set_context_in_set_cmd(
11033 expand_T *xp,
11034 char_u *arg,
11035 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011036{
11037 int nextchar;
11038 long_u flags = 0; /* init for GCC */
11039 int opt_idx = 0; /* init for GCC */
11040 char_u *p;
11041 char_u *s;
11042 int is_term_option = FALSE;
11043 int key;
11044
11045 expand_option_flags = opt_flags;
11046
11047 xp->xp_context = EXPAND_SETTINGS;
11048 if (*arg == NUL)
11049 {
11050 xp->xp_pattern = arg;
11051 return;
11052 }
11053 p = arg + STRLEN(arg) - 1;
11054 if (*p == ' ' && *(p - 1) != '\\')
11055 {
11056 xp->xp_pattern = p + 1;
11057 return;
11058 }
11059 while (p > arg)
11060 {
11061 s = p;
11062 /* count number of backslashes before ' ' or ',' */
11063 if (*p == ' ' || *p == ',')
11064 {
11065 while (s > arg && *(s - 1) == '\\')
11066 --s;
11067 }
11068 /* break at a space with an even number of backslashes */
11069 if (*p == ' ' && ((p - s) & 1) == 0)
11070 {
11071 ++p;
11072 break;
11073 }
11074 --p;
11075 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011076 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011077 {
11078 xp->xp_context = EXPAND_BOOL_SETTINGS;
11079 p += 2;
11080 }
11081 if (STRNCMP(p, "inv", 3) == 0)
11082 {
11083 xp->xp_context = EXPAND_BOOL_SETTINGS;
11084 p += 3;
11085 }
11086 xp->xp_pattern = arg = p;
11087 if (*arg == '<')
11088 {
11089 while (*p != '>')
11090 if (*p++ == NUL) /* expand terminal option name */
11091 return;
11092 key = get_special_key_code(arg + 1);
11093 if (key == 0) /* unknown name */
11094 {
11095 xp->xp_context = EXPAND_NOTHING;
11096 return;
11097 }
11098 nextchar = *++p;
11099 is_term_option = TRUE;
11100 expand_option_name[2] = KEY2TERMCAP0(key);
11101 expand_option_name[3] = KEY2TERMCAP1(key);
11102 }
11103 else
11104 {
11105 if (p[0] == 't' && p[1] == '_')
11106 {
11107 p += 2;
11108 if (*p != NUL)
11109 ++p;
11110 if (*p == NUL)
11111 return; /* expand option name */
11112 nextchar = *++p;
11113 is_term_option = TRUE;
11114 expand_option_name[2] = p[-2];
11115 expand_option_name[3] = p[-1];
11116 }
11117 else
11118 {
11119 /* Allow * wildcard */
11120 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11121 p++;
11122 if (*p == NUL)
11123 return;
11124 nextchar = *p;
11125 *p = NUL;
11126 opt_idx = findoption(arg);
11127 *p = nextchar;
11128 if (opt_idx == -1 || options[opt_idx].var == NULL)
11129 {
11130 xp->xp_context = EXPAND_NOTHING;
11131 return;
11132 }
11133 flags = options[opt_idx].flags;
11134 if (flags & P_BOOL)
11135 {
11136 xp->xp_context = EXPAND_NOTHING;
11137 return;
11138 }
11139 }
11140 }
11141 /* handle "-=" and "+=" */
11142 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11143 {
11144 ++p;
11145 nextchar = '=';
11146 }
11147 if ((nextchar != '=' && nextchar != ':')
11148 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11149 {
11150 xp->xp_context = EXPAND_UNSUCCESSFUL;
11151 return;
11152 }
11153 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11154 {
11155 xp->xp_context = EXPAND_OLD_SETTING;
11156 if (is_term_option)
11157 expand_option_idx = -1;
11158 else
11159 expand_option_idx = opt_idx;
11160 xp->xp_pattern = p + 1;
11161 return;
11162 }
11163 xp->xp_context = EXPAND_NOTHING;
11164 if (is_term_option || (flags & P_NUM))
11165 return;
11166
11167 xp->xp_pattern = p + 1;
11168
11169 if (flags & P_EXPAND)
11170 {
11171 p = options[opt_idx].var;
11172 if (p == (char_u *)&p_bdir
11173 || p == (char_u *)&p_dir
11174 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011175 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011176 || p == (char_u *)&p_rtp
11177#ifdef FEAT_SEARCHPATH
11178 || p == (char_u *)&p_cdpath
11179#endif
11180#ifdef FEAT_SESSION
11181 || p == (char_u *)&p_vdir
11182#endif
11183 )
11184 {
11185 xp->xp_context = EXPAND_DIRECTORIES;
11186 if (p == (char_u *)&p_path
11187#ifdef FEAT_SEARCHPATH
11188 || p == (char_u *)&p_cdpath
11189#endif
11190 )
11191 xp->xp_backslash = XP_BS_THREE;
11192 else
11193 xp->xp_backslash = XP_BS_ONE;
11194 }
11195 else
11196 {
11197 xp->xp_context = EXPAND_FILES;
11198 /* for 'tags' need three backslashes for a space */
11199 if (p == (char_u *)&p_tags)
11200 xp->xp_backslash = XP_BS_THREE;
11201 else
11202 xp->xp_backslash = XP_BS_ONE;
11203 }
11204 }
11205
11206 /* For an option that is a list of file names, find the start of the
11207 * last file name. */
11208 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11209 {
11210 /* count number of backslashes before ' ' or ',' */
11211 if (*p == ' ' || *p == ',')
11212 {
11213 s = p;
11214 while (s > xp->xp_pattern && *(s - 1) == '\\')
11215 --s;
11216 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11217 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11218 {
11219 xp->xp_pattern = p + 1;
11220 break;
11221 }
11222 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011223
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011224#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011225 /* for 'spellsuggest' start at "file:" */
11226 if (options[opt_idx].var == (char_u *)&p_sps
11227 && STRNCMP(p, "file:", 5) == 0)
11228 {
11229 xp->xp_pattern = p + 5;
11230 break;
11231 }
11232#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011233 }
11234
11235 return;
11236}
11237
11238 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011239ExpandSettings(
11240 expand_T *xp,
11241 regmatch_T *regmatch,
11242 int *num_file,
11243 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011244{
11245 int num_normal = 0; /* Nr of matching non-term-code settings */
11246 int num_term = 0; /* Nr of matching terminal code settings */
11247 int opt_idx;
11248 int match;
11249 int count = 0;
11250 char_u *str;
11251 int loop;
11252 int is_term_opt;
11253 char_u name_buf[MAX_KEY_NAME_LEN];
11254 static char *(names[]) = {"all", "termcap"};
11255 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11256
11257 /* do this loop twice:
11258 * loop == 0: count the number of matching options
11259 * loop == 1: copy the matching options into allocated memory
11260 */
11261 for (loop = 0; loop <= 1; ++loop)
11262 {
11263 regmatch->rm_ic = ic;
11264 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11265 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011266 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11267 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011268 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11269 {
11270 if (loop == 0)
11271 num_normal++;
11272 else
11273 (*file)[count++] = vim_strsave((char_u *)names[match]);
11274 }
11275 }
11276 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11277 opt_idx++)
11278 {
11279 if (options[opt_idx].var == NULL)
11280 continue;
11281 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11282 && !(options[opt_idx].flags & P_BOOL))
11283 continue;
11284 is_term_opt = istermoption(&options[opt_idx]);
11285 if (is_term_opt && num_normal > 0)
11286 continue;
11287 match = FALSE;
11288 if (vim_regexec(regmatch, str, (colnr_T)0)
11289 || (options[opt_idx].shortname != NULL
11290 && vim_regexec(regmatch,
11291 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11292 match = TRUE;
11293 else if (is_term_opt)
11294 {
11295 name_buf[0] = '<';
11296 name_buf[1] = 't';
11297 name_buf[2] = '_';
11298 name_buf[3] = str[2];
11299 name_buf[4] = str[3];
11300 name_buf[5] = '>';
11301 name_buf[6] = NUL;
11302 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11303 {
11304 match = TRUE;
11305 str = name_buf;
11306 }
11307 }
11308 if (match)
11309 {
11310 if (loop == 0)
11311 {
11312 if (is_term_opt)
11313 num_term++;
11314 else
11315 num_normal++;
11316 }
11317 else
11318 (*file)[count++] = vim_strsave(str);
11319 }
11320 }
11321 /*
11322 * Check terminal key codes, these are not in the option table
11323 */
11324 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11325 {
11326 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11327 {
11328 if (!isprint(str[0]) || !isprint(str[1]))
11329 continue;
11330
11331 name_buf[0] = 't';
11332 name_buf[1] = '_';
11333 name_buf[2] = str[0];
11334 name_buf[3] = str[1];
11335 name_buf[4] = NUL;
11336
11337 match = FALSE;
11338 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11339 match = TRUE;
11340 else
11341 {
11342 name_buf[0] = '<';
11343 name_buf[1] = 't';
11344 name_buf[2] = '_';
11345 name_buf[3] = str[0];
11346 name_buf[4] = str[1];
11347 name_buf[5] = '>';
11348 name_buf[6] = NUL;
11349
11350 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11351 match = TRUE;
11352 }
11353 if (match)
11354 {
11355 if (loop == 0)
11356 num_term++;
11357 else
11358 (*file)[count++] = vim_strsave(name_buf);
11359 }
11360 }
11361
11362 /*
11363 * Check special key names.
11364 */
11365 regmatch->rm_ic = TRUE; /* ignore case here */
11366 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11367 {
11368 name_buf[0] = '<';
11369 STRCPY(name_buf + 1, str);
11370 STRCAT(name_buf, ">");
11371
11372 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11373 {
11374 if (loop == 0)
11375 num_term++;
11376 else
11377 (*file)[count++] = vim_strsave(name_buf);
11378 }
11379 }
11380 }
11381 if (loop == 0)
11382 {
11383 if (num_normal > 0)
11384 *num_file = num_normal;
11385 else if (num_term > 0)
11386 *num_file = num_term;
11387 else
11388 return OK;
11389 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11390 if (*file == NULL)
11391 {
11392 *file = (char_u **)"";
11393 return FAIL;
11394 }
11395 }
11396 }
11397 return OK;
11398}
11399
11400 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011401ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011402{
11403 char_u *var = NULL; /* init for GCC */
11404 char_u *buf;
11405
11406 *num_file = 0;
11407 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11408 if (*file == NULL)
11409 return FAIL;
11410
11411 /*
11412 * For a terminal key code expand_option_idx is < 0.
11413 */
11414 if (expand_option_idx < 0)
11415 {
11416 var = find_termcode(expand_option_name + 2);
11417 if (var == NULL)
11418 expand_option_idx = findoption(expand_option_name);
11419 }
11420
11421 if (expand_option_idx >= 0)
11422 {
11423 /* put string of option value in NameBuff */
11424 option_value2string(&options[expand_option_idx], expand_option_flags);
11425 var = NameBuff;
11426 }
11427 else if (var == NULL)
11428 var = (char_u *)"";
11429
11430 /* A backslash is required before some characters. This is the reverse of
11431 * what happens in do_set(). */
11432 buf = vim_strsave_escaped(var, escape_chars);
11433
11434 if (buf == NULL)
11435 {
11436 vim_free(*file);
11437 *file = NULL;
11438 return FAIL;
11439 }
11440
11441#ifdef BACKSLASH_IN_FILENAME
11442 /* For MS-Windows et al. we don't double backslashes at the start and
11443 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011444 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011445 if (var[0] == '\\' && var[1] == '\\'
11446 && expand_option_idx >= 0
11447 && (options[expand_option_idx].flags & P_EXPAND)
11448 && vim_isfilec(var[2])
11449 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011450 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011451#endif
11452
11453 *file[0] = buf;
11454 *num_file = 1;
11455 return OK;
11456}
11457#endif
11458
11459/*
11460 * Get the value for the numeric or string option *opp in a nice format into
11461 * NameBuff[]. Must not be called with a hidden option!
11462 */
11463 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011464option_value2string(
11465 struct vimoption *opp,
11466 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011467{
11468 char_u *varp;
11469
11470 varp = get_varp_scope(opp, opt_flags);
11471
11472 if (opp->flags & P_NUM)
11473 {
11474 long wc = 0;
11475
11476 if (wc_use_keyname(varp, &wc))
11477 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11478 else if (wc != 0)
11479 STRCPY(NameBuff, transchar((int)wc));
11480 else
11481 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11482 }
11483 else /* P_STRING */
11484 {
11485 varp = *(char_u **)(varp);
11486 if (varp == NULL) /* just in case */
11487 NameBuff[0] = NUL;
11488#ifdef FEAT_CRYPT
11489 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011490 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491 STRCPY(NameBuff, "*****");
11492#endif
11493 else if (opp->flags & P_EXPAND)
11494 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11495 /* Translate 'pastetoggle' into special key names */
11496 else if ((char_u **)opp->var == &p_pt)
11497 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11498 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011499 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011500 }
11501}
11502
11503/*
11504 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11505 * printed as a keyname.
11506 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11507 */
11508 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011509wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011510{
11511 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11512 {
11513 *wcp = *(long *)varp;
11514 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11515 return TRUE;
11516 }
11517 return FALSE;
11518}
11519
Bram Moolenaar01615492015-02-03 13:00:38 +010011520#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011521/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011522 * Any character has an equivalent 'langmap' character. This is used for
11523 * keyboards that have a special language mode that sends characters above
11524 * 128 (although other characters can be translated too). The "to" field is a
11525 * Vim command character. This avoids having to switch the keyboard back to
11526 * ASCII mode when leaving Insert mode.
11527 *
11528 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11529 * commands.
11530 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11531 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11532 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011534# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011535/*
11536 * With multi-byte support use growarray for 'langmap' chars >= 256
11537 */
11538typedef struct
11539{
11540 int from;
11541 int to;
11542} langmap_entry_T;
11543
11544static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011545static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011546
11547/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011548 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11549 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011550 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011551 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011552langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011553{
11554 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011555 int a = 0;
11556 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011557
11558 /* Do a binary search for an existing entry. */
11559 while (a != b)
11560 {
11561 int i = (a + b) / 2;
11562 int d = entries[i].from - from;
11563
11564 if (d == 0)
11565 {
11566 entries[i].to = to;
11567 return;
11568 }
11569 if (d < 0)
11570 a = i + 1;
11571 else
11572 b = i;
11573 }
11574
11575 if (ga_grow(&langmap_mapga, 1) != OK)
11576 return; /* out of memory */
11577
11578 /* insert new entry at position "a" */
11579 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11580 mch_memmove(entries + 1, entries,
11581 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11582 ++langmap_mapga.ga_len;
11583 entries[0].from = from;
11584 entries[0].to = to;
11585}
11586
11587/*
11588 * Apply 'langmap' to multi-byte character "c" and return the result.
11589 */
11590 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011591langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011592{
11593 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11594 int a = 0;
11595 int b = langmap_mapga.ga_len;
11596
11597 while (a != b)
11598 {
11599 int i = (a + b) / 2;
11600 int d = entries[i].from - c;
11601
11602 if (d == 0)
11603 return entries[i].to; /* found matching entry */
11604 if (d < 0)
11605 a = i + 1;
11606 else
11607 b = i;
11608 }
11609 return c; /* no entry found, return "c" unmodified */
11610}
11611# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612
11613 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011614langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011615{
11616 int i;
11617
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011618 for (i = 0; i < 256; i++)
11619 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11620# ifdef FEAT_MBYTE
11621 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11622# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623}
11624
11625/*
11626 * Called when langmap option is set; the language map can be
11627 * changed at any time!
11628 */
11629 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011630langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011631{
11632 char_u *p;
11633 char_u *p2;
11634 int from, to;
11635
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011636#ifdef FEAT_MBYTE
11637 ga_clear(&langmap_mapga); /* clear the previous map first */
11638#endif
11639 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640
11641 for (p = p_langmap; p[0] != NUL; )
11642 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011643 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11644 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011645 {
11646 if (p2[0] == '\\' && p2[1] != NUL)
11647 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011648 }
11649 if (p2[0] == ';')
11650 ++p2; /* abcd;ABCD form, p2 points to A */
11651 else
11652 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11653 while (p[0])
11654 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011655 if (p[0] == ',')
11656 {
11657 ++p;
11658 break;
11659 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011660 if (p[0] == '\\' && p[1] != NUL)
11661 ++p;
11662#ifdef FEAT_MBYTE
11663 from = (*mb_ptr2char)(p);
11664#else
11665 from = p[0];
11666#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011667 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011668 if (p2 == NULL)
11669 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011670 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011671 if (p[0] != ',')
11672 {
11673 if (p[0] == '\\')
11674 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011675#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011676 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011677#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011678 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011679#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011680 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011681 }
11682 else
11683 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011684 if (p2[0] != ',')
11685 {
11686 if (p2[0] == '\\')
11687 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011688#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011689 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011690#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011691 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011692#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011693 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011694 }
11695 if (to == NUL)
11696 {
11697 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11698 transchar(from));
11699 return;
11700 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011701
11702#ifdef FEAT_MBYTE
11703 if (from >= 256)
11704 langmap_set_entry(from, to);
11705 else
11706#endif
11707 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011708
11709 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011710 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011711 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011712 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011713 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714 if (*p == ';')
11715 {
11716 p = p2;
11717 if (p[0] != NUL)
11718 {
11719 if (p[0] != ',')
11720 {
11721 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11722 return;
11723 }
11724 ++p;
11725 }
11726 break;
11727 }
11728 }
11729 }
11730 }
11731}
11732#endif
11733
11734/*
11735 * Return TRUE if format option 'x' is in effect.
11736 * Take care of no formatting when 'paste' is set.
11737 */
11738 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011739has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011740{
11741 if (p_paste)
11742 return FALSE;
11743 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11744}
11745
11746/*
11747 * Return TRUE if "x" is present in 'shortmess' option, or
11748 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11749 */
11750 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011751shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011753 return p_shm != NULL &&
11754 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011755 || (vim_strchr(p_shm, 'a') != NULL
11756 && vim_strchr((char_u *)SHM_A, x) != NULL));
11757}
11758
11759/*
11760 * paste_option_changed() - Called after p_paste was set or reset.
11761 */
11762 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011763paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011764{
11765 static int old_p_paste = FALSE;
11766 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011767 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011768#ifdef FEAT_CMDL_INFO
11769 static int save_ru = 0;
11770#endif
11771#ifdef FEAT_RIGHTLEFT
11772 static int save_ri = 0;
11773 static int save_hkmap = 0;
11774#endif
11775 buf_T *buf;
11776
11777 if (p_paste)
11778 {
11779 /*
11780 * Paste switched from off to on.
11781 * Save the current values, so they can be restored later.
11782 */
11783 if (!old_p_paste)
11784 {
11785 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011786 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011787 {
11788 buf->b_p_tw_nopaste = buf->b_p_tw;
11789 buf->b_p_wm_nopaste = buf->b_p_wm;
11790 buf->b_p_sts_nopaste = buf->b_p_sts;
11791 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011792 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011793 }
11794
11795 /* save global options */
11796 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011797 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011798#ifdef FEAT_CMDL_INFO
11799 save_ru = p_ru;
11800#endif
11801#ifdef FEAT_RIGHTLEFT
11802 save_ri = p_ri;
11803 save_hkmap = p_hkmap;
11804#endif
11805 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011806 p_ai_nopaste = p_ai;
11807 p_et_nopaste = p_et;
11808 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011809 p_tw_nopaste = p_tw;
11810 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011811 }
11812
11813 /*
11814 * Always set the option values, also when 'paste' is set when it is
11815 * already on.
11816 */
11817 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011818 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819 {
11820 buf->b_p_tw = 0; /* textwidth is 0 */
11821 buf->b_p_wm = 0; /* wrapmargin is 0 */
11822 buf->b_p_sts = 0; /* softtabstop is 0 */
11823 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011824 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011825 }
11826
11827 /* set global options */
11828 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011829 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011830#ifdef FEAT_CMDL_INFO
11831# ifdef FEAT_WINDOWS
11832 if (p_ru)
11833 status_redraw_all(); /* redraw to remove the ruler */
11834# endif
11835 p_ru = 0; /* no ruler */
11836#endif
11837#ifdef FEAT_RIGHTLEFT
11838 p_ri = 0; /* no reverse insert */
11839 p_hkmap = 0; /* no Hebrew keyboard */
11840#endif
11841 /* set global values for local buffer options */
11842 p_tw = 0;
11843 p_wm = 0;
11844 p_sts = 0;
11845 p_ai = 0;
11846 }
11847
11848 /*
11849 * Paste switched from on to off: Restore saved values.
11850 */
11851 else if (old_p_paste)
11852 {
11853 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011854 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011855 {
11856 buf->b_p_tw = buf->b_p_tw_nopaste;
11857 buf->b_p_wm = buf->b_p_wm_nopaste;
11858 buf->b_p_sts = buf->b_p_sts_nopaste;
11859 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011860 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011861 }
11862
11863 /* restore global options */
11864 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011865 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011866#ifdef FEAT_CMDL_INFO
11867# ifdef FEAT_WINDOWS
11868 if (p_ru != save_ru)
11869 status_redraw_all(); /* redraw to draw the ruler */
11870# endif
11871 p_ru = save_ru;
11872#endif
11873#ifdef FEAT_RIGHTLEFT
11874 p_ri = save_ri;
11875 p_hkmap = save_hkmap;
11876#endif
11877 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011878 p_ai = p_ai_nopaste;
11879 p_et = p_et_nopaste;
11880 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881 p_tw = p_tw_nopaste;
11882 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883 }
11884
11885 old_p_paste = p_paste;
11886}
11887
11888/*
11889 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11890 *
11891 * Reset 'compatible' and set the values for options that didn't get set yet
11892 * to the Vim defaults.
11893 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011894 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011895 */
11896 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011897vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011898{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011899 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011900 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011901 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902
11903 if (!option_was_set((char_u *)"cp"))
11904 {
11905 p_cp = FALSE;
11906 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11907 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11908 set_option_default(opt_idx, OPT_FREE, FALSE);
11909 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011910 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011911 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011912
11913 if (fname != NULL)
11914 {
11915 p = vim_getenv(envname, &dofree);
11916 if (p == NULL)
11917 {
11918 /* Set $MYVIMRC to the first vimrc file found. */
11919 p = FullName_save(fname, FALSE);
11920 if (p != NULL)
11921 {
11922 vim_setenv(envname, p);
11923 vim_free(p);
11924 }
11925 }
11926 else if (dofree)
11927 vim_free(p);
11928 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011929}
11930
11931/*
11932 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11933 */
11934 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011935change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011936{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011937 int opt_idx;
11938
Bram Moolenaar071d4272004-06-13 20:20:40 +000011939 if (p_cp != on)
11940 {
11941 p_cp = on;
11942 compatible_set();
11943 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011944 opt_idx = findoption((char_u *)"cp");
11945 if (opt_idx >= 0)
11946 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011947}
11948
11949/*
11950 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011951 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011952 */
11953 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011954option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955{
11956 int idx;
11957
11958 idx = findoption(name);
11959 if (idx < 0) /* unknown option */
11960 return FALSE;
11961 if (options[idx].flags & P_WAS_SET)
11962 return TRUE;
11963 return FALSE;
11964}
11965
11966/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011967 * Reset the flag indicating option "name" was set.
11968 */
11969 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011970reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011971{
11972 int idx = findoption(name);
11973
11974 if (idx >= 0)
11975 options[idx].flags &= ~P_WAS_SET;
11976}
11977
11978/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011979 * compatible_set() - Called when 'compatible' has been set or unset.
11980 *
11981 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11982 * flag) to a Vi compatible value.
11983 * When 'compatible' is unset: Set all options that have a different default
11984 * for Vim (without the P_VI_DEF flag) to that default.
11985 */
11986 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011987compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011988{
11989 int opt_idx;
11990
11991 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11992 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11993 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11994 set_option_default(opt_idx, OPT_FREE, p_cp);
11995 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011996 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011997}
11998
11999#ifdef FEAT_LINEBREAK
12000
12001# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12002 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012003 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012004# endif
12005
12006/*
12007 * fill_breakat_flags() -- called when 'breakat' changes value.
12008 */
12009 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012010fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012011{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012012 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012013 int i;
12014
12015 for (i = 0; i < 256; i++)
12016 breakat_flags[i] = FALSE;
12017
12018 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012019 for (p = p_breakat; *p; p++)
12020 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021}
12022
12023# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012024 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025# endif
12026
12027#endif
12028
12029/*
12030 * Check an option that can be a range of string values.
12031 *
12032 * Return OK for correct value, FAIL otherwise.
12033 * Empty is always OK.
12034 */
12035 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012036check_opt_strings(
12037 char_u *val,
12038 char **values,
12039 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012040{
12041 return opt_strings_flags(val, values, NULL, list);
12042}
12043
12044/*
12045 * Handle an option that can be a range of string values.
12046 * Set a flag in "*flagp" for each string present.
12047 *
12048 * Return OK for correct value, FAIL otherwise.
12049 * Empty is always OK.
12050 */
12051 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012052opt_strings_flags(
12053 char_u *val, /* new value */
12054 char **values, /* array of valid string values */
12055 unsigned *flagp,
12056 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012057{
12058 int i;
12059 int len;
12060 unsigned new_flags = 0;
12061
12062 while (*val)
12063 {
12064 for (i = 0; ; ++i)
12065 {
12066 if (values[i] == NULL) /* val not found in values[] */
12067 return FAIL;
12068
12069 len = (int)STRLEN(values[i]);
12070 if (STRNCMP(values[i], val, len) == 0
12071 && ((list && val[len] == ',') || val[len] == NUL))
12072 {
12073 val += len + (val[len] == ',');
12074 new_flags |= (1 << i);
12075 break; /* check next item in val list */
12076 }
12077 }
12078 }
12079 if (flagp != NULL)
12080 *flagp = new_flags;
12081
12082 return OK;
12083}
12084
12085/*
12086 * Read the 'wildmode' option, fill wim_flags[].
12087 */
12088 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012089check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012090{
12091 char_u new_wim_flags[4];
12092 char_u *p;
12093 int i;
12094 int idx = 0;
12095
12096 for (i = 0; i < 4; ++i)
12097 new_wim_flags[i] = 0;
12098
12099 for (p = p_wim; *p; ++p)
12100 {
12101 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12102 ;
12103 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12104 return FAIL;
12105 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12106 new_wim_flags[idx] |= WIM_LONGEST;
12107 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12108 new_wim_flags[idx] |= WIM_FULL;
12109 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12110 new_wim_flags[idx] |= WIM_LIST;
12111 else
12112 return FAIL;
12113 p += i;
12114 if (*p == NUL)
12115 break;
12116 if (*p == ',')
12117 {
12118 if (idx == 3)
12119 return FAIL;
12120 ++idx;
12121 }
12122 }
12123
12124 /* fill remaining entries with last flag */
12125 while (idx < 3)
12126 {
12127 new_wim_flags[idx + 1] = new_wim_flags[idx];
12128 ++idx;
12129 }
12130
12131 /* only when there are no errors, wim_flags[] is changed */
12132 for (i = 0; i < 4; ++i)
12133 wim_flags[i] = new_wim_flags[i];
12134 return OK;
12135}
12136
12137/*
12138 * Check if backspacing over something is allowed.
12139 */
12140 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012141can_bs(
12142 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012143{
12144 switch (*p_bs)
12145 {
12146 case '2': return TRUE;
12147 case '1': return (what != BS_START);
12148 case '0': return FALSE;
12149 }
12150 return vim_strchr(p_bs, what) != NULL;
12151}
12152
12153/*
12154 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12155 * the file must be considered changed when the value is different.
12156 */
12157 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012158save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012159{
12160 buf->b_start_ffc = *buf->b_p_ff;
12161 buf->b_start_eol = buf->b_p_eol;
12162#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012163 buf->b_start_bomb = buf->b_p_bomb;
12164
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 /* Only use free/alloc when necessary, they take time. */
12166 if (buf->b_start_fenc == NULL
12167 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12168 {
12169 vim_free(buf->b_start_fenc);
12170 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12171 }
12172#endif
12173}
12174
12175/*
12176 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12177 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012178 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12179 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012180 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012181 * When "ignore_empty" is true don't consider a new, empty buffer to be
12182 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183 */
12184 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012185file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012186{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012187 /* In a buffer that was never loaded the options are not valid. */
12188 if (buf->b_flags & BF_NEVERLOADED)
12189 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012190 if (ignore_empty
12191 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012192 && buf->b_ml.ml_line_count == 1
12193 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12194 return FALSE;
12195 if (buf->b_start_ffc != *buf->b_p_ff)
12196 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012197 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012198 return TRUE;
12199#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012200 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12201 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012202 if (buf->b_start_fenc == NULL)
12203 return (*buf->b_p_fenc != NUL);
12204 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12205#else
12206 return FALSE;
12207#endif
12208}
12209
12210/*
12211 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12212 */
12213 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012214check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012215{
12216 return check_opt_strings(p, p_ff_values, FALSE);
12217}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012218
12219/*
12220 * Return the effective shiftwidth value for current buffer, using the
12221 * 'tabstop' value when 'shiftwidth' is zero.
12222 */
12223 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012224get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012225{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012226 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012227}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012228
12229/*
12230 * Return the effective softtabstop value for the current buffer, using the
12231 * 'tabstop' value when 'softtabstop' is negative.
12232 */
12233 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012234get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012235{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012236 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012237}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012238
12239/*
12240 * Check matchpairs option for "*initc".
12241 * If there is a match set "*initc" to the matching character and "*findc" to
12242 * the opposite character. Set "*backwards" to the direction.
12243 * When "switchit" is TRUE swap the direction.
12244 */
12245 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012246find_mps_values(
12247 int *initc,
12248 int *findc,
12249 int *backwards,
12250 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012251{
12252 char_u *ptr;
12253
12254 ptr = curbuf->b_p_mps;
12255 while (*ptr != NUL)
12256 {
12257#ifdef FEAT_MBYTE
12258 if (has_mbyte)
12259 {
12260 char_u *prev;
12261
12262 if (mb_ptr2char(ptr) == *initc)
12263 {
12264 if (switchit)
12265 {
12266 *findc = *initc;
12267 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12268 *backwards = TRUE;
12269 }
12270 else
12271 {
12272 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12273 *backwards = FALSE;
12274 }
12275 return;
12276 }
12277 prev = ptr;
12278 ptr += mb_ptr2len(ptr) + 1;
12279 if (mb_ptr2char(ptr) == *initc)
12280 {
12281 if (switchit)
12282 {
12283 *findc = *initc;
12284 *initc = mb_ptr2char(prev);
12285 *backwards = FALSE;
12286 }
12287 else
12288 {
12289 *findc = mb_ptr2char(prev);
12290 *backwards = TRUE;
12291 }
12292 return;
12293 }
12294 ptr += mb_ptr2len(ptr);
12295 }
12296 else
12297#endif
12298 {
12299 if (*ptr == *initc)
12300 {
12301 if (switchit)
12302 {
12303 *backwards = TRUE;
12304 *findc = *initc;
12305 *initc = ptr[2];
12306 }
12307 else
12308 {
12309 *backwards = FALSE;
12310 *findc = ptr[2];
12311 }
12312 return;
12313 }
12314 ptr += 2;
12315 if (*ptr == *initc)
12316 {
12317 if (switchit)
12318 {
12319 *backwards = FALSE;
12320 *findc = *initc;
12321 *initc = ptr[-2];
12322 }
12323 else
12324 {
12325 *backwards = TRUE;
12326 *findc = ptr[-2];
12327 }
12328 return;
12329 }
12330 ++ptr;
12331 }
12332 if (*ptr == ',')
12333 ++ptr;
12334 }
12335}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012336
12337#if defined(FEAT_LINEBREAK) || defined(PROTO)
12338/*
12339 * This is called when 'breakindentopt' is changed and when a window is
12340 * initialized.
12341 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012342 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012343briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012344{
12345 char_u *p;
12346 int bri_shift = 0;
12347 long bri_min = 20;
12348 int bri_sbr = FALSE;
12349
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012350 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012351 while (*p != NUL)
12352 {
12353 if (STRNCMP(p, "shift:", 6) == 0
12354 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12355 {
12356 p += 6;
12357 bri_shift = getdigits(&p);
12358 }
12359 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12360 {
12361 p += 4;
12362 bri_min = getdigits(&p);
12363 }
12364 else if (STRNCMP(p, "sbr", 3) == 0)
12365 {
12366 p += 3;
12367 bri_sbr = TRUE;
12368 }
12369 if (*p != ',' && *p != NUL)
12370 return FAIL;
12371 if (*p == ',')
12372 ++p;
12373 }
12374
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012375 wp->w_p_brishift = bri_shift;
12376 wp->w_p_brimin = bri_min;
12377 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012378
12379 return OK;
12380}
12381#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012382
12383/*
12384 * Get the local or global value of 'backupcopy'.
12385 */
12386 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012387get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012388{
12389 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12390}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012391
12392#if defined(FEAT_SIGNS) || defined(PROTO)
12393/*
12394 * Return TRUE when window "wp" has a column to draw signs in.
12395 */
12396 int
12397signcolumn_on(win_T *wp)
12398{
12399 if (*wp->w_p_scl == 'n')
12400 return FALSE;
12401 if (*wp->w_p_scl == 'y')
12402 return TRUE;
12403 return (wp->w_buffer->b_signlist != NULL
12404# ifdef FEAT_NETBEANS_INTG
12405 || wp->w_buffer->b_has_sign_column
12406# endif
12407 );
12408}
12409#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012410
12411#if defined(FEAT_EVAL) || defined(PROTO)
12412/*
12413 * Get window or buffer local options.
12414 */
12415 dict_T *
12416get_winbuf_options(int bufopt)
12417{
12418 dict_T *d;
12419 int opt_idx;
12420
12421 d = dict_alloc();
12422 if (d == NULL)
12423 return NULL;
12424
12425 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12426 {
12427 struct vimoption *opt = &options[opt_idx];
12428
12429 if ((bufopt && (opt->indir & PV_BUF))
12430 || (!bufopt && (opt->indir & PV_WIN)))
12431 {
12432 char_u *varp = get_varp(opt);
12433
12434 if (varp != NULL)
12435 {
12436 if (opt->flags & P_STRING)
12437 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012438 else if (opt->flags & P_NUM)
12439 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012440 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012441 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012442 }
12443 }
12444 }
12445
12446 return d;
12447}
12448#endif