blob: cc68cdfd5b8c11f2651e1053ac42cda77a3cf8b5 [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 }
6622 }
6623
6624#ifdef FEAT_LINEBREAK
6625 /* 'showbreak' */
6626 else if (varp == &p_sbr)
6627 {
6628 for (s = p_sbr; *s; )
6629 {
6630 if (ptr2cells(s) != 1)
6631 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006632 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006633 }
6634 }
6635#endif
6636
6637#ifdef FEAT_GUI
6638 /* 'guifont' */
6639 else if (varp == &p_guifont)
6640 {
6641 if (gui.in_use)
6642 {
6643 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006644# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006645 /*
6646 * Put up a font dialog and let the user select a new value.
6647 * If this is cancelled go back to the old value but don't
6648 * give an error message.
6649 */
6650 if (STRCMP(p, "*") == 0)
6651 {
6652 p = gui_mch_font_dialog(oldval);
6653
6654 if (new_value_alloced)
6655 free_string_option(p_guifont);
6656
6657 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6658 new_value_alloced = TRUE;
6659 }
6660# endif
6661 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6662 {
6663# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6664 if (STRCMP(p_guifont, "*") == 0)
6665 {
6666 /* Dialog was cancelled: Keep the old value without giving
6667 * an error message. */
6668 if (new_value_alloced)
6669 free_string_option(p_guifont);
6670 p_guifont = vim_strsave(oldval);
6671 new_value_alloced = TRUE;
6672 }
6673 else
6674# endif
6675 errmsg = (char_u *)N_("E596: Invalid font(s)");
6676 }
6677 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006678 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006679 }
6680# ifdef FEAT_XFONTSET
6681 else if (varp == &p_guifontset)
6682 {
6683 if (STRCMP(p_guifontset, "*") == 0)
6684 errmsg = (char_u *)N_("E597: can't select fontset");
6685 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6686 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006687 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006688 }
6689# endif
6690# ifdef FEAT_MBYTE
6691 else if (varp == &p_guifontwide)
6692 {
6693 if (STRCMP(p_guifontwide, "*") == 0)
6694 errmsg = (char_u *)N_("E533: can't select wide font");
6695 else if (gui_get_wide_font() == FAIL)
6696 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006697 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698 }
6699# endif
6700#endif
6701
6702#ifdef CURSOR_SHAPE
6703 /* 'guicursor' */
6704 else if (varp == &p_guicursor)
6705 errmsg = parse_shape_opt(SHAPE_CURSOR);
6706#endif
6707
6708#ifdef FEAT_MOUSESHAPE
6709 /* 'mouseshape' */
6710 else if (varp == &p_mouseshape)
6711 {
6712 errmsg = parse_shape_opt(SHAPE_MOUSE);
6713 update_mouseshape(-1);
6714 }
6715#endif
6716
6717#ifdef FEAT_PRINTER
6718 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006719 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006720# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006721 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006722 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006723# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006724#endif
6725
6726#ifdef FEAT_LANGMAP
6727 /* 'langmap' */
6728 else if (varp == &p_langmap)
6729 langmap_set();
6730#endif
6731
6732#ifdef FEAT_LINEBREAK
6733 /* 'breakat' */
6734 else if (varp == &p_breakat)
6735 fill_breakat_flags();
6736#endif
6737
6738#ifdef FEAT_TITLE
6739 /* 'titlestring' and 'iconstring' */
6740 else if (varp == &p_titlestring || varp == &p_iconstring)
6741 {
6742# ifdef FEAT_STL_OPT
6743 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6744
6745 /* NULL => statusline syntax */
6746 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6747 stl_syntax |= flagval;
6748 else
6749 stl_syntax &= ~flagval;
6750# endif
6751 did_set_title(varp == &p_iconstring);
6752
6753 }
6754#endif
6755
6756#ifdef FEAT_GUI
6757 /* 'guioptions' */
6758 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006759 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006760 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006761 redraw_gui_only = TRUE;
6762 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006763#endif
6764
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006765#if defined(FEAT_GUI_TABLINE)
6766 /* 'guitablabel' */
6767 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006768 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006769 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006770 redraw_gui_only = TRUE;
6771 }
6772 /* 'guitabtooltip' */
6773 else if (varp == &p_gtt)
6774 {
6775 redraw_gui_only = TRUE;
6776 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006777#endif
6778
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6780 /* 'ttymouse' */
6781 else if (varp == &p_ttym)
6782 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006783 /* Switch the mouse off before changing the escape sequences used for
6784 * that. */
6785 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6787 errmsg = e_invarg;
6788 else
6789 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006790 if (termcap_active)
6791 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792 }
6793#endif
6794
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 /* 'selection' */
6796 else if (varp == &p_sel)
6797 {
6798 if (*p_sel == NUL
6799 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6800 errmsg = e_invarg;
6801 }
6802
6803 /* 'selectmode' */
6804 else if (varp == &p_slm)
6805 {
6806 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6807 errmsg = e_invarg;
6808 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006809
6810#ifdef FEAT_BROWSE
6811 /* 'browsedir' */
6812 else if (varp == &p_bsdir)
6813 {
6814 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6815 && !mch_isdir(p_bsdir))
6816 errmsg = e_invarg;
6817 }
6818#endif
6819
Bram Moolenaar071d4272004-06-13 20:20:40 +00006820 /* 'keymodel' */
6821 else if (varp == &p_km)
6822 {
6823 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6824 errmsg = e_invarg;
6825 else
6826 {
6827 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6828 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6829 }
6830 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831
6832 /* 'mousemodel' */
6833 else if (varp == &p_mousem)
6834 {
6835 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6836 errmsg = e_invarg;
6837#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6838 else if (*p_mousem != *oldval)
6839 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6840 * to create or delete the popup menus. */
6841 gui_motif_update_mousemodel(root_menu);
6842#endif
6843 }
6844
6845 /* 'switchbuf' */
6846 else if (varp == &p_swb)
6847 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006848 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006849 errmsg = e_invarg;
6850 }
6851
6852 /* 'debug' */
6853 else if (varp == &p_debug)
6854 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006855 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006856 errmsg = e_invarg;
6857 }
6858
6859 /* 'display' */
6860 else if (varp == &p_dy)
6861 {
6862 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6863 errmsg = e_invarg;
6864 else
6865 (void)init_chartab();
6866
6867 }
6868
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006869#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870 /* 'eadirection' */
6871 else if (varp == &p_ead)
6872 {
6873 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6874 errmsg = e_invarg;
6875 }
6876#endif
6877
6878#ifdef FEAT_CLIPBOARD
6879 /* 'clipboard' */
6880 else if (varp == &p_cb)
6881 errmsg = check_clipboard_option();
6882#endif
6883
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006884#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006885 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6886 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006887 else if (varp == &(curwin->w_s->b_p_spl)
6888 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006889 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006890 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006891 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006892 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006893 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006894 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006895 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006896 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006897 /* 'spellsuggest' */
6898 else if (varp == &p_sps)
6899 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006900 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006901 errmsg = e_invarg;
6902 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006903 /* 'mkspellmem' */
6904 else if (varp == &p_msm)
6905 {
6906 if (spell_check_msm() != OK)
6907 errmsg = e_invarg;
6908 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006909#endif
6910
Bram Moolenaar071d4272004-06-13 20:20:40 +00006911#ifdef FEAT_QUICKFIX
6912 /* When 'bufhidden' is set, check for valid value. */
6913 else if (gvarp == &p_bh)
6914 {
6915 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6916 errmsg = e_invarg;
6917 }
6918
6919 /* When 'buftype' is set, check for valid value. */
6920 else if (gvarp == &p_bt)
6921 {
6922 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6923 errmsg = e_invarg;
6924 else
6925 {
6926# ifdef FEAT_WINDOWS
6927 if (curwin->w_status_height)
6928 {
6929 curwin->w_redr_status = TRUE;
6930 redraw_later(VALID);
6931 }
6932# endif
6933 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006934# ifdef FEAT_TITLE
6935 redraw_titles();
6936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006937 }
6938 }
6939#endif
6940
6941#ifdef FEAT_STL_OPT
6942 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006943 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006944 {
6945 int wid;
6946
6947 if (varp == &p_ruf) /* reset ru_wid first */
6948 ru_wid = 0;
6949 s = *varp;
6950 if (varp == &p_ruf && *s == '%')
6951 {
6952 /* set ru_wid if 'ruf' starts with "%99(" */
6953 if (*++s == '-') /* ignore a '-' */
6954 s++;
6955 wid = getdigits(&s);
6956 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6957 ru_wid = wid;
6958 else
6959 errmsg = check_stl_option(p_ruf);
6960 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006961 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006962 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006963 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006964 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965 comp_col();
6966 }
6967#endif
6968
6969#ifdef FEAT_INS_EXPAND
6970 /* check if it is a valid value for 'complete' -- Acevedo */
6971 else if (gvarp == &p_cpt)
6972 {
6973 for (s = *varp; *s;)
6974 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02006975 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006976 s++;
6977 if (!*s)
6978 break;
6979 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
6980 {
6981 errmsg = illegal_char(errbuf, *s);
6982 break;
6983 }
6984 if (*++s != NUL && *s != ',' && *s != ' ')
6985 {
6986 if (s[-1] == 'k' || s[-1] == 's')
6987 {
6988 /* skip optional filename after 'k' and 's' */
6989 while (*s && *s != ',' && *s != ' ')
6990 {
6991 if (*s == '\\')
6992 ++s;
6993 ++s;
6994 }
6995 }
6996 else
6997 {
6998 if (errbuf != NULL)
6999 {
7000 sprintf((char *)errbuf,
7001 _("E535: Illegal character after <%c>"),
7002 *--s);
7003 errmsg = errbuf;
7004 }
7005 else
7006 errmsg = (char_u *)"";
7007 break;
7008 }
7009 }
7010 }
7011 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007012
7013 /* 'completeopt' */
7014 else if (varp == &p_cot)
7015 {
7016 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7017 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007018 else
7019 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007020 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007021#endif /* FEAT_INS_EXPAND */
7022
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007023#ifdef FEAT_SIGNS
7024 /* 'signcolumn' */
7025 else if (varp == &curwin->w_p_scl)
7026 {
7027 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7028 errmsg = e_invarg;
7029 }
7030#endif
7031
Bram Moolenaar071d4272004-06-13 20:20:40 +00007032
7033#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007034 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007035 else if (varp == &p_toolbar)
7036 {
7037 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7038 &toolbar_flags, TRUE) != OK)
7039 errmsg = e_invarg;
7040 else
7041 {
7042 out_flush();
7043 gui_mch_show_toolbar((toolbar_flags &
7044 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7045 }
7046 }
7047#endif
7048
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007049#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 /* 'toolbariconsize': GTK+ 2 only */
7051 else if (varp == &p_tbis)
7052 {
7053 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7054 errmsg = e_invarg;
7055 else
7056 {
7057 out_flush();
7058 gui_mch_show_toolbar((toolbar_flags &
7059 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7060 }
7061 }
7062#endif
7063
7064 /* 'pastetoggle': translate key codes like in a mapping */
7065 else if (varp == &p_pt)
7066 {
7067 if (*p_pt)
7068 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007069 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 if (p != NULL)
7071 {
7072 if (new_value_alloced)
7073 free_string_option(p_pt);
7074 p_pt = p;
7075 new_value_alloced = TRUE;
7076 }
7077 }
7078 }
7079
7080 /* 'backspace' */
7081 else if (varp == &p_bs)
7082 {
7083 if (VIM_ISDIGIT(*p_bs))
7084 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007085 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007086 errmsg = e_invarg;
7087 }
7088 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7089 errmsg = e_invarg;
7090 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007091 else if (varp == &p_bo)
7092 {
7093 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7094 errmsg = e_invarg;
7095 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007097 /* 'tagcase' */
7098 else if (gvarp == &p_tc)
7099 {
7100 unsigned int *flags;
7101
7102 if (opt_flags & OPT_LOCAL)
7103 {
7104 p = curbuf->b_p_tc;
7105 flags = &curbuf->b_tc_flags;
7106 }
7107 else
7108 {
7109 p = p_tc;
7110 flags = &tc_flags;
7111 }
7112
7113 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7114 /* make the local value empty: use the global value */
7115 *flags = 0;
7116 else if (*p == NUL
7117 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7118 errmsg = e_invarg;
7119 }
7120
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007121#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 /* 'casemap' */
7123 else if (varp == &p_cmp)
7124 {
7125 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7126 errmsg = e_invarg;
7127 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007128#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007129
7130#ifdef FEAT_DIFF
7131 /* 'diffopt' */
7132 else if (varp == &p_dip)
7133 {
7134 if (diffopt_changed() == FAIL)
7135 errmsg = e_invarg;
7136 }
7137#endif
7138
7139#ifdef FEAT_FOLDING
7140 /* 'foldmethod' */
7141 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7142 {
7143 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7144 || *curwin->w_p_fdm == NUL)
7145 errmsg = e_invarg;
7146 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007147 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007148 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007149 if (foldmethodIsDiff(curwin))
7150 newFoldLevel();
7151 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007152 }
7153# ifdef FEAT_EVAL
7154 /* 'foldexpr' */
7155 else if (varp == &curwin->w_p_fde)
7156 {
7157 if (foldmethodIsExpr(curwin))
7158 foldUpdateAll(curwin);
7159 }
7160# endif
7161 /* 'foldmarker' */
7162 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7163 {
7164 p = vim_strchr(*varp, ',');
7165 if (p == NULL)
7166 errmsg = (char_u *)N_("E536: comma required");
7167 else if (p == *varp || p[1] == NUL)
7168 errmsg = e_invarg;
7169 else if (foldmethodIsMarker(curwin))
7170 foldUpdateAll(curwin);
7171 }
7172 /* 'commentstring' */
7173 else if (gvarp == &p_cms)
7174 {
7175 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7176 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7177 }
7178 /* 'foldopen' */
7179 else if (varp == &p_fdo)
7180 {
7181 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7182 errmsg = e_invarg;
7183 }
7184 /* 'foldclose' */
7185 else if (varp == &p_fcl)
7186 {
7187 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7188 errmsg = e_invarg;
7189 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007190 /* 'foldignore' */
7191 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7192 {
7193 if (foldmethodIsIndent(curwin))
7194 foldUpdateAll(curwin);
7195 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007196#endif
7197
7198#ifdef FEAT_VIRTUALEDIT
7199 /* 'virtualedit' */
7200 else if (varp == &p_ve)
7201 {
7202 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7203 errmsg = e_invarg;
7204 else if (STRCMP(p_ve, oldval) != 0)
7205 {
7206 /* Recompute cursor position in case the new 've' setting
7207 * changes something. */
7208 validate_virtcol();
7209 coladvance(curwin->w_virtcol);
7210 }
7211 }
7212#endif
7213
7214#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7215 else if (varp == &p_csqf)
7216 {
7217 if (p_csqf != NULL)
7218 {
7219 p = p_csqf;
7220 while (*p != NUL)
7221 {
7222 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7223 || p[1] == NUL
7224 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7225 || (p[2] != NUL && p[2] != ','))
7226 {
7227 errmsg = e_invarg;
7228 break;
7229 }
7230 else if (p[2] == NUL)
7231 break;
7232 else
7233 p += 3;
7234 }
7235 }
7236 }
7237#endif
7238
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007239#ifdef FEAT_CINDENT
7240 /* 'cinoptions' */
7241 else if (gvarp == &p_cino)
7242 {
7243 /* TODO: recognize errors */
7244 parse_cino(curbuf);
7245 }
7246#endif
7247
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007248#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007249 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007250 else if (varp == &p_rop && gui.in_use)
7251 {
7252 if (!gui_mch_set_rendering_options(p_rop))
7253 errmsg = e_invarg;
7254 }
7255#endif
7256
Bram Moolenaard0b51382016-11-04 15:23:45 +01007257#ifdef FEAT_AUTOCMD
7258 else if (gvarp == &p_ft)
7259 {
7260 if (!valid_filetype(*varp))
7261 errmsg = e_invarg;
7262 }
7263#endif
7264
7265#ifdef FEAT_SYN_HL
7266 else if (gvarp == &p_syn)
7267 {
7268 if (!valid_filetype(*varp))
7269 errmsg = e_invarg;
7270 }
7271#endif
7272
Bram Moolenaar071d4272004-06-13 20:20:40 +00007273 /* Options that are a list of flags. */
7274 else
7275 {
7276 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007277 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007278 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007279 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007280 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007281 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007283 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007284 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007285#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007286 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007287 p = (char_u *)COCU_ALL;
7288#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007289 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007290 {
7291#ifdef FEAT_MOUSE
7292 p = (char_u *)MOUSE_ALL;
7293#else
7294 if (*p_mouse != NUL)
7295 errmsg = (char_u *)N_("E538: No mouse support");
7296#endif
7297 }
7298#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007299 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007300 p = (char_u *)GO_ALL;
7301#endif
7302 if (p != NULL)
7303 {
7304 for (s = *varp; *s; ++s)
7305 if (vim_strchr(p, *s) == NULL)
7306 {
7307 errmsg = illegal_char(errbuf, *s);
7308 break;
7309 }
7310 }
7311 }
7312
7313 /*
7314 * If error detected, restore the previous value.
7315 */
7316 if (errmsg != NULL)
7317 {
7318 if (new_value_alloced)
7319 free_string_option(*varp);
7320 *varp = oldval;
7321 /*
7322 * When resetting some values, need to act on it.
7323 */
7324 if (did_chartab)
7325 (void)init_chartab();
7326 if (varp == &p_hl)
7327 (void)highlight_changed();
7328 }
7329 else
7330 {
7331#ifdef FEAT_EVAL
7332 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007333 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007334#endif
7335 /*
7336 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007337 * Use "free_oldval", because recursiveness may change the flags under
7338 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007339 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007340 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007341 free_string_option(oldval);
7342 if (new_value_alloced)
7343 options[opt_idx].flags |= P_ALLOCED;
7344 else
7345 options[opt_idx].flags &= ~P_ALLOCED;
7346
7347 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007348 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007349 {
7350 /* global option with local value set to use global value; free
7351 * the local value and make it empty */
7352 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7353 free_string_option(*(char_u **)p);
7354 *(char_u **)p = empty_option;
7355 }
7356
7357 /* May set global value for local option. */
7358 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7359 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007360
7361#ifdef FEAT_AUTOCMD
7362 /*
7363 * Trigger the autocommand only after setting the flags.
7364 */
7365# ifdef FEAT_SYN_HL
7366 /* When 'syntax' is set, load the syntax of that name */
7367 if (varp == &(curbuf->b_p_syn))
7368 {
7369 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7370 curbuf->b_fname, TRUE, curbuf);
7371 }
7372# endif
7373 else if (varp == &(curbuf->b_p_ft))
7374 {
7375 /* 'filetype' is set, trigger the FileType autocommand */
7376 did_filetype = TRUE;
7377 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7378 curbuf->b_fname, TRUE, curbuf);
7379 }
7380#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007381#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007382 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007383 {
7384 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007385 char_u *q = curwin->w_s->b_p_spl;
7386
7387 /* Skip the first name if it is "cjk". */
7388 if (STRNCMP(q, "cjk,", 4) == 0)
7389 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007390
7391 /*
7392 * Source the spell/LANG.vim in 'runtimepath'.
7393 * They could set 'spellcapcheck' depending on the language.
7394 * Use the first name in 'spelllang' up to '_region' or
7395 * '.encoding'.
7396 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007397 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007398 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7399 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007400 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007401 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007402 }
7403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007404 }
7405
7406#ifdef FEAT_MOUSE
7407 if (varp == &p_mouse)
7408 {
7409# ifdef FEAT_MOUSE_TTY
7410 if (*p_mouse == NUL)
7411 mch_setmouse(FALSE); /* switch mouse off */
7412 else
7413# endif
7414 setmouse(); /* in case 'mouse' changed */
7415 }
7416#endif
7417
Bram Moolenaar913077c2012-03-28 19:59:04 +02007418 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007419 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007420 curwin->w_set_curswant = TRUE;
7421
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007422#ifdef FEAT_GUI
7423 /* check redraw when it's not a GUI option or the GUI is active. */
7424 if (!redraw_gui_only || gui.in_use)
7425#endif
7426 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007427
7428 return errmsg;
7429}
7430
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007431#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007432/*
7433 * Simple int comparison function for use with qsort()
7434 */
7435 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007436int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007437{
7438 return *(const int *)a - *(const int *)b;
7439}
7440
7441/*
7442 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7443 * Returns error message, NULL if it's OK.
7444 */
7445 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007446check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007447{
7448 char_u *s;
7449 int col;
7450 int count = 0;
7451 int color_cols[256];
7452 int i;
7453 int j = 0;
7454
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007455 if (wp->w_buffer == NULL)
7456 return NULL; /* buffer was closed */
7457
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007458 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007459 {
7460 if (*s == '-' || *s == '+')
7461 {
7462 /* -N and +N: add to 'textwidth' */
7463 col = (*s == '-') ? -1 : 1;
7464 ++s;
7465 if (!VIM_ISDIGIT(*s))
7466 return e_invarg;
7467 col = col * getdigits(&s);
7468 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007469 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007470 col += wp->w_buffer->b_p_tw;
7471 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007472 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007473 }
7474 else if (VIM_ISDIGIT(*s))
7475 col = getdigits(&s);
7476 else
7477 return e_invarg;
7478 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007479skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007480 if (*s == NUL)
7481 break;
7482 if (*s != ',')
7483 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007484 if (*++s == NUL)
7485 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007486 }
7487
7488 vim_free(wp->w_p_cc_cols);
7489 if (count == 0)
7490 wp->w_p_cc_cols = NULL;
7491 else
7492 {
7493 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7494 if (wp->w_p_cc_cols != NULL)
7495 {
7496 /* sort the columns for faster usage on screen redraw inside
7497 * win_line() */
7498 qsort(color_cols, count, sizeof(int), int_cmp);
7499
7500 for (i = 0; i < count; ++i)
7501 /* skip duplicates */
7502 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7503 wp->w_p_cc_cols[j++] = color_cols[i];
7504 wp->w_p_cc_cols[j] = -1; /* end marker */
7505 }
7506 }
7507
7508 return NULL; /* no error */
7509}
7510#endif
7511
Bram Moolenaar071d4272004-06-13 20:20:40 +00007512/*
7513 * Handle setting 'listchars' or 'fillchars'.
7514 * Returns error message, NULL if it's OK.
7515 */
7516 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007517set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518{
7519 int round, i, len, entries;
7520 char_u *p, *s;
7521 int c1, c2 = 0;
7522 struct charstab
7523 {
7524 int *cp;
7525 char *name;
7526 };
7527#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7528 static struct charstab filltab[] =
7529 {
7530 {&fill_stl, "stl"},
7531 {&fill_stlnc, "stlnc"},
7532 {&fill_vert, "vert"},
7533 {&fill_fold, "fold"},
7534 {&fill_diff, "diff"},
7535 };
7536#endif
7537 static struct charstab lcstab[] =
7538 {
7539 {&lcs_eol, "eol"},
7540 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007541 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007542 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007543 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007544 {&lcs_tab2, "tab"},
7545 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007546#ifdef FEAT_CONCEAL
7547 {&lcs_conceal, "conceal"},
7548#else
7549 {NULL, "conceal"},
7550#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007551 };
7552 struct charstab *tab;
7553
7554#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7555 if (varp == &p_lcs)
7556#endif
7557 {
7558 tab = lcstab;
7559 entries = sizeof(lcstab) / sizeof(struct charstab);
7560 }
7561#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7562 else
7563 {
7564 tab = filltab;
7565 entries = sizeof(filltab) / sizeof(struct charstab);
7566 }
7567#endif
7568
7569 /* first round: check for valid value, second round: assign values */
7570 for (round = 0; round <= 1; ++round)
7571 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007572 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573 {
7574 /* After checking that the value is valid: set defaults: space for
7575 * 'fillchars', NUL for 'listchars' */
7576 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007577 if (tab[i].cp != NULL)
7578 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007579 if (varp == &p_lcs)
7580 lcs_tab1 = NUL;
7581#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7582 else
7583 fill_diff = '-';
7584#endif
7585 }
7586 p = *varp;
7587 while (*p)
7588 {
7589 for (i = 0; i < entries; ++i)
7590 {
7591 len = (int)STRLEN(tab[i].name);
7592 if (STRNCMP(p, tab[i].name, len) == 0
7593 && p[len] == ':'
7594 && p[len + 1] != NUL)
7595 {
7596 s = p + len + 1;
7597#ifdef FEAT_MBYTE
7598 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007599 if (mb_char2cells(c1) > 1)
7600 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601#else
7602 c1 = *s++;
7603#endif
7604 if (tab[i].cp == &lcs_tab2)
7605 {
7606 if (*s == NUL)
7607 continue;
7608#ifdef FEAT_MBYTE
7609 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007610 if (mb_char2cells(c2) > 1)
7611 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007612#else
7613 c2 = *s++;
7614#endif
7615 }
7616 if (*s == ',' || *s == NUL)
7617 {
7618 if (round)
7619 {
7620 if (tab[i].cp == &lcs_tab2)
7621 {
7622 lcs_tab1 = c1;
7623 lcs_tab2 = c2;
7624 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007625 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007626 *(tab[i].cp) = c1;
7627
7628 }
7629 p = s;
7630 break;
7631 }
7632 }
7633 }
7634
7635 if (i == entries)
7636 return e_invarg;
7637 if (*p == ',')
7638 ++p;
7639 }
7640 }
7641
7642 return NULL; /* no error */
7643}
7644
7645#ifdef FEAT_STL_OPT
7646/*
7647 * Check validity of options with the 'statusline' format.
7648 * Return error message or NULL.
7649 */
7650 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007651check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007652{
7653 int itemcnt = 0;
7654 int groupdepth = 0;
7655 static char_u errbuf[80];
7656
7657 while (*s && itemcnt < STL_MAX_ITEM)
7658 {
7659 /* Check for valid keys after % sequences */
7660 while (*s && *s != '%')
7661 s++;
7662 if (!*s)
7663 break;
7664 s++;
7665 if (*s != '%' && *s != ')')
7666 ++itemcnt;
7667 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7668 {
7669 s++;
7670 continue;
7671 }
7672 if (*s == ')')
7673 {
7674 s++;
7675 if (--groupdepth < 0)
7676 break;
7677 continue;
7678 }
7679 if (*s == '-')
7680 s++;
7681 while (VIM_ISDIGIT(*s))
7682 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007683 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007684 continue;
7685 if (*s == '.')
7686 {
7687 s++;
7688 while (*s && VIM_ISDIGIT(*s))
7689 s++;
7690 }
7691 if (*s == '(')
7692 {
7693 groupdepth++;
7694 continue;
7695 }
7696 if (vim_strchr(STL_ALL, *s) == NULL)
7697 {
7698 return illegal_char(errbuf, *s);
7699 }
7700 if (*s == '{')
7701 {
7702 s++;
7703 while (*s != '}' && *s)
7704 s++;
7705 if (*s != '}')
7706 return (char_u *)N_("E540: Unclosed expression sequence");
7707 }
7708 }
7709 if (itemcnt >= STL_MAX_ITEM)
7710 return (char_u *)N_("E541: too many items");
7711 if (groupdepth != 0)
7712 return (char_u *)N_("E542: unbalanced groups");
7713 return NULL;
7714}
7715#endif
7716
7717#ifdef FEAT_CLIPBOARD
7718/*
7719 * Extract the items in the 'clipboard' option and set global values.
7720 */
7721 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007722check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007723{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007724 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007725 int new_autoselect_star = FALSE;
7726 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007727 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007728 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729 regprog_T *new_exclude_prog = NULL;
7730 char_u *errmsg = NULL;
7731 char_u *p;
7732
7733 for (p = p_cb; *p != NUL; )
7734 {
7735 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7736 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007737 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007738 p += 7;
7739 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007740 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007741 && (p[11] == ',' || p[11] == NUL))
7742 {
7743 new_unnamed |= CLIP_UNNAMED_PLUS;
7744 p += 11;
7745 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007746 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007747 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007748 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007749 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007750 p += 10;
7751 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007752 else if (STRNCMP(p, "autoselectplus", 14) == 0
7753 && (p[14] == ',' || p[14] == NUL))
7754 {
7755 new_autoselect_plus = TRUE;
7756 p += 14;
7757 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007759 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007760 {
7761 new_autoselectml = TRUE;
7762 p += 12;
7763 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007764 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7765 {
7766 new_html = TRUE;
7767 p += 4;
7768 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007769 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7770 {
7771 p += 8;
7772 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7773 if (new_exclude_prog == NULL)
7774 errmsg = e_invarg;
7775 break;
7776 }
7777 else
7778 {
7779 errmsg = e_invarg;
7780 break;
7781 }
7782 if (*p == ',')
7783 ++p;
7784 }
7785 if (errmsg == NULL)
7786 {
7787 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007788 clip_autoselect_star = new_autoselect_star;
7789 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007790 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007791 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007792 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007793 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007794#ifdef FEAT_GUI_GTK
7795 if (gui.in_use)
7796 {
7797 gui_gtk_set_selection_targets();
7798 gui_gtk_set_dnd_targets();
7799 }
7800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007801 }
7802 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007803 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007804
7805 return errmsg;
7806}
7807#endif
7808
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007809#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007810 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007811did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007812{
7813 char_u *errmsg = NULL;
7814 win_T *wp;
7815 int l;
7816
7817 if (is_spellfile)
7818 {
7819 l = (int)STRLEN(curwin->w_s->b_p_spf);
7820 if (l > 0 && (l < 4
7821 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7822 errmsg = e_invarg;
7823 }
7824
7825 if (errmsg == NULL)
7826 {
7827 FOR_ALL_WINDOWS(wp)
7828 if (wp->w_buffer == curbuf && wp->w_p_spell)
7829 {
7830 errmsg = did_set_spelllang(wp);
7831# ifdef FEAT_WINDOWS
7832 break;
7833# endif
7834 }
7835 }
7836 return errmsg;
7837}
7838
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007839/*
7840 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7841 * Return error message when failed, NULL when OK.
7842 */
7843 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007844compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007845{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007846 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007847 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007848
Bram Moolenaar860cae12010-06-05 23:22:07 +02007849 if (*synblock->b_p_spc == NUL)
7850 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007851 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007852 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007853 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007854 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007855 if (re != NULL)
7856 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007857 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007858 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007859 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007860 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007861 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007862 return e_invarg;
7863 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007864 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007865 }
7866
Bram Moolenaar473de612013-06-08 18:19:48 +02007867 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007868 return NULL;
7869}
7870#endif
7871
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007872#if defined(FEAT_EVAL) || defined(PROTO)
7873/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007874 * Set the scriptID for an option, taking care of setting the buffer- or
7875 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007876 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007877 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007878set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007879{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007880 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7881 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007882
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007883 /* Remember where the option was set. For local options need to do that
7884 * in the buffer or window structure. */
7885 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007886 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007887 if (both || (opt_flags & OPT_LOCAL))
7888 {
7889 if (indir & PV_BUF)
7890 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7891 else if (indir & PV_WIN)
7892 curwin->w_p_scriptID[indir & PV_MASK] = id;
7893 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007894}
7895#endif
7896
Bram Moolenaar071d4272004-06-13 20:20:40 +00007897/*
7898 * Set the value of a boolean option, and take care of side effects.
7899 * Returns NULL for success, or an error message for an error.
7900 */
7901 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007902set_bool_option(
7903 int opt_idx, /* index in options[] table */
7904 char_u *varp, /* pointer to the option variable */
7905 int value, /* new value */
7906 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907{
7908 int old_value = *(int *)varp;
7909
Bram Moolenaar071d4272004-06-13 20:20:40 +00007910 /* Disallow changing some options from secure mode */
7911 if ((secure
7912#ifdef HAVE_SANDBOX
7913 || sandbox != 0
7914#endif
7915 ) && (options[opt_idx].flags & P_SECURE))
7916 return e_secure;
7917
7918 *(int *)varp = value; /* set the new value */
7919#ifdef FEAT_EVAL
7920 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007921 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007922#endif
7923
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007924#ifdef FEAT_GUI
7925 need_mouse_correct = TRUE;
7926#endif
7927
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928 /* May set global value for local option. */
7929 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7930 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7931
7932 /*
7933 * Handle side effects of changing a bool option.
7934 */
7935
7936 /* 'compatible' */
7937 if ((int *)varp == &p_cp)
7938 {
7939 compatible_set();
7940 }
7941
Bram Moolenaar920694c2016-08-21 17:45:02 +02007942#ifdef FEAT_LANGMAP
7943 if ((int *)varp == &p_lrm)
7944 /* 'langremap' -> !'langnoremap' */
7945 p_lnr = !p_lrm;
7946 else if ((int *)varp == &p_lnr)
7947 /* 'langnoremap' -> !'langremap' */
7948 p_lrm = !p_lnr;
7949#endif
7950
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007951#ifdef FEAT_PERSISTENT_UNDO
7952 /* 'undofile' */
7953 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7954 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007955 /* Only take action when the option was set. When reset we do not
7956 * delete the undo file, the option may be set again without making
7957 * any changes in between. */
7958 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007959 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007960 char_u hash[UNDO_HASH_SIZE];
7961 buf_T *save_curbuf = curbuf;
7962
Bram Moolenaar29323592016-07-24 22:04:11 +02007963 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007964 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007965 /* When 'undofile' is set globally: for every buffer, otherwise
7966 * only for the current buffer: Try to read in the undofile,
7967 * if one exists, the buffer wasn't changed and the buffer was
7968 * loaded */
7969 if ((curbuf == save_curbuf
7970 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7971 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
7972 {
7973 u_compute_hash(hash);
7974 u_read_undo(NULL, hash, curbuf->b_fname);
7975 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007976 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007977 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007978 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007979 }
7980#endif
7981
Bram Moolenaar071d4272004-06-13 20:20:40 +00007982 else if ((int *)varp == &curbuf->b_p_ro)
7983 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007984 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
7986 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00007987
7988 /* when 'readonly' is set may give W10 again */
7989 if (curbuf->b_p_ro)
7990 curbuf->b_did_warn = FALSE;
7991
Bram Moolenaar071d4272004-06-13 20:20:40 +00007992#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00007993 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007994#endif
7995 }
7996
Bram Moolenaar9c449722010-07-20 18:44:27 +02007997#ifdef FEAT_GUI
7998 else if ((int *)varp == &p_mh)
7999 {
8000 if (!p_mh)
8001 gui_mch_mousehide(FALSE);
8002 }
8003#endif
8004
Bram Moolenaara539df02010-08-01 14:35:05 +02008005#ifdef FEAT_TITLE
8006 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008008 {
8009 redraw_titles();
8010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008011 /* when 'endofline' is changed, redraw the window title */
8012 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008013 {
8014 redraw_titles();
8015 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008016 /* when 'fixeol' is changed, redraw the window title */
8017 else if ((int *)varp == &curbuf->b_p_fixeol)
8018 {
8019 redraw_titles();
8020 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008021# ifdef FEAT_MBYTE
8022 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008023 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008024 {
8025 redraw_titles();
8026 }
8027# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008028#endif
8029
8030 /* when 'bin' is set also set some other options */
8031 else if ((int *)varp == &curbuf->b_p_bin)
8032 {
8033 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8034#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008035 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008036#endif
8037 }
8038
8039#ifdef FEAT_AUTOCMD
8040 /* when 'buflisted' changes, trigger autocommands */
8041 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8042 {
8043 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8044 NULL, NULL, TRUE, curbuf);
8045 }
8046#endif
8047
8048 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8049 else if ((int *)varp == &curbuf->b_p_swf)
8050 {
8051 if (curbuf->b_p_swf && p_uc)
8052 ml_open_file(curbuf); /* create the swap file */
8053 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008054 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8055 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 mf_close_file(curbuf, TRUE); /* remove the swap file */
8057 }
8058
8059 /* when 'terse' is set change 'shortmess' */
8060 else if ((int *)varp == &p_terse)
8061 {
8062 char_u *p;
8063
8064 p = vim_strchr(p_shm, SHM_SEARCH);
8065
8066 /* insert 's' in p_shm */
8067 if (p_terse && p == NULL)
8068 {
8069 STRCPY(IObuff, p_shm);
8070 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008071 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072 }
8073 /* remove 's' from p_shm */
8074 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008075 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008076 }
8077
8078 /* when 'paste' is set or reset also change other options */
8079 else if ((int *)varp == &p_paste)
8080 {
8081 paste_option_changed();
8082 }
8083
8084 /* when 'insertmode' is set from an autocommand need to do work here */
8085 else if ((int *)varp == &p_im)
8086 {
8087 if (p_im)
8088 {
8089 if ((State & INSERT) == 0)
8090 need_start_insertmode = TRUE;
8091 stop_insert_mode = FALSE;
8092 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008093 /* only reset if it was set previously */
8094 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095 {
8096 need_start_insertmode = FALSE;
8097 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008098 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008099 clear_cmdline = TRUE; /* remove "(insert)" */
8100 restart_edit = 0;
8101 }
8102 }
8103
8104 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8105 else if ((int *)varp == &p_ic && p_hls)
8106 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008107 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008108 }
8109
8110#ifdef FEAT_SEARCH_EXTRA
8111 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8112 else if ((int *)varp == &p_hls)
8113 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008114 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115 }
8116#endif
8117
8118#ifdef FEAT_SCROLLBIND
8119 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8120 * at the end of normal_cmd() */
8121 else if ((int *)varp == &curwin->w_p_scb)
8122 {
8123 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008124 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008125 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008126 curwin->w_scbind_pos = curwin->w_topline;
8127 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128 }
8129#endif
8130
8131#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8132 /* There can be only one window with 'previewwindow' set. */
8133 else if ((int *)varp == &curwin->w_p_pvw)
8134 {
8135 if (curwin->w_p_pvw)
8136 {
8137 win_T *win;
8138
Bram Moolenaar29323592016-07-24 22:04:11 +02008139 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008140 if (win->w_p_pvw && win != curwin)
8141 {
8142 curwin->w_p_pvw = FALSE;
8143 return (char_u *)N_("E590: A preview window already exists");
8144 }
8145 }
8146 }
8147#endif
8148
8149 /* when 'textmode' is set or reset also change 'fileformat' */
8150 else if ((int *)varp == &curbuf->b_p_tx)
8151 {
8152 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8153 }
8154
8155 /* when 'textauto' is set or reset also change 'fileformats' */
8156 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 set_string_option_direct((char_u *)"ffs", -1,
8158 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008159 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160
8161 /*
8162 * When 'lisp' option changes include/exclude '-' in
8163 * keyword characters.
8164 */
8165#ifdef FEAT_LISP
8166 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8167 {
8168 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8169 }
8170#endif
8171
8172#ifdef FEAT_TITLE
8173 /* when 'title' changed, may need to change the title; same for 'icon' */
8174 else if ((int *)varp == &p_title)
8175 {
8176 did_set_title(FALSE);
8177 }
8178
8179 else if ((int *)varp == &p_icon)
8180 {
8181 did_set_title(TRUE);
8182 }
8183#endif
8184
8185 else if ((int *)varp == &curbuf->b_changed)
8186 {
8187 if (!value)
8188 save_file_ff(curbuf); /* Buffer is unchanged */
8189#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008190 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008191#endif
8192#ifdef FEAT_AUTOCMD
8193 modified_was_set = value;
8194#endif
8195 }
8196
8197#ifdef BACKSLASH_IN_FILENAME
8198 else if ((int *)varp == &p_ssl)
8199 {
8200 if (p_ssl)
8201 {
8202 psepc = '/';
8203 psepcN = '\\';
8204 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 }
8206 else
8207 {
8208 psepc = '\\';
8209 psepcN = '/';
8210 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008211 }
8212
8213 /* need to adjust the file name arguments and buffer names. */
8214 buflist_slash_adjust();
8215 alist_slash_adjust();
8216# ifdef FEAT_EVAL
8217 scriptnames_slash_adjust();
8218# endif
8219 }
8220#endif
8221
8222 /* If 'wrap' is set, set w_leftcol to zero. */
8223 else if ((int *)varp == &curwin->w_p_wrap)
8224 {
8225 if (curwin->w_p_wrap)
8226 curwin->w_leftcol = 0;
8227 }
8228
8229#ifdef FEAT_WINDOWS
8230 else if ((int *)varp == &p_ea)
8231 {
8232 if (p_ea && !old_value)
8233 win_equal(curwin, FALSE, 0);
8234 }
8235#endif
8236
8237 else if ((int *)varp == &p_wiv)
8238 {
8239 /*
8240 * When 'weirdinvert' changed, set/reset 't_xs'.
8241 * Then set 'weirdinvert' according to value of 't_xs'.
8242 */
8243 if (p_wiv && !old_value)
8244 T_XS = (char_u *)"y";
8245 else if (!p_wiv && old_value)
8246 T_XS = empty_option;
8247 p_wiv = (*T_XS != NUL);
8248 }
8249
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008250#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251 else if ((int *)varp == &p_beval)
8252 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008253 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008254 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008255 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008256 gui_mch_disable_beval_area(balloonEval);
8257 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008258#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008259
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008260#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 else if ((int *)varp == &p_acd)
8262 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008263 /* Change directories when the 'acd' option is set now. */
8264 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008265 }
8266#endif
8267
8268#ifdef FEAT_DIFF
8269 /* 'diff' */
8270 else if ((int *)varp == &curwin->w_p_diff)
8271 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008272 /* May add or remove the buffer from the list of diff buffers. */
8273 diff_buf_adjust(curwin);
8274# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008275 if (foldmethodIsDiff(curwin))
8276 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008277# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008278 }
8279#endif
8280
8281#ifdef USE_IM_CONTROL
8282 /* 'imdisable' */
8283 else if ((int *)varp == &p_imdisable)
8284 {
8285 /* Only de-activate it here, it will be enabled when changing mode. */
8286 if (p_imdisable)
8287 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008288 else if (State & INSERT)
8289 /* When the option is set from an autocommand, it may need to take
8290 * effect right away. */
8291 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008292 }
8293#endif
8294
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008295#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008296 /* 'spell' */
8297 else if ((int *)varp == &curwin->w_p_spell)
8298 {
8299 if (curwin->w_p_spell)
8300 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008301 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008302 if (errmsg != NULL)
8303 EMSG(_(errmsg));
8304 }
8305 }
8306#endif
8307
Bram Moolenaar071d4272004-06-13 20:20:40 +00008308#ifdef FEAT_FKMAP
8309 else if ((int *)varp == &p_altkeymap)
8310 {
8311 if (old_value != p_altkeymap)
8312 {
8313 if (!p_altkeymap)
8314 {
8315 p_hkmap = p_fkmap;
8316 p_fkmap = 0;
8317 }
8318 else
8319 {
8320 p_fkmap = p_hkmap;
8321 p_hkmap = 0;
8322 }
8323 (void)init_chartab();
8324 }
8325 }
8326
8327 /*
8328 * In case some second language keymapping options have changed, check
8329 * and correct the setting in a consistent way.
8330 */
8331
8332 /*
8333 * If hkmap or fkmap are set, reset Arabic keymapping.
8334 */
8335 if ((p_hkmap || p_fkmap) && p_altkeymap)
8336 {
8337 p_altkeymap = p_fkmap;
8338# ifdef FEAT_ARABIC
8339 curwin->w_p_arab = FALSE;
8340# endif
8341 (void)init_chartab();
8342 }
8343
8344 /*
8345 * If hkmap set, reset Farsi keymapping.
8346 */
8347 if (p_hkmap && p_altkeymap)
8348 {
8349 p_altkeymap = 0;
8350 p_fkmap = 0;
8351# ifdef FEAT_ARABIC
8352 curwin->w_p_arab = FALSE;
8353# endif
8354 (void)init_chartab();
8355 }
8356
8357 /*
8358 * If fkmap set, reset Hebrew keymapping.
8359 */
8360 if (p_fkmap && !p_altkeymap)
8361 {
8362 p_altkeymap = 1;
8363 p_hkmap = 0;
8364# ifdef FEAT_ARABIC
8365 curwin->w_p_arab = FALSE;
8366# endif
8367 (void)init_chartab();
8368 }
8369#endif
8370
8371#ifdef FEAT_ARABIC
8372 if ((int *)varp == &curwin->w_p_arab)
8373 {
8374 if (curwin->w_p_arab)
8375 {
8376 /*
8377 * 'arabic' is set, handle various sub-settings.
8378 */
8379 if (!p_tbidi)
8380 {
8381 /* set rightleft mode */
8382 if (!curwin->w_p_rl)
8383 {
8384 curwin->w_p_rl = TRUE;
8385 changed_window_setting();
8386 }
8387
8388 /* Enable Arabic shaping (major part of what Arabic requires) */
8389 if (!p_arshape)
8390 {
8391 p_arshape = TRUE;
8392 redraw_later_clear();
8393 }
8394 }
8395
8396 /* Arabic requires a utf-8 encoding, inform the user if its not
8397 * set. */
8398 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008399 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008400 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8401
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008402 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008403 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8404#ifdef FEAT_EVAL
8405 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8406#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008407 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408
8409# ifdef FEAT_MBYTE
8410 /* set 'delcombine' */
8411 p_deco = TRUE;
8412# endif
8413
8414# ifdef FEAT_KEYMAP
8415 /* Force-set the necessary keymap for arabic */
8416 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8417 OPT_LOCAL);
8418# endif
8419# ifdef FEAT_FKMAP
8420 p_altkeymap = 0;
8421 p_hkmap = 0;
8422 p_fkmap = 0;
8423 (void)init_chartab();
8424# endif
8425 }
8426 else
8427 {
8428 /*
8429 * 'arabic' is reset, handle various sub-settings.
8430 */
8431 if (!p_tbidi)
8432 {
8433 /* reset rightleft mode */
8434 if (curwin->w_p_rl)
8435 {
8436 curwin->w_p_rl = FALSE;
8437 changed_window_setting();
8438 }
8439
8440 /* 'arabicshape' isn't reset, it is a global option and
8441 * another window may still need it "on". */
8442 }
8443
8444 /* 'delcombine' isn't reset, it is a global option and another
8445 * window may still want it "on". */
8446
8447# ifdef FEAT_KEYMAP
8448 /* Revert to the default keymap */
8449 curbuf->b_p_iminsert = B_IMODE_NONE;
8450 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8451# endif
8452 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008453 }
8454
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008455#endif
8456
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008457#ifdef FEAT_TERMGUICOLORS
8458 /* 'termguicolors' */
8459 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008460 {
8461# ifdef FEAT_GUI
8462 if (!gui.in_use && !gui.starting)
8463# endif
8464 highlight_gui_started();
8465 }
8466#endif
8467
Bram Moolenaar071d4272004-06-13 20:20:40 +00008468 /*
8469 * End of handling side effects for bool options.
8470 */
8471
Bram Moolenaar53744302015-07-17 17:38:22 +02008472 /* after handling side effects, call autocommand */
8473
Bram Moolenaar071d4272004-06-13 20:20:40 +00008474 options[opt_idx].flags |= P_WAS_SET;
8475
Bram Moolenaar53744302015-07-17 17:38:22 +02008476#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8477 if (!starting)
8478 {
8479 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008480 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8481 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8482 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008483 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8484 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8485 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8486 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8487 reset_v_option_vars();
8488 }
8489#endif
8490
Bram Moolenaar071d4272004-06-13 20:20:40 +00008491 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008492 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008493 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008494 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495 check_redraw(options[opt_idx].flags);
8496
8497 return NULL;
8498}
8499
8500/*
8501 * Set the value of a number option, and take care of side effects.
8502 * Returns NULL for success, or an error message for an error.
8503 */
8504 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008505set_num_option(
8506 int opt_idx, /* index in options[] table */
8507 char_u *varp, /* pointer to the option variable */
8508 long value, /* new value */
8509 char_u *errbuf, /* buffer for error messages */
8510 size_t errbuflen, /* length of "errbuf" */
8511 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512 OPT_MODELINE */
8513{
8514 char_u *errmsg = NULL;
8515 long old_value = *(long *)varp;
8516 long old_Rows = Rows; /* remember old Rows */
8517 long old_Columns = Columns; /* remember old Columns */
8518 long *pp = (long *)varp;
8519
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008520 /* Disallow changing some options from secure mode. */
8521 if ((secure
8522#ifdef HAVE_SANDBOX
8523 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008524#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008525 ) && (options[opt_idx].flags & P_SECURE))
8526 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008527
8528 *pp = value;
8529#ifdef FEAT_EVAL
8530 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008531 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008533#ifdef FEAT_GUI
8534 need_mouse_correct = TRUE;
8535#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008536
Bram Moolenaar14f24742012-08-08 18:01:05 +02008537 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538 {
8539 errmsg = e_positive;
8540 curbuf->b_p_sw = curbuf->b_p_ts;
8541 }
8542
8543 /*
8544 * Number options that need some action when changed
8545 */
8546#ifdef FEAT_WINDOWS
8547 if (pp == &p_wh || pp == &p_hh)
8548 {
8549 if (p_wh < 1)
8550 {
8551 errmsg = e_positive;
8552 p_wh = 1;
8553 }
8554 if (p_wmh > p_wh)
8555 {
8556 errmsg = e_winheight;
8557 p_wh = p_wmh;
8558 }
8559 if (p_hh < 0)
8560 {
8561 errmsg = e_positive;
8562 p_hh = 0;
8563 }
8564
8565 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008566 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567 {
8568 if (pp == &p_wh && curwin->w_height < p_wh)
8569 win_setheight((int)p_wh);
8570 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8571 win_setheight((int)p_hh);
8572 }
8573 }
8574
8575 /* 'winminheight' */
8576 else if (pp == &p_wmh)
8577 {
8578 if (p_wmh < 0)
8579 {
8580 errmsg = e_positive;
8581 p_wmh = 0;
8582 }
8583 if (p_wmh > p_wh)
8584 {
8585 errmsg = e_winheight;
8586 p_wmh = p_wh;
8587 }
8588 win_setminheight();
8589 }
8590
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008591# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008592 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008593 {
8594 if (p_wiw < 1)
8595 {
8596 errmsg = e_positive;
8597 p_wiw = 1;
8598 }
8599 if (p_wmw > p_wiw)
8600 {
8601 errmsg = e_winwidth;
8602 p_wiw = p_wmw;
8603 }
8604
8605 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008606 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008607 win_setwidth((int)p_wiw);
8608 }
8609
8610 /* 'winminwidth' */
8611 else if (pp == &p_wmw)
8612 {
8613 if (p_wmw < 0)
8614 {
8615 errmsg = e_positive;
8616 p_wmw = 0;
8617 }
8618 if (p_wmw > p_wiw)
8619 {
8620 errmsg = e_winwidth;
8621 p_wmw = p_wiw;
8622 }
8623 win_setminheight();
8624 }
8625# endif
8626
8627#endif
8628
8629#ifdef FEAT_WINDOWS
8630 /* (re)set last window status line */
8631 else if (pp == &p_ls)
8632 {
8633 last_status(FALSE);
8634 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008635
8636 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008637 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008638 {
8639 shell_new_rows(); /* recompute window positions and heights */
8640 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641#endif
8642
8643#ifdef FEAT_GUI
8644 else if (pp == &p_linespace)
8645 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008646 /* Recompute gui.char_height and resize the Vim window to keep the
8647 * same number of lines. */
8648 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008649 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008650 }
8651#endif
8652
8653#ifdef FEAT_FOLDING
8654 /* 'foldlevel' */
8655 else if (pp == &curwin->w_p_fdl)
8656 {
8657 if (curwin->w_p_fdl < 0)
8658 curwin->w_p_fdl = 0;
8659 newFoldLevel();
8660 }
8661
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008662 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008663 else if (pp == &curwin->w_p_fml)
8664 {
8665 foldUpdateAll(curwin);
8666 }
8667
8668 /* 'foldnestmax' */
8669 else if (pp == &curwin->w_p_fdn)
8670 {
8671 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8672 foldUpdateAll(curwin);
8673 }
8674
8675 /* 'foldcolumn' */
8676 else if (pp == &curwin->w_p_fdc)
8677 {
8678 if (curwin->w_p_fdc < 0)
8679 {
8680 errmsg = e_positive;
8681 curwin->w_p_fdc = 0;
8682 }
8683 else if (curwin->w_p_fdc > 12)
8684 {
8685 errmsg = e_invarg;
8686 curwin->w_p_fdc = 12;
8687 }
8688 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008689#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008690
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008691#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008692 /* 'shiftwidth' or 'tabstop' */
8693 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8694 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008695# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008696 if (foldmethodIsIndent(curwin))
8697 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008698# endif
8699# ifdef FEAT_CINDENT
8700 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8701 * parse 'cinoptions'. */
8702 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8703 parse_cino(curbuf);
8704# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008707
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008708#ifdef FEAT_MBYTE
8709 /* 'maxcombine' */
8710 else if (pp == &p_mco)
8711 {
8712 if (p_mco > MAX_MCO)
8713 p_mco = MAX_MCO;
8714 else if (p_mco < 0)
8715 p_mco = 0;
8716 screenclear(); /* will re-allocate the screen */
8717 }
8718#endif
8719
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 else if (pp == &curbuf->b_p_iminsert)
8721 {
8722 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8723 {
8724 errmsg = e_invarg;
8725 curbuf->b_p_iminsert = B_IMODE_NONE;
8726 }
8727 p_iminsert = curbuf->b_p_iminsert;
8728 if (termcap_active) /* don't do this in the alternate screen */
8729 showmode();
8730#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8731 /* Show/unshow value of 'keymap' in status lines. */
8732 status_redraw_curbuf();
8733#endif
8734 }
8735
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008736 else if (pp == &p_window)
8737 {
8738 if (p_window < 1)
8739 p_window = 1;
8740 else if (p_window >= Rows)
8741 p_window = Rows - 1;
8742 }
8743
Bram Moolenaar071d4272004-06-13 20:20:40 +00008744 else if (pp == &curbuf->b_p_imsearch)
8745 {
8746 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8747 {
8748 errmsg = e_invarg;
8749 curbuf->b_p_imsearch = B_IMODE_NONE;
8750 }
8751 p_imsearch = curbuf->b_p_imsearch;
8752 }
8753
8754#ifdef FEAT_TITLE
8755 /* if 'titlelen' has changed, redraw the title */
8756 else if (pp == &p_titlelen)
8757 {
8758 if (p_titlelen < 0)
8759 {
8760 errmsg = e_positive;
8761 p_titlelen = 85;
8762 }
8763 if (starting != NO_SCREEN && old_value != p_titlelen)
8764 need_maketitle = TRUE;
8765 }
8766#endif
8767
8768 /* if p_ch changed value, change the command line height */
8769 else if (pp == &p_ch)
8770 {
8771 if (p_ch < 1)
8772 {
8773 errmsg = e_positive;
8774 p_ch = 1;
8775 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008776 if (p_ch > Rows - min_rows() + 1)
8777 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778
8779 /* Only compute the new window layout when startup has been
8780 * completed. Otherwise the frame sizes may be wrong. */
8781 if (p_ch != old_value && full_screen
8782#ifdef FEAT_GUI
8783 && !gui.starting
8784#endif
8785 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008786 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787 }
8788
8789 /* when 'updatecount' changes from zero to non-zero, open swap files */
8790 else if (pp == &p_uc)
8791 {
8792 if (p_uc < 0)
8793 {
8794 errmsg = e_positive;
8795 p_uc = 100;
8796 }
8797 if (p_uc && !old_value)
8798 ml_open_files();
8799 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008800#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008801 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008802 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008803 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008804 {
8805 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008806 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008807 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008808 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008809 {
8810 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008811 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008812 }
8813 }
8814#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008815#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008816 else if (pp == &p_mzq)
8817 mzvim_reset_timer();
8818#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819
8820 /* sync undo before 'undolevels' changes */
8821 else if (pp == &p_ul)
8822 {
8823 /* use the old value, otherwise u_sync() may not work properly */
8824 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008825 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008826 p_ul = value;
8827 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008828 else if (pp == &curbuf->b_p_ul)
8829 {
8830 /* use the old value, otherwise u_sync() may not work properly */
8831 curbuf->b_p_ul = old_value;
8832 u_sync(TRUE);
8833 curbuf->b_p_ul = value;
8834 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008835
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008836#ifdef FEAT_LINEBREAK
8837 /* 'numberwidth' must be positive */
8838 else if (pp == &curwin->w_p_nuw)
8839 {
8840 if (curwin->w_p_nuw < 1)
8841 {
8842 errmsg = e_positive;
8843 curwin->w_p_nuw = 1;
8844 }
8845 if (curwin->w_p_nuw > 10)
8846 {
8847 errmsg = e_invarg;
8848 curwin->w_p_nuw = 10;
8849 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008850 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008851 }
8852#endif
8853
Bram Moolenaar1a384422010-07-14 19:53:30 +02008854 else if (pp == &curbuf->b_p_tw)
8855 {
8856 if (curbuf->b_p_tw < 0)
8857 {
8858 errmsg = e_positive;
8859 curbuf->b_p_tw = 0;
8860 }
8861#ifdef FEAT_SYN_HL
8862# ifdef FEAT_WINDOWS
8863 {
8864 win_T *wp;
8865 tabpage_T *tp;
8866
8867 FOR_ALL_TAB_WINDOWS(tp, wp)
8868 check_colorcolumn(wp);
8869 }
8870# else
8871 check_colorcolumn(curwin);
8872# endif
8873#endif
8874 }
8875
Bram Moolenaar071d4272004-06-13 20:20:40 +00008876 /*
8877 * Check the bounds for numeric options here
8878 */
8879 if (Rows < min_rows() && full_screen)
8880 {
8881 if (errbuf != NULL)
8882 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008883 vim_snprintf((char *)errbuf, errbuflen,
8884 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008885 errmsg = errbuf;
8886 }
8887 Rows = min_rows();
8888 }
8889 if (Columns < MIN_COLUMNS && full_screen)
8890 {
8891 if (errbuf != NULL)
8892 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008893 vim_snprintf((char *)errbuf, errbuflen,
8894 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008895 errmsg = errbuf;
8896 }
8897 Columns = MIN_COLUMNS;
8898 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008899 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008900
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901 /*
8902 * If the screen (shell) height has been changed, assume it is the
8903 * physical screenheight.
8904 */
8905 if (old_Rows != Rows || old_Columns != Columns)
8906 {
8907 /* Changing the screen size is not allowed while updating the screen. */
8908 if (updating_screen)
8909 *pp = old_value;
8910 else if (full_screen
8911#ifdef FEAT_GUI
8912 && !gui.starting
8913#endif
8914 )
8915 set_shellsize((int)Columns, (int)Rows, TRUE);
8916 else
8917 {
8918 /* Postpone the resizing; check the size and cmdline position for
8919 * messages. */
8920 check_shellsize();
8921 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8922 cmdline_row = Rows - p_ch;
8923 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008924 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008925 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926 }
8927
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928 if (curbuf->b_p_ts <= 0)
8929 {
8930 errmsg = e_positive;
8931 curbuf->b_p_ts = 8;
8932 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008933 if (p_tm < 0)
8934 {
8935 errmsg = e_positive;
8936 p_tm = 0;
8937 }
8938 if ((curwin->w_p_scr <= 0
8939 || (curwin->w_p_scr > curwin->w_height
8940 && curwin->w_height > 0))
8941 && full_screen)
8942 {
8943 if (pp == &(curwin->w_p_scr))
8944 {
8945 if (curwin->w_p_scr != 0)
8946 errmsg = e_scroll;
8947 win_comp_scroll(curwin);
8948 }
8949 /* If 'scroll' became invalid because of a side effect silently adjust
8950 * it. */
8951 else if (curwin->w_p_scr <= 0)
8952 curwin->w_p_scr = 1;
8953 else /* curwin->w_p_scr > curwin->w_height */
8954 curwin->w_p_scr = curwin->w_height;
8955 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008956 if (p_hi < 0)
8957 {
8958 errmsg = e_positive;
8959 p_hi = 0;
8960 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008961 else if (p_hi > 10000)
8962 {
8963 errmsg = e_invarg;
8964 p_hi = 10000;
8965 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02008966 if (p_re < 0 || p_re > 2)
8967 {
8968 errmsg = e_invarg;
8969 p_re = 0;
8970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008971 if (p_report < 0)
8972 {
8973 errmsg = e_positive;
8974 p_report = 1;
8975 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00008976 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008977 {
8978 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
8979 p_sj = Rows / 2;
8980 else
8981 {
8982 errmsg = e_scroll;
8983 p_sj = 1;
8984 }
8985 }
8986 if (p_so < 0 && full_screen)
8987 {
8988 errmsg = e_scroll;
8989 p_so = 0;
8990 }
8991 if (p_siso < 0 && full_screen)
8992 {
8993 errmsg = e_positive;
8994 p_siso = 0;
8995 }
8996#ifdef FEAT_CMDWIN
8997 if (p_cwh < 1)
8998 {
8999 errmsg = e_positive;
9000 p_cwh = 1;
9001 }
9002#endif
9003 if (p_ut < 0)
9004 {
9005 errmsg = e_positive;
9006 p_ut = 2000;
9007 }
9008 if (p_ss < 0)
9009 {
9010 errmsg = e_positive;
9011 p_ss = 0;
9012 }
9013
9014 /* May set global value for local option. */
9015 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9016 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9017
9018 options[opt_idx].flags |= P_WAS_SET;
9019
Bram Moolenaar53744302015-07-17 17:38:22 +02009020#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9021 if (!starting && errmsg == NULL)
9022 {
9023 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009024 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9025 vim_snprintf((char *)buf_new, 10, "%ld", value);
9026 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009027 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9028 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9029 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9030 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9031 reset_v_option_vars();
9032 }
9033#endif
9034
Bram Moolenaar071d4272004-06-13 20:20:40 +00009035 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009036 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009037 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009038 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009039 check_redraw(options[opt_idx].flags);
9040
9041 return errmsg;
9042}
9043
9044/*
9045 * Called after an option changed: check if something needs to be redrawn.
9046 */
9047 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009048check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009049{
9050 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009051 int doclear = (flags & P_RCLR) == P_RCLR;
9052 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009053
9054#ifdef FEAT_WINDOWS
9055 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9056 status_redraw_all();
9057#endif
9058
9059 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9060 changed_window_setting();
9061 if (flags & P_RBUF)
9062 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009063 if (flags & P_RWINONLY)
9064 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009065 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009066 redraw_all_later(CLEAR);
9067 else if (all)
9068 redraw_all_later(NOT_VALID);
9069}
9070
9071/*
9072 * Find index for option 'arg'.
9073 * Return -1 if not found.
9074 */
9075 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009076findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077{
9078 int opt_idx;
9079 char *s, *p;
9080 static short quick_tab[27] = {0, 0}; /* quick access table */
9081 int is_term_opt;
9082
9083 /*
9084 * For first call: Initialize the quick-access table.
9085 * It contains the index for the first option that starts with a certain
9086 * letter. There are 26 letters, plus the first "t_" option.
9087 */
9088 if (quick_tab[1] == 0)
9089 {
9090 p = options[0].fullname;
9091 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9092 {
9093 if (s[0] != p[0])
9094 {
9095 if (s[0] == 't' && s[1] == '_')
9096 quick_tab[26] = opt_idx;
9097 else
9098 quick_tab[CharOrdLow(s[0])] = opt_idx;
9099 }
9100 p = s;
9101 }
9102 }
9103
9104 /*
9105 * Check for name starting with an illegal character.
9106 */
9107#ifdef EBCDIC
9108 if (!islower(arg[0]))
9109#else
9110 if (arg[0] < 'a' || arg[0] > 'z')
9111#endif
9112 return -1;
9113
9114 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9115 if (is_term_opt)
9116 opt_idx = quick_tab[26];
9117 else
9118 opt_idx = quick_tab[CharOrdLow(arg[0])];
9119 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9120 {
9121 if (STRCMP(arg, s) == 0) /* match full name */
9122 break;
9123 }
9124 if (s == NULL && !is_term_opt)
9125 {
9126 opt_idx = quick_tab[CharOrdLow(arg[0])];
9127 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9128 {
9129 s = options[opt_idx].shortname;
9130 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9131 break;
9132 s = NULL;
9133 }
9134 }
9135 if (s == NULL)
9136 opt_idx = -1;
9137 return opt_idx;
9138}
9139
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009140#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009141/*
9142 * Get the value for an option.
9143 *
9144 * Returns:
9145 * Number or Toggle option: 1, *numval gets value.
9146 * String option: 0, *stringval gets allocated string.
9147 * Hidden Number or Toggle option: -1.
9148 * hidden String option: -2.
9149 * unknown option: -3.
9150 */
9151 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009152get_option_value(
9153 char_u *name,
9154 long *numval,
9155 char_u **stringval, /* NULL when only checking existence */
9156 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009157{
9158 int opt_idx;
9159 char_u *varp;
9160
9161 opt_idx = findoption(name);
9162 if (opt_idx < 0) /* unknown option */
9163 return -3;
9164
9165 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9166
9167 if (options[opt_idx].flags & P_STRING)
9168 {
9169 if (varp == NULL) /* hidden option */
9170 return -2;
9171 if (stringval != NULL)
9172 {
9173#ifdef FEAT_CRYPT
9174 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009175 if ((char_u **)varp == &curbuf->b_p_key
9176 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009177 *stringval = vim_strsave((char_u *)"*****");
9178 else
9179#endif
9180 *stringval = vim_strsave(*(char_u **)(varp));
9181 }
9182 return 0;
9183 }
9184
9185 if (varp == NULL) /* hidden option */
9186 return -1;
9187 if (options[opt_idx].flags & P_NUM)
9188 *numval = *(long *)varp;
9189 else
9190 {
9191 /* Special case: 'modified' is b_changed, but we also want to consider
9192 * it set when 'ff' or 'fenc' changed. */
9193 if ((int *)varp == &curbuf->b_changed)
9194 *numval = curbufIsChanged();
9195 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009196 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009197 }
9198 return 1;
9199}
9200#endif
9201
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009202#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009203/*
9204 * Returns the option attributes and its value. Unlike the above function it
9205 * will return either global value or local value of the option depending on
9206 * what was requested, but it will never return global value if it was
9207 * requested to return local one and vice versa. Neither it will return
9208 * buffer-local value if it was requested to return window-local one.
9209 *
9210 * Pretends that option is absent if it is not present in the requested scope
9211 * (i.e. has no global, window-local or buffer-local value depending on
9212 * opt_type). Uses
9213 *
9214 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009215 * 0 hidden or unknown option, also option that does not have requested
9216 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009217 * see SOPT_* in vim.h for other flags
9218 *
9219 * Possible opt_type values: see SREQ_* in vim.h
9220 */
9221 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009222get_option_value_strict(
9223 char_u *name,
9224 long *numval,
9225 char_u **stringval, /* NULL when only obtaining attributes */
9226 int opt_type,
9227 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009228{
9229 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009230 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009231 struct vimoption *p;
9232 int r = 0;
9233
9234 opt_idx = findoption(name);
9235 if (opt_idx < 0)
9236 return 0;
9237
9238 p = &(options[opt_idx]);
9239
9240 /* Hidden option */
9241 if (p->var == NULL)
9242 return 0;
9243
9244 if (p->flags & P_BOOL)
9245 r |= SOPT_BOOL;
9246 else if (p->flags & P_NUM)
9247 r |= SOPT_NUM;
9248 else if (p->flags & P_STRING)
9249 r |= SOPT_STRING;
9250
9251 if (p->indir == PV_NONE)
9252 {
9253 if (opt_type == SREQ_GLOBAL)
9254 r |= SOPT_GLOBAL;
9255 else
9256 return 0; /* Did not request global-only option */
9257 }
9258 else
9259 {
9260 if (p->indir & PV_BOTH)
9261 r |= SOPT_GLOBAL;
9262 else if (opt_type == SREQ_GLOBAL)
9263 return 0; /* Requested global option */
9264
9265 if (p->indir & PV_WIN)
9266 {
9267 if (opt_type == SREQ_BUF)
9268 return 0; /* Did not request window-local option */
9269 else
9270 r |= SOPT_WIN;
9271 }
9272 else if (p->indir & PV_BUF)
9273 {
9274 if (opt_type == SREQ_WIN)
9275 return 0; /* Did not request buffer-local option */
9276 else
9277 r |= SOPT_BUF;
9278 }
9279 }
9280
9281 if (stringval == NULL)
9282 return r;
9283
9284 if (opt_type == SREQ_GLOBAL)
9285 varp = p->var;
9286 else
9287 {
9288 if (opt_type == SREQ_BUF)
9289 {
9290 /* Special case: 'modified' is b_changed, but we also want to
9291 * consider it set when 'ff' or 'fenc' changed. */
9292 if (p->indir == PV_MOD)
9293 {
9294 *numval = bufIsChanged((buf_T *) from);
9295 varp = NULL;
9296 }
9297#ifdef FEAT_CRYPT
9298 else if (p->indir == PV_KEY)
9299 {
9300 /* never return the value of the crypt key */
9301 *stringval = NULL;
9302 varp = NULL;
9303 }
9304#endif
9305 else
9306 {
9307 aco_save_T aco;
9308 aucmd_prepbuf(&aco, (buf_T *) from);
9309 varp = get_varp(p);
9310 aucmd_restbuf(&aco);
9311 }
9312 }
9313 else if (opt_type == SREQ_WIN)
9314 {
9315 win_T *save_curwin;
9316 save_curwin = curwin;
9317 curwin = (win_T *) from;
9318 curbuf = curwin->w_buffer;
9319 varp = get_varp(p);
9320 curwin = save_curwin;
9321 curbuf = curwin->w_buffer;
9322 }
9323 if (varp == p->var)
9324 return (r | SOPT_UNSET);
9325 }
9326
9327 if (varp != NULL)
9328 {
9329 if (p->flags & P_STRING)
9330 *stringval = vim_strsave(*(char_u **)(varp));
9331 else if (p->flags & P_NUM)
9332 *numval = *(long *) varp;
9333 else
9334 *numval = *(int *)varp;
9335 }
9336
9337 return r;
9338}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009339
9340/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009341 * Iterate over options. First argument is a pointer to a pointer to a
9342 * structure inside options[] array, second is option type like in the above
9343 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009344 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009345 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009346 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009347 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009348 * first argument to NULL.
9349 *
9350 * Returns full option name for current option on each call.
9351 */
9352 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009353option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009354{
9355 struct vimoption *ret = NULL;
9356 do
9357 {
9358 if (*option == NULL)
9359 *option = (void *) options;
9360 else if (((struct vimoption *) (*option))->fullname == NULL)
9361 {
9362 *option = NULL;
9363 return NULL;
9364 }
9365 else
9366 *option = (void *) (((struct vimoption *) (*option)) + 1);
9367
9368 ret = ((struct vimoption *) (*option));
9369
9370 /* Hidden option */
9371 if (ret->var == NULL)
9372 {
9373 ret = NULL;
9374 continue;
9375 }
9376
9377 switch (opt_type)
9378 {
9379 case SREQ_GLOBAL:
9380 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9381 ret = NULL;
9382 break;
9383 case SREQ_BUF:
9384 if (!(ret->indir & PV_BUF))
9385 ret = NULL;
9386 break;
9387 case SREQ_WIN:
9388 if (!(ret->indir & PV_WIN))
9389 ret = NULL;
9390 break;
9391 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009392 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009393 return NULL;
9394 }
9395 }
9396 while (ret == NULL);
9397
9398 return (char_u *)ret->fullname;
9399}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009400#endif
9401
Bram Moolenaar071d4272004-06-13 20:20:40 +00009402/*
9403 * Set the value of option "name".
9404 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009405 *
9406 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009407 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009408 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009409set_option_value(
9410 char_u *name,
9411 long number,
9412 char_u *string,
9413 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009414{
9415 int opt_idx;
9416 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009417 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418
9419 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009420 if (opt_idx < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009421 EMSG2(_("E355: Unknown option: %s"), name);
9422 else
9423 {
9424 flags = options[opt_idx].flags;
9425#ifdef HAVE_SANDBOX
9426 /* Disallow changing some options in the sandbox */
9427 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009428 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009429 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009430 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009431 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009433 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009434 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009435 else
9436 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009437 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009438 if (varp != NULL) /* hidden option is not changed */
9439 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009440 if (number == 0 && string != NULL)
9441 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009442 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009443
9444 /* Either we are given a string or we are setting option
9445 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009446 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009447 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009448 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009449 {
9450 /* There's another character after zeros or the string
9451 * is empty. In both cases, we are trying to set a
9452 * num option using a string. */
9453 EMSG3(_("E521: Number required: &%s = '%s'"),
9454 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009455 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009456
9457 }
9458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009459 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009460 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009461 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009462 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009463 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009464 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009465 }
9466 }
9467 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009468 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009469}
9470
9471/*
9472 * Get the terminal code for a terminal option.
9473 * Returns NULL when not found.
9474 */
9475 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009476get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009477{
9478 int opt_idx;
9479 char_u *varp;
9480
9481 if (tname[0] != 't' || tname[1] != '_' ||
9482 tname[2] == NUL || tname[3] == NUL)
9483 return NULL;
9484 if ((opt_idx = findoption(tname)) >= 0)
9485 {
9486 varp = get_varp(&(options[opt_idx]));
9487 if (varp != NULL)
9488 varp = *(char_u **)(varp);
9489 return varp;
9490 }
9491 return find_termcode(tname + 2);
9492}
9493
9494 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009495get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009496{
9497 int i;
9498
9499 i = findoption((char_u *)"hl");
9500 if (i >= 0)
9501 return options[i].def_val[VI_DEFAULT];
9502 return (char_u *)NULL;
9503}
9504
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009505#if defined(FEAT_MBYTE) || defined(PROTO)
9506 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009507get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009508{
9509 int i;
9510
9511 i = findoption((char_u *)"enc");
9512 if (i >= 0)
9513 return options[i].def_val[VI_DEFAULT];
9514 return (char_u *)NULL;
9515}
9516#endif
9517
Bram Moolenaar071d4272004-06-13 20:20:40 +00009518/*
9519 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9520 */
9521 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009522find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009523{
9524 int key;
9525 int modifiers;
9526
9527 /*
9528 * Don't use get_special_key_code() for t_xx, we don't want it to call
9529 * add_termcap_entry().
9530 */
9531 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9532 key = TERMCAP2KEY(arg[2], arg[3]);
9533 else
9534 {
9535 --arg; /* put arg at the '<' */
9536 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009537 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009538 if (modifiers) /* can't handle modifiers here */
9539 key = 0;
9540 }
9541 return key;
9542}
9543
9544/*
9545 * if 'all' == 0: show changed options
9546 * if 'all' == 1: show all normal options
9547 * if 'all' == 2: show all terminal options
9548 */
9549 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009550showoptions(
9551 int all,
9552 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009553{
9554 struct vimoption *p;
9555 int col;
9556 int isterm;
9557 char_u *varp;
9558 struct vimoption **items;
9559 int item_count;
9560 int run;
9561 int row, rows;
9562 int cols;
9563 int i;
9564 int len;
9565
9566#define INC 20
9567#define GAP 3
9568
9569 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9570 PARAM_COUNT));
9571 if (items == NULL)
9572 return;
9573
9574 /* Highlight title */
9575 if (all == 2)
9576 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9577 else if (opt_flags & OPT_GLOBAL)
9578 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9579 else if (opt_flags & OPT_LOCAL)
9580 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9581 else
9582 MSG_PUTS_TITLE(_("\n--- Options ---"));
9583
9584 /*
9585 * do the loop two times:
9586 * 1. display the short items
9587 * 2. display the long items (only strings and numbers)
9588 */
9589 for (run = 1; run <= 2 && !got_int; ++run)
9590 {
9591 /*
9592 * collect the items in items[]
9593 */
9594 item_count = 0;
9595 for (p = &options[0]; p->fullname != NULL; p++)
9596 {
9597 varp = NULL;
9598 isterm = istermoption(p);
9599 if (opt_flags != 0)
9600 {
9601 if (p->indir != PV_NONE && !isterm)
9602 varp = get_varp_scope(p, opt_flags);
9603 }
9604 else
9605 varp = get_varp(p);
9606 if (varp != NULL
9607 && ((all == 2 && isterm)
9608 || (all == 1 && !isterm)
9609 || (all == 0 && !optval_default(p, varp))))
9610 {
9611 if (p->flags & P_BOOL)
9612 len = 1; /* a toggle option fits always */
9613 else
9614 {
9615 option_value2string(p, opt_flags);
9616 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9617 }
9618 if ((len <= INC - GAP && run == 1) ||
9619 (len > INC - GAP && run == 2))
9620 items[item_count++] = p;
9621 }
9622 }
9623
9624 /*
9625 * display the items
9626 */
9627 if (run == 1)
9628 {
9629 cols = (Columns + GAP - 3) / INC;
9630 if (cols == 0)
9631 cols = 1;
9632 rows = (item_count + cols - 1) / cols;
9633 }
9634 else /* run == 2 */
9635 rows = item_count;
9636 for (row = 0; row < rows && !got_int; ++row)
9637 {
9638 msg_putchar('\n'); /* go to next line */
9639 if (got_int) /* 'q' typed in more */
9640 break;
9641 col = 0;
9642 for (i = row; i < item_count; i += rows)
9643 {
9644 msg_col = col; /* make columns */
9645 showoneopt(items[i], opt_flags);
9646 col += INC;
9647 }
9648 out_flush();
9649 ui_breakcheck();
9650 }
9651 }
9652 vim_free(items);
9653}
9654
9655/*
9656 * Return TRUE if option "p" has its default value.
9657 */
9658 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009659optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660{
9661 int dvi;
9662
9663 if (varp == NULL)
9664 return TRUE; /* hidden option is always at default */
9665 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9666 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009667 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009668 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009669 /* the cast to long is required for Manx C, long_i is
9670 * needed for MSVC */
9671 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009672 /* P_STRING */
9673 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9674}
9675
9676/*
9677 * showoneopt: show the value of one option
9678 * must not be called with a hidden option!
9679 */
9680 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009681showoneopt(
9682 struct vimoption *p,
9683 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009684{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009685 char_u *varp;
9686 int save_silent = silent_mode;
9687
9688 silent_mode = FALSE;
9689 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009690
9691 varp = get_varp_scope(p, opt_flags);
9692
9693 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9694 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9695 ? !curbufIsChanged() : !*(int *)varp))
9696 MSG_PUTS("no");
9697 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9698 MSG_PUTS("--");
9699 else
9700 MSG_PUTS(" ");
9701 MSG_PUTS(p->fullname);
9702 if (!(p->flags & P_BOOL))
9703 {
9704 msg_putchar('=');
9705 /* put value string in NameBuff */
9706 option_value2string(p, opt_flags);
9707 msg_outtrans(NameBuff);
9708 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009709
9710 silent_mode = save_silent;
9711 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009712}
9713
9714/*
9715 * Write modified options as ":set" commands to a file.
9716 *
9717 * There are three values for "opt_flags":
9718 * OPT_GLOBAL: Write global option values and fresh values of
9719 * buffer-local options (used for start of a session
9720 * file).
9721 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9722 * curwin (used for a vimrc file).
9723 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9724 * and local values for window-local options of
9725 * curwin. Local values are also written when at the
9726 * default value, because a modeline or autocommand
9727 * may have set them when doing ":edit file" and the
9728 * user has set them back at the default or fresh
9729 * value.
9730 * When "local_only" is TRUE, don't write fresh
9731 * values, only local values (for ":mkview").
9732 * (fresh value = value used for a new buffer or window for a local option).
9733 *
9734 * Return FAIL on error, OK otherwise.
9735 */
9736 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009737makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009738{
9739 struct vimoption *p;
9740 char_u *varp; /* currently used value */
9741 char_u *varp_fresh; /* local value */
9742 char_u *varp_local = NULL; /* fresh value */
9743 char *cmd;
9744 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009745 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009746
9747 /*
9748 * The options that don't have a default (terminal name, columns, lines)
9749 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009750 * Do the loop over "options[]" twice: once for options with the
9751 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009753 for (pri = 1; pri >= 0; --pri)
9754 {
9755 for (p = &options[0]; !istermoption(p); p++)
9756 if (!(p->flags & P_NO_MKRC)
9757 && !istermoption(p)
9758 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009759 {
9760 /* skip global option when only doing locals */
9761 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9762 continue;
9763
9764 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9765 * file, they are always buffer-specific. */
9766 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9767 continue;
9768
9769 /* Global values are only written when not at the default value. */
9770 varp = get_varp_scope(p, opt_flags);
9771 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9772 continue;
9773
9774 round = 2;
9775 if (p->indir != PV_NONE)
9776 {
9777 if (p->var == VAR_WIN)
9778 {
9779 /* skip window-local option when only doing globals */
9780 if (!(opt_flags & OPT_LOCAL))
9781 continue;
9782 /* When fresh value of window-local option is not at the
9783 * default, need to write it too. */
9784 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9785 {
9786 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9787 if (!optval_default(p, varp_fresh))
9788 {
9789 round = 1;
9790 varp_local = varp;
9791 varp = varp_fresh;
9792 }
9793 }
9794 }
9795 }
9796
9797 /* Round 1: fresh value for window-local options.
9798 * Round 2: other values */
9799 for ( ; round <= 2; varp = varp_local, ++round)
9800 {
9801 if (round == 1 || (opt_flags & OPT_GLOBAL))
9802 cmd = "set";
9803 else
9804 cmd = "setlocal";
9805
9806 if (p->flags & P_BOOL)
9807 {
9808 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9809 return FAIL;
9810 }
9811 else if (p->flags & P_NUM)
9812 {
9813 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9814 return FAIL;
9815 }
9816 else /* P_STRING */
9817 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009818#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9819 int do_endif = FALSE;
9820
Bram Moolenaar071d4272004-06-13 20:20:40 +00009821 /* Don't set 'syntax' and 'filetype' again if the value is
9822 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009823 if (
9824# if defined(FEAT_SYN_HL)
9825 p->indir == PV_SYN
9826# if defined(FEAT_AUTOCMD)
9827 ||
9828# endif
9829# endif
9830# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009831 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009832# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009833 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009834 {
9835 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9836 *(char_u **)(varp)) < 0
9837 || put_eol(fd) < 0)
9838 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009839 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009840 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009841#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009842 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9843 (p->flags & P_EXPAND) != 0) == FAIL)
9844 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009845#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9846 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009847 {
9848 if (put_line(fd, "endif") == FAIL)
9849 return FAIL;
9850 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009851#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009852 }
9853 }
9854 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009855 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009856 return OK;
9857}
9858
9859#if defined(FEAT_FOLDING) || defined(PROTO)
9860/*
9861 * Generate set commands for the local fold options only. Used when
9862 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9863 */
9864 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009865makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009866{
9867 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9868# ifdef FEAT_EVAL
9869 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9870 == FAIL
9871# endif
9872 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9873 == FAIL
9874 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9875 == FAIL
9876 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9877 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9878 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9879 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9880 )
9881 return FAIL;
9882
9883 return OK;
9884}
9885#endif
9886
9887 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009888put_setstring(
9889 FILE *fd,
9890 char *cmd,
9891 char *name,
9892 char_u **valuep,
9893 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009894{
9895 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009896 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009897
9898 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9899 return FAIL;
9900 if (*valuep != NULL)
9901 {
9902 /* Output 'pastetoggle' as key names. For other
9903 * options some characters have to be escaped with
9904 * CTRL-V or backslash */
9905 if (valuep == &p_pt)
9906 {
9907 s = *valuep;
9908 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +00009909 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910 return FAIL;
9911 }
9912 else if (expand)
9913 {
Bram Moolenaarf8441472011-04-28 17:24:58 +02009914 buf = alloc(MAXPATHL);
9915 if (buf == NULL)
9916 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009917 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
9918 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +02009919 {
9920 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009922 }
9923 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009924 }
9925 else if (put_escstr(fd, *valuep, 2) == FAIL)
9926 return FAIL;
9927 }
9928 if (put_eol(fd) < 0)
9929 return FAIL;
9930 return OK;
9931}
9932
9933 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009934put_setnum(
9935 FILE *fd,
9936 char *cmd,
9937 char *name,
9938 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009939{
9940 long wc;
9941
9942 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9943 return FAIL;
9944 if (wc_use_keyname((char_u *)valuep, &wc))
9945 {
9946 /* print 'wildchar' and 'wildcharm' as a key name */
9947 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
9948 return FAIL;
9949 }
9950 else if (fprintf(fd, "%ld", *valuep) < 0)
9951 return FAIL;
9952 if (put_eol(fd) < 0)
9953 return FAIL;
9954 return OK;
9955}
9956
9957 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009958put_setbool(
9959 FILE *fd,
9960 char *cmd,
9961 char *name,
9962 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009963{
Bram Moolenaar893de922007-10-02 18:40:57 +00009964 if (value < 0) /* global/local option using global value */
9965 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009966 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
9967 || put_eol(fd) < 0)
9968 return FAIL;
9969 return OK;
9970}
9971
9972/*
9973 * Clear all the terminal options.
9974 * If the option has been allocated, free the memory.
9975 * Terminal options are never hidden or indirect.
9976 */
9977 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009978clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009979{
Bram Moolenaar071d4272004-06-13 20:20:40 +00009980 /*
9981 * Reset a few things before clearing the old options. This may cause
9982 * outputting a few things that the terminal doesn't understand, but the
9983 * screen will be cleared later, so this is OK.
9984 */
9985#ifdef FEAT_MOUSE_TTY
9986 mch_setmouse(FALSE); /* switch mouse off */
9987#endif
9988#ifdef FEAT_TITLE
9989 mch_restore_title(3); /* restore window titles */
9990#endif
9991#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
9992 /* When starting the GUI close the display opened for the clipboard.
9993 * After restoring the title, because that will need the display. */
9994 if (gui.starting)
9995 clear_xterm_clip();
9996#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +02009997 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00009999 free_termoptions();
10000}
10001
10002 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010003free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010004{
10005 struct vimoption *p;
10006
Bram Moolenaar071d4272004-06-13 20:20:40 +000010007 for (p = &options[0]; p->fullname != NULL; p++)
10008 if (istermoption(p))
10009 {
10010 if (p->flags & P_ALLOCED)
10011 free_string_option(*(char_u **)(p->var));
10012 if (p->flags & P_DEF_ALLOCED)
10013 free_string_option(p->def_val[VI_DEFAULT]);
10014 *(char_u **)(p->var) = empty_option;
10015 p->def_val[VI_DEFAULT] = empty_option;
10016 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10017 }
10018 clear_termcodes();
10019}
10020
10021/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010022 * Free the string for one term option, if it was allocated.
10023 * Set the string to empty_option and clear allocated flag.
10024 * "var" points to the option value.
10025 */
10026 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010027free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010028{
10029 struct vimoption *p;
10030
10031 for (p = &options[0]; p->fullname != NULL; p++)
10032 if (p->var == var)
10033 {
10034 if (p->flags & P_ALLOCED)
10035 free_string_option(*(char_u **)(p->var));
10036 *(char_u **)(p->var) = empty_option;
10037 p->flags &= ~P_ALLOCED;
10038 break;
10039 }
10040}
10041
10042/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010043 * Set the terminal option defaults to the current value.
10044 * Used after setting the terminal name.
10045 */
10046 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010047set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010048{
10049 struct vimoption *p;
10050
10051 for (p = &options[0]; p->fullname != NULL; p++)
10052 {
10053 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10054 {
10055 if (p->flags & P_DEF_ALLOCED)
10056 {
10057 free_string_option(p->def_val[VI_DEFAULT]);
10058 p->flags &= ~P_DEF_ALLOCED;
10059 }
10060 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10061 if (p->flags & P_ALLOCED)
10062 {
10063 p->flags |= P_DEF_ALLOCED;
10064 p->flags &= ~P_ALLOCED; /* don't free the value now */
10065 }
10066 }
10067 }
10068}
10069
10070/*
10071 * return TRUE if 'p' starts with 't_'
10072 */
10073 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010074istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010075{
10076 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10077}
10078
10079/*
10080 * Compute columns for ruler and shown command. 'sc_col' is also used to
10081 * decide what the maximum length of a message on the status line can be.
10082 * If there is a status line for the last window, 'sc_col' is independent
10083 * of 'ru_col'.
10084 */
10085
10086#define COL_RULER 17 /* columns needed by standard ruler */
10087
10088 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010089comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010090{
10091#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010092 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010093
10094 sc_col = 0;
10095 ru_col = 0;
10096 if (p_ru)
10097 {
10098#ifdef FEAT_STL_OPT
10099 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10100#else
10101 ru_col = COL_RULER + 1;
10102#endif
10103 /* no last status line, adjust sc_col */
10104 if (!last_has_status)
10105 sc_col = ru_col;
10106 }
10107 if (p_sc)
10108 {
10109 sc_col += SHOWCMD_COLS;
10110 if (!p_ru || last_has_status) /* no need for separating space */
10111 ++sc_col;
10112 }
10113 sc_col = Columns - sc_col;
10114 ru_col = Columns - ru_col;
10115 if (sc_col <= 0) /* screen too narrow, will become a mess */
10116 sc_col = 1;
10117 if (ru_col <= 0)
10118 ru_col = 1;
10119#else
10120 sc_col = Columns;
10121 ru_col = Columns;
10122#endif
10123}
10124
10125/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010126 * Unset local option value, similar to ":set opt<".
10127 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010128 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010129unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010130{
10131 struct vimoption *p;
10132 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010133 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010134
10135 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010136 if (opt_idx < 0)
10137 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010138 p = &(options[opt_idx]);
10139
10140 switch ((int)p->indir)
10141 {
10142 /* global option with local value: use local value if it's been set */
10143 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010144 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010145 break;
10146 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010147 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010148 break;
10149 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010150 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010151 break;
10152 case PV_AR:
10153 buf->b_p_ar = -1;
10154 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010155 case PV_BKC:
10156 clear_string_option(&buf->b_p_bkc);
10157 buf->b_bkc_flags = 0;
10158 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010159 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010160 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010161 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010162 case PV_TC:
10163 clear_string_option(&buf->b_p_tc);
10164 buf->b_tc_flags = 0;
10165 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010166#ifdef FEAT_FIND_ID
10167 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010168 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010169 break;
10170 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010171 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010172 break;
10173#endif
10174#ifdef FEAT_INS_EXPAND
10175 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010176 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010177 break;
10178 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010179 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010180 break;
10181#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010182 case PV_FP:
10183 clear_string_option(&buf->b_p_fp);
10184 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010185#ifdef FEAT_QUICKFIX
10186 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010187 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010188 break;
10189 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010190 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010191 break;
10192 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010193 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010194 break;
10195#endif
10196#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10197 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010198 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010199 break;
10200#endif
10201#if defined(FEAT_CRYPT)
10202 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010203 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010204 break;
10205#endif
10206#ifdef FEAT_STL_OPT
10207 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010208 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010209 break;
10210#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010211 case PV_UL:
10212 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10213 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010214#ifdef FEAT_LISP
10215 case PV_LW:
10216 clear_string_option(&buf->b_p_lw);
10217 break;
10218#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010219 }
10220}
10221
10222/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010223 * Get pointer to option variable, depending on local or global scope.
10224 */
10225 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010226get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227{
10228 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10229 {
10230 if (p->var == VAR_WIN)
10231 return (char_u *)GLOBAL_WO(get_varp(p));
10232 return p->var;
10233 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010234 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010235 {
10236 switch ((int)p->indir)
10237 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010238 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010240 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10241 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10242 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010244 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10245 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10246 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010247 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010248 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010249 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010250#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010251 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10252 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010253#endif
10254#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010255 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10256 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010258#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10259 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10260#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010261#if defined(FEAT_CRYPT)
10262 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10263#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010264#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010265 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010266#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010267 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010268#ifdef FEAT_LISP
10269 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10270#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010271 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272 }
10273 return NULL; /* "cannot happen" */
10274 }
10275 return get_varp(p);
10276}
10277
10278/*
10279 * Get pointer to option variable.
10280 */
10281 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010282get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010283{
10284 /* hidden option, always return NULL */
10285 if (p->var == NULL)
10286 return NULL;
10287
10288 switch ((int)p->indir)
10289 {
10290 case PV_NONE: return p->var;
10291
10292 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010293 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010295 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010296 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010297 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010298 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010299 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010301 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010303 case PV_TC: return *curbuf->b_p_tc != NUL
10304 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010305 case PV_BKC: return *curbuf->b_p_bkc != NUL
10306 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010307#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010308 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010310 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10312#endif
10313#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010314 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010316 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010317 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10318#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010319 case PV_FP: return *curbuf->b_p_fp != NUL
10320 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010322 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010324 case PV_GP: return *curbuf->b_p_gp != NUL
10325 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10326 case PV_MP: return *curbuf->b_p_mp != NUL
10327 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010328#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010329#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10330 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10331 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10332#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010333#if defined(FEAT_CRYPT)
10334 case PV_CM: return *curbuf->b_p_cm != NUL
10335 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10336#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010337#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010338 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010339 ? (char_u *)&(curwin->w_p_stl) : p->var;
10340#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010341 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10342 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010343#ifdef FEAT_LISP
10344 case PV_LW: return *curbuf->b_p_lw != NUL
10345 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347
10348#ifdef FEAT_ARABIC
10349 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10350#endif
10351 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010352#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010353 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10354#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010355#ifdef FEAT_SYN_HL
10356 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10357 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010358 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010360#ifdef FEAT_DIFF
10361 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10362#endif
10363#ifdef FEAT_FOLDING
10364 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10365 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10366 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10367 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10368 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10369 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10370 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10371# ifdef FEAT_EVAL
10372 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10373 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10374# endif
10375 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10376#endif
10377 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010378 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010379#ifdef FEAT_LINEBREAK
10380 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10381#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010382#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010384 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010386#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10387 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10388#endif
10389#ifdef FEAT_RIGHTLEFT
10390 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10391 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10392#endif
10393 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10394 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10395#ifdef FEAT_LINEBREAK
10396 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010397 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10398 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399#endif
10400#ifdef FEAT_SCROLLBIND
10401 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10402#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010403#ifdef FEAT_CURSORBIND
10404 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10405#endif
10406#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010407 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10408 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010409#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010410
10411 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10412 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10413#ifdef FEAT_MBYTE
10414 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10415#endif
10416#if defined(FEAT_QUICKFIX)
10417 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10418 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10419#endif
10420 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10421 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10422#ifdef FEAT_CINDENT
10423 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10424 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10425 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10426#endif
10427#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10428 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10429#endif
10430#ifdef FEAT_COMMENTS
10431 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10432#endif
10433#ifdef FEAT_FOLDING
10434 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10435#endif
10436#ifdef FEAT_INS_EXPAND
10437 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10438#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010439#ifdef FEAT_COMPL_FUNC
10440 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010441 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010442#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010443 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010444 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010445 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10446#ifdef FEAT_MBYTE
10447 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10448#endif
10449 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10450#ifdef FEAT_AUTOCMD
10451 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10452#endif
10453 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010454 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010455 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10456 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10457 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10458 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10459#ifdef FEAT_FIND_ID
10460# ifdef FEAT_EVAL
10461 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10462# endif
10463#endif
10464#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10465 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10466 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10467#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010468#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010469 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10470#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010471#ifdef FEAT_CRYPT
10472 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10473#endif
10474#ifdef FEAT_LISP
10475 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10476#endif
10477 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10478 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10479 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10480 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10481 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010483#ifdef FEAT_TEXTOBJ
10484 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10485#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10487#ifdef FEAT_SMARTINDENT
10488 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10489#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10492#ifdef FEAT_SEARCHPATH
10493 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10494#endif
10495 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10496#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010497 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010498 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10499#endif
10500#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010501 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10502 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10503 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010504#endif
10505 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10506 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10507 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10508 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010509#ifdef FEAT_PERSISTENT_UNDO
10510 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10511#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10513#ifdef FEAT_KEYMAP
10514 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10515#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010516#ifdef FEAT_SIGNS
10517 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10518#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010519 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 }
10521 /* always return a valid pointer to avoid a crash! */
10522 return (char_u *)&(curbuf->b_p_wm);
10523}
10524
10525/*
10526 * Get the value of 'equalprg', either the buffer-local one or the global one.
10527 */
10528 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010529get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530{
10531 if (*curbuf->b_p_ep == NUL)
10532 return p_ep;
10533 return curbuf->b_p_ep;
10534}
10535
10536#if defined(FEAT_WINDOWS) || defined(PROTO)
10537/*
10538 * Copy options from one window to another.
10539 * Used when splitting a window.
10540 */
10541 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010542win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543{
10544 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10545 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10546# ifdef FEAT_RIGHTLEFT
10547# ifdef FEAT_FKMAP
10548 /* Is this right? */
10549 wp_to->w_farsi = wp_from->w_farsi;
10550# endif
10551# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010552#if defined(FEAT_LINEBREAK)
10553 briopt_check(wp_to);
10554#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555}
10556#endif
10557
10558/*
10559 * Copy the options from one winopt_T to another.
10560 * Doesn't free the old option values in "to", use clear_winopt() for that.
10561 * The 'scroll' option is not copied, because it depends on the window height.
10562 * The 'previewwindow' option is reset, there can be only one preview window.
10563 */
10564 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010565copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010566{
10567#ifdef FEAT_ARABIC
10568 to->wo_arab = from->wo_arab;
10569#endif
10570 to->wo_list = from->wo_list;
10571 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010572 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010573#ifdef FEAT_LINEBREAK
10574 to->wo_nuw = from->wo_nuw;
10575#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010576#ifdef FEAT_RIGHTLEFT
10577 to->wo_rl = from->wo_rl;
10578 to->wo_rlc = vim_strsave(from->wo_rlc);
10579#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010580#ifdef FEAT_STL_OPT
10581 to->wo_stl = vim_strsave(from->wo_stl);
10582#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010584#ifdef FEAT_DIFF
10585 to->wo_wrap_save = from->wo_wrap_save;
10586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587#ifdef FEAT_LINEBREAK
10588 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010589 to->wo_bri = from->wo_bri;
10590 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591#endif
10592#ifdef FEAT_SCROLLBIND
10593 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010594 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010596#ifdef FEAT_CURSORBIND
10597 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010598 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010599#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010600#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010601 to->wo_spell = from->wo_spell;
10602#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010603#ifdef FEAT_SYN_HL
10604 to->wo_cuc = from->wo_cuc;
10605 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010606 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010607#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608#ifdef FEAT_DIFF
10609 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010610 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010612#ifdef FEAT_CONCEAL
10613 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010614 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010615#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616#ifdef FEAT_FOLDING
10617 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010618 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010620 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621 to->wo_fdi = vim_strsave(from->wo_fdi);
10622 to->wo_fml = from->wo_fml;
10623 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010624 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010626 to->wo_fdm_save = from->wo_diff_saved
10627 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628 to->wo_fdn = from->wo_fdn;
10629# ifdef FEAT_EVAL
10630 to->wo_fde = vim_strsave(from->wo_fde);
10631 to->wo_fdt = vim_strsave(from->wo_fdt);
10632# endif
10633 to->wo_fmr = vim_strsave(from->wo_fmr);
10634#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010635#ifdef FEAT_SIGNS
10636 to->wo_scl = vim_strsave(from->wo_scl);
10637#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010638 check_winopt(to); /* don't want NULL pointers */
10639}
10640
10641/*
10642 * Check string options in a window for a NULL value.
10643 */
10644 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010645check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010646{
10647 check_winopt(&win->w_onebuf_opt);
10648 check_winopt(&win->w_allbuf_opt);
10649}
10650
10651/*
10652 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10653 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010654 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010655check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010656{
10657#ifdef FEAT_FOLDING
10658 check_string_option(&wop->wo_fdi);
10659 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010660 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010661# ifdef FEAT_EVAL
10662 check_string_option(&wop->wo_fde);
10663 check_string_option(&wop->wo_fdt);
10664# endif
10665 check_string_option(&wop->wo_fmr);
10666#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010667#ifdef FEAT_SIGNS
10668 check_string_option(&wop->wo_scl);
10669#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010670#ifdef FEAT_RIGHTLEFT
10671 check_string_option(&wop->wo_rlc);
10672#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010673#ifdef FEAT_STL_OPT
10674 check_string_option(&wop->wo_stl);
10675#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010676#ifdef FEAT_SYN_HL
10677 check_string_option(&wop->wo_cc);
10678#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010679#ifdef FEAT_CONCEAL
10680 check_string_option(&wop->wo_cocu);
10681#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010682#ifdef FEAT_LINEBREAK
10683 check_string_option(&wop->wo_briopt);
10684#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685}
10686
10687/*
10688 * Free the allocated memory inside a winopt_T.
10689 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010690 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010691clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010692{
10693#ifdef FEAT_FOLDING
10694 clear_string_option(&wop->wo_fdi);
10695 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010696 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010697# ifdef FEAT_EVAL
10698 clear_string_option(&wop->wo_fde);
10699 clear_string_option(&wop->wo_fdt);
10700# endif
10701 clear_string_option(&wop->wo_fmr);
10702#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010703#ifdef FEAT_SIGNS
10704 clear_string_option(&wop->wo_scl);
10705#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010706#ifdef FEAT_LINEBREAK
10707 clear_string_option(&wop->wo_briopt);
10708#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709#ifdef FEAT_RIGHTLEFT
10710 clear_string_option(&wop->wo_rlc);
10711#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010712#ifdef FEAT_STL_OPT
10713 clear_string_option(&wop->wo_stl);
10714#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010715#ifdef FEAT_SYN_HL
10716 clear_string_option(&wop->wo_cc);
10717#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010718#ifdef FEAT_CONCEAL
10719 clear_string_option(&wop->wo_cocu);
10720#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721}
10722
10723/*
10724 * Copy global option values to local options for one buffer.
10725 * Used when creating a new buffer and sometimes when entering a buffer.
10726 * flags:
10727 * BCO_ENTER We will enter the buf buffer.
10728 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10729 * appropriate.
10730 * BCO_NOHELP Don't copy the values to a help buffer.
10731 */
10732 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010733buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734{
10735 int should_copy = TRUE;
10736 char_u *save_p_isk = NULL; /* init for GCC */
10737 int dont_do_help;
10738 int did_isk = FALSE;
10739
10740 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741 * Skip this when the option defaults have not been set yet. Happens when
10742 * main() allocates the first buffer.
10743 */
10744 if (p_cpo != NULL)
10745 {
10746 /*
10747 * Always copy when entering and 'cpo' contains 'S'.
10748 * Don't copy when already initialized.
10749 * Don't copy when 'cpo' contains 's' and not entering.
10750 * 'S' BCO_ENTER initialized 's' should_copy
10751 * yes yes X X TRUE
10752 * yes no yes X FALSE
10753 * no X yes X FALSE
10754 * X no no yes FALSE
10755 * X no no no TRUE
10756 * no yes no X TRUE
10757 */
10758 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10759 && (buf->b_p_initialized
10760 || (!(flags & BCO_ENTER)
10761 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10762 should_copy = FALSE;
10763
10764 if (should_copy || (flags & BCO_ALWAYS))
10765 {
10766 /* Don't copy the options specific to a help buffer when
10767 * BCO_NOHELP is given or the options were initialized already
10768 * (jumping back to a help file with CTRL-T or CTRL-O) */
10769 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10770 || buf->b_p_initialized;
10771 if (dont_do_help) /* don't free b_p_isk */
10772 {
10773 save_p_isk = buf->b_p_isk;
10774 buf->b_p_isk = NULL;
10775 }
10776 /*
10777 * Always free the allocated strings.
10778 * If not already initialized, set 'readonly' and copy 'fileformat'.
10779 */
10780 if (!buf->b_p_initialized)
10781 {
10782 free_buf_options(buf, TRUE);
10783 buf->b_p_ro = FALSE; /* don't copy readonly */
10784 buf->b_p_tx = p_tx;
10785#ifdef FEAT_MBYTE
10786 buf->b_p_fenc = vim_strsave(p_fenc);
10787#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020010788 switch (*p_ffs)
10789 {
10790 case 'm':
10791 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
10792 case 'd':
10793 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
10794 case 'u':
10795 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
10796 default:
10797 buf->b_p_ff = vim_strsave(p_ff);
10798 }
10799 if (buf->b_p_ff != NULL)
10800 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801#if defined(FEAT_QUICKFIX)
10802 buf->b_p_bh = empty_option;
10803 buf->b_p_bt = empty_option;
10804#endif
10805 }
10806 else
10807 free_buf_options(buf, FALSE);
10808
10809 buf->b_p_ai = p_ai;
10810 buf->b_p_ai_nopaste = p_ai_nopaste;
10811 buf->b_p_sw = p_sw;
10812 buf->b_p_tw = p_tw;
10813 buf->b_p_tw_nopaste = p_tw_nopaste;
10814 buf->b_p_tw_nobin = p_tw_nobin;
10815 buf->b_p_wm = p_wm;
10816 buf->b_p_wm_nopaste = p_wm_nopaste;
10817 buf->b_p_wm_nobin = p_wm_nobin;
10818 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010819#ifdef FEAT_MBYTE
10820 buf->b_p_bomb = p_bomb;
10821#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010822 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823 buf->b_p_et = p_et;
10824 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010825 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010826 buf->b_p_ml = p_ml;
10827 buf->b_p_ml_nobin = p_ml_nobin;
10828 buf->b_p_inf = p_inf;
10829 buf->b_p_swf = p_swf;
10830#ifdef FEAT_INS_EXPAND
10831 buf->b_p_cpt = vim_strsave(p_cpt);
10832#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010833#ifdef FEAT_COMPL_FUNC
10834 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010835 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010836#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837 buf->b_p_sts = p_sts;
10838 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840#ifdef FEAT_COMMENTS
10841 buf->b_p_com = vim_strsave(p_com);
10842#endif
10843#ifdef FEAT_FOLDING
10844 buf->b_p_cms = vim_strsave(p_cms);
10845#endif
10846 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010847 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848 buf->b_p_nf = vim_strsave(p_nf);
10849 buf->b_p_mps = vim_strsave(p_mps);
10850#ifdef FEAT_SMARTINDENT
10851 buf->b_p_si = p_si;
10852#endif
10853 buf->b_p_ci = p_ci;
10854#ifdef FEAT_CINDENT
10855 buf->b_p_cin = p_cin;
10856 buf->b_p_cink = vim_strsave(p_cink);
10857 buf->b_p_cino = vim_strsave(p_cino);
10858#endif
10859#ifdef FEAT_AUTOCMD
10860 /* Don't copy 'filetype', it must be detected */
10861 buf->b_p_ft = empty_option;
10862#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863 buf->b_p_pi = p_pi;
10864#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10865 buf->b_p_cinw = vim_strsave(p_cinw);
10866#endif
10867#ifdef FEAT_LISP
10868 buf->b_p_lisp = p_lisp;
10869#endif
10870#ifdef FEAT_SYN_HL
10871 /* Don't copy 'syntax', it must be set */
10872 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010873 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010874 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010875#endif
10876#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010877 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010878 (void)compile_cap_prog(&buf->b_s);
10879 buf->b_s.b_p_spf = vim_strsave(p_spf);
10880 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010881#endif
10882#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10883 buf->b_p_inde = vim_strsave(p_inde);
10884 buf->b_p_indk = vim_strsave(p_indk);
10885#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010886 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010887#if defined(FEAT_EVAL)
10888 buf->b_p_fex = vim_strsave(p_fex);
10889#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890#ifdef FEAT_CRYPT
10891 buf->b_p_key = vim_strsave(p_key);
10892#endif
10893#ifdef FEAT_SEARCHPATH
10894 buf->b_p_sua = vim_strsave(p_sua);
10895#endif
10896#ifdef FEAT_KEYMAP
10897 buf->b_p_keymap = vim_strsave(p_keymap);
10898 buf->b_kmap_state |= KEYMAP_INIT;
10899#endif
10900 /* This isn't really an option, but copying the langmap and IME
10901 * state from the current buffer is better than resetting it. */
10902 buf->b_p_iminsert = p_iminsert;
10903 buf->b_p_imsearch = p_imsearch;
10904
10905 /* options that are normally global but also have a local value
10906 * are not copied, start using the global value */
10907 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010908 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010909 buf->b_p_bkc = empty_option;
10910 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010911#ifdef FEAT_QUICKFIX
10912 buf->b_p_gp = empty_option;
10913 buf->b_p_mp = empty_option;
10914 buf->b_p_efm = empty_option;
10915#endif
10916 buf->b_p_ep = empty_option;
10917 buf->b_p_kp = empty_option;
10918 buf->b_p_path = empty_option;
10919 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010920 buf->b_p_tc = empty_option;
10921 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922#ifdef FEAT_FIND_ID
10923 buf->b_p_def = empty_option;
10924 buf->b_p_inc = empty_option;
10925# ifdef FEAT_EVAL
10926 buf->b_p_inex = vim_strsave(p_inex);
10927# endif
10928#endif
10929#ifdef FEAT_INS_EXPAND
10930 buf->b_p_dict = empty_option;
10931 buf->b_p_tsr = empty_option;
10932#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010933#ifdef FEAT_TEXTOBJ
10934 buf->b_p_qe = vim_strsave(p_qe);
10935#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010936#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10937 buf->b_p_bexpr = empty_option;
10938#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010939#if defined(FEAT_CRYPT)
10940 buf->b_p_cm = empty_option;
10941#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010942#ifdef FEAT_PERSISTENT_UNDO
10943 buf->b_p_udf = p_udf;
10944#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010945#ifdef FEAT_LISP
10946 buf->b_p_lw = empty_option;
10947#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010948
10949 /*
10950 * Don't copy the options set by ex_help(), use the saved values,
10951 * when going from a help buffer to a non-help buffer.
10952 * Don't touch these at all when BCO_NOHELP is used and going from
10953 * or to a help buffer.
10954 */
10955 if (dont_do_help)
10956 buf->b_p_isk = save_p_isk;
10957 else
10958 {
10959 buf->b_p_isk = vim_strsave(p_isk);
10960 did_isk = TRUE;
10961 buf->b_p_ts = p_ts;
10962 buf->b_help = FALSE;
10963#ifdef FEAT_QUICKFIX
10964 if (buf->b_p_bt[0] == 'h')
10965 clear_string_option(&buf->b_p_bt);
10966#endif
10967 buf->b_p_ma = p_ma;
10968 }
10969 }
10970
10971 /*
10972 * When the options should be copied (ignoring BCO_ALWAYS), set the
10973 * flag that indicates that the options have been initialized.
10974 */
10975 if (should_copy)
10976 buf->b_p_initialized = TRUE;
10977 }
10978
10979 check_buf_options(buf); /* make sure we don't have NULLs */
10980 if (did_isk)
10981 (void)buf_init_chartab(buf, FALSE);
10982}
10983
10984/*
10985 * Reset the 'modifiable' option and its default value.
10986 */
10987 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010988reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989{
10990 int opt_idx;
10991
10992 curbuf->b_p_ma = FALSE;
10993 p_ma = FALSE;
10994 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010995 if (opt_idx >= 0)
10996 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010997}
10998
10999/*
11000 * Set the global value for 'iminsert' to the local value.
11001 */
11002 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011003set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011004{
11005 p_iminsert = curbuf->b_p_iminsert;
11006}
11007
11008/*
11009 * Set the global value for 'imsearch' to the local value.
11010 */
11011 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011012set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013{
11014 p_imsearch = curbuf->b_p_imsearch;
11015}
11016
11017#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11018static int expand_option_idx = -1;
11019static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11020static int expand_option_flags = 0;
11021
11022 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011023set_context_in_set_cmd(
11024 expand_T *xp,
11025 char_u *arg,
11026 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011027{
11028 int nextchar;
11029 long_u flags = 0; /* init for GCC */
11030 int opt_idx = 0; /* init for GCC */
11031 char_u *p;
11032 char_u *s;
11033 int is_term_option = FALSE;
11034 int key;
11035
11036 expand_option_flags = opt_flags;
11037
11038 xp->xp_context = EXPAND_SETTINGS;
11039 if (*arg == NUL)
11040 {
11041 xp->xp_pattern = arg;
11042 return;
11043 }
11044 p = arg + STRLEN(arg) - 1;
11045 if (*p == ' ' && *(p - 1) != '\\')
11046 {
11047 xp->xp_pattern = p + 1;
11048 return;
11049 }
11050 while (p > arg)
11051 {
11052 s = p;
11053 /* count number of backslashes before ' ' or ',' */
11054 if (*p == ' ' || *p == ',')
11055 {
11056 while (s > arg && *(s - 1) == '\\')
11057 --s;
11058 }
11059 /* break at a space with an even number of backslashes */
11060 if (*p == ' ' && ((p - s) & 1) == 0)
11061 {
11062 ++p;
11063 break;
11064 }
11065 --p;
11066 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011067 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011068 {
11069 xp->xp_context = EXPAND_BOOL_SETTINGS;
11070 p += 2;
11071 }
11072 if (STRNCMP(p, "inv", 3) == 0)
11073 {
11074 xp->xp_context = EXPAND_BOOL_SETTINGS;
11075 p += 3;
11076 }
11077 xp->xp_pattern = arg = p;
11078 if (*arg == '<')
11079 {
11080 while (*p != '>')
11081 if (*p++ == NUL) /* expand terminal option name */
11082 return;
11083 key = get_special_key_code(arg + 1);
11084 if (key == 0) /* unknown name */
11085 {
11086 xp->xp_context = EXPAND_NOTHING;
11087 return;
11088 }
11089 nextchar = *++p;
11090 is_term_option = TRUE;
11091 expand_option_name[2] = KEY2TERMCAP0(key);
11092 expand_option_name[3] = KEY2TERMCAP1(key);
11093 }
11094 else
11095 {
11096 if (p[0] == 't' && p[1] == '_')
11097 {
11098 p += 2;
11099 if (*p != NUL)
11100 ++p;
11101 if (*p == NUL)
11102 return; /* expand option name */
11103 nextchar = *++p;
11104 is_term_option = TRUE;
11105 expand_option_name[2] = p[-2];
11106 expand_option_name[3] = p[-1];
11107 }
11108 else
11109 {
11110 /* Allow * wildcard */
11111 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11112 p++;
11113 if (*p == NUL)
11114 return;
11115 nextchar = *p;
11116 *p = NUL;
11117 opt_idx = findoption(arg);
11118 *p = nextchar;
11119 if (opt_idx == -1 || options[opt_idx].var == NULL)
11120 {
11121 xp->xp_context = EXPAND_NOTHING;
11122 return;
11123 }
11124 flags = options[opt_idx].flags;
11125 if (flags & P_BOOL)
11126 {
11127 xp->xp_context = EXPAND_NOTHING;
11128 return;
11129 }
11130 }
11131 }
11132 /* handle "-=" and "+=" */
11133 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11134 {
11135 ++p;
11136 nextchar = '=';
11137 }
11138 if ((nextchar != '=' && nextchar != ':')
11139 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11140 {
11141 xp->xp_context = EXPAND_UNSUCCESSFUL;
11142 return;
11143 }
11144 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11145 {
11146 xp->xp_context = EXPAND_OLD_SETTING;
11147 if (is_term_option)
11148 expand_option_idx = -1;
11149 else
11150 expand_option_idx = opt_idx;
11151 xp->xp_pattern = p + 1;
11152 return;
11153 }
11154 xp->xp_context = EXPAND_NOTHING;
11155 if (is_term_option || (flags & P_NUM))
11156 return;
11157
11158 xp->xp_pattern = p + 1;
11159
11160 if (flags & P_EXPAND)
11161 {
11162 p = options[opt_idx].var;
11163 if (p == (char_u *)&p_bdir
11164 || p == (char_u *)&p_dir
11165 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011166 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 || p == (char_u *)&p_rtp
11168#ifdef FEAT_SEARCHPATH
11169 || p == (char_u *)&p_cdpath
11170#endif
11171#ifdef FEAT_SESSION
11172 || p == (char_u *)&p_vdir
11173#endif
11174 )
11175 {
11176 xp->xp_context = EXPAND_DIRECTORIES;
11177 if (p == (char_u *)&p_path
11178#ifdef FEAT_SEARCHPATH
11179 || p == (char_u *)&p_cdpath
11180#endif
11181 )
11182 xp->xp_backslash = XP_BS_THREE;
11183 else
11184 xp->xp_backslash = XP_BS_ONE;
11185 }
11186 else
11187 {
11188 xp->xp_context = EXPAND_FILES;
11189 /* for 'tags' need three backslashes for a space */
11190 if (p == (char_u *)&p_tags)
11191 xp->xp_backslash = XP_BS_THREE;
11192 else
11193 xp->xp_backslash = XP_BS_ONE;
11194 }
11195 }
11196
11197 /* For an option that is a list of file names, find the start of the
11198 * last file name. */
11199 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11200 {
11201 /* count number of backslashes before ' ' or ',' */
11202 if (*p == ' ' || *p == ',')
11203 {
11204 s = p;
11205 while (s > xp->xp_pattern && *(s - 1) == '\\')
11206 --s;
11207 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11208 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11209 {
11210 xp->xp_pattern = p + 1;
11211 break;
11212 }
11213 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011214
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011215#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011216 /* for 'spellsuggest' start at "file:" */
11217 if (options[opt_idx].var == (char_u *)&p_sps
11218 && STRNCMP(p, "file:", 5) == 0)
11219 {
11220 xp->xp_pattern = p + 5;
11221 break;
11222 }
11223#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011224 }
11225
11226 return;
11227}
11228
11229 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011230ExpandSettings(
11231 expand_T *xp,
11232 regmatch_T *regmatch,
11233 int *num_file,
11234 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011235{
11236 int num_normal = 0; /* Nr of matching non-term-code settings */
11237 int num_term = 0; /* Nr of matching terminal code settings */
11238 int opt_idx;
11239 int match;
11240 int count = 0;
11241 char_u *str;
11242 int loop;
11243 int is_term_opt;
11244 char_u name_buf[MAX_KEY_NAME_LEN];
11245 static char *(names[]) = {"all", "termcap"};
11246 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11247
11248 /* do this loop twice:
11249 * loop == 0: count the number of matching options
11250 * loop == 1: copy the matching options into allocated memory
11251 */
11252 for (loop = 0; loop <= 1; ++loop)
11253 {
11254 regmatch->rm_ic = ic;
11255 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11256 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011257 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11258 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011259 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11260 {
11261 if (loop == 0)
11262 num_normal++;
11263 else
11264 (*file)[count++] = vim_strsave((char_u *)names[match]);
11265 }
11266 }
11267 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11268 opt_idx++)
11269 {
11270 if (options[opt_idx].var == NULL)
11271 continue;
11272 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11273 && !(options[opt_idx].flags & P_BOOL))
11274 continue;
11275 is_term_opt = istermoption(&options[opt_idx]);
11276 if (is_term_opt && num_normal > 0)
11277 continue;
11278 match = FALSE;
11279 if (vim_regexec(regmatch, str, (colnr_T)0)
11280 || (options[opt_idx].shortname != NULL
11281 && vim_regexec(regmatch,
11282 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11283 match = TRUE;
11284 else if (is_term_opt)
11285 {
11286 name_buf[0] = '<';
11287 name_buf[1] = 't';
11288 name_buf[2] = '_';
11289 name_buf[3] = str[2];
11290 name_buf[4] = str[3];
11291 name_buf[5] = '>';
11292 name_buf[6] = NUL;
11293 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11294 {
11295 match = TRUE;
11296 str = name_buf;
11297 }
11298 }
11299 if (match)
11300 {
11301 if (loop == 0)
11302 {
11303 if (is_term_opt)
11304 num_term++;
11305 else
11306 num_normal++;
11307 }
11308 else
11309 (*file)[count++] = vim_strsave(str);
11310 }
11311 }
11312 /*
11313 * Check terminal key codes, these are not in the option table
11314 */
11315 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11316 {
11317 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11318 {
11319 if (!isprint(str[0]) || !isprint(str[1]))
11320 continue;
11321
11322 name_buf[0] = 't';
11323 name_buf[1] = '_';
11324 name_buf[2] = str[0];
11325 name_buf[3] = str[1];
11326 name_buf[4] = NUL;
11327
11328 match = FALSE;
11329 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11330 match = TRUE;
11331 else
11332 {
11333 name_buf[0] = '<';
11334 name_buf[1] = 't';
11335 name_buf[2] = '_';
11336 name_buf[3] = str[0];
11337 name_buf[4] = str[1];
11338 name_buf[5] = '>';
11339 name_buf[6] = NUL;
11340
11341 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11342 match = TRUE;
11343 }
11344 if (match)
11345 {
11346 if (loop == 0)
11347 num_term++;
11348 else
11349 (*file)[count++] = vim_strsave(name_buf);
11350 }
11351 }
11352
11353 /*
11354 * Check special key names.
11355 */
11356 regmatch->rm_ic = TRUE; /* ignore case here */
11357 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11358 {
11359 name_buf[0] = '<';
11360 STRCPY(name_buf + 1, str);
11361 STRCAT(name_buf, ">");
11362
11363 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11364 {
11365 if (loop == 0)
11366 num_term++;
11367 else
11368 (*file)[count++] = vim_strsave(name_buf);
11369 }
11370 }
11371 }
11372 if (loop == 0)
11373 {
11374 if (num_normal > 0)
11375 *num_file = num_normal;
11376 else if (num_term > 0)
11377 *num_file = num_term;
11378 else
11379 return OK;
11380 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11381 if (*file == NULL)
11382 {
11383 *file = (char_u **)"";
11384 return FAIL;
11385 }
11386 }
11387 }
11388 return OK;
11389}
11390
11391 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011392ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011393{
11394 char_u *var = NULL; /* init for GCC */
11395 char_u *buf;
11396
11397 *num_file = 0;
11398 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11399 if (*file == NULL)
11400 return FAIL;
11401
11402 /*
11403 * For a terminal key code expand_option_idx is < 0.
11404 */
11405 if (expand_option_idx < 0)
11406 {
11407 var = find_termcode(expand_option_name + 2);
11408 if (var == NULL)
11409 expand_option_idx = findoption(expand_option_name);
11410 }
11411
11412 if (expand_option_idx >= 0)
11413 {
11414 /* put string of option value in NameBuff */
11415 option_value2string(&options[expand_option_idx], expand_option_flags);
11416 var = NameBuff;
11417 }
11418 else if (var == NULL)
11419 var = (char_u *)"";
11420
11421 /* A backslash is required before some characters. This is the reverse of
11422 * what happens in do_set(). */
11423 buf = vim_strsave_escaped(var, escape_chars);
11424
11425 if (buf == NULL)
11426 {
11427 vim_free(*file);
11428 *file = NULL;
11429 return FAIL;
11430 }
11431
11432#ifdef BACKSLASH_IN_FILENAME
11433 /* For MS-Windows et al. we don't double backslashes at the start and
11434 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011435 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011436 if (var[0] == '\\' && var[1] == '\\'
11437 && expand_option_idx >= 0
11438 && (options[expand_option_idx].flags & P_EXPAND)
11439 && vim_isfilec(var[2])
11440 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011441 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011442#endif
11443
11444 *file[0] = buf;
11445 *num_file = 1;
11446 return OK;
11447}
11448#endif
11449
11450/*
11451 * Get the value for the numeric or string option *opp in a nice format into
11452 * NameBuff[]. Must not be called with a hidden option!
11453 */
11454 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011455option_value2string(
11456 struct vimoption *opp,
11457 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011458{
11459 char_u *varp;
11460
11461 varp = get_varp_scope(opp, opt_flags);
11462
11463 if (opp->flags & P_NUM)
11464 {
11465 long wc = 0;
11466
11467 if (wc_use_keyname(varp, &wc))
11468 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11469 else if (wc != 0)
11470 STRCPY(NameBuff, transchar((int)wc));
11471 else
11472 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11473 }
11474 else /* P_STRING */
11475 {
11476 varp = *(char_u **)(varp);
11477 if (varp == NULL) /* just in case */
11478 NameBuff[0] = NUL;
11479#ifdef FEAT_CRYPT
11480 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011481 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011482 STRCPY(NameBuff, "*****");
11483#endif
11484 else if (opp->flags & P_EXPAND)
11485 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11486 /* Translate 'pastetoggle' into special key names */
11487 else if ((char_u **)opp->var == &p_pt)
11488 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11489 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011490 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491 }
11492}
11493
11494/*
11495 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11496 * printed as a keyname.
11497 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11498 */
11499 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011500wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011501{
11502 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11503 {
11504 *wcp = *(long *)varp;
11505 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11506 return TRUE;
11507 }
11508 return FALSE;
11509}
11510
Bram Moolenaar01615492015-02-03 13:00:38 +010011511#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011512/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011513 * Any character has an equivalent 'langmap' character. This is used for
11514 * keyboards that have a special language mode that sends characters above
11515 * 128 (although other characters can be translated too). The "to" field is a
11516 * Vim command character. This avoids having to switch the keyboard back to
11517 * ASCII mode when leaving Insert mode.
11518 *
11519 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11520 * commands.
11521 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11522 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11523 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011524 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011525# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011526/*
11527 * With multi-byte support use growarray for 'langmap' chars >= 256
11528 */
11529typedef struct
11530{
11531 int from;
11532 int to;
11533} langmap_entry_T;
11534
11535static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011536static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011537
11538/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011539 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11540 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011541 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011542 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011543langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011544{
11545 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011546 int a = 0;
11547 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011548
11549 /* Do a binary search for an existing entry. */
11550 while (a != b)
11551 {
11552 int i = (a + b) / 2;
11553 int d = entries[i].from - from;
11554
11555 if (d == 0)
11556 {
11557 entries[i].to = to;
11558 return;
11559 }
11560 if (d < 0)
11561 a = i + 1;
11562 else
11563 b = i;
11564 }
11565
11566 if (ga_grow(&langmap_mapga, 1) != OK)
11567 return; /* out of memory */
11568
11569 /* insert new entry at position "a" */
11570 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11571 mch_memmove(entries + 1, entries,
11572 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11573 ++langmap_mapga.ga_len;
11574 entries[0].from = from;
11575 entries[0].to = to;
11576}
11577
11578/*
11579 * Apply 'langmap' to multi-byte character "c" and return the result.
11580 */
11581 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011582langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011583{
11584 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11585 int a = 0;
11586 int b = langmap_mapga.ga_len;
11587
11588 while (a != b)
11589 {
11590 int i = (a + b) / 2;
11591 int d = entries[i].from - c;
11592
11593 if (d == 0)
11594 return entries[i].to; /* found matching entry */
11595 if (d < 0)
11596 a = i + 1;
11597 else
11598 b = i;
11599 }
11600 return c; /* no entry found, return "c" unmodified */
11601}
11602# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011603
11604 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011605langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011606{
11607 int i;
11608
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011609 for (i = 0; i < 256; i++)
11610 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11611# ifdef FEAT_MBYTE
11612 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11613# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011614}
11615
11616/*
11617 * Called when langmap option is set; the language map can be
11618 * changed at any time!
11619 */
11620 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011621langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622{
11623 char_u *p;
11624 char_u *p2;
11625 int from, to;
11626
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011627#ifdef FEAT_MBYTE
11628 ga_clear(&langmap_mapga); /* clear the previous map first */
11629#endif
11630 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011631
11632 for (p = p_langmap; p[0] != NUL; )
11633 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011634 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11635 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011636 {
11637 if (p2[0] == '\\' && p2[1] != NUL)
11638 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011639 }
11640 if (p2[0] == ';')
11641 ++p2; /* abcd;ABCD form, p2 points to A */
11642 else
11643 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11644 while (p[0])
11645 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011646 if (p[0] == ',')
11647 {
11648 ++p;
11649 break;
11650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011651 if (p[0] == '\\' && p[1] != NUL)
11652 ++p;
11653#ifdef FEAT_MBYTE
11654 from = (*mb_ptr2char)(p);
11655#else
11656 from = p[0];
11657#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011658 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011659 if (p2 == NULL)
11660 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011661 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011662 if (p[0] != ',')
11663 {
11664 if (p[0] == '\\')
11665 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011666#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011667 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011668#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011669 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011670#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011671 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011672 }
11673 else
11674 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011675 if (p2[0] != ',')
11676 {
11677 if (p2[0] == '\\')
11678 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011679#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011680 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011681#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011682 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011683#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011684 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011685 }
11686 if (to == NUL)
11687 {
11688 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11689 transchar(from));
11690 return;
11691 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011692
11693#ifdef FEAT_MBYTE
11694 if (from >= 256)
11695 langmap_set_entry(from, to);
11696 else
11697#endif
11698 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011699
11700 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011701 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011702 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011703 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011704 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011705 if (*p == ';')
11706 {
11707 p = p2;
11708 if (p[0] != NUL)
11709 {
11710 if (p[0] != ',')
11711 {
11712 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11713 return;
11714 }
11715 ++p;
11716 }
11717 break;
11718 }
11719 }
11720 }
11721 }
11722}
11723#endif
11724
11725/*
11726 * Return TRUE if format option 'x' is in effect.
11727 * Take care of no formatting when 'paste' is set.
11728 */
11729 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011730has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731{
11732 if (p_paste)
11733 return FALSE;
11734 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11735}
11736
11737/*
11738 * Return TRUE if "x" is present in 'shortmess' option, or
11739 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11740 */
11741 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011742shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011743{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011744 return p_shm != NULL &&
11745 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746 || (vim_strchr(p_shm, 'a') != NULL
11747 && vim_strchr((char_u *)SHM_A, x) != NULL));
11748}
11749
11750/*
11751 * paste_option_changed() - Called after p_paste was set or reset.
11752 */
11753 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011754paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011755{
11756 static int old_p_paste = FALSE;
11757 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011758 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011759#ifdef FEAT_CMDL_INFO
11760 static int save_ru = 0;
11761#endif
11762#ifdef FEAT_RIGHTLEFT
11763 static int save_ri = 0;
11764 static int save_hkmap = 0;
11765#endif
11766 buf_T *buf;
11767
11768 if (p_paste)
11769 {
11770 /*
11771 * Paste switched from off to on.
11772 * Save the current values, so they can be restored later.
11773 */
11774 if (!old_p_paste)
11775 {
11776 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011777 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011778 {
11779 buf->b_p_tw_nopaste = buf->b_p_tw;
11780 buf->b_p_wm_nopaste = buf->b_p_wm;
11781 buf->b_p_sts_nopaste = buf->b_p_sts;
11782 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011783 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784 }
11785
11786 /* save global options */
11787 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011788 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011789#ifdef FEAT_CMDL_INFO
11790 save_ru = p_ru;
11791#endif
11792#ifdef FEAT_RIGHTLEFT
11793 save_ri = p_ri;
11794 save_hkmap = p_hkmap;
11795#endif
11796 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011797 p_ai_nopaste = p_ai;
11798 p_et_nopaste = p_et;
11799 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011800 p_tw_nopaste = p_tw;
11801 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802 }
11803
11804 /*
11805 * Always set the option values, also when 'paste' is set when it is
11806 * already on.
11807 */
11808 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011809 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011810 {
11811 buf->b_p_tw = 0; /* textwidth is 0 */
11812 buf->b_p_wm = 0; /* wrapmargin is 0 */
11813 buf->b_p_sts = 0; /* softtabstop is 0 */
11814 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011815 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816 }
11817
11818 /* set global options */
11819 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011820 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011821#ifdef FEAT_CMDL_INFO
11822# ifdef FEAT_WINDOWS
11823 if (p_ru)
11824 status_redraw_all(); /* redraw to remove the ruler */
11825# endif
11826 p_ru = 0; /* no ruler */
11827#endif
11828#ifdef FEAT_RIGHTLEFT
11829 p_ri = 0; /* no reverse insert */
11830 p_hkmap = 0; /* no Hebrew keyboard */
11831#endif
11832 /* set global values for local buffer options */
11833 p_tw = 0;
11834 p_wm = 0;
11835 p_sts = 0;
11836 p_ai = 0;
11837 }
11838
11839 /*
11840 * Paste switched from on to off: Restore saved values.
11841 */
11842 else if (old_p_paste)
11843 {
11844 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011845 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011846 {
11847 buf->b_p_tw = buf->b_p_tw_nopaste;
11848 buf->b_p_wm = buf->b_p_wm_nopaste;
11849 buf->b_p_sts = buf->b_p_sts_nopaste;
11850 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011851 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011852 }
11853
11854 /* restore global options */
11855 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011856 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011857#ifdef FEAT_CMDL_INFO
11858# ifdef FEAT_WINDOWS
11859 if (p_ru != save_ru)
11860 status_redraw_all(); /* redraw to draw the ruler */
11861# endif
11862 p_ru = save_ru;
11863#endif
11864#ifdef FEAT_RIGHTLEFT
11865 p_ri = save_ri;
11866 p_hkmap = save_hkmap;
11867#endif
11868 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011869 p_ai = p_ai_nopaste;
11870 p_et = p_et_nopaste;
11871 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011872 p_tw = p_tw_nopaste;
11873 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011874 }
11875
11876 old_p_paste = p_paste;
11877}
11878
11879/*
11880 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11881 *
11882 * Reset 'compatible' and set the values for options that didn't get set yet
11883 * to the Vim defaults.
11884 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011885 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011886 */
11887 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011888vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011890 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011891 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011892 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893
11894 if (!option_was_set((char_u *)"cp"))
11895 {
11896 p_cp = FALSE;
11897 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11898 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11899 set_option_default(opt_idx, OPT_FREE, FALSE);
11900 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011901 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011903
11904 if (fname != NULL)
11905 {
11906 p = vim_getenv(envname, &dofree);
11907 if (p == NULL)
11908 {
11909 /* Set $MYVIMRC to the first vimrc file found. */
11910 p = FullName_save(fname, FALSE);
11911 if (p != NULL)
11912 {
11913 vim_setenv(envname, p);
11914 vim_free(p);
11915 }
11916 }
11917 else if (dofree)
11918 vim_free(p);
11919 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011920}
11921
11922/*
11923 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
11924 */
11925 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011926change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011927{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011928 int opt_idx;
11929
Bram Moolenaar071d4272004-06-13 20:20:40 +000011930 if (p_cp != on)
11931 {
11932 p_cp = on;
11933 compatible_set();
11934 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011935 opt_idx = findoption((char_u *)"cp");
11936 if (opt_idx >= 0)
11937 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011938}
11939
11940/*
11941 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020011942 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011943 */
11944 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011945option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011946{
11947 int idx;
11948
11949 idx = findoption(name);
11950 if (idx < 0) /* unknown option */
11951 return FALSE;
11952 if (options[idx].flags & P_WAS_SET)
11953 return TRUE;
11954 return FALSE;
11955}
11956
11957/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011958 * Reset the flag indicating option "name" was set.
11959 */
11960 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011961reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010011962{
11963 int idx = findoption(name);
11964
11965 if (idx >= 0)
11966 options[idx].flags &= ~P_WAS_SET;
11967}
11968
11969/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011970 * compatible_set() - Called when 'compatible' has been set or unset.
11971 *
11972 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
11973 * flag) to a Vi compatible value.
11974 * When 'compatible' is unset: Set all options that have a different default
11975 * for Vim (without the P_VI_DEF flag) to that default.
11976 */
11977 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011978compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011979{
11980 int opt_idx;
11981
11982 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11983 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
11984 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
11985 set_option_default(opt_idx, OPT_FREE, p_cp);
11986 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011987 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011988}
11989
11990#ifdef FEAT_LINEBREAK
11991
11992# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
11993 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000011994 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000011995# endif
11996
11997/*
11998 * fill_breakat_flags() -- called when 'breakat' changes value.
11999 */
12000 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012001fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012003 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012004 int i;
12005
12006 for (i = 0; i < 256; i++)
12007 breakat_flags[i] = FALSE;
12008
12009 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012010 for (p = p_breakat; *p; p++)
12011 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012}
12013
12014# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012015 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012016# endif
12017
12018#endif
12019
12020/*
12021 * Check an option that can be a range of string values.
12022 *
12023 * Return OK for correct value, FAIL otherwise.
12024 * Empty is always OK.
12025 */
12026 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012027check_opt_strings(
12028 char_u *val,
12029 char **values,
12030 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031{
12032 return opt_strings_flags(val, values, NULL, list);
12033}
12034
12035/*
12036 * Handle an option that can be a range of string values.
12037 * Set a flag in "*flagp" for each string present.
12038 *
12039 * Return OK for correct value, FAIL otherwise.
12040 * Empty is always OK.
12041 */
12042 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012043opt_strings_flags(
12044 char_u *val, /* new value */
12045 char **values, /* array of valid string values */
12046 unsigned *flagp,
12047 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012048{
12049 int i;
12050 int len;
12051 unsigned new_flags = 0;
12052
12053 while (*val)
12054 {
12055 for (i = 0; ; ++i)
12056 {
12057 if (values[i] == NULL) /* val not found in values[] */
12058 return FAIL;
12059
12060 len = (int)STRLEN(values[i]);
12061 if (STRNCMP(values[i], val, len) == 0
12062 && ((list && val[len] == ',') || val[len] == NUL))
12063 {
12064 val += len + (val[len] == ',');
12065 new_flags |= (1 << i);
12066 break; /* check next item in val list */
12067 }
12068 }
12069 }
12070 if (flagp != NULL)
12071 *flagp = new_flags;
12072
12073 return OK;
12074}
12075
12076/*
12077 * Read the 'wildmode' option, fill wim_flags[].
12078 */
12079 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012080check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081{
12082 char_u new_wim_flags[4];
12083 char_u *p;
12084 int i;
12085 int idx = 0;
12086
12087 for (i = 0; i < 4; ++i)
12088 new_wim_flags[i] = 0;
12089
12090 for (p = p_wim; *p; ++p)
12091 {
12092 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12093 ;
12094 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12095 return FAIL;
12096 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12097 new_wim_flags[idx] |= WIM_LONGEST;
12098 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12099 new_wim_flags[idx] |= WIM_FULL;
12100 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12101 new_wim_flags[idx] |= WIM_LIST;
12102 else
12103 return FAIL;
12104 p += i;
12105 if (*p == NUL)
12106 break;
12107 if (*p == ',')
12108 {
12109 if (idx == 3)
12110 return FAIL;
12111 ++idx;
12112 }
12113 }
12114
12115 /* fill remaining entries with last flag */
12116 while (idx < 3)
12117 {
12118 new_wim_flags[idx + 1] = new_wim_flags[idx];
12119 ++idx;
12120 }
12121
12122 /* only when there are no errors, wim_flags[] is changed */
12123 for (i = 0; i < 4; ++i)
12124 wim_flags[i] = new_wim_flags[i];
12125 return OK;
12126}
12127
12128/*
12129 * Check if backspacing over something is allowed.
12130 */
12131 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012132can_bs(
12133 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012134{
12135 switch (*p_bs)
12136 {
12137 case '2': return TRUE;
12138 case '1': return (what != BS_START);
12139 case '0': return FALSE;
12140 }
12141 return vim_strchr(p_bs, what) != NULL;
12142}
12143
12144/*
12145 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12146 * the file must be considered changed when the value is different.
12147 */
12148 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012149save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012150{
12151 buf->b_start_ffc = *buf->b_p_ff;
12152 buf->b_start_eol = buf->b_p_eol;
12153#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012154 buf->b_start_bomb = buf->b_p_bomb;
12155
Bram Moolenaar071d4272004-06-13 20:20:40 +000012156 /* Only use free/alloc when necessary, they take time. */
12157 if (buf->b_start_fenc == NULL
12158 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12159 {
12160 vim_free(buf->b_start_fenc);
12161 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12162 }
12163#endif
12164}
12165
12166/*
12167 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12168 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012169 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12170 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012171 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012172 * When "ignore_empty" is true don't consider a new, empty buffer to be
12173 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012174 */
12175 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012176file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012177{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012178 /* In a buffer that was never loaded the options are not valid. */
12179 if (buf->b_flags & BF_NEVERLOADED)
12180 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012181 if (ignore_empty
12182 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183 && buf->b_ml.ml_line_count == 1
12184 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12185 return FALSE;
12186 if (buf->b_start_ffc != *buf->b_p_ff)
12187 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012188 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012189 return TRUE;
12190#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012191 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12192 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193 if (buf->b_start_fenc == NULL)
12194 return (*buf->b_p_fenc != NUL);
12195 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12196#else
12197 return FALSE;
12198#endif
12199}
12200
12201/*
12202 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12203 */
12204 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012205check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012206{
12207 return check_opt_strings(p, p_ff_values, FALSE);
12208}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012209
12210/*
12211 * Return the effective shiftwidth value for current buffer, using the
12212 * 'tabstop' value when 'shiftwidth' is zero.
12213 */
12214 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012215get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012216{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012217 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012218}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012219
12220/*
12221 * Return the effective softtabstop value for the current buffer, using the
12222 * 'tabstop' value when 'softtabstop' is negative.
12223 */
12224 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012225get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012226{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012227 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012228}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012229
12230/*
12231 * Check matchpairs option for "*initc".
12232 * If there is a match set "*initc" to the matching character and "*findc" to
12233 * the opposite character. Set "*backwards" to the direction.
12234 * When "switchit" is TRUE swap the direction.
12235 */
12236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012237find_mps_values(
12238 int *initc,
12239 int *findc,
12240 int *backwards,
12241 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012242{
12243 char_u *ptr;
12244
12245 ptr = curbuf->b_p_mps;
12246 while (*ptr != NUL)
12247 {
12248#ifdef FEAT_MBYTE
12249 if (has_mbyte)
12250 {
12251 char_u *prev;
12252
12253 if (mb_ptr2char(ptr) == *initc)
12254 {
12255 if (switchit)
12256 {
12257 *findc = *initc;
12258 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12259 *backwards = TRUE;
12260 }
12261 else
12262 {
12263 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12264 *backwards = FALSE;
12265 }
12266 return;
12267 }
12268 prev = ptr;
12269 ptr += mb_ptr2len(ptr) + 1;
12270 if (mb_ptr2char(ptr) == *initc)
12271 {
12272 if (switchit)
12273 {
12274 *findc = *initc;
12275 *initc = mb_ptr2char(prev);
12276 *backwards = FALSE;
12277 }
12278 else
12279 {
12280 *findc = mb_ptr2char(prev);
12281 *backwards = TRUE;
12282 }
12283 return;
12284 }
12285 ptr += mb_ptr2len(ptr);
12286 }
12287 else
12288#endif
12289 {
12290 if (*ptr == *initc)
12291 {
12292 if (switchit)
12293 {
12294 *backwards = TRUE;
12295 *findc = *initc;
12296 *initc = ptr[2];
12297 }
12298 else
12299 {
12300 *backwards = FALSE;
12301 *findc = ptr[2];
12302 }
12303 return;
12304 }
12305 ptr += 2;
12306 if (*ptr == *initc)
12307 {
12308 if (switchit)
12309 {
12310 *backwards = FALSE;
12311 *findc = *initc;
12312 *initc = ptr[-2];
12313 }
12314 else
12315 {
12316 *backwards = TRUE;
12317 *findc = ptr[-2];
12318 }
12319 return;
12320 }
12321 ++ptr;
12322 }
12323 if (*ptr == ',')
12324 ++ptr;
12325 }
12326}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012327
12328#if defined(FEAT_LINEBREAK) || defined(PROTO)
12329/*
12330 * This is called when 'breakindentopt' is changed and when a window is
12331 * initialized.
12332 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012333 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012334briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012335{
12336 char_u *p;
12337 int bri_shift = 0;
12338 long bri_min = 20;
12339 int bri_sbr = FALSE;
12340
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012341 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012342 while (*p != NUL)
12343 {
12344 if (STRNCMP(p, "shift:", 6) == 0
12345 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12346 {
12347 p += 6;
12348 bri_shift = getdigits(&p);
12349 }
12350 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12351 {
12352 p += 4;
12353 bri_min = getdigits(&p);
12354 }
12355 else if (STRNCMP(p, "sbr", 3) == 0)
12356 {
12357 p += 3;
12358 bri_sbr = TRUE;
12359 }
12360 if (*p != ',' && *p != NUL)
12361 return FAIL;
12362 if (*p == ',')
12363 ++p;
12364 }
12365
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012366 wp->w_p_brishift = bri_shift;
12367 wp->w_p_brimin = bri_min;
12368 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012369
12370 return OK;
12371}
12372#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012373
12374/*
12375 * Get the local or global value of 'backupcopy'.
12376 */
12377 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012378get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012379{
12380 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12381}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012382
12383#if defined(FEAT_SIGNS) || defined(PROTO)
12384/*
12385 * Return TRUE when window "wp" has a column to draw signs in.
12386 */
12387 int
12388signcolumn_on(win_T *wp)
12389{
12390 if (*wp->w_p_scl == 'n')
12391 return FALSE;
12392 if (*wp->w_p_scl == 'y')
12393 return TRUE;
12394 return (wp->w_buffer->b_signlist != NULL
12395# ifdef FEAT_NETBEANS_INTG
12396 || wp->w_buffer->b_has_sign_column
12397# endif
12398 );
12399}
12400#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012401
12402#if defined(FEAT_EVAL) || defined(PROTO)
12403/*
12404 * Get window or buffer local options.
12405 */
12406 dict_T *
12407get_winbuf_options(int bufopt)
12408{
12409 dict_T *d;
12410 int opt_idx;
12411
12412 d = dict_alloc();
12413 if (d == NULL)
12414 return NULL;
12415
12416 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12417 {
12418 struct vimoption *opt = &options[opt_idx];
12419
12420 if ((bufopt && (opt->indir & PV_BUF))
12421 || (!bufopt && (opt->indir & PV_WIN)))
12422 {
12423 char_u *varp = get_varp(opt);
12424
12425 if (varp != NULL)
12426 {
12427 if (opt->flags & P_STRING)
12428 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012429 else if (opt->flags & P_NUM)
12430 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012431 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012432 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012433 }
12434 }
12435 }
12436
12437 return d;
12438}
12439#endif