blob: 4ba436341d52b27708120773751c9debe3df106f [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 Moolenaarf42dd3c2017-01-28 16:06:38 +0100482/* Default python version for pyx* commands */
483#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
484# define DEFAULT_PYTHON_VER 0
485#elif defined(FEAT_PYTHON3)
486# define DEFAULT_PYTHON_VER 3
487#elif defined(FEAT_PYTHON)
488# define DEFAULT_PYTHON_VER 2
489#else
490# define DEFAULT_PYTHON_VER 0
491#endif
492
Bram Moolenaar071d4272004-06-13 20:20:40 +0000493/*
494 * options[] is initialized here.
495 * The order of the options MUST be alphabetic for ":set all" and findoption().
496 * All option names MUST start with a lowercase letter (for findoption()).
497 * Exception: "t_" options are at the end.
498 * The options with a NULL variable are 'hidden': a set command for them is
499 * ignored and they are not printed.
500 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100501static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200503 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504#ifdef FEAT_RIGHTLEFT
505 (char_u *)&p_aleph, PV_NONE,
506#else
507 (char_u *)NULL, PV_NONE,
508#endif
509 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100510#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511 (char_u *)128L,
512#else
513 (char_u *)224L,
514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000515 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
517#if defined(FEAT_GUI) && defined(MACOS_X)
518 (char_u *)&p_antialias, PV_NONE,
519 {(char_u *)FALSE, (char_u *)FALSE}
520#else
521 (char_u *)NULL, PV_NONE,
522 {(char_u *)FALSE, (char_u *)FALSE}
523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000524 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200525 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526#ifdef FEAT_ARABIC
527 (char_u *)VAR_WIN, PV_ARAB,
528#else
529 (char_u *)NULL, PV_NONE,
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
533#ifdef FEAT_ARABIC
534 (char_u *)&p_arshape, PV_NONE,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000538 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
540#ifdef FEAT_RIGHTLEFT
541 (char_u *)&p_ari, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
547#ifdef FEAT_FKMAP
548 (char_u *)&p_altkeymap, PV_NONE,
549#else
550 (char_u *)NULL, PV_NONE,
551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
554#if defined(FEAT_MBYTE)
555 (char_u *)&p_ambw, PV_NONE,
556 {(char_u *)"single", (char_u *)0L}
557#else
558 (char_u *)NULL, PV_NONE,
559 {(char_u *)0L, (char_u *)0L}
560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000562#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autochdir", "acd", P_BOOL|P_VI_DEF,
564 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566#endif
567 {"autoindent", "ai", P_BOOL|P_VI_DEF,
568 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autoprint", "ap", P_BOOL|P_VI_DEF,
571 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000574 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"autowrite", "aw", P_BOOL|P_VI_DEF,
577 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"autowriteall","awa", P_BOOL|P_VI_DEF,
580 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
583 (char_u *)&p_bg, PV_NONE,
584 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100585#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)"dark",
587#else
588 (char_u *)"light",
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
595 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200598 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599#ifdef UNIX
600 {(char_u *)"yes", (char_u *)"auto"}
601#else
602 {(char_u *)"auto", (char_u *)"auto"}
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200605 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
606 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000609 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610 (char_u *)&p_bex, PV_NONE,
611 {
612#ifdef VMS
613 (char_u *)"_",
614#else
615 (char_u *)"~",
616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200618 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_WILDIGN
620 (char_u *)&p_bsk, PV_NONE,
621 {(char_u *)"", (char_u *)0L}
622#else
623 (char_u *)NULL, PV_NONE,
624 {(char_u *)0L, (char_u *)0L}
625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627#ifdef FEAT_BEVAL
628 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
629 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000630 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
632 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000633 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000634# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000635 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000636 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000638# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639#endif
640 {"beautify", "bf", P_BOOL|P_VI_DEF,
641 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000642 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200643 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
644 (char_u *)&p_bo, PV_NONE,
645 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
647 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000648 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000650 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000651 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
653#ifdef FEAT_MBYTE
654 (char_u *)&p_bomb, PV_BOMB,
655#else
656 (char_u *)NULL, PV_NONE,
657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000658 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
660#ifdef FEAT_LINEBREAK
661 (char_u *)&p_breakat, PV_NONE,
662 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
663#else
664 (char_u *)NULL, PV_NONE,
665 {(char_u *)0L, (char_u *)0L}
666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000667 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200668 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
669#ifdef FEAT_LINEBREAK
670 (char_u *)VAR_WIN, PV_BRI,
671 {(char_u *)FALSE, (char_u *)0L}
672#else
673 (char_u *)NULL, PV_NONE,
674 {(char_u *)0L, (char_u *)0L}
675#endif
676 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200677 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
678 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200679#ifdef FEAT_LINEBREAK
680 (char_u *)VAR_WIN, PV_BRIOPT,
681 {(char_u *)"", (char_u *)NULL}
682#else
683 (char_u *)NULL, PV_NONE,
684 {(char_u *)"", (char_u *)NULL}
685#endif
686 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000687 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
688#ifdef FEAT_BROWSE
689 (char_u *)&p_bsdir, PV_NONE,
690 {(char_u *)"last", (char_u *)0L}
691#else
692 (char_u *)NULL, PV_NONE,
693 {(char_u *)0L, (char_u *)0L}
694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
697#if defined(FEAT_QUICKFIX)
698 (char_u *)&p_bh, PV_BH,
699 {(char_u *)"", (char_u *)0L}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)0L, (char_u *)0L}
703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
706 (char_u *)&p_bl, PV_BL,
707 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
710#if defined(FEAT_QUICKFIX)
711 (char_u *)&p_bt, PV_BT,
712 {(char_u *)"", (char_u *)0L}
713#else
714 (char_u *)NULL, PV_NONE,
715 {(char_u *)0L, (char_u *)0L}
716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200718 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000719#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 (char_u *)&p_cmp, PV_NONE,
721 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000722#else
723 (char_u *)NULL, PV_NONE,
724 {(char_u *)0L, (char_u *)0L}
725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
728#ifdef FEAT_SEARCHPATH
729 (char_u *)&p_cdpath, PV_NONE,
730 {(char_u *)",,", (char_u *)0L}
731#else
732 (char_u *)NULL, PV_NONE,
733 {(char_u *)0L, (char_u *)0L}
734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736 {"cedit", NULL, P_STRING,
737#ifdef FEAT_CMDWIN
738 (char_u *)&p_cedit, PV_NONE,
739 {(char_u *)"", (char_u *)CTRL_F_STR}
740#else
741 (char_u *)NULL, PV_NONE,
742 {(char_u *)0L, (char_u *)0L}
743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000744 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
746#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
747 (char_u *)&p_ccv, PV_NONE,
748 {(char_u *)"", (char_u *)0L}
749#else
750 (char_u *)NULL, PV_NONE,
751 {(char_u *)0L, (char_u *)0L}
752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
755#ifdef FEAT_CINDENT
756 (char_u *)&p_cin, PV_CIN,
757#else
758 (char_u *)NULL, PV_NONE,
759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000760 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200761 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762#ifdef FEAT_CINDENT
763 (char_u *)&p_cink, PV_CINK,
764 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
765#else
766 (char_u *)NULL, PV_NONE,
767 {(char_u *)0L, (char_u *)0L}
768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000769 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200770 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#ifdef FEAT_CINDENT
772 (char_u *)&p_cino, PV_CINO,
773#else
774 (char_u *)NULL, PV_NONE,
775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000776 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200777 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000778#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
779 (char_u *)&p_cinw, PV_CINW,
780 {(char_u *)"if,else,while,do,for,switch",
781 (char_u *)0L}
782#else
783 (char_u *)NULL, PV_NONE,
784 {(char_u *)0L, (char_u *)0L}
785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200787 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000788#ifdef FEAT_CLIPBOARD
789 (char_u *)&p_cb, PV_NONE,
790# ifdef FEAT_XCLIPBOARD
791 {(char_u *)"autoselect,exclude:cons\\|linux",
792 (char_u *)0L}
793# else
794 {(char_u *)"", (char_u *)0L}
795# endif
796#else
797 (char_u *)NULL, PV_NONE,
798 {(char_u *)"", (char_u *)0L}
799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000800 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
802 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000803 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
805#ifdef FEAT_CMDWIN
806 (char_u *)&p_cwh, PV_NONE,
807#else
808 (char_u *)NULL, PV_NONE,
809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000810 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200811 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200812#ifdef FEAT_SYN_HL
813 (char_u *)VAR_WIN, PV_CC,
814#else
815 (char_u *)NULL, PV_NONE,
816#endif
817 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
819 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000820 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200821 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
822 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823#ifdef FEAT_COMMENTS
824 (char_u *)&p_com, PV_COM,
825 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
826 (char_u *)0L}
827#else
828 (char_u *)NULL, PV_NONE,
829 {(char_u *)0L, (char_u *)0L}
830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200832 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833#ifdef FEAT_FOLDING
834 (char_u *)&p_cms, PV_CMS,
835 {(char_u *)"/*%s*/", (char_u *)0L}
836#else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000840 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000841 /* P_PRI_MKRC isn't needed here, optval_default()
842 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843 {"compatible", "cp", P_BOOL|P_RALL,
844 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200846 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847#ifdef FEAT_INS_EXPAND
848 (char_u *)&p_cpt, PV_CPT,
849 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
850#else
851 (char_u *)NULL, PV_NONE,
852 {(char_u *)0L, (char_u *)0L}
853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000854 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200855 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200856#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200857 (char_u *)VAR_WIN, PV_COCU,
858 {(char_u *)"", (char_u *)NULL}
859#else
860 (char_u *)NULL, PV_NONE,
861 {(char_u *)NULL, (char_u *)0L}
862#endif
863 SCRIPTID_INIT},
864 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
865#ifdef FEAT_CONCEAL
866 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200867#else
868 (char_u *)NULL, PV_NONE,
869#endif
870 {(char_u *)0L, (char_u *)0L}
871 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000872 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
873#ifdef FEAT_COMPL_FUNC
874 (char_u *)&p_cfu, PV_CFU,
875 {(char_u *)"", (char_u *)0L}
876#else
877 (char_u *)NULL, PV_NONE,
878 {(char_u *)0L, (char_u *)0L}
879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000880 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200881 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000882#ifdef FEAT_INS_EXPAND
883 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000884 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000885#else
886 (char_u *)NULL, PV_NONE,
887 {(char_u *)0L, (char_u *)0L}
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890 {"confirm", "cf", P_BOOL|P_VI_DEF,
891#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
892 (char_u *)&p_confirm, PV_NONE,
893#else
894 (char_u *)NULL, PV_NONE,
895#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000896 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000898 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000899 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
901 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
904 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
906 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200907 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200908#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200909 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200910 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200911#else
912 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200913 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200914#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200915 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
917#ifdef FEAT_CSCOPE
918 (char_u *)&p_cspc, PV_NONE,
919#else
920 (char_u *)NULL, PV_NONE,
921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000922 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000923 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
924#ifdef FEAT_CSCOPE
925 (char_u *)&p_csprg, PV_NONE,
926 {(char_u *)"cscope", (char_u *)0L}
927#else
928 (char_u *)NULL, PV_NONE,
929 {(char_u *)0L, (char_u *)0L}
930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000931 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200932 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000933#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
934 (char_u *)&p_csqf, PV_NONE,
935 {(char_u *)"", (char_u *)0L}
936#else
937 (char_u *)NULL, PV_NONE,
938 {(char_u *)0L, (char_u *)0L}
939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000940 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200941 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
942#ifdef FEAT_CSCOPE
943 (char_u *)&p_csre, PV_NONE,
944#else
945 (char_u *)NULL, PV_NONE,
946#endif
947 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
949#ifdef FEAT_CSCOPE
950 (char_u *)&p_cst, PV_NONE,
951#else
952 (char_u *)NULL, PV_NONE,
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
956#ifdef FEAT_CSCOPE
957 (char_u *)&p_csto, PV_NONE,
958#else
959 (char_u *)NULL, PV_NONE,
960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000961 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
963#ifdef FEAT_CSCOPE
964 (char_u *)&p_csverbose, PV_NONE,
965#else
966 (char_u *)NULL, PV_NONE,
967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200969 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
970#ifdef FEAT_CURSORBIND
971 (char_u *)VAR_WIN, PV_CRBIND,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000976 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
977#ifdef FEAT_SYN_HL
978 (char_u *)VAR_WIN, PV_CUC,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100983 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000984#ifdef FEAT_SYN_HL
985 (char_u *)VAR_WIN, PV_CUL,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000990 {"debug", NULL, P_STRING|P_VI_DEF,
991 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000992 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200993 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000995 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000996 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000997#else
998 (char_u *)NULL, PV_NONE,
999 {(char_u *)NULL, (char_u *)0L}
1000#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001001 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1003#ifdef FEAT_MBYTE
1004 (char_u *)&p_deco, PV_NONE,
1005#else
1006 (char_u *)NULL, PV_NONE,
1007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001009 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001011 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#else
1013 (char_u *)NULL, PV_NONE,
1014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001015 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1017#ifdef FEAT_DIFF
1018 (char_u *)VAR_WIN, PV_DIFF,
1019#else
1020 (char_u *)NULL, PV_NONE,
1021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001023 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1025 (char_u *)&p_dex, PV_NONE,
1026 {(char_u *)"", (char_u *)0L}
1027#else
1028 (char_u *)NULL, PV_NONE,
1029 {(char_u *)0L, (char_u *)0L}
1030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001031 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001032 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1033 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034#ifdef FEAT_DIFF
1035 (char_u *)&p_dip, PV_NONE,
1036 {(char_u *)"filler", (char_u *)NULL}
1037#else
1038 (char_u *)NULL, PV_NONE,
1039 {(char_u *)"", (char_u *)NULL}
1040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1043#ifdef FEAT_DIGRAPHS
1044 (char_u *)&p_dg, PV_NONE,
1045#else
1046 (char_u *)NULL, PV_NONE,
1047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001048 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001049 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1050 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001055 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001057#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 (char_u *)&p_ead, PV_NONE,
1059 {(char_u *)"both", (char_u *)0L}
1060#else
1061 (char_u *)NULL, PV_NONE,
1062 {(char_u *)NULL, (char_u *)0L}
1063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1066 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001068 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1069#if defined(FEAT_MBYTE)
1070 (char_u *)&p_emoji, PV_NONE,
1071 {(char_u *)TRUE, (char_u *)0L}
1072#else
1073 (char_u *)NULL, PV_NONE,
1074 {(char_u *)0L, (char_u *)0L}
1075#endif
1076 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001077 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078#ifdef FEAT_MBYTE
1079 (char_u *)&p_enc, PV_NONE,
1080 {(char_u *)ENC_DFLT, (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)0L, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1087 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1090 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001091 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001093 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1096 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1099#ifdef FEAT_QUICKFIX
1100 (char_u *)&p_ef, PV_NONE,
1101 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)NULL, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001107 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001109 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111#else
1112 (char_u *)NULL, PV_NONE,
1113 {(char_u *)NULL, (char_u *)0L}
1114#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"esckeys", "ek", P_BOOL|P_VIM,
1117 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001119 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120#ifdef FEAT_AUTOCMD
1121 (char_u *)&p_ei, PV_NONE,
1122#else
1123 (char_u *)NULL, PV_NONE,
1124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1127 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1130 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001132 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1133 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134#ifdef FEAT_MBYTE
1135 (char_u *)&p_fenc, PV_FENC,
1136 {(char_u *)"", (char_u *)0L}
1137#else
1138 (char_u *)NULL, PV_NONE,
1139 {(char_u *)0L, (char_u *)0L}
1140#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001141 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001142 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143#ifdef FEAT_MBYTE
1144 (char_u *)&p_fencs, PV_NONE,
1145 {(char_u *)"ucs-bom", (char_u *)0L}
1146#else
1147 (char_u *)NULL, PV_NONE,
1148 {(char_u *)0L, (char_u *)0L}
1149#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001151 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1152 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001154 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001155 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1158 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001159 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1160 (char_u *)&p_fic, PV_NONE,
1161 {
1162#ifdef CASE_INSENSITIVE_FILENAME
1163 (char_u *)TRUE,
1164#else
1165 (char_u *)FALSE,
1166#endif
1167 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001168 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169#ifdef FEAT_AUTOCMD
1170 (char_u *)&p_ft, PV_FT,
1171 {(char_u *)"", (char_u *)0L}
1172#else
1173 (char_u *)NULL, PV_NONE,
1174 {(char_u *)0L, (char_u *)0L}
1175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001176 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001177 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1179 (char_u *)&p_fcs, PV_NONE,
1180 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1181#else
1182 (char_u *)NULL, PV_NONE,
1183 {(char_u *)"", (char_u *)0L}
1184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001186 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1187 (char_u *)&p_fixeol, PV_FIXEOL,
1188 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1190#ifdef FEAT_FKMAP
1191 (char_u *)&p_fkmap, PV_NONE,
1192#else
1193 (char_u *)NULL, PV_NONE,
1194#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001195 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {"flash", "fl", P_BOOL|P_VI_DEF,
1197 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001200 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001202 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1204 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001205 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001206 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1207 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001208 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1210# ifdef FEAT_EVAL
1211 (char_u *)VAR_WIN, PV_FDE,
1212 {(char_u *)"0", (char_u *)NULL}
1213# else
1214 (char_u *)NULL, PV_NONE,
1215 {(char_u *)NULL, (char_u *)0L}
1216# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1219 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001224 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001228 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 {(char_u *)"{{{,}}}", (char_u *)NULL}
1231 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1233 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001234 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1236 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1239 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001240 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001241 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242 (char_u *)&p_fdo, PV_NONE,
1243 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1246# ifdef FEAT_EVAL
1247 (char_u *)VAR_WIN, PV_FDT,
1248 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001249# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 (char_u *)NULL, PV_NONE,
1251 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001252# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001253 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001255 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001256#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001257 (char_u *)&p_fex, PV_FEX,
1258 {(char_u *)"", (char_u *)0L}
1259#else
1260 (char_u *)NULL, PV_NONE,
1261 {(char_u *)0L, (char_u *)0L}
1262#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1265 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1267 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001268 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1269 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001270 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1271 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001272 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001273 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001274 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001275 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1276#ifdef HAVE_FSYNC
1277 (char_u *)&p_fs, PV_NONE,
1278 {(char_u *)TRUE, (char_u *)0L}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)FALSE, (char_u *)0L}
1282#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001283 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1285 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001286 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287 {"graphic", "gr", P_BOOL|P_VI_DEF,
1288 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001289 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001290 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291#ifdef FEAT_QUICKFIX
1292 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001293 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294#else
1295 (char_u *)NULL, PV_NONE,
1296 {(char_u *)NULL, (char_u *)0L}
1297#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001298 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1300#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001301 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 {
1303# ifdef WIN3264
1304 /* may be changed to "grep -n" in os_win32.c */
1305 (char_u *)"findstr /n",
1306# else
1307# ifdef UNIX
1308 /* Add an extra file name so that grep will always
1309 * insert a file name in the match line. */
1310 (char_u *)"grep -n $* /dev/null",
1311# else
1312# ifdef VMS
1313 (char_u *)"SEARCH/NUMBERS ",
1314# else
1315 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001316# endif
1317# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001319 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320#else
1321 (char_u *)NULL, PV_NONE,
1322 {(char_u *)NULL, (char_u *)0L}
1323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001324 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001325 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001326#ifdef CURSOR_SHAPE
1327 (char_u *)&p_guicursor, PV_NONE,
1328 {
1329# ifdef FEAT_GUI
1330 (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 +01001331# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1333# endif
1334 (char_u *)0L}
1335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001339 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001340 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341#ifdef FEAT_GUI
1342 (char_u *)&p_guifont, PV_NONE,
1343 {(char_u *)"", (char_u *)0L}
1344#else
1345 (char_u *)NULL, PV_NONE,
1346 {(char_u *)NULL, (char_u *)0L}
1347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001349 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1351 (char_u *)&p_guifontset, PV_NONE,
1352 {(char_u *)"", (char_u *)0L}
1353#else
1354 (char_u *)NULL, PV_NONE,
1355 {(char_u *)NULL, (char_u *)0L}
1356#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001357 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001358 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1360 (char_u *)&p_guifontwide, PV_NONE,
1361 {(char_u *)"", (char_u *)0L}
1362#else
1363 (char_u *)NULL, PV_NONE,
1364 {(char_u *)NULL, (char_u *)0L}
1365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001368#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 (char_u *)&p_ghr, PV_NONE,
1370#else
1371 (char_u *)NULL, PV_NONE,
1372#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001374 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001375#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 (char_u *)&p_go, PV_NONE,
1377# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001378 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001380 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381# endif
1382#else
1383 (char_u *)NULL, PV_NONE,
1384 {(char_u *)NULL, (char_u *)0L}
1385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001386 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387 {"guipty", NULL, P_BOOL|P_VI_DEF,
1388#if defined(FEAT_GUI)
1389 (char_u *)&p_guipty, PV_NONE,
1390#else
1391 (char_u *)NULL, PV_NONE,
1392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001393 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001394 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001395#if defined(FEAT_GUI_TABLINE)
1396 (char_u *)&p_gtl, PV_NONE,
1397 {(char_u *)"", (char_u *)0L}
1398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001403 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001404#if defined(FEAT_GUI_TABLINE)
1405 (char_u *)&p_gtt, PV_NONE,
1406 {(char_u *)"", (char_u *)0L}
1407#else
1408 (char_u *)NULL, PV_NONE,
1409 {(char_u *)NULL, (char_u *)0L}
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1413 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1416 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1418 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 {"helpheight", "hh", P_NUM|P_VI_DEF,
1420#ifdef FEAT_WINDOWS
1421 (char_u *)&p_hh, PV_NONE,
1422#else
1423 (char_u *)NULL, PV_NONE,
1424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001425 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001426 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427#ifdef FEAT_MULTI_LANG
1428 (char_u *)&p_hlg, PV_NONE,
1429 {(char_u *)"", (char_u *)0L}
1430#else
1431 (char_u *)NULL, PV_NONE,
1432 {(char_u *)0L, (char_u *)0L}
1433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"hidden", "hid", P_BOOL|P_VI_DEF,
1436 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001438 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001439 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001440 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1441 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"history", "hi", P_NUM|P_VIM,
1443 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001444 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1446#ifdef FEAT_RIGHTLEFT
1447 (char_u *)&p_hkmap, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1453#ifdef FEAT_RIGHTLEFT
1454 (char_u *)&p_hkmapp, PV_NONE,
1455#else
1456 (char_u *)NULL, PV_NONE,
1457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1460 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"icon", NULL, P_BOOL|P_VI_DEF,
1463#ifdef FEAT_TITLE
1464 (char_u *)&p_icon, PV_NONE,
1465#else
1466 (char_u *)NULL, PV_NONE,
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"iconstring", NULL, P_STRING|P_VI_DEF,
1470#ifdef FEAT_TITLE
1471 (char_u *)&p_iconstring, PV_NONE,
1472#else
1473 (char_u *)NULL, PV_NONE,
1474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1477 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001479 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1480# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1481 (char_u *)&p_imaf, PV_NONE,
1482 {(char_u *)"", (char_u *)NULL}
1483# else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)NULL, (char_u *)0L}
1486# endif
1487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001489#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 (char_u *)&p_imak, PV_NONE,
1491#else
1492 (char_u *)NULL, PV_NONE,
1493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001494 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1496#ifdef USE_IM_CONTROL
1497 (char_u *)&p_imcmdline, PV_NONE,
1498#else
1499 (char_u *)NULL, PV_NONE,
1500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001501 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1503#ifdef USE_IM_CONTROL
1504 (char_u *)&p_imdisable, PV_NONE,
1505#else
1506 (char_u *)NULL, PV_NONE,
1507#endif
1508#ifdef __sgi
1509 {(char_u *)TRUE, (char_u *)0L}
1510#else
1511 {(char_u *)FALSE, (char_u *)0L}
1512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001513 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"iminsert", "imi", P_NUM|P_VI_DEF,
1515 (char_u *)&p_iminsert, PV_IMI,
1516#ifdef B_IMODE_IM
1517 {(char_u *)B_IMODE_IM, (char_u *)0L}
1518#else
1519 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"imsearch", "ims", P_NUM|P_VI_DEF,
1523 (char_u *)&p_imsearch, PV_IMS,
1524#ifdef B_IMODE_IM
1525 {(char_u *)B_IMODE_IM, (char_u *)0L}
1526#else
1527 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001530 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001531# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1532 (char_u *)&p_imsf, PV_NONE,
1533 {(char_u *)"", (char_u *)NULL}
1534# else
1535 (char_u *)NULL, PV_NONE,
1536 {(char_u *)NULL, (char_u *)0L}
1537# endif
1538 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001539 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1540#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001541 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1543#else
1544 (char_u *)NULL, PV_NONE,
1545 {(char_u *)0L, (char_u *)0L}
1546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001547 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1549#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1550 (char_u *)&p_inex, PV_INEX,
1551 {(char_u *)"", (char_u *)0L}
1552#else
1553 (char_u *)NULL, PV_NONE,
1554 {(char_u *)0L, (char_u *)0L}
1555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1558 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001560 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1561#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1562 (char_u *)&p_inde, PV_INDE,
1563 {(char_u *)"", (char_u *)0L}
1564#else
1565 (char_u *)NULL, PV_NONE,
1566 {(char_u *)0L, (char_u *)0L}
1567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001568 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001569 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1571 (char_u *)&p_indk, PV_INDK,
1572 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1573#else
1574 (char_u *)NULL, PV_NONE,
1575 {(char_u *)0L, (char_u *)0L}
1576#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001577 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001578 {"infercase", "inf", P_BOOL|P_VI_DEF,
1579 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1582 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1585 (char_u *)&p_isf, PV_NONE,
1586 {
1587#ifdef BACKSLASH_IN_FILENAME
1588 /* Excluded are: & and ^ are special in cmd.exe
1589 * ( and ) are used in text separating fnames */
1590 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1591#else
1592# ifdef AMIGA
1593 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1594# else
1595# ifdef VMS
1596 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1597# else /* UNIX et al. */
1598# ifdef EBCDIC
1599 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1600# else
1601 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1602# endif
1603# endif
1604# endif
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1608 (char_u *)&p_isi, PV_NONE,
1609 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001610#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 (char_u *)"@,48-57,_,128-167,224-235",
1612#else
1613# ifdef EBCDIC
1614 /* TODO: EBCDIC Check this! @ == isalpha()*/
1615 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1616 "112-120,128,140-142,156,158,172,"
1617 "174,186,191,203-207,219-225,235-239,"
1618 "251-254",
1619# else
1620 (char_u *)"@,48-57,_,192-255",
1621# endif
1622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001623 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1625 (char_u *)&p_isk, PV_ISK,
1626 {
1627#ifdef EBCDIC
1628 (char_u *)"@,240-249,_",
1629 /* TODO: EBCDIC Check this! @ == isalpha()*/
1630 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1631 "112-120,128,140-142,156,158,172,"
1632 "174,186,191,203-207,219-225,235-239,"
1633 "251-254",
1634#else
1635 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001636# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637 (char_u *)"@,48-57,_,128-167,224-235"
1638# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001639 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640# endif
1641#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001642 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1644 (char_u *)&p_isp, PV_NONE,
1645 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001646#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 || defined(VMS)
1648 (char_u *)"@,~-255",
1649#else
1650# ifdef EBCDIC
1651 /* all chars above 63 are printable */
1652 (char_u *)"63-255",
1653# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001654 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655# endif
1656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001657 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1659 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001660 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1662#ifdef FEAT_CRYPT
1663 (char_u *)&p_key, PV_KEY,
1664 {(char_u *)"", (char_u *)0L}
1665#else
1666 (char_u *)NULL, PV_NONE,
1667 {(char_u *)0L, (char_u *)0L}
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001670 {"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 +00001671#ifdef FEAT_KEYMAP
1672 (char_u *)&p_keymap, PV_KMAP,
1673 {(char_u *)"", (char_u *)0L}
1674#else
1675 (char_u *)NULL, PV_NONE,
1676 {(char_u *)"", (char_u *)0L}
1677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001678 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001679 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001680 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001681 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001683 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001685#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 (char_u *)":help",
1687#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001688# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001690# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001691# ifdef USEMAN_S
1692 (char_u *)"man -s",
1693# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001695# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696# endif
1697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001698 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001699 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700#ifdef FEAT_LANGMAP
1701 (char_u *)&p_langmap, PV_NONE,
1702 {(char_u *)"", /* unmatched } */
1703#else
1704 (char_u *)NULL, PV_NONE,
1705 {(char_u *)NULL,
1706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001708 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1710 (char_u *)&p_lm, PV_NONE,
1711#else
1712 (char_u *)NULL, PV_NONE,
1713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001715 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1716#ifdef FEAT_LANGMAP
1717 (char_u *)&p_lnr, PV_NONE,
1718#else
1719 (char_u *)NULL, PV_NONE,
1720#endif
1721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001722 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1723#ifdef FEAT_LANGMAP
1724 (char_u *)&p_lrm, PV_NONE,
1725#else
1726 (char_u *)NULL, PV_NONE,
1727#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001728 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1730#ifdef FEAT_WINDOWS
1731 (char_u *)&p_ls, PV_NONE,
1732#else
1733 (char_u *)NULL, PV_NONE,
1734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001735 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1737 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001738 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1740#ifdef FEAT_LINEBREAK
1741 (char_u *)VAR_WIN, PV_LBR,
1742#else
1743 (char_u *)NULL, PV_NONE,
1744#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1747 (char_u *)&Rows, PV_NONE,
1748 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001749#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 (char_u *)25L,
1751#else
1752 (char_u *)24L,
1753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1756#ifdef FEAT_GUI
1757 (char_u *)&p_linespace, PV_NONE,
1758#else
1759 (char_u *)NULL, PV_NONE,
1760#endif
1761#ifdef FEAT_GUI_W32
1762 {(char_u *)1L, (char_u *)0L}
1763#else
1764 {(char_u *)0L, (char_u *)0L}
1765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 {"lisp", NULL, P_BOOL|P_VI_DEF,
1768#ifdef FEAT_LISP
1769 (char_u *)&p_lisp, PV_LISP,
1770#else
1771 (char_u *)NULL, PV_NONE,
1772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001774 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001776 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1778#else
1779 (char_u *)NULL, PV_NONE,
1780 {(char_u *)"", (char_u *)0L}
1781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1784 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001786 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1790 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001792#if defined(DYNAMIC_LUA)
Bram Moolenaara6e42502016-04-20 16:19:52 +02001793 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001794 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001795 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1796 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001797#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001798#ifdef FEAT_GUI_MAC
1799 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1800 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001801 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001802#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803 {"magic", NULL, P_BOOL|P_VI_DEF,
1804 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001805 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001806 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807#ifdef FEAT_QUICKFIX
1808 (char_u *)&p_mef, PV_NONE,
1809 {(char_u *)"", (char_u *)0L}
1810#else
1811 (char_u *)NULL, PV_NONE,
1812 {(char_u *)NULL, (char_u *)0L}
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1816#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001817 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818# ifdef VMS
1819 {(char_u *)"MMS", (char_u *)0L}
1820# else
1821 {(char_u *)"make", (char_u *)0L}
1822# endif
1823#else
1824 (char_u *)NULL, PV_NONE,
1825 {(char_u *)NULL, (char_u *)0L}
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001828 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1831 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"matchtime", "mat", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001835 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001836#ifdef FEAT_MBYTE
1837 (char_u *)&p_mco, PV_NONE,
1838#else
1839 (char_u *)NULL, PV_NONE,
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1843#ifdef FEAT_EVAL
1844 (char_u *)&p_mfd, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1850 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"maxmem", "mm", P_NUM|P_VI_DEF,
1853 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001854 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1855 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001856 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1857 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1860 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1862 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"menuitems", "mis", P_NUM|P_VI_DEF,
1864#ifdef FEAT_MENU
1865 (char_u *)&p_mis, PV_NONE,
1866#else
1867 (char_u *)NULL, PV_NONE,
1868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"mesg", NULL, P_BOOL|P_VI_DEF,
1871 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001873 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001874#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001875 (char_u *)&p_msm, PV_NONE,
1876 {(char_u *)"460000,2000,500", (char_u *)0L}
1877#else
1878 (char_u *)NULL, PV_NONE,
1879 {(char_u *)0L, (char_u *)0L}
1880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 {"modeline", "ml", P_BOOL|P_VIM,
1883 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001884 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885 {"modelines", "mls", P_NUM|P_VI_DEF,
1886 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1889 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1892 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"more", NULL, P_BOOL|P_VIM,
1895 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1898 (char_u *)&p_mouse, PV_NONE,
1899 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001900#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901 (char_u *)"a",
1902#else
1903 (char_u *)"",
1904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1907#ifdef FEAT_GUI
1908 (char_u *)&p_mousef, PV_NONE,
1909#else
1910 (char_u *)NULL, PV_NONE,
1911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1914#ifdef FEAT_GUI
1915 (char_u *)&p_mh, PV_NONE,
1916#else
1917 (char_u *)NULL, PV_NONE,
1918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1921 (char_u *)&p_mousem, PV_NONE,
1922 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001923#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 (char_u *)"popup",
1925#else
1926# if defined(MACOS)
1927 (char_u *)"popup_setpos",
1928# else
1929 (char_u *)"extend",
1930# endif
1931#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001932 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001933 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934#ifdef FEAT_MOUSESHAPE
1935 (char_u *)&p_mouseshape, PV_NONE,
1936 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1937#else
1938 (char_u *)NULL, PV_NONE,
1939 {(char_u *)NULL, (char_u *)0L}
1940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1943 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001945 {"mzquantum", "mzq", P_NUM,
1946#ifdef FEAT_MZSCHEME
1947 (char_u *)&p_mzq, PV_NONE,
1948#else
1949 (char_u *)NULL, PV_NONE,
1950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"novice", NULL, P_BOOL|P_VI_DEF,
1953 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001955 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001957 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1960 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001962 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1963#ifdef FEAT_LINEBREAK
1964 (char_u *)VAR_WIN, PV_NUW,
1965#else
1966 (char_u *)NULL, PV_NONE,
1967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001968 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001969 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001970#ifdef FEAT_COMPL_FUNC
1971 (char_u *)&p_ofu, PV_OFU,
1972 {(char_u *)"", (char_u *)0L}
1973#else
1974 (char_u *)NULL, PV_NONE,
1975 {(char_u *)0L, (char_u *)0L}
1976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"open", NULL, P_BOOL|P_VI_DEF,
1979 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001981 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001982#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001983 (char_u *)&p_odev, PV_NONE,
1984#else
1985 (char_u *)NULL, PV_NONE,
1986#endif
1987 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001989 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1990 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"optimize", "opt", P_BOOL|P_VI_DEF,
1993 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001997 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001998 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1999 |P_SECURE,
2000 (char_u *)&p_pp, PV_NONE,
2001 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2002 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003 {"paragraphs", "para", P_STRING|P_VI_DEF,
2004 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002005 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002007 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2011 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2014#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2015 (char_u *)&p_pex, PV_NONE,
2016 {(char_u *)"", (char_u *)0L}
2017#else
2018 (char_u *)NULL, PV_NONE,
2019 {(char_u *)0L, (char_u *)0L}
2020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002021 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002022 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002024 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002026 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002028#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029 (char_u *)".,,",
2030#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002034#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002035 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002036 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002037 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2038 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2041 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002043 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2045 (char_u *)&p_pvh, PV_NONE,
2046#else
2047 (char_u *)NULL, PV_NONE,
2048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2051#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2052 (char_u *)VAR_WIN, PV_PVW,
2053#else
2054 (char_u *)NULL, PV_NONE,
2055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002057 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058#ifdef FEAT_PRINTER
2059 (char_u *)&p_pdev, PV_NONE,
2060 {(char_u *)"", (char_u *)0L}
2061#else
2062 (char_u *)NULL, PV_NONE,
2063 {(char_u *)NULL, (char_u *)0L}
2064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002065 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 {"printencoding", "penc", P_STRING|P_VI_DEF,
2067#ifdef FEAT_POSTSCRIPT
2068 (char_u *)&p_penc, PV_NONE,
2069 {(char_u *)"", (char_u *)0L}
2070#else
2071 (char_u *)NULL, PV_NONE,
2072 {(char_u *)NULL, (char_u *)0L}
2073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002075 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076#ifdef FEAT_POSTSCRIPT
2077 (char_u *)&p_pexpr, PV_NONE,
2078 {(char_u *)"", (char_u *)0L}
2079#else
2080 (char_u *)NULL, PV_NONE,
2081 {(char_u *)NULL, (char_u *)0L}
2082#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 {"printfont", "pfn", P_STRING|P_VI_DEF,
2085#ifdef FEAT_PRINTER
2086 (char_u *)&p_pfn, PV_NONE,
2087 {
2088# ifdef MSWIN
2089 (char_u *)"Courier_New:h10",
2090# else
2091 (char_u *)"courier",
2092# endif
2093 (char_u *)0L}
2094#else
2095 (char_u *)NULL, PV_NONE,
2096 {(char_u *)NULL, (char_u *)0L}
2097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2100#ifdef FEAT_PRINTER
2101 (char_u *)&p_header, PV_NONE,
2102 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2103#else
2104 (char_u *)NULL, PV_NONE,
2105 {(char_u *)NULL, (char_u *)0L}
2106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002108 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2109#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2110 (char_u *)&p_pmcs, PV_NONE,
2111 {(char_u *)"", (char_u *)0L}
2112#else
2113 (char_u *)NULL, PV_NONE,
2114 {(char_u *)NULL, (char_u *)0L}
2115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002117 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2118#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2119 (char_u *)&p_pmfn, PV_NONE,
2120 {(char_u *)"", (char_u *)0L}
2121#else
2122 (char_u *)NULL, PV_NONE,
2123 {(char_u *)NULL, (char_u *)0L}
2124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002126 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127#ifdef FEAT_PRINTER
2128 (char_u *)&p_popt, PV_NONE,
2129 {(char_u *)"", (char_u *)0L}
2130#else
2131 (char_u *)NULL, PV_NONE,
2132 {(char_u *)NULL, (char_u *)0L}
2133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002136 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002138 {"pumheight", "ph", P_NUM|P_VI_DEF,
2139#ifdef FEAT_INS_EXPAND
2140 (char_u *)&p_ph, PV_NONE,
2141#else
2142 (char_u *)NULL, PV_NONE,
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002145#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002146 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002147 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002148 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2149 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002150#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002151#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002152 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002153 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002154 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2155 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002156#endif
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002157 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2158#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2159 (char_u *)&p_pyx, PV_NONE,
2160#else
2161 (char_u *)NULL, PV_NONE,
2162#endif
2163 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2164 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002165 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2166#ifdef FEAT_TEXTOBJ
2167 (char_u *)&p_qe, PV_QE,
2168 {(char_u *)"\\", (char_u *)0L}
2169#else
2170 (char_u *)NULL, PV_NONE,
2171 {(char_u *)NULL, (char_u *)0L}
2172#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002173 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2175 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"redraw", NULL, P_BOOL|P_VI_DEF,
2178 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002179 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002180 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2181#ifdef FEAT_RELTIME
2182 (char_u *)&p_rdt, PV_NONE,
2183#else
2184 (char_u *)NULL, PV_NONE,
2185#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002187 {"regexpengine", "re", P_NUM|P_VI_DEF,
2188 (char_u *)&p_re, PV_NONE,
2189 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002190 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2191 (char_u *)VAR_WIN, PV_RNU,
2192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 {"remap", NULL, P_BOOL|P_VI_DEF,
2194 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002195 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002196 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002197#ifdef FEAT_RENDER_OPTIONS
2198 (char_u *)&p_rop, PV_NONE,
2199 {(char_u *)"", (char_u *)0L}
2200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
2203#endif
2204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"report", NULL, P_NUM|P_VI_DEF,
2206 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2209#ifdef WIN3264
2210 (char_u *)&p_rs, PV_NONE,
2211#else
2212 (char_u *)NULL, PV_NONE,
2213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2216#ifdef FEAT_RIGHTLEFT
2217 (char_u *)&p_ri, PV_NONE,
2218#else
2219 (char_u *)NULL, PV_NONE,
2220#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2223#ifdef FEAT_RIGHTLEFT
2224 (char_u *)VAR_WIN, PV_RL,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2230#ifdef FEAT_RIGHTLEFT
2231 (char_u *)VAR_WIN, PV_RLC,
2232 {(char_u *)"search", (char_u *)NULL}
2233#else
2234 (char_u *)NULL, PV_NONE,
2235 {(char_u *)NULL, (char_u *)0L}
2236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002238#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002239 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002240 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002241 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2242 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002243#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2245#ifdef FEAT_CMDL_INFO
2246 (char_u *)&p_ru, PV_NONE,
2247#else
2248 (char_u *)NULL, PV_NONE,
2249#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002250 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2252#ifdef FEAT_STL_OPT
2253 (char_u *)&p_ruf, PV_NONE,
2254#else
2255 (char_u *)NULL, PV_NONE,
2256#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002257 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002258 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2259 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002261 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2262 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2264 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2267#ifdef FEAT_SCROLLBIND
2268 (char_u *)VAR_WIN, PV_SCBIND,
2269#else
2270 (char_u *)NULL, PV_NONE,
2271#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2274 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2277 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002279 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280#ifdef FEAT_SCROLLBIND
2281 (char_u *)&p_sbo, PV_NONE,
2282 {(char_u *)"ver,jump", (char_u *)0L}
2283#else
2284 (char_u *)NULL, PV_NONE,
2285 {(char_u *)0L, (char_u *)0L}
2286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"sections", "sect", P_STRING|P_VI_DEF,
2289 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2291 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2293 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002294 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 {(char_u *)"inclusive", (char_u *)0L}
2298 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002299 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002302 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303#ifdef FEAT_SESSION
2304 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002305 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 (char_u *)0L}
2307#else
2308 (char_u *)NULL, PV_NONE,
2309 {(char_u *)0L, (char_u *)0L}
2310#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2313 (char_u *)&p_sh, PV_NONE,
2314 {
2315#ifdef VMS
2316 (char_u *)"-",
2317#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002318# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002320# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322# endif
2323#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2326 (char_u *)&p_shcf, PV_NONE,
2327 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002328#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 (char_u *)"/c",
2330#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002333 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2335#ifdef FEAT_QUICKFIX
2336 (char_u *)&p_sp, PV_NONE,
2337 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002338#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340#else
2341 (char_u *)">",
2342#endif
2343 (char_u *)0L}
2344#else
2345 (char_u *)NULL, PV_NONE,
2346 {(char_u *)0L, (char_u *)0L}
2347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2350 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2353 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2356#ifdef BACKSLASH_IN_FILENAME
2357 (char_u *)&p_ssl, PV_NONE,
2358#else
2359 (char_u *)NULL, PV_NONE,
2360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002362 {"shelltemp", "stmp", P_BOOL,
2363 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"shelltype", "st", P_NUM|P_VI_DEF,
2366#ifdef AMIGA
2367 (char_u *)&p_st, PV_NONE,
2368#else
2369 (char_u *)NULL, PV_NONE,
2370#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2373 (char_u *)&p_sxq, PV_NONE,
2374 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002375#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 (char_u *)"\"",
2377#else
2378 (char_u *)"",
2379#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002381 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2382 (char_u *)&p_sxe, PV_NONE,
2383 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002384#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002385 (char_u *)"\"&|<>()@^",
2386#else
2387 (char_u *)"",
2388#endif
2389 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2391 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2394 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2397 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)"", (char_u *)"filnxtToO"}
2399 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2404#ifdef FEAT_LINEBREAK
2405 (char_u *)&p_sbr, PV_NONE,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"showcmd", "sc", P_BOOL|P_VIM,
2411#ifdef FEAT_CMDL_INFO
2412 (char_u *)&p_sc, PV_NONE,
2413#else
2414 (char_u *)NULL, PV_NONE,
2415#endif
2416 {(char_u *)FALSE,
2417#ifdef UNIX
2418 (char_u *)FALSE
2419#else
2420 (char_u *)TRUE
2421#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2424 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2427 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"showmode", "smd", P_BOOL|P_VIM,
2430 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002432 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2433#ifdef FEAT_WINDOWS
2434 (char_u *)&p_stal, PV_NONE,
2435#else
2436 (char_u *)NULL, PV_NONE,
2437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2440 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2443 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002445 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2446#ifdef FEAT_SIGNS
2447 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002448 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002449#else
2450 (char_u *)NULL, PV_NONE,
2451 {(char_u *)NULL, (char_u *)0L}
2452#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002453 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"slowopen", "slow", 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 Moolenaar071d4272004-06-13 20:20:40 +00002457 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2458 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2461#ifdef FEAT_SMARTINDENT
2462 (char_u *)&p_si, PV_SI,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2468 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2471 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2474 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002476 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002477#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002478 (char_u *)VAR_WIN, PV_SPELL,
2479#else
2480 (char_u *)NULL, PV_NONE,
2481#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002483 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002484#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002485 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002486 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002487#else
2488 (char_u *)NULL, PV_NONE,
2489 {(char_u *)0L, (char_u *)0L}
2490#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002491 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002492 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2493 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002494#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002495 (char_u *)&p_spf, PV_SPF,
2496 {(char_u *)"", (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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002502 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2503 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002504#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002505 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002506 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002507#else
2508 (char_u *)NULL, PV_NONE,
2509 {(char_u *)0L, (char_u *)0L}
2510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002512 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002513#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002514 (char_u *)&p_sps, PV_NONE,
2515 {(char_u *)"best", (char_u *)0L}
2516#else
2517 (char_u *)NULL, PV_NONE,
2518 {(char_u *)0L, (char_u *)0L}
2519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2522#ifdef FEAT_WINDOWS
2523 (char_u *)&p_sb, PV_NONE,
2524#else
2525 (char_u *)NULL, PV_NONE,
2526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002529#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 (char_u *)&p_spr, PV_NONE,
2531#else
2532 (char_u *)NULL, PV_NONE,
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2536 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2539#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002540 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541#else
2542 (char_u *)NULL, PV_NONE,
2543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002545 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 (char_u *)&p_su, PV_NONE,
2547 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002548 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002549 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002550#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 (char_u *)&p_sua, PV_SUA,
2552 {(char_u *)"", (char_u *)0L}
2553#else
2554 (char_u *)NULL, PV_NONE,
2555 {(char_u *)0L, (char_u *)0L}
2556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2559 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"swapsync", "sws", P_STRING|P_VI_DEF,
2562 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002563 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002564 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002567 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2568#ifdef FEAT_SYN_HL
2569 (char_u *)&p_smc, PV_SMC,
2570 {(char_u *)3000L, (char_u *)0L}
2571#else
2572 (char_u *)NULL, PV_NONE,
2573 {(char_u *)0L, (char_u *)0L}
2574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002576 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577#ifdef FEAT_SYN_HL
2578 (char_u *)&p_syn, PV_SYN,
2579 {(char_u *)"", (char_u *)0L}
2580#else
2581 (char_u *)NULL, PV_NONE,
2582 {(char_u *)0L, (char_u *)0L}
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002585 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2586#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002587 (char_u *)&p_tal, PV_NONE,
2588#else
2589 (char_u *)NULL, PV_NONE,
2590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002592 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2593#ifdef FEAT_WINDOWS
2594 (char_u *)&p_tpm, PV_NONE,
2595#else
2596 (char_u *)NULL, PV_NONE,
2597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2600 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2603 (char_u *)&p_tbs, PV_NONE,
2604#ifdef VMS /* binary searching doesn't appear to work on VMS */
2605 {(char_u *)0L, (char_u *)0L}
2606#else
2607 {(char_u *)TRUE, (char_u *)0L}
2608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002610 {"tagcase", "tc", P_STRING|P_VIM,
2611 (char_u *)&p_tc, PV_TC,
2612 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 {"taglength", "tl", P_NUM|P_VI_DEF,
2614 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002615 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 {"tagrelative", "tr", P_BOOL|P_VIM,
2617 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002619 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002620 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {
2622#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2623 (char_u *)"./tags,./TAGS,tags,TAGS",
2624#else
2625 (char_u *)"./tags,tags",
2626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2629 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002631#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002632 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002633 (char_u *)&p_tcldll, PV_NONE,
2634 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2635 SCRIPTID_INIT},
2636#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2638 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2641#ifdef FEAT_ARABIC
2642 (char_u *)&p_tbidi, PV_NONE,
2643#else
2644 (char_u *)NULL, PV_NONE,
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2648#ifdef FEAT_MBYTE
2649 (char_u *)&p_tenc, PV_NONE,
2650 {(char_u *)"", (char_u *)0L}
2651#else
2652 (char_u *)NULL, PV_NONE,
2653 {(char_u *)0L, (char_u *)0L}
2654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002656 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2657#ifdef FEAT_TERMGUICOLORS
2658 (char_u *)&p_tgc, PV_NONE,
2659 {(char_u *)FALSE, (char_u *)FALSE}
2660#else
2661 (char_u*)NULL, PV_NONE,
2662 {(char_u *)FALSE, (char_u *)FALSE}
2663#endif
2664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"terse", NULL, P_BOOL|P_VI_DEF,
2666 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"textauto", "ta", P_BOOL|P_VIM,
2669 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2671 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2673 (char_u *)&p_tx, PV_TX,
2674 {
2675#ifdef USE_CRNL
2676 (char_u *)TRUE,
2677#else
2678 (char_u *)FALSE,
2679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002681 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002684 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002686 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687#else
2688 (char_u *)NULL, PV_NONE,
2689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2692 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002693 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 {"timeout", "to", P_BOOL|P_VI_DEF,
2695 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2698 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700 {"title", NULL, P_BOOL|P_VI_DEF,
2701#ifdef FEAT_TITLE
2702 (char_u *)&p_title, PV_NONE,
2703#else
2704 (char_u *)NULL, PV_NONE,
2705#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"titlelen", NULL, P_NUM|P_VI_DEF,
2708#ifdef FEAT_TITLE
2709 (char_u *)&p_titlelen, PV_NONE,
2710#else
2711 (char_u *)NULL, PV_NONE,
2712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002714 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715#ifdef FEAT_TITLE
2716 (char_u *)&p_titleold, PV_NONE,
2717 {(char_u *)N_("Thanks for flying Vim"),
2718 (char_u *)0L}
2719#else
2720 (char_u *)NULL, PV_NONE,
2721 {(char_u *)0L, (char_u *)0L}
2722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"titlestring", NULL, P_STRING|P_VI_DEF,
2725#ifdef FEAT_TITLE
2726 (char_u *)&p_titlestring, PV_NONE,
2727#else
2728 (char_u *)NULL, PV_NONE,
2729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002732 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)"icons,tooltips", (char_u *)0L}
2735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002737#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2739 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002741#endif
2742 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2743 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2746 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2749 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002750 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2752 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002753 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2755#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2756 (char_u *)&p_ttym, PV_NONE,
2757#else
2758 (char_u *)NULL, PV_NONE,
2759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002760 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2762 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002763 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2765 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002767 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2768 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002769#ifdef FEAT_PERSISTENT_UNDO
2770 (char_u *)&p_udir, PV_NONE,
2771 {(char_u *)".", (char_u *)0L}
2772#else
2773 (char_u *)NULL, PV_NONE,
2774 {(char_u *)0L, (char_u *)0L}
2775#endif
2776 SCRIPTID_INIT},
2777 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2778#ifdef FEAT_PERSISTENT_UNDO
2779 (char_u *)&p_udf, PV_UDF,
2780#else
2781 (char_u *)NULL, PV_NONE,
2782#endif
2783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002785 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002787#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 (char_u *)1000L,
2789#else
2790 (char_u *)100L,
2791#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002792 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002793 {"undoreload", "ur", P_NUM|P_VI_DEF,
2794 (char_u *)&p_ur, PV_NONE,
2795 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {"updatecount", "uc", P_NUM|P_VI_DEF,
2797 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"updatetime", "ut", P_NUM|P_VI_DEF,
2800 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002801 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"verbose", "vbs", P_NUM|P_VI_DEF,
2803 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002805 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2806 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2809#ifdef FEAT_SESSION
2810 (char_u *)&p_vdir, PV_NONE,
2811 {(char_u *)DFLT_VDIR, (char_u *)0L}
2812#else
2813 (char_u *)NULL, PV_NONE,
2814 {(char_u *)0L, (char_u *)0L}
2815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002817 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818#ifdef FEAT_SESSION
2819 (char_u *)&p_vop, PV_NONE,
2820 {(char_u *)"folds,options,cursor", (char_u *)0L}
2821#else
2822 (char_u *)NULL, PV_NONE,
2823 {(char_u *)0L, (char_u *)0L}
2824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002826 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827#ifdef FEAT_VIMINFO
2828 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002829#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002830 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831#else
2832# ifdef AMIGA
2833 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002834 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002836 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837# endif
2838#endif
2839#else
2840 (char_u *)NULL, PV_NONE,
2841 {(char_u *)0L, (char_u *)0L}
2842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002844 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2845 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846#ifdef FEAT_VIRTUALEDIT
2847 (char_u *)&p_ve, PV_NONE,
2848 {(char_u *)"", (char_u *)""}
2849#else
2850 (char_u *)NULL, PV_NONE,
2851 {(char_u *)0L, (char_u *)0L}
2852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2855 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002856 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 {"w300", NULL, P_NUM|P_VI_DEF,
2858 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"w1200", NULL, P_NUM|P_VI_DEF,
2861 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"w9600", NULL, P_NUM|P_VI_DEF,
2864 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"warn", NULL, P_BOOL|P_VI_DEF,
2867 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002868 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2870 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002872 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002874 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 {"wildchar", "wc", P_NUM|P_VIM,
2876 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002877 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2878 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002879 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002882 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883#ifdef FEAT_WILDIGN
2884 (char_u *)&p_wig, PV_NONE,
2885#else
2886 (char_u *)NULL, PV_NONE,
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002889 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2890 (char_u *)&p_wic, PV_NONE,
2891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2893#ifdef FEAT_WILDMENU
2894 (char_u *)&p_wmnu, PV_NONE,
2895#else
2896 (char_u *)NULL, PV_NONE,
2897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002899 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002901 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002902 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2903#ifdef FEAT_CMDL_COMPL
2904 (char_u *)&p_wop, PV_NONE,
2905 {(char_u *)"", (char_u *)0L}
2906#else
2907 (char_u *)NULL, PV_NONE,
2908 {(char_u *)NULL, (char_u *)0L}
2909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2912#ifdef FEAT_WAK
2913 (char_u *)&p_wak, PV_NONE,
2914 {(char_u *)"menu", (char_u *)0L}
2915#else
2916 (char_u *)NULL, PV_NONE,
2917 {(char_u *)NULL, (char_u *)0L}
2918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002921 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 {"winheight", "wh", P_NUM|P_VI_DEF,
2924#ifdef FEAT_WINDOWS
2925 (char_u *)&p_wh, PV_NONE,
2926#else
2927 (char_u *)NULL, PV_NONE,
2928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002931#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 (char_u *)VAR_WIN, PV_WFH,
2933#else
2934 (char_u *)NULL, PV_NONE,
2935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002937 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002938#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002939 (char_u *)VAR_WIN, PV_WFW,
2940#else
2941 (char_u *)NULL, PV_NONE,
2942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002943 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2945#ifdef FEAT_WINDOWS
2946 (char_u *)&p_wmh, PV_NONE,
2947#else
2948 (char_u *)NULL, PV_NONE,
2949#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002952#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953 (char_u *)&p_wmw, PV_NONE,
2954#else
2955 (char_u *)NULL, PV_NONE,
2956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002959#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 (char_u *)&p_wiw, PV_NONE,
2961#else
2962 (char_u *)NULL, PV_NONE,
2963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002964 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2966 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002967 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2969 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002970 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2972 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002973 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 {"write", NULL, P_BOOL|P_VI_DEF,
2975 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002976 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 {"writeany", "wa", P_BOOL|P_VI_DEF,
2978 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2981 (char_u *)&p_wb, PV_NONE,
2982 {
2983#ifdef FEAT_WRITEBACKUP
2984 (char_u *)TRUE,
2985#else
2986 (char_u *)FALSE,
2987#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002988 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 {"writedelay", "wd", P_NUM|P_VI_DEF,
2990 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002991 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992
2993/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002994#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997
2998 p_term("t_AB", T_CAB)
2999 p_term("t_AF", T_CAF)
3000 p_term("t_AL", T_CAL)
3001 p_term("t_al", T_AL)
3002 p_term("t_bc", T_BC)
3003 p_term("t_cd", T_CD)
3004 p_term("t_ce", T_CE)
3005 p_term("t_cl", T_CL)
3006 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003007 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 p_term("t_Co", T_CCO)
3009 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003010 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003012#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013 p_term("t_CV", T_CSV)
3014#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 p_term("t_da", T_DA)
3016 p_term("t_db", T_DB)
3017 p_term("t_DL", T_CDL)
3018 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003019 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 p_term("t_fs", T_FS)
3021 p_term("t_IE", T_CIE)
3022 p_term("t_IS", T_CIS)
3023 p_term("t_ke", T_KE)
3024 p_term("t_ks", T_KS)
3025 p_term("t_le", T_LE)
3026 p_term("t_mb", T_MB)
3027 p_term("t_md", T_MD)
3028 p_term("t_me", T_ME)
3029 p_term("t_mr", T_MR)
3030 p_term("t_ms", T_MS)
3031 p_term("t_nd", T_ND)
3032 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003033 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 p_term("t_RI", T_CRI)
3035 p_term("t_RV", T_CRV)
3036 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003038 p_term("t_Sf", T_CSF)
3039 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003041 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043 p_term("t_te", T_TE)
3044 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003045 p_term("t_ts", T_TS)
3046 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 p_term("t_ue", T_UE)
3048 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003049 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 p_term("t_vb", T_VB)
3051 p_term("t_ve", T_VE)
3052 p_term("t_vi", T_VI)
3053 p_term("t_vs", T_VS)
3054 p_term("t_WP", T_CWP)
3055 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003056 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 p_term("t_xs", T_XS)
3058 p_term("t_ZH", T_CZH)
3059 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003060 p_term("t_8f", T_8F)
3061 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003062 p_term("t_BE", T_BE)
3063 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064
3065/* terminal key codes are not in here */
3066
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003067 /* end marker */
3068 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069};
3070
3071#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3072
3073#ifdef FEAT_MBYTE
3074static char *(p_ambw_values[]) = {"single", "double", NULL};
3075#endif
3076static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003077static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003079#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003080static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003081#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003082#ifdef FEAT_CMDL_COMPL
3083static char *(p_wop_values[]) = {"tagfile", NULL};
3084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085#ifdef FEAT_WAK
3086static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3087#endif
3088static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3090static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092#ifdef FEAT_BROWSE
3093static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3094#endif
3095#ifdef FEAT_SCROLLBIND
3096static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3097#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003098static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003099#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3101#endif
3102#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003103# ifdef FEAT_AUTOCMD
3104static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3105# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003107# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3109#endif
3110static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3111#ifdef FEAT_FOLDING
3112static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003113# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003115# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116 NULL};
3117static char *(p_fcl_values[]) = {"all", NULL};
3118#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003119#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003120static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003121#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003122#ifdef FEAT_SIGNS
3123static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003126static void set_option_default(int, int opt_flags, int compatible);
3127static void set_options_default(int opt_flags);
3128static char_u *term_bg_default(void);
3129static void did_set_option(int opt_idx, int opt_flags, int new_value);
3130static char_u *illegal_char(char_u *, int);
3131static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003133static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134#endif
3135#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003136static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003138static char_u *option_expand(int opt_idx, char_u *val);
3139static void didset_options(void);
3140static void didset_options2(void);
3141static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003142#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003143static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003144#else
3145# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3146#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003147static void set_string_option_global(int opt_idx, char_u **varp);
3148static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3149static 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);
3150static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003151#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003152static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003155static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003157#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003158static char_u *did_set_spell_option(int is_spellfile);
3159static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003160#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003161#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003162static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003163#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003164static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3165static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3166static void check_redraw(long_u flags);
3167static int findoption(char_u *);
3168static int find_key_option(char_u *);
3169static void showoptions(int all, int opt_flags);
3170static int optval_default(struct vimoption *, char_u *varp);
3171static void showoneopt(struct vimoption *, int opt_flags);
3172static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3173static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3174static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3175static int istermoption(struct vimoption *);
3176static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3177static char_u *get_varp(struct vimoption *);
3178static void option_value2string(struct vimoption *, int opt_flags);
3179static void check_winopt(winopt_T *wop);
3180static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003182static void langmap_init(void);
3183static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003185static void paste_option_changed(void);
3186static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003188static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003190static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3191static int check_opt_strings(char_u *val, char **values, int);
3192static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003193#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003194static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003195#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196
3197/*
3198 * Initialize the options, first part.
3199 *
3200 * Called only once from main(), just after creating the first buffer.
3201 */
3202 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003203set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204{
3205 char_u *p;
3206 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003207 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208
3209#ifdef FEAT_LANGMAP
3210 langmap_init();
3211#endif
3212
3213 /* Be Vi compatible by default */
3214 p_cp = TRUE;
3215
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003216 /* Use POSIX compatibility when $VIM_POSIX is set. */
3217 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003218 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003219 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003220 set_string_default("shm", (char_u *)"A");
3221 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003222
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 /*
3224 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003225 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003227 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003228#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003229 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003231 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232# endif
3233#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003234 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235 set_string_default("sh", p);
3236
3237#ifdef FEAT_WILDIGN
3238 /*
3239 * Set the default for 'backupskip' to include environment variables for
3240 * temp files.
3241 */
3242 {
3243# ifdef UNIX
3244 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3245# else
3246 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3247# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003248 int len;
3249 garray_T ga;
3250 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251
3252 ga_init2(&ga, 1, 100);
3253 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3254 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003255 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256# ifdef UNIX
3257 if (*names[n] == NUL)
3258 p = (char_u *)"/tmp";
3259 else
3260# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003261 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262 if (p != NULL && *p != NUL)
3263 {
3264 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003265 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266 if (ga_grow(&ga, len) == OK)
3267 {
3268 if (ga.ga_len > 0)
3269 STRCAT(ga.ga_data, ",");
3270 STRCAT(ga.ga_data, p);
3271 add_pathsep(ga.ga_data);
3272 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273 ga.ga_len += len;
3274 }
3275 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003276 if (mustfree)
3277 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278 }
3279 if (ga.ga_data != NULL)
3280 {
3281 set_string_default("bsk", ga.ga_data);
3282 vim_free(ga.ga_data);
3283 }
3284 }
3285#endif
3286
3287 /*
3288 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3289 */
3290 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003291 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003293#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3294 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3295#endif
3296 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003298 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003299 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#else
3301# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003302 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003303 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003305 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306# endif
3307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003309 opt_idx = findoption((char_u *)"maxmem");
3310 if (opt_idx >= 0)
3311 {
3312#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003313 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3314 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003315#endif
3316 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3317 }
3318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319 }
3320
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321#ifdef FEAT_SEARCHPATH
3322 {
3323 char_u *cdpath;
3324 char_u *buf;
3325 int i;
3326 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003327 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328
3329 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003330 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331 if (cdpath != NULL)
3332 {
3333 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3334 if (buf != NULL)
3335 {
3336 buf[0] = ','; /* start with ",", current dir first */
3337 j = 1;
3338 for (i = 0; cdpath[i] != NUL; ++i)
3339 {
3340 if (vim_ispathlistsep(cdpath[i]))
3341 buf[j++] = ',';
3342 else
3343 {
3344 if (cdpath[i] == ' ' || cdpath[i] == ',')
3345 buf[j++] = '\\';
3346 buf[j++] = cdpath[i];
3347 }
3348 }
3349 buf[j] = NUL;
3350 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003351 if (opt_idx >= 0)
3352 {
3353 options[opt_idx].def_val[VI_DEFAULT] = buf;
3354 options[opt_idx].flags |= P_DEF_ALLOCED;
3355 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003356 else
3357 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003359 if (mustfree)
3360 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361 }
3362 }
3363#endif
3364
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003365#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366 /* Set print encoding on platforms that don't default to latin1 */
3367 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003368# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369 (char_u *)"cp1252"
3370# else
3371# ifdef VMS
3372 (char_u *)"dec-mcs"
3373# else
3374# ifdef EBCDIC
3375 (char_u *)"ebcdic-uk"
3376# else
3377# ifdef MAC
3378 (char_u *)"mac-roman"
3379# else /* HPUX */
3380 (char_u *)"hp-roman8"
3381# endif
3382# endif
3383# endif
3384# endif
3385 );
3386#endif
3387
3388#ifdef FEAT_POSTSCRIPT
3389 /* 'printexpr' must be allocated to be able to evaluate it. */
3390 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003391# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003392 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393# else
3394# ifdef VMS
3395 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3396
3397# else
3398 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3399# endif
3400# endif
3401 );
3402#endif
3403
3404 /*
3405 * Set all the options (except the terminal options) to their default
3406 * value. Also set the global value for local options.
3407 */
3408 set_options_default(0);
3409
3410#ifdef FEAT_GUI
3411 if (found_reverse_arg)
3412 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3413#endif
3414
3415 curbuf->b_p_initialized = TRUE;
3416 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003417 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 check_buf_options(curbuf);
3419 check_win_options(curwin);
3420 check_options();
3421
3422 /* Must be before option_expand(), because that one needs vim_isIDc() */
3423 didset_options();
3424
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003425#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003426 /* Use the current chartab for the generic chartab. This is not in
3427 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003428 init_spell_chartab();
3429#endif
3430
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431 /*
3432 * Expand environment variables and things like "~" for the defaults.
3433 * If option_expand() returns non-NULL the variable is expanded. This can
3434 * only happen for non-indirect options.
3435 * Also set the default to the expanded value, so ":set" does not list
3436 * them.
3437 * Don't set the P_ALLOCED flag, because we don't want to free the
3438 * default.
3439 */
3440 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3441 {
3442 if ((options[opt_idx].flags & P_GETTEXT)
3443 && options[opt_idx].var != NULL)
3444 p = (char_u *)_(*(char **)options[opt_idx].var);
3445 else
3446 p = option_expand(opt_idx, NULL);
3447 if (p != NULL && (p = vim_strsave(p)) != NULL)
3448 {
3449 *(char_u **)options[opt_idx].var = p;
3450 /* VIMEXP
3451 * Defaults for all expanded options are currently the same for Vi
3452 * and Vim. When this changes, add some code here! Also need to
3453 * split P_DEF_ALLOCED in two.
3454 */
3455 if (options[opt_idx].flags & P_DEF_ALLOCED)
3456 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3457 options[opt_idx].def_val[VI_DEFAULT] = p;
3458 options[opt_idx].flags |= P_DEF_ALLOCED;
3459 }
3460 }
3461
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462 save_file_ff(curbuf); /* Buffer is unchanged */
3463
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464#if defined(FEAT_ARABIC)
3465 /* Detect use of mlterm.
3466 * Mlterm is a terminal emulator akin to xterm that has some special
3467 * abilities (bidi namely).
3468 * NOTE: mlterm's author is being asked to 'set' a variable
3469 * instead of an environment variable due to inheritance.
3470 */
3471 if (mch_getenv((char_u *)"MLTERM") != NULL)
3472 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3473#endif
3474
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003475 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476
3477#ifdef FEAT_MBYTE
3478# if defined(WIN3264) && defined(FEAT_GETTEXT)
3479 /*
3480 * If $LANG isn't set, try to get a good value for it. This makes the
3481 * right language be used automatically. Don't do this for English.
3482 */
3483 if (mch_getenv((char_u *)"LANG") == NULL)
3484 {
3485 char buf[20];
3486
3487 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3488 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3489 * only the first two. */
3490 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3491 (LPTSTR)buf, 20);
3492 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3493 {
3494 /* There are a few exceptions (probably more) */
3495 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3496 STRCPY(buf, "zh_TW");
3497 else if (STRNICMP(buf, "chs", 3) == 0
3498 || STRNICMP(buf, "zhc", 3) == 0)
3499 STRCPY(buf, "zh_CN");
3500 else if (STRNICMP(buf, "jp", 2) == 0)
3501 STRCPY(buf, "ja");
3502 else
3503 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003504 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505 }
3506 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003507# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003508# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003509 /* Moved to os_mac_conv.c to avoid dependency problems. */
3510 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003511# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003512# endif
3513
3514 /* enc_locale() will try to find the encoding of the current locale. */
3515 p = enc_locale();
3516 if (p != NULL)
3517 {
3518 char_u *save_enc;
3519
3520 /* Try setting 'encoding' and check if the value is valid.
3521 * If not, go back to the default "latin1". */
3522 save_enc = p_enc;
3523 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003524 if (STRCMP(p_enc, "gb18030") == 0)
3525 {
3526 /* We don't support "gb18030", but "cp936" is a good substitute
3527 * for practical purposes, thus use that. It's not an alias to
3528 * still support conversion between gb18030 and utf-8. */
3529 p_enc = vim_strsave((char_u *)"cp936");
3530 vim_free(p);
3531 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003532 if (mb_init() == NULL)
3533 {
3534 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003535 if (opt_idx >= 0)
3536 {
3537 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3538 options[opt_idx].flags |= P_DEF_ALLOCED;
3539 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003541#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003542 if (STRCMP(p_enc, "latin1") == 0
3543# ifdef FEAT_MBYTE
3544 || enc_utf8
3545# endif
3546 )
3547 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003548 /* Adjust the default for 'isprint' and 'iskeyword' to match
3549 * latin1. Also set the defaults for when 'nocompatible' is
3550 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003551 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003552 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003553 set_string_option_direct((char_u *)"isk", -1,
3554 ISK_LATIN1, OPT_FREE, SID_NONE);
3555 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003556 if (opt_idx >= 0)
3557 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003558 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003559 if (opt_idx >= 0)
3560 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003561 (void)init_chartab();
3562 }
3563#endif
3564
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565# if defined(WIN3264) && !defined(FEAT_GUI)
3566 /* Win32 console: When GetACP() returns a different value from
3567 * GetConsoleCP() set 'termencoding'. */
3568 if (GetACP() != GetConsoleCP())
3569 {
3570 char buf[50];
3571
3572 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3573 p_tenc = vim_strsave((char_u *)buf);
3574 if (p_tenc != NULL)
3575 {
3576 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003577 if (opt_idx >= 0)
3578 {
3579 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3580 options[opt_idx].flags |= P_DEF_ALLOCED;
3581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582 convert_setup(&input_conv, p_tenc, p_enc);
3583 convert_setup(&output_conv, p_enc, p_tenc);
3584 }
3585 else
3586 p_tenc = empty_option;
3587 }
3588# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003589# if defined(WIN3264) && defined(FEAT_MBYTE)
3590 /* $HOME may have characters in active code page. */
3591 init_homedir();
3592# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 }
3594 else
3595 {
3596 vim_free(p_enc);
3597 p_enc = save_enc;
3598 }
3599 }
3600#endif
3601
3602#ifdef FEAT_MULTI_LANG
3603 /* Set the default for 'helplang'. */
3604 set_helplang_default(get_mess_lang());
3605#endif
3606}
3607
3608/*
3609 * Set an option to its default value.
3610 * This does not take care of side effects!
3611 */
3612 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003613set_option_default(
3614 int opt_idx,
3615 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3616 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617{
3618 char_u *varp; /* pointer to variable for current option */
3619 int dvi; /* index in def_val[] */
3620 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003621 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3623
3624 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3625 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003626 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 {
3628 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3629 if (flags & P_STRING)
3630 {
3631 /* Use set_string_option_direct() for local options to handle
3632 * freeing and allocating the value. */
3633 if (options[opt_idx].indir != PV_NONE)
3634 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003635 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 else
3637 {
3638 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3639 free_string_option(*(char_u **)(varp));
3640 *(char_u **)varp = options[opt_idx].def_val[dvi];
3641 options[opt_idx].flags &= ~P_ALLOCED;
3642 }
3643 }
3644 else if (flags & P_NUM)
3645 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003646 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003647 win_comp_scroll(curwin);
3648 else
3649 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003650 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651 /* May also set global value for local option. */
3652 if (both)
3653 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3654 *(long *)varp;
3655 }
3656 }
3657 else /* P_BOOL */
3658 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003659 /* the cast to long is required for Manx C, long_i is needed for
3660 * MSVC */
3661 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003662#ifdef UNIX
3663 /* 'modeline' defaults to off for root */
3664 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3665 *(int *)varp = FALSE;
3666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003667 /* May also set global value for local option. */
3668 if (both)
3669 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3670 *(int *)varp;
3671 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003672
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003673 /* The default value is not insecure. */
3674 flagsp = insecure_flag(opt_idx, opt_flags);
3675 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676 }
3677
3678#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003679 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680#endif
3681}
3682
3683/*
3684 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003685 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686 */
3687 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003688set_options_default(
3689 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690{
3691 int i;
3692#ifdef FEAT_WINDOWS
3693 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003694 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695#endif
3696
3697 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003698 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003699#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003700 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003701 || (TRUE
3702# if defined(FEAT_MBYTE)
3703 && options[i].var != (char_u *)&p_enc
3704# endif
3705# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003706 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003707 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003708# endif
3709 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003710#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003711 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003712 set_option_default(i, opt_flags, p_cp);
3713
3714#ifdef FEAT_WINDOWS
3715 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003716 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 win_comp_scroll(wp);
3718#else
3719 win_comp_scroll(curwin);
3720#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003721#ifdef FEAT_CINDENT
3722 parse_cino(curbuf);
3723#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003724}
3725
3726/*
3727 * Set the Vi-default value of a string option.
3728 * Used for 'sh', 'backupskip' and 'term'.
3729 */
3730 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003731set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732{
3733 char_u *p;
3734 int opt_idx;
3735
3736 p = vim_strsave(val);
3737 if (p != NULL) /* we don't want a NULL */
3738 {
3739 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003740 if (opt_idx >= 0)
3741 {
3742 if (options[opt_idx].flags & P_DEF_ALLOCED)
3743 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3744 options[opt_idx].def_val[VI_DEFAULT] = p;
3745 options[opt_idx].flags |= P_DEF_ALLOCED;
3746 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747 }
3748}
3749
3750/*
3751 * Set the Vi-default value of a number option.
3752 * Used for 'lines' and 'columns'.
3753 */
3754 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003755set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003757 int opt_idx;
3758
3759 opt_idx = findoption((char_u *)name);
3760 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003761 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762}
3763
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003764#if defined(EXITFREE) || defined(PROTO)
3765/*
3766 * Free all options.
3767 */
3768 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003769free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003770{
3771 int i;
3772
3773 for (i = 0; !istermoption(&options[i]); i++)
3774 {
3775 if (options[i].indir == PV_NONE)
3776 {
3777 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003778 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003779 free_string_option(*(char_u **)options[i].var);
3780 if (options[i].flags & P_DEF_ALLOCED)
3781 free_string_option(options[i].def_val[VI_DEFAULT]);
3782 }
3783 else if (options[i].var != VAR_WIN
3784 && (options[i].flags & P_STRING))
3785 /* buffer-local option: free global value */
3786 free_string_option(*(char_u **)options[i].var);
3787 }
3788}
3789#endif
3790
3791
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792/*
3793 * Initialize the options, part two: After getting Rows and Columns and
3794 * setting 'term'.
3795 */
3796 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003797set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003799 int idx;
3800
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 /*
3802 * 'scroll' defaults to half the window height. Note that this default is
3803 * wrong when the window height changes.
3804 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003805 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003806 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003807 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003808 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 comp_col();
3810
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003811 /*
3812 * 'window' is only for backwards compatibility with Vi.
3813 * Default is Rows - 1.
3814 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003815 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003816 p_window = Rows - 1;
3817 set_number_default("window", Rows - 1);
3818
Bram Moolenaarf740b292006-02-16 22:11:02 +00003819 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003820#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003821 /*
3822 * If 'background' wasn't set by the user, try guessing the value,
3823 * depending on the terminal name. Only need to check for terminals
3824 * with a dark background, that can handle color.
3825 */
3826 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003827 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3828 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003830 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003831 /* don't mark it as set, when starting the GUI it may be
3832 * changed again */
3833 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 }
3835#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003836
3837#ifdef CURSOR_SHAPE
3838 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3839#endif
3840#ifdef FEAT_MOUSESHAPE
3841 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3842#endif
3843#ifdef FEAT_PRINTER
3844 (void)parse_printoptions(); /* parse 'printoptions' default value */
3845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846}
3847
3848/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003849 * Return "dark" or "light" depending on the kind of terminal.
3850 * This is just guessing! Recognized are:
3851 * "linux" Linux console
3852 * "screen.linux" Linux console with screen
3853 * "cygwin" Cygwin shell
3854 * "putty" Putty program
3855 * We also check the COLORFGBG environment variable, which is set by
3856 * rxvt and derivatives. This variable contains either two or three
3857 * values separated by semicolons; we want the last value in either
3858 * case. If this value is 0-6 or 8, our background is dark.
3859 */
3860 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003861term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003862{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003863#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003864 /* DOS console nearly always black */
3865 return (char_u *)"dark";
3866#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003867 char_u *p;
3868
Bram Moolenaarf740b292006-02-16 22:11:02 +00003869 if (STRCMP(T_NAME, "linux") == 0
3870 || STRCMP(T_NAME, "screen.linux") == 0
3871 || STRCMP(T_NAME, "cygwin") == 0
3872 || STRCMP(T_NAME, "putty") == 0
3873 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3874 && (p = vim_strrchr(p, ';')) != NULL
3875 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3876 && p[2] == NUL))
3877 return (char_u *)"dark";
3878 return (char_u *)"light";
3879#endif
3880}
3881
3882/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883 * Initialize the options, part three: After reading the .vimrc
3884 */
3885 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003886set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003888#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889/*
3890 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3891 * This is done after other initializations, where 'shell' might have been
3892 * set, but only if they have not been set before.
3893 */
3894 char_u *p;
3895 int idx_srr;
3896 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003897# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898 int idx_sp;
3899 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003900# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901
3902 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003903 if (idx_srr < 0)
3904 do_srr = FALSE;
3905 else
3906 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003907# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003909 if (idx_sp < 0)
3910 do_sp = FALSE;
3911 else
3912 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003913# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003914 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 if (p != NULL)
3916 {
3917 /*
3918 * Default for p_sp is "| tee", for p_srr is ">".
3919 * For known shells it is changed here to include stderr.
3920 */
3921 if ( fnamecmp(p, "csh") == 0
3922 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003923# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 || fnamecmp(p, "csh.exe") == 0
3925 || fnamecmp(p, "tcsh.exe") == 0
3926# endif
3927 )
3928 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003929# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 if (do_sp)
3931 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003932# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003934# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3938 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003939# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 if (do_srr)
3941 {
3942 p_srr = (char_u *)">&";
3943 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3944 }
3945 }
3946 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003947 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 if ( fnamecmp(p, "sh") == 0
3949 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003950 || fnamecmp(p, "mksh") == 0
3951 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003953 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003955 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003956# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003957 || fnamecmp(p, "cmd") == 0
3958 || fnamecmp(p, "sh.exe") == 0
3959 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003960 || fnamecmp(p, "mksh.exe") == 0
3961 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003963 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 || fnamecmp(p, "bash.exe") == 0
3965 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003967 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003969# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 if (do_sp)
3971 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003972# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003974# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003976# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3978 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003979# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003980 if (do_srr)
3981 {
3982 p_srr = (char_u *)">%s 2>&1";
3983 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3984 }
3985 }
3986 vim_free(p);
3987 }
3988#endif
3989
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003990#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003992 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3993 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 * This is done after other initializations, where 'shell' might have been
3995 * set, but only if they have not been set before. Default for p_shcf is
3996 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003997 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003999 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 {
4001 int idx3;
4002
4003 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004004 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 {
4006 p_shcf = (char_u *)"-c";
4007 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4008 }
4009
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004010# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011 /* Somehow Win32 requires the quotes around the redirection too */
4012 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004013 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 {
4015 p_sxq = (char_u *)"\"";
4016 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4017 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004018# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004020 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021 {
4022 p_shq = (char_u *)"\"";
4023 options[idx3].def_val[VI_DEFAULT] = p_shq;
4024 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004025# endif
4026 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004027 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4028 {
4029 int idx3;
4030
4031 /*
4032 * cmd.exe on Windows will strip the first and last double quote given
4033 * on the command line, e.g. most of the time things like:
4034 * cmd /c "my path/to/echo" "my args to echo"
4035 * become:
4036 * my path/to/echo" "my args to echo
4037 * when executed.
4038 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004039 * To avoid this, set shellxquote to surround the command in
4040 * parenthesis. This appears to make most commands work, without
4041 * breaking commands that worked previously, such as
4042 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004043 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004044 idx3 = findoption((char_u *)"sxq");
4045 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4046 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004047 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004048 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4049 }
4050
Bram Moolenaara64ba222012-02-12 23:23:31 +01004051 idx3 = findoption((char_u *)"shcf");
4052 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4053 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004054 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004055 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4056 }
4057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058#endif
4059
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004060 if (bufempty())
4061 {
4062 int idx_ffs = findoption((char_u *)"ffs");
4063
4064 /* Apply the first entry of 'fileformats' to the initial buffer. */
4065 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4066 set_fileformat(default_fileformat(), OPT_LOCAL);
4067 }
4068
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069#ifdef FEAT_TITLE
4070 set_title_defaults();
4071#endif
4072}
4073
4074#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4075/*
4076 * When 'helplang' is still at its default value, set it to "lang".
4077 * Only the first two characters of "lang" are used.
4078 */
4079 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004080set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081{
4082 int idx;
4083
4084 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4085 return;
4086 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004087 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 {
4089 if (options[idx].flags & P_ALLOCED)
4090 free_string_option(p_hlg);
4091 p_hlg = vim_strsave(lang);
4092 if (p_hlg == NULL)
4093 p_hlg = empty_option;
4094 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004095 {
4096 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4097 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4098 {
4099 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4100 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4101 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004103 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 options[idx].flags |= P_ALLOCED;
4105 }
4106}
4107#endif
4108
4109#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004110static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111
4112 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004113gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114{
4115 if (gui_get_lightness(gui.back_pixel) < 127)
4116 return (char_u *)"dark";
4117 return (char_u *)"light";
4118}
4119
4120/*
4121 * Option initializations that can only be done after opening the GUI window.
4122 */
4123 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004124init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125{
4126 /* Set the 'background' option according to the lightness of the
4127 * background color, unless the user has set it already. */
4128 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4129 {
4130 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4131 highlight_changed();
4132 }
4133}
4134#endif
4135
4136#ifdef FEAT_TITLE
4137/*
4138 * 'title' and 'icon' only default to true if they have not been set or reset
4139 * in .vimrc and we can read the old value.
4140 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4141 * they can be reset. This reduces startup time when using X on a remote
4142 * machine.
4143 */
4144 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004145set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146{
4147 int idx1;
4148 long val;
4149
4150 /*
4151 * If GUI is (going to be) used, we can always set the window title and
4152 * icon name. Saves a bit of time, because the X11 display server does
4153 * not need to be contacted.
4154 */
4155 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004156 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 {
4158#ifdef FEAT_GUI
4159 if (gui.starting || gui.in_use)
4160 val = TRUE;
4161 else
4162#endif
4163 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004164 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 p_title = val;
4166 }
4167 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004168 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 {
4170#ifdef FEAT_GUI
4171 if (gui.starting || gui.in_use)
4172 val = TRUE;
4173 else
4174#endif
4175 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004176 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 p_icon = val;
4178 }
4179}
4180#endif
4181
4182/*
4183 * Parse 'arg' for option settings.
4184 *
4185 * 'arg' may be IObuff, but only when no errors can be present and option
4186 * does not need to be expanded with option_expand().
4187 * "opt_flags":
4188 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004189 * OPT_GLOBAL for ":setglobal"
4190 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004192 * OPT_WINONLY to only set window-local options
4193 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194 *
4195 * returns FAIL if an error is detected, OK otherwise
4196 */
4197 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004198do_set(
4199 char_u *arg, /* option string (may be written to!) */
4200 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201{
4202 int opt_idx;
4203 char_u *errmsg;
4204 char_u errbuf[80];
4205 char_u *startarg;
4206 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4207 int nextchar; /* next non-white char after option name */
4208 int afterchar; /* character just after option name */
4209 int len;
4210 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004211 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 int key;
4213 long_u flags; /* flags for current option */
4214 char_u *varp = NULL; /* pointer to variable for current option */
4215 int did_show = FALSE; /* already showed one value */
4216 int adding; /* "opt+=arg" */
4217 int prepending; /* "opt^=arg" */
4218 int removing; /* "opt-=arg" */
4219 int cp_val = 0;
4220 char_u key_name[2];
4221
4222 if (*arg == NUL)
4223 {
4224 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004225 did_show = TRUE;
4226 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 }
4228
4229 while (*arg != NUL) /* loop to process all options */
4230 {
4231 errmsg = NULL;
4232 startarg = arg; /* remember for error message */
4233
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004234 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4235 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 {
4237 /*
4238 * ":set all" show all options.
4239 * ":set all&" set all options to their default value.
4240 */
4241 arg += 3;
4242 if (*arg == '&')
4243 {
4244 ++arg;
4245 /* Only for :set command set global value of local options. */
4246 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004247 didset_options();
4248 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004249 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004250 }
4251 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004252 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004253 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004254 did_show = TRUE;
4255 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004257 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004258 {
4259 showoptions(2, opt_flags);
4260 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004261 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262 arg += 7;
4263 }
4264 else
4265 {
4266 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004267 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268 {
4269 prefix = 0;
4270 arg += 2;
4271 }
4272 else if (STRNCMP(arg, "inv", 3) == 0)
4273 {
4274 prefix = 2;
4275 arg += 3;
4276 }
4277
4278 /* find end of name */
4279 key = 0;
4280 if (*arg == '<')
4281 {
4282 nextchar = 0;
4283 opt_idx = -1;
4284 /* look out for <t_>;> */
4285 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4286 len = 5;
4287 else
4288 {
4289 len = 1;
4290 while (arg[len] != NUL && arg[len] != '>')
4291 ++len;
4292 }
4293 if (arg[len] != '>')
4294 {
4295 errmsg = e_invarg;
4296 goto skip;
4297 }
4298 arg[len] = NUL; /* put NUL after name */
4299 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4300 opt_idx = findoption(arg + 1);
4301 arg[len++] = '>'; /* restore '>' */
4302 if (opt_idx == -1)
4303 key = find_key_option(arg + 1);
4304 }
4305 else
4306 {
4307 len = 0;
4308 /*
4309 * The two characters after "t_" may not be alphanumeric.
4310 */
4311 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4312 len = 4;
4313 else
4314 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4315 ++len;
4316 nextchar = arg[len];
4317 arg[len] = NUL; /* put NUL after name */
4318 opt_idx = findoption(arg);
4319 arg[len] = nextchar; /* restore nextchar */
4320 if (opt_idx == -1)
4321 key = find_key_option(arg);
4322 }
4323
4324 /* remember character after option name */
4325 afterchar = arg[len];
4326
4327 /* skip white space, allow ":set ai ?" */
4328 while (vim_iswhite(arg[len]))
4329 ++len;
4330
4331 adding = FALSE;
4332 prepending = FALSE;
4333 removing = FALSE;
4334 if (arg[len] != NUL && arg[len + 1] == '=')
4335 {
4336 if (arg[len] == '+')
4337 {
4338 adding = TRUE; /* "+=" */
4339 ++len;
4340 }
4341 else if (arg[len] == '^')
4342 {
4343 prepending = TRUE; /* "^=" */
4344 ++len;
4345 }
4346 else if (arg[len] == '-')
4347 {
4348 removing = TRUE; /* "-=" */
4349 ++len;
4350 }
4351 }
4352 nextchar = arg[len];
4353
4354 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4355 {
4356 errmsg = (char_u *)N_("E518: Unknown option");
4357 goto skip;
4358 }
4359
4360 if (opt_idx >= 0)
4361 {
4362 if (options[opt_idx].var == NULL) /* hidden option: skip */
4363 {
4364 /* Only give an error message when requesting the value of
4365 * a hidden option, ignore setting it. */
4366 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4367 && (!(options[opt_idx].flags & P_BOOL)
4368 || nextchar == '?'))
4369 errmsg = (char_u *)N_("E519: Option not supported");
4370 goto skip;
4371 }
4372
4373 flags = options[opt_idx].flags;
4374 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4375 }
4376 else
4377 {
4378 flags = P_STRING;
4379 if (key < 0)
4380 {
4381 key_name[0] = KEY2TERMCAP0(key);
4382 key_name[1] = KEY2TERMCAP1(key);
4383 }
4384 else
4385 {
4386 key_name[0] = KS_KEY;
4387 key_name[1] = (key & 0xff);
4388 }
4389 }
4390
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004391 /* Skip all options that are not window-local (used when showing
4392 * an already loaded buffer in a window). */
4393 if ((opt_flags & OPT_WINONLY)
4394 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4395 goto skip;
4396
Bram Moolenaara3227e22006-03-08 21:32:40 +00004397 /* Skip all options that are window-local (used for :vimgrep). */
4398 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4399 && options[opt_idx].var == VAR_WIN)
4400 goto skip;
4401
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004402 /* Disallow changing some options from modelines. */
4403 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004405 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004406 {
4407 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4408 goto skip;
4409 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004410#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004411 /* In diff mode some options are overruled. This avoids that
4412 * 'foldmethod' becomes "marker" instead of "diff" and that
4413 * "wrap" gets set. */
4414 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004415 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004416 && (options[opt_idx].indir == PV_FDM
4417 || options[opt_idx].indir == PV_WRAP))
4418 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 }
4421
4422#ifdef HAVE_SANDBOX
4423 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004424 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 {
4426 errmsg = (char_u *)_(e_sandbox);
4427 goto skip;
4428 }
4429#endif
4430
4431 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4432 {
4433 arg += len;
4434 cp_val = p_cp;
4435 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4436 {
4437 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4438 {
4439 cp_val = FALSE;
4440 arg += 3;
4441 }
4442 else /* "opt&vi": set to Vi default */
4443 {
4444 cp_val = TRUE;
4445 arg += 2;
4446 }
4447 }
4448 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4449 && arg[1] != NUL && !vim_iswhite(arg[1]))
4450 {
4451 errmsg = e_trailing;
4452 goto skip;
4453 }
4454 }
4455
4456 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004457 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4458 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004459 */
4460 if (nextchar == '?'
4461 || (prefix == 1
4462 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4463 && !(flags & P_BOOL)))
4464 {
4465 /*
4466 * print value
4467 */
4468 if (did_show)
4469 msg_putchar('\n'); /* cursor below last one */
4470 else
4471 {
4472 gotocmdline(TRUE); /* cursor at status line */
4473 did_show = TRUE; /* remember that we did a line */
4474 }
4475 if (opt_idx >= 0)
4476 {
4477 showoneopt(&options[opt_idx], opt_flags);
4478#ifdef FEAT_EVAL
4479 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004480 {
4481 /* Mention where the option was last set. */
4482 if (varp == options[opt_idx].var)
4483 last_set_msg(options[opt_idx].scriptID);
4484 else if ((int)options[opt_idx].indir & PV_WIN)
4485 last_set_msg(curwin->w_p_scriptID[
4486 (int)options[opt_idx].indir & PV_MASK]);
4487 else if ((int)options[opt_idx].indir & PV_BUF)
4488 last_set_msg(curbuf->b_p_scriptID[
4489 (int)options[opt_idx].indir & PV_MASK]);
4490 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004491#endif
4492 }
4493 else
4494 {
4495 char_u *p;
4496
4497 p = find_termcode(key_name);
4498 if (p == NULL)
4499 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004500 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004501 goto skip;
4502 }
4503 else
4504 (void)show_one_termcode(key_name, p, TRUE);
4505 }
4506 if (nextchar != '?'
4507 && nextchar != NUL && !vim_iswhite(afterchar))
4508 errmsg = e_trailing;
4509 }
4510 else
4511 {
4512 if (flags & P_BOOL) /* boolean */
4513 {
4514 if (nextchar == '=' || nextchar == ':')
4515 {
4516 errmsg = e_invarg;
4517 goto skip;
4518 }
4519
4520 /*
4521 * ":set opt!": invert
4522 * ":set opt&": reset to default value
4523 * ":set opt<": reset to global value
4524 */
4525 if (nextchar == '!')
4526 value = *(int *)(varp) ^ 1;
4527 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004528 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004529 ((flags & P_VI_DEF) || cp_val)
4530 ? VI_DEFAULT : VIM_DEFAULT];
4531 else if (nextchar == '<')
4532 {
4533 /* For 'autoread' -1 means to use global value. */
4534 if ((int *)varp == &curbuf->b_p_ar
4535 && opt_flags == OPT_LOCAL)
4536 value = -1;
4537 else
4538 value = *(int *)get_varp_scope(&(options[opt_idx]),
4539 OPT_GLOBAL);
4540 }
4541 else
4542 {
4543 /*
4544 * ":set invopt": invert
4545 * ":set opt" or ":set noopt": set or reset
4546 */
4547 if (nextchar != NUL && !vim_iswhite(afterchar))
4548 {
4549 errmsg = e_trailing;
4550 goto skip;
4551 }
4552 if (prefix == 2) /* inv */
4553 value = *(int *)(varp) ^ 1;
4554 else
4555 value = prefix;
4556 }
4557
4558 errmsg = set_bool_option(opt_idx, varp, (int)value,
4559 opt_flags);
4560 }
4561 else /* numeric or string */
4562 {
4563 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4564 || prefix != 1)
4565 {
4566 errmsg = e_invarg;
4567 goto skip;
4568 }
4569
4570 if (flags & P_NUM) /* numeric */
4571 {
4572 /*
4573 * Different ways to set a number option:
4574 * & set to default value
4575 * < set to global value
4576 * <xx> accept special key codes for 'wildchar'
4577 * c accept any non-digit for 'wildchar'
4578 * [-]0-9 set number
4579 * other error
4580 */
4581 ++arg;
4582 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004583 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004584 ((flags & P_VI_DEF) || cp_val)
4585 ? VI_DEFAULT : VIM_DEFAULT];
4586 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004587 {
4588 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4589 * use the global value. */
4590 if ((long *)varp == &curbuf->b_p_ul
4591 && opt_flags == OPT_LOCAL)
4592 value = NO_LOCAL_UNDOLEVEL;
4593 else
4594 value = *(long *)get_varp_scope(
4595 &(options[opt_idx]), OPT_GLOBAL);
4596 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004597 else if (((long *)varp == &p_wc
4598 || (long *)varp == &p_wcm)
4599 && (*arg == '<'
4600 || *arg == '^'
4601 || ((!arg[1] || vim_iswhite(arg[1]))
4602 && !VIM_ISDIGIT(*arg))))
4603 {
4604 value = string_to_key(arg);
4605 if (value == 0 && (long *)varp != &p_wcm)
4606 {
4607 errmsg = e_invarg;
4608 goto skip;
4609 }
4610 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4612 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004613 /* Allow negative (for 'undolevels'), octal and
4614 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004615 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4616 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4618 {
4619 errmsg = e_invarg;
4620 goto skip;
4621 }
4622 }
4623 else
4624 {
4625 errmsg = (char_u *)N_("E521: Number required after =");
4626 goto skip;
4627 }
4628
4629 if (adding)
4630 value = *(long *)varp + value;
4631 if (prepending)
4632 value = *(long *)varp * value;
4633 if (removing)
4634 value = *(long *)varp - value;
4635 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004636 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004637 }
4638 else if (opt_idx >= 0) /* string */
4639 {
4640 char_u *save_arg = NULL;
4641 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004642 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004643 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004644 char_u *origval = NULL;
4645#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4646 char_u *saved_origval = NULL;
4647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004648 unsigned newlen;
4649 int comma;
4650 int bs;
4651 int new_value_alloced; /* new string option
4652 was allocated */
4653
4654 /* When using ":set opt=val" for a global option
4655 * with a local value the local value will be
4656 * reset, use the global value here. */
4657 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004658 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004659 varp = options[opt_idx].var;
4660
4661 /* The old value is kept until we are sure that the
4662 * new value is valid. */
4663 oldval = *(char_u **)varp;
4664 if (nextchar == '&') /* set to default val */
4665 {
4666 newval = options[opt_idx].def_val[
4667 ((flags & P_VI_DEF) || cp_val)
4668 ? VI_DEFAULT : VIM_DEFAULT];
4669 if ((char_u **)varp == &p_bg)
4670 {
4671 /* guess the value of 'background' */
4672#ifdef FEAT_GUI
4673 if (gui.in_use)
4674 newval = gui_bg_default();
4675 else
4676#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004677 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004678 }
4679
4680 /* expand environment variables and ~ (since the
4681 * default value was already expanded, only
4682 * required when an environment variable was set
4683 * later */
4684 if (newval == NULL)
4685 newval = empty_option;
4686 else
4687 {
4688 s = option_expand(opt_idx, newval);
4689 if (s == NULL)
4690 s = newval;
4691 newval = vim_strsave(s);
4692 }
4693 new_value_alloced = TRUE;
4694 }
4695 else if (nextchar == '<') /* set to global val */
4696 {
4697 newval = vim_strsave(*(char_u **)get_varp_scope(
4698 &(options[opt_idx]), OPT_GLOBAL));
4699 new_value_alloced = TRUE;
4700 }
4701 else
4702 {
4703 ++arg; /* jump to after the '=' or ':' */
4704
4705 /*
4706 * Set 'keywordprg' to ":help" if an empty
4707 * value was passed to :set by the user.
4708 * Misuse errbuf[] for the resulting string.
4709 */
4710 if (varp == (char_u *)&p_kp
4711 && (*arg == NUL || *arg == ' '))
4712 {
4713 STRCPY(errbuf, ":help");
4714 save_arg = arg;
4715 arg = errbuf;
4716 }
4717 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004718 * Convert 'backspace' number to string, for
4719 * adding, prepending and removing string.
4720 */
4721 else if (varp == (char_u *)&p_bs
4722 && VIM_ISDIGIT(**(char_u **)varp))
4723 {
4724 i = getdigits((char_u **)varp);
4725 switch (i)
4726 {
4727 case 0:
4728 *(char_u **)varp = empty_option;
4729 break;
4730 case 1:
4731 *(char_u **)varp = vim_strsave(
4732 (char_u *)"indent,eol");
4733 break;
4734 case 2:
4735 *(char_u **)varp = vim_strsave(
4736 (char_u *)"indent,eol,start");
4737 break;
4738 }
4739 vim_free(oldval);
4740 oldval = *(char_u **)varp;
4741 }
4742 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004743 * Convert 'whichwrap' number to string, for
4744 * backwards compatibility with Vim 3.0.
4745 * Misuse errbuf[] for the resulting string.
4746 */
4747 else if (varp == (char_u *)&p_ww
4748 && VIM_ISDIGIT(*arg))
4749 {
4750 *errbuf = NUL;
4751 i = getdigits(&arg);
4752 if (i & 1)
4753 STRCAT(errbuf, "b,");
4754 if (i & 2)
4755 STRCAT(errbuf, "s,");
4756 if (i & 4)
4757 STRCAT(errbuf, "h,l,");
4758 if (i & 8)
4759 STRCAT(errbuf, "<,>,");
4760 if (i & 16)
4761 STRCAT(errbuf, "[,],");
4762 if (*errbuf != NUL) /* remove trailing , */
4763 errbuf[STRLEN(errbuf) - 1] = NUL;
4764 save_arg = arg;
4765 arg = errbuf;
4766 }
4767 /*
4768 * Remove '>' before 'dir' and 'bdir', for
4769 * backwards compatibility with version 3.0
4770 */
4771 else if ( *arg == '>'
4772 && (varp == (char_u *)&p_dir
4773 || varp == (char_u *)&p_bdir))
4774 {
4775 ++arg;
4776 }
4777
4778 /* When setting the local value of a global
4779 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004780 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004781 && (opt_flags & OPT_LOCAL))
4782 origval = *(char_u **)get_varp(
4783 &options[opt_idx]);
4784 else
4785 origval = oldval;
4786
4787 /*
4788 * Copy the new string into allocated memory.
4789 * Can't use set_string_option_direct(), because
4790 * we need to remove the backslashes.
4791 */
4792 /* get a bit too much */
4793 newlen = (unsigned)STRLEN(arg) + 1;
4794 if (adding || prepending || removing)
4795 newlen += (unsigned)STRLEN(origval) + 1;
4796 newval = alloc(newlen);
4797 if (newval == NULL) /* out of mem, don't change */
4798 break;
4799 s = newval;
4800
4801 /*
4802 * Copy the string, skip over escaped chars.
4803 * For MS-DOS and WIN32 backslashes before normal
4804 * file name characters are not removed, and keep
4805 * backslash at start, for "\\machine\path", but
4806 * do remove it for "\\\\machine\\path".
4807 * The reverse is found in ExpandOldSetting().
4808 */
4809 while (*arg && !vim_iswhite(*arg))
4810 {
4811 if (*arg == '\\' && arg[1] != NUL
4812#ifdef BACKSLASH_IN_FILENAME
4813 && !((flags & P_EXPAND)
4814 && vim_isfilec(arg[1])
4815 && (arg[1] != '\\'
4816 || (s == newval
4817 && arg[2] != '\\')))
4818#endif
4819 )
4820 ++arg; /* remove backslash */
4821#ifdef FEAT_MBYTE
4822 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004823 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004824 {
4825 /* copy multibyte char */
4826 mch_memmove(s, arg, (size_t)i);
4827 arg += i;
4828 s += i;
4829 }
4830 else
4831#endif
4832 *s++ = *arg++;
4833 }
4834 *s = NUL;
4835
4836 /*
4837 * Expand environment variables and ~.
4838 * Don't do it when adding without inserting a
4839 * comma.
4840 */
4841 if (!(adding || prepending || removing)
4842 || (flags & P_COMMA))
4843 {
4844 s = option_expand(opt_idx, newval);
4845 if (s != NULL)
4846 {
4847 vim_free(newval);
4848 newlen = (unsigned)STRLEN(s) + 1;
4849 if (adding || prepending || removing)
4850 newlen += (unsigned)STRLEN(origval) + 1;
4851 newval = alloc(newlen);
4852 if (newval == NULL)
4853 break;
4854 STRCPY(newval, s);
4855 }
4856 }
4857
4858 /* locate newval[] in origval[] when removing it
4859 * and when adding to avoid duplicates */
4860 i = 0; /* init for GCC */
4861 if (removing || (flags & P_NODUP))
4862 {
4863 i = (int)STRLEN(newval);
4864 bs = 0;
4865 for (s = origval; *s; ++s)
4866 {
4867 if ((!(flags & P_COMMA)
4868 || s == origval
4869 || (s[-1] == ',' && !(bs & 1)))
4870 && STRNCMP(s, newval, i) == 0
4871 && (!(flags & P_COMMA)
4872 || s[i] == ','
4873 || s[i] == NUL))
4874 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004875 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004876 * even number of backslashes or a single
4877 * backslash preceded by a comma before it
4878 * is recognized as a separator */
4879 if ((s > origval + 1
4880 && s[-1] == '\\'
4881 && s[-2] != ',')
4882 || (s == origval + 1
4883 && s[-1] == '\\'))
4884
Bram Moolenaar071d4272004-06-13 20:20:40 +00004885 ++bs;
4886 else
4887 bs = 0;
4888 }
4889
4890 /* do not add if already there */
4891 if ((adding || prepending) && *s)
4892 {
4893 prepending = FALSE;
4894 adding = FALSE;
4895 STRCPY(newval, origval);
4896 }
4897 }
4898
4899 /* concatenate the two strings; add a ',' if
4900 * needed */
4901 if (adding || prepending)
4902 {
4903 comma = ((flags & P_COMMA) && *origval != NUL
4904 && *newval != NUL);
4905 if (adding)
4906 {
4907 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004908 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004909 if (comma && i > 1
4910 && (flags & P_ONECOMMA) == P_ONECOMMA
4911 && origval[i - 1] == ','
4912 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004913 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004914 mch_memmove(newval + i + comma, newval,
4915 STRLEN(newval) + 1);
4916 mch_memmove(newval, origval, (size_t)i);
4917 }
4918 else
4919 {
4920 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004921 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004922 }
4923 if (comma)
4924 newval[i] = ',';
4925 }
4926
4927 /* Remove newval[] from origval[]. (Note: "i" has
4928 * been set above and is used here). */
4929 if (removing)
4930 {
4931 STRCPY(newval, origval);
4932 if (*s)
4933 {
4934 /* may need to remove a comma */
4935 if (flags & P_COMMA)
4936 {
4937 if (s == origval)
4938 {
4939 /* include comma after string */
4940 if (s[i] == ',')
4941 ++i;
4942 }
4943 else
4944 {
4945 /* include comma before string */
4946 --s;
4947 ++i;
4948 }
4949 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004950 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004951 }
4952 }
4953
4954 if (flags & P_FLAGLIST)
4955 {
4956 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004957 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004958 {
4959 /* if options have P_FLAGLIST and
4960 * P_ONECOMMA such as 'whichwrap' */
4961 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004962 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004963 if (*s != ',' && *(s + 1) == ','
4964 && vim_strchr(s + 2, *s) != NULL)
4965 {
4966 /* Remove the duplicated value and
4967 * the next comma. */
4968 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004969 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004971 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004972 else
4973 {
4974 if ((!(flags & P_COMMA) || *s != ',')
4975 && vim_strchr(s + 1, *s) != NULL)
4976 {
4977 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004978 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004979 }
4980 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004981 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004982 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004983 }
4984
4985 if (save_arg != NULL) /* number for 'whichwrap' */
4986 arg = save_arg;
4987 new_value_alloced = TRUE;
4988 }
4989
4990 /* Set the new value. */
4991 *(char_u **)(varp) = newval;
4992
Bram Moolenaar53744302015-07-17 17:38:22 +02004993#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004994 if (!starting
4995# ifdef FEAT_CRYPT
4996 && options[opt_idx].indir != PV_KEY
4997# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004998 && origval != NULL)
4999 /* origval may be freed by
5000 * did_set_string_option(), make a copy. */
5001 saved_origval = vim_strsave(origval);
5002#endif
5003
Bram Moolenaar071d4272004-06-13 20:20:40 +00005004 /* Handle side effects, and set the global value for
5005 * ":set" on local options. */
5006 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5007 new_value_alloced, oldval, errbuf, opt_flags);
5008
5009 /* If error detected, print the error message. */
5010 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005011 {
5012#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5013 vim_free(saved_origval);
5014#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005015 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005016 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005017#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5018 if (saved_origval != NULL)
5019 {
5020 char_u buf_type[7];
5021
5022 sprintf((char *)buf_type, "%s",
5023 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005024 set_vim_var_string(VV_OPTION_NEW,
5025 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005026 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5027 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5028 apply_autocmds(EVENT_OPTIONSET,
5029 (char_u *)options[opt_idx].fullname,
5030 NULL, FALSE, NULL);
5031 reset_v_option_vars();
5032 vim_free(saved_origval);
5033 }
5034#endif
5035
Bram Moolenaar071d4272004-06-13 20:20:40 +00005036 }
5037 else /* key code option */
5038 {
5039 char_u *p;
5040
5041 if (nextchar == '&')
5042 {
5043 if (add_termcap_entry(key_name, TRUE) == FAIL)
5044 errmsg = (char_u *)N_("E522: Not found in termcap");
5045 }
5046 else
5047 {
5048 ++arg; /* jump to after the '=' or ':' */
5049 for (p = arg; *p && !vim_iswhite(*p); ++p)
5050 if (*p == '\\' && p[1] != NUL)
5051 ++p;
5052 nextchar = *p;
5053 *p = NUL;
5054 add_termcode(key_name, arg, FALSE);
5055 *p = nextchar;
5056 }
5057 if (full_screen)
5058 ttest(FALSE);
5059 redraw_all_later(CLEAR);
5060 }
5061 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005062
Bram Moolenaar071d4272004-06-13 20:20:40 +00005063 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005064 did_set_option(opt_idx, opt_flags,
5065 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005066 }
5067
5068skip:
5069 /*
5070 * Advance to next argument.
5071 * - skip until a blank found, taking care of backslashes
5072 * - skip blanks
5073 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5074 */
5075 for (i = 0; i < 2 ; ++i)
5076 {
5077 while (*arg != NUL && !vim_iswhite(*arg))
5078 if (*arg++ == '\\' && *arg != NUL)
5079 ++arg;
5080 arg = skipwhite(arg);
5081 if (*arg != '=')
5082 break;
5083 }
5084 }
5085
5086 if (errmsg != NULL)
5087 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005088 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005089 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005090 if (i + (arg - startarg) < IOSIZE)
5091 {
5092 /* append the argument with the error */
5093 STRCAT(IObuff, ": ");
5094 mch_memmove(IObuff + i, startarg, (arg - startarg));
5095 IObuff[i + (arg - startarg)] = NUL;
5096 }
5097 /* make sure all characters are printable */
5098 trans_characters(IObuff, IOSIZE);
5099
5100 ++no_wait_return; /* wait_return done later */
5101 emsg(IObuff); /* show error highlighted */
5102 --no_wait_return;
5103
5104 return FAIL;
5105 }
5106
5107 arg = skipwhite(arg);
5108 }
5109
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005110theend:
5111 if (silent_mode && did_show)
5112 {
5113 /* After displaying option values in silent mode. */
5114 silent_mode = FALSE;
5115 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5116 msg_putchar('\n');
5117 cursor_on(); /* msg_start() switches it off */
5118 out_flush();
5119 silent_mode = TRUE;
5120 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5121 }
5122
Bram Moolenaar071d4272004-06-13 20:20:40 +00005123 return OK;
5124}
5125
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005126/*
5127 * Call this when an option has been given a new value through a user command.
5128 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5129 */
5130 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005131did_set_option(
5132 int opt_idx,
5133 int opt_flags, /* possibly with OPT_MODELINE */
5134 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005135{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005136 long_u *p;
5137
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005138 options[opt_idx].flags |= P_WAS_SET;
5139
5140 /* When an option is set in the sandbox, from a modeline or in secure mode
5141 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005142 * flag. */
5143 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005144 if (secure
5145#ifdef HAVE_SANDBOX
5146 || sandbox != 0
5147#endif
5148 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005149 *p = *p | P_INSECURE;
5150 else if (new_value)
5151 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005152}
5153
Bram Moolenaar071d4272004-06-13 20:20:40 +00005154 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005155illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005156{
5157 if (errbuf == NULL)
5158 return (char_u *)"";
5159 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005160 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005161 return errbuf;
5162}
5163
5164/*
5165 * Convert a key name or string into a key value.
5166 * Used for 'wildchar' and 'cedit' options.
5167 */
5168 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005169string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005170{
5171 if (*arg == '<')
5172 return find_key_option(arg + 1);
5173 if (*arg == '^')
5174 return Ctrl_chr(arg[1]);
5175 return *arg;
5176}
5177
5178#ifdef FEAT_CMDWIN
5179/*
5180 * Check value of 'cedit' and set cedit_key.
5181 * Returns NULL if value is OK, error message otherwise.
5182 */
5183 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005184check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185{
5186 int n;
5187
5188 if (*p_cedit == NUL)
5189 cedit_key = -1;
5190 else
5191 {
5192 n = string_to_key(p_cedit);
5193 if (vim_isprintc(n))
5194 return e_invarg;
5195 cedit_key = n;
5196 }
5197 return NULL;
5198}
5199#endif
5200
5201#ifdef FEAT_TITLE
5202/*
5203 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5204 * maketitle() to create and display it.
5205 * When switching the title or icon off, call mch_restore_title() to get
5206 * the old value back.
5207 */
5208 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005209did_set_title(
5210 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211{
5212 if (starting != NO_SCREEN
5213#ifdef FEAT_GUI
5214 && !gui.starting
5215#endif
5216 )
5217 {
5218 maketitle();
5219 if (icon)
5220 {
5221 if (!p_icon)
5222 mch_restore_title(2);
5223 }
5224 else
5225 {
5226 if (!p_title)
5227 mch_restore_title(1);
5228 }
5229 }
5230}
5231#endif
5232
5233/*
5234 * set_options_bin - called when 'bin' changes value.
5235 */
5236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005237set_options_bin(
5238 int oldval,
5239 int newval,
5240 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005241{
5242 /*
5243 * The option values that are changed when 'bin' changes are
5244 * copied when 'bin is set and restored when 'bin' is reset.
5245 */
5246 if (newval)
5247 {
5248 if (!oldval) /* switched on */
5249 {
5250 if (!(opt_flags & OPT_GLOBAL))
5251 {
5252 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5253 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5254 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5255 curbuf->b_p_et_nobin = curbuf->b_p_et;
5256 }
5257 if (!(opt_flags & OPT_LOCAL))
5258 {
5259 p_tw_nobin = p_tw;
5260 p_wm_nobin = p_wm;
5261 p_ml_nobin = p_ml;
5262 p_et_nobin = p_et;
5263 }
5264 }
5265
5266 if (!(opt_flags & OPT_GLOBAL))
5267 {
5268 curbuf->b_p_tw = 0; /* no automatic line wrap */
5269 curbuf->b_p_wm = 0; /* no automatic line wrap */
5270 curbuf->b_p_ml = 0; /* no modelines */
5271 curbuf->b_p_et = 0; /* no expandtab */
5272 }
5273 if (!(opt_flags & OPT_LOCAL))
5274 {
5275 p_tw = 0;
5276 p_wm = 0;
5277 p_ml = FALSE;
5278 p_et = FALSE;
5279 p_bin = TRUE; /* needed when called for the "-b" argument */
5280 }
5281 }
5282 else if (oldval) /* switched off */
5283 {
5284 if (!(opt_flags & OPT_GLOBAL))
5285 {
5286 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5287 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5288 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5289 curbuf->b_p_et = curbuf->b_p_et_nobin;
5290 }
5291 if (!(opt_flags & OPT_LOCAL))
5292 {
5293 p_tw = p_tw_nobin;
5294 p_wm = p_wm_nobin;
5295 p_ml = p_ml_nobin;
5296 p_et = p_et_nobin;
5297 }
5298 }
5299}
5300
5301#ifdef FEAT_VIMINFO
5302/*
5303 * Find the parameter represented by the given character (eg ', :, ", or /),
5304 * and return its associated value in the 'viminfo' string.
5305 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005306 * If the parameter is not specified in the string or there is no following
5307 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308 */
5309 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005310get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005311{
5312 char_u *p;
5313
5314 p = find_viminfo_parameter(type);
5315 if (p != NULL && VIM_ISDIGIT(*p))
5316 return atoi((char *)p);
5317 return -1;
5318}
5319
5320/*
5321 * Find the parameter represented by the given character (eg ''', ':', '"', or
5322 * '/') in the 'viminfo' option and return a pointer to the string after it.
5323 * Return NULL if the parameter is not specified in the string.
5324 */
5325 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005326find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327{
5328 char_u *p;
5329
5330 for (p = p_viminfo; *p; ++p)
5331 {
5332 if (*p == type)
5333 return p + 1;
5334 if (*p == 'n') /* 'n' is always the last one */
5335 break;
5336 p = vim_strchr(p, ','); /* skip until next ',' */
5337 if (p == NULL) /* hit the end without finding parameter */
5338 break;
5339 }
5340 return NULL;
5341}
5342#endif
5343
5344/*
5345 * Expand environment variables for some string options.
5346 * These string options cannot be indirect!
5347 * If "val" is NULL expand the current value of the option.
5348 * Return pointer to NameBuff, or NULL when not expanded.
5349 */
5350 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005351option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352{
5353 /* if option doesn't need expansion nothing to do */
5354 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5355 return NULL;
5356
5357 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5358 * expand_env() would truncate the string. */
5359 if (val != NULL && STRLEN(val) > MAXPATHL)
5360 return NULL;
5361
5362 if (val == NULL)
5363 val = *(char_u **)options[opt_idx].var;
5364
5365 /*
5366 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5367 * Escape spaces when expanding 'tags', they are used to separate file
5368 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005369 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005370 */
5371 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005372 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005373#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005374 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5375#endif
5376 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005377 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5378 return NULL;
5379
5380 return NameBuff;
5381}
5382
5383/*
5384 * After setting various option values: recompute variables that depend on
5385 * option values.
5386 */
5387 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005388didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005389{
5390 /* initialize the table for 'iskeyword' et.al. */
5391 (void)init_chartab();
5392
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005393#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005394 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005396 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005397 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005398#ifdef FEAT_SESSION
5399 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5400 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5401#endif
5402#ifdef FEAT_FOLDING
5403 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5404#endif
5405 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005406 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005407#ifdef FEAT_VIRTUALEDIT
5408 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5409#endif
5410#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5411 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5412#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005413#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005414 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005415 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005416 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005417 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005419#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5420 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5421#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005422#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005423 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5424#endif
5425#ifdef FEAT_CMDWIN
5426 /* set cedit_key */
5427 (void)check_cedit();
5428#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005429#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005430 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005431#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005432#ifdef FEAT_LINEBREAK
5433 /* initialize the table for 'breakat'. */
5434 fill_breakat_flags();
5435#endif
5436
5437}
5438
5439/*
5440 * More side effects of setting options.
5441 */
5442 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005443didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005444{
5445 /* Initialize the highlight_attr[] table. */
5446 (void)highlight_changed();
5447
5448 /* Parse default for 'wildmode' */
5449 check_opt_wim();
5450
5451 (void)set_chars_option(&p_lcs);
5452#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5453 /* Parse default for 'fillchars'. */
5454 (void)set_chars_option(&p_fcs);
5455#endif
5456
5457#ifdef FEAT_CLIPBOARD
5458 /* Parse default for 'clipboard' */
5459 (void)check_clipboard_option();
5460#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005461}
5462
5463/*
5464 * Check for string options that are NULL (normally only termcap options).
5465 */
5466 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005467check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005468{
5469 int opt_idx;
5470
5471 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5472 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5473 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5474}
5475
5476/*
5477 * Check string options in a buffer for NULL value.
5478 */
5479 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005480check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005481{
5482#if defined(FEAT_QUICKFIX)
5483 check_string_option(&buf->b_p_bh);
5484 check_string_option(&buf->b_p_bt);
5485#endif
5486#ifdef FEAT_MBYTE
5487 check_string_option(&buf->b_p_fenc);
5488#endif
5489 check_string_option(&buf->b_p_ff);
5490#ifdef FEAT_FIND_ID
5491 check_string_option(&buf->b_p_def);
5492 check_string_option(&buf->b_p_inc);
5493# ifdef FEAT_EVAL
5494 check_string_option(&buf->b_p_inex);
5495# endif
5496#endif
5497#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5498 check_string_option(&buf->b_p_inde);
5499 check_string_option(&buf->b_p_indk);
5500#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005501#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5502 check_string_option(&buf->b_p_bexpr);
5503#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005504#if defined(FEAT_CRYPT)
5505 check_string_option(&buf->b_p_cm);
5506#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005507 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005508#if defined(FEAT_EVAL)
5509 check_string_option(&buf->b_p_fex);
5510#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511#ifdef FEAT_CRYPT
5512 check_string_option(&buf->b_p_key);
5513#endif
5514 check_string_option(&buf->b_p_kp);
5515 check_string_option(&buf->b_p_mps);
5516 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005517 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005518 check_string_option(&buf->b_p_isk);
5519#ifdef FEAT_COMMENTS
5520 check_string_option(&buf->b_p_com);
5521#endif
5522#ifdef FEAT_FOLDING
5523 check_string_option(&buf->b_p_cms);
5524#endif
5525 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005526#ifdef FEAT_TEXTOBJ
5527 check_string_option(&buf->b_p_qe);
5528#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529#ifdef FEAT_SYN_HL
5530 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005531 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005532#endif
5533#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005534 check_string_option(&buf->b_s.b_p_spc);
5535 check_string_option(&buf->b_s.b_p_spf);
5536 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537#endif
5538#ifdef FEAT_SEARCHPATH
5539 check_string_option(&buf->b_p_sua);
5540#endif
5541#ifdef FEAT_CINDENT
5542 check_string_option(&buf->b_p_cink);
5543 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005544 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545#endif
5546#ifdef FEAT_AUTOCMD
5547 check_string_option(&buf->b_p_ft);
5548#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5550 check_string_option(&buf->b_p_cinw);
5551#endif
5552#ifdef FEAT_INS_EXPAND
5553 check_string_option(&buf->b_p_cpt);
5554#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005555#ifdef FEAT_COMPL_FUNC
5556 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005557 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005558#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559#ifdef FEAT_KEYMAP
5560 check_string_option(&buf->b_p_keymap);
5561#endif
5562#ifdef FEAT_QUICKFIX
5563 check_string_option(&buf->b_p_gp);
5564 check_string_option(&buf->b_p_mp);
5565 check_string_option(&buf->b_p_efm);
5566#endif
5567 check_string_option(&buf->b_p_ep);
5568 check_string_option(&buf->b_p_path);
5569 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005570 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571#ifdef FEAT_INS_EXPAND
5572 check_string_option(&buf->b_p_dict);
5573 check_string_option(&buf->b_p_tsr);
5574#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005575#ifdef FEAT_LISP
5576 check_string_option(&buf->b_p_lw);
5577#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005578 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005579}
5580
5581/*
5582 * Free the string allocated for an option.
5583 * Checks for the string being empty_option. This may happen if we're out of
5584 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5585 * check_options().
5586 * Does NOT check for P_ALLOCED flag!
5587 */
5588 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005589free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590{
5591 if (p != empty_option)
5592 vim_free(p);
5593}
5594
5595 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005596clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005597{
5598 if (*pp != empty_option)
5599 vim_free(*pp);
5600 *pp = empty_option;
5601}
5602
5603 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005604check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605{
5606 if (*pp == NULL)
5607 *pp = empty_option;
5608}
5609
5610/*
5611 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5612 */
5613 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005614set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615{
5616 int opt_idx;
5617
5618 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5619 if (options[opt_idx].var == (char_u *)p)
5620 {
5621 options[opt_idx].flags |= P_ALLOCED;
5622 return;
5623 }
5624 return; /* cannot happen: didn't find it! */
5625}
5626
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005627#if defined(FEAT_EVAL) || defined(PROTO)
5628/*
5629 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5630 * Return FALSE when it wasn't.
5631 * Return -1 for an unknown option.
5632 */
5633 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005634was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005635{
5636 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005637 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005638
5639 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005640 {
5641 flagp = insecure_flag(idx, opt_flags);
5642 return (*flagp & P_INSECURE) != 0;
5643 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005644 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005645 return -1;
5646}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005647
5648/*
5649 * Get a pointer to the flags used for the P_INSECURE flag of option
5650 * "opt_idx". For some local options a local flags field is used.
5651 */
5652 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005653insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005654{
5655 if (opt_flags & OPT_LOCAL)
5656 switch ((int)options[opt_idx].indir)
5657 {
5658#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005659 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005660#endif
5661#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005662# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005663 case PV_FDE: return &curwin->w_p_fde_flags;
5664 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005665# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005666# ifdef FEAT_BEVAL
5667 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5668# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005669# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005670 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005671# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005672 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005673# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005674 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005675# endif
5676#endif
5677 }
5678
5679 /* Nothing special, return global flags field. */
5680 return &options[opt_idx].flags;
5681}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005682#endif
5683
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005684#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005685static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005686
5687/*
5688 * Redraw the window title and/or tab page text later.
5689 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005690static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005691{
5692 need_maketitle = TRUE;
5693# ifdef FEAT_WINDOWS
5694 redraw_tabline = TRUE;
5695# endif
5696}
5697#endif
5698
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699/*
5700 * Set a string option to a new value (without checking the effect).
5701 * The string is copied into allocated memory.
5702 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005703 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005704 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705 */
5706 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005707set_string_option_direct(
5708 char_u *name,
5709 int opt_idx,
5710 char_u *val,
5711 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5712 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713{
5714 char_u *s;
5715 char_u **varp;
5716 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005717 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005718
Bram Moolenaar89d40322006-08-29 15:30:07 +00005719 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005720 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005721 idx = findoption(name);
5722 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005723 {
5724 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005725 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005727 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728 }
5729
Bram Moolenaar89d40322006-08-29 15:30:07 +00005730 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731 return;
5732
5733 s = vim_strsave(val);
5734 if (s != NULL)
5735 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005736 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005738 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739 free_string_option(*varp);
5740 *varp = s;
5741
5742 /* For buffer/window local option may also set the global value. */
5743 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005744 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745
Bram Moolenaar89d40322006-08-29 15:30:07 +00005746 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747
5748 /* When setting both values of a global option with a local value,
5749 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005750 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751 {
5752 free_string_option(*varp);
5753 *varp = empty_option;
5754 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005755# ifdef FEAT_EVAL
5756 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005757 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005758 set_sid == 0 ? current_SID : set_sid);
5759# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005760 }
5761}
5762
5763/*
5764 * Set global value for string option when it's a local option.
5765 */
5766 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005767set_string_option_global(
5768 int opt_idx, /* option index */
5769 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770{
5771 char_u **p, *s;
5772
5773 /* the global value is always allocated */
5774 if (options[opt_idx].var == VAR_WIN)
5775 p = (char_u **)GLOBAL_WO(varp);
5776 else
5777 p = (char_u **)options[opt_idx].var;
5778 if (options[opt_idx].indir != PV_NONE
5779 && p != varp
5780 && (s = vim_strsave(*varp)) != NULL)
5781 {
5782 free_string_option(*p);
5783 *p = s;
5784 }
5785}
5786
5787/*
5788 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005789 *
5790 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005791 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005792 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005793set_string_option(
5794 int opt_idx,
5795 char_u *value,
5796 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005797{
5798 char_u *s;
5799 char_u **varp;
5800 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005801#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5802 char_u *saved_oldval = NULL;
5803#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005804 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005805
5806 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005807 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005808
5809 s = vim_strsave(value);
5810 if (s != NULL)
5811 {
5812 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5813 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005814 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005815 ? OPT_GLOBAL : OPT_LOCAL)
5816 : opt_flags);
5817 oldval = *varp;
5818 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005819
5820#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005821 if (!starting
5822# ifdef FEAT_CRYPT
5823 && options[opt_idx].indir != PV_KEY
5824# endif
5825 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005826 saved_oldval = vim_strsave(oldval);
5827#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005828 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5829 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005830 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005831
5832 /* call autocomamnd after handling side effects */
5833#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5834 if (saved_oldval != NULL)
5835 {
5836 char_u buf_type[7];
5837 sprintf((char *)buf_type, "%s",
5838 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005839 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5840 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005841 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5842 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5843 reset_v_option_vars();
5844 vim_free(saved_oldval);
5845 }
5846#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005848 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849}
5850
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005851#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005853 * Return TRUE if "val" is a valid 'filetype' name.
5854 * Also used for 'syntax' and 'keymap'.
5855 */
5856 static int
5857valid_filetype(char_u *val)
5858{
5859 char_u *s;
5860
5861 for (s = val; *s != NUL; ++s)
5862 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5863 return FALSE;
5864 return TRUE;
5865}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005866#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005867
5868/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 * Handle string options that need some action to perform when changed.
5870 * Returns NULL for success, or an error message for an error.
5871 */
5872 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005873did_set_string_option(
5874 int opt_idx, /* index in options[] table */
5875 char_u **varp, /* pointer to the option variable */
5876 int new_value_alloced, /* new value was allocated */
5877 char_u *oldval, /* previous value of the option */
5878 char_u *errbuf, /* buffer for errors, or NULL */
5879 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880{
5881 char_u *errmsg = NULL;
5882 char_u *s, *p;
5883 int did_chartab = FALSE;
5884 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005885 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005886#ifdef FEAT_GUI
5887 /* set when changing an option that only requires a redraw in the GUI */
5888 int redraw_gui_only = FALSE;
5889#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890
5891 /* Get the global option to compare with, otherwise we would have to check
5892 * two values for all local options. */
5893 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5894
5895 /* Disallow changing some options from secure mode */
5896 if ((secure
5897#ifdef HAVE_SANDBOX
5898 || sandbox != 0
5899#endif
5900 ) && (options[opt_idx].flags & P_SECURE))
5901 {
5902 errmsg = e_secure;
5903 }
5904
Bram Moolenaar7554da42016-11-25 22:04:13 +01005905 /* Check for a "normal" directory or file name in some options. Disallow a
5906 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005907 * are often illegal in a file name. Be more permissive if "secure" is off.
5908 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01005909 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005910 && vim_strpbrk(*varp, (char_u *)(secure
5911 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01005912 || ((options[opt_idx].flags & P_NDNAME)
5913 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005914 {
5915 errmsg = e_invarg;
5916 }
5917
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 /* 'term' */
5919 else if (varp == &T_NAME)
5920 {
5921 if (T_NAME[0] == NUL)
5922 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5923#ifdef FEAT_GUI
5924 if (gui.in_use)
5925 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5926 else if (term_is_gui(T_NAME))
5927 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5928#endif
5929 else if (set_termname(T_NAME) == FAIL)
5930 errmsg = (char_u *)N_("E522: Not found in termcap");
5931 else
Bram Moolenaar67391142017-02-19 21:07:04 +01005932 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00005933 /* Screen colors may have changed. */
5934 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01005935
5936 /* Both 'term' and 'ttytype' point to T_NAME, only set the
5937 * P_ALLOCED flag on 'term'. */
5938 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01005939 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01005940 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941 }
5942
5943 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005944 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005945 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005946 char_u *bkc = p_bkc;
5947 unsigned int *flags = &bkc_flags;
5948
5949 if (opt_flags & OPT_LOCAL)
5950 {
5951 bkc = curbuf->b_p_bkc;
5952 flags = &curbuf->b_bkc_flags;
5953 }
5954
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005955 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5956 /* make the local value empty: use the global value */
5957 *flags = 0;
5958 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005960 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5961 errmsg = e_invarg;
5962 if ((((int)*flags & BKC_AUTO) != 0)
5963 + (((int)*flags & BKC_YES) != 0)
5964 + (((int)*flags & BKC_NO) != 0) != 1)
5965 {
5966 /* Must have exactly one of "auto", "yes" and "no". */
5967 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5968 errmsg = e_invarg;
5969 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005970 }
5971 }
5972
5973 /* 'backupext' and 'patchmode' */
5974 else if (varp == &p_bex || varp == &p_pm)
5975 {
5976 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5977 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5978 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5979 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005980#ifdef FEAT_LINEBREAK
5981 /* 'breakindentopt' */
5982 else if (varp == &curwin->w_p_briopt)
5983 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005984 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005985 errmsg = e_invarg;
5986 }
5987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005988
5989 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005990 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005992 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005993 */
5994 else if ( varp == &p_isi
5995 || varp == &(curbuf->b_p_isk)
5996 || varp == &p_isp
5997 || varp == &p_isf)
5998 {
5999 if (init_chartab() == FAIL)
6000 {
6001 did_chartab = TRUE; /* need to restore it below */
6002 errmsg = e_invarg; /* error in value */
6003 }
6004 }
6005
6006 /* 'helpfile' */
6007 else if (varp == &p_hf)
6008 {
6009 /* May compute new values for $VIM and $VIMRUNTIME */
6010 if (didset_vim)
6011 {
6012 vim_setenv((char_u *)"VIM", (char_u *)"");
6013 didset_vim = FALSE;
6014 }
6015 if (didset_vimruntime)
6016 {
6017 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6018 didset_vimruntime = FALSE;
6019 }
6020 }
6021
Bram Moolenaar1a384422010-07-14 19:53:30 +02006022#ifdef FEAT_SYN_HL
6023 /* 'colorcolumn' */
6024 else if (varp == &curwin->w_p_cc)
6025 errmsg = check_colorcolumn(curwin);
6026#endif
6027
Bram Moolenaar071d4272004-06-13 20:20:40 +00006028#ifdef FEAT_MULTI_LANG
6029 /* 'helplang' */
6030 else if (varp == &p_hlg)
6031 {
6032 /* Check for "", "ab", "ab,cd", etc. */
6033 for (s = p_hlg; *s != NUL; s += 3)
6034 {
6035 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6036 {
6037 errmsg = e_invarg;
6038 break;
6039 }
6040 if (s[2] == NUL)
6041 break;
6042 }
6043 }
6044#endif
6045
6046 /* 'highlight' */
6047 else if (varp == &p_hl)
6048 {
6049 if (highlight_changed() == FAIL)
6050 errmsg = e_invarg; /* invalid flags */
6051 }
6052
6053 /* 'nrformats' */
6054 else if (gvarp == &p_nf)
6055 {
6056 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6057 errmsg = e_invarg;
6058 }
6059
6060#ifdef FEAT_SESSION
6061 /* 'sessionoptions' */
6062 else if (varp == &p_ssop)
6063 {
6064 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6065 errmsg = e_invarg;
6066 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6067 {
6068 /* Don't allow both "sesdir" and "curdir". */
6069 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6070 errmsg = e_invarg;
6071 }
6072 }
6073 /* 'viewoptions' */
6074 else if (varp == &p_vop)
6075 {
6076 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6077 errmsg = e_invarg;
6078 }
6079#endif
6080
6081 /* 'scrollopt' */
6082#ifdef FEAT_SCROLLBIND
6083 else if (varp == &p_sbo)
6084 {
6085 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6086 errmsg = e_invarg;
6087 }
6088#endif
6089
6090 /* 'ambiwidth' */
6091#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006092 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006093 {
6094 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6095 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006096 else if (set_chars_option(&p_lcs) != NULL)
6097 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6098# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6099 else if (set_chars_option(&p_fcs) != NULL)
6100 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6101# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006102 }
6103#endif
6104
6105 /* 'background' */
6106 else if (varp == &p_bg)
6107 {
6108 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6109 {
6110#ifdef FEAT_EVAL
6111 int dark = (*p_bg == 'd');
6112#endif
6113
6114 init_highlight(FALSE, FALSE);
6115
6116#ifdef FEAT_EVAL
6117 if (dark != (*p_bg == 'd')
6118 && get_var_value((char_u *)"g:colors_name") != NULL)
6119 {
6120 /* The color scheme must have set 'background' back to another
6121 * value, that's not what we want here. Disable the color
6122 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006123 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006124 free_string_option(p_bg);
6125 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6126 check_string_option(&p_bg);
6127 init_highlight(FALSE, FALSE);
6128 }
6129#endif
6130 }
6131 else
6132 errmsg = e_invarg;
6133 }
6134
6135 /* 'wildmode' */
6136 else if (varp == &p_wim)
6137 {
6138 if (check_opt_wim() == FAIL)
6139 errmsg = e_invarg;
6140 }
6141
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006142#ifdef FEAT_CMDL_COMPL
6143 /* 'wildoptions' */
6144 else if (varp == &p_wop)
6145 {
6146 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6147 errmsg = e_invarg;
6148 }
6149#endif
6150
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151#ifdef FEAT_WAK
6152 /* 'winaltkeys' */
6153 else if (varp == &p_wak)
6154 {
6155 if (*p_wak == NUL
6156 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6157 errmsg = e_invarg;
6158# ifdef FEAT_MENU
6159# ifdef FEAT_GUI_MOTIF
6160 else if (gui.in_use)
6161 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6162# else
6163# ifdef FEAT_GUI_GTK
6164 else if (gui.in_use)
6165 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6166# endif
6167# endif
6168# endif
6169 }
6170#endif
6171
6172#ifdef FEAT_AUTOCMD
6173 /* 'eventignore' */
6174 else if (varp == &p_ei)
6175 {
6176 if (check_ei() == FAIL)
6177 errmsg = e_invarg;
6178 }
6179#endif
6180
6181#ifdef FEAT_MBYTE
6182 /* 'encoding' and 'fileencoding' */
6183 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6184 {
6185 if (gvarp == &p_fenc)
6186 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006187 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188 errmsg = e_modifiable;
6189 else if (vim_strchr(*varp, ',') != NULL)
6190 /* No comma allowed in 'fileencoding'; catches confusing it
6191 * with 'fileencodings'. */
6192 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006193 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006194 {
6195# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006196 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006197 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006198# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006199 /* Add 'fileencoding' to the swap file. */
6200 ml_setflags(curbuf);
6201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 }
6203 if (errmsg == NULL)
6204 {
6205 /* canonize the value, so that STRCMP() can be used on it */
6206 p = enc_canonize(*varp);
6207 if (p != NULL)
6208 {
6209 vim_free(*varp);
6210 *varp = p;
6211 }
6212 if (varp == &p_enc)
6213 {
6214 errmsg = mb_init();
6215# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006216 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006217# endif
6218 }
6219 }
6220
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006221# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006222 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6223 {
6224 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6225 if (STRCMP(p_tenc, "utf-8") != 0)
6226 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6227 }
6228# endif
6229
6230 if (errmsg == NULL)
6231 {
6232# ifdef FEAT_KEYMAP
6233 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6234 * (with another encoding). */
6235 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6236 (void)keymap_init();
6237# endif
6238
6239 /* When 'termencoding' is not empty and 'encoding' changes or when
6240 * 'termencoding' changes, need to setup for keyboard input and
6241 * display output conversion. */
6242 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6243 {
6244 convert_setup(&input_conv, p_tenc, p_enc);
6245 convert_setup(&output_conv, p_enc, p_tenc);
6246 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006247
6248# if defined(WIN3264) && defined(FEAT_MBYTE)
6249 /* $HOME may have characters in active code page. */
6250 if (varp == &p_enc)
6251 init_homedir();
6252# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006253 }
6254 }
6255#endif
6256
6257#if defined(FEAT_POSTSCRIPT)
6258 else if (varp == &p_penc)
6259 {
6260 /* Canonize printencoding if VIM standard one */
6261 p = enc_canonize(p_penc);
6262 if (p != NULL)
6263 {
6264 vim_free(p_penc);
6265 p_penc = p;
6266 }
6267 else
6268 {
6269 /* Ensure lower case and '-' for '_' */
6270 for (s = p_penc; *s != NUL; s++)
6271 {
6272 if (*s == '_')
6273 *s = '-';
6274 else
6275 *s = TOLOWER_ASC(*s);
6276 }
6277 }
6278 }
6279#endif
6280
Bram Moolenaar9372a112005-12-06 19:59:18 +00006281#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006282 else if (varp == &p_imak)
6283 {
6284 if (gui.in_use && !im_xim_isvalid_imactivate())
6285 errmsg = e_invarg;
6286 }
6287#endif
6288
6289#ifdef FEAT_KEYMAP
6290 else if (varp == &curbuf->b_p_keymap)
6291 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006292 if (!valid_filetype(*varp))
6293 errmsg = e_invarg;
6294 else
6295 /* load or unload key mapping tables */
6296 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006297
Bram Moolenaarfab06232009-03-04 03:13:35 +00006298 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006299 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006300 if (*curbuf->b_p_keymap != NUL)
6301 {
6302 /* Installed a new keymap, switch on using it. */
6303 curbuf->b_p_iminsert = B_IMODE_LMAP;
6304 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6305 curbuf->b_p_imsearch = B_IMODE_LMAP;
6306 }
6307 else
6308 {
6309 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6310 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6311 curbuf->b_p_iminsert = B_IMODE_NONE;
6312 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6313 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6314 }
6315 if ((opt_flags & OPT_LOCAL) == 0)
6316 {
6317 set_iminsert_global();
6318 set_imsearch_global();
6319 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006320# ifdef FEAT_WINDOWS
6321 status_redraw_curbuf();
6322# endif
6323 }
6324 }
6325#endif
6326
6327 /* 'fileformat' */
6328 else if (gvarp == &p_ff)
6329 {
6330 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6331 errmsg = e_modifiable;
6332 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6333 errmsg = e_invarg;
6334 else
6335 {
6336 /* may also change 'textmode' */
6337 if (get_fileformat(curbuf) == EOL_DOS)
6338 curbuf->b_p_tx = TRUE;
6339 else
6340 curbuf->b_p_tx = FALSE;
6341#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006342 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006344 /* update flag in swap file */
6345 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006346 /* Redraw needed when switching to/from "mac": a CR in the text
6347 * will be displayed differently. */
6348 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6349 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006350 }
6351 }
6352
6353 /* 'fileformats' */
6354 else if (varp == &p_ffs)
6355 {
6356 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6357 errmsg = e_invarg;
6358 else
6359 {
6360 /* also change 'textauto' */
6361 if (*p_ffs == NUL)
6362 p_ta = FALSE;
6363 else
6364 p_ta = TRUE;
6365 }
6366 }
6367
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006368#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006369 /* 'cryptkey' */
6370 else if (gvarp == &p_key)
6371 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006372# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006373 /* Make sure the ":set" command doesn't show the new value in the
6374 * history. */
6375 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006376# endif
6377 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6378 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006379 ml_set_crypt_key(curbuf, oldval,
6380 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006381 }
6382
6383 else if (gvarp == &p_cm)
6384 {
6385 if (opt_flags & OPT_LOCAL)
6386 p = curbuf->b_p_cm;
6387 else
6388 p = p_cm;
6389 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6390 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006391 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006392 errmsg = e_invarg;
6393 else
6394 {
6395 /* When setting the global value to empty, make it "zip". */
6396 if (*p_cm == NUL)
6397 {
6398 if (new_value_alloced)
6399 free_string_option(p_cm);
6400 p_cm = vim_strsave((char_u *)"zip");
6401 new_value_alloced = TRUE;
6402 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006403 /* When using ":set cm=name" the local value is going to be empty.
6404 * Do that here, otherwise the crypt functions will still use the
6405 * local value. */
6406 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6407 {
6408 free_string_option(curbuf->b_p_cm);
6409 curbuf->b_p_cm = empty_option;
6410 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006411
6412 /* Need to update the swapfile when the effective method changed.
6413 * Set "s" to the effective old value, "p" to the effective new
6414 * method and compare. */
6415 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6416 s = p_cm; /* was previously using the global value */
6417 else
6418 s = oldval;
6419 if (*curbuf->b_p_cm == NUL)
6420 p = p_cm; /* is now using the global value */
6421 else
6422 p = curbuf->b_p_cm;
6423 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006424 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006425
6426 /* If the global value changes need to update the swapfile for all
6427 * buffers using that value. */
6428 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6429 {
6430 buf_T *buf;
6431
Bram Moolenaar29323592016-07-24 22:04:11 +02006432 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006433 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006434 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006435 }
6436 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006437 }
6438#endif
6439
6440 /* 'matchpairs' */
6441 else if (gvarp == &p_mps)
6442 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006443#ifdef FEAT_MBYTE
6444 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006446 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006447 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006448 int x2 = -1;
6449 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006450
6451 if (*p != NUL)
6452 p += mb_ptr2len(p);
6453 if (*p != NUL)
6454 x2 = *p++;
6455 if (*p != NUL)
6456 {
6457 x3 = mb_ptr2char(p);
6458 p += mb_ptr2len(p);
6459 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006460 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006461 {
6462 errmsg = e_invarg;
6463 break;
6464 }
6465 if (*p == NUL)
6466 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006468 }
6469 else
6470#endif
6471 {
6472 /* Check for "x:y,x:y" */
6473 for (p = *varp; *p != NUL; p += 4)
6474 {
6475 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6476 {
6477 errmsg = e_invarg;
6478 break;
6479 }
6480 if (p[3] == NUL)
6481 break;
6482 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 }
6484 }
6485
6486#ifdef FEAT_COMMENTS
6487 /* 'comments' */
6488 else if (gvarp == &p_com)
6489 {
6490 for (s = *varp; *s; )
6491 {
6492 while (*s && *s != ':')
6493 {
6494 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6495 && !VIM_ISDIGIT(*s) && *s != '-')
6496 {
6497 errmsg = illegal_char(errbuf, *s);
6498 break;
6499 }
6500 ++s;
6501 }
6502 if (*s++ == NUL)
6503 errmsg = (char_u *)N_("E524: Missing colon");
6504 else if (*s == ',' || *s == NUL)
6505 errmsg = (char_u *)N_("E525: Zero length string");
6506 if (errmsg != NULL)
6507 break;
6508 while (*s && *s != ',')
6509 {
6510 if (*s == '\\' && s[1] != NUL)
6511 ++s;
6512 ++s;
6513 }
6514 s = skip_to_option_part(s);
6515 }
6516 }
6517#endif
6518
6519 /* 'listchars' */
6520 else if (varp == &p_lcs)
6521 {
6522 errmsg = set_chars_option(varp);
6523 }
6524
6525#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6526 /* 'fillchars' */
6527 else if (varp == &p_fcs)
6528 {
6529 errmsg = set_chars_option(varp);
6530 }
6531#endif
6532
6533#ifdef FEAT_CMDWIN
6534 /* 'cedit' */
6535 else if (varp == &p_cedit)
6536 {
6537 errmsg = check_cedit();
6538 }
6539#endif
6540
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006541 /* 'verbosefile' */
6542 else if (varp == &p_vfile)
6543 {
6544 verbose_stop();
6545 if (*p_vfile != NUL && verbose_open() == FAIL)
6546 errmsg = e_invarg;
6547 }
6548
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549#ifdef FEAT_VIMINFO
6550 /* 'viminfo' */
6551 else if (varp == &p_viminfo)
6552 {
6553 for (s = p_viminfo; *s;)
6554 {
6555 /* Check it's a valid character */
6556 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6557 {
6558 errmsg = illegal_char(errbuf, *s);
6559 break;
6560 }
6561 if (*s == 'n') /* name is always last one */
6562 {
6563 break;
6564 }
6565 else if (*s == 'r') /* skip until next ',' */
6566 {
6567 while (*++s && *s != ',')
6568 ;
6569 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006570 else if (*s == '%')
6571 {
6572 /* optional number */
6573 while (vim_isdigit(*++s))
6574 ;
6575 }
6576 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006577 ++s; /* no extra chars */
6578 else /* must have a number */
6579 {
6580 while (vim_isdigit(*++s))
6581 ;
6582
6583 if (!VIM_ISDIGIT(*(s - 1)))
6584 {
6585 if (errbuf != NULL)
6586 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006587 sprintf((char *)errbuf,
6588 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006589 transchar_byte(*(s - 1)));
6590 errmsg = errbuf;
6591 }
6592 else
6593 errmsg = (char_u *)"";
6594 break;
6595 }
6596 }
6597 if (*s == ',')
6598 ++s;
6599 else if (*s)
6600 {
6601 if (errbuf != NULL)
6602 errmsg = (char_u *)N_("E527: Missing comma");
6603 else
6604 errmsg = (char_u *)"";
6605 break;
6606 }
6607 }
6608 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6609 errmsg = (char_u *)N_("E528: Must specify a ' value");
6610 }
6611#endif /* FEAT_VIMINFO */
6612
6613 /* terminal options */
6614 else if (istermoption(&options[opt_idx]) && full_screen)
6615 {
6616 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6617 if (varp == &T_CCO)
6618 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006619 int colors = atoi((char *)T_CCO);
6620
6621 /* Only reinitialize colors if t_Co value has really changed to
6622 * avoid expensive reload of colorscheme if t_Co is set to the
6623 * same value multiple times. */
6624 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006625 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006626 t_colors = colors;
6627 if (t_colors <= 1)
6628 {
6629 if (new_value_alloced)
6630 vim_free(T_CCO);
6631 T_CCO = empty_option;
6632 }
6633 /* We now have a different color setup, initialize it again. */
6634 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006636 }
6637 ttest(FALSE);
6638 if (varp == &T_ME)
6639 {
6640 out_str(T_ME);
6641 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006642#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006643 /* Since t_me has been set, this probably means that the user
6644 * wants to use this as default colors. Need to reset default
6645 * background/foreground colors. */
6646 mch_set_normal_colors();
6647#endif
6648 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006649 if (varp == &T_BE && termcap_active)
6650 {
6651 if (*T_BE == NUL)
6652 /* When clearing t_BE we assume the user no longer wants
6653 * bracketed paste, thus disable it by writing t_BD. */
6654 out_str(T_BD);
6655 else
6656 out_str(T_BE);
6657 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006658 }
6659
6660#ifdef FEAT_LINEBREAK
6661 /* 'showbreak' */
6662 else if (varp == &p_sbr)
6663 {
6664 for (s = p_sbr; *s; )
6665 {
6666 if (ptr2cells(s) != 1)
6667 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006668 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006669 }
6670 }
6671#endif
6672
6673#ifdef FEAT_GUI
6674 /* 'guifont' */
6675 else if (varp == &p_guifont)
6676 {
6677 if (gui.in_use)
6678 {
6679 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006680# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006681 /*
6682 * Put up a font dialog and let the user select a new value.
6683 * If this is cancelled go back to the old value but don't
6684 * give an error message.
6685 */
6686 if (STRCMP(p, "*") == 0)
6687 {
6688 p = gui_mch_font_dialog(oldval);
6689
6690 if (new_value_alloced)
6691 free_string_option(p_guifont);
6692
6693 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6694 new_value_alloced = TRUE;
6695 }
6696# endif
6697 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6698 {
6699# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6700 if (STRCMP(p_guifont, "*") == 0)
6701 {
6702 /* Dialog was cancelled: Keep the old value without giving
6703 * an error message. */
6704 if (new_value_alloced)
6705 free_string_option(p_guifont);
6706 p_guifont = vim_strsave(oldval);
6707 new_value_alloced = TRUE;
6708 }
6709 else
6710# endif
6711 errmsg = (char_u *)N_("E596: Invalid font(s)");
6712 }
6713 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006714 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006715 }
6716# ifdef FEAT_XFONTSET
6717 else if (varp == &p_guifontset)
6718 {
6719 if (STRCMP(p_guifontset, "*") == 0)
6720 errmsg = (char_u *)N_("E597: can't select fontset");
6721 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6722 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006723 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006724 }
6725# endif
6726# ifdef FEAT_MBYTE
6727 else if (varp == &p_guifontwide)
6728 {
6729 if (STRCMP(p_guifontwide, "*") == 0)
6730 errmsg = (char_u *)N_("E533: can't select wide font");
6731 else if (gui_get_wide_font() == FAIL)
6732 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006733 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006734 }
6735# endif
6736#endif
6737
6738#ifdef CURSOR_SHAPE
6739 /* 'guicursor' */
6740 else if (varp == &p_guicursor)
6741 errmsg = parse_shape_opt(SHAPE_CURSOR);
6742#endif
6743
6744#ifdef FEAT_MOUSESHAPE
6745 /* 'mouseshape' */
6746 else if (varp == &p_mouseshape)
6747 {
6748 errmsg = parse_shape_opt(SHAPE_MOUSE);
6749 update_mouseshape(-1);
6750 }
6751#endif
6752
6753#ifdef FEAT_PRINTER
6754 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006755 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006756# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006757 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006758 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006759# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006760#endif
6761
6762#ifdef FEAT_LANGMAP
6763 /* 'langmap' */
6764 else if (varp == &p_langmap)
6765 langmap_set();
6766#endif
6767
6768#ifdef FEAT_LINEBREAK
6769 /* 'breakat' */
6770 else if (varp == &p_breakat)
6771 fill_breakat_flags();
6772#endif
6773
6774#ifdef FEAT_TITLE
6775 /* 'titlestring' and 'iconstring' */
6776 else if (varp == &p_titlestring || varp == &p_iconstring)
6777 {
6778# ifdef FEAT_STL_OPT
6779 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6780
6781 /* NULL => statusline syntax */
6782 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6783 stl_syntax |= flagval;
6784 else
6785 stl_syntax &= ~flagval;
6786# endif
6787 did_set_title(varp == &p_iconstring);
6788
6789 }
6790#endif
6791
6792#ifdef FEAT_GUI
6793 /* 'guioptions' */
6794 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006795 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006796 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006797 redraw_gui_only = TRUE;
6798 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006799#endif
6800
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006801#if defined(FEAT_GUI_TABLINE)
6802 /* 'guitablabel' */
6803 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006804 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006805 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006806 redraw_gui_only = TRUE;
6807 }
6808 /* 'guitabtooltip' */
6809 else if (varp == &p_gtt)
6810 {
6811 redraw_gui_only = TRUE;
6812 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006813#endif
6814
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6816 /* 'ttymouse' */
6817 else if (varp == &p_ttym)
6818 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006819 /* Switch the mouse off before changing the escape sequences used for
6820 * that. */
6821 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6823 errmsg = e_invarg;
6824 else
6825 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006826 if (termcap_active)
6827 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 }
6829#endif
6830
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831 /* 'selection' */
6832 else if (varp == &p_sel)
6833 {
6834 if (*p_sel == NUL
6835 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6836 errmsg = e_invarg;
6837 }
6838
6839 /* 'selectmode' */
6840 else if (varp == &p_slm)
6841 {
6842 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6843 errmsg = e_invarg;
6844 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006845
6846#ifdef FEAT_BROWSE
6847 /* 'browsedir' */
6848 else if (varp == &p_bsdir)
6849 {
6850 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6851 && !mch_isdir(p_bsdir))
6852 errmsg = e_invarg;
6853 }
6854#endif
6855
Bram Moolenaar071d4272004-06-13 20:20:40 +00006856 /* 'keymodel' */
6857 else if (varp == &p_km)
6858 {
6859 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6860 errmsg = e_invarg;
6861 else
6862 {
6863 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6864 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6865 }
6866 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006867
6868 /* 'mousemodel' */
6869 else if (varp == &p_mousem)
6870 {
6871 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6872 errmsg = e_invarg;
6873#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6874 else if (*p_mousem != *oldval)
6875 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6876 * to create or delete the popup menus. */
6877 gui_motif_update_mousemodel(root_menu);
6878#endif
6879 }
6880
6881 /* 'switchbuf' */
6882 else if (varp == &p_swb)
6883 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006884 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006885 errmsg = e_invarg;
6886 }
6887
6888 /* 'debug' */
6889 else if (varp == &p_debug)
6890 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006891 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006892 errmsg = e_invarg;
6893 }
6894
6895 /* 'display' */
6896 else if (varp == &p_dy)
6897 {
6898 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6899 errmsg = e_invarg;
6900 else
6901 (void)init_chartab();
6902
6903 }
6904
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006905#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 /* 'eadirection' */
6907 else if (varp == &p_ead)
6908 {
6909 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6910 errmsg = e_invarg;
6911 }
6912#endif
6913
6914#ifdef FEAT_CLIPBOARD
6915 /* 'clipboard' */
6916 else if (varp == &p_cb)
6917 errmsg = check_clipboard_option();
6918#endif
6919
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006920#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006921 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6922 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006923 else if (varp == &(curwin->w_s->b_p_spl)
6924 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006925 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006926 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006927 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006928 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006929 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006930 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006931 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006932 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006933 /* 'spellsuggest' */
6934 else if (varp == &p_sps)
6935 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006936 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006937 errmsg = e_invarg;
6938 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006939 /* 'mkspellmem' */
6940 else if (varp == &p_msm)
6941 {
6942 if (spell_check_msm() != OK)
6943 errmsg = e_invarg;
6944 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006945#endif
6946
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947#ifdef FEAT_QUICKFIX
6948 /* When 'bufhidden' is set, check for valid value. */
6949 else if (gvarp == &p_bh)
6950 {
6951 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6952 errmsg = e_invarg;
6953 }
6954
6955 /* When 'buftype' is set, check for valid value. */
6956 else if (gvarp == &p_bt)
6957 {
6958 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6959 errmsg = e_invarg;
6960 else
6961 {
6962# ifdef FEAT_WINDOWS
6963 if (curwin->w_status_height)
6964 {
6965 curwin->w_redr_status = TRUE;
6966 redraw_later(VALID);
6967 }
6968# endif
6969 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006970# ifdef FEAT_TITLE
6971 redraw_titles();
6972# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973 }
6974 }
6975#endif
6976
6977#ifdef FEAT_STL_OPT
6978 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006979 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980 {
6981 int wid;
6982
6983 if (varp == &p_ruf) /* reset ru_wid first */
6984 ru_wid = 0;
6985 s = *varp;
6986 if (varp == &p_ruf && *s == '%')
6987 {
6988 /* set ru_wid if 'ruf' starts with "%99(" */
6989 if (*++s == '-') /* ignore a '-' */
6990 s++;
6991 wid = getdigits(&s);
6992 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6993 ru_wid = wid;
6994 else
6995 errmsg = check_stl_option(p_ruf);
6996 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006997 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006998 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006999 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007000 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007001 comp_col();
7002 }
7003#endif
7004
7005#ifdef FEAT_INS_EXPAND
7006 /* check if it is a valid value for 'complete' -- Acevedo */
7007 else if (gvarp == &p_cpt)
7008 {
7009 for (s = *varp; *s;)
7010 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007011 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007012 s++;
7013 if (!*s)
7014 break;
7015 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7016 {
7017 errmsg = illegal_char(errbuf, *s);
7018 break;
7019 }
7020 if (*++s != NUL && *s != ',' && *s != ' ')
7021 {
7022 if (s[-1] == 'k' || s[-1] == 's')
7023 {
7024 /* skip optional filename after 'k' and 's' */
7025 while (*s && *s != ',' && *s != ' ')
7026 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007027 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007028 ++s;
7029 ++s;
7030 }
7031 }
7032 else
7033 {
7034 if (errbuf != NULL)
7035 {
7036 sprintf((char *)errbuf,
7037 _("E535: Illegal character after <%c>"),
7038 *--s);
7039 errmsg = errbuf;
7040 }
7041 else
7042 errmsg = (char_u *)"";
7043 break;
7044 }
7045 }
7046 }
7047 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007048
7049 /* 'completeopt' */
7050 else if (varp == &p_cot)
7051 {
7052 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7053 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007054 else
7055 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007056 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007057#endif /* FEAT_INS_EXPAND */
7058
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007059#ifdef FEAT_SIGNS
7060 /* 'signcolumn' */
7061 else if (varp == &curwin->w_p_scl)
7062 {
7063 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7064 errmsg = e_invarg;
7065 }
7066#endif
7067
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068
7069#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007070 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071 else if (varp == &p_toolbar)
7072 {
7073 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7074 &toolbar_flags, TRUE) != OK)
7075 errmsg = e_invarg;
7076 else
7077 {
7078 out_flush();
7079 gui_mch_show_toolbar((toolbar_flags &
7080 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7081 }
7082 }
7083#endif
7084
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007085#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007086 /* 'toolbariconsize': GTK+ 2 only */
7087 else if (varp == &p_tbis)
7088 {
7089 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7090 errmsg = e_invarg;
7091 else
7092 {
7093 out_flush();
7094 gui_mch_show_toolbar((toolbar_flags &
7095 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7096 }
7097 }
7098#endif
7099
7100 /* 'pastetoggle': translate key codes like in a mapping */
7101 else if (varp == &p_pt)
7102 {
7103 if (*p_pt)
7104 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007105 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 if (p != NULL)
7107 {
7108 if (new_value_alloced)
7109 free_string_option(p_pt);
7110 p_pt = p;
7111 new_value_alloced = TRUE;
7112 }
7113 }
7114 }
7115
7116 /* 'backspace' */
7117 else if (varp == &p_bs)
7118 {
7119 if (VIM_ISDIGIT(*p_bs))
7120 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007121 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 errmsg = e_invarg;
7123 }
7124 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7125 errmsg = e_invarg;
7126 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007127 else if (varp == &p_bo)
7128 {
7129 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7130 errmsg = e_invarg;
7131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007132
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007133 /* 'tagcase' */
7134 else if (gvarp == &p_tc)
7135 {
7136 unsigned int *flags;
7137
7138 if (opt_flags & OPT_LOCAL)
7139 {
7140 p = curbuf->b_p_tc;
7141 flags = &curbuf->b_tc_flags;
7142 }
7143 else
7144 {
7145 p = p_tc;
7146 flags = &tc_flags;
7147 }
7148
7149 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7150 /* make the local value empty: use the global value */
7151 *flags = 0;
7152 else if (*p == NUL
7153 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7154 errmsg = e_invarg;
7155 }
7156
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007157#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158 /* 'casemap' */
7159 else if (varp == &p_cmp)
7160 {
7161 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7162 errmsg = e_invarg;
7163 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007164#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165
7166#ifdef FEAT_DIFF
7167 /* 'diffopt' */
7168 else if (varp == &p_dip)
7169 {
7170 if (diffopt_changed() == FAIL)
7171 errmsg = e_invarg;
7172 }
7173#endif
7174
7175#ifdef FEAT_FOLDING
7176 /* 'foldmethod' */
7177 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7178 {
7179 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7180 || *curwin->w_p_fdm == NUL)
7181 errmsg = e_invarg;
7182 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007183 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007185 if (foldmethodIsDiff(curwin))
7186 newFoldLevel();
7187 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007188 }
7189# ifdef FEAT_EVAL
7190 /* 'foldexpr' */
7191 else if (varp == &curwin->w_p_fde)
7192 {
7193 if (foldmethodIsExpr(curwin))
7194 foldUpdateAll(curwin);
7195 }
7196# endif
7197 /* 'foldmarker' */
7198 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7199 {
7200 p = vim_strchr(*varp, ',');
7201 if (p == NULL)
7202 errmsg = (char_u *)N_("E536: comma required");
7203 else if (p == *varp || p[1] == NUL)
7204 errmsg = e_invarg;
7205 else if (foldmethodIsMarker(curwin))
7206 foldUpdateAll(curwin);
7207 }
7208 /* 'commentstring' */
7209 else if (gvarp == &p_cms)
7210 {
7211 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7212 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7213 }
7214 /* 'foldopen' */
7215 else if (varp == &p_fdo)
7216 {
7217 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7218 errmsg = e_invarg;
7219 }
7220 /* 'foldclose' */
7221 else if (varp == &p_fcl)
7222 {
7223 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7224 errmsg = e_invarg;
7225 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007226 /* 'foldignore' */
7227 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7228 {
7229 if (foldmethodIsIndent(curwin))
7230 foldUpdateAll(curwin);
7231 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007232#endif
7233
7234#ifdef FEAT_VIRTUALEDIT
7235 /* 'virtualedit' */
7236 else if (varp == &p_ve)
7237 {
7238 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7239 errmsg = e_invarg;
7240 else if (STRCMP(p_ve, oldval) != 0)
7241 {
7242 /* Recompute cursor position in case the new 've' setting
7243 * changes something. */
7244 validate_virtcol();
7245 coladvance(curwin->w_virtcol);
7246 }
7247 }
7248#endif
7249
7250#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7251 else if (varp == &p_csqf)
7252 {
7253 if (p_csqf != NULL)
7254 {
7255 p = p_csqf;
7256 while (*p != NUL)
7257 {
7258 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7259 || p[1] == NUL
7260 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7261 || (p[2] != NUL && p[2] != ','))
7262 {
7263 errmsg = e_invarg;
7264 break;
7265 }
7266 else if (p[2] == NUL)
7267 break;
7268 else
7269 p += 3;
7270 }
7271 }
7272 }
7273#endif
7274
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007275#ifdef FEAT_CINDENT
7276 /* 'cinoptions' */
7277 else if (gvarp == &p_cino)
7278 {
7279 /* TODO: recognize errors */
7280 parse_cino(curbuf);
7281 }
7282#endif
7283
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007284#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007285 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007286 else if (varp == &p_rop && gui.in_use)
7287 {
7288 if (!gui_mch_set_rendering_options(p_rop))
7289 errmsg = e_invarg;
7290 }
7291#endif
7292
Bram Moolenaard0b51382016-11-04 15:23:45 +01007293#ifdef FEAT_AUTOCMD
7294 else if (gvarp == &p_ft)
7295 {
7296 if (!valid_filetype(*varp))
7297 errmsg = e_invarg;
7298 }
7299#endif
7300
7301#ifdef FEAT_SYN_HL
7302 else if (gvarp == &p_syn)
7303 {
7304 if (!valid_filetype(*varp))
7305 errmsg = e_invarg;
7306 }
7307#endif
7308
Bram Moolenaar071d4272004-06-13 20:20:40 +00007309 /* Options that are a list of flags. */
7310 else
7311 {
7312 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007313 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007314 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007315 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007316 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007317 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007318 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007319 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007321#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007322 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007323 p = (char_u *)COCU_ALL;
7324#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007325 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007326 {
7327#ifdef FEAT_MOUSE
7328 p = (char_u *)MOUSE_ALL;
7329#else
7330 if (*p_mouse != NUL)
7331 errmsg = (char_u *)N_("E538: No mouse support");
7332#endif
7333 }
7334#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007335 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336 p = (char_u *)GO_ALL;
7337#endif
7338 if (p != NULL)
7339 {
7340 for (s = *varp; *s; ++s)
7341 if (vim_strchr(p, *s) == NULL)
7342 {
7343 errmsg = illegal_char(errbuf, *s);
7344 break;
7345 }
7346 }
7347 }
7348
7349 /*
7350 * If error detected, restore the previous value.
7351 */
7352 if (errmsg != NULL)
7353 {
7354 if (new_value_alloced)
7355 free_string_option(*varp);
7356 *varp = oldval;
7357 /*
7358 * When resetting some values, need to act on it.
7359 */
7360 if (did_chartab)
7361 (void)init_chartab();
7362 if (varp == &p_hl)
7363 (void)highlight_changed();
7364 }
7365 else
7366 {
7367#ifdef FEAT_EVAL
7368 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007369 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007370#endif
7371 /*
7372 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007373 * Use "free_oldval", because recursiveness may change the flags under
7374 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007375 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007376 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007377 free_string_option(oldval);
7378 if (new_value_alloced)
7379 options[opt_idx].flags |= P_ALLOCED;
7380 else
7381 options[opt_idx].flags &= ~P_ALLOCED;
7382
7383 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007384 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007385 {
7386 /* global option with local value set to use global value; free
7387 * the local value and make it empty */
7388 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7389 free_string_option(*(char_u **)p);
7390 *(char_u **)p = empty_option;
7391 }
7392
7393 /* May set global value for local option. */
7394 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7395 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007396
7397#ifdef FEAT_AUTOCMD
7398 /*
7399 * Trigger the autocommand only after setting the flags.
7400 */
7401# ifdef FEAT_SYN_HL
7402 /* When 'syntax' is set, load the syntax of that name */
7403 if (varp == &(curbuf->b_p_syn))
7404 {
7405 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7406 curbuf->b_fname, TRUE, curbuf);
7407 }
7408# endif
7409 else if (varp == &(curbuf->b_p_ft))
7410 {
7411 /* 'filetype' is set, trigger the FileType autocommand */
7412 did_filetype = TRUE;
7413 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7414 curbuf->b_fname, TRUE, curbuf);
7415 }
7416#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007417#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007418 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007419 {
7420 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007421 char_u *q = curwin->w_s->b_p_spl;
7422
7423 /* Skip the first name if it is "cjk". */
7424 if (STRNCMP(q, "cjk,", 4) == 0)
7425 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007426
7427 /*
7428 * Source the spell/LANG.vim in 'runtimepath'.
7429 * They could set 'spellcapcheck' depending on the language.
7430 * Use the first name in 'spelllang' up to '_region' or
7431 * '.encoding'.
7432 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007433 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007434 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7435 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007436 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007437 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007438 }
7439#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007440 }
7441
7442#ifdef FEAT_MOUSE
7443 if (varp == &p_mouse)
7444 {
7445# ifdef FEAT_MOUSE_TTY
7446 if (*p_mouse == NUL)
7447 mch_setmouse(FALSE); /* switch mouse off */
7448 else
7449# endif
7450 setmouse(); /* in case 'mouse' changed */
7451 }
7452#endif
7453
Bram Moolenaar913077c2012-03-28 19:59:04 +02007454 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007455 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007456 curwin->w_set_curswant = TRUE;
7457
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007458#ifdef FEAT_GUI
7459 /* check redraw when it's not a GUI option or the GUI is active. */
7460 if (!redraw_gui_only || gui.in_use)
7461#endif
7462 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463
7464 return errmsg;
7465}
7466
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007467#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007468/*
7469 * Simple int comparison function for use with qsort()
7470 */
7471 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007472int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007473{
7474 return *(const int *)a - *(const int *)b;
7475}
7476
7477/*
7478 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7479 * Returns error message, NULL if it's OK.
7480 */
7481 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007482check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007483{
7484 char_u *s;
7485 int col;
7486 int count = 0;
7487 int color_cols[256];
7488 int i;
7489 int j = 0;
7490
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007491 if (wp->w_buffer == NULL)
7492 return NULL; /* buffer was closed */
7493
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007494 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007495 {
7496 if (*s == '-' || *s == '+')
7497 {
7498 /* -N and +N: add to 'textwidth' */
7499 col = (*s == '-') ? -1 : 1;
7500 ++s;
7501 if (!VIM_ISDIGIT(*s))
7502 return e_invarg;
7503 col = col * getdigits(&s);
7504 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007505 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007506 col += wp->w_buffer->b_p_tw;
7507 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007508 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007509 }
7510 else if (VIM_ISDIGIT(*s))
7511 col = getdigits(&s);
7512 else
7513 return e_invarg;
7514 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007515skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007516 if (*s == NUL)
7517 break;
7518 if (*s != ',')
7519 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007520 if (*++s == NUL)
7521 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007522 }
7523
7524 vim_free(wp->w_p_cc_cols);
7525 if (count == 0)
7526 wp->w_p_cc_cols = NULL;
7527 else
7528 {
7529 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7530 if (wp->w_p_cc_cols != NULL)
7531 {
7532 /* sort the columns for faster usage on screen redraw inside
7533 * win_line() */
7534 qsort(color_cols, count, sizeof(int), int_cmp);
7535
7536 for (i = 0; i < count; ++i)
7537 /* skip duplicates */
7538 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7539 wp->w_p_cc_cols[j++] = color_cols[i];
7540 wp->w_p_cc_cols[j] = -1; /* end marker */
7541 }
7542 }
7543
7544 return NULL; /* no error */
7545}
7546#endif
7547
Bram Moolenaar071d4272004-06-13 20:20:40 +00007548/*
7549 * Handle setting 'listchars' or 'fillchars'.
7550 * Returns error message, NULL if it's OK.
7551 */
7552 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007553set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007554{
7555 int round, i, len, entries;
7556 char_u *p, *s;
7557 int c1, c2 = 0;
7558 struct charstab
7559 {
7560 int *cp;
7561 char *name;
7562 };
7563#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7564 static struct charstab filltab[] =
7565 {
7566 {&fill_stl, "stl"},
7567 {&fill_stlnc, "stlnc"},
7568 {&fill_vert, "vert"},
7569 {&fill_fold, "fold"},
7570 {&fill_diff, "diff"},
7571 };
7572#endif
7573 static struct charstab lcstab[] =
7574 {
7575 {&lcs_eol, "eol"},
7576 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007577 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007578 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007579 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007580 {&lcs_tab2, "tab"},
7581 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007582#ifdef FEAT_CONCEAL
7583 {&lcs_conceal, "conceal"},
7584#else
7585 {NULL, "conceal"},
7586#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007587 };
7588 struct charstab *tab;
7589
7590#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7591 if (varp == &p_lcs)
7592#endif
7593 {
7594 tab = lcstab;
7595 entries = sizeof(lcstab) / sizeof(struct charstab);
7596 }
7597#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7598 else
7599 {
7600 tab = filltab;
7601 entries = sizeof(filltab) / sizeof(struct charstab);
7602 }
7603#endif
7604
7605 /* first round: check for valid value, second round: assign values */
7606 for (round = 0; round <= 1; ++round)
7607 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007608 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007609 {
7610 /* After checking that the value is valid: set defaults: space for
7611 * 'fillchars', NUL for 'listchars' */
7612 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007613 if (tab[i].cp != NULL)
7614 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007615 if (varp == &p_lcs)
7616 lcs_tab1 = NUL;
7617#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7618 else
7619 fill_diff = '-';
7620#endif
7621 }
7622 p = *varp;
7623 while (*p)
7624 {
7625 for (i = 0; i < entries; ++i)
7626 {
7627 len = (int)STRLEN(tab[i].name);
7628 if (STRNCMP(p, tab[i].name, len) == 0
7629 && p[len] == ':'
7630 && p[len + 1] != NUL)
7631 {
7632 s = p + len + 1;
7633#ifdef FEAT_MBYTE
7634 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007635 if (mb_char2cells(c1) > 1)
7636 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007637#else
7638 c1 = *s++;
7639#endif
7640 if (tab[i].cp == &lcs_tab2)
7641 {
7642 if (*s == NUL)
7643 continue;
7644#ifdef FEAT_MBYTE
7645 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007646 if (mb_char2cells(c2) > 1)
7647 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007648#else
7649 c2 = *s++;
7650#endif
7651 }
7652 if (*s == ',' || *s == NUL)
7653 {
7654 if (round)
7655 {
7656 if (tab[i].cp == &lcs_tab2)
7657 {
7658 lcs_tab1 = c1;
7659 lcs_tab2 = c2;
7660 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007661 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662 *(tab[i].cp) = c1;
7663
7664 }
7665 p = s;
7666 break;
7667 }
7668 }
7669 }
7670
7671 if (i == entries)
7672 return e_invarg;
7673 if (*p == ',')
7674 ++p;
7675 }
7676 }
7677
7678 return NULL; /* no error */
7679}
7680
7681#ifdef FEAT_STL_OPT
7682/*
7683 * Check validity of options with the 'statusline' format.
7684 * Return error message or NULL.
7685 */
7686 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007687check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007688{
7689 int itemcnt = 0;
7690 int groupdepth = 0;
7691 static char_u errbuf[80];
7692
7693 while (*s && itemcnt < STL_MAX_ITEM)
7694 {
7695 /* Check for valid keys after % sequences */
7696 while (*s && *s != '%')
7697 s++;
7698 if (!*s)
7699 break;
7700 s++;
7701 if (*s != '%' && *s != ')')
7702 ++itemcnt;
7703 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7704 {
7705 s++;
7706 continue;
7707 }
7708 if (*s == ')')
7709 {
7710 s++;
7711 if (--groupdepth < 0)
7712 break;
7713 continue;
7714 }
7715 if (*s == '-')
7716 s++;
7717 while (VIM_ISDIGIT(*s))
7718 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007719 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007720 continue;
7721 if (*s == '.')
7722 {
7723 s++;
7724 while (*s && VIM_ISDIGIT(*s))
7725 s++;
7726 }
7727 if (*s == '(')
7728 {
7729 groupdepth++;
7730 continue;
7731 }
7732 if (vim_strchr(STL_ALL, *s) == NULL)
7733 {
7734 return illegal_char(errbuf, *s);
7735 }
7736 if (*s == '{')
7737 {
7738 s++;
7739 while (*s != '}' && *s)
7740 s++;
7741 if (*s != '}')
7742 return (char_u *)N_("E540: Unclosed expression sequence");
7743 }
7744 }
7745 if (itemcnt >= STL_MAX_ITEM)
7746 return (char_u *)N_("E541: too many items");
7747 if (groupdepth != 0)
7748 return (char_u *)N_("E542: unbalanced groups");
7749 return NULL;
7750}
7751#endif
7752
7753#ifdef FEAT_CLIPBOARD
7754/*
7755 * Extract the items in the 'clipboard' option and set global values.
7756 */
7757 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007758check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007759{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007760 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007761 int new_autoselect_star = FALSE;
7762 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007763 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007764 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007765 regprog_T *new_exclude_prog = NULL;
7766 char_u *errmsg = NULL;
7767 char_u *p;
7768
7769 for (p = p_cb; *p != NUL; )
7770 {
7771 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7772 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007773 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774 p += 7;
7775 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007776 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007777 && (p[11] == ',' || p[11] == NUL))
7778 {
7779 new_unnamed |= CLIP_UNNAMED_PLUS;
7780 p += 11;
7781 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007782 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007783 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007785 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007786 p += 10;
7787 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007788 else if (STRNCMP(p, "autoselectplus", 14) == 0
7789 && (p[14] == ',' || p[14] == NUL))
7790 {
7791 new_autoselect_plus = TRUE;
7792 p += 14;
7793 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007794 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007795 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007796 {
7797 new_autoselectml = TRUE;
7798 p += 12;
7799 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007800 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7801 {
7802 new_html = TRUE;
7803 p += 4;
7804 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007805 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7806 {
7807 p += 8;
7808 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7809 if (new_exclude_prog == NULL)
7810 errmsg = e_invarg;
7811 break;
7812 }
7813 else
7814 {
7815 errmsg = e_invarg;
7816 break;
7817 }
7818 if (*p == ',')
7819 ++p;
7820 }
7821 if (errmsg == NULL)
7822 {
7823 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007824 clip_autoselect_star = new_autoselect_star;
7825 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007826 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007827 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007828 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007829 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007830#ifdef FEAT_GUI_GTK
7831 if (gui.in_use)
7832 {
7833 gui_gtk_set_selection_targets();
7834 gui_gtk_set_dnd_targets();
7835 }
7836#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837 }
7838 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007839 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007840
7841 return errmsg;
7842}
7843#endif
7844
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007845#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007846 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007847did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007848{
7849 char_u *errmsg = NULL;
7850 win_T *wp;
7851 int l;
7852
7853 if (is_spellfile)
7854 {
7855 l = (int)STRLEN(curwin->w_s->b_p_spf);
7856 if (l > 0 && (l < 4
7857 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7858 errmsg = e_invarg;
7859 }
7860
7861 if (errmsg == NULL)
7862 {
7863 FOR_ALL_WINDOWS(wp)
7864 if (wp->w_buffer == curbuf && wp->w_p_spell)
7865 {
7866 errmsg = did_set_spelllang(wp);
7867# ifdef FEAT_WINDOWS
7868 break;
7869# endif
7870 }
7871 }
7872 return errmsg;
7873}
7874
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007875/*
7876 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7877 * Return error message when failed, NULL when OK.
7878 */
7879 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007880compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007881{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007882 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007883 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007884
Bram Moolenaar860cae12010-06-05 23:22:07 +02007885 if (*synblock->b_p_spc == NUL)
7886 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007887 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007888 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007889 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007890 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007891 if (re != NULL)
7892 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007893 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007894 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007895 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007896 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007897 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007898 return e_invarg;
7899 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007900 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007901 }
7902
Bram Moolenaar473de612013-06-08 18:19:48 +02007903 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007904 return NULL;
7905}
7906#endif
7907
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007908#if defined(FEAT_EVAL) || defined(PROTO)
7909/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007910 * Set the scriptID for an option, taking care of setting the buffer- or
7911 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007912 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007913 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007914set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007915{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007916 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7917 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007918
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007919 /* Remember where the option was set. For local options need to do that
7920 * in the buffer or window structure. */
7921 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007922 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007923 if (both || (opt_flags & OPT_LOCAL))
7924 {
7925 if (indir & PV_BUF)
7926 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7927 else if (indir & PV_WIN)
7928 curwin->w_p_scriptID[indir & PV_MASK] = id;
7929 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007930}
7931#endif
7932
Bram Moolenaar071d4272004-06-13 20:20:40 +00007933/*
7934 * Set the value of a boolean option, and take care of side effects.
7935 * Returns NULL for success, or an error message for an error.
7936 */
7937 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007938set_bool_option(
7939 int opt_idx, /* index in options[] table */
7940 char_u *varp, /* pointer to the option variable */
7941 int value, /* new value */
7942 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943{
7944 int old_value = *(int *)varp;
7945
Bram Moolenaar071d4272004-06-13 20:20:40 +00007946 /* Disallow changing some options from secure mode */
7947 if ((secure
7948#ifdef HAVE_SANDBOX
7949 || sandbox != 0
7950#endif
7951 ) && (options[opt_idx].flags & P_SECURE))
7952 return e_secure;
7953
7954 *(int *)varp = value; /* set the new value */
7955#ifdef FEAT_EVAL
7956 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007957 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958#endif
7959
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007960#ifdef FEAT_GUI
7961 need_mouse_correct = TRUE;
7962#endif
7963
Bram Moolenaar071d4272004-06-13 20:20:40 +00007964 /* May set global value for local option. */
7965 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7966 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7967
7968 /*
7969 * Handle side effects of changing a bool option.
7970 */
7971
7972 /* 'compatible' */
7973 if ((int *)varp == &p_cp)
7974 {
7975 compatible_set();
7976 }
7977
Bram Moolenaar920694c2016-08-21 17:45:02 +02007978#ifdef FEAT_LANGMAP
7979 if ((int *)varp == &p_lrm)
7980 /* 'langremap' -> !'langnoremap' */
7981 p_lnr = !p_lrm;
7982 else if ((int *)varp == &p_lnr)
7983 /* 'langnoremap' -> !'langremap' */
7984 p_lrm = !p_lnr;
7985#endif
7986
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007987#ifdef FEAT_PERSISTENT_UNDO
7988 /* 'undofile' */
7989 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7990 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007991 /* Only take action when the option was set. When reset we do not
7992 * delete the undo file, the option may be set again without making
7993 * any changes in between. */
7994 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007995 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007996 char_u hash[UNDO_HASH_SIZE];
7997 buf_T *save_curbuf = curbuf;
7998
Bram Moolenaar29323592016-07-24 22:04:11 +02007999 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008000 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008001 /* When 'undofile' is set globally: for every buffer, otherwise
8002 * only for the current buffer: Try to read in the undofile,
8003 * if one exists, the buffer wasn't changed and the buffer was
8004 * loaded */
8005 if ((curbuf == save_curbuf
8006 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8007 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8008 {
8009 u_compute_hash(hash);
8010 u_read_undo(NULL, hash, curbuf->b_fname);
8011 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008012 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008013 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008014 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008015 }
8016#endif
8017
Bram Moolenaar071d4272004-06-13 20:20:40 +00008018 else if ((int *)varp == &curbuf->b_p_ro)
8019 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008020 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8022 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008023
8024 /* when 'readonly' is set may give W10 again */
8025 if (curbuf->b_p_ro)
8026 curbuf->b_did_warn = FALSE;
8027
Bram Moolenaar071d4272004-06-13 20:20:40 +00008028#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008029 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008030#endif
8031 }
8032
Bram Moolenaar9c449722010-07-20 18:44:27 +02008033#ifdef FEAT_GUI
8034 else if ((int *)varp == &p_mh)
8035 {
8036 if (!p_mh)
8037 gui_mch_mousehide(FALSE);
8038 }
8039#endif
8040
Bram Moolenaara539df02010-08-01 14:35:05 +02008041#ifdef FEAT_TITLE
8042 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008043 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008044 {
8045 redraw_titles();
8046 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008047 /* when 'endofline' is changed, redraw the window title */
8048 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008049 {
8050 redraw_titles();
8051 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008052 /* when 'fixeol' is changed, redraw the window title */
8053 else if ((int *)varp == &curbuf->b_p_fixeol)
8054 {
8055 redraw_titles();
8056 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008057# ifdef FEAT_MBYTE
8058 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008059 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008060 {
8061 redraw_titles();
8062 }
8063# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064#endif
8065
8066 /* when 'bin' is set also set some other options */
8067 else if ((int *)varp == &curbuf->b_p_bin)
8068 {
8069 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8070#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008071 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072#endif
8073 }
8074
8075#ifdef FEAT_AUTOCMD
8076 /* when 'buflisted' changes, trigger autocommands */
8077 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8078 {
8079 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8080 NULL, NULL, TRUE, curbuf);
8081 }
8082#endif
8083
8084 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8085 else if ((int *)varp == &curbuf->b_p_swf)
8086 {
8087 if (curbuf->b_p_swf && p_uc)
8088 ml_open_file(curbuf); /* create the swap file */
8089 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008090 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8091 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008092 mf_close_file(curbuf, TRUE); /* remove the swap file */
8093 }
8094
8095 /* when 'terse' is set change 'shortmess' */
8096 else if ((int *)varp == &p_terse)
8097 {
8098 char_u *p;
8099
8100 p = vim_strchr(p_shm, SHM_SEARCH);
8101
8102 /* insert 's' in p_shm */
8103 if (p_terse && p == NULL)
8104 {
8105 STRCPY(IObuff, p_shm);
8106 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008107 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008108 }
8109 /* remove 's' from p_shm */
8110 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008111 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008112 }
8113
8114 /* when 'paste' is set or reset also change other options */
8115 else if ((int *)varp == &p_paste)
8116 {
8117 paste_option_changed();
8118 }
8119
8120 /* when 'insertmode' is set from an autocommand need to do work here */
8121 else if ((int *)varp == &p_im)
8122 {
8123 if (p_im)
8124 {
8125 if ((State & INSERT) == 0)
8126 need_start_insertmode = TRUE;
8127 stop_insert_mode = FALSE;
8128 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008129 /* only reset if it was set previously */
8130 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008131 {
8132 need_start_insertmode = FALSE;
8133 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008134 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 clear_cmdline = TRUE; /* remove "(insert)" */
8136 restart_edit = 0;
8137 }
8138 }
8139
8140 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8141 else if ((int *)varp == &p_ic && p_hls)
8142 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008143 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144 }
8145
8146#ifdef FEAT_SEARCH_EXTRA
8147 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8148 else if ((int *)varp == &p_hls)
8149 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008150 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151 }
8152#endif
8153
8154#ifdef FEAT_SCROLLBIND
8155 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8156 * at the end of normal_cmd() */
8157 else if ((int *)varp == &curwin->w_p_scb)
8158 {
8159 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008160 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008161 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008162 curwin->w_scbind_pos = curwin->w_topline;
8163 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164 }
8165#endif
8166
8167#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8168 /* There can be only one window with 'previewwindow' set. */
8169 else if ((int *)varp == &curwin->w_p_pvw)
8170 {
8171 if (curwin->w_p_pvw)
8172 {
8173 win_T *win;
8174
Bram Moolenaar29323592016-07-24 22:04:11 +02008175 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008176 if (win->w_p_pvw && win != curwin)
8177 {
8178 curwin->w_p_pvw = FALSE;
8179 return (char_u *)N_("E590: A preview window already exists");
8180 }
8181 }
8182 }
8183#endif
8184
8185 /* when 'textmode' is set or reset also change 'fileformat' */
8186 else if ((int *)varp == &curbuf->b_p_tx)
8187 {
8188 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8189 }
8190
8191 /* when 'textauto' is set or reset also change 'fileformats' */
8192 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193 set_string_option_direct((char_u *)"ffs", -1,
8194 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008195 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008196
8197 /*
8198 * When 'lisp' option changes include/exclude '-' in
8199 * keyword characters.
8200 */
8201#ifdef FEAT_LISP
8202 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8203 {
8204 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8205 }
8206#endif
8207
8208#ifdef FEAT_TITLE
8209 /* when 'title' changed, may need to change the title; same for 'icon' */
8210 else if ((int *)varp == &p_title)
8211 {
8212 did_set_title(FALSE);
8213 }
8214
8215 else if ((int *)varp == &p_icon)
8216 {
8217 did_set_title(TRUE);
8218 }
8219#endif
8220
8221 else if ((int *)varp == &curbuf->b_changed)
8222 {
8223 if (!value)
8224 save_file_ff(curbuf); /* Buffer is unchanged */
8225#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008226 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008227#endif
8228#ifdef FEAT_AUTOCMD
8229 modified_was_set = value;
8230#endif
8231 }
8232
8233#ifdef BACKSLASH_IN_FILENAME
8234 else if ((int *)varp == &p_ssl)
8235 {
8236 if (p_ssl)
8237 {
8238 psepc = '/';
8239 psepcN = '\\';
8240 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241 }
8242 else
8243 {
8244 psepc = '\\';
8245 psepcN = '/';
8246 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008247 }
8248
8249 /* need to adjust the file name arguments and buffer names. */
8250 buflist_slash_adjust();
8251 alist_slash_adjust();
8252# ifdef FEAT_EVAL
8253 scriptnames_slash_adjust();
8254# endif
8255 }
8256#endif
8257
8258 /* If 'wrap' is set, set w_leftcol to zero. */
8259 else if ((int *)varp == &curwin->w_p_wrap)
8260 {
8261 if (curwin->w_p_wrap)
8262 curwin->w_leftcol = 0;
8263 }
8264
8265#ifdef FEAT_WINDOWS
8266 else if ((int *)varp == &p_ea)
8267 {
8268 if (p_ea && !old_value)
8269 win_equal(curwin, FALSE, 0);
8270 }
8271#endif
8272
8273 else if ((int *)varp == &p_wiv)
8274 {
8275 /*
8276 * When 'weirdinvert' changed, set/reset 't_xs'.
8277 * Then set 'weirdinvert' according to value of 't_xs'.
8278 */
8279 if (p_wiv && !old_value)
8280 T_XS = (char_u *)"y";
8281 else if (!p_wiv && old_value)
8282 T_XS = empty_option;
8283 p_wiv = (*T_XS != NUL);
8284 }
8285
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008286#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008287 else if ((int *)varp == &p_beval)
8288 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008289 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008291 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008292 gui_mch_disable_beval_area(balloonEval);
8293 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008294#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008295
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008296#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 else if ((int *)varp == &p_acd)
8298 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008299 /* Change directories when the 'acd' option is set now. */
8300 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301 }
8302#endif
8303
8304#ifdef FEAT_DIFF
8305 /* 'diff' */
8306 else if ((int *)varp == &curwin->w_p_diff)
8307 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008308 /* May add or remove the buffer from the list of diff buffers. */
8309 diff_buf_adjust(curwin);
8310# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008311 if (foldmethodIsDiff(curwin))
8312 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008313# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 }
8315#endif
8316
8317#ifdef USE_IM_CONTROL
8318 /* 'imdisable' */
8319 else if ((int *)varp == &p_imdisable)
8320 {
8321 /* Only de-activate it here, it will be enabled when changing mode. */
8322 if (p_imdisable)
8323 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008324 else if (State & INSERT)
8325 /* When the option is set from an autocommand, it may need to take
8326 * effect right away. */
8327 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008328 }
8329#endif
8330
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008331#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008332 /* 'spell' */
8333 else if ((int *)varp == &curwin->w_p_spell)
8334 {
8335 if (curwin->w_p_spell)
8336 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008337 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008338 if (errmsg != NULL)
8339 EMSG(_(errmsg));
8340 }
8341 }
8342#endif
8343
Bram Moolenaar071d4272004-06-13 20:20:40 +00008344#ifdef FEAT_FKMAP
8345 else if ((int *)varp == &p_altkeymap)
8346 {
8347 if (old_value != p_altkeymap)
8348 {
8349 if (!p_altkeymap)
8350 {
8351 p_hkmap = p_fkmap;
8352 p_fkmap = 0;
8353 }
8354 else
8355 {
8356 p_fkmap = p_hkmap;
8357 p_hkmap = 0;
8358 }
8359 (void)init_chartab();
8360 }
8361 }
8362
8363 /*
8364 * In case some second language keymapping options have changed, check
8365 * and correct the setting in a consistent way.
8366 */
8367
8368 /*
8369 * If hkmap or fkmap are set, reset Arabic keymapping.
8370 */
8371 if ((p_hkmap || p_fkmap) && p_altkeymap)
8372 {
8373 p_altkeymap = p_fkmap;
8374# ifdef FEAT_ARABIC
8375 curwin->w_p_arab = FALSE;
8376# endif
8377 (void)init_chartab();
8378 }
8379
8380 /*
8381 * If hkmap set, reset Farsi keymapping.
8382 */
8383 if (p_hkmap && p_altkeymap)
8384 {
8385 p_altkeymap = 0;
8386 p_fkmap = 0;
8387# ifdef FEAT_ARABIC
8388 curwin->w_p_arab = FALSE;
8389# endif
8390 (void)init_chartab();
8391 }
8392
8393 /*
8394 * If fkmap set, reset Hebrew keymapping.
8395 */
8396 if (p_fkmap && !p_altkeymap)
8397 {
8398 p_altkeymap = 1;
8399 p_hkmap = 0;
8400# ifdef FEAT_ARABIC
8401 curwin->w_p_arab = FALSE;
8402# endif
8403 (void)init_chartab();
8404 }
8405#endif
8406
8407#ifdef FEAT_ARABIC
8408 if ((int *)varp == &curwin->w_p_arab)
8409 {
8410 if (curwin->w_p_arab)
8411 {
8412 /*
8413 * 'arabic' is set, handle various sub-settings.
8414 */
8415 if (!p_tbidi)
8416 {
8417 /* set rightleft mode */
8418 if (!curwin->w_p_rl)
8419 {
8420 curwin->w_p_rl = TRUE;
8421 changed_window_setting();
8422 }
8423
8424 /* Enable Arabic shaping (major part of what Arabic requires) */
8425 if (!p_arshape)
8426 {
8427 p_arshape = TRUE;
8428 redraw_later_clear();
8429 }
8430 }
8431
8432 /* Arabic requires a utf-8 encoding, inform the user if its not
8433 * set. */
8434 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008435 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008436 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8437
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008438 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008439 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8440#ifdef FEAT_EVAL
8441 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8442#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008443 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008444
8445# ifdef FEAT_MBYTE
8446 /* set 'delcombine' */
8447 p_deco = TRUE;
8448# endif
8449
8450# ifdef FEAT_KEYMAP
8451 /* Force-set the necessary keymap for arabic */
8452 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8453 OPT_LOCAL);
8454# endif
8455# ifdef FEAT_FKMAP
8456 p_altkeymap = 0;
8457 p_hkmap = 0;
8458 p_fkmap = 0;
8459 (void)init_chartab();
8460# endif
8461 }
8462 else
8463 {
8464 /*
8465 * 'arabic' is reset, handle various sub-settings.
8466 */
8467 if (!p_tbidi)
8468 {
8469 /* reset rightleft mode */
8470 if (curwin->w_p_rl)
8471 {
8472 curwin->w_p_rl = FALSE;
8473 changed_window_setting();
8474 }
8475
8476 /* 'arabicshape' isn't reset, it is a global option and
8477 * another window may still need it "on". */
8478 }
8479
8480 /* 'delcombine' isn't reset, it is a global option and another
8481 * window may still want it "on". */
8482
8483# ifdef FEAT_KEYMAP
8484 /* Revert to the default keymap */
8485 curbuf->b_p_iminsert = B_IMODE_NONE;
8486 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8487# endif
8488 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008489 }
8490
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008491#endif
8492
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008493#ifdef FEAT_TERMGUICOLORS
8494 /* 'termguicolors' */
8495 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008496 {
8497# ifdef FEAT_GUI
8498 if (!gui.in_use && !gui.starting)
8499# endif
8500 highlight_gui_started();
8501 }
8502#endif
8503
Bram Moolenaar071d4272004-06-13 20:20:40 +00008504 /*
8505 * End of handling side effects for bool options.
8506 */
8507
Bram Moolenaar53744302015-07-17 17:38:22 +02008508 /* after handling side effects, call autocommand */
8509
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510 options[opt_idx].flags |= P_WAS_SET;
8511
Bram Moolenaar53744302015-07-17 17:38:22 +02008512#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8513 if (!starting)
8514 {
8515 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008516 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8517 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8518 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008519 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8520 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8521 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8522 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8523 reset_v_option_vars();
8524 }
8525#endif
8526
Bram Moolenaar071d4272004-06-13 20:20:40 +00008527 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008528 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008529 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008530 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531 check_redraw(options[opt_idx].flags);
8532
8533 return NULL;
8534}
8535
8536/*
8537 * Set the value of a number option, and take care of side effects.
8538 * Returns NULL for success, or an error message for an error.
8539 */
8540 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008541set_num_option(
8542 int opt_idx, /* index in options[] table */
8543 char_u *varp, /* pointer to the option variable */
8544 long value, /* new value */
8545 char_u *errbuf, /* buffer for error messages */
8546 size_t errbuflen, /* length of "errbuf" */
8547 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008548 OPT_MODELINE */
8549{
8550 char_u *errmsg = NULL;
8551 long old_value = *(long *)varp;
8552 long old_Rows = Rows; /* remember old Rows */
8553 long old_Columns = Columns; /* remember old Columns */
8554 long *pp = (long *)varp;
8555
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008556 /* Disallow changing some options from secure mode. */
8557 if ((secure
8558#ifdef HAVE_SANDBOX
8559 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008561 ) && (options[opt_idx].flags & P_SECURE))
8562 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563
8564 *pp = value;
8565#ifdef FEAT_EVAL
8566 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008567 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008568#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008569#ifdef FEAT_GUI
8570 need_mouse_correct = TRUE;
8571#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008572
Bram Moolenaar14f24742012-08-08 18:01:05 +02008573 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008574 {
8575 errmsg = e_positive;
8576 curbuf->b_p_sw = curbuf->b_p_ts;
8577 }
8578
8579 /*
8580 * Number options that need some action when changed
8581 */
8582#ifdef FEAT_WINDOWS
8583 if (pp == &p_wh || pp == &p_hh)
8584 {
8585 if (p_wh < 1)
8586 {
8587 errmsg = e_positive;
8588 p_wh = 1;
8589 }
8590 if (p_wmh > p_wh)
8591 {
8592 errmsg = e_winheight;
8593 p_wh = p_wmh;
8594 }
8595 if (p_hh < 0)
8596 {
8597 errmsg = e_positive;
8598 p_hh = 0;
8599 }
8600
8601 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008602 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008603 {
8604 if (pp == &p_wh && curwin->w_height < p_wh)
8605 win_setheight((int)p_wh);
8606 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8607 win_setheight((int)p_hh);
8608 }
8609 }
8610
8611 /* 'winminheight' */
8612 else if (pp == &p_wmh)
8613 {
8614 if (p_wmh < 0)
8615 {
8616 errmsg = e_positive;
8617 p_wmh = 0;
8618 }
8619 if (p_wmh > p_wh)
8620 {
8621 errmsg = e_winheight;
8622 p_wmh = p_wh;
8623 }
8624 win_setminheight();
8625 }
8626
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008627# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008628 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008629 {
8630 if (p_wiw < 1)
8631 {
8632 errmsg = e_positive;
8633 p_wiw = 1;
8634 }
8635 if (p_wmw > p_wiw)
8636 {
8637 errmsg = e_winwidth;
8638 p_wiw = p_wmw;
8639 }
8640
8641 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008642 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008643 win_setwidth((int)p_wiw);
8644 }
8645
8646 /* 'winminwidth' */
8647 else if (pp == &p_wmw)
8648 {
8649 if (p_wmw < 0)
8650 {
8651 errmsg = e_positive;
8652 p_wmw = 0;
8653 }
8654 if (p_wmw > p_wiw)
8655 {
8656 errmsg = e_winwidth;
8657 p_wmw = p_wiw;
8658 }
8659 win_setminheight();
8660 }
8661# endif
8662
8663#endif
8664
8665#ifdef FEAT_WINDOWS
8666 /* (re)set last window status line */
8667 else if (pp == &p_ls)
8668 {
8669 last_status(FALSE);
8670 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008671
8672 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008673 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008674 {
8675 shell_new_rows(); /* recompute window positions and heights */
8676 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008677#endif
8678
8679#ifdef FEAT_GUI
8680 else if (pp == &p_linespace)
8681 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008682 /* Recompute gui.char_height and resize the Vim window to keep the
8683 * same number of lines. */
8684 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008685 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008686 }
8687#endif
8688
8689#ifdef FEAT_FOLDING
8690 /* 'foldlevel' */
8691 else if (pp == &curwin->w_p_fdl)
8692 {
8693 if (curwin->w_p_fdl < 0)
8694 curwin->w_p_fdl = 0;
8695 newFoldLevel();
8696 }
8697
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008698 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699 else if (pp == &curwin->w_p_fml)
8700 {
8701 foldUpdateAll(curwin);
8702 }
8703
8704 /* 'foldnestmax' */
8705 else if (pp == &curwin->w_p_fdn)
8706 {
8707 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8708 foldUpdateAll(curwin);
8709 }
8710
8711 /* 'foldcolumn' */
8712 else if (pp == &curwin->w_p_fdc)
8713 {
8714 if (curwin->w_p_fdc < 0)
8715 {
8716 errmsg = e_positive;
8717 curwin->w_p_fdc = 0;
8718 }
8719 else if (curwin->w_p_fdc > 12)
8720 {
8721 errmsg = e_invarg;
8722 curwin->w_p_fdc = 12;
8723 }
8724 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008725#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008727#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008728 /* 'shiftwidth' or 'tabstop' */
8729 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8730 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008731# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008732 if (foldmethodIsIndent(curwin))
8733 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008734# endif
8735# ifdef FEAT_CINDENT
8736 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8737 * parse 'cinoptions'. */
8738 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8739 parse_cino(curbuf);
8740# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008741 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008742#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008743
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008744#ifdef FEAT_MBYTE
8745 /* 'maxcombine' */
8746 else if (pp == &p_mco)
8747 {
8748 if (p_mco > MAX_MCO)
8749 p_mco = MAX_MCO;
8750 else if (p_mco < 0)
8751 p_mco = 0;
8752 screenclear(); /* will re-allocate the screen */
8753 }
8754#endif
8755
Bram Moolenaar071d4272004-06-13 20:20:40 +00008756 else if (pp == &curbuf->b_p_iminsert)
8757 {
8758 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8759 {
8760 errmsg = e_invarg;
8761 curbuf->b_p_iminsert = B_IMODE_NONE;
8762 }
8763 p_iminsert = curbuf->b_p_iminsert;
8764 if (termcap_active) /* don't do this in the alternate screen */
8765 showmode();
8766#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8767 /* Show/unshow value of 'keymap' in status lines. */
8768 status_redraw_curbuf();
8769#endif
8770 }
8771
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008772 else if (pp == &p_window)
8773 {
8774 if (p_window < 1)
8775 p_window = 1;
8776 else if (p_window >= Rows)
8777 p_window = Rows - 1;
8778 }
8779
Bram Moolenaar071d4272004-06-13 20:20:40 +00008780 else if (pp == &curbuf->b_p_imsearch)
8781 {
8782 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8783 {
8784 errmsg = e_invarg;
8785 curbuf->b_p_imsearch = B_IMODE_NONE;
8786 }
8787 p_imsearch = curbuf->b_p_imsearch;
8788 }
8789
8790#ifdef FEAT_TITLE
8791 /* if 'titlelen' has changed, redraw the title */
8792 else if (pp == &p_titlelen)
8793 {
8794 if (p_titlelen < 0)
8795 {
8796 errmsg = e_positive;
8797 p_titlelen = 85;
8798 }
8799 if (starting != NO_SCREEN && old_value != p_titlelen)
8800 need_maketitle = TRUE;
8801 }
8802#endif
8803
8804 /* if p_ch changed value, change the command line height */
8805 else if (pp == &p_ch)
8806 {
8807 if (p_ch < 1)
8808 {
8809 errmsg = e_positive;
8810 p_ch = 1;
8811 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008812 if (p_ch > Rows - min_rows() + 1)
8813 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008814
8815 /* Only compute the new window layout when startup has been
8816 * completed. Otherwise the frame sizes may be wrong. */
8817 if (p_ch != old_value && full_screen
8818#ifdef FEAT_GUI
8819 && !gui.starting
8820#endif
8821 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008822 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 }
8824
8825 /* when 'updatecount' changes from zero to non-zero, open swap files */
8826 else if (pp == &p_uc)
8827 {
8828 if (p_uc < 0)
8829 {
8830 errmsg = e_positive;
8831 p_uc = 100;
8832 }
8833 if (p_uc && !old_value)
8834 ml_open_files();
8835 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008836#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008837 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008838 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008839 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008840 {
8841 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008842 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008843 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008844 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008845 {
8846 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008847 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008848 }
8849 }
8850#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008851#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008852 else if (pp == &p_mzq)
8853 mzvim_reset_timer();
8854#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008856#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8857 /* 'pyxversion' */
8858 else if (pp == &p_pyx)
8859 {
8860 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8861 errmsg = e_invarg;
8862 }
8863#endif
8864
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 /* sync undo before 'undolevels' changes */
8866 else if (pp == &p_ul)
8867 {
8868 /* use the old value, otherwise u_sync() may not work properly */
8869 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008870 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008871 p_ul = value;
8872 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008873 else if (pp == &curbuf->b_p_ul)
8874 {
8875 /* use the old value, otherwise u_sync() may not work properly */
8876 curbuf->b_p_ul = old_value;
8877 u_sync(TRUE);
8878 curbuf->b_p_ul = value;
8879 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008881#ifdef FEAT_LINEBREAK
8882 /* 'numberwidth' must be positive */
8883 else if (pp == &curwin->w_p_nuw)
8884 {
8885 if (curwin->w_p_nuw < 1)
8886 {
8887 errmsg = e_positive;
8888 curwin->w_p_nuw = 1;
8889 }
8890 if (curwin->w_p_nuw > 10)
8891 {
8892 errmsg = e_invarg;
8893 curwin->w_p_nuw = 10;
8894 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008895 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008896 }
8897#endif
8898
Bram Moolenaar1a384422010-07-14 19:53:30 +02008899 else if (pp == &curbuf->b_p_tw)
8900 {
8901 if (curbuf->b_p_tw < 0)
8902 {
8903 errmsg = e_positive;
8904 curbuf->b_p_tw = 0;
8905 }
8906#ifdef FEAT_SYN_HL
8907# ifdef FEAT_WINDOWS
8908 {
8909 win_T *wp;
8910 tabpage_T *tp;
8911
8912 FOR_ALL_TAB_WINDOWS(tp, wp)
8913 check_colorcolumn(wp);
8914 }
8915# else
8916 check_colorcolumn(curwin);
8917# endif
8918#endif
8919 }
8920
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921 /*
8922 * Check the bounds for numeric options here
8923 */
8924 if (Rows < min_rows() && full_screen)
8925 {
8926 if (errbuf != NULL)
8927 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008928 vim_snprintf((char *)errbuf, errbuflen,
8929 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008930 errmsg = errbuf;
8931 }
8932 Rows = min_rows();
8933 }
8934 if (Columns < MIN_COLUMNS && full_screen)
8935 {
8936 if (errbuf != NULL)
8937 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008938 vim_snprintf((char *)errbuf, errbuflen,
8939 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940 errmsg = errbuf;
8941 }
8942 Columns = MIN_COLUMNS;
8943 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008944 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945
Bram Moolenaar071d4272004-06-13 20:20:40 +00008946 /*
8947 * If the screen (shell) height has been changed, assume it is the
8948 * physical screenheight.
8949 */
8950 if (old_Rows != Rows || old_Columns != Columns)
8951 {
8952 /* Changing the screen size is not allowed while updating the screen. */
8953 if (updating_screen)
8954 *pp = old_value;
8955 else if (full_screen
8956#ifdef FEAT_GUI
8957 && !gui.starting
8958#endif
8959 )
8960 set_shellsize((int)Columns, (int)Rows, TRUE);
8961 else
8962 {
8963 /* Postpone the resizing; check the size and cmdline position for
8964 * messages. */
8965 check_shellsize();
8966 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8967 cmdline_row = Rows - p_ch;
8968 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008969 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008970 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008971 }
8972
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973 if (curbuf->b_p_ts <= 0)
8974 {
8975 errmsg = e_positive;
8976 curbuf->b_p_ts = 8;
8977 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 if (p_tm < 0)
8979 {
8980 errmsg = e_positive;
8981 p_tm = 0;
8982 }
8983 if ((curwin->w_p_scr <= 0
8984 || (curwin->w_p_scr > curwin->w_height
8985 && curwin->w_height > 0))
8986 && full_screen)
8987 {
8988 if (pp == &(curwin->w_p_scr))
8989 {
8990 if (curwin->w_p_scr != 0)
8991 errmsg = e_scroll;
8992 win_comp_scroll(curwin);
8993 }
8994 /* If 'scroll' became invalid because of a side effect silently adjust
8995 * it. */
8996 else if (curwin->w_p_scr <= 0)
8997 curwin->w_p_scr = 1;
8998 else /* curwin->w_p_scr > curwin->w_height */
8999 curwin->w_p_scr = curwin->w_height;
9000 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009001 if (p_hi < 0)
9002 {
9003 errmsg = e_positive;
9004 p_hi = 0;
9005 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009006 else if (p_hi > 10000)
9007 {
9008 errmsg = e_invarg;
9009 p_hi = 10000;
9010 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009011 if (p_re < 0 || p_re > 2)
9012 {
9013 errmsg = e_invarg;
9014 p_re = 0;
9015 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016 if (p_report < 0)
9017 {
9018 errmsg = e_positive;
9019 p_report = 1;
9020 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009021 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009022 {
9023 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9024 p_sj = Rows / 2;
9025 else
9026 {
9027 errmsg = e_scroll;
9028 p_sj = 1;
9029 }
9030 }
9031 if (p_so < 0 && full_screen)
9032 {
9033 errmsg = e_scroll;
9034 p_so = 0;
9035 }
9036 if (p_siso < 0 && full_screen)
9037 {
9038 errmsg = e_positive;
9039 p_siso = 0;
9040 }
9041#ifdef FEAT_CMDWIN
9042 if (p_cwh < 1)
9043 {
9044 errmsg = e_positive;
9045 p_cwh = 1;
9046 }
9047#endif
9048 if (p_ut < 0)
9049 {
9050 errmsg = e_positive;
9051 p_ut = 2000;
9052 }
9053 if (p_ss < 0)
9054 {
9055 errmsg = e_positive;
9056 p_ss = 0;
9057 }
9058
9059 /* May set global value for local option. */
9060 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9061 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9062
9063 options[opt_idx].flags |= P_WAS_SET;
9064
Bram Moolenaar53744302015-07-17 17:38:22 +02009065#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9066 if (!starting && errmsg == NULL)
9067 {
9068 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009069 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9070 vim_snprintf((char *)buf_new, 10, "%ld", value);
9071 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009072 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9073 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9074 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9075 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9076 reset_v_option_vars();
9077 }
9078#endif
9079
Bram Moolenaar071d4272004-06-13 20:20:40 +00009080 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009081 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009082 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009083 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009084 check_redraw(options[opt_idx].flags);
9085
9086 return errmsg;
9087}
9088
9089/*
9090 * Called after an option changed: check if something needs to be redrawn.
9091 */
9092 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009093check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094{
9095 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009096 int doclear = (flags & P_RCLR) == P_RCLR;
9097 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009098
9099#ifdef FEAT_WINDOWS
9100 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9101 status_redraw_all();
9102#endif
9103
9104 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9105 changed_window_setting();
9106 if (flags & P_RBUF)
9107 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009108 if (flags & P_RWINONLY)
9109 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009110 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 redraw_all_later(CLEAR);
9112 else if (all)
9113 redraw_all_later(NOT_VALID);
9114}
9115
9116/*
9117 * Find index for option 'arg'.
9118 * Return -1 if not found.
9119 */
9120 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009121findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009122{
9123 int opt_idx;
9124 char *s, *p;
9125 static short quick_tab[27] = {0, 0}; /* quick access table */
9126 int is_term_opt;
9127
9128 /*
9129 * For first call: Initialize the quick-access table.
9130 * It contains the index for the first option that starts with a certain
9131 * letter. There are 26 letters, plus the first "t_" option.
9132 */
9133 if (quick_tab[1] == 0)
9134 {
9135 p = options[0].fullname;
9136 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9137 {
9138 if (s[0] != p[0])
9139 {
9140 if (s[0] == 't' && s[1] == '_')
9141 quick_tab[26] = opt_idx;
9142 else
9143 quick_tab[CharOrdLow(s[0])] = opt_idx;
9144 }
9145 p = s;
9146 }
9147 }
9148
9149 /*
9150 * Check for name starting with an illegal character.
9151 */
9152#ifdef EBCDIC
9153 if (!islower(arg[0]))
9154#else
9155 if (arg[0] < 'a' || arg[0] > 'z')
9156#endif
9157 return -1;
9158
9159 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9160 if (is_term_opt)
9161 opt_idx = quick_tab[26];
9162 else
9163 opt_idx = quick_tab[CharOrdLow(arg[0])];
9164 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9165 {
9166 if (STRCMP(arg, s) == 0) /* match full name */
9167 break;
9168 }
9169 if (s == NULL && !is_term_opt)
9170 {
9171 opt_idx = quick_tab[CharOrdLow(arg[0])];
9172 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9173 {
9174 s = options[opt_idx].shortname;
9175 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9176 break;
9177 s = NULL;
9178 }
9179 }
9180 if (s == NULL)
9181 opt_idx = -1;
9182 return opt_idx;
9183}
9184
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009185#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009186/*
9187 * Get the value for an option.
9188 *
9189 * Returns:
9190 * Number or Toggle option: 1, *numval gets value.
9191 * String option: 0, *stringval gets allocated string.
9192 * Hidden Number or Toggle option: -1.
9193 * hidden String option: -2.
9194 * unknown option: -3.
9195 */
9196 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009197get_option_value(
9198 char_u *name,
9199 long *numval,
9200 char_u **stringval, /* NULL when only checking existence */
9201 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009202{
9203 int opt_idx;
9204 char_u *varp;
9205
9206 opt_idx = findoption(name);
9207 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009208 {
9209 int key;
9210
9211 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9212 && (key = find_key_option(name)) != 0)
9213 {
9214 char_u key_name[2];
9215 char_u *p;
9216
9217 if (key < 0)
9218 {
9219 key_name[0] = KEY2TERMCAP0(key);
9220 key_name[1] = KEY2TERMCAP1(key);
9221 }
9222 else
9223 {
9224 key_name[0] = KS_KEY;
9225 key_name[1] = (key & 0xff);
9226 }
9227 p = find_termcode(key_name);
9228 if (p != NULL)
9229 {
9230 if (stringval != NULL)
9231 *stringval = vim_strsave(p);
9232 return 0;
9233 }
9234 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009235 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009236 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009237
9238 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9239
9240 if (options[opt_idx].flags & P_STRING)
9241 {
9242 if (varp == NULL) /* hidden option */
9243 return -2;
9244 if (stringval != NULL)
9245 {
9246#ifdef FEAT_CRYPT
9247 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009248 if ((char_u **)varp == &curbuf->b_p_key
9249 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009250 *stringval = vim_strsave((char_u *)"*****");
9251 else
9252#endif
9253 *stringval = vim_strsave(*(char_u **)(varp));
9254 }
9255 return 0;
9256 }
9257
9258 if (varp == NULL) /* hidden option */
9259 return -1;
9260 if (options[opt_idx].flags & P_NUM)
9261 *numval = *(long *)varp;
9262 else
9263 {
9264 /* Special case: 'modified' is b_changed, but we also want to consider
9265 * it set when 'ff' or 'fenc' changed. */
9266 if ((int *)varp == &curbuf->b_changed)
9267 *numval = curbufIsChanged();
9268 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009269 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009270 }
9271 return 1;
9272}
9273#endif
9274
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009275#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009276/*
9277 * Returns the option attributes and its value. Unlike the above function it
9278 * will return either global value or local value of the option depending on
9279 * what was requested, but it will never return global value if it was
9280 * requested to return local one and vice versa. Neither it will return
9281 * buffer-local value if it was requested to return window-local one.
9282 *
9283 * Pretends that option is absent if it is not present in the requested scope
9284 * (i.e. has no global, window-local or buffer-local value depending on
9285 * opt_type). Uses
9286 *
9287 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009288 * 0 hidden or unknown option, also option that does not have requested
9289 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009290 * see SOPT_* in vim.h for other flags
9291 *
9292 * Possible opt_type values: see SREQ_* in vim.h
9293 */
9294 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009295get_option_value_strict(
9296 char_u *name,
9297 long *numval,
9298 char_u **stringval, /* NULL when only obtaining attributes */
9299 int opt_type,
9300 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009301{
9302 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009303 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009304 struct vimoption *p;
9305 int r = 0;
9306
9307 opt_idx = findoption(name);
9308 if (opt_idx < 0)
9309 return 0;
9310
9311 p = &(options[opt_idx]);
9312
9313 /* Hidden option */
9314 if (p->var == NULL)
9315 return 0;
9316
9317 if (p->flags & P_BOOL)
9318 r |= SOPT_BOOL;
9319 else if (p->flags & P_NUM)
9320 r |= SOPT_NUM;
9321 else if (p->flags & P_STRING)
9322 r |= SOPT_STRING;
9323
9324 if (p->indir == PV_NONE)
9325 {
9326 if (opt_type == SREQ_GLOBAL)
9327 r |= SOPT_GLOBAL;
9328 else
9329 return 0; /* Did not request global-only option */
9330 }
9331 else
9332 {
9333 if (p->indir & PV_BOTH)
9334 r |= SOPT_GLOBAL;
9335 else if (opt_type == SREQ_GLOBAL)
9336 return 0; /* Requested global option */
9337
9338 if (p->indir & PV_WIN)
9339 {
9340 if (opt_type == SREQ_BUF)
9341 return 0; /* Did not request window-local option */
9342 else
9343 r |= SOPT_WIN;
9344 }
9345 else if (p->indir & PV_BUF)
9346 {
9347 if (opt_type == SREQ_WIN)
9348 return 0; /* Did not request buffer-local option */
9349 else
9350 r |= SOPT_BUF;
9351 }
9352 }
9353
9354 if (stringval == NULL)
9355 return r;
9356
9357 if (opt_type == SREQ_GLOBAL)
9358 varp = p->var;
9359 else
9360 {
9361 if (opt_type == SREQ_BUF)
9362 {
9363 /* Special case: 'modified' is b_changed, but we also want to
9364 * consider it set when 'ff' or 'fenc' changed. */
9365 if (p->indir == PV_MOD)
9366 {
9367 *numval = bufIsChanged((buf_T *) from);
9368 varp = NULL;
9369 }
9370#ifdef FEAT_CRYPT
9371 else if (p->indir == PV_KEY)
9372 {
9373 /* never return the value of the crypt key */
9374 *stringval = NULL;
9375 varp = NULL;
9376 }
9377#endif
9378 else
9379 {
9380 aco_save_T aco;
9381 aucmd_prepbuf(&aco, (buf_T *) from);
9382 varp = get_varp(p);
9383 aucmd_restbuf(&aco);
9384 }
9385 }
9386 else if (opt_type == SREQ_WIN)
9387 {
9388 win_T *save_curwin;
9389 save_curwin = curwin;
9390 curwin = (win_T *) from;
9391 curbuf = curwin->w_buffer;
9392 varp = get_varp(p);
9393 curwin = save_curwin;
9394 curbuf = curwin->w_buffer;
9395 }
9396 if (varp == p->var)
9397 return (r | SOPT_UNSET);
9398 }
9399
9400 if (varp != NULL)
9401 {
9402 if (p->flags & P_STRING)
9403 *stringval = vim_strsave(*(char_u **)(varp));
9404 else if (p->flags & P_NUM)
9405 *numval = *(long *) varp;
9406 else
9407 *numval = *(int *)varp;
9408 }
9409
9410 return r;
9411}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009412
9413/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009414 * Iterate over options. First argument is a pointer to a pointer to a
9415 * structure inside options[] array, second is option type like in the above
9416 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009417 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009418 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009419 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009420 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009421 * first argument to NULL.
9422 *
9423 * Returns full option name for current option on each call.
9424 */
9425 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009426option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009427{
9428 struct vimoption *ret = NULL;
9429 do
9430 {
9431 if (*option == NULL)
9432 *option = (void *) options;
9433 else if (((struct vimoption *) (*option))->fullname == NULL)
9434 {
9435 *option = NULL;
9436 return NULL;
9437 }
9438 else
9439 *option = (void *) (((struct vimoption *) (*option)) + 1);
9440
9441 ret = ((struct vimoption *) (*option));
9442
9443 /* Hidden option */
9444 if (ret->var == NULL)
9445 {
9446 ret = NULL;
9447 continue;
9448 }
9449
9450 switch (opt_type)
9451 {
9452 case SREQ_GLOBAL:
9453 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9454 ret = NULL;
9455 break;
9456 case SREQ_BUF:
9457 if (!(ret->indir & PV_BUF))
9458 ret = NULL;
9459 break;
9460 case SREQ_WIN:
9461 if (!(ret->indir & PV_WIN))
9462 ret = NULL;
9463 break;
9464 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009465 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009466 return NULL;
9467 }
9468 }
9469 while (ret == NULL);
9470
9471 return (char_u *)ret->fullname;
9472}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009473#endif
9474
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475/*
9476 * Set the value of option "name".
9477 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009478 *
9479 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009480 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009481 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009482set_option_value(
9483 char_u *name,
9484 long number,
9485 char_u *string,
9486 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009487{
9488 int opt_idx;
9489 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009490 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009491
9492 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009493 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009494 {
9495 int key;
9496
9497 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9498 && (key = find_key_option(name)) != 0)
9499 {
9500 char_u key_name[2];
9501
9502 if (key < 0)
9503 {
9504 key_name[0] = KEY2TERMCAP0(key);
9505 key_name[1] = KEY2TERMCAP1(key);
9506 }
9507 else
9508 {
9509 key_name[0] = KS_KEY;
9510 key_name[1] = (key & 0xff);
9511 }
9512 add_termcode(key_name, string, FALSE);
9513 if (full_screen)
9514 ttest(FALSE);
9515 redraw_all_later(CLEAR);
9516 return NULL;
9517 }
9518
Bram Moolenaar071d4272004-06-13 20:20:40 +00009519 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009520 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009521 else
9522 {
9523 flags = options[opt_idx].flags;
9524#ifdef HAVE_SANDBOX
9525 /* Disallow changing some options in the sandbox */
9526 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009527 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009528 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009529 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009530 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009531#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009532 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009533 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009534 else
9535 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009536 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009537 if (varp != NULL) /* hidden option is not changed */
9538 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009539 if (number == 0 && string != NULL)
9540 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009541 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009542
9543 /* Either we are given a string or we are setting option
9544 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009545 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009546 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009547 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009548 {
9549 /* There's another character after zeros or the string
9550 * is empty. In both cases, we are trying to set a
9551 * num option using a string. */
9552 EMSG3(_("E521: Number required: &%s = '%s'"),
9553 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009554 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009555
9556 }
9557 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009558 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009559 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009560 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009561 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009562 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009563 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009564 }
9565 }
9566 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009567 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568}
9569
9570/*
9571 * Get the terminal code for a terminal option.
9572 * Returns NULL when not found.
9573 */
9574 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009575get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576{
9577 int opt_idx;
9578 char_u *varp;
9579
9580 if (tname[0] != 't' || tname[1] != '_' ||
9581 tname[2] == NUL || tname[3] == NUL)
9582 return NULL;
9583 if ((opt_idx = findoption(tname)) >= 0)
9584 {
9585 varp = get_varp(&(options[opt_idx]));
9586 if (varp != NULL)
9587 varp = *(char_u **)(varp);
9588 return varp;
9589 }
9590 return find_termcode(tname + 2);
9591}
9592
9593 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009594get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009595{
9596 int i;
9597
9598 i = findoption((char_u *)"hl");
9599 if (i >= 0)
9600 return options[i].def_val[VI_DEFAULT];
9601 return (char_u *)NULL;
9602}
9603
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009604#if defined(FEAT_MBYTE) || defined(PROTO)
9605 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009606get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009607{
9608 int i;
9609
9610 i = findoption((char_u *)"enc");
9611 if (i >= 0)
9612 return options[i].def_val[VI_DEFAULT];
9613 return (char_u *)NULL;
9614}
9615#endif
9616
Bram Moolenaar071d4272004-06-13 20:20:40 +00009617/*
9618 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9619 */
9620 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009621find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009622{
9623 int key;
9624 int modifiers;
9625
9626 /*
9627 * Don't use get_special_key_code() for t_xx, we don't want it to call
9628 * add_termcap_entry().
9629 */
9630 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9631 key = TERMCAP2KEY(arg[2], arg[3]);
9632 else
9633 {
9634 --arg; /* put arg at the '<' */
9635 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009636 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009637 if (modifiers) /* can't handle modifiers here */
9638 key = 0;
9639 }
9640 return key;
9641}
9642
9643/*
9644 * if 'all' == 0: show changed options
9645 * if 'all' == 1: show all normal options
9646 * if 'all' == 2: show all terminal options
9647 */
9648 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009649showoptions(
9650 int all,
9651 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009652{
9653 struct vimoption *p;
9654 int col;
9655 int isterm;
9656 char_u *varp;
9657 struct vimoption **items;
9658 int item_count;
9659 int run;
9660 int row, rows;
9661 int cols;
9662 int i;
9663 int len;
9664
9665#define INC 20
9666#define GAP 3
9667
9668 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9669 PARAM_COUNT));
9670 if (items == NULL)
9671 return;
9672
9673 /* Highlight title */
9674 if (all == 2)
9675 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9676 else if (opt_flags & OPT_GLOBAL)
9677 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9678 else if (opt_flags & OPT_LOCAL)
9679 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9680 else
9681 MSG_PUTS_TITLE(_("\n--- Options ---"));
9682
9683 /*
9684 * do the loop two times:
9685 * 1. display the short items
9686 * 2. display the long items (only strings and numbers)
9687 */
9688 for (run = 1; run <= 2 && !got_int; ++run)
9689 {
9690 /*
9691 * collect the items in items[]
9692 */
9693 item_count = 0;
9694 for (p = &options[0]; p->fullname != NULL; p++)
9695 {
9696 varp = NULL;
9697 isterm = istermoption(p);
9698 if (opt_flags != 0)
9699 {
9700 if (p->indir != PV_NONE && !isterm)
9701 varp = get_varp_scope(p, opt_flags);
9702 }
9703 else
9704 varp = get_varp(p);
9705 if (varp != NULL
9706 && ((all == 2 && isterm)
9707 || (all == 1 && !isterm)
9708 || (all == 0 && !optval_default(p, varp))))
9709 {
9710 if (p->flags & P_BOOL)
9711 len = 1; /* a toggle option fits always */
9712 else
9713 {
9714 option_value2string(p, opt_flags);
9715 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9716 }
9717 if ((len <= INC - GAP && run == 1) ||
9718 (len > INC - GAP && run == 2))
9719 items[item_count++] = p;
9720 }
9721 }
9722
9723 /*
9724 * display the items
9725 */
9726 if (run == 1)
9727 {
9728 cols = (Columns + GAP - 3) / INC;
9729 if (cols == 0)
9730 cols = 1;
9731 rows = (item_count + cols - 1) / cols;
9732 }
9733 else /* run == 2 */
9734 rows = item_count;
9735 for (row = 0; row < rows && !got_int; ++row)
9736 {
9737 msg_putchar('\n'); /* go to next line */
9738 if (got_int) /* 'q' typed in more */
9739 break;
9740 col = 0;
9741 for (i = row; i < item_count; i += rows)
9742 {
9743 msg_col = col; /* make columns */
9744 showoneopt(items[i], opt_flags);
9745 col += INC;
9746 }
9747 out_flush();
9748 ui_breakcheck();
9749 }
9750 }
9751 vim_free(items);
9752}
9753
9754/*
9755 * Return TRUE if option "p" has its default value.
9756 */
9757 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009758optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009759{
9760 int dvi;
9761
9762 if (varp == NULL)
9763 return TRUE; /* hidden option is always at default */
9764 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9765 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009766 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009767 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009768 /* the cast to long is required for Manx C, long_i is
9769 * needed for MSVC */
9770 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009771 /* P_STRING */
9772 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9773}
9774
9775/*
9776 * showoneopt: show the value of one option
9777 * must not be called with a hidden option!
9778 */
9779 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009780showoneopt(
9781 struct vimoption *p,
9782 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009783{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009784 char_u *varp;
9785 int save_silent = silent_mode;
9786
9787 silent_mode = FALSE;
9788 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009789
9790 varp = get_varp_scope(p, opt_flags);
9791
9792 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9793 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9794 ? !curbufIsChanged() : !*(int *)varp))
9795 MSG_PUTS("no");
9796 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9797 MSG_PUTS("--");
9798 else
9799 MSG_PUTS(" ");
9800 MSG_PUTS(p->fullname);
9801 if (!(p->flags & P_BOOL))
9802 {
9803 msg_putchar('=');
9804 /* put value string in NameBuff */
9805 option_value2string(p, opt_flags);
9806 msg_outtrans(NameBuff);
9807 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009808
9809 silent_mode = save_silent;
9810 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009811}
9812
9813/*
9814 * Write modified options as ":set" commands to a file.
9815 *
9816 * There are three values for "opt_flags":
9817 * OPT_GLOBAL: Write global option values and fresh values of
9818 * buffer-local options (used for start of a session
9819 * file).
9820 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9821 * curwin (used for a vimrc file).
9822 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9823 * and local values for window-local options of
9824 * curwin. Local values are also written when at the
9825 * default value, because a modeline or autocommand
9826 * may have set them when doing ":edit file" and the
9827 * user has set them back at the default or fresh
9828 * value.
9829 * When "local_only" is TRUE, don't write fresh
9830 * values, only local values (for ":mkview").
9831 * (fresh value = value used for a new buffer or window for a local option).
9832 *
9833 * Return FAIL on error, OK otherwise.
9834 */
9835 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009836makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009837{
9838 struct vimoption *p;
9839 char_u *varp; /* currently used value */
9840 char_u *varp_fresh; /* local value */
9841 char_u *varp_local = NULL; /* fresh value */
9842 char *cmd;
9843 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009844 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009845
9846 /*
9847 * The options that don't have a default (terminal name, columns, lines)
9848 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009849 * Do the loop over "options[]" twice: once for options with the
9850 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009851 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009852 for (pri = 1; pri >= 0; --pri)
9853 {
9854 for (p = &options[0]; !istermoption(p); p++)
9855 if (!(p->flags & P_NO_MKRC)
9856 && !istermoption(p)
9857 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009858 {
9859 /* skip global option when only doing locals */
9860 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9861 continue;
9862
9863 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9864 * file, they are always buffer-specific. */
9865 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9866 continue;
9867
9868 /* Global values are only written when not at the default value. */
9869 varp = get_varp_scope(p, opt_flags);
9870 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9871 continue;
9872
9873 round = 2;
9874 if (p->indir != PV_NONE)
9875 {
9876 if (p->var == VAR_WIN)
9877 {
9878 /* skip window-local option when only doing globals */
9879 if (!(opt_flags & OPT_LOCAL))
9880 continue;
9881 /* When fresh value of window-local option is not at the
9882 * default, need to write it too. */
9883 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9884 {
9885 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9886 if (!optval_default(p, varp_fresh))
9887 {
9888 round = 1;
9889 varp_local = varp;
9890 varp = varp_fresh;
9891 }
9892 }
9893 }
9894 }
9895
9896 /* Round 1: fresh value for window-local options.
9897 * Round 2: other values */
9898 for ( ; round <= 2; varp = varp_local, ++round)
9899 {
9900 if (round == 1 || (opt_flags & OPT_GLOBAL))
9901 cmd = "set";
9902 else
9903 cmd = "setlocal";
9904
9905 if (p->flags & P_BOOL)
9906 {
9907 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9908 return FAIL;
9909 }
9910 else if (p->flags & P_NUM)
9911 {
9912 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9913 return FAIL;
9914 }
9915 else /* P_STRING */
9916 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009917#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9918 int do_endif = FALSE;
9919
Bram Moolenaar071d4272004-06-13 20:20:40 +00009920 /* Don't set 'syntax' and 'filetype' again if the value is
9921 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009922 if (
9923# if defined(FEAT_SYN_HL)
9924 p->indir == PV_SYN
9925# if defined(FEAT_AUTOCMD)
9926 ||
9927# endif
9928# endif
9929# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009930 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009931# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009932 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009933 {
9934 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9935 *(char_u **)(varp)) < 0
9936 || put_eol(fd) < 0)
9937 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009938 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009939 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009940#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009941 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9942 (p->flags & P_EXPAND) != 0) == FAIL)
9943 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009944#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9945 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009946 {
9947 if (put_line(fd, "endif") == FAIL)
9948 return FAIL;
9949 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009950#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009951 }
9952 }
9953 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009955 return OK;
9956}
9957
9958#if defined(FEAT_FOLDING) || defined(PROTO)
9959/*
9960 * Generate set commands for the local fold options only. Used when
9961 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9962 */
9963 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009964makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965{
9966 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9967# ifdef FEAT_EVAL
9968 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9969 == FAIL
9970# endif
9971 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9972 == FAIL
9973 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9974 == FAIL
9975 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9976 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9977 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9978 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9979 )
9980 return FAIL;
9981
9982 return OK;
9983}
9984#endif
9985
9986 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009987put_setstring(
9988 FILE *fd,
9989 char *cmd,
9990 char *name,
9991 char_u **valuep,
9992 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993{
9994 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009995 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996
9997 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9998 return FAIL;
9999 if (*valuep != NULL)
10000 {
10001 /* Output 'pastetoggle' as key names. For other
10002 * options some characters have to be escaped with
10003 * CTRL-V or backslash */
10004 if (valuep == &p_pt)
10005 {
10006 s = *valuep;
10007 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010008 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010009 return FAIL;
10010 }
10011 else if (expand)
10012 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010013 buf = alloc(MAXPATHL);
10014 if (buf == NULL)
10015 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10017 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010018 {
10019 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010020 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010021 }
10022 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010023 }
10024 else if (put_escstr(fd, *valuep, 2) == FAIL)
10025 return FAIL;
10026 }
10027 if (put_eol(fd) < 0)
10028 return FAIL;
10029 return OK;
10030}
10031
10032 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010033put_setnum(
10034 FILE *fd,
10035 char *cmd,
10036 char *name,
10037 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010038{
10039 long wc;
10040
10041 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10042 return FAIL;
10043 if (wc_use_keyname((char_u *)valuep, &wc))
10044 {
10045 /* print 'wildchar' and 'wildcharm' as a key name */
10046 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10047 return FAIL;
10048 }
10049 else if (fprintf(fd, "%ld", *valuep) < 0)
10050 return FAIL;
10051 if (put_eol(fd) < 0)
10052 return FAIL;
10053 return OK;
10054}
10055
10056 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010057put_setbool(
10058 FILE *fd,
10059 char *cmd,
10060 char *name,
10061 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062{
Bram Moolenaar893de922007-10-02 18:40:57 +000010063 if (value < 0) /* global/local option using global value */
10064 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010065 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10066 || put_eol(fd) < 0)
10067 return FAIL;
10068 return OK;
10069}
10070
10071/*
10072 * Clear all the terminal options.
10073 * If the option has been allocated, free the memory.
10074 * Terminal options are never hidden or indirect.
10075 */
10076 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010077clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010078{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010079 /*
10080 * Reset a few things before clearing the old options. This may cause
10081 * outputting a few things that the terminal doesn't understand, but the
10082 * screen will be cleared later, so this is OK.
10083 */
10084#ifdef FEAT_MOUSE_TTY
10085 mch_setmouse(FALSE); /* switch mouse off */
10086#endif
10087#ifdef FEAT_TITLE
10088 mch_restore_title(3); /* restore window titles */
10089#endif
10090#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10091 /* When starting the GUI close the display opened for the clipboard.
10092 * After restoring the title, because that will need the display. */
10093 if (gui.starting)
10094 clear_xterm_clip();
10095#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010096 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010097
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010098 free_termoptions();
10099}
10100
10101 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010102free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010103{
10104 struct vimoption *p;
10105
Bram Moolenaar071d4272004-06-13 20:20:40 +000010106 for (p = &options[0]; p->fullname != NULL; p++)
10107 if (istermoption(p))
10108 {
10109 if (p->flags & P_ALLOCED)
10110 free_string_option(*(char_u **)(p->var));
10111 if (p->flags & P_DEF_ALLOCED)
10112 free_string_option(p->def_val[VI_DEFAULT]);
10113 *(char_u **)(p->var) = empty_option;
10114 p->def_val[VI_DEFAULT] = empty_option;
10115 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10116 }
10117 clear_termcodes();
10118}
10119
10120/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010121 * Free the string for one term option, if it was allocated.
10122 * Set the string to empty_option and clear allocated flag.
10123 * "var" points to the option value.
10124 */
10125 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010126free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010127{
10128 struct vimoption *p;
10129
10130 for (p = &options[0]; p->fullname != NULL; p++)
10131 if (p->var == var)
10132 {
10133 if (p->flags & P_ALLOCED)
10134 free_string_option(*(char_u **)(p->var));
10135 *(char_u **)(p->var) = empty_option;
10136 p->flags &= ~P_ALLOCED;
10137 break;
10138 }
10139}
10140
10141/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010142 * Set the terminal option defaults to the current value.
10143 * Used after setting the terminal name.
10144 */
10145 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010146set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147{
10148 struct vimoption *p;
10149
10150 for (p = &options[0]; p->fullname != NULL; p++)
10151 {
10152 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10153 {
10154 if (p->flags & P_DEF_ALLOCED)
10155 {
10156 free_string_option(p->def_val[VI_DEFAULT]);
10157 p->flags &= ~P_DEF_ALLOCED;
10158 }
10159 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10160 if (p->flags & P_ALLOCED)
10161 {
10162 p->flags |= P_DEF_ALLOCED;
10163 p->flags &= ~P_ALLOCED; /* don't free the value now */
10164 }
10165 }
10166 }
10167}
10168
10169/*
10170 * return TRUE if 'p' starts with 't_'
10171 */
10172 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010173istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010174{
10175 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10176}
10177
10178/*
10179 * Compute columns for ruler and shown command. 'sc_col' is also used to
10180 * decide what the maximum length of a message on the status line can be.
10181 * If there is a status line for the last window, 'sc_col' is independent
10182 * of 'ru_col'.
10183 */
10184
10185#define COL_RULER 17 /* columns needed by standard ruler */
10186
10187 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010188comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189{
10190#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010191 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192
10193 sc_col = 0;
10194 ru_col = 0;
10195 if (p_ru)
10196 {
10197#ifdef FEAT_STL_OPT
10198 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10199#else
10200 ru_col = COL_RULER + 1;
10201#endif
10202 /* no last status line, adjust sc_col */
10203 if (!last_has_status)
10204 sc_col = ru_col;
10205 }
10206 if (p_sc)
10207 {
10208 sc_col += SHOWCMD_COLS;
10209 if (!p_ru || last_has_status) /* no need for separating space */
10210 ++sc_col;
10211 }
10212 sc_col = Columns - sc_col;
10213 ru_col = Columns - ru_col;
10214 if (sc_col <= 0) /* screen too narrow, will become a mess */
10215 sc_col = 1;
10216 if (ru_col <= 0)
10217 ru_col = 1;
10218#else
10219 sc_col = Columns;
10220 ru_col = Columns;
10221#endif
10222}
10223
10224/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010225 * Unset local option value, similar to ":set opt<".
10226 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010227 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010228unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010229{
10230 struct vimoption *p;
10231 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010232 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010233
10234 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010235 if (opt_idx < 0)
10236 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010237 p = &(options[opt_idx]);
10238
10239 switch ((int)p->indir)
10240 {
10241 /* global option with local value: use local value if it's been set */
10242 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010243 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010244 break;
10245 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010246 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010247 break;
10248 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010249 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010250 break;
10251 case PV_AR:
10252 buf->b_p_ar = -1;
10253 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010254 case PV_BKC:
10255 clear_string_option(&buf->b_p_bkc);
10256 buf->b_bkc_flags = 0;
10257 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010258 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010259 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010260 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010261 case PV_TC:
10262 clear_string_option(&buf->b_p_tc);
10263 buf->b_tc_flags = 0;
10264 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010265#ifdef FEAT_FIND_ID
10266 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010267 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010268 break;
10269 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010270 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010271 break;
10272#endif
10273#ifdef FEAT_INS_EXPAND
10274 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010275 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010276 break;
10277 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010278 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010279 break;
10280#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010281 case PV_FP:
10282 clear_string_option(&buf->b_p_fp);
10283 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010284#ifdef FEAT_QUICKFIX
10285 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010286 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010287 break;
10288 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010289 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010290 break;
10291 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010292 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010293 break;
10294#endif
10295#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10296 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010297 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010298 break;
10299#endif
10300#if defined(FEAT_CRYPT)
10301 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010302 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010303 break;
10304#endif
10305#ifdef FEAT_STL_OPT
10306 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010307 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010308 break;
10309#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010310 case PV_UL:
10311 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10312 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010313#ifdef FEAT_LISP
10314 case PV_LW:
10315 clear_string_option(&buf->b_p_lw);
10316 break;
10317#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010318 }
10319}
10320
10321/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010322 * Get pointer to option variable, depending on local or global scope.
10323 */
10324 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010325get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326{
10327 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10328 {
10329 if (p->var == VAR_WIN)
10330 return (char_u *)GLOBAL_WO(get_varp(p));
10331 return p->var;
10332 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010333 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334 {
10335 switch ((int)p->indir)
10336 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010337 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010338#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010339 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10340 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10341 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010343 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10344 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10345 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010346 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010347 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010348 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010349#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010350 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10351 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352#endif
10353#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010354 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10355 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010357#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10358 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10359#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010360#if defined(FEAT_CRYPT)
10361 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10362#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010363#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010364 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010365#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010366 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010367#ifdef FEAT_LISP
10368 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10369#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010370 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371 }
10372 return NULL; /* "cannot happen" */
10373 }
10374 return get_varp(p);
10375}
10376
10377/*
10378 * Get pointer to option variable.
10379 */
10380 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010381get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010382{
10383 /* hidden option, always return NULL */
10384 if (p->var == NULL)
10385 return NULL;
10386
10387 switch ((int)p->indir)
10388 {
10389 case PV_NONE: return p->var;
10390
10391 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010392 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010393 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010394 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010396 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010397 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010398 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010400 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010402 case PV_TC: return *curbuf->b_p_tc != NUL
10403 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010404 case PV_BKC: return *curbuf->b_p_bkc != NUL
10405 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010407 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010409 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010410 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10411#endif
10412#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010413 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010414 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010415 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010416 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10417#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010418 case PV_FP: return *curbuf->b_p_fp != NUL
10419 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010421 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010422 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010423 case PV_GP: return *curbuf->b_p_gp != NUL
10424 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10425 case PV_MP: return *curbuf->b_p_mp != NUL
10426 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010427#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010428#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10429 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10430 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10431#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010432#if defined(FEAT_CRYPT)
10433 case PV_CM: return *curbuf->b_p_cm != NUL
10434 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10435#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010436#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010437 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010438 ? (char_u *)&(curwin->w_p_stl) : p->var;
10439#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010440 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10441 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010442#ifdef FEAT_LISP
10443 case PV_LW: return *curbuf->b_p_lw != NUL
10444 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10445#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010446
10447#ifdef FEAT_ARABIC
10448 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10449#endif
10450 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010451#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010452 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10453#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010454#ifdef FEAT_SYN_HL
10455 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10456 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010457 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459#ifdef FEAT_DIFF
10460 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10461#endif
10462#ifdef FEAT_FOLDING
10463 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10464 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10465 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10466 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10467 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10468 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10469 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10470# ifdef FEAT_EVAL
10471 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10472 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10473# endif
10474 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10475#endif
10476 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010477 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010478#ifdef FEAT_LINEBREAK
10479 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10480#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010481#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010483 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10484#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010485#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10486 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10487#endif
10488#ifdef FEAT_RIGHTLEFT
10489 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10490 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10491#endif
10492 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10493 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10494#ifdef FEAT_LINEBREAK
10495 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010496 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10497 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010498#endif
10499#ifdef FEAT_SCROLLBIND
10500 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10501#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010502#ifdef FEAT_CURSORBIND
10503 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10504#endif
10505#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010506 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10507 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010508#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509
10510 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10511 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10512#ifdef FEAT_MBYTE
10513 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10514#endif
10515#if defined(FEAT_QUICKFIX)
10516 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10517 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10518#endif
10519 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10520 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10521#ifdef FEAT_CINDENT
10522 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10523 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10524 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10525#endif
10526#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10527 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10528#endif
10529#ifdef FEAT_COMMENTS
10530 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10531#endif
10532#ifdef FEAT_FOLDING
10533 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10534#endif
10535#ifdef FEAT_INS_EXPAND
10536 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10537#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010538#ifdef FEAT_COMPL_FUNC
10539 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010540 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010541#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010543 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010544 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10545#ifdef FEAT_MBYTE
10546 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10547#endif
10548 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10549#ifdef FEAT_AUTOCMD
10550 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10551#endif
10552 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010553 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10555 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10556 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10557 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10558#ifdef FEAT_FIND_ID
10559# ifdef FEAT_EVAL
10560 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10561# endif
10562#endif
10563#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10564 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10565 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10566#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010567#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010568 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10569#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010570#ifdef FEAT_CRYPT
10571 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10572#endif
10573#ifdef FEAT_LISP
10574 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10575#endif
10576 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10577 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10578 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10579 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10580 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010582#ifdef FEAT_TEXTOBJ
10583 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10584#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10586#ifdef FEAT_SMARTINDENT
10587 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10591#ifdef FEAT_SEARCHPATH
10592 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10593#endif
10594 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10595#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010596 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010597 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10598#endif
10599#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010600 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10601 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10602 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603#endif
10604 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10605 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10606 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10607 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010608#ifdef FEAT_PERSISTENT_UNDO
10609 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10610#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10612#ifdef FEAT_KEYMAP
10613 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10614#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010615#ifdef FEAT_SIGNS
10616 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10617#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010618 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619 }
10620 /* always return a valid pointer to avoid a crash! */
10621 return (char_u *)&(curbuf->b_p_wm);
10622}
10623
10624/*
10625 * Get the value of 'equalprg', either the buffer-local one or the global one.
10626 */
10627 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010628get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629{
10630 if (*curbuf->b_p_ep == NUL)
10631 return p_ep;
10632 return curbuf->b_p_ep;
10633}
10634
10635#if defined(FEAT_WINDOWS) || defined(PROTO)
10636/*
10637 * Copy options from one window to another.
10638 * Used when splitting a window.
10639 */
10640 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010641win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642{
10643 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10644 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10645# ifdef FEAT_RIGHTLEFT
10646# ifdef FEAT_FKMAP
10647 /* Is this right? */
10648 wp_to->w_farsi = wp_from->w_farsi;
10649# endif
10650# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010651#if defined(FEAT_LINEBREAK)
10652 briopt_check(wp_to);
10653#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010654}
10655#endif
10656
10657/*
10658 * Copy the options from one winopt_T to another.
10659 * Doesn't free the old option values in "to", use clear_winopt() for that.
10660 * The 'scroll' option is not copied, because it depends on the window height.
10661 * The 'previewwindow' option is reset, there can be only one preview window.
10662 */
10663 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010664copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010665{
10666#ifdef FEAT_ARABIC
10667 to->wo_arab = from->wo_arab;
10668#endif
10669 to->wo_list = from->wo_list;
10670 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010671 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010672#ifdef FEAT_LINEBREAK
10673 to->wo_nuw = from->wo_nuw;
10674#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010675#ifdef FEAT_RIGHTLEFT
10676 to->wo_rl = from->wo_rl;
10677 to->wo_rlc = vim_strsave(from->wo_rlc);
10678#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010679#ifdef FEAT_STL_OPT
10680 to->wo_stl = vim_strsave(from->wo_stl);
10681#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010682 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010683#ifdef FEAT_DIFF
10684 to->wo_wrap_save = from->wo_wrap_save;
10685#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686#ifdef FEAT_LINEBREAK
10687 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010688 to->wo_bri = from->wo_bri;
10689 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010690#endif
10691#ifdef FEAT_SCROLLBIND
10692 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010693 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010694#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010695#ifdef FEAT_CURSORBIND
10696 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010697 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010698#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010699#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010700 to->wo_spell = from->wo_spell;
10701#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010702#ifdef FEAT_SYN_HL
10703 to->wo_cuc = from->wo_cuc;
10704 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010705 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707#ifdef FEAT_DIFF
10708 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010709 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010710#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010711#ifdef FEAT_CONCEAL
10712 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010713 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010715#ifdef FEAT_FOLDING
10716 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010717 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010719 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720 to->wo_fdi = vim_strsave(from->wo_fdi);
10721 to->wo_fml = from->wo_fml;
10722 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010723 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010724 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010725 to->wo_fdm_save = from->wo_diff_saved
10726 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010727 to->wo_fdn = from->wo_fdn;
10728# ifdef FEAT_EVAL
10729 to->wo_fde = vim_strsave(from->wo_fde);
10730 to->wo_fdt = vim_strsave(from->wo_fdt);
10731# endif
10732 to->wo_fmr = vim_strsave(from->wo_fmr);
10733#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010734#ifdef FEAT_SIGNS
10735 to->wo_scl = vim_strsave(from->wo_scl);
10736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 check_winopt(to); /* don't want NULL pointers */
10738}
10739
10740/*
10741 * Check string options in a window for a NULL value.
10742 */
10743 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010744check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010745{
10746 check_winopt(&win->w_onebuf_opt);
10747 check_winopt(&win->w_allbuf_opt);
10748}
10749
10750/*
10751 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10752 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010753 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010754check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755{
10756#ifdef FEAT_FOLDING
10757 check_string_option(&wop->wo_fdi);
10758 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010759 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010760# ifdef FEAT_EVAL
10761 check_string_option(&wop->wo_fde);
10762 check_string_option(&wop->wo_fdt);
10763# endif
10764 check_string_option(&wop->wo_fmr);
10765#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010766#ifdef FEAT_SIGNS
10767 check_string_option(&wop->wo_scl);
10768#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010769#ifdef FEAT_RIGHTLEFT
10770 check_string_option(&wop->wo_rlc);
10771#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010772#ifdef FEAT_STL_OPT
10773 check_string_option(&wop->wo_stl);
10774#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010775#ifdef FEAT_SYN_HL
10776 check_string_option(&wop->wo_cc);
10777#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010778#ifdef FEAT_CONCEAL
10779 check_string_option(&wop->wo_cocu);
10780#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010781#ifdef FEAT_LINEBREAK
10782 check_string_option(&wop->wo_briopt);
10783#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010784}
10785
10786/*
10787 * Free the allocated memory inside a winopt_T.
10788 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010790clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010791{
10792#ifdef FEAT_FOLDING
10793 clear_string_option(&wop->wo_fdi);
10794 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010795 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796# ifdef FEAT_EVAL
10797 clear_string_option(&wop->wo_fde);
10798 clear_string_option(&wop->wo_fdt);
10799# endif
10800 clear_string_option(&wop->wo_fmr);
10801#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010802#ifdef FEAT_SIGNS
10803 clear_string_option(&wop->wo_scl);
10804#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010805#ifdef FEAT_LINEBREAK
10806 clear_string_option(&wop->wo_briopt);
10807#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010808#ifdef FEAT_RIGHTLEFT
10809 clear_string_option(&wop->wo_rlc);
10810#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010811#ifdef FEAT_STL_OPT
10812 clear_string_option(&wop->wo_stl);
10813#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010814#ifdef FEAT_SYN_HL
10815 clear_string_option(&wop->wo_cc);
10816#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010817#ifdef FEAT_CONCEAL
10818 clear_string_option(&wop->wo_cocu);
10819#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820}
10821
10822/*
10823 * Copy global option values to local options for one buffer.
10824 * Used when creating a new buffer and sometimes when entering a buffer.
10825 * flags:
10826 * BCO_ENTER We will enter the buf buffer.
10827 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10828 * appropriate.
10829 * BCO_NOHELP Don't copy the values to a help buffer.
10830 */
10831 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010832buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833{
10834 int should_copy = TRUE;
10835 char_u *save_p_isk = NULL; /* init for GCC */
10836 int dont_do_help;
10837 int did_isk = FALSE;
10838
10839 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840 * Skip this when the option defaults have not been set yet. Happens when
10841 * main() allocates the first buffer.
10842 */
10843 if (p_cpo != NULL)
10844 {
10845 /*
10846 * Always copy when entering and 'cpo' contains 'S'.
10847 * Don't copy when already initialized.
10848 * Don't copy when 'cpo' contains 's' and not entering.
10849 * 'S' BCO_ENTER initialized 's' should_copy
10850 * yes yes X X TRUE
10851 * yes no yes X FALSE
10852 * no X yes X FALSE
10853 * X no no yes FALSE
10854 * X no no no TRUE
10855 * no yes no X TRUE
10856 */
10857 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10858 && (buf->b_p_initialized
10859 || (!(flags & BCO_ENTER)
10860 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10861 should_copy = FALSE;
10862
10863 if (should_copy || (flags & BCO_ALWAYS))
10864 {
10865 /* Don't copy the options specific to a help buffer when
10866 * BCO_NOHELP is given or the options were initialized already
10867 * (jumping back to a help file with CTRL-T or CTRL-O) */
10868 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10869 || buf->b_p_initialized;
10870 if (dont_do_help) /* don't free b_p_isk */
10871 {
10872 save_p_isk = buf->b_p_isk;
10873 buf->b_p_isk = NULL;
10874 }
10875 /*
10876 * Always free the allocated strings.
10877 * If not already initialized, set 'readonly' and copy 'fileformat'.
10878 */
10879 if (!buf->b_p_initialized)
10880 {
10881 free_buf_options(buf, TRUE);
10882 buf->b_p_ro = FALSE; /* don't copy readonly */
10883 buf->b_p_tx = p_tx;
10884#ifdef FEAT_MBYTE
10885 buf->b_p_fenc = vim_strsave(p_fenc);
10886#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020010887 switch (*p_ffs)
10888 {
10889 case 'm':
10890 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
10891 case 'd':
10892 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
10893 case 'u':
10894 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
10895 default:
10896 buf->b_p_ff = vim_strsave(p_ff);
10897 }
10898 if (buf->b_p_ff != NULL)
10899 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010900#if defined(FEAT_QUICKFIX)
10901 buf->b_p_bh = empty_option;
10902 buf->b_p_bt = empty_option;
10903#endif
10904 }
10905 else
10906 free_buf_options(buf, FALSE);
10907
10908 buf->b_p_ai = p_ai;
10909 buf->b_p_ai_nopaste = p_ai_nopaste;
10910 buf->b_p_sw = p_sw;
10911 buf->b_p_tw = p_tw;
10912 buf->b_p_tw_nopaste = p_tw_nopaste;
10913 buf->b_p_tw_nobin = p_tw_nobin;
10914 buf->b_p_wm = p_wm;
10915 buf->b_p_wm_nopaste = p_wm_nopaste;
10916 buf->b_p_wm_nobin = p_wm_nobin;
10917 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010918#ifdef FEAT_MBYTE
10919 buf->b_p_bomb = p_bomb;
10920#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010921 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010922 buf->b_p_et = p_et;
10923 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010924 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010925 buf->b_p_ml = p_ml;
10926 buf->b_p_ml_nobin = p_ml_nobin;
10927 buf->b_p_inf = p_inf;
10928 buf->b_p_swf = p_swf;
10929#ifdef FEAT_INS_EXPAND
10930 buf->b_p_cpt = vim_strsave(p_cpt);
10931#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010932#ifdef FEAT_COMPL_FUNC
10933 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010934 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010935#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936 buf->b_p_sts = p_sts;
10937 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939#ifdef FEAT_COMMENTS
10940 buf->b_p_com = vim_strsave(p_com);
10941#endif
10942#ifdef FEAT_FOLDING
10943 buf->b_p_cms = vim_strsave(p_cms);
10944#endif
10945 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010946 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010947 buf->b_p_nf = vim_strsave(p_nf);
10948 buf->b_p_mps = vim_strsave(p_mps);
10949#ifdef FEAT_SMARTINDENT
10950 buf->b_p_si = p_si;
10951#endif
10952 buf->b_p_ci = p_ci;
10953#ifdef FEAT_CINDENT
10954 buf->b_p_cin = p_cin;
10955 buf->b_p_cink = vim_strsave(p_cink);
10956 buf->b_p_cino = vim_strsave(p_cino);
10957#endif
10958#ifdef FEAT_AUTOCMD
10959 /* Don't copy 'filetype', it must be detected */
10960 buf->b_p_ft = empty_option;
10961#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010962 buf->b_p_pi = p_pi;
10963#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10964 buf->b_p_cinw = vim_strsave(p_cinw);
10965#endif
10966#ifdef FEAT_LISP
10967 buf->b_p_lisp = p_lisp;
10968#endif
10969#ifdef FEAT_SYN_HL
10970 /* Don't copy 'syntax', it must be set */
10971 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010972 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010973 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010974#endif
10975#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010976 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010977 (void)compile_cap_prog(&buf->b_s);
10978 buf->b_s.b_p_spf = vim_strsave(p_spf);
10979 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010980#endif
10981#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10982 buf->b_p_inde = vim_strsave(p_inde);
10983 buf->b_p_indk = vim_strsave(p_indk);
10984#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010985 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010986#if defined(FEAT_EVAL)
10987 buf->b_p_fex = vim_strsave(p_fex);
10988#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989#ifdef FEAT_CRYPT
10990 buf->b_p_key = vim_strsave(p_key);
10991#endif
10992#ifdef FEAT_SEARCHPATH
10993 buf->b_p_sua = vim_strsave(p_sua);
10994#endif
10995#ifdef FEAT_KEYMAP
10996 buf->b_p_keymap = vim_strsave(p_keymap);
10997 buf->b_kmap_state |= KEYMAP_INIT;
10998#endif
10999 /* This isn't really an option, but copying the langmap and IME
11000 * state from the current buffer is better than resetting it. */
11001 buf->b_p_iminsert = p_iminsert;
11002 buf->b_p_imsearch = p_imsearch;
11003
11004 /* options that are normally global but also have a local value
11005 * are not copied, start using the global value */
11006 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011007 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011008 buf->b_p_bkc = empty_option;
11009 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010#ifdef FEAT_QUICKFIX
11011 buf->b_p_gp = empty_option;
11012 buf->b_p_mp = empty_option;
11013 buf->b_p_efm = empty_option;
11014#endif
11015 buf->b_p_ep = empty_option;
11016 buf->b_p_kp = empty_option;
11017 buf->b_p_path = empty_option;
11018 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011019 buf->b_p_tc = empty_option;
11020 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011021#ifdef FEAT_FIND_ID
11022 buf->b_p_def = empty_option;
11023 buf->b_p_inc = empty_option;
11024# ifdef FEAT_EVAL
11025 buf->b_p_inex = vim_strsave(p_inex);
11026# endif
11027#endif
11028#ifdef FEAT_INS_EXPAND
11029 buf->b_p_dict = empty_option;
11030 buf->b_p_tsr = empty_option;
11031#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011032#ifdef FEAT_TEXTOBJ
11033 buf->b_p_qe = vim_strsave(p_qe);
11034#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011035#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11036 buf->b_p_bexpr = empty_option;
11037#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011038#if defined(FEAT_CRYPT)
11039 buf->b_p_cm = empty_option;
11040#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011041#ifdef FEAT_PERSISTENT_UNDO
11042 buf->b_p_udf = p_udf;
11043#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011044#ifdef FEAT_LISP
11045 buf->b_p_lw = empty_option;
11046#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011047
11048 /*
11049 * Don't copy the options set by ex_help(), use the saved values,
11050 * when going from a help buffer to a non-help buffer.
11051 * Don't touch these at all when BCO_NOHELP is used and going from
11052 * or to a help buffer.
11053 */
11054 if (dont_do_help)
11055 buf->b_p_isk = save_p_isk;
11056 else
11057 {
11058 buf->b_p_isk = vim_strsave(p_isk);
11059 did_isk = TRUE;
11060 buf->b_p_ts = p_ts;
11061 buf->b_help = FALSE;
11062#ifdef FEAT_QUICKFIX
11063 if (buf->b_p_bt[0] == 'h')
11064 clear_string_option(&buf->b_p_bt);
11065#endif
11066 buf->b_p_ma = p_ma;
11067 }
11068 }
11069
11070 /*
11071 * When the options should be copied (ignoring BCO_ALWAYS), set the
11072 * flag that indicates that the options have been initialized.
11073 */
11074 if (should_copy)
11075 buf->b_p_initialized = TRUE;
11076 }
11077
11078 check_buf_options(buf); /* make sure we don't have NULLs */
11079 if (did_isk)
11080 (void)buf_init_chartab(buf, FALSE);
11081}
11082
11083/*
11084 * Reset the 'modifiable' option and its default value.
11085 */
11086 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011087reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011088{
11089 int opt_idx;
11090
11091 curbuf->b_p_ma = FALSE;
11092 p_ma = FALSE;
11093 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011094 if (opt_idx >= 0)
11095 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096}
11097
11098/*
11099 * Set the global value for 'iminsert' to the local value.
11100 */
11101 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011102set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103{
11104 p_iminsert = curbuf->b_p_iminsert;
11105}
11106
11107/*
11108 * Set the global value for 'imsearch' to the local value.
11109 */
11110 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011111set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011112{
11113 p_imsearch = curbuf->b_p_imsearch;
11114}
11115
11116#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11117static int expand_option_idx = -1;
11118static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11119static int expand_option_flags = 0;
11120
11121 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011122set_context_in_set_cmd(
11123 expand_T *xp,
11124 char_u *arg,
11125 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011126{
11127 int nextchar;
11128 long_u flags = 0; /* init for GCC */
11129 int opt_idx = 0; /* init for GCC */
11130 char_u *p;
11131 char_u *s;
11132 int is_term_option = FALSE;
11133 int key;
11134
11135 expand_option_flags = opt_flags;
11136
11137 xp->xp_context = EXPAND_SETTINGS;
11138 if (*arg == NUL)
11139 {
11140 xp->xp_pattern = arg;
11141 return;
11142 }
11143 p = arg + STRLEN(arg) - 1;
11144 if (*p == ' ' && *(p - 1) != '\\')
11145 {
11146 xp->xp_pattern = p + 1;
11147 return;
11148 }
11149 while (p > arg)
11150 {
11151 s = p;
11152 /* count number of backslashes before ' ' or ',' */
11153 if (*p == ' ' || *p == ',')
11154 {
11155 while (s > arg && *(s - 1) == '\\')
11156 --s;
11157 }
11158 /* break at a space with an even number of backslashes */
11159 if (*p == ' ' && ((p - s) & 1) == 0)
11160 {
11161 ++p;
11162 break;
11163 }
11164 --p;
11165 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011166 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011167 {
11168 xp->xp_context = EXPAND_BOOL_SETTINGS;
11169 p += 2;
11170 }
11171 if (STRNCMP(p, "inv", 3) == 0)
11172 {
11173 xp->xp_context = EXPAND_BOOL_SETTINGS;
11174 p += 3;
11175 }
11176 xp->xp_pattern = arg = p;
11177 if (*arg == '<')
11178 {
11179 while (*p != '>')
11180 if (*p++ == NUL) /* expand terminal option name */
11181 return;
11182 key = get_special_key_code(arg + 1);
11183 if (key == 0) /* unknown name */
11184 {
11185 xp->xp_context = EXPAND_NOTHING;
11186 return;
11187 }
11188 nextchar = *++p;
11189 is_term_option = TRUE;
11190 expand_option_name[2] = KEY2TERMCAP0(key);
11191 expand_option_name[3] = KEY2TERMCAP1(key);
11192 }
11193 else
11194 {
11195 if (p[0] == 't' && p[1] == '_')
11196 {
11197 p += 2;
11198 if (*p != NUL)
11199 ++p;
11200 if (*p == NUL)
11201 return; /* expand option name */
11202 nextchar = *++p;
11203 is_term_option = TRUE;
11204 expand_option_name[2] = p[-2];
11205 expand_option_name[3] = p[-1];
11206 }
11207 else
11208 {
11209 /* Allow * wildcard */
11210 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11211 p++;
11212 if (*p == NUL)
11213 return;
11214 nextchar = *p;
11215 *p = NUL;
11216 opt_idx = findoption(arg);
11217 *p = nextchar;
11218 if (opt_idx == -1 || options[opt_idx].var == NULL)
11219 {
11220 xp->xp_context = EXPAND_NOTHING;
11221 return;
11222 }
11223 flags = options[opt_idx].flags;
11224 if (flags & P_BOOL)
11225 {
11226 xp->xp_context = EXPAND_NOTHING;
11227 return;
11228 }
11229 }
11230 }
11231 /* handle "-=" and "+=" */
11232 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11233 {
11234 ++p;
11235 nextchar = '=';
11236 }
11237 if ((nextchar != '=' && nextchar != ':')
11238 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11239 {
11240 xp->xp_context = EXPAND_UNSUCCESSFUL;
11241 return;
11242 }
11243 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11244 {
11245 xp->xp_context = EXPAND_OLD_SETTING;
11246 if (is_term_option)
11247 expand_option_idx = -1;
11248 else
11249 expand_option_idx = opt_idx;
11250 xp->xp_pattern = p + 1;
11251 return;
11252 }
11253 xp->xp_context = EXPAND_NOTHING;
11254 if (is_term_option || (flags & P_NUM))
11255 return;
11256
11257 xp->xp_pattern = p + 1;
11258
11259 if (flags & P_EXPAND)
11260 {
11261 p = options[opt_idx].var;
11262 if (p == (char_u *)&p_bdir
11263 || p == (char_u *)&p_dir
11264 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011265 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266 || p == (char_u *)&p_rtp
11267#ifdef FEAT_SEARCHPATH
11268 || p == (char_u *)&p_cdpath
11269#endif
11270#ifdef FEAT_SESSION
11271 || p == (char_u *)&p_vdir
11272#endif
11273 )
11274 {
11275 xp->xp_context = EXPAND_DIRECTORIES;
11276 if (p == (char_u *)&p_path
11277#ifdef FEAT_SEARCHPATH
11278 || p == (char_u *)&p_cdpath
11279#endif
11280 )
11281 xp->xp_backslash = XP_BS_THREE;
11282 else
11283 xp->xp_backslash = XP_BS_ONE;
11284 }
11285 else
11286 {
11287 xp->xp_context = EXPAND_FILES;
11288 /* for 'tags' need three backslashes for a space */
11289 if (p == (char_u *)&p_tags)
11290 xp->xp_backslash = XP_BS_THREE;
11291 else
11292 xp->xp_backslash = XP_BS_ONE;
11293 }
11294 }
11295
11296 /* For an option that is a list of file names, find the start of the
11297 * last file name. */
11298 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11299 {
11300 /* count number of backslashes before ' ' or ',' */
11301 if (*p == ' ' || *p == ',')
11302 {
11303 s = p;
11304 while (s > xp->xp_pattern && *(s - 1) == '\\')
11305 --s;
11306 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11307 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11308 {
11309 xp->xp_pattern = p + 1;
11310 break;
11311 }
11312 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011313
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011314#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011315 /* for 'spellsuggest' start at "file:" */
11316 if (options[opt_idx].var == (char_u *)&p_sps
11317 && STRNCMP(p, "file:", 5) == 0)
11318 {
11319 xp->xp_pattern = p + 5;
11320 break;
11321 }
11322#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323 }
11324
11325 return;
11326}
11327
11328 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011329ExpandSettings(
11330 expand_T *xp,
11331 regmatch_T *regmatch,
11332 int *num_file,
11333 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011334{
11335 int num_normal = 0; /* Nr of matching non-term-code settings */
11336 int num_term = 0; /* Nr of matching terminal code settings */
11337 int opt_idx;
11338 int match;
11339 int count = 0;
11340 char_u *str;
11341 int loop;
11342 int is_term_opt;
11343 char_u name_buf[MAX_KEY_NAME_LEN];
11344 static char *(names[]) = {"all", "termcap"};
11345 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11346
11347 /* do this loop twice:
11348 * loop == 0: count the number of matching options
11349 * loop == 1: copy the matching options into allocated memory
11350 */
11351 for (loop = 0; loop <= 1; ++loop)
11352 {
11353 regmatch->rm_ic = ic;
11354 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11355 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011356 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11357 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011358 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11359 {
11360 if (loop == 0)
11361 num_normal++;
11362 else
11363 (*file)[count++] = vim_strsave((char_u *)names[match]);
11364 }
11365 }
11366 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11367 opt_idx++)
11368 {
11369 if (options[opt_idx].var == NULL)
11370 continue;
11371 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11372 && !(options[opt_idx].flags & P_BOOL))
11373 continue;
11374 is_term_opt = istermoption(&options[opt_idx]);
11375 if (is_term_opt && num_normal > 0)
11376 continue;
11377 match = FALSE;
11378 if (vim_regexec(regmatch, str, (colnr_T)0)
11379 || (options[opt_idx].shortname != NULL
11380 && vim_regexec(regmatch,
11381 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11382 match = TRUE;
11383 else if (is_term_opt)
11384 {
11385 name_buf[0] = '<';
11386 name_buf[1] = 't';
11387 name_buf[2] = '_';
11388 name_buf[3] = str[2];
11389 name_buf[4] = str[3];
11390 name_buf[5] = '>';
11391 name_buf[6] = NUL;
11392 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11393 {
11394 match = TRUE;
11395 str = name_buf;
11396 }
11397 }
11398 if (match)
11399 {
11400 if (loop == 0)
11401 {
11402 if (is_term_opt)
11403 num_term++;
11404 else
11405 num_normal++;
11406 }
11407 else
11408 (*file)[count++] = vim_strsave(str);
11409 }
11410 }
11411 /*
11412 * Check terminal key codes, these are not in the option table
11413 */
11414 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11415 {
11416 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11417 {
11418 if (!isprint(str[0]) || !isprint(str[1]))
11419 continue;
11420
11421 name_buf[0] = 't';
11422 name_buf[1] = '_';
11423 name_buf[2] = str[0];
11424 name_buf[3] = str[1];
11425 name_buf[4] = NUL;
11426
11427 match = FALSE;
11428 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11429 match = TRUE;
11430 else
11431 {
11432 name_buf[0] = '<';
11433 name_buf[1] = 't';
11434 name_buf[2] = '_';
11435 name_buf[3] = str[0];
11436 name_buf[4] = str[1];
11437 name_buf[5] = '>';
11438 name_buf[6] = NUL;
11439
11440 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11441 match = TRUE;
11442 }
11443 if (match)
11444 {
11445 if (loop == 0)
11446 num_term++;
11447 else
11448 (*file)[count++] = vim_strsave(name_buf);
11449 }
11450 }
11451
11452 /*
11453 * Check special key names.
11454 */
11455 regmatch->rm_ic = TRUE; /* ignore case here */
11456 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11457 {
11458 name_buf[0] = '<';
11459 STRCPY(name_buf + 1, str);
11460 STRCAT(name_buf, ">");
11461
11462 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11463 {
11464 if (loop == 0)
11465 num_term++;
11466 else
11467 (*file)[count++] = vim_strsave(name_buf);
11468 }
11469 }
11470 }
11471 if (loop == 0)
11472 {
11473 if (num_normal > 0)
11474 *num_file = num_normal;
11475 else if (num_term > 0)
11476 *num_file = num_term;
11477 else
11478 return OK;
11479 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11480 if (*file == NULL)
11481 {
11482 *file = (char_u **)"";
11483 return FAIL;
11484 }
11485 }
11486 }
11487 return OK;
11488}
11489
11490 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011491ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011492{
11493 char_u *var = NULL; /* init for GCC */
11494 char_u *buf;
11495
11496 *num_file = 0;
11497 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11498 if (*file == NULL)
11499 return FAIL;
11500
11501 /*
11502 * For a terminal key code expand_option_idx is < 0.
11503 */
11504 if (expand_option_idx < 0)
11505 {
11506 var = find_termcode(expand_option_name + 2);
11507 if (var == NULL)
11508 expand_option_idx = findoption(expand_option_name);
11509 }
11510
11511 if (expand_option_idx >= 0)
11512 {
11513 /* put string of option value in NameBuff */
11514 option_value2string(&options[expand_option_idx], expand_option_flags);
11515 var = NameBuff;
11516 }
11517 else if (var == NULL)
11518 var = (char_u *)"";
11519
11520 /* A backslash is required before some characters. This is the reverse of
11521 * what happens in do_set(). */
11522 buf = vim_strsave_escaped(var, escape_chars);
11523
11524 if (buf == NULL)
11525 {
11526 vim_free(*file);
11527 *file = NULL;
11528 return FAIL;
11529 }
11530
11531#ifdef BACKSLASH_IN_FILENAME
11532 /* For MS-Windows et al. we don't double backslashes at the start and
11533 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011534 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535 if (var[0] == '\\' && var[1] == '\\'
11536 && expand_option_idx >= 0
11537 && (options[expand_option_idx].flags & P_EXPAND)
11538 && vim_isfilec(var[2])
11539 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011540 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011541#endif
11542
11543 *file[0] = buf;
11544 *num_file = 1;
11545 return OK;
11546}
11547#endif
11548
11549/*
11550 * Get the value for the numeric or string option *opp in a nice format into
11551 * NameBuff[]. Must not be called with a hidden option!
11552 */
11553 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011554option_value2string(
11555 struct vimoption *opp,
11556 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011557{
11558 char_u *varp;
11559
11560 varp = get_varp_scope(opp, opt_flags);
11561
11562 if (opp->flags & P_NUM)
11563 {
11564 long wc = 0;
11565
11566 if (wc_use_keyname(varp, &wc))
11567 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11568 else if (wc != 0)
11569 STRCPY(NameBuff, transchar((int)wc));
11570 else
11571 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11572 }
11573 else /* P_STRING */
11574 {
11575 varp = *(char_u **)(varp);
11576 if (varp == NULL) /* just in case */
11577 NameBuff[0] = NUL;
11578#ifdef FEAT_CRYPT
11579 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011580 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011581 STRCPY(NameBuff, "*****");
11582#endif
11583 else if (opp->flags & P_EXPAND)
11584 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11585 /* Translate 'pastetoggle' into special key names */
11586 else if ((char_u **)opp->var == &p_pt)
11587 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11588 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011589 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590 }
11591}
11592
11593/*
11594 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11595 * printed as a keyname.
11596 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11597 */
11598 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011599wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011600{
11601 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11602 {
11603 *wcp = *(long *)varp;
11604 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11605 return TRUE;
11606 }
11607 return FALSE;
11608}
11609
Bram Moolenaar01615492015-02-03 13:00:38 +010011610#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011611/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011612 * Any character has an equivalent 'langmap' character. This is used for
11613 * keyboards that have a special language mode that sends characters above
11614 * 128 (although other characters can be translated too). The "to" field is a
11615 * Vim command character. This avoids having to switch the keyboard back to
11616 * ASCII mode when leaving Insert mode.
11617 *
11618 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11619 * commands.
11620 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11621 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11622 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011624# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011625/*
11626 * With multi-byte support use growarray for 'langmap' chars >= 256
11627 */
11628typedef struct
11629{
11630 int from;
11631 int to;
11632} langmap_entry_T;
11633
11634static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011635static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011636
11637/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011638 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11639 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011640 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011641 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011642langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011643{
11644 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011645 int a = 0;
11646 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011647
11648 /* Do a binary search for an existing entry. */
11649 while (a != b)
11650 {
11651 int i = (a + b) / 2;
11652 int d = entries[i].from - from;
11653
11654 if (d == 0)
11655 {
11656 entries[i].to = to;
11657 return;
11658 }
11659 if (d < 0)
11660 a = i + 1;
11661 else
11662 b = i;
11663 }
11664
11665 if (ga_grow(&langmap_mapga, 1) != OK)
11666 return; /* out of memory */
11667
11668 /* insert new entry at position "a" */
11669 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11670 mch_memmove(entries + 1, entries,
11671 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11672 ++langmap_mapga.ga_len;
11673 entries[0].from = from;
11674 entries[0].to = to;
11675}
11676
11677/*
11678 * Apply 'langmap' to multi-byte character "c" and return the result.
11679 */
11680 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011681langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011682{
11683 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11684 int a = 0;
11685 int b = langmap_mapga.ga_len;
11686
11687 while (a != b)
11688 {
11689 int i = (a + b) / 2;
11690 int d = entries[i].from - c;
11691
11692 if (d == 0)
11693 return entries[i].to; /* found matching entry */
11694 if (d < 0)
11695 a = i + 1;
11696 else
11697 b = i;
11698 }
11699 return c; /* no entry found, return "c" unmodified */
11700}
11701# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011702
11703 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011704langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011705{
11706 int i;
11707
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011708 for (i = 0; i < 256; i++)
11709 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11710# ifdef FEAT_MBYTE
11711 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11712# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011713}
11714
11715/*
11716 * Called when langmap option is set; the language map can be
11717 * changed at any time!
11718 */
11719 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011720langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011721{
11722 char_u *p;
11723 char_u *p2;
11724 int from, to;
11725
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011726#ifdef FEAT_MBYTE
11727 ga_clear(&langmap_mapga); /* clear the previous map first */
11728#endif
11729 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011730
11731 for (p = p_langmap; p[0] != NUL; )
11732 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011733 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11734 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735 {
11736 if (p2[0] == '\\' && p2[1] != NUL)
11737 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011738 }
11739 if (p2[0] == ';')
11740 ++p2; /* abcd;ABCD form, p2 points to A */
11741 else
11742 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11743 while (p[0])
11744 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011745 if (p[0] == ',')
11746 {
11747 ++p;
11748 break;
11749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011750 if (p[0] == '\\' && p[1] != NUL)
11751 ++p;
11752#ifdef FEAT_MBYTE
11753 from = (*mb_ptr2char)(p);
11754#else
11755 from = p[0];
11756#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011757 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011758 if (p2 == NULL)
11759 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011760 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011761 if (p[0] != ',')
11762 {
11763 if (p[0] == '\\')
11764 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011765#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011766 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011768 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011769#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011770 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771 }
11772 else
11773 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011774 if (p2[0] != ',')
11775 {
11776 if (p2[0] == '\\')
11777 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011778#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011779 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011780#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011781 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011782#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011783 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784 }
11785 if (to == NUL)
11786 {
11787 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11788 transchar(from));
11789 return;
11790 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011791
11792#ifdef FEAT_MBYTE
11793 if (from >= 256)
11794 langmap_set_entry(from, to);
11795 else
11796#endif
11797 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011798
11799 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011800 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011801 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011802 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011803 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011804 if (*p == ';')
11805 {
11806 p = p2;
11807 if (p[0] != NUL)
11808 {
11809 if (p[0] != ',')
11810 {
11811 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11812 return;
11813 }
11814 ++p;
11815 }
11816 break;
11817 }
11818 }
11819 }
11820 }
11821}
11822#endif
11823
11824/*
11825 * Return TRUE if format option 'x' is in effect.
11826 * Take care of no formatting when 'paste' is set.
11827 */
11828 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011829has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011830{
11831 if (p_paste)
11832 return FALSE;
11833 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11834}
11835
11836/*
11837 * Return TRUE if "x" is present in 'shortmess' option, or
11838 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11839 */
11840 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011841shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011842{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011843 return p_shm != NULL &&
11844 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845 || (vim_strchr(p_shm, 'a') != NULL
11846 && vim_strchr((char_u *)SHM_A, x) != NULL));
11847}
11848
11849/*
11850 * paste_option_changed() - Called after p_paste was set or reset.
11851 */
11852 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011853paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011854{
11855 static int old_p_paste = FALSE;
11856 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011857 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011858#ifdef FEAT_CMDL_INFO
11859 static int save_ru = 0;
11860#endif
11861#ifdef FEAT_RIGHTLEFT
11862 static int save_ri = 0;
11863 static int save_hkmap = 0;
11864#endif
11865 buf_T *buf;
11866
11867 if (p_paste)
11868 {
11869 /*
11870 * Paste switched from off to on.
11871 * Save the current values, so they can be restored later.
11872 */
11873 if (!old_p_paste)
11874 {
11875 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011876 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877 {
11878 buf->b_p_tw_nopaste = buf->b_p_tw;
11879 buf->b_p_wm_nopaste = buf->b_p_wm;
11880 buf->b_p_sts_nopaste = buf->b_p_sts;
11881 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011882 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883 }
11884
11885 /* save global options */
11886 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011887 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011888#ifdef FEAT_CMDL_INFO
11889 save_ru = p_ru;
11890#endif
11891#ifdef FEAT_RIGHTLEFT
11892 save_ri = p_ri;
11893 save_hkmap = p_hkmap;
11894#endif
11895 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011896 p_ai_nopaste = p_ai;
11897 p_et_nopaste = p_et;
11898 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011899 p_tw_nopaste = p_tw;
11900 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901 }
11902
11903 /*
11904 * Always set the option values, also when 'paste' is set when it is
11905 * already on.
11906 */
11907 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011908 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011909 {
11910 buf->b_p_tw = 0; /* textwidth is 0 */
11911 buf->b_p_wm = 0; /* wrapmargin is 0 */
11912 buf->b_p_sts = 0; /* softtabstop is 0 */
11913 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011914 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915 }
11916
11917 /* set global options */
11918 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011919 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011920#ifdef FEAT_CMDL_INFO
11921# ifdef FEAT_WINDOWS
11922 if (p_ru)
11923 status_redraw_all(); /* redraw to remove the ruler */
11924# endif
11925 p_ru = 0; /* no ruler */
11926#endif
11927#ifdef FEAT_RIGHTLEFT
11928 p_ri = 0; /* no reverse insert */
11929 p_hkmap = 0; /* no Hebrew keyboard */
11930#endif
11931 /* set global values for local buffer options */
11932 p_tw = 0;
11933 p_wm = 0;
11934 p_sts = 0;
11935 p_ai = 0;
11936 }
11937
11938 /*
11939 * Paste switched from on to off: Restore saved values.
11940 */
11941 else if (old_p_paste)
11942 {
11943 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011944 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011945 {
11946 buf->b_p_tw = buf->b_p_tw_nopaste;
11947 buf->b_p_wm = buf->b_p_wm_nopaste;
11948 buf->b_p_sts = buf->b_p_sts_nopaste;
11949 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011950 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951 }
11952
11953 /* restore global options */
11954 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011955 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011956#ifdef FEAT_CMDL_INFO
11957# ifdef FEAT_WINDOWS
11958 if (p_ru != save_ru)
11959 status_redraw_all(); /* redraw to draw the ruler */
11960# endif
11961 p_ru = save_ru;
11962#endif
11963#ifdef FEAT_RIGHTLEFT
11964 p_ri = save_ri;
11965 p_hkmap = save_hkmap;
11966#endif
11967 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011968 p_ai = p_ai_nopaste;
11969 p_et = p_et_nopaste;
11970 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011971 p_tw = p_tw_nopaste;
11972 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011973 }
11974
11975 old_p_paste = p_paste;
11976}
11977
11978/*
11979 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11980 *
11981 * Reset 'compatible' and set the values for options that didn't get set yet
11982 * to the Vim defaults.
11983 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011984 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985 */
11986 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011987vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011988{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011989 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011990 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011991 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011992
11993 if (!option_was_set((char_u *)"cp"))
11994 {
11995 p_cp = FALSE;
11996 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11997 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11998 set_option_default(opt_idx, OPT_FREE, FALSE);
11999 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012000 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012001 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012002
12003 if (fname != NULL)
12004 {
12005 p = vim_getenv(envname, &dofree);
12006 if (p == NULL)
12007 {
12008 /* Set $MYVIMRC to the first vimrc file found. */
12009 p = FullName_save(fname, FALSE);
12010 if (p != NULL)
12011 {
12012 vim_setenv(envname, p);
12013 vim_free(p);
12014 }
12015 }
12016 else if (dofree)
12017 vim_free(p);
12018 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012019}
12020
12021/*
12022 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12023 */
12024 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012025change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012026{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012027 int opt_idx;
12028
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029 if (p_cp != on)
12030 {
12031 p_cp = on;
12032 compatible_set();
12033 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012034 opt_idx = findoption((char_u *)"cp");
12035 if (opt_idx >= 0)
12036 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012037}
12038
12039/*
12040 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012041 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012042 */
12043 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012044option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045{
12046 int idx;
12047
12048 idx = findoption(name);
12049 if (idx < 0) /* unknown option */
12050 return FALSE;
12051 if (options[idx].flags & P_WAS_SET)
12052 return TRUE;
12053 return FALSE;
12054}
12055
12056/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012057 * Reset the flag indicating option "name" was set.
12058 */
12059 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012060reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012061{
12062 int idx = findoption(name);
12063
12064 if (idx >= 0)
12065 options[idx].flags &= ~P_WAS_SET;
12066}
12067
12068/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012069 * compatible_set() - Called when 'compatible' has been set or unset.
12070 *
12071 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12072 * flag) to a Vi compatible value.
12073 * When 'compatible' is unset: Set all options that have a different default
12074 * for Vim (without the P_VI_DEF flag) to that default.
12075 */
12076 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012077compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078{
12079 int opt_idx;
12080
12081 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12082 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12083 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12084 set_option_default(opt_idx, OPT_FREE, p_cp);
12085 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012086 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087}
12088
12089#ifdef FEAT_LINEBREAK
12090
12091# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12092 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012093 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012094# endif
12095
12096/*
12097 * fill_breakat_flags() -- called when 'breakat' changes value.
12098 */
12099 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012100fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012101{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012102 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103 int i;
12104
12105 for (i = 0; i < 256; i++)
12106 breakat_flags[i] = FALSE;
12107
12108 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012109 for (p = p_breakat; *p; p++)
12110 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012111}
12112
12113# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012114 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012115# endif
12116
12117#endif
12118
12119/*
12120 * Check an option that can be a range of string values.
12121 *
12122 * Return OK for correct value, FAIL otherwise.
12123 * Empty is always OK.
12124 */
12125 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012126check_opt_strings(
12127 char_u *val,
12128 char **values,
12129 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012130{
12131 return opt_strings_flags(val, values, NULL, list);
12132}
12133
12134/*
12135 * Handle an option that can be a range of string values.
12136 * Set a flag in "*flagp" for each string present.
12137 *
12138 * Return OK for correct value, FAIL otherwise.
12139 * Empty is always OK.
12140 */
12141 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012142opt_strings_flags(
12143 char_u *val, /* new value */
12144 char **values, /* array of valid string values */
12145 unsigned *flagp,
12146 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147{
12148 int i;
12149 int len;
12150 unsigned new_flags = 0;
12151
12152 while (*val)
12153 {
12154 for (i = 0; ; ++i)
12155 {
12156 if (values[i] == NULL) /* val not found in values[] */
12157 return FAIL;
12158
12159 len = (int)STRLEN(values[i]);
12160 if (STRNCMP(values[i], val, len) == 0
12161 && ((list && val[len] == ',') || val[len] == NUL))
12162 {
12163 val += len + (val[len] == ',');
12164 new_flags |= (1 << i);
12165 break; /* check next item in val list */
12166 }
12167 }
12168 }
12169 if (flagp != NULL)
12170 *flagp = new_flags;
12171
12172 return OK;
12173}
12174
12175/*
12176 * Read the 'wildmode' option, fill wim_flags[].
12177 */
12178 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012179check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012180{
12181 char_u new_wim_flags[4];
12182 char_u *p;
12183 int i;
12184 int idx = 0;
12185
12186 for (i = 0; i < 4; ++i)
12187 new_wim_flags[i] = 0;
12188
12189 for (p = p_wim; *p; ++p)
12190 {
12191 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12192 ;
12193 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12194 return FAIL;
12195 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12196 new_wim_flags[idx] |= WIM_LONGEST;
12197 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12198 new_wim_flags[idx] |= WIM_FULL;
12199 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12200 new_wim_flags[idx] |= WIM_LIST;
12201 else
12202 return FAIL;
12203 p += i;
12204 if (*p == NUL)
12205 break;
12206 if (*p == ',')
12207 {
12208 if (idx == 3)
12209 return FAIL;
12210 ++idx;
12211 }
12212 }
12213
12214 /* fill remaining entries with last flag */
12215 while (idx < 3)
12216 {
12217 new_wim_flags[idx + 1] = new_wim_flags[idx];
12218 ++idx;
12219 }
12220
12221 /* only when there are no errors, wim_flags[] is changed */
12222 for (i = 0; i < 4; ++i)
12223 wim_flags[i] = new_wim_flags[i];
12224 return OK;
12225}
12226
12227/*
12228 * Check if backspacing over something is allowed.
12229 */
12230 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012231can_bs(
12232 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012233{
12234 switch (*p_bs)
12235 {
12236 case '2': return TRUE;
12237 case '1': return (what != BS_START);
12238 case '0': return FALSE;
12239 }
12240 return vim_strchr(p_bs, what) != NULL;
12241}
12242
12243/*
12244 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12245 * the file must be considered changed when the value is different.
12246 */
12247 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012248save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012249{
12250 buf->b_start_ffc = *buf->b_p_ff;
12251 buf->b_start_eol = buf->b_p_eol;
12252#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012253 buf->b_start_bomb = buf->b_p_bomb;
12254
Bram Moolenaar071d4272004-06-13 20:20:40 +000012255 /* Only use free/alloc when necessary, they take time. */
12256 if (buf->b_start_fenc == NULL
12257 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12258 {
12259 vim_free(buf->b_start_fenc);
12260 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12261 }
12262#endif
12263}
12264
12265/*
12266 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12267 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012268 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12269 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012270 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012271 * When "ignore_empty" is true don't consider a new, empty buffer to be
12272 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012273 */
12274 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012275file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012276{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012277 /* In a buffer that was never loaded the options are not valid. */
12278 if (buf->b_flags & BF_NEVERLOADED)
12279 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012280 if (ignore_empty
12281 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012282 && buf->b_ml.ml_line_count == 1
12283 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12284 return FALSE;
12285 if (buf->b_start_ffc != *buf->b_p_ff)
12286 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012287 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288 return TRUE;
12289#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012290 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12291 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012292 if (buf->b_start_fenc == NULL)
12293 return (*buf->b_p_fenc != NUL);
12294 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12295#else
12296 return FALSE;
12297#endif
12298}
12299
12300/*
12301 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12302 */
12303 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012304check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012305{
12306 return check_opt_strings(p, p_ff_values, FALSE);
12307}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012308
12309/*
12310 * Return the effective shiftwidth value for current buffer, using the
12311 * 'tabstop' value when 'shiftwidth' is zero.
12312 */
12313 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012314get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012315{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012316 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012317}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012318
12319/*
12320 * Return the effective softtabstop value for the current buffer, using the
12321 * 'tabstop' value when 'softtabstop' is negative.
12322 */
12323 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012324get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012325{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012326 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012327}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012328
12329/*
12330 * Check matchpairs option for "*initc".
12331 * If there is a match set "*initc" to the matching character and "*findc" to
12332 * the opposite character. Set "*backwards" to the direction.
12333 * When "switchit" is TRUE swap the direction.
12334 */
12335 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012336find_mps_values(
12337 int *initc,
12338 int *findc,
12339 int *backwards,
12340 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012341{
12342 char_u *ptr;
12343
12344 ptr = curbuf->b_p_mps;
12345 while (*ptr != NUL)
12346 {
12347#ifdef FEAT_MBYTE
12348 if (has_mbyte)
12349 {
12350 char_u *prev;
12351
12352 if (mb_ptr2char(ptr) == *initc)
12353 {
12354 if (switchit)
12355 {
12356 *findc = *initc;
12357 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12358 *backwards = TRUE;
12359 }
12360 else
12361 {
12362 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12363 *backwards = FALSE;
12364 }
12365 return;
12366 }
12367 prev = ptr;
12368 ptr += mb_ptr2len(ptr) + 1;
12369 if (mb_ptr2char(ptr) == *initc)
12370 {
12371 if (switchit)
12372 {
12373 *findc = *initc;
12374 *initc = mb_ptr2char(prev);
12375 *backwards = FALSE;
12376 }
12377 else
12378 {
12379 *findc = mb_ptr2char(prev);
12380 *backwards = TRUE;
12381 }
12382 return;
12383 }
12384 ptr += mb_ptr2len(ptr);
12385 }
12386 else
12387#endif
12388 {
12389 if (*ptr == *initc)
12390 {
12391 if (switchit)
12392 {
12393 *backwards = TRUE;
12394 *findc = *initc;
12395 *initc = ptr[2];
12396 }
12397 else
12398 {
12399 *backwards = FALSE;
12400 *findc = ptr[2];
12401 }
12402 return;
12403 }
12404 ptr += 2;
12405 if (*ptr == *initc)
12406 {
12407 if (switchit)
12408 {
12409 *backwards = FALSE;
12410 *findc = *initc;
12411 *initc = ptr[-2];
12412 }
12413 else
12414 {
12415 *backwards = TRUE;
12416 *findc = ptr[-2];
12417 }
12418 return;
12419 }
12420 ++ptr;
12421 }
12422 if (*ptr == ',')
12423 ++ptr;
12424 }
12425}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012426
12427#if defined(FEAT_LINEBREAK) || defined(PROTO)
12428/*
12429 * This is called when 'breakindentopt' is changed and when a window is
12430 * initialized.
12431 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012432 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012433briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012434{
12435 char_u *p;
12436 int bri_shift = 0;
12437 long bri_min = 20;
12438 int bri_sbr = FALSE;
12439
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012440 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012441 while (*p != NUL)
12442 {
12443 if (STRNCMP(p, "shift:", 6) == 0
12444 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12445 {
12446 p += 6;
12447 bri_shift = getdigits(&p);
12448 }
12449 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12450 {
12451 p += 4;
12452 bri_min = getdigits(&p);
12453 }
12454 else if (STRNCMP(p, "sbr", 3) == 0)
12455 {
12456 p += 3;
12457 bri_sbr = TRUE;
12458 }
12459 if (*p != ',' && *p != NUL)
12460 return FAIL;
12461 if (*p == ',')
12462 ++p;
12463 }
12464
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012465 wp->w_p_brishift = bri_shift;
12466 wp->w_p_brimin = bri_min;
12467 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012468
12469 return OK;
12470}
12471#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012472
12473/*
12474 * Get the local or global value of 'backupcopy'.
12475 */
12476 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012477get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012478{
12479 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12480}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012481
12482#if defined(FEAT_SIGNS) || defined(PROTO)
12483/*
12484 * Return TRUE when window "wp" has a column to draw signs in.
12485 */
12486 int
12487signcolumn_on(win_T *wp)
12488{
12489 if (*wp->w_p_scl == 'n')
12490 return FALSE;
12491 if (*wp->w_p_scl == 'y')
12492 return TRUE;
12493 return (wp->w_buffer->b_signlist != NULL
12494# ifdef FEAT_NETBEANS_INTG
12495 || wp->w_buffer->b_has_sign_column
12496# endif
12497 );
12498}
12499#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012500
12501#if defined(FEAT_EVAL) || defined(PROTO)
12502/*
12503 * Get window or buffer local options.
12504 */
12505 dict_T *
12506get_winbuf_options(int bufopt)
12507{
12508 dict_T *d;
12509 int opt_idx;
12510
12511 d = dict_alloc();
12512 if (d == NULL)
12513 return NULL;
12514
12515 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12516 {
12517 struct vimoption *opt = &options[opt_idx];
12518
12519 if ((bufopt && (opt->indir & PV_BUF))
12520 || (!bufopt && (opt->indir & PV_WIN)))
12521 {
12522 char_u *varp = get_varp(opt);
12523
12524 if (varp != NULL)
12525 {
12526 if (opt->flags & P_STRING)
12527 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012528 else if (opt->flags & P_NUM)
12529 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012530 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012531 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012532 }
12533 }
12534 }
12535
12536 return d;
12537}
12538#endif