blob: 48a8048cb991da8157a1dd263abed595a201216b [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");
5939 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940 }
5941
5942 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005943 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005945 char_u *bkc = p_bkc;
5946 unsigned int *flags = &bkc_flags;
5947
5948 if (opt_flags & OPT_LOCAL)
5949 {
5950 bkc = curbuf->b_p_bkc;
5951 flags = &curbuf->b_bkc_flags;
5952 }
5953
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005954 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5955 /* make the local value empty: use the global value */
5956 *flags = 0;
5957 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005958 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005959 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5960 errmsg = e_invarg;
5961 if ((((int)*flags & BKC_AUTO) != 0)
5962 + (((int)*flags & BKC_YES) != 0)
5963 + (((int)*flags & BKC_NO) != 0) != 1)
5964 {
5965 /* Must have exactly one of "auto", "yes" and "no". */
5966 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5967 errmsg = e_invarg;
5968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969 }
5970 }
5971
5972 /* 'backupext' and 'patchmode' */
5973 else if (varp == &p_bex || varp == &p_pm)
5974 {
5975 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5976 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5977 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5978 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005979#ifdef FEAT_LINEBREAK
5980 /* 'breakindentopt' */
5981 else if (varp == &curwin->w_p_briopt)
5982 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005983 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005984 errmsg = e_invarg;
5985 }
5986#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005987
5988 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005989 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005991 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005992 */
5993 else if ( varp == &p_isi
5994 || varp == &(curbuf->b_p_isk)
5995 || varp == &p_isp
5996 || varp == &p_isf)
5997 {
5998 if (init_chartab() == FAIL)
5999 {
6000 did_chartab = TRUE; /* need to restore it below */
6001 errmsg = e_invarg; /* error in value */
6002 }
6003 }
6004
6005 /* 'helpfile' */
6006 else if (varp == &p_hf)
6007 {
6008 /* May compute new values for $VIM and $VIMRUNTIME */
6009 if (didset_vim)
6010 {
6011 vim_setenv((char_u *)"VIM", (char_u *)"");
6012 didset_vim = FALSE;
6013 }
6014 if (didset_vimruntime)
6015 {
6016 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6017 didset_vimruntime = FALSE;
6018 }
6019 }
6020
Bram Moolenaar1a384422010-07-14 19:53:30 +02006021#ifdef FEAT_SYN_HL
6022 /* 'colorcolumn' */
6023 else if (varp == &curwin->w_p_cc)
6024 errmsg = check_colorcolumn(curwin);
6025#endif
6026
Bram Moolenaar071d4272004-06-13 20:20:40 +00006027#ifdef FEAT_MULTI_LANG
6028 /* 'helplang' */
6029 else if (varp == &p_hlg)
6030 {
6031 /* Check for "", "ab", "ab,cd", etc. */
6032 for (s = p_hlg; *s != NUL; s += 3)
6033 {
6034 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6035 {
6036 errmsg = e_invarg;
6037 break;
6038 }
6039 if (s[2] == NUL)
6040 break;
6041 }
6042 }
6043#endif
6044
6045 /* 'highlight' */
6046 else if (varp == &p_hl)
6047 {
6048 if (highlight_changed() == FAIL)
6049 errmsg = e_invarg; /* invalid flags */
6050 }
6051
6052 /* 'nrformats' */
6053 else if (gvarp == &p_nf)
6054 {
6055 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6056 errmsg = e_invarg;
6057 }
6058
6059#ifdef FEAT_SESSION
6060 /* 'sessionoptions' */
6061 else if (varp == &p_ssop)
6062 {
6063 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6064 errmsg = e_invarg;
6065 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6066 {
6067 /* Don't allow both "sesdir" and "curdir". */
6068 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6069 errmsg = e_invarg;
6070 }
6071 }
6072 /* 'viewoptions' */
6073 else if (varp == &p_vop)
6074 {
6075 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6076 errmsg = e_invarg;
6077 }
6078#endif
6079
6080 /* 'scrollopt' */
6081#ifdef FEAT_SCROLLBIND
6082 else if (varp == &p_sbo)
6083 {
6084 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6085 errmsg = e_invarg;
6086 }
6087#endif
6088
6089 /* 'ambiwidth' */
6090#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006091 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006092 {
6093 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6094 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006095 else if (set_chars_option(&p_lcs) != NULL)
6096 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6097# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6098 else if (set_chars_option(&p_fcs) != NULL)
6099 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6100# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101 }
6102#endif
6103
6104 /* 'background' */
6105 else if (varp == &p_bg)
6106 {
6107 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6108 {
6109#ifdef FEAT_EVAL
6110 int dark = (*p_bg == 'd');
6111#endif
6112
6113 init_highlight(FALSE, FALSE);
6114
6115#ifdef FEAT_EVAL
6116 if (dark != (*p_bg == 'd')
6117 && get_var_value((char_u *)"g:colors_name") != NULL)
6118 {
6119 /* The color scheme must have set 'background' back to another
6120 * value, that's not what we want here. Disable the color
6121 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006122 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123 free_string_option(p_bg);
6124 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6125 check_string_option(&p_bg);
6126 init_highlight(FALSE, FALSE);
6127 }
6128#endif
6129 }
6130 else
6131 errmsg = e_invarg;
6132 }
6133
6134 /* 'wildmode' */
6135 else if (varp == &p_wim)
6136 {
6137 if (check_opt_wim() == FAIL)
6138 errmsg = e_invarg;
6139 }
6140
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006141#ifdef FEAT_CMDL_COMPL
6142 /* 'wildoptions' */
6143 else if (varp == &p_wop)
6144 {
6145 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6146 errmsg = e_invarg;
6147 }
6148#endif
6149
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150#ifdef FEAT_WAK
6151 /* 'winaltkeys' */
6152 else if (varp == &p_wak)
6153 {
6154 if (*p_wak == NUL
6155 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6156 errmsg = e_invarg;
6157# ifdef FEAT_MENU
6158# ifdef FEAT_GUI_MOTIF
6159 else if (gui.in_use)
6160 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6161# else
6162# ifdef FEAT_GUI_GTK
6163 else if (gui.in_use)
6164 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6165# endif
6166# endif
6167# endif
6168 }
6169#endif
6170
6171#ifdef FEAT_AUTOCMD
6172 /* 'eventignore' */
6173 else if (varp == &p_ei)
6174 {
6175 if (check_ei() == FAIL)
6176 errmsg = e_invarg;
6177 }
6178#endif
6179
6180#ifdef FEAT_MBYTE
6181 /* 'encoding' and 'fileencoding' */
6182 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6183 {
6184 if (gvarp == &p_fenc)
6185 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006186 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006187 errmsg = e_modifiable;
6188 else if (vim_strchr(*varp, ',') != NULL)
6189 /* No comma allowed in 'fileencoding'; catches confusing it
6190 * with 'fileencodings'. */
6191 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006192 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006193 {
6194# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006195 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006196 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006197# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006198 /* Add 'fileencoding' to the swap file. */
6199 ml_setflags(curbuf);
6200 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006201 }
6202 if (errmsg == NULL)
6203 {
6204 /* canonize the value, so that STRCMP() can be used on it */
6205 p = enc_canonize(*varp);
6206 if (p != NULL)
6207 {
6208 vim_free(*varp);
6209 *varp = p;
6210 }
6211 if (varp == &p_enc)
6212 {
6213 errmsg = mb_init();
6214# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006215 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006216# endif
6217 }
6218 }
6219
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006220# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006221 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6222 {
6223 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6224 if (STRCMP(p_tenc, "utf-8") != 0)
6225 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6226 }
6227# endif
6228
6229 if (errmsg == NULL)
6230 {
6231# ifdef FEAT_KEYMAP
6232 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6233 * (with another encoding). */
6234 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6235 (void)keymap_init();
6236# endif
6237
6238 /* When 'termencoding' is not empty and 'encoding' changes or when
6239 * 'termencoding' changes, need to setup for keyboard input and
6240 * display output conversion. */
6241 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6242 {
6243 convert_setup(&input_conv, p_tenc, p_enc);
6244 convert_setup(&output_conv, p_enc, p_tenc);
6245 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006246
6247# if defined(WIN3264) && defined(FEAT_MBYTE)
6248 /* $HOME may have characters in active code page. */
6249 if (varp == &p_enc)
6250 init_homedir();
6251# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006252 }
6253 }
6254#endif
6255
6256#if defined(FEAT_POSTSCRIPT)
6257 else if (varp == &p_penc)
6258 {
6259 /* Canonize printencoding if VIM standard one */
6260 p = enc_canonize(p_penc);
6261 if (p != NULL)
6262 {
6263 vim_free(p_penc);
6264 p_penc = p;
6265 }
6266 else
6267 {
6268 /* Ensure lower case and '-' for '_' */
6269 for (s = p_penc; *s != NUL; s++)
6270 {
6271 if (*s == '_')
6272 *s = '-';
6273 else
6274 *s = TOLOWER_ASC(*s);
6275 }
6276 }
6277 }
6278#endif
6279
Bram Moolenaar9372a112005-12-06 19:59:18 +00006280#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006281 else if (varp == &p_imak)
6282 {
6283 if (gui.in_use && !im_xim_isvalid_imactivate())
6284 errmsg = e_invarg;
6285 }
6286#endif
6287
6288#ifdef FEAT_KEYMAP
6289 else if (varp == &curbuf->b_p_keymap)
6290 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006291 if (!valid_filetype(*varp))
6292 errmsg = e_invarg;
6293 else
6294 /* load or unload key mapping tables */
6295 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296
Bram Moolenaarfab06232009-03-04 03:13:35 +00006297 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006298 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006299 if (*curbuf->b_p_keymap != NUL)
6300 {
6301 /* Installed a new keymap, switch on using it. */
6302 curbuf->b_p_iminsert = B_IMODE_LMAP;
6303 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6304 curbuf->b_p_imsearch = B_IMODE_LMAP;
6305 }
6306 else
6307 {
6308 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6309 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6310 curbuf->b_p_iminsert = B_IMODE_NONE;
6311 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6312 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6313 }
6314 if ((opt_flags & OPT_LOCAL) == 0)
6315 {
6316 set_iminsert_global();
6317 set_imsearch_global();
6318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319# ifdef FEAT_WINDOWS
6320 status_redraw_curbuf();
6321# endif
6322 }
6323 }
6324#endif
6325
6326 /* 'fileformat' */
6327 else if (gvarp == &p_ff)
6328 {
6329 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6330 errmsg = e_modifiable;
6331 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6332 errmsg = e_invarg;
6333 else
6334 {
6335 /* may also change 'textmode' */
6336 if (get_fileformat(curbuf) == EOL_DOS)
6337 curbuf->b_p_tx = TRUE;
6338 else
6339 curbuf->b_p_tx = FALSE;
6340#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006341 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006343 /* update flag in swap file */
6344 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006345 /* Redraw needed when switching to/from "mac": a CR in the text
6346 * will be displayed differently. */
6347 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6348 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006349 }
6350 }
6351
6352 /* 'fileformats' */
6353 else if (varp == &p_ffs)
6354 {
6355 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6356 errmsg = e_invarg;
6357 else
6358 {
6359 /* also change 'textauto' */
6360 if (*p_ffs == NUL)
6361 p_ta = FALSE;
6362 else
6363 p_ta = TRUE;
6364 }
6365 }
6366
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006367#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006368 /* 'cryptkey' */
6369 else if (gvarp == &p_key)
6370 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006371# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006372 /* Make sure the ":set" command doesn't show the new value in the
6373 * history. */
6374 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006375# endif
6376 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6377 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006378 ml_set_crypt_key(curbuf, oldval,
6379 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006380 }
6381
6382 else if (gvarp == &p_cm)
6383 {
6384 if (opt_flags & OPT_LOCAL)
6385 p = curbuf->b_p_cm;
6386 else
6387 p = p_cm;
6388 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6389 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006390 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006391 errmsg = e_invarg;
6392 else
6393 {
6394 /* When setting the global value to empty, make it "zip". */
6395 if (*p_cm == NUL)
6396 {
6397 if (new_value_alloced)
6398 free_string_option(p_cm);
6399 p_cm = vim_strsave((char_u *)"zip");
6400 new_value_alloced = TRUE;
6401 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006402 /* When using ":set cm=name" the local value is going to be empty.
6403 * Do that here, otherwise the crypt functions will still use the
6404 * local value. */
6405 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6406 {
6407 free_string_option(curbuf->b_p_cm);
6408 curbuf->b_p_cm = empty_option;
6409 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006410
6411 /* Need to update the swapfile when the effective method changed.
6412 * Set "s" to the effective old value, "p" to the effective new
6413 * method and compare. */
6414 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6415 s = p_cm; /* was previously using the global value */
6416 else
6417 s = oldval;
6418 if (*curbuf->b_p_cm == NUL)
6419 p = p_cm; /* is now using the global value */
6420 else
6421 p = curbuf->b_p_cm;
6422 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006423 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006424
6425 /* If the global value changes need to update the swapfile for all
6426 * buffers using that value. */
6427 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6428 {
6429 buf_T *buf;
6430
Bram Moolenaar29323592016-07-24 22:04:11 +02006431 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006432 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006433 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006434 }
6435 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006436 }
6437#endif
6438
6439 /* 'matchpairs' */
6440 else if (gvarp == &p_mps)
6441 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006442#ifdef FEAT_MBYTE
6443 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006444 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006445 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006446 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006447 int x2 = -1;
6448 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006449
6450 if (*p != NUL)
6451 p += mb_ptr2len(p);
6452 if (*p != NUL)
6453 x2 = *p++;
6454 if (*p != NUL)
6455 {
6456 x3 = mb_ptr2char(p);
6457 p += mb_ptr2len(p);
6458 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006459 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006460 {
6461 errmsg = e_invarg;
6462 break;
6463 }
6464 if (*p == NUL)
6465 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006466 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006467 }
6468 else
6469#endif
6470 {
6471 /* Check for "x:y,x:y" */
6472 for (p = *varp; *p != NUL; p += 4)
6473 {
6474 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6475 {
6476 errmsg = e_invarg;
6477 break;
6478 }
6479 if (p[3] == NUL)
6480 break;
6481 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006482 }
6483 }
6484
6485#ifdef FEAT_COMMENTS
6486 /* 'comments' */
6487 else if (gvarp == &p_com)
6488 {
6489 for (s = *varp; *s; )
6490 {
6491 while (*s && *s != ':')
6492 {
6493 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6494 && !VIM_ISDIGIT(*s) && *s != '-')
6495 {
6496 errmsg = illegal_char(errbuf, *s);
6497 break;
6498 }
6499 ++s;
6500 }
6501 if (*s++ == NUL)
6502 errmsg = (char_u *)N_("E524: Missing colon");
6503 else if (*s == ',' || *s == NUL)
6504 errmsg = (char_u *)N_("E525: Zero length string");
6505 if (errmsg != NULL)
6506 break;
6507 while (*s && *s != ',')
6508 {
6509 if (*s == '\\' && s[1] != NUL)
6510 ++s;
6511 ++s;
6512 }
6513 s = skip_to_option_part(s);
6514 }
6515 }
6516#endif
6517
6518 /* 'listchars' */
6519 else if (varp == &p_lcs)
6520 {
6521 errmsg = set_chars_option(varp);
6522 }
6523
6524#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6525 /* 'fillchars' */
6526 else if (varp == &p_fcs)
6527 {
6528 errmsg = set_chars_option(varp);
6529 }
6530#endif
6531
6532#ifdef FEAT_CMDWIN
6533 /* 'cedit' */
6534 else if (varp == &p_cedit)
6535 {
6536 errmsg = check_cedit();
6537 }
6538#endif
6539
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006540 /* 'verbosefile' */
6541 else if (varp == &p_vfile)
6542 {
6543 verbose_stop();
6544 if (*p_vfile != NUL && verbose_open() == FAIL)
6545 errmsg = e_invarg;
6546 }
6547
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548#ifdef FEAT_VIMINFO
6549 /* 'viminfo' */
6550 else if (varp == &p_viminfo)
6551 {
6552 for (s = p_viminfo; *s;)
6553 {
6554 /* Check it's a valid character */
6555 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6556 {
6557 errmsg = illegal_char(errbuf, *s);
6558 break;
6559 }
6560 if (*s == 'n') /* name is always last one */
6561 {
6562 break;
6563 }
6564 else if (*s == 'r') /* skip until next ',' */
6565 {
6566 while (*++s && *s != ',')
6567 ;
6568 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006569 else if (*s == '%')
6570 {
6571 /* optional number */
6572 while (vim_isdigit(*++s))
6573 ;
6574 }
6575 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006576 ++s; /* no extra chars */
6577 else /* must have a number */
6578 {
6579 while (vim_isdigit(*++s))
6580 ;
6581
6582 if (!VIM_ISDIGIT(*(s - 1)))
6583 {
6584 if (errbuf != NULL)
6585 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006586 sprintf((char *)errbuf,
6587 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006588 transchar_byte(*(s - 1)));
6589 errmsg = errbuf;
6590 }
6591 else
6592 errmsg = (char_u *)"";
6593 break;
6594 }
6595 }
6596 if (*s == ',')
6597 ++s;
6598 else if (*s)
6599 {
6600 if (errbuf != NULL)
6601 errmsg = (char_u *)N_("E527: Missing comma");
6602 else
6603 errmsg = (char_u *)"";
6604 break;
6605 }
6606 }
6607 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6608 errmsg = (char_u *)N_("E528: Must specify a ' value");
6609 }
6610#endif /* FEAT_VIMINFO */
6611
6612 /* terminal options */
6613 else if (istermoption(&options[opt_idx]) && full_screen)
6614 {
6615 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6616 if (varp == &T_CCO)
6617 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006618 int colors = atoi((char *)T_CCO);
6619
6620 /* Only reinitialize colors if t_Co value has really changed to
6621 * avoid expensive reload of colorscheme if t_Co is set to the
6622 * same value multiple times. */
6623 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006625 t_colors = colors;
6626 if (t_colors <= 1)
6627 {
6628 if (new_value_alloced)
6629 vim_free(T_CCO);
6630 T_CCO = empty_option;
6631 }
6632 /* We now have a different color setup, initialize it again. */
6633 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 }
6636 ttest(FALSE);
6637 if (varp == &T_ME)
6638 {
6639 out_str(T_ME);
6640 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006641#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006642 /* Since t_me has been set, this probably means that the user
6643 * wants to use this as default colors. Need to reset default
6644 * background/foreground colors. */
6645 mch_set_normal_colors();
6646#endif
6647 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006648 if (varp == &T_BE && termcap_active)
6649 {
6650 if (*T_BE == NUL)
6651 /* When clearing t_BE we assume the user no longer wants
6652 * bracketed paste, thus disable it by writing t_BD. */
6653 out_str(T_BD);
6654 else
6655 out_str(T_BE);
6656 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006657 }
6658
6659#ifdef FEAT_LINEBREAK
6660 /* 'showbreak' */
6661 else if (varp == &p_sbr)
6662 {
6663 for (s = p_sbr; *s; )
6664 {
6665 if (ptr2cells(s) != 1)
6666 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006667 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006668 }
6669 }
6670#endif
6671
6672#ifdef FEAT_GUI
6673 /* 'guifont' */
6674 else if (varp == &p_guifont)
6675 {
6676 if (gui.in_use)
6677 {
6678 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006679# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006680 /*
6681 * Put up a font dialog and let the user select a new value.
6682 * If this is cancelled go back to the old value but don't
6683 * give an error message.
6684 */
6685 if (STRCMP(p, "*") == 0)
6686 {
6687 p = gui_mch_font_dialog(oldval);
6688
6689 if (new_value_alloced)
6690 free_string_option(p_guifont);
6691
6692 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6693 new_value_alloced = TRUE;
6694 }
6695# endif
6696 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6697 {
6698# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6699 if (STRCMP(p_guifont, "*") == 0)
6700 {
6701 /* Dialog was cancelled: Keep the old value without giving
6702 * an error message. */
6703 if (new_value_alloced)
6704 free_string_option(p_guifont);
6705 p_guifont = vim_strsave(oldval);
6706 new_value_alloced = TRUE;
6707 }
6708 else
6709# endif
6710 errmsg = (char_u *)N_("E596: Invalid font(s)");
6711 }
6712 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006713 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006714 }
6715# ifdef FEAT_XFONTSET
6716 else if (varp == &p_guifontset)
6717 {
6718 if (STRCMP(p_guifontset, "*") == 0)
6719 errmsg = (char_u *)N_("E597: can't select fontset");
6720 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6721 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006722 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006723 }
6724# endif
6725# ifdef FEAT_MBYTE
6726 else if (varp == &p_guifontwide)
6727 {
6728 if (STRCMP(p_guifontwide, "*") == 0)
6729 errmsg = (char_u *)N_("E533: can't select wide font");
6730 else if (gui_get_wide_font() == FAIL)
6731 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006732 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006733 }
6734# endif
6735#endif
6736
6737#ifdef CURSOR_SHAPE
6738 /* 'guicursor' */
6739 else if (varp == &p_guicursor)
6740 errmsg = parse_shape_opt(SHAPE_CURSOR);
6741#endif
6742
6743#ifdef FEAT_MOUSESHAPE
6744 /* 'mouseshape' */
6745 else if (varp == &p_mouseshape)
6746 {
6747 errmsg = parse_shape_opt(SHAPE_MOUSE);
6748 update_mouseshape(-1);
6749 }
6750#endif
6751
6752#ifdef FEAT_PRINTER
6753 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006754 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006755# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006756 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006757 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006758# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006759#endif
6760
6761#ifdef FEAT_LANGMAP
6762 /* 'langmap' */
6763 else if (varp == &p_langmap)
6764 langmap_set();
6765#endif
6766
6767#ifdef FEAT_LINEBREAK
6768 /* 'breakat' */
6769 else if (varp == &p_breakat)
6770 fill_breakat_flags();
6771#endif
6772
6773#ifdef FEAT_TITLE
6774 /* 'titlestring' and 'iconstring' */
6775 else if (varp == &p_titlestring || varp == &p_iconstring)
6776 {
6777# ifdef FEAT_STL_OPT
6778 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6779
6780 /* NULL => statusline syntax */
6781 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6782 stl_syntax |= flagval;
6783 else
6784 stl_syntax &= ~flagval;
6785# endif
6786 did_set_title(varp == &p_iconstring);
6787
6788 }
6789#endif
6790
6791#ifdef FEAT_GUI
6792 /* 'guioptions' */
6793 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006794 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006795 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006796 redraw_gui_only = TRUE;
6797 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006798#endif
6799
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006800#if defined(FEAT_GUI_TABLINE)
6801 /* 'guitablabel' */
6802 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006803 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006804 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006805 redraw_gui_only = TRUE;
6806 }
6807 /* 'guitabtooltip' */
6808 else if (varp == &p_gtt)
6809 {
6810 redraw_gui_only = TRUE;
6811 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006812#endif
6813
Bram Moolenaar071d4272004-06-13 20:20:40 +00006814#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6815 /* 'ttymouse' */
6816 else if (varp == &p_ttym)
6817 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006818 /* Switch the mouse off before changing the escape sequences used for
6819 * that. */
6820 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6822 errmsg = e_invarg;
6823 else
6824 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006825 if (termcap_active)
6826 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006827 }
6828#endif
6829
Bram Moolenaar071d4272004-06-13 20:20:40 +00006830 /* 'selection' */
6831 else if (varp == &p_sel)
6832 {
6833 if (*p_sel == NUL
6834 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6835 errmsg = e_invarg;
6836 }
6837
6838 /* 'selectmode' */
6839 else if (varp == &p_slm)
6840 {
6841 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6842 errmsg = e_invarg;
6843 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006844
6845#ifdef FEAT_BROWSE
6846 /* 'browsedir' */
6847 else if (varp == &p_bsdir)
6848 {
6849 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6850 && !mch_isdir(p_bsdir))
6851 errmsg = e_invarg;
6852 }
6853#endif
6854
Bram Moolenaar071d4272004-06-13 20:20:40 +00006855 /* 'keymodel' */
6856 else if (varp == &p_km)
6857 {
6858 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6859 errmsg = e_invarg;
6860 else
6861 {
6862 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6863 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6864 }
6865 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006866
6867 /* 'mousemodel' */
6868 else if (varp == &p_mousem)
6869 {
6870 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6871 errmsg = e_invarg;
6872#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6873 else if (*p_mousem != *oldval)
6874 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6875 * to create or delete the popup menus. */
6876 gui_motif_update_mousemodel(root_menu);
6877#endif
6878 }
6879
6880 /* 'switchbuf' */
6881 else if (varp == &p_swb)
6882 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006883 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 errmsg = e_invarg;
6885 }
6886
6887 /* 'debug' */
6888 else if (varp == &p_debug)
6889 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006890 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006891 errmsg = e_invarg;
6892 }
6893
6894 /* 'display' */
6895 else if (varp == &p_dy)
6896 {
6897 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6898 errmsg = e_invarg;
6899 else
6900 (void)init_chartab();
6901
6902 }
6903
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006904#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006905 /* 'eadirection' */
6906 else if (varp == &p_ead)
6907 {
6908 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6909 errmsg = e_invarg;
6910 }
6911#endif
6912
6913#ifdef FEAT_CLIPBOARD
6914 /* 'clipboard' */
6915 else if (varp == &p_cb)
6916 errmsg = check_clipboard_option();
6917#endif
6918
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006919#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006920 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6921 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006922 else if (varp == &(curwin->w_s->b_p_spl)
6923 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006924 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006925 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006926 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006927 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006928 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006929 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006930 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006931 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006932 /* 'spellsuggest' */
6933 else if (varp == &p_sps)
6934 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006935 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006936 errmsg = e_invarg;
6937 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006938 /* 'mkspellmem' */
6939 else if (varp == &p_msm)
6940 {
6941 if (spell_check_msm() != OK)
6942 errmsg = e_invarg;
6943 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006944#endif
6945
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946#ifdef FEAT_QUICKFIX
6947 /* When 'bufhidden' is set, check for valid value. */
6948 else if (gvarp == &p_bh)
6949 {
6950 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6951 errmsg = e_invarg;
6952 }
6953
6954 /* When 'buftype' is set, check for valid value. */
6955 else if (gvarp == &p_bt)
6956 {
6957 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6958 errmsg = e_invarg;
6959 else
6960 {
6961# ifdef FEAT_WINDOWS
6962 if (curwin->w_status_height)
6963 {
6964 curwin->w_redr_status = TRUE;
6965 redraw_later(VALID);
6966 }
6967# endif
6968 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006969# ifdef FEAT_TITLE
6970 redraw_titles();
6971# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972 }
6973 }
6974#endif
6975
6976#ifdef FEAT_STL_OPT
6977 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006978 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 {
6980 int wid;
6981
6982 if (varp == &p_ruf) /* reset ru_wid first */
6983 ru_wid = 0;
6984 s = *varp;
6985 if (varp == &p_ruf && *s == '%')
6986 {
6987 /* set ru_wid if 'ruf' starts with "%99(" */
6988 if (*++s == '-') /* ignore a '-' */
6989 s++;
6990 wid = getdigits(&s);
6991 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6992 ru_wid = wid;
6993 else
6994 errmsg = check_stl_option(p_ruf);
6995 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006996 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006997 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006998 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006999 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007000 comp_col();
7001 }
7002#endif
7003
7004#ifdef FEAT_INS_EXPAND
7005 /* check if it is a valid value for 'complete' -- Acevedo */
7006 else if (gvarp == &p_cpt)
7007 {
7008 for (s = *varp; *s;)
7009 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007010 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011 s++;
7012 if (!*s)
7013 break;
7014 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7015 {
7016 errmsg = illegal_char(errbuf, *s);
7017 break;
7018 }
7019 if (*++s != NUL && *s != ',' && *s != ' ')
7020 {
7021 if (s[-1] == 'k' || s[-1] == 's')
7022 {
7023 /* skip optional filename after 'k' and 's' */
7024 while (*s && *s != ',' && *s != ' ')
7025 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007026 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 ++s;
7028 ++s;
7029 }
7030 }
7031 else
7032 {
7033 if (errbuf != NULL)
7034 {
7035 sprintf((char *)errbuf,
7036 _("E535: Illegal character after <%c>"),
7037 *--s);
7038 errmsg = errbuf;
7039 }
7040 else
7041 errmsg = (char_u *)"";
7042 break;
7043 }
7044 }
7045 }
7046 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007047
7048 /* 'completeopt' */
7049 else if (varp == &p_cot)
7050 {
7051 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7052 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007053 else
7054 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007055 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007056#endif /* FEAT_INS_EXPAND */
7057
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007058#ifdef FEAT_SIGNS
7059 /* 'signcolumn' */
7060 else if (varp == &curwin->w_p_scl)
7061 {
7062 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7063 errmsg = e_invarg;
7064 }
7065#endif
7066
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067
7068#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007069 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 else if (varp == &p_toolbar)
7071 {
7072 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7073 &toolbar_flags, TRUE) != OK)
7074 errmsg = e_invarg;
7075 else
7076 {
7077 out_flush();
7078 gui_mch_show_toolbar((toolbar_flags &
7079 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7080 }
7081 }
7082#endif
7083
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007084#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085 /* 'toolbariconsize': GTK+ 2 only */
7086 else if (varp == &p_tbis)
7087 {
7088 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7089 errmsg = e_invarg;
7090 else
7091 {
7092 out_flush();
7093 gui_mch_show_toolbar((toolbar_flags &
7094 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7095 }
7096 }
7097#endif
7098
7099 /* 'pastetoggle': translate key codes like in a mapping */
7100 else if (varp == &p_pt)
7101 {
7102 if (*p_pt)
7103 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007104 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007105 if (p != NULL)
7106 {
7107 if (new_value_alloced)
7108 free_string_option(p_pt);
7109 p_pt = p;
7110 new_value_alloced = TRUE;
7111 }
7112 }
7113 }
7114
7115 /* 'backspace' */
7116 else if (varp == &p_bs)
7117 {
7118 if (VIM_ISDIGIT(*p_bs))
7119 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007120 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121 errmsg = e_invarg;
7122 }
7123 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7124 errmsg = e_invarg;
7125 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007126 else if (varp == &p_bo)
7127 {
7128 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7129 errmsg = e_invarg;
7130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007131
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007132 /* 'tagcase' */
7133 else if (gvarp == &p_tc)
7134 {
7135 unsigned int *flags;
7136
7137 if (opt_flags & OPT_LOCAL)
7138 {
7139 p = curbuf->b_p_tc;
7140 flags = &curbuf->b_tc_flags;
7141 }
7142 else
7143 {
7144 p = p_tc;
7145 flags = &tc_flags;
7146 }
7147
7148 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7149 /* make the local value empty: use the global value */
7150 *flags = 0;
7151 else if (*p == NUL
7152 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7153 errmsg = e_invarg;
7154 }
7155
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007156#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157 /* 'casemap' */
7158 else if (varp == &p_cmp)
7159 {
7160 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7161 errmsg = e_invarg;
7162 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007164
7165#ifdef FEAT_DIFF
7166 /* 'diffopt' */
7167 else if (varp == &p_dip)
7168 {
7169 if (diffopt_changed() == FAIL)
7170 errmsg = e_invarg;
7171 }
7172#endif
7173
7174#ifdef FEAT_FOLDING
7175 /* 'foldmethod' */
7176 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7177 {
7178 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7179 || *curwin->w_p_fdm == NUL)
7180 errmsg = e_invarg;
7181 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007182 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007183 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007184 if (foldmethodIsDiff(curwin))
7185 newFoldLevel();
7186 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007187 }
7188# ifdef FEAT_EVAL
7189 /* 'foldexpr' */
7190 else if (varp == &curwin->w_p_fde)
7191 {
7192 if (foldmethodIsExpr(curwin))
7193 foldUpdateAll(curwin);
7194 }
7195# endif
7196 /* 'foldmarker' */
7197 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7198 {
7199 p = vim_strchr(*varp, ',');
7200 if (p == NULL)
7201 errmsg = (char_u *)N_("E536: comma required");
7202 else if (p == *varp || p[1] == NUL)
7203 errmsg = e_invarg;
7204 else if (foldmethodIsMarker(curwin))
7205 foldUpdateAll(curwin);
7206 }
7207 /* 'commentstring' */
7208 else if (gvarp == &p_cms)
7209 {
7210 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7211 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7212 }
7213 /* 'foldopen' */
7214 else if (varp == &p_fdo)
7215 {
7216 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7217 errmsg = e_invarg;
7218 }
7219 /* 'foldclose' */
7220 else if (varp == &p_fcl)
7221 {
7222 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7223 errmsg = e_invarg;
7224 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007225 /* 'foldignore' */
7226 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7227 {
7228 if (foldmethodIsIndent(curwin))
7229 foldUpdateAll(curwin);
7230 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007231#endif
7232
7233#ifdef FEAT_VIRTUALEDIT
7234 /* 'virtualedit' */
7235 else if (varp == &p_ve)
7236 {
7237 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7238 errmsg = e_invarg;
7239 else if (STRCMP(p_ve, oldval) != 0)
7240 {
7241 /* Recompute cursor position in case the new 've' setting
7242 * changes something. */
7243 validate_virtcol();
7244 coladvance(curwin->w_virtcol);
7245 }
7246 }
7247#endif
7248
7249#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7250 else if (varp == &p_csqf)
7251 {
7252 if (p_csqf != NULL)
7253 {
7254 p = p_csqf;
7255 while (*p != NUL)
7256 {
7257 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7258 || p[1] == NUL
7259 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7260 || (p[2] != NUL && p[2] != ','))
7261 {
7262 errmsg = e_invarg;
7263 break;
7264 }
7265 else if (p[2] == NUL)
7266 break;
7267 else
7268 p += 3;
7269 }
7270 }
7271 }
7272#endif
7273
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007274#ifdef FEAT_CINDENT
7275 /* 'cinoptions' */
7276 else if (gvarp == &p_cino)
7277 {
7278 /* TODO: recognize errors */
7279 parse_cino(curbuf);
7280 }
7281#endif
7282
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007283#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007284 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007285 else if (varp == &p_rop && gui.in_use)
7286 {
7287 if (!gui_mch_set_rendering_options(p_rop))
7288 errmsg = e_invarg;
7289 }
7290#endif
7291
Bram Moolenaard0b51382016-11-04 15:23:45 +01007292#ifdef FEAT_AUTOCMD
7293 else if (gvarp == &p_ft)
7294 {
7295 if (!valid_filetype(*varp))
7296 errmsg = e_invarg;
7297 }
7298#endif
7299
7300#ifdef FEAT_SYN_HL
7301 else if (gvarp == &p_syn)
7302 {
7303 if (!valid_filetype(*varp))
7304 errmsg = e_invarg;
7305 }
7306#endif
7307
Bram Moolenaar071d4272004-06-13 20:20:40 +00007308 /* Options that are a list of flags. */
7309 else
7310 {
7311 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007312 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007314 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007315 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007316 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007318 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007319 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007320#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007321 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007322 p = (char_u *)COCU_ALL;
7323#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007324 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007325 {
7326#ifdef FEAT_MOUSE
7327 p = (char_u *)MOUSE_ALL;
7328#else
7329 if (*p_mouse != NUL)
7330 errmsg = (char_u *)N_("E538: No mouse support");
7331#endif
7332 }
7333#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007334 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007335 p = (char_u *)GO_ALL;
7336#endif
7337 if (p != NULL)
7338 {
7339 for (s = *varp; *s; ++s)
7340 if (vim_strchr(p, *s) == NULL)
7341 {
7342 errmsg = illegal_char(errbuf, *s);
7343 break;
7344 }
7345 }
7346 }
7347
7348 /*
7349 * If error detected, restore the previous value.
7350 */
7351 if (errmsg != NULL)
7352 {
7353 if (new_value_alloced)
7354 free_string_option(*varp);
7355 *varp = oldval;
7356 /*
7357 * When resetting some values, need to act on it.
7358 */
7359 if (did_chartab)
7360 (void)init_chartab();
7361 if (varp == &p_hl)
7362 (void)highlight_changed();
7363 }
7364 else
7365 {
7366#ifdef FEAT_EVAL
7367 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007368 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007369#endif
7370 /*
7371 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007372 * Use "free_oldval", because recursiveness may change the flags under
7373 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007374 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007375 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007376 free_string_option(oldval);
7377 if (new_value_alloced)
7378 options[opt_idx].flags |= P_ALLOCED;
7379 else
7380 options[opt_idx].flags &= ~P_ALLOCED;
7381
7382 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007383 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007384 {
7385 /* global option with local value set to use global value; free
7386 * the local value and make it empty */
7387 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7388 free_string_option(*(char_u **)p);
7389 *(char_u **)p = empty_option;
7390 }
7391
7392 /* May set global value for local option. */
7393 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7394 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007395
7396#ifdef FEAT_AUTOCMD
7397 /*
7398 * Trigger the autocommand only after setting the flags.
7399 */
7400# ifdef FEAT_SYN_HL
7401 /* When 'syntax' is set, load the syntax of that name */
7402 if (varp == &(curbuf->b_p_syn))
7403 {
7404 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7405 curbuf->b_fname, TRUE, curbuf);
7406 }
7407# endif
7408 else if (varp == &(curbuf->b_p_ft))
7409 {
7410 /* 'filetype' is set, trigger the FileType autocommand */
7411 did_filetype = TRUE;
7412 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7413 curbuf->b_fname, TRUE, curbuf);
7414 }
7415#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007416#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007417 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007418 {
7419 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007420 char_u *q = curwin->w_s->b_p_spl;
7421
7422 /* Skip the first name if it is "cjk". */
7423 if (STRNCMP(q, "cjk,", 4) == 0)
7424 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007425
7426 /*
7427 * Source the spell/LANG.vim in 'runtimepath'.
7428 * They could set 'spellcapcheck' depending on the language.
7429 * Use the first name in 'spelllang' up to '_region' or
7430 * '.encoding'.
7431 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007432 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007433 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7434 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007435 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007436 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007437 }
7438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007439 }
7440
7441#ifdef FEAT_MOUSE
7442 if (varp == &p_mouse)
7443 {
7444# ifdef FEAT_MOUSE_TTY
7445 if (*p_mouse == NUL)
7446 mch_setmouse(FALSE); /* switch mouse off */
7447 else
7448# endif
7449 setmouse(); /* in case 'mouse' changed */
7450 }
7451#endif
7452
Bram Moolenaar913077c2012-03-28 19:59:04 +02007453 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007454 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007455 curwin->w_set_curswant = TRUE;
7456
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007457#ifdef FEAT_GUI
7458 /* check redraw when it's not a GUI option or the GUI is active. */
7459 if (!redraw_gui_only || gui.in_use)
7460#endif
7461 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007462
7463 return errmsg;
7464}
7465
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007466#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007467/*
7468 * Simple int comparison function for use with qsort()
7469 */
7470 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007471int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007472{
7473 return *(const int *)a - *(const int *)b;
7474}
7475
7476/*
7477 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7478 * Returns error message, NULL if it's OK.
7479 */
7480 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007481check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007482{
7483 char_u *s;
7484 int col;
7485 int count = 0;
7486 int color_cols[256];
7487 int i;
7488 int j = 0;
7489
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007490 if (wp->w_buffer == NULL)
7491 return NULL; /* buffer was closed */
7492
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007493 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007494 {
7495 if (*s == '-' || *s == '+')
7496 {
7497 /* -N and +N: add to 'textwidth' */
7498 col = (*s == '-') ? -1 : 1;
7499 ++s;
7500 if (!VIM_ISDIGIT(*s))
7501 return e_invarg;
7502 col = col * getdigits(&s);
7503 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007504 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007505 col += wp->w_buffer->b_p_tw;
7506 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007507 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007508 }
7509 else if (VIM_ISDIGIT(*s))
7510 col = getdigits(&s);
7511 else
7512 return e_invarg;
7513 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007514skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007515 if (*s == NUL)
7516 break;
7517 if (*s != ',')
7518 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007519 if (*++s == NUL)
7520 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007521 }
7522
7523 vim_free(wp->w_p_cc_cols);
7524 if (count == 0)
7525 wp->w_p_cc_cols = NULL;
7526 else
7527 {
7528 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7529 if (wp->w_p_cc_cols != NULL)
7530 {
7531 /* sort the columns for faster usage on screen redraw inside
7532 * win_line() */
7533 qsort(color_cols, count, sizeof(int), int_cmp);
7534
7535 for (i = 0; i < count; ++i)
7536 /* skip duplicates */
7537 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7538 wp->w_p_cc_cols[j++] = color_cols[i];
7539 wp->w_p_cc_cols[j] = -1; /* end marker */
7540 }
7541 }
7542
7543 return NULL; /* no error */
7544}
7545#endif
7546
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547/*
7548 * Handle setting 'listchars' or 'fillchars'.
7549 * Returns error message, NULL if it's OK.
7550 */
7551 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007552set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007553{
7554 int round, i, len, entries;
7555 char_u *p, *s;
7556 int c1, c2 = 0;
7557 struct charstab
7558 {
7559 int *cp;
7560 char *name;
7561 };
7562#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7563 static struct charstab filltab[] =
7564 {
7565 {&fill_stl, "stl"},
7566 {&fill_stlnc, "stlnc"},
7567 {&fill_vert, "vert"},
7568 {&fill_fold, "fold"},
7569 {&fill_diff, "diff"},
7570 };
7571#endif
7572 static struct charstab lcstab[] =
7573 {
7574 {&lcs_eol, "eol"},
7575 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007576 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007578 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007579 {&lcs_tab2, "tab"},
7580 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007581#ifdef FEAT_CONCEAL
7582 {&lcs_conceal, "conceal"},
7583#else
7584 {NULL, "conceal"},
7585#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007586 };
7587 struct charstab *tab;
7588
7589#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7590 if (varp == &p_lcs)
7591#endif
7592 {
7593 tab = lcstab;
7594 entries = sizeof(lcstab) / sizeof(struct charstab);
7595 }
7596#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7597 else
7598 {
7599 tab = filltab;
7600 entries = sizeof(filltab) / sizeof(struct charstab);
7601 }
7602#endif
7603
7604 /* first round: check for valid value, second round: assign values */
7605 for (round = 0; round <= 1; ++round)
7606 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007607 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007608 {
7609 /* After checking that the value is valid: set defaults: space for
7610 * 'fillchars', NUL for 'listchars' */
7611 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007612 if (tab[i].cp != NULL)
7613 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007614 if (varp == &p_lcs)
7615 lcs_tab1 = NUL;
7616#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7617 else
7618 fill_diff = '-';
7619#endif
7620 }
7621 p = *varp;
7622 while (*p)
7623 {
7624 for (i = 0; i < entries; ++i)
7625 {
7626 len = (int)STRLEN(tab[i].name);
7627 if (STRNCMP(p, tab[i].name, len) == 0
7628 && p[len] == ':'
7629 && p[len + 1] != NUL)
7630 {
7631 s = p + len + 1;
7632#ifdef FEAT_MBYTE
7633 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007634 if (mb_char2cells(c1) > 1)
7635 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636#else
7637 c1 = *s++;
7638#endif
7639 if (tab[i].cp == &lcs_tab2)
7640 {
7641 if (*s == NUL)
7642 continue;
7643#ifdef FEAT_MBYTE
7644 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007645 if (mb_char2cells(c2) > 1)
7646 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007647#else
7648 c2 = *s++;
7649#endif
7650 }
7651 if (*s == ',' || *s == NUL)
7652 {
7653 if (round)
7654 {
7655 if (tab[i].cp == &lcs_tab2)
7656 {
7657 lcs_tab1 = c1;
7658 lcs_tab2 = c2;
7659 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007660 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 *(tab[i].cp) = c1;
7662
7663 }
7664 p = s;
7665 break;
7666 }
7667 }
7668 }
7669
7670 if (i == entries)
7671 return e_invarg;
7672 if (*p == ',')
7673 ++p;
7674 }
7675 }
7676
7677 return NULL; /* no error */
7678}
7679
7680#ifdef FEAT_STL_OPT
7681/*
7682 * Check validity of options with the 'statusline' format.
7683 * Return error message or NULL.
7684 */
7685 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007686check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007687{
7688 int itemcnt = 0;
7689 int groupdepth = 0;
7690 static char_u errbuf[80];
7691
7692 while (*s && itemcnt < STL_MAX_ITEM)
7693 {
7694 /* Check for valid keys after % sequences */
7695 while (*s && *s != '%')
7696 s++;
7697 if (!*s)
7698 break;
7699 s++;
7700 if (*s != '%' && *s != ')')
7701 ++itemcnt;
7702 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7703 {
7704 s++;
7705 continue;
7706 }
7707 if (*s == ')')
7708 {
7709 s++;
7710 if (--groupdepth < 0)
7711 break;
7712 continue;
7713 }
7714 if (*s == '-')
7715 s++;
7716 while (VIM_ISDIGIT(*s))
7717 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007718 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007719 continue;
7720 if (*s == '.')
7721 {
7722 s++;
7723 while (*s && VIM_ISDIGIT(*s))
7724 s++;
7725 }
7726 if (*s == '(')
7727 {
7728 groupdepth++;
7729 continue;
7730 }
7731 if (vim_strchr(STL_ALL, *s) == NULL)
7732 {
7733 return illegal_char(errbuf, *s);
7734 }
7735 if (*s == '{')
7736 {
7737 s++;
7738 while (*s != '}' && *s)
7739 s++;
7740 if (*s != '}')
7741 return (char_u *)N_("E540: Unclosed expression sequence");
7742 }
7743 }
7744 if (itemcnt >= STL_MAX_ITEM)
7745 return (char_u *)N_("E541: too many items");
7746 if (groupdepth != 0)
7747 return (char_u *)N_("E542: unbalanced groups");
7748 return NULL;
7749}
7750#endif
7751
7752#ifdef FEAT_CLIPBOARD
7753/*
7754 * Extract the items in the 'clipboard' option and set global values.
7755 */
7756 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007757check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007759 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007760 int new_autoselect_star = FALSE;
7761 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007762 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007763 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007764 regprog_T *new_exclude_prog = NULL;
7765 char_u *errmsg = NULL;
7766 char_u *p;
7767
7768 for (p = p_cb; *p != NUL; )
7769 {
7770 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7771 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007772 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007773 p += 7;
7774 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007775 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007776 && (p[11] == ',' || p[11] == NUL))
7777 {
7778 new_unnamed |= CLIP_UNNAMED_PLUS;
7779 p += 11;
7780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007781 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007782 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007783 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007784 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007785 p += 10;
7786 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007787 else if (STRNCMP(p, "autoselectplus", 14) == 0
7788 && (p[14] == ',' || p[14] == NUL))
7789 {
7790 new_autoselect_plus = TRUE;
7791 p += 14;
7792 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007793 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007794 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007795 {
7796 new_autoselectml = TRUE;
7797 p += 12;
7798 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007799 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7800 {
7801 new_html = TRUE;
7802 p += 4;
7803 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007804 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7805 {
7806 p += 8;
7807 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7808 if (new_exclude_prog == NULL)
7809 errmsg = e_invarg;
7810 break;
7811 }
7812 else
7813 {
7814 errmsg = e_invarg;
7815 break;
7816 }
7817 if (*p == ',')
7818 ++p;
7819 }
7820 if (errmsg == NULL)
7821 {
7822 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007823 clip_autoselect_star = new_autoselect_star;
7824 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007825 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007826 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007827 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007828 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007829#ifdef FEAT_GUI_GTK
7830 if (gui.in_use)
7831 {
7832 gui_gtk_set_selection_targets();
7833 gui_gtk_set_dnd_targets();
7834 }
7835#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007836 }
7837 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007838 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839
7840 return errmsg;
7841}
7842#endif
7843
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007844#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007845 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007846did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007847{
7848 char_u *errmsg = NULL;
7849 win_T *wp;
7850 int l;
7851
7852 if (is_spellfile)
7853 {
7854 l = (int)STRLEN(curwin->w_s->b_p_spf);
7855 if (l > 0 && (l < 4
7856 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7857 errmsg = e_invarg;
7858 }
7859
7860 if (errmsg == NULL)
7861 {
7862 FOR_ALL_WINDOWS(wp)
7863 if (wp->w_buffer == curbuf && wp->w_p_spell)
7864 {
7865 errmsg = did_set_spelllang(wp);
7866# ifdef FEAT_WINDOWS
7867 break;
7868# endif
7869 }
7870 }
7871 return errmsg;
7872}
7873
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007874/*
7875 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7876 * Return error message when failed, NULL when OK.
7877 */
7878 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007879compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007880{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007881 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007882 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007883
Bram Moolenaar860cae12010-06-05 23:22:07 +02007884 if (*synblock->b_p_spc == NUL)
7885 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007886 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007887 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007888 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007889 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007890 if (re != NULL)
7891 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007892 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007893 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007894 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007895 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007896 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007897 return e_invarg;
7898 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007899 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007900 }
7901
Bram Moolenaar473de612013-06-08 18:19:48 +02007902 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007903 return NULL;
7904}
7905#endif
7906
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007907#if defined(FEAT_EVAL) || defined(PROTO)
7908/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007909 * Set the scriptID for an option, taking care of setting the buffer- or
7910 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007911 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007912 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007913set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007914{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007915 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7916 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007917
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007918 /* Remember where the option was set. For local options need to do that
7919 * in the buffer or window structure. */
7920 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007921 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007922 if (both || (opt_flags & OPT_LOCAL))
7923 {
7924 if (indir & PV_BUF)
7925 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7926 else if (indir & PV_WIN)
7927 curwin->w_p_scriptID[indir & PV_MASK] = id;
7928 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007929}
7930#endif
7931
Bram Moolenaar071d4272004-06-13 20:20:40 +00007932/*
7933 * Set the value of a boolean option, and take care of side effects.
7934 * Returns NULL for success, or an error message for an error.
7935 */
7936 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007937set_bool_option(
7938 int opt_idx, /* index in options[] table */
7939 char_u *varp, /* pointer to the option variable */
7940 int value, /* new value */
7941 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007942{
7943 int old_value = *(int *)varp;
7944
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945 /* Disallow changing some options from secure mode */
7946 if ((secure
7947#ifdef HAVE_SANDBOX
7948 || sandbox != 0
7949#endif
7950 ) && (options[opt_idx].flags & P_SECURE))
7951 return e_secure;
7952
7953 *(int *)varp = value; /* set the new value */
7954#ifdef FEAT_EVAL
7955 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007956 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957#endif
7958
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007959#ifdef FEAT_GUI
7960 need_mouse_correct = TRUE;
7961#endif
7962
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 /* May set global value for local option. */
7964 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7965 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7966
7967 /*
7968 * Handle side effects of changing a bool option.
7969 */
7970
7971 /* 'compatible' */
7972 if ((int *)varp == &p_cp)
7973 {
7974 compatible_set();
7975 }
7976
Bram Moolenaar920694c2016-08-21 17:45:02 +02007977#ifdef FEAT_LANGMAP
7978 if ((int *)varp == &p_lrm)
7979 /* 'langremap' -> !'langnoremap' */
7980 p_lnr = !p_lrm;
7981 else if ((int *)varp == &p_lnr)
7982 /* 'langnoremap' -> !'langremap' */
7983 p_lrm = !p_lnr;
7984#endif
7985
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007986#ifdef FEAT_PERSISTENT_UNDO
7987 /* 'undofile' */
7988 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7989 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007990 /* Only take action when the option was set. When reset we do not
7991 * delete the undo file, the option may be set again without making
7992 * any changes in between. */
7993 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007994 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007995 char_u hash[UNDO_HASH_SIZE];
7996 buf_T *save_curbuf = curbuf;
7997
Bram Moolenaar29323592016-07-24 22:04:11 +02007998 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007999 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008000 /* When 'undofile' is set globally: for every buffer, otherwise
8001 * only for the current buffer: Try to read in the undofile,
8002 * if one exists, the buffer wasn't changed and the buffer was
8003 * loaded */
8004 if ((curbuf == save_curbuf
8005 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8006 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8007 {
8008 u_compute_hash(hash);
8009 u_read_undo(NULL, hash, curbuf->b_fname);
8010 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008011 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008012 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008013 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008014 }
8015#endif
8016
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 else if ((int *)varp == &curbuf->b_p_ro)
8018 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008019 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008020 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8021 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008022
8023 /* when 'readonly' is set may give W10 again */
8024 if (curbuf->b_p_ro)
8025 curbuf->b_did_warn = FALSE;
8026
Bram Moolenaar071d4272004-06-13 20:20:40 +00008027#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008028 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008029#endif
8030 }
8031
Bram Moolenaar9c449722010-07-20 18:44:27 +02008032#ifdef FEAT_GUI
8033 else if ((int *)varp == &p_mh)
8034 {
8035 if (!p_mh)
8036 gui_mch_mousehide(FALSE);
8037 }
8038#endif
8039
Bram Moolenaara539df02010-08-01 14:35:05 +02008040#ifdef FEAT_TITLE
8041 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008043 {
8044 redraw_titles();
8045 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008046 /* when 'endofline' is changed, redraw the window title */
8047 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008048 {
8049 redraw_titles();
8050 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008051 /* when 'fixeol' is changed, redraw the window title */
8052 else if ((int *)varp == &curbuf->b_p_fixeol)
8053 {
8054 redraw_titles();
8055 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008056# ifdef FEAT_MBYTE
8057 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008058 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008059 {
8060 redraw_titles();
8061 }
8062# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008063#endif
8064
8065 /* when 'bin' is set also set some other options */
8066 else if ((int *)varp == &curbuf->b_p_bin)
8067 {
8068 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8069#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008070 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008071#endif
8072 }
8073
8074#ifdef FEAT_AUTOCMD
8075 /* when 'buflisted' changes, trigger autocommands */
8076 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8077 {
8078 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8079 NULL, NULL, TRUE, curbuf);
8080 }
8081#endif
8082
8083 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8084 else if ((int *)varp == &curbuf->b_p_swf)
8085 {
8086 if (curbuf->b_p_swf && p_uc)
8087 ml_open_file(curbuf); /* create the swap file */
8088 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008089 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8090 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 mf_close_file(curbuf, TRUE); /* remove the swap file */
8092 }
8093
8094 /* when 'terse' is set change 'shortmess' */
8095 else if ((int *)varp == &p_terse)
8096 {
8097 char_u *p;
8098
8099 p = vim_strchr(p_shm, SHM_SEARCH);
8100
8101 /* insert 's' in p_shm */
8102 if (p_terse && p == NULL)
8103 {
8104 STRCPY(IObuff, p_shm);
8105 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008106 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008107 }
8108 /* remove 's' from p_shm */
8109 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008110 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008111 }
8112
8113 /* when 'paste' is set or reset also change other options */
8114 else if ((int *)varp == &p_paste)
8115 {
8116 paste_option_changed();
8117 }
8118
8119 /* when 'insertmode' is set from an autocommand need to do work here */
8120 else if ((int *)varp == &p_im)
8121 {
8122 if (p_im)
8123 {
8124 if ((State & INSERT) == 0)
8125 need_start_insertmode = TRUE;
8126 stop_insert_mode = FALSE;
8127 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008128 /* only reset if it was set previously */
8129 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008130 {
8131 need_start_insertmode = FALSE;
8132 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008133 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008134 clear_cmdline = TRUE; /* remove "(insert)" */
8135 restart_edit = 0;
8136 }
8137 }
8138
8139 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8140 else if ((int *)varp == &p_ic && p_hls)
8141 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008142 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 }
8144
8145#ifdef FEAT_SEARCH_EXTRA
8146 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8147 else if ((int *)varp == &p_hls)
8148 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008149 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 }
8151#endif
8152
8153#ifdef FEAT_SCROLLBIND
8154 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8155 * at the end of normal_cmd() */
8156 else if ((int *)varp == &curwin->w_p_scb)
8157 {
8158 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008159 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008161 curwin->w_scbind_pos = curwin->w_topline;
8162 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 }
8164#endif
8165
8166#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8167 /* There can be only one window with 'previewwindow' set. */
8168 else if ((int *)varp == &curwin->w_p_pvw)
8169 {
8170 if (curwin->w_p_pvw)
8171 {
8172 win_T *win;
8173
Bram Moolenaar29323592016-07-24 22:04:11 +02008174 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175 if (win->w_p_pvw && win != curwin)
8176 {
8177 curwin->w_p_pvw = FALSE;
8178 return (char_u *)N_("E590: A preview window already exists");
8179 }
8180 }
8181 }
8182#endif
8183
8184 /* when 'textmode' is set or reset also change 'fileformat' */
8185 else if ((int *)varp == &curbuf->b_p_tx)
8186 {
8187 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8188 }
8189
8190 /* when 'textauto' is set or reset also change 'fileformats' */
8191 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192 set_string_option_direct((char_u *)"ffs", -1,
8193 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008194 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195
8196 /*
8197 * When 'lisp' option changes include/exclude '-' in
8198 * keyword characters.
8199 */
8200#ifdef FEAT_LISP
8201 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8202 {
8203 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8204 }
8205#endif
8206
8207#ifdef FEAT_TITLE
8208 /* when 'title' changed, may need to change the title; same for 'icon' */
8209 else if ((int *)varp == &p_title)
8210 {
8211 did_set_title(FALSE);
8212 }
8213
8214 else if ((int *)varp == &p_icon)
8215 {
8216 did_set_title(TRUE);
8217 }
8218#endif
8219
8220 else if ((int *)varp == &curbuf->b_changed)
8221 {
8222 if (!value)
8223 save_file_ff(curbuf); /* Buffer is unchanged */
8224#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008225 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008226#endif
8227#ifdef FEAT_AUTOCMD
8228 modified_was_set = value;
8229#endif
8230 }
8231
8232#ifdef BACKSLASH_IN_FILENAME
8233 else if ((int *)varp == &p_ssl)
8234 {
8235 if (p_ssl)
8236 {
8237 psepc = '/';
8238 psepcN = '\\';
8239 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008240 }
8241 else
8242 {
8243 psepc = '\\';
8244 psepcN = '/';
8245 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008246 }
8247
8248 /* need to adjust the file name arguments and buffer names. */
8249 buflist_slash_adjust();
8250 alist_slash_adjust();
8251# ifdef FEAT_EVAL
8252 scriptnames_slash_adjust();
8253# endif
8254 }
8255#endif
8256
8257 /* If 'wrap' is set, set w_leftcol to zero. */
8258 else if ((int *)varp == &curwin->w_p_wrap)
8259 {
8260 if (curwin->w_p_wrap)
8261 curwin->w_leftcol = 0;
8262 }
8263
8264#ifdef FEAT_WINDOWS
8265 else if ((int *)varp == &p_ea)
8266 {
8267 if (p_ea && !old_value)
8268 win_equal(curwin, FALSE, 0);
8269 }
8270#endif
8271
8272 else if ((int *)varp == &p_wiv)
8273 {
8274 /*
8275 * When 'weirdinvert' changed, set/reset 't_xs'.
8276 * Then set 'weirdinvert' according to value of 't_xs'.
8277 */
8278 if (p_wiv && !old_value)
8279 T_XS = (char_u *)"y";
8280 else if (!p_wiv && old_value)
8281 T_XS = empty_option;
8282 p_wiv = (*T_XS != NUL);
8283 }
8284
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008285#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008286 else if ((int *)varp == &p_beval)
8287 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008288 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008290 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008291 gui_mch_disable_beval_area(balloonEval);
8292 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008294
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008295#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008296 else if ((int *)varp == &p_acd)
8297 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008298 /* Change directories when the 'acd' option is set now. */
8299 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300 }
8301#endif
8302
8303#ifdef FEAT_DIFF
8304 /* 'diff' */
8305 else if ((int *)varp == &curwin->w_p_diff)
8306 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008307 /* May add or remove the buffer from the list of diff buffers. */
8308 diff_buf_adjust(curwin);
8309# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008310 if (foldmethodIsDiff(curwin))
8311 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008312# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008313 }
8314#endif
8315
8316#ifdef USE_IM_CONTROL
8317 /* 'imdisable' */
8318 else if ((int *)varp == &p_imdisable)
8319 {
8320 /* Only de-activate it here, it will be enabled when changing mode. */
8321 if (p_imdisable)
8322 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008323 else if (State & INSERT)
8324 /* When the option is set from an autocommand, it may need to take
8325 * effect right away. */
8326 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008327 }
8328#endif
8329
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008330#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008331 /* 'spell' */
8332 else if ((int *)varp == &curwin->w_p_spell)
8333 {
8334 if (curwin->w_p_spell)
8335 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008336 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008337 if (errmsg != NULL)
8338 EMSG(_(errmsg));
8339 }
8340 }
8341#endif
8342
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343#ifdef FEAT_FKMAP
8344 else if ((int *)varp == &p_altkeymap)
8345 {
8346 if (old_value != p_altkeymap)
8347 {
8348 if (!p_altkeymap)
8349 {
8350 p_hkmap = p_fkmap;
8351 p_fkmap = 0;
8352 }
8353 else
8354 {
8355 p_fkmap = p_hkmap;
8356 p_hkmap = 0;
8357 }
8358 (void)init_chartab();
8359 }
8360 }
8361
8362 /*
8363 * In case some second language keymapping options have changed, check
8364 * and correct the setting in a consistent way.
8365 */
8366
8367 /*
8368 * If hkmap or fkmap are set, reset Arabic keymapping.
8369 */
8370 if ((p_hkmap || p_fkmap) && p_altkeymap)
8371 {
8372 p_altkeymap = p_fkmap;
8373# ifdef FEAT_ARABIC
8374 curwin->w_p_arab = FALSE;
8375# endif
8376 (void)init_chartab();
8377 }
8378
8379 /*
8380 * If hkmap set, reset Farsi keymapping.
8381 */
8382 if (p_hkmap && p_altkeymap)
8383 {
8384 p_altkeymap = 0;
8385 p_fkmap = 0;
8386# ifdef FEAT_ARABIC
8387 curwin->w_p_arab = FALSE;
8388# endif
8389 (void)init_chartab();
8390 }
8391
8392 /*
8393 * If fkmap set, reset Hebrew keymapping.
8394 */
8395 if (p_fkmap && !p_altkeymap)
8396 {
8397 p_altkeymap = 1;
8398 p_hkmap = 0;
8399# ifdef FEAT_ARABIC
8400 curwin->w_p_arab = FALSE;
8401# endif
8402 (void)init_chartab();
8403 }
8404#endif
8405
8406#ifdef FEAT_ARABIC
8407 if ((int *)varp == &curwin->w_p_arab)
8408 {
8409 if (curwin->w_p_arab)
8410 {
8411 /*
8412 * 'arabic' is set, handle various sub-settings.
8413 */
8414 if (!p_tbidi)
8415 {
8416 /* set rightleft mode */
8417 if (!curwin->w_p_rl)
8418 {
8419 curwin->w_p_rl = TRUE;
8420 changed_window_setting();
8421 }
8422
8423 /* Enable Arabic shaping (major part of what Arabic requires) */
8424 if (!p_arshape)
8425 {
8426 p_arshape = TRUE;
8427 redraw_later_clear();
8428 }
8429 }
8430
8431 /* Arabic requires a utf-8 encoding, inform the user if its not
8432 * set. */
8433 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008434 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008435 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8436
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008437 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008438 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8439#ifdef FEAT_EVAL
8440 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8441#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008442 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443
8444# ifdef FEAT_MBYTE
8445 /* set 'delcombine' */
8446 p_deco = TRUE;
8447# endif
8448
8449# ifdef FEAT_KEYMAP
8450 /* Force-set the necessary keymap for arabic */
8451 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8452 OPT_LOCAL);
8453# endif
8454# ifdef FEAT_FKMAP
8455 p_altkeymap = 0;
8456 p_hkmap = 0;
8457 p_fkmap = 0;
8458 (void)init_chartab();
8459# endif
8460 }
8461 else
8462 {
8463 /*
8464 * 'arabic' is reset, handle various sub-settings.
8465 */
8466 if (!p_tbidi)
8467 {
8468 /* reset rightleft mode */
8469 if (curwin->w_p_rl)
8470 {
8471 curwin->w_p_rl = FALSE;
8472 changed_window_setting();
8473 }
8474
8475 /* 'arabicshape' isn't reset, it is a global option and
8476 * another window may still need it "on". */
8477 }
8478
8479 /* 'delcombine' isn't reset, it is a global option and another
8480 * window may still want it "on". */
8481
8482# ifdef FEAT_KEYMAP
8483 /* Revert to the default keymap */
8484 curbuf->b_p_iminsert = B_IMODE_NONE;
8485 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8486# endif
8487 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008488 }
8489
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008490#endif
8491
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008492#ifdef FEAT_TERMGUICOLORS
8493 /* 'termguicolors' */
8494 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008495 {
8496# ifdef FEAT_GUI
8497 if (!gui.in_use && !gui.starting)
8498# endif
8499 highlight_gui_started();
8500 }
8501#endif
8502
Bram Moolenaar071d4272004-06-13 20:20:40 +00008503 /*
8504 * End of handling side effects for bool options.
8505 */
8506
Bram Moolenaar53744302015-07-17 17:38:22 +02008507 /* after handling side effects, call autocommand */
8508
Bram Moolenaar071d4272004-06-13 20:20:40 +00008509 options[opt_idx].flags |= P_WAS_SET;
8510
Bram Moolenaar53744302015-07-17 17:38:22 +02008511#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8512 if (!starting)
8513 {
8514 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008515 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8516 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8517 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008518 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8519 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8520 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8521 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8522 reset_v_option_vars();
8523 }
8524#endif
8525
Bram Moolenaar071d4272004-06-13 20:20:40 +00008526 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008527 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008528 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008529 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008530 check_redraw(options[opt_idx].flags);
8531
8532 return NULL;
8533}
8534
8535/*
8536 * Set the value of a number option, and take care of side effects.
8537 * Returns NULL for success, or an error message for an error.
8538 */
8539 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008540set_num_option(
8541 int opt_idx, /* index in options[] table */
8542 char_u *varp, /* pointer to the option variable */
8543 long value, /* new value */
8544 char_u *errbuf, /* buffer for error messages */
8545 size_t errbuflen, /* length of "errbuf" */
8546 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008547 OPT_MODELINE */
8548{
8549 char_u *errmsg = NULL;
8550 long old_value = *(long *)varp;
8551 long old_Rows = Rows; /* remember old Rows */
8552 long old_Columns = Columns; /* remember old Columns */
8553 long *pp = (long *)varp;
8554
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008555 /* Disallow changing some options from secure mode. */
8556 if ((secure
8557#ifdef HAVE_SANDBOX
8558 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008560 ) && (options[opt_idx].flags & P_SECURE))
8561 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008562
8563 *pp = value;
8564#ifdef FEAT_EVAL
8565 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008566 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008568#ifdef FEAT_GUI
8569 need_mouse_correct = TRUE;
8570#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008571
Bram Moolenaar14f24742012-08-08 18:01:05 +02008572 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008573 {
8574 errmsg = e_positive;
8575 curbuf->b_p_sw = curbuf->b_p_ts;
8576 }
8577
8578 /*
8579 * Number options that need some action when changed
8580 */
8581#ifdef FEAT_WINDOWS
8582 if (pp == &p_wh || pp == &p_hh)
8583 {
8584 if (p_wh < 1)
8585 {
8586 errmsg = e_positive;
8587 p_wh = 1;
8588 }
8589 if (p_wmh > p_wh)
8590 {
8591 errmsg = e_winheight;
8592 p_wh = p_wmh;
8593 }
8594 if (p_hh < 0)
8595 {
8596 errmsg = e_positive;
8597 p_hh = 0;
8598 }
8599
8600 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008601 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008602 {
8603 if (pp == &p_wh && curwin->w_height < p_wh)
8604 win_setheight((int)p_wh);
8605 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8606 win_setheight((int)p_hh);
8607 }
8608 }
8609
8610 /* 'winminheight' */
8611 else if (pp == &p_wmh)
8612 {
8613 if (p_wmh < 0)
8614 {
8615 errmsg = e_positive;
8616 p_wmh = 0;
8617 }
8618 if (p_wmh > p_wh)
8619 {
8620 errmsg = e_winheight;
8621 p_wmh = p_wh;
8622 }
8623 win_setminheight();
8624 }
8625
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008626# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008627 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 {
8629 if (p_wiw < 1)
8630 {
8631 errmsg = e_positive;
8632 p_wiw = 1;
8633 }
8634 if (p_wmw > p_wiw)
8635 {
8636 errmsg = e_winwidth;
8637 p_wiw = p_wmw;
8638 }
8639
8640 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008641 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 win_setwidth((int)p_wiw);
8643 }
8644
8645 /* 'winminwidth' */
8646 else if (pp == &p_wmw)
8647 {
8648 if (p_wmw < 0)
8649 {
8650 errmsg = e_positive;
8651 p_wmw = 0;
8652 }
8653 if (p_wmw > p_wiw)
8654 {
8655 errmsg = e_winwidth;
8656 p_wmw = p_wiw;
8657 }
8658 win_setminheight();
8659 }
8660# endif
8661
8662#endif
8663
8664#ifdef FEAT_WINDOWS
8665 /* (re)set last window status line */
8666 else if (pp == &p_ls)
8667 {
8668 last_status(FALSE);
8669 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008670
8671 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008672 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008673 {
8674 shell_new_rows(); /* recompute window positions and heights */
8675 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008676#endif
8677
8678#ifdef FEAT_GUI
8679 else if (pp == &p_linespace)
8680 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008681 /* Recompute gui.char_height and resize the Vim window to keep the
8682 * same number of lines. */
8683 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008684 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008685 }
8686#endif
8687
8688#ifdef FEAT_FOLDING
8689 /* 'foldlevel' */
8690 else if (pp == &curwin->w_p_fdl)
8691 {
8692 if (curwin->w_p_fdl < 0)
8693 curwin->w_p_fdl = 0;
8694 newFoldLevel();
8695 }
8696
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008697 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008698 else if (pp == &curwin->w_p_fml)
8699 {
8700 foldUpdateAll(curwin);
8701 }
8702
8703 /* 'foldnestmax' */
8704 else if (pp == &curwin->w_p_fdn)
8705 {
8706 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8707 foldUpdateAll(curwin);
8708 }
8709
8710 /* 'foldcolumn' */
8711 else if (pp == &curwin->w_p_fdc)
8712 {
8713 if (curwin->w_p_fdc < 0)
8714 {
8715 errmsg = e_positive;
8716 curwin->w_p_fdc = 0;
8717 }
8718 else if (curwin->w_p_fdc > 12)
8719 {
8720 errmsg = e_invarg;
8721 curwin->w_p_fdc = 12;
8722 }
8723 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008724#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008725
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008726#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008727 /* 'shiftwidth' or 'tabstop' */
8728 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8729 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008730# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008731 if (foldmethodIsIndent(curwin))
8732 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008733# endif
8734# ifdef FEAT_CINDENT
8735 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8736 * parse 'cinoptions'. */
8737 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8738 parse_cino(curbuf);
8739# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008741#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008743#ifdef FEAT_MBYTE
8744 /* 'maxcombine' */
8745 else if (pp == &p_mco)
8746 {
8747 if (p_mco > MAX_MCO)
8748 p_mco = MAX_MCO;
8749 else if (p_mco < 0)
8750 p_mco = 0;
8751 screenclear(); /* will re-allocate the screen */
8752 }
8753#endif
8754
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755 else if (pp == &curbuf->b_p_iminsert)
8756 {
8757 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8758 {
8759 errmsg = e_invarg;
8760 curbuf->b_p_iminsert = B_IMODE_NONE;
8761 }
8762 p_iminsert = curbuf->b_p_iminsert;
8763 if (termcap_active) /* don't do this in the alternate screen */
8764 showmode();
8765#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8766 /* Show/unshow value of 'keymap' in status lines. */
8767 status_redraw_curbuf();
8768#endif
8769 }
8770
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008771 else if (pp == &p_window)
8772 {
8773 if (p_window < 1)
8774 p_window = 1;
8775 else if (p_window >= Rows)
8776 p_window = Rows - 1;
8777 }
8778
Bram Moolenaar071d4272004-06-13 20:20:40 +00008779 else if (pp == &curbuf->b_p_imsearch)
8780 {
8781 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8782 {
8783 errmsg = e_invarg;
8784 curbuf->b_p_imsearch = B_IMODE_NONE;
8785 }
8786 p_imsearch = curbuf->b_p_imsearch;
8787 }
8788
8789#ifdef FEAT_TITLE
8790 /* if 'titlelen' has changed, redraw the title */
8791 else if (pp == &p_titlelen)
8792 {
8793 if (p_titlelen < 0)
8794 {
8795 errmsg = e_positive;
8796 p_titlelen = 85;
8797 }
8798 if (starting != NO_SCREEN && old_value != p_titlelen)
8799 need_maketitle = TRUE;
8800 }
8801#endif
8802
8803 /* if p_ch changed value, change the command line height */
8804 else if (pp == &p_ch)
8805 {
8806 if (p_ch < 1)
8807 {
8808 errmsg = e_positive;
8809 p_ch = 1;
8810 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008811 if (p_ch > Rows - min_rows() + 1)
8812 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008813
8814 /* Only compute the new window layout when startup has been
8815 * completed. Otherwise the frame sizes may be wrong. */
8816 if (p_ch != old_value && full_screen
8817#ifdef FEAT_GUI
8818 && !gui.starting
8819#endif
8820 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008821 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822 }
8823
8824 /* when 'updatecount' changes from zero to non-zero, open swap files */
8825 else if (pp == &p_uc)
8826 {
8827 if (p_uc < 0)
8828 {
8829 errmsg = e_positive;
8830 p_uc = 100;
8831 }
8832 if (p_uc && !old_value)
8833 ml_open_files();
8834 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008835#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008836 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008837 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008838 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008839 {
8840 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008841 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008842 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008843 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008844 {
8845 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008846 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008847 }
8848 }
8849#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008850#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008851 else if (pp == &p_mzq)
8852 mzvim_reset_timer();
8853#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008854
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008855#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8856 /* 'pyxversion' */
8857 else if (pp == &p_pyx)
8858 {
8859 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8860 errmsg = e_invarg;
8861 }
8862#endif
8863
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864 /* sync undo before 'undolevels' changes */
8865 else if (pp == &p_ul)
8866 {
8867 /* use the old value, otherwise u_sync() may not work properly */
8868 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008869 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008870 p_ul = value;
8871 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008872 else if (pp == &curbuf->b_p_ul)
8873 {
8874 /* use the old value, otherwise u_sync() may not work properly */
8875 curbuf->b_p_ul = old_value;
8876 u_sync(TRUE);
8877 curbuf->b_p_ul = value;
8878 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008879
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008880#ifdef FEAT_LINEBREAK
8881 /* 'numberwidth' must be positive */
8882 else if (pp == &curwin->w_p_nuw)
8883 {
8884 if (curwin->w_p_nuw < 1)
8885 {
8886 errmsg = e_positive;
8887 curwin->w_p_nuw = 1;
8888 }
8889 if (curwin->w_p_nuw > 10)
8890 {
8891 errmsg = e_invarg;
8892 curwin->w_p_nuw = 10;
8893 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008894 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008895 }
8896#endif
8897
Bram Moolenaar1a384422010-07-14 19:53:30 +02008898 else if (pp == &curbuf->b_p_tw)
8899 {
8900 if (curbuf->b_p_tw < 0)
8901 {
8902 errmsg = e_positive;
8903 curbuf->b_p_tw = 0;
8904 }
8905#ifdef FEAT_SYN_HL
8906# ifdef FEAT_WINDOWS
8907 {
8908 win_T *wp;
8909 tabpage_T *tp;
8910
8911 FOR_ALL_TAB_WINDOWS(tp, wp)
8912 check_colorcolumn(wp);
8913 }
8914# else
8915 check_colorcolumn(curwin);
8916# endif
8917#endif
8918 }
8919
Bram Moolenaar071d4272004-06-13 20:20:40 +00008920 /*
8921 * Check the bounds for numeric options here
8922 */
8923 if (Rows < min_rows() && full_screen)
8924 {
8925 if (errbuf != NULL)
8926 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008927 vim_snprintf((char *)errbuf, errbuflen,
8928 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929 errmsg = errbuf;
8930 }
8931 Rows = min_rows();
8932 }
8933 if (Columns < MIN_COLUMNS && full_screen)
8934 {
8935 if (errbuf != NULL)
8936 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008937 vim_snprintf((char *)errbuf, errbuflen,
8938 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 errmsg = errbuf;
8940 }
8941 Columns = MIN_COLUMNS;
8942 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008943 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945 /*
8946 * If the screen (shell) height has been changed, assume it is the
8947 * physical screenheight.
8948 */
8949 if (old_Rows != Rows || old_Columns != Columns)
8950 {
8951 /* Changing the screen size is not allowed while updating the screen. */
8952 if (updating_screen)
8953 *pp = old_value;
8954 else if (full_screen
8955#ifdef FEAT_GUI
8956 && !gui.starting
8957#endif
8958 )
8959 set_shellsize((int)Columns, (int)Rows, TRUE);
8960 else
8961 {
8962 /* Postpone the resizing; check the size and cmdline position for
8963 * messages. */
8964 check_shellsize();
8965 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8966 cmdline_row = Rows - p_ch;
8967 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008968 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008969 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970 }
8971
Bram Moolenaar071d4272004-06-13 20:20:40 +00008972 if (curbuf->b_p_ts <= 0)
8973 {
8974 errmsg = e_positive;
8975 curbuf->b_p_ts = 8;
8976 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008977 if (p_tm < 0)
8978 {
8979 errmsg = e_positive;
8980 p_tm = 0;
8981 }
8982 if ((curwin->w_p_scr <= 0
8983 || (curwin->w_p_scr > curwin->w_height
8984 && curwin->w_height > 0))
8985 && full_screen)
8986 {
8987 if (pp == &(curwin->w_p_scr))
8988 {
8989 if (curwin->w_p_scr != 0)
8990 errmsg = e_scroll;
8991 win_comp_scroll(curwin);
8992 }
8993 /* If 'scroll' became invalid because of a side effect silently adjust
8994 * it. */
8995 else if (curwin->w_p_scr <= 0)
8996 curwin->w_p_scr = 1;
8997 else /* curwin->w_p_scr > curwin->w_height */
8998 curwin->w_p_scr = curwin->w_height;
8999 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009000 if (p_hi < 0)
9001 {
9002 errmsg = e_positive;
9003 p_hi = 0;
9004 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009005 else if (p_hi > 10000)
9006 {
9007 errmsg = e_invarg;
9008 p_hi = 10000;
9009 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009010 if (p_re < 0 || p_re > 2)
9011 {
9012 errmsg = e_invarg;
9013 p_re = 0;
9014 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009015 if (p_report < 0)
9016 {
9017 errmsg = e_positive;
9018 p_report = 1;
9019 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009020 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009021 {
9022 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9023 p_sj = Rows / 2;
9024 else
9025 {
9026 errmsg = e_scroll;
9027 p_sj = 1;
9028 }
9029 }
9030 if (p_so < 0 && full_screen)
9031 {
9032 errmsg = e_scroll;
9033 p_so = 0;
9034 }
9035 if (p_siso < 0 && full_screen)
9036 {
9037 errmsg = e_positive;
9038 p_siso = 0;
9039 }
9040#ifdef FEAT_CMDWIN
9041 if (p_cwh < 1)
9042 {
9043 errmsg = e_positive;
9044 p_cwh = 1;
9045 }
9046#endif
9047 if (p_ut < 0)
9048 {
9049 errmsg = e_positive;
9050 p_ut = 2000;
9051 }
9052 if (p_ss < 0)
9053 {
9054 errmsg = e_positive;
9055 p_ss = 0;
9056 }
9057
9058 /* May set global value for local option. */
9059 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9060 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9061
9062 options[opt_idx].flags |= P_WAS_SET;
9063
Bram Moolenaar53744302015-07-17 17:38:22 +02009064#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9065 if (!starting && errmsg == NULL)
9066 {
9067 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009068 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9069 vim_snprintf((char *)buf_new, 10, "%ld", value);
9070 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009071 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9072 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9073 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9074 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9075 reset_v_option_vars();
9076 }
9077#endif
9078
Bram Moolenaar071d4272004-06-13 20:20:40 +00009079 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009080 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009081 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009082 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083 check_redraw(options[opt_idx].flags);
9084
9085 return errmsg;
9086}
9087
9088/*
9089 * Called after an option changed: check if something needs to be redrawn.
9090 */
9091 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009092check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009093{
9094 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009095 int doclear = (flags & P_RCLR) == P_RCLR;
9096 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009097
9098#ifdef FEAT_WINDOWS
9099 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9100 status_redraw_all();
9101#endif
9102
9103 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9104 changed_window_setting();
9105 if (flags & P_RBUF)
9106 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009107 if (flags & P_RWINONLY)
9108 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009109 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009110 redraw_all_later(CLEAR);
9111 else if (all)
9112 redraw_all_later(NOT_VALID);
9113}
9114
9115/*
9116 * Find index for option 'arg'.
9117 * Return -1 if not found.
9118 */
9119 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009120findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121{
9122 int opt_idx;
9123 char *s, *p;
9124 static short quick_tab[27] = {0, 0}; /* quick access table */
9125 int is_term_opt;
9126
9127 /*
9128 * For first call: Initialize the quick-access table.
9129 * It contains the index for the first option that starts with a certain
9130 * letter. There are 26 letters, plus the first "t_" option.
9131 */
9132 if (quick_tab[1] == 0)
9133 {
9134 p = options[0].fullname;
9135 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9136 {
9137 if (s[0] != p[0])
9138 {
9139 if (s[0] == 't' && s[1] == '_')
9140 quick_tab[26] = opt_idx;
9141 else
9142 quick_tab[CharOrdLow(s[0])] = opt_idx;
9143 }
9144 p = s;
9145 }
9146 }
9147
9148 /*
9149 * Check for name starting with an illegal character.
9150 */
9151#ifdef EBCDIC
9152 if (!islower(arg[0]))
9153#else
9154 if (arg[0] < 'a' || arg[0] > 'z')
9155#endif
9156 return -1;
9157
9158 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9159 if (is_term_opt)
9160 opt_idx = quick_tab[26];
9161 else
9162 opt_idx = quick_tab[CharOrdLow(arg[0])];
9163 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9164 {
9165 if (STRCMP(arg, s) == 0) /* match full name */
9166 break;
9167 }
9168 if (s == NULL && !is_term_opt)
9169 {
9170 opt_idx = quick_tab[CharOrdLow(arg[0])];
9171 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9172 {
9173 s = options[opt_idx].shortname;
9174 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9175 break;
9176 s = NULL;
9177 }
9178 }
9179 if (s == NULL)
9180 opt_idx = -1;
9181 return opt_idx;
9182}
9183
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009184#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009185/*
9186 * Get the value for an option.
9187 *
9188 * Returns:
9189 * Number or Toggle option: 1, *numval gets value.
9190 * String option: 0, *stringval gets allocated string.
9191 * Hidden Number or Toggle option: -1.
9192 * hidden String option: -2.
9193 * unknown option: -3.
9194 */
9195 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009196get_option_value(
9197 char_u *name,
9198 long *numval,
9199 char_u **stringval, /* NULL when only checking existence */
9200 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009201{
9202 int opt_idx;
9203 char_u *varp;
9204
9205 opt_idx = findoption(name);
9206 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009207 {
9208 int key;
9209
9210 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9211 && (key = find_key_option(name)) != 0)
9212 {
9213 char_u key_name[2];
9214 char_u *p;
9215
9216 if (key < 0)
9217 {
9218 key_name[0] = KEY2TERMCAP0(key);
9219 key_name[1] = KEY2TERMCAP1(key);
9220 }
9221 else
9222 {
9223 key_name[0] = KS_KEY;
9224 key_name[1] = (key & 0xff);
9225 }
9226 p = find_termcode(key_name);
9227 if (p != NULL)
9228 {
9229 if (stringval != NULL)
9230 *stringval = vim_strsave(p);
9231 return 0;
9232 }
9233 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009234 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009236
9237 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9238
9239 if (options[opt_idx].flags & P_STRING)
9240 {
9241 if (varp == NULL) /* hidden option */
9242 return -2;
9243 if (stringval != NULL)
9244 {
9245#ifdef FEAT_CRYPT
9246 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009247 if ((char_u **)varp == &curbuf->b_p_key
9248 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249 *stringval = vim_strsave((char_u *)"*****");
9250 else
9251#endif
9252 *stringval = vim_strsave(*(char_u **)(varp));
9253 }
9254 return 0;
9255 }
9256
9257 if (varp == NULL) /* hidden option */
9258 return -1;
9259 if (options[opt_idx].flags & P_NUM)
9260 *numval = *(long *)varp;
9261 else
9262 {
9263 /* Special case: 'modified' is b_changed, but we also want to consider
9264 * it set when 'ff' or 'fenc' changed. */
9265 if ((int *)varp == &curbuf->b_changed)
9266 *numval = curbufIsChanged();
9267 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009268 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009269 }
9270 return 1;
9271}
9272#endif
9273
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009274#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009275/*
9276 * Returns the option attributes and its value. Unlike the above function it
9277 * will return either global value or local value of the option depending on
9278 * what was requested, but it will never return global value if it was
9279 * requested to return local one and vice versa. Neither it will return
9280 * buffer-local value if it was requested to return window-local one.
9281 *
9282 * Pretends that option is absent if it is not present in the requested scope
9283 * (i.e. has no global, window-local or buffer-local value depending on
9284 * opt_type). Uses
9285 *
9286 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009287 * 0 hidden or unknown option, also option that does not have requested
9288 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009289 * see SOPT_* in vim.h for other flags
9290 *
9291 * Possible opt_type values: see SREQ_* in vim.h
9292 */
9293 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009294get_option_value_strict(
9295 char_u *name,
9296 long *numval,
9297 char_u **stringval, /* NULL when only obtaining attributes */
9298 int opt_type,
9299 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009300{
9301 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009302 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009303 struct vimoption *p;
9304 int r = 0;
9305
9306 opt_idx = findoption(name);
9307 if (opt_idx < 0)
9308 return 0;
9309
9310 p = &(options[opt_idx]);
9311
9312 /* Hidden option */
9313 if (p->var == NULL)
9314 return 0;
9315
9316 if (p->flags & P_BOOL)
9317 r |= SOPT_BOOL;
9318 else if (p->flags & P_NUM)
9319 r |= SOPT_NUM;
9320 else if (p->flags & P_STRING)
9321 r |= SOPT_STRING;
9322
9323 if (p->indir == PV_NONE)
9324 {
9325 if (opt_type == SREQ_GLOBAL)
9326 r |= SOPT_GLOBAL;
9327 else
9328 return 0; /* Did not request global-only option */
9329 }
9330 else
9331 {
9332 if (p->indir & PV_BOTH)
9333 r |= SOPT_GLOBAL;
9334 else if (opt_type == SREQ_GLOBAL)
9335 return 0; /* Requested global option */
9336
9337 if (p->indir & PV_WIN)
9338 {
9339 if (opt_type == SREQ_BUF)
9340 return 0; /* Did not request window-local option */
9341 else
9342 r |= SOPT_WIN;
9343 }
9344 else if (p->indir & PV_BUF)
9345 {
9346 if (opt_type == SREQ_WIN)
9347 return 0; /* Did not request buffer-local option */
9348 else
9349 r |= SOPT_BUF;
9350 }
9351 }
9352
9353 if (stringval == NULL)
9354 return r;
9355
9356 if (opt_type == SREQ_GLOBAL)
9357 varp = p->var;
9358 else
9359 {
9360 if (opt_type == SREQ_BUF)
9361 {
9362 /* Special case: 'modified' is b_changed, but we also want to
9363 * consider it set when 'ff' or 'fenc' changed. */
9364 if (p->indir == PV_MOD)
9365 {
9366 *numval = bufIsChanged((buf_T *) from);
9367 varp = NULL;
9368 }
9369#ifdef FEAT_CRYPT
9370 else if (p->indir == PV_KEY)
9371 {
9372 /* never return the value of the crypt key */
9373 *stringval = NULL;
9374 varp = NULL;
9375 }
9376#endif
9377 else
9378 {
9379 aco_save_T aco;
9380 aucmd_prepbuf(&aco, (buf_T *) from);
9381 varp = get_varp(p);
9382 aucmd_restbuf(&aco);
9383 }
9384 }
9385 else if (opt_type == SREQ_WIN)
9386 {
9387 win_T *save_curwin;
9388 save_curwin = curwin;
9389 curwin = (win_T *) from;
9390 curbuf = curwin->w_buffer;
9391 varp = get_varp(p);
9392 curwin = save_curwin;
9393 curbuf = curwin->w_buffer;
9394 }
9395 if (varp == p->var)
9396 return (r | SOPT_UNSET);
9397 }
9398
9399 if (varp != NULL)
9400 {
9401 if (p->flags & P_STRING)
9402 *stringval = vim_strsave(*(char_u **)(varp));
9403 else if (p->flags & P_NUM)
9404 *numval = *(long *) varp;
9405 else
9406 *numval = *(int *)varp;
9407 }
9408
9409 return r;
9410}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009411
9412/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009413 * Iterate over options. First argument is a pointer to a pointer to a
9414 * structure inside options[] array, second is option type like in the above
9415 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009416 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009417 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009418 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009419 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009420 * first argument to NULL.
9421 *
9422 * Returns full option name for current option on each call.
9423 */
9424 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009425option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009426{
9427 struct vimoption *ret = NULL;
9428 do
9429 {
9430 if (*option == NULL)
9431 *option = (void *) options;
9432 else if (((struct vimoption *) (*option))->fullname == NULL)
9433 {
9434 *option = NULL;
9435 return NULL;
9436 }
9437 else
9438 *option = (void *) (((struct vimoption *) (*option)) + 1);
9439
9440 ret = ((struct vimoption *) (*option));
9441
9442 /* Hidden option */
9443 if (ret->var == NULL)
9444 {
9445 ret = NULL;
9446 continue;
9447 }
9448
9449 switch (opt_type)
9450 {
9451 case SREQ_GLOBAL:
9452 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9453 ret = NULL;
9454 break;
9455 case SREQ_BUF:
9456 if (!(ret->indir & PV_BUF))
9457 ret = NULL;
9458 break;
9459 case SREQ_WIN:
9460 if (!(ret->indir & PV_WIN))
9461 ret = NULL;
9462 break;
9463 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009464 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009465 return NULL;
9466 }
9467 }
9468 while (ret == NULL);
9469
9470 return (char_u *)ret->fullname;
9471}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009472#endif
9473
Bram Moolenaar071d4272004-06-13 20:20:40 +00009474/*
9475 * Set the value of option "name".
9476 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009477 *
9478 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009479 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009480 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009481set_option_value(
9482 char_u *name,
9483 long number,
9484 char_u *string,
9485 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009486{
9487 int opt_idx;
9488 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009489 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009490
9491 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009492 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009493 {
9494 int key;
9495
9496 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9497 && (key = find_key_option(name)) != 0)
9498 {
9499 char_u key_name[2];
9500
9501 if (key < 0)
9502 {
9503 key_name[0] = KEY2TERMCAP0(key);
9504 key_name[1] = KEY2TERMCAP1(key);
9505 }
9506 else
9507 {
9508 key_name[0] = KS_KEY;
9509 key_name[1] = (key & 0xff);
9510 }
9511 add_termcode(key_name, string, FALSE);
9512 if (full_screen)
9513 ttest(FALSE);
9514 redraw_all_later(CLEAR);
9515 return NULL;
9516 }
9517
Bram Moolenaar071d4272004-06-13 20:20:40 +00009518 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009519 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009520 else
9521 {
9522 flags = options[opt_idx].flags;
9523#ifdef HAVE_SANDBOX
9524 /* Disallow changing some options in the sandbox */
9525 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009526 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009527 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009528 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009530#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009531 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009532 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009533 else
9534 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009535 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009536 if (varp != NULL) /* hidden option is not changed */
9537 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009538 if (number == 0 && string != NULL)
9539 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009540 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009541
9542 /* Either we are given a string or we are setting option
9543 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009544 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009545 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009546 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009547 {
9548 /* There's another character after zeros or the string
9549 * is empty. In both cases, we are trying to set a
9550 * num option using a string. */
9551 EMSG3(_("E521: Number required: &%s = '%s'"),
9552 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009553 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009554
9555 }
9556 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009557 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009558 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009559 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009560 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009561 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009562 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009563 }
9564 }
9565 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009566 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567}
9568
9569/*
9570 * Get the terminal code for a terminal option.
9571 * Returns NULL when not found.
9572 */
9573 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009574get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009575{
9576 int opt_idx;
9577 char_u *varp;
9578
9579 if (tname[0] != 't' || tname[1] != '_' ||
9580 tname[2] == NUL || tname[3] == NUL)
9581 return NULL;
9582 if ((opt_idx = findoption(tname)) >= 0)
9583 {
9584 varp = get_varp(&(options[opt_idx]));
9585 if (varp != NULL)
9586 varp = *(char_u **)(varp);
9587 return varp;
9588 }
9589 return find_termcode(tname + 2);
9590}
9591
9592 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009593get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009594{
9595 int i;
9596
9597 i = findoption((char_u *)"hl");
9598 if (i >= 0)
9599 return options[i].def_val[VI_DEFAULT];
9600 return (char_u *)NULL;
9601}
9602
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009603#if defined(FEAT_MBYTE) || defined(PROTO)
9604 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009605get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009606{
9607 int i;
9608
9609 i = findoption((char_u *)"enc");
9610 if (i >= 0)
9611 return options[i].def_val[VI_DEFAULT];
9612 return (char_u *)NULL;
9613}
9614#endif
9615
Bram Moolenaar071d4272004-06-13 20:20:40 +00009616/*
9617 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9618 */
9619 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009620find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009621{
9622 int key;
9623 int modifiers;
9624
9625 /*
9626 * Don't use get_special_key_code() for t_xx, we don't want it to call
9627 * add_termcap_entry().
9628 */
9629 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9630 key = TERMCAP2KEY(arg[2], arg[3]);
9631 else
9632 {
9633 --arg; /* put arg at the '<' */
9634 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009635 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009636 if (modifiers) /* can't handle modifiers here */
9637 key = 0;
9638 }
9639 return key;
9640}
9641
9642/*
9643 * if 'all' == 0: show changed options
9644 * if 'all' == 1: show all normal options
9645 * if 'all' == 2: show all terminal options
9646 */
9647 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009648showoptions(
9649 int all,
9650 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651{
9652 struct vimoption *p;
9653 int col;
9654 int isterm;
9655 char_u *varp;
9656 struct vimoption **items;
9657 int item_count;
9658 int run;
9659 int row, rows;
9660 int cols;
9661 int i;
9662 int len;
9663
9664#define INC 20
9665#define GAP 3
9666
9667 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9668 PARAM_COUNT));
9669 if (items == NULL)
9670 return;
9671
9672 /* Highlight title */
9673 if (all == 2)
9674 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9675 else if (opt_flags & OPT_GLOBAL)
9676 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9677 else if (opt_flags & OPT_LOCAL)
9678 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9679 else
9680 MSG_PUTS_TITLE(_("\n--- Options ---"));
9681
9682 /*
9683 * do the loop two times:
9684 * 1. display the short items
9685 * 2. display the long items (only strings and numbers)
9686 */
9687 for (run = 1; run <= 2 && !got_int; ++run)
9688 {
9689 /*
9690 * collect the items in items[]
9691 */
9692 item_count = 0;
9693 for (p = &options[0]; p->fullname != NULL; p++)
9694 {
9695 varp = NULL;
9696 isterm = istermoption(p);
9697 if (opt_flags != 0)
9698 {
9699 if (p->indir != PV_NONE && !isterm)
9700 varp = get_varp_scope(p, opt_flags);
9701 }
9702 else
9703 varp = get_varp(p);
9704 if (varp != NULL
9705 && ((all == 2 && isterm)
9706 || (all == 1 && !isterm)
9707 || (all == 0 && !optval_default(p, varp))))
9708 {
9709 if (p->flags & P_BOOL)
9710 len = 1; /* a toggle option fits always */
9711 else
9712 {
9713 option_value2string(p, opt_flags);
9714 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9715 }
9716 if ((len <= INC - GAP && run == 1) ||
9717 (len > INC - GAP && run == 2))
9718 items[item_count++] = p;
9719 }
9720 }
9721
9722 /*
9723 * display the items
9724 */
9725 if (run == 1)
9726 {
9727 cols = (Columns + GAP - 3) / INC;
9728 if (cols == 0)
9729 cols = 1;
9730 rows = (item_count + cols - 1) / cols;
9731 }
9732 else /* run == 2 */
9733 rows = item_count;
9734 for (row = 0; row < rows && !got_int; ++row)
9735 {
9736 msg_putchar('\n'); /* go to next line */
9737 if (got_int) /* 'q' typed in more */
9738 break;
9739 col = 0;
9740 for (i = row; i < item_count; i += rows)
9741 {
9742 msg_col = col; /* make columns */
9743 showoneopt(items[i], opt_flags);
9744 col += INC;
9745 }
9746 out_flush();
9747 ui_breakcheck();
9748 }
9749 }
9750 vim_free(items);
9751}
9752
9753/*
9754 * Return TRUE if option "p" has its default value.
9755 */
9756 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009757optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009758{
9759 int dvi;
9760
9761 if (varp == NULL)
9762 return TRUE; /* hidden option is always at default */
9763 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9764 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009765 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009766 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009767 /* the cast to long is required for Manx C, long_i is
9768 * needed for MSVC */
9769 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009770 /* P_STRING */
9771 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9772}
9773
9774/*
9775 * showoneopt: show the value of one option
9776 * must not be called with a hidden option!
9777 */
9778 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009779showoneopt(
9780 struct vimoption *p,
9781 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009782{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009783 char_u *varp;
9784 int save_silent = silent_mode;
9785
9786 silent_mode = FALSE;
9787 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009788
9789 varp = get_varp_scope(p, opt_flags);
9790
9791 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9792 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9793 ? !curbufIsChanged() : !*(int *)varp))
9794 MSG_PUTS("no");
9795 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9796 MSG_PUTS("--");
9797 else
9798 MSG_PUTS(" ");
9799 MSG_PUTS(p->fullname);
9800 if (!(p->flags & P_BOOL))
9801 {
9802 msg_putchar('=');
9803 /* put value string in NameBuff */
9804 option_value2string(p, opt_flags);
9805 msg_outtrans(NameBuff);
9806 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009807
9808 silent_mode = save_silent;
9809 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009810}
9811
9812/*
9813 * Write modified options as ":set" commands to a file.
9814 *
9815 * There are three values for "opt_flags":
9816 * OPT_GLOBAL: Write global option values and fresh values of
9817 * buffer-local options (used for start of a session
9818 * file).
9819 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9820 * curwin (used for a vimrc file).
9821 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9822 * and local values for window-local options of
9823 * curwin. Local values are also written when at the
9824 * default value, because a modeline or autocommand
9825 * may have set them when doing ":edit file" and the
9826 * user has set them back at the default or fresh
9827 * value.
9828 * When "local_only" is TRUE, don't write fresh
9829 * values, only local values (for ":mkview").
9830 * (fresh value = value used for a new buffer or window for a local option).
9831 *
9832 * Return FAIL on error, OK otherwise.
9833 */
9834 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009835makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009836{
9837 struct vimoption *p;
9838 char_u *varp; /* currently used value */
9839 char_u *varp_fresh; /* local value */
9840 char_u *varp_local = NULL; /* fresh value */
9841 char *cmd;
9842 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009843 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009844
9845 /*
9846 * The options that don't have a default (terminal name, columns, lines)
9847 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009848 * Do the loop over "options[]" twice: once for options with the
9849 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009850 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009851 for (pri = 1; pri >= 0; --pri)
9852 {
9853 for (p = &options[0]; !istermoption(p); p++)
9854 if (!(p->flags & P_NO_MKRC)
9855 && !istermoption(p)
9856 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009857 {
9858 /* skip global option when only doing locals */
9859 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9860 continue;
9861
9862 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9863 * file, they are always buffer-specific. */
9864 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9865 continue;
9866
9867 /* Global values are only written when not at the default value. */
9868 varp = get_varp_scope(p, opt_flags);
9869 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9870 continue;
9871
9872 round = 2;
9873 if (p->indir != PV_NONE)
9874 {
9875 if (p->var == VAR_WIN)
9876 {
9877 /* skip window-local option when only doing globals */
9878 if (!(opt_flags & OPT_LOCAL))
9879 continue;
9880 /* When fresh value of window-local option is not at the
9881 * default, need to write it too. */
9882 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9883 {
9884 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9885 if (!optval_default(p, varp_fresh))
9886 {
9887 round = 1;
9888 varp_local = varp;
9889 varp = varp_fresh;
9890 }
9891 }
9892 }
9893 }
9894
9895 /* Round 1: fresh value for window-local options.
9896 * Round 2: other values */
9897 for ( ; round <= 2; varp = varp_local, ++round)
9898 {
9899 if (round == 1 || (opt_flags & OPT_GLOBAL))
9900 cmd = "set";
9901 else
9902 cmd = "setlocal";
9903
9904 if (p->flags & P_BOOL)
9905 {
9906 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9907 return FAIL;
9908 }
9909 else if (p->flags & P_NUM)
9910 {
9911 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9912 return FAIL;
9913 }
9914 else /* P_STRING */
9915 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009916#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9917 int do_endif = FALSE;
9918
Bram Moolenaar071d4272004-06-13 20:20:40 +00009919 /* Don't set 'syntax' and 'filetype' again if the value is
9920 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009921 if (
9922# if defined(FEAT_SYN_HL)
9923 p->indir == PV_SYN
9924# if defined(FEAT_AUTOCMD)
9925 ||
9926# endif
9927# endif
9928# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009929 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009930# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009931 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932 {
9933 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9934 *(char_u **)(varp)) < 0
9935 || put_eol(fd) < 0)
9936 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009937 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009938 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009939#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9941 (p->flags & P_EXPAND) != 0) == FAIL)
9942 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009943#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9944 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009945 {
9946 if (put_line(fd, "endif") == FAIL)
9947 return FAIL;
9948 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009949#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950 }
9951 }
9952 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009953 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009954 return OK;
9955}
9956
9957#if defined(FEAT_FOLDING) || defined(PROTO)
9958/*
9959 * Generate set commands for the local fold options only. Used when
9960 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9961 */
9962 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009963makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009964{
9965 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9966# ifdef FEAT_EVAL
9967 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9968 == FAIL
9969# endif
9970 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9971 == FAIL
9972 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9973 == FAIL
9974 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9975 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9976 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9977 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9978 )
9979 return FAIL;
9980
9981 return OK;
9982}
9983#endif
9984
9985 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009986put_setstring(
9987 FILE *fd,
9988 char *cmd,
9989 char *name,
9990 char_u **valuep,
9991 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992{
9993 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009994 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009995
9996 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9997 return FAIL;
9998 if (*valuep != NULL)
9999 {
10000 /* Output 'pastetoggle' as key names. For other
10001 * options some characters have to be escaped with
10002 * CTRL-V or backslash */
10003 if (valuep == &p_pt)
10004 {
10005 s = *valuep;
10006 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010007 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008 return FAIL;
10009 }
10010 else if (expand)
10011 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010012 buf = alloc(MAXPATHL);
10013 if (buf == NULL)
10014 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010015 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10016 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010017 {
10018 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010019 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010020 }
10021 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010022 }
10023 else if (put_escstr(fd, *valuep, 2) == FAIL)
10024 return FAIL;
10025 }
10026 if (put_eol(fd) < 0)
10027 return FAIL;
10028 return OK;
10029}
10030
10031 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010032put_setnum(
10033 FILE *fd,
10034 char *cmd,
10035 char *name,
10036 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010037{
10038 long wc;
10039
10040 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10041 return FAIL;
10042 if (wc_use_keyname((char_u *)valuep, &wc))
10043 {
10044 /* print 'wildchar' and 'wildcharm' as a key name */
10045 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10046 return FAIL;
10047 }
10048 else if (fprintf(fd, "%ld", *valuep) < 0)
10049 return FAIL;
10050 if (put_eol(fd) < 0)
10051 return FAIL;
10052 return OK;
10053}
10054
10055 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010056put_setbool(
10057 FILE *fd,
10058 char *cmd,
10059 char *name,
10060 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010061{
Bram Moolenaar893de922007-10-02 18:40:57 +000010062 if (value < 0) /* global/local option using global value */
10063 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010064 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10065 || put_eol(fd) < 0)
10066 return FAIL;
10067 return OK;
10068}
10069
10070/*
10071 * Clear all the terminal options.
10072 * If the option has been allocated, free the memory.
10073 * Terminal options are never hidden or indirect.
10074 */
10075 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010076clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010077{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010078 /*
10079 * Reset a few things before clearing the old options. This may cause
10080 * outputting a few things that the terminal doesn't understand, but the
10081 * screen will be cleared later, so this is OK.
10082 */
10083#ifdef FEAT_MOUSE_TTY
10084 mch_setmouse(FALSE); /* switch mouse off */
10085#endif
10086#ifdef FEAT_TITLE
10087 mch_restore_title(3); /* restore window titles */
10088#endif
10089#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10090 /* When starting the GUI close the display opened for the clipboard.
10091 * After restoring the title, because that will need the display. */
10092 if (gui.starting)
10093 clear_xterm_clip();
10094#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010095 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010096
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010097 free_termoptions();
10098}
10099
10100 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010101free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010102{
10103 struct vimoption *p;
10104
Bram Moolenaar071d4272004-06-13 20:20:40 +000010105 for (p = &options[0]; p->fullname != NULL; p++)
10106 if (istermoption(p))
10107 {
10108 if (p->flags & P_ALLOCED)
10109 free_string_option(*(char_u **)(p->var));
10110 if (p->flags & P_DEF_ALLOCED)
10111 free_string_option(p->def_val[VI_DEFAULT]);
10112 *(char_u **)(p->var) = empty_option;
10113 p->def_val[VI_DEFAULT] = empty_option;
10114 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10115 }
10116 clear_termcodes();
10117}
10118
10119/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010120 * Free the string for one term option, if it was allocated.
10121 * Set the string to empty_option and clear allocated flag.
10122 * "var" points to the option value.
10123 */
10124 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010125free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010126{
10127 struct vimoption *p;
10128
10129 for (p = &options[0]; p->fullname != NULL; p++)
10130 if (p->var == var)
10131 {
10132 if (p->flags & P_ALLOCED)
10133 free_string_option(*(char_u **)(p->var));
10134 *(char_u **)(p->var) = empty_option;
10135 p->flags &= ~P_ALLOCED;
10136 break;
10137 }
10138}
10139
10140/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141 * Set the terminal option defaults to the current value.
10142 * Used after setting the terminal name.
10143 */
10144 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010145set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146{
10147 struct vimoption *p;
10148
10149 for (p = &options[0]; p->fullname != NULL; p++)
10150 {
10151 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10152 {
10153 if (p->flags & P_DEF_ALLOCED)
10154 {
10155 free_string_option(p->def_val[VI_DEFAULT]);
10156 p->flags &= ~P_DEF_ALLOCED;
10157 }
10158 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10159 if (p->flags & P_ALLOCED)
10160 {
10161 p->flags |= P_DEF_ALLOCED;
10162 p->flags &= ~P_ALLOCED; /* don't free the value now */
10163 }
10164 }
10165 }
10166}
10167
10168/*
10169 * return TRUE if 'p' starts with 't_'
10170 */
10171 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010172istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173{
10174 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10175}
10176
10177/*
10178 * Compute columns for ruler and shown command. 'sc_col' is also used to
10179 * decide what the maximum length of a message on the status line can be.
10180 * If there is a status line for the last window, 'sc_col' is independent
10181 * of 'ru_col'.
10182 */
10183
10184#define COL_RULER 17 /* columns needed by standard ruler */
10185
10186 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010187comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188{
10189#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010190 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191
10192 sc_col = 0;
10193 ru_col = 0;
10194 if (p_ru)
10195 {
10196#ifdef FEAT_STL_OPT
10197 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10198#else
10199 ru_col = COL_RULER + 1;
10200#endif
10201 /* no last status line, adjust sc_col */
10202 if (!last_has_status)
10203 sc_col = ru_col;
10204 }
10205 if (p_sc)
10206 {
10207 sc_col += SHOWCMD_COLS;
10208 if (!p_ru || last_has_status) /* no need for separating space */
10209 ++sc_col;
10210 }
10211 sc_col = Columns - sc_col;
10212 ru_col = Columns - ru_col;
10213 if (sc_col <= 0) /* screen too narrow, will become a mess */
10214 sc_col = 1;
10215 if (ru_col <= 0)
10216 ru_col = 1;
10217#else
10218 sc_col = Columns;
10219 ru_col = Columns;
10220#endif
10221}
10222
10223/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010224 * Unset local option value, similar to ":set opt<".
10225 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010226 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010227unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010228{
10229 struct vimoption *p;
10230 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010231 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010232
10233 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010234 if (opt_idx < 0)
10235 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010236 p = &(options[opt_idx]);
10237
10238 switch ((int)p->indir)
10239 {
10240 /* global option with local value: use local value if it's been set */
10241 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010242 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010243 break;
10244 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010245 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010246 break;
10247 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010248 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010249 break;
10250 case PV_AR:
10251 buf->b_p_ar = -1;
10252 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010253 case PV_BKC:
10254 clear_string_option(&buf->b_p_bkc);
10255 buf->b_bkc_flags = 0;
10256 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010257 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010258 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010259 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010260 case PV_TC:
10261 clear_string_option(&buf->b_p_tc);
10262 buf->b_tc_flags = 0;
10263 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010264#ifdef FEAT_FIND_ID
10265 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010266 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010267 break;
10268 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010269 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010270 break;
10271#endif
10272#ifdef FEAT_INS_EXPAND
10273 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010274 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010275 break;
10276 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010277 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010278 break;
10279#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010280 case PV_FP:
10281 clear_string_option(&buf->b_p_fp);
10282 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010283#ifdef FEAT_QUICKFIX
10284 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010285 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010286 break;
10287 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010288 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010289 break;
10290 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010291 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010292 break;
10293#endif
10294#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10295 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010296 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010297 break;
10298#endif
10299#if defined(FEAT_CRYPT)
10300 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010301 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010302 break;
10303#endif
10304#ifdef FEAT_STL_OPT
10305 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010306 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010307 break;
10308#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010309 case PV_UL:
10310 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10311 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010312#ifdef FEAT_LISP
10313 case PV_LW:
10314 clear_string_option(&buf->b_p_lw);
10315 break;
10316#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010317 }
10318}
10319
10320/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321 * Get pointer to option variable, depending on local or global scope.
10322 */
10323 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010324get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010325{
10326 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10327 {
10328 if (p->var == VAR_WIN)
10329 return (char_u *)GLOBAL_WO(get_varp(p));
10330 return p->var;
10331 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010332 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010333 {
10334 switch ((int)p->indir)
10335 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010336 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010338 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10339 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10340 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010342 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10343 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10344 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010345 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010346 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010347 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010349 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10350 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351#endif
10352#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010353 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10354 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010355#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010356#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10357 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10358#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010359#if defined(FEAT_CRYPT)
10360 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10361#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010362#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010363 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010364#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010365 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010366#ifdef FEAT_LISP
10367 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10368#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010369 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370 }
10371 return NULL; /* "cannot happen" */
10372 }
10373 return get_varp(p);
10374}
10375
10376/*
10377 * Get pointer to option variable.
10378 */
10379 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010380get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010381{
10382 /* hidden option, always return NULL */
10383 if (p->var == NULL)
10384 return NULL;
10385
10386 switch ((int)p->indir)
10387 {
10388 case PV_NONE: return p->var;
10389
10390 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010391 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010392 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010393 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010394 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010395 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010396 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010397 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010399 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010400 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010401 case PV_TC: return *curbuf->b_p_tc != NUL
10402 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010403 case PV_BKC: return *curbuf->b_p_bkc != NUL
10404 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010405#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010406 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010408 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010409 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10410#endif
10411#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010412 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010414 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10416#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010417 case PV_FP: return *curbuf->b_p_fp != NUL
10418 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010419#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010420 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010421 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010422 case PV_GP: return *curbuf->b_p_gp != NUL
10423 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10424 case PV_MP: return *curbuf->b_p_mp != NUL
10425 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010427#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10428 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10429 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10430#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010431#if defined(FEAT_CRYPT)
10432 case PV_CM: return *curbuf->b_p_cm != NUL
10433 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10434#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010435#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010436 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010437 ? (char_u *)&(curwin->w_p_stl) : p->var;
10438#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010439 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10440 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010441#ifdef FEAT_LISP
10442 case PV_LW: return *curbuf->b_p_lw != NUL
10443 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10444#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010445
10446#ifdef FEAT_ARABIC
10447 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10448#endif
10449 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010450#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010451 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10452#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010453#ifdef FEAT_SYN_HL
10454 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10455 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010456 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010457#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010458#ifdef FEAT_DIFF
10459 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10460#endif
10461#ifdef FEAT_FOLDING
10462 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10463 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10464 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10465 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10466 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10467 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10468 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10469# ifdef FEAT_EVAL
10470 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10471 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10472# endif
10473 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10474#endif
10475 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010476 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010477#ifdef FEAT_LINEBREAK
10478 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10479#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010480#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010482 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10483#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10485 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10486#endif
10487#ifdef FEAT_RIGHTLEFT
10488 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10489 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10490#endif
10491 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10492 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10493#ifdef FEAT_LINEBREAK
10494 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010495 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10496 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010497#endif
10498#ifdef FEAT_SCROLLBIND
10499 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10500#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010501#ifdef FEAT_CURSORBIND
10502 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10503#endif
10504#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010505 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10506 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010507#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010508
10509 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10510 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10511#ifdef FEAT_MBYTE
10512 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10513#endif
10514#if defined(FEAT_QUICKFIX)
10515 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10516 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10517#endif
10518 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10519 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10520#ifdef FEAT_CINDENT
10521 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10522 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10523 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10524#endif
10525#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10526 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10527#endif
10528#ifdef FEAT_COMMENTS
10529 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10530#endif
10531#ifdef FEAT_FOLDING
10532 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10533#endif
10534#ifdef FEAT_INS_EXPAND
10535 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10536#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010537#ifdef FEAT_COMPL_FUNC
10538 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010539 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010540#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010541 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010542 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10544#ifdef FEAT_MBYTE
10545 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10546#endif
10547 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10548#ifdef FEAT_AUTOCMD
10549 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10550#endif
10551 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010552 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10554 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10555 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10556 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10557#ifdef FEAT_FIND_ID
10558# ifdef FEAT_EVAL
10559 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10560# endif
10561#endif
10562#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10563 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10564 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10565#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010566#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010567 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10568#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569#ifdef FEAT_CRYPT
10570 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10571#endif
10572#ifdef FEAT_LISP
10573 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10574#endif
10575 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10576 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10577 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10578 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10579 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010581#ifdef FEAT_TEXTOBJ
10582 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10585#ifdef FEAT_SMARTINDENT
10586 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10587#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10590#ifdef FEAT_SEARCHPATH
10591 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10592#endif
10593 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10594#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010595 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010596 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10597#endif
10598#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010599 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10600 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10601 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010602#endif
10603 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10604 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10605 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10606 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010607#ifdef FEAT_PERSISTENT_UNDO
10608 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10609#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10611#ifdef FEAT_KEYMAP
10612 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10613#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010614#ifdef FEAT_SIGNS
10615 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10616#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010617 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618 }
10619 /* always return a valid pointer to avoid a crash! */
10620 return (char_u *)&(curbuf->b_p_wm);
10621}
10622
10623/*
10624 * Get the value of 'equalprg', either the buffer-local one or the global one.
10625 */
10626 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010627get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628{
10629 if (*curbuf->b_p_ep == NUL)
10630 return p_ep;
10631 return curbuf->b_p_ep;
10632}
10633
10634#if defined(FEAT_WINDOWS) || defined(PROTO)
10635/*
10636 * Copy options from one window to another.
10637 * Used when splitting a window.
10638 */
10639 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010640win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010641{
10642 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10643 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10644# ifdef FEAT_RIGHTLEFT
10645# ifdef FEAT_FKMAP
10646 /* Is this right? */
10647 wp_to->w_farsi = wp_from->w_farsi;
10648# endif
10649# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010650#if defined(FEAT_LINEBREAK)
10651 briopt_check(wp_to);
10652#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010653}
10654#endif
10655
10656/*
10657 * Copy the options from one winopt_T to another.
10658 * Doesn't free the old option values in "to", use clear_winopt() for that.
10659 * The 'scroll' option is not copied, because it depends on the window height.
10660 * The 'previewwindow' option is reset, there can be only one preview window.
10661 */
10662 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010663copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010664{
10665#ifdef FEAT_ARABIC
10666 to->wo_arab = from->wo_arab;
10667#endif
10668 to->wo_list = from->wo_list;
10669 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010670 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010671#ifdef FEAT_LINEBREAK
10672 to->wo_nuw = from->wo_nuw;
10673#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010674#ifdef FEAT_RIGHTLEFT
10675 to->wo_rl = from->wo_rl;
10676 to->wo_rlc = vim_strsave(from->wo_rlc);
10677#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010678#ifdef FEAT_STL_OPT
10679 to->wo_stl = vim_strsave(from->wo_stl);
10680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010681 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010682#ifdef FEAT_DIFF
10683 to->wo_wrap_save = from->wo_wrap_save;
10684#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010685#ifdef FEAT_LINEBREAK
10686 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010687 to->wo_bri = from->wo_bri;
10688 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689#endif
10690#ifdef FEAT_SCROLLBIND
10691 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010692 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010693#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010694#ifdef FEAT_CURSORBIND
10695 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010696 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010697#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010698#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010699 to->wo_spell = from->wo_spell;
10700#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010701#ifdef FEAT_SYN_HL
10702 to->wo_cuc = from->wo_cuc;
10703 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010704 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010705#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010706#ifdef FEAT_DIFF
10707 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010708 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010710#ifdef FEAT_CONCEAL
10711 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010712 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010714#ifdef FEAT_FOLDING
10715 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010716 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010717 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010718 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719 to->wo_fdi = vim_strsave(from->wo_fdi);
10720 to->wo_fml = from->wo_fml;
10721 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010722 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010723 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010724 to->wo_fdm_save = from->wo_diff_saved
10725 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010726 to->wo_fdn = from->wo_fdn;
10727# ifdef FEAT_EVAL
10728 to->wo_fde = vim_strsave(from->wo_fde);
10729 to->wo_fdt = vim_strsave(from->wo_fdt);
10730# endif
10731 to->wo_fmr = vim_strsave(from->wo_fmr);
10732#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010733#ifdef FEAT_SIGNS
10734 to->wo_scl = vim_strsave(from->wo_scl);
10735#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010736 check_winopt(to); /* don't want NULL pointers */
10737}
10738
10739/*
10740 * Check string options in a window for a NULL value.
10741 */
10742 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010743check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010744{
10745 check_winopt(&win->w_onebuf_opt);
10746 check_winopt(&win->w_allbuf_opt);
10747}
10748
10749/*
10750 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10751 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010752 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010753check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754{
10755#ifdef FEAT_FOLDING
10756 check_string_option(&wop->wo_fdi);
10757 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010758 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759# ifdef FEAT_EVAL
10760 check_string_option(&wop->wo_fde);
10761 check_string_option(&wop->wo_fdt);
10762# endif
10763 check_string_option(&wop->wo_fmr);
10764#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010765#ifdef FEAT_SIGNS
10766 check_string_option(&wop->wo_scl);
10767#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768#ifdef FEAT_RIGHTLEFT
10769 check_string_option(&wop->wo_rlc);
10770#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010771#ifdef FEAT_STL_OPT
10772 check_string_option(&wop->wo_stl);
10773#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010774#ifdef FEAT_SYN_HL
10775 check_string_option(&wop->wo_cc);
10776#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010777#ifdef FEAT_CONCEAL
10778 check_string_option(&wop->wo_cocu);
10779#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010780#ifdef FEAT_LINEBREAK
10781 check_string_option(&wop->wo_briopt);
10782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783}
10784
10785/*
10786 * Free the allocated memory inside a winopt_T.
10787 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010789clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010790{
10791#ifdef FEAT_FOLDING
10792 clear_string_option(&wop->wo_fdi);
10793 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010794 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010795# ifdef FEAT_EVAL
10796 clear_string_option(&wop->wo_fde);
10797 clear_string_option(&wop->wo_fdt);
10798# endif
10799 clear_string_option(&wop->wo_fmr);
10800#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010801#ifdef FEAT_SIGNS
10802 clear_string_option(&wop->wo_scl);
10803#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010804#ifdef FEAT_LINEBREAK
10805 clear_string_option(&wop->wo_briopt);
10806#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807#ifdef FEAT_RIGHTLEFT
10808 clear_string_option(&wop->wo_rlc);
10809#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010810#ifdef FEAT_STL_OPT
10811 clear_string_option(&wop->wo_stl);
10812#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010813#ifdef FEAT_SYN_HL
10814 clear_string_option(&wop->wo_cc);
10815#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010816#ifdef FEAT_CONCEAL
10817 clear_string_option(&wop->wo_cocu);
10818#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819}
10820
10821/*
10822 * Copy global option values to local options for one buffer.
10823 * Used when creating a new buffer and sometimes when entering a buffer.
10824 * flags:
10825 * BCO_ENTER We will enter the buf buffer.
10826 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10827 * appropriate.
10828 * BCO_NOHELP Don't copy the values to a help buffer.
10829 */
10830 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010831buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832{
10833 int should_copy = TRUE;
10834 char_u *save_p_isk = NULL; /* init for GCC */
10835 int dont_do_help;
10836 int did_isk = FALSE;
10837
10838 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839 * Skip this when the option defaults have not been set yet. Happens when
10840 * main() allocates the first buffer.
10841 */
10842 if (p_cpo != NULL)
10843 {
10844 /*
10845 * Always copy when entering and 'cpo' contains 'S'.
10846 * Don't copy when already initialized.
10847 * Don't copy when 'cpo' contains 's' and not entering.
10848 * 'S' BCO_ENTER initialized 's' should_copy
10849 * yes yes X X TRUE
10850 * yes no yes X FALSE
10851 * no X yes X FALSE
10852 * X no no yes FALSE
10853 * X no no no TRUE
10854 * no yes no X TRUE
10855 */
10856 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10857 && (buf->b_p_initialized
10858 || (!(flags & BCO_ENTER)
10859 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10860 should_copy = FALSE;
10861
10862 if (should_copy || (flags & BCO_ALWAYS))
10863 {
10864 /* Don't copy the options specific to a help buffer when
10865 * BCO_NOHELP is given or the options were initialized already
10866 * (jumping back to a help file with CTRL-T or CTRL-O) */
10867 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10868 || buf->b_p_initialized;
10869 if (dont_do_help) /* don't free b_p_isk */
10870 {
10871 save_p_isk = buf->b_p_isk;
10872 buf->b_p_isk = NULL;
10873 }
10874 /*
10875 * Always free the allocated strings.
10876 * If not already initialized, set 'readonly' and copy 'fileformat'.
10877 */
10878 if (!buf->b_p_initialized)
10879 {
10880 free_buf_options(buf, TRUE);
10881 buf->b_p_ro = FALSE; /* don't copy readonly */
10882 buf->b_p_tx = p_tx;
10883#ifdef FEAT_MBYTE
10884 buf->b_p_fenc = vim_strsave(p_fenc);
10885#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020010886 switch (*p_ffs)
10887 {
10888 case 'm':
10889 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
10890 case 'd':
10891 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
10892 case 'u':
10893 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
10894 default:
10895 buf->b_p_ff = vim_strsave(p_ff);
10896 }
10897 if (buf->b_p_ff != NULL)
10898 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899#if defined(FEAT_QUICKFIX)
10900 buf->b_p_bh = empty_option;
10901 buf->b_p_bt = empty_option;
10902#endif
10903 }
10904 else
10905 free_buf_options(buf, FALSE);
10906
10907 buf->b_p_ai = p_ai;
10908 buf->b_p_ai_nopaste = p_ai_nopaste;
10909 buf->b_p_sw = p_sw;
10910 buf->b_p_tw = p_tw;
10911 buf->b_p_tw_nopaste = p_tw_nopaste;
10912 buf->b_p_tw_nobin = p_tw_nobin;
10913 buf->b_p_wm = p_wm;
10914 buf->b_p_wm_nopaste = p_wm_nopaste;
10915 buf->b_p_wm_nobin = p_wm_nobin;
10916 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010917#ifdef FEAT_MBYTE
10918 buf->b_p_bomb = p_bomb;
10919#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010920 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 buf->b_p_et = p_et;
10922 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010923 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924 buf->b_p_ml = p_ml;
10925 buf->b_p_ml_nobin = p_ml_nobin;
10926 buf->b_p_inf = p_inf;
10927 buf->b_p_swf = p_swf;
10928#ifdef FEAT_INS_EXPAND
10929 buf->b_p_cpt = vim_strsave(p_cpt);
10930#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010931#ifdef FEAT_COMPL_FUNC
10932 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010933 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010934#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010935 buf->b_p_sts = p_sts;
10936 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010937 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938#ifdef FEAT_COMMENTS
10939 buf->b_p_com = vim_strsave(p_com);
10940#endif
10941#ifdef FEAT_FOLDING
10942 buf->b_p_cms = vim_strsave(p_cms);
10943#endif
10944 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010945 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010946 buf->b_p_nf = vim_strsave(p_nf);
10947 buf->b_p_mps = vim_strsave(p_mps);
10948#ifdef FEAT_SMARTINDENT
10949 buf->b_p_si = p_si;
10950#endif
10951 buf->b_p_ci = p_ci;
10952#ifdef FEAT_CINDENT
10953 buf->b_p_cin = p_cin;
10954 buf->b_p_cink = vim_strsave(p_cink);
10955 buf->b_p_cino = vim_strsave(p_cino);
10956#endif
10957#ifdef FEAT_AUTOCMD
10958 /* Don't copy 'filetype', it must be detected */
10959 buf->b_p_ft = empty_option;
10960#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961 buf->b_p_pi = p_pi;
10962#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10963 buf->b_p_cinw = vim_strsave(p_cinw);
10964#endif
10965#ifdef FEAT_LISP
10966 buf->b_p_lisp = p_lisp;
10967#endif
10968#ifdef FEAT_SYN_HL
10969 /* Don't copy 'syntax', it must be set */
10970 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010971 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010972 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010973#endif
10974#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010975 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010976 (void)compile_cap_prog(&buf->b_s);
10977 buf->b_s.b_p_spf = vim_strsave(p_spf);
10978 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010979#endif
10980#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10981 buf->b_p_inde = vim_strsave(p_inde);
10982 buf->b_p_indk = vim_strsave(p_indk);
10983#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010984 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010985#if defined(FEAT_EVAL)
10986 buf->b_p_fex = vim_strsave(p_fex);
10987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988#ifdef FEAT_CRYPT
10989 buf->b_p_key = vim_strsave(p_key);
10990#endif
10991#ifdef FEAT_SEARCHPATH
10992 buf->b_p_sua = vim_strsave(p_sua);
10993#endif
10994#ifdef FEAT_KEYMAP
10995 buf->b_p_keymap = vim_strsave(p_keymap);
10996 buf->b_kmap_state |= KEYMAP_INIT;
10997#endif
10998 /* This isn't really an option, but copying the langmap and IME
10999 * state from the current buffer is better than resetting it. */
11000 buf->b_p_iminsert = p_iminsert;
11001 buf->b_p_imsearch = p_imsearch;
11002
11003 /* options that are normally global but also have a local value
11004 * are not copied, start using the global value */
11005 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011006 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011007 buf->b_p_bkc = empty_option;
11008 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011009#ifdef FEAT_QUICKFIX
11010 buf->b_p_gp = empty_option;
11011 buf->b_p_mp = empty_option;
11012 buf->b_p_efm = empty_option;
11013#endif
11014 buf->b_p_ep = empty_option;
11015 buf->b_p_kp = empty_option;
11016 buf->b_p_path = empty_option;
11017 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011018 buf->b_p_tc = empty_option;
11019 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011020#ifdef FEAT_FIND_ID
11021 buf->b_p_def = empty_option;
11022 buf->b_p_inc = empty_option;
11023# ifdef FEAT_EVAL
11024 buf->b_p_inex = vim_strsave(p_inex);
11025# endif
11026#endif
11027#ifdef FEAT_INS_EXPAND
11028 buf->b_p_dict = empty_option;
11029 buf->b_p_tsr = empty_option;
11030#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011031#ifdef FEAT_TEXTOBJ
11032 buf->b_p_qe = vim_strsave(p_qe);
11033#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011034#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11035 buf->b_p_bexpr = empty_option;
11036#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011037#if defined(FEAT_CRYPT)
11038 buf->b_p_cm = empty_option;
11039#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011040#ifdef FEAT_PERSISTENT_UNDO
11041 buf->b_p_udf = p_udf;
11042#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011043#ifdef FEAT_LISP
11044 buf->b_p_lw = empty_option;
11045#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011046
11047 /*
11048 * Don't copy the options set by ex_help(), use the saved values,
11049 * when going from a help buffer to a non-help buffer.
11050 * Don't touch these at all when BCO_NOHELP is used and going from
11051 * or to a help buffer.
11052 */
11053 if (dont_do_help)
11054 buf->b_p_isk = save_p_isk;
11055 else
11056 {
11057 buf->b_p_isk = vim_strsave(p_isk);
11058 did_isk = TRUE;
11059 buf->b_p_ts = p_ts;
11060 buf->b_help = FALSE;
11061#ifdef FEAT_QUICKFIX
11062 if (buf->b_p_bt[0] == 'h')
11063 clear_string_option(&buf->b_p_bt);
11064#endif
11065 buf->b_p_ma = p_ma;
11066 }
11067 }
11068
11069 /*
11070 * When the options should be copied (ignoring BCO_ALWAYS), set the
11071 * flag that indicates that the options have been initialized.
11072 */
11073 if (should_copy)
11074 buf->b_p_initialized = TRUE;
11075 }
11076
11077 check_buf_options(buf); /* make sure we don't have NULLs */
11078 if (did_isk)
11079 (void)buf_init_chartab(buf, FALSE);
11080}
11081
11082/*
11083 * Reset the 'modifiable' option and its default value.
11084 */
11085 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011086reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011087{
11088 int opt_idx;
11089
11090 curbuf->b_p_ma = FALSE;
11091 p_ma = FALSE;
11092 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011093 if (opt_idx >= 0)
11094 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095}
11096
11097/*
11098 * Set the global value for 'iminsert' to the local value.
11099 */
11100 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011101set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102{
11103 p_iminsert = curbuf->b_p_iminsert;
11104}
11105
11106/*
11107 * Set the global value for 'imsearch' to the local value.
11108 */
11109 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011110set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011111{
11112 p_imsearch = curbuf->b_p_imsearch;
11113}
11114
11115#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11116static int expand_option_idx = -1;
11117static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11118static int expand_option_flags = 0;
11119
11120 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011121set_context_in_set_cmd(
11122 expand_T *xp,
11123 char_u *arg,
11124 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011125{
11126 int nextchar;
11127 long_u flags = 0; /* init for GCC */
11128 int opt_idx = 0; /* init for GCC */
11129 char_u *p;
11130 char_u *s;
11131 int is_term_option = FALSE;
11132 int key;
11133
11134 expand_option_flags = opt_flags;
11135
11136 xp->xp_context = EXPAND_SETTINGS;
11137 if (*arg == NUL)
11138 {
11139 xp->xp_pattern = arg;
11140 return;
11141 }
11142 p = arg + STRLEN(arg) - 1;
11143 if (*p == ' ' && *(p - 1) != '\\')
11144 {
11145 xp->xp_pattern = p + 1;
11146 return;
11147 }
11148 while (p > arg)
11149 {
11150 s = p;
11151 /* count number of backslashes before ' ' or ',' */
11152 if (*p == ' ' || *p == ',')
11153 {
11154 while (s > arg && *(s - 1) == '\\')
11155 --s;
11156 }
11157 /* break at a space with an even number of backslashes */
11158 if (*p == ' ' && ((p - s) & 1) == 0)
11159 {
11160 ++p;
11161 break;
11162 }
11163 --p;
11164 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011165 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011166 {
11167 xp->xp_context = EXPAND_BOOL_SETTINGS;
11168 p += 2;
11169 }
11170 if (STRNCMP(p, "inv", 3) == 0)
11171 {
11172 xp->xp_context = EXPAND_BOOL_SETTINGS;
11173 p += 3;
11174 }
11175 xp->xp_pattern = arg = p;
11176 if (*arg == '<')
11177 {
11178 while (*p != '>')
11179 if (*p++ == NUL) /* expand terminal option name */
11180 return;
11181 key = get_special_key_code(arg + 1);
11182 if (key == 0) /* unknown name */
11183 {
11184 xp->xp_context = EXPAND_NOTHING;
11185 return;
11186 }
11187 nextchar = *++p;
11188 is_term_option = TRUE;
11189 expand_option_name[2] = KEY2TERMCAP0(key);
11190 expand_option_name[3] = KEY2TERMCAP1(key);
11191 }
11192 else
11193 {
11194 if (p[0] == 't' && p[1] == '_')
11195 {
11196 p += 2;
11197 if (*p != NUL)
11198 ++p;
11199 if (*p == NUL)
11200 return; /* expand option name */
11201 nextchar = *++p;
11202 is_term_option = TRUE;
11203 expand_option_name[2] = p[-2];
11204 expand_option_name[3] = p[-1];
11205 }
11206 else
11207 {
11208 /* Allow * wildcard */
11209 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11210 p++;
11211 if (*p == NUL)
11212 return;
11213 nextchar = *p;
11214 *p = NUL;
11215 opt_idx = findoption(arg);
11216 *p = nextchar;
11217 if (opt_idx == -1 || options[opt_idx].var == NULL)
11218 {
11219 xp->xp_context = EXPAND_NOTHING;
11220 return;
11221 }
11222 flags = options[opt_idx].flags;
11223 if (flags & P_BOOL)
11224 {
11225 xp->xp_context = EXPAND_NOTHING;
11226 return;
11227 }
11228 }
11229 }
11230 /* handle "-=" and "+=" */
11231 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11232 {
11233 ++p;
11234 nextchar = '=';
11235 }
11236 if ((nextchar != '=' && nextchar != ':')
11237 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11238 {
11239 xp->xp_context = EXPAND_UNSUCCESSFUL;
11240 return;
11241 }
11242 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11243 {
11244 xp->xp_context = EXPAND_OLD_SETTING;
11245 if (is_term_option)
11246 expand_option_idx = -1;
11247 else
11248 expand_option_idx = opt_idx;
11249 xp->xp_pattern = p + 1;
11250 return;
11251 }
11252 xp->xp_context = EXPAND_NOTHING;
11253 if (is_term_option || (flags & P_NUM))
11254 return;
11255
11256 xp->xp_pattern = p + 1;
11257
11258 if (flags & P_EXPAND)
11259 {
11260 p = options[opt_idx].var;
11261 if (p == (char_u *)&p_bdir
11262 || p == (char_u *)&p_dir
11263 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011264 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011265 || p == (char_u *)&p_rtp
11266#ifdef FEAT_SEARCHPATH
11267 || p == (char_u *)&p_cdpath
11268#endif
11269#ifdef FEAT_SESSION
11270 || p == (char_u *)&p_vdir
11271#endif
11272 )
11273 {
11274 xp->xp_context = EXPAND_DIRECTORIES;
11275 if (p == (char_u *)&p_path
11276#ifdef FEAT_SEARCHPATH
11277 || p == (char_u *)&p_cdpath
11278#endif
11279 )
11280 xp->xp_backslash = XP_BS_THREE;
11281 else
11282 xp->xp_backslash = XP_BS_ONE;
11283 }
11284 else
11285 {
11286 xp->xp_context = EXPAND_FILES;
11287 /* for 'tags' need three backslashes for a space */
11288 if (p == (char_u *)&p_tags)
11289 xp->xp_backslash = XP_BS_THREE;
11290 else
11291 xp->xp_backslash = XP_BS_ONE;
11292 }
11293 }
11294
11295 /* For an option that is a list of file names, find the start of the
11296 * last file name. */
11297 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11298 {
11299 /* count number of backslashes before ' ' or ',' */
11300 if (*p == ' ' || *p == ',')
11301 {
11302 s = p;
11303 while (s > xp->xp_pattern && *(s - 1) == '\\')
11304 --s;
11305 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11306 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11307 {
11308 xp->xp_pattern = p + 1;
11309 break;
11310 }
11311 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011312
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011313#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011314 /* for 'spellsuggest' start at "file:" */
11315 if (options[opt_idx].var == (char_u *)&p_sps
11316 && STRNCMP(p, "file:", 5) == 0)
11317 {
11318 xp->xp_pattern = p + 5;
11319 break;
11320 }
11321#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322 }
11323
11324 return;
11325}
11326
11327 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011328ExpandSettings(
11329 expand_T *xp,
11330 regmatch_T *regmatch,
11331 int *num_file,
11332 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011333{
11334 int num_normal = 0; /* Nr of matching non-term-code settings */
11335 int num_term = 0; /* Nr of matching terminal code settings */
11336 int opt_idx;
11337 int match;
11338 int count = 0;
11339 char_u *str;
11340 int loop;
11341 int is_term_opt;
11342 char_u name_buf[MAX_KEY_NAME_LEN];
11343 static char *(names[]) = {"all", "termcap"};
11344 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11345
11346 /* do this loop twice:
11347 * loop == 0: count the number of matching options
11348 * loop == 1: copy the matching options into allocated memory
11349 */
11350 for (loop = 0; loop <= 1; ++loop)
11351 {
11352 regmatch->rm_ic = ic;
11353 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11354 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011355 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11356 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011357 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11358 {
11359 if (loop == 0)
11360 num_normal++;
11361 else
11362 (*file)[count++] = vim_strsave((char_u *)names[match]);
11363 }
11364 }
11365 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11366 opt_idx++)
11367 {
11368 if (options[opt_idx].var == NULL)
11369 continue;
11370 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11371 && !(options[opt_idx].flags & P_BOOL))
11372 continue;
11373 is_term_opt = istermoption(&options[opt_idx]);
11374 if (is_term_opt && num_normal > 0)
11375 continue;
11376 match = FALSE;
11377 if (vim_regexec(regmatch, str, (colnr_T)0)
11378 || (options[opt_idx].shortname != NULL
11379 && vim_regexec(regmatch,
11380 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11381 match = TRUE;
11382 else if (is_term_opt)
11383 {
11384 name_buf[0] = '<';
11385 name_buf[1] = 't';
11386 name_buf[2] = '_';
11387 name_buf[3] = str[2];
11388 name_buf[4] = str[3];
11389 name_buf[5] = '>';
11390 name_buf[6] = NUL;
11391 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11392 {
11393 match = TRUE;
11394 str = name_buf;
11395 }
11396 }
11397 if (match)
11398 {
11399 if (loop == 0)
11400 {
11401 if (is_term_opt)
11402 num_term++;
11403 else
11404 num_normal++;
11405 }
11406 else
11407 (*file)[count++] = vim_strsave(str);
11408 }
11409 }
11410 /*
11411 * Check terminal key codes, these are not in the option table
11412 */
11413 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11414 {
11415 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11416 {
11417 if (!isprint(str[0]) || !isprint(str[1]))
11418 continue;
11419
11420 name_buf[0] = 't';
11421 name_buf[1] = '_';
11422 name_buf[2] = str[0];
11423 name_buf[3] = str[1];
11424 name_buf[4] = NUL;
11425
11426 match = FALSE;
11427 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11428 match = TRUE;
11429 else
11430 {
11431 name_buf[0] = '<';
11432 name_buf[1] = 't';
11433 name_buf[2] = '_';
11434 name_buf[3] = str[0];
11435 name_buf[4] = str[1];
11436 name_buf[5] = '>';
11437 name_buf[6] = NUL;
11438
11439 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11440 match = TRUE;
11441 }
11442 if (match)
11443 {
11444 if (loop == 0)
11445 num_term++;
11446 else
11447 (*file)[count++] = vim_strsave(name_buf);
11448 }
11449 }
11450
11451 /*
11452 * Check special key names.
11453 */
11454 regmatch->rm_ic = TRUE; /* ignore case here */
11455 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11456 {
11457 name_buf[0] = '<';
11458 STRCPY(name_buf + 1, str);
11459 STRCAT(name_buf, ">");
11460
11461 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11462 {
11463 if (loop == 0)
11464 num_term++;
11465 else
11466 (*file)[count++] = vim_strsave(name_buf);
11467 }
11468 }
11469 }
11470 if (loop == 0)
11471 {
11472 if (num_normal > 0)
11473 *num_file = num_normal;
11474 else if (num_term > 0)
11475 *num_file = num_term;
11476 else
11477 return OK;
11478 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11479 if (*file == NULL)
11480 {
11481 *file = (char_u **)"";
11482 return FAIL;
11483 }
11484 }
11485 }
11486 return OK;
11487}
11488
11489 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011490ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491{
11492 char_u *var = NULL; /* init for GCC */
11493 char_u *buf;
11494
11495 *num_file = 0;
11496 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11497 if (*file == NULL)
11498 return FAIL;
11499
11500 /*
11501 * For a terminal key code expand_option_idx is < 0.
11502 */
11503 if (expand_option_idx < 0)
11504 {
11505 var = find_termcode(expand_option_name + 2);
11506 if (var == NULL)
11507 expand_option_idx = findoption(expand_option_name);
11508 }
11509
11510 if (expand_option_idx >= 0)
11511 {
11512 /* put string of option value in NameBuff */
11513 option_value2string(&options[expand_option_idx], expand_option_flags);
11514 var = NameBuff;
11515 }
11516 else if (var == NULL)
11517 var = (char_u *)"";
11518
11519 /* A backslash is required before some characters. This is the reverse of
11520 * what happens in do_set(). */
11521 buf = vim_strsave_escaped(var, escape_chars);
11522
11523 if (buf == NULL)
11524 {
11525 vim_free(*file);
11526 *file = NULL;
11527 return FAIL;
11528 }
11529
11530#ifdef BACKSLASH_IN_FILENAME
11531 /* For MS-Windows et al. we don't double backslashes at the start and
11532 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011533 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534 if (var[0] == '\\' && var[1] == '\\'
11535 && expand_option_idx >= 0
11536 && (options[expand_option_idx].flags & P_EXPAND)
11537 && vim_isfilec(var[2])
11538 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011539 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011540#endif
11541
11542 *file[0] = buf;
11543 *num_file = 1;
11544 return OK;
11545}
11546#endif
11547
11548/*
11549 * Get the value for the numeric or string option *opp in a nice format into
11550 * NameBuff[]. Must not be called with a hidden option!
11551 */
11552 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011553option_value2string(
11554 struct vimoption *opp,
11555 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011556{
11557 char_u *varp;
11558
11559 varp = get_varp_scope(opp, opt_flags);
11560
11561 if (opp->flags & P_NUM)
11562 {
11563 long wc = 0;
11564
11565 if (wc_use_keyname(varp, &wc))
11566 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11567 else if (wc != 0)
11568 STRCPY(NameBuff, transchar((int)wc));
11569 else
11570 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11571 }
11572 else /* P_STRING */
11573 {
11574 varp = *(char_u **)(varp);
11575 if (varp == NULL) /* just in case */
11576 NameBuff[0] = NUL;
11577#ifdef FEAT_CRYPT
11578 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011579 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011580 STRCPY(NameBuff, "*****");
11581#endif
11582 else if (opp->flags & P_EXPAND)
11583 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11584 /* Translate 'pastetoggle' into special key names */
11585 else if ((char_u **)opp->var == &p_pt)
11586 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11587 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011588 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011589 }
11590}
11591
11592/*
11593 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11594 * printed as a keyname.
11595 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11596 */
11597 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011598wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011599{
11600 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11601 {
11602 *wcp = *(long *)varp;
11603 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11604 return TRUE;
11605 }
11606 return FALSE;
11607}
11608
Bram Moolenaar01615492015-02-03 13:00:38 +010011609#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011611 * Any character has an equivalent 'langmap' character. This is used for
11612 * keyboards that have a special language mode that sends characters above
11613 * 128 (although other characters can be translated too). The "to" field is a
11614 * Vim command character. This avoids having to switch the keyboard back to
11615 * ASCII mode when leaving Insert mode.
11616 *
11617 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11618 * commands.
11619 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11620 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11621 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011622 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011623# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011624/*
11625 * With multi-byte support use growarray for 'langmap' chars >= 256
11626 */
11627typedef struct
11628{
11629 int from;
11630 int to;
11631} langmap_entry_T;
11632
11633static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011634static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011635
11636/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011637 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11638 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011639 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011640 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011641langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011642{
11643 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011644 int a = 0;
11645 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011646
11647 /* Do a binary search for an existing entry. */
11648 while (a != b)
11649 {
11650 int i = (a + b) / 2;
11651 int d = entries[i].from - from;
11652
11653 if (d == 0)
11654 {
11655 entries[i].to = to;
11656 return;
11657 }
11658 if (d < 0)
11659 a = i + 1;
11660 else
11661 b = i;
11662 }
11663
11664 if (ga_grow(&langmap_mapga, 1) != OK)
11665 return; /* out of memory */
11666
11667 /* insert new entry at position "a" */
11668 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11669 mch_memmove(entries + 1, entries,
11670 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11671 ++langmap_mapga.ga_len;
11672 entries[0].from = from;
11673 entries[0].to = to;
11674}
11675
11676/*
11677 * Apply 'langmap' to multi-byte character "c" and return the result.
11678 */
11679 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011680langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011681{
11682 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11683 int a = 0;
11684 int b = langmap_mapga.ga_len;
11685
11686 while (a != b)
11687 {
11688 int i = (a + b) / 2;
11689 int d = entries[i].from - c;
11690
11691 if (d == 0)
11692 return entries[i].to; /* found matching entry */
11693 if (d < 0)
11694 a = i + 1;
11695 else
11696 b = i;
11697 }
11698 return c; /* no entry found, return "c" unmodified */
11699}
11700# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011701
11702 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011703langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011704{
11705 int i;
11706
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011707 for (i = 0; i < 256; i++)
11708 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11709# ifdef FEAT_MBYTE
11710 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11711# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011712}
11713
11714/*
11715 * Called when langmap option is set; the language map can be
11716 * changed at any time!
11717 */
11718 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011719langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011720{
11721 char_u *p;
11722 char_u *p2;
11723 int from, to;
11724
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011725#ifdef FEAT_MBYTE
11726 ga_clear(&langmap_mapga); /* clear the previous map first */
11727#endif
11728 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011729
11730 for (p = p_langmap; p[0] != NUL; )
11731 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011732 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11733 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011734 {
11735 if (p2[0] == '\\' && p2[1] != NUL)
11736 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011737 }
11738 if (p2[0] == ';')
11739 ++p2; /* abcd;ABCD form, p2 points to A */
11740 else
11741 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11742 while (p[0])
11743 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011744 if (p[0] == ',')
11745 {
11746 ++p;
11747 break;
11748 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011749 if (p[0] == '\\' && p[1] != NUL)
11750 ++p;
11751#ifdef FEAT_MBYTE
11752 from = (*mb_ptr2char)(p);
11753#else
11754 from = p[0];
11755#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011756 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011757 if (p2 == NULL)
11758 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011759 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011760 if (p[0] != ',')
11761 {
11762 if (p[0] == '\\')
11763 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011764#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011765 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011766#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011767 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011768#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011769 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011770 }
11771 else
11772 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011773 if (p2[0] != ',')
11774 {
11775 if (p2[0] == '\\')
11776 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011777#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011778 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011779#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011780 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011782 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011783 }
11784 if (to == NUL)
11785 {
11786 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11787 transchar(from));
11788 return;
11789 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011790
11791#ifdef FEAT_MBYTE
11792 if (from >= 256)
11793 langmap_set_entry(from, to);
11794 else
11795#endif
11796 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011797
11798 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011799 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011800 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011801 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011802 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011803 if (*p == ';')
11804 {
11805 p = p2;
11806 if (p[0] != NUL)
11807 {
11808 if (p[0] != ',')
11809 {
11810 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11811 return;
11812 }
11813 ++p;
11814 }
11815 break;
11816 }
11817 }
11818 }
11819 }
11820}
11821#endif
11822
11823/*
11824 * Return TRUE if format option 'x' is in effect.
11825 * Take care of no formatting when 'paste' is set.
11826 */
11827 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011828has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011829{
11830 if (p_paste)
11831 return FALSE;
11832 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11833}
11834
11835/*
11836 * Return TRUE if "x" is present in 'shortmess' option, or
11837 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11838 */
11839 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011840shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011841{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011842 return p_shm != NULL &&
11843 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011844 || (vim_strchr(p_shm, 'a') != NULL
11845 && vim_strchr((char_u *)SHM_A, x) != NULL));
11846}
11847
11848/*
11849 * paste_option_changed() - Called after p_paste was set or reset.
11850 */
11851 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011852paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011853{
11854 static int old_p_paste = FALSE;
11855 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011856 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011857#ifdef FEAT_CMDL_INFO
11858 static int save_ru = 0;
11859#endif
11860#ifdef FEAT_RIGHTLEFT
11861 static int save_ri = 0;
11862 static int save_hkmap = 0;
11863#endif
11864 buf_T *buf;
11865
11866 if (p_paste)
11867 {
11868 /*
11869 * Paste switched from off to on.
11870 * Save the current values, so they can be restored later.
11871 */
11872 if (!old_p_paste)
11873 {
11874 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011875 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876 {
11877 buf->b_p_tw_nopaste = buf->b_p_tw;
11878 buf->b_p_wm_nopaste = buf->b_p_wm;
11879 buf->b_p_sts_nopaste = buf->b_p_sts;
11880 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011881 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011882 }
11883
11884 /* save global options */
11885 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011886 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011887#ifdef FEAT_CMDL_INFO
11888 save_ru = p_ru;
11889#endif
11890#ifdef FEAT_RIGHTLEFT
11891 save_ri = p_ri;
11892 save_hkmap = p_hkmap;
11893#endif
11894 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011895 p_ai_nopaste = p_ai;
11896 p_et_nopaste = p_et;
11897 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011898 p_tw_nopaste = p_tw;
11899 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900 }
11901
11902 /*
11903 * Always set the option values, also when 'paste' is set when it is
11904 * already on.
11905 */
11906 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011907 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011908 {
11909 buf->b_p_tw = 0; /* textwidth is 0 */
11910 buf->b_p_wm = 0; /* wrapmargin is 0 */
11911 buf->b_p_sts = 0; /* softtabstop is 0 */
11912 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011913 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011914 }
11915
11916 /* set global options */
11917 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011918 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011919#ifdef FEAT_CMDL_INFO
11920# ifdef FEAT_WINDOWS
11921 if (p_ru)
11922 status_redraw_all(); /* redraw to remove the ruler */
11923# endif
11924 p_ru = 0; /* no ruler */
11925#endif
11926#ifdef FEAT_RIGHTLEFT
11927 p_ri = 0; /* no reverse insert */
11928 p_hkmap = 0; /* no Hebrew keyboard */
11929#endif
11930 /* set global values for local buffer options */
11931 p_tw = 0;
11932 p_wm = 0;
11933 p_sts = 0;
11934 p_ai = 0;
11935 }
11936
11937 /*
11938 * Paste switched from on to off: Restore saved values.
11939 */
11940 else if (old_p_paste)
11941 {
11942 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011943 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011944 {
11945 buf->b_p_tw = buf->b_p_tw_nopaste;
11946 buf->b_p_wm = buf->b_p_wm_nopaste;
11947 buf->b_p_sts = buf->b_p_sts_nopaste;
11948 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011949 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011950 }
11951
11952 /* restore global options */
11953 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011954 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955#ifdef FEAT_CMDL_INFO
11956# ifdef FEAT_WINDOWS
11957 if (p_ru != save_ru)
11958 status_redraw_all(); /* redraw to draw the ruler */
11959# endif
11960 p_ru = save_ru;
11961#endif
11962#ifdef FEAT_RIGHTLEFT
11963 p_ri = save_ri;
11964 p_hkmap = save_hkmap;
11965#endif
11966 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011967 p_ai = p_ai_nopaste;
11968 p_et = p_et_nopaste;
11969 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011970 p_tw = p_tw_nopaste;
11971 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011972 }
11973
11974 old_p_paste = p_paste;
11975}
11976
11977/*
11978 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11979 *
11980 * Reset 'compatible' and set the values for options that didn't get set yet
11981 * to the Vim defaults.
11982 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011983 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011984 */
11985 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011986vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011987{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011988 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011989 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011990 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011991
11992 if (!option_was_set((char_u *)"cp"))
11993 {
11994 p_cp = FALSE;
11995 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11996 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11997 set_option_default(opt_idx, OPT_FREE, FALSE);
11998 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011999 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012000 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012001
12002 if (fname != NULL)
12003 {
12004 p = vim_getenv(envname, &dofree);
12005 if (p == NULL)
12006 {
12007 /* Set $MYVIMRC to the first vimrc file found. */
12008 p = FullName_save(fname, FALSE);
12009 if (p != NULL)
12010 {
12011 vim_setenv(envname, p);
12012 vim_free(p);
12013 }
12014 }
12015 else if (dofree)
12016 vim_free(p);
12017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012018}
12019
12020/*
12021 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12022 */
12023 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012024change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012026 int opt_idx;
12027
Bram Moolenaar071d4272004-06-13 20:20:40 +000012028 if (p_cp != on)
12029 {
12030 p_cp = on;
12031 compatible_set();
12032 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012033 opt_idx = findoption((char_u *)"cp");
12034 if (opt_idx >= 0)
12035 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036}
12037
12038/*
12039 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012040 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012041 */
12042 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012043option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012044{
12045 int idx;
12046
12047 idx = findoption(name);
12048 if (idx < 0) /* unknown option */
12049 return FALSE;
12050 if (options[idx].flags & P_WAS_SET)
12051 return TRUE;
12052 return FALSE;
12053}
12054
12055/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012056 * Reset the flag indicating option "name" was set.
12057 */
12058 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012059reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012060{
12061 int idx = findoption(name);
12062
12063 if (idx >= 0)
12064 options[idx].flags &= ~P_WAS_SET;
12065}
12066
12067/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012068 * compatible_set() - Called when 'compatible' has been set or unset.
12069 *
12070 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12071 * flag) to a Vi compatible value.
12072 * When 'compatible' is unset: Set all options that have a different default
12073 * for Vim (without the P_VI_DEF flag) to that default.
12074 */
12075 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012076compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012077{
12078 int opt_idx;
12079
12080 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12081 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12082 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12083 set_option_default(opt_idx, OPT_FREE, p_cp);
12084 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012085 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086}
12087
12088#ifdef FEAT_LINEBREAK
12089
12090# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12091 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012092 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012093# endif
12094
12095/*
12096 * fill_breakat_flags() -- called when 'breakat' changes value.
12097 */
12098 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012099fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012101 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012102 int i;
12103
12104 for (i = 0; i < 256; i++)
12105 breakat_flags[i] = FALSE;
12106
12107 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012108 for (p = p_breakat; *p; p++)
12109 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012110}
12111
12112# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012113 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012114# endif
12115
12116#endif
12117
12118/*
12119 * Check an option that can be a range of string values.
12120 *
12121 * Return OK for correct value, FAIL otherwise.
12122 * Empty is always OK.
12123 */
12124 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012125check_opt_strings(
12126 char_u *val,
12127 char **values,
12128 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012129{
12130 return opt_strings_flags(val, values, NULL, list);
12131}
12132
12133/*
12134 * Handle an option that can be a range of string values.
12135 * Set a flag in "*flagp" for each string present.
12136 *
12137 * Return OK for correct value, FAIL otherwise.
12138 * Empty is always OK.
12139 */
12140 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012141opt_strings_flags(
12142 char_u *val, /* new value */
12143 char **values, /* array of valid string values */
12144 unsigned *flagp,
12145 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146{
12147 int i;
12148 int len;
12149 unsigned new_flags = 0;
12150
12151 while (*val)
12152 {
12153 for (i = 0; ; ++i)
12154 {
12155 if (values[i] == NULL) /* val not found in values[] */
12156 return FAIL;
12157
12158 len = (int)STRLEN(values[i]);
12159 if (STRNCMP(values[i], val, len) == 0
12160 && ((list && val[len] == ',') || val[len] == NUL))
12161 {
12162 val += len + (val[len] == ',');
12163 new_flags |= (1 << i);
12164 break; /* check next item in val list */
12165 }
12166 }
12167 }
12168 if (flagp != NULL)
12169 *flagp = new_flags;
12170
12171 return OK;
12172}
12173
12174/*
12175 * Read the 'wildmode' option, fill wim_flags[].
12176 */
12177 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012178check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012179{
12180 char_u new_wim_flags[4];
12181 char_u *p;
12182 int i;
12183 int idx = 0;
12184
12185 for (i = 0; i < 4; ++i)
12186 new_wim_flags[i] = 0;
12187
12188 for (p = p_wim; *p; ++p)
12189 {
12190 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12191 ;
12192 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12193 return FAIL;
12194 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12195 new_wim_flags[idx] |= WIM_LONGEST;
12196 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12197 new_wim_flags[idx] |= WIM_FULL;
12198 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12199 new_wim_flags[idx] |= WIM_LIST;
12200 else
12201 return FAIL;
12202 p += i;
12203 if (*p == NUL)
12204 break;
12205 if (*p == ',')
12206 {
12207 if (idx == 3)
12208 return FAIL;
12209 ++idx;
12210 }
12211 }
12212
12213 /* fill remaining entries with last flag */
12214 while (idx < 3)
12215 {
12216 new_wim_flags[idx + 1] = new_wim_flags[idx];
12217 ++idx;
12218 }
12219
12220 /* only when there are no errors, wim_flags[] is changed */
12221 for (i = 0; i < 4; ++i)
12222 wim_flags[i] = new_wim_flags[i];
12223 return OK;
12224}
12225
12226/*
12227 * Check if backspacing over something is allowed.
12228 */
12229 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012230can_bs(
12231 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012232{
12233 switch (*p_bs)
12234 {
12235 case '2': return TRUE;
12236 case '1': return (what != BS_START);
12237 case '0': return FALSE;
12238 }
12239 return vim_strchr(p_bs, what) != NULL;
12240}
12241
12242/*
12243 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12244 * the file must be considered changed when the value is different.
12245 */
12246 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012247save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012248{
12249 buf->b_start_ffc = *buf->b_p_ff;
12250 buf->b_start_eol = buf->b_p_eol;
12251#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012252 buf->b_start_bomb = buf->b_p_bomb;
12253
Bram Moolenaar071d4272004-06-13 20:20:40 +000012254 /* Only use free/alloc when necessary, they take time. */
12255 if (buf->b_start_fenc == NULL
12256 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12257 {
12258 vim_free(buf->b_start_fenc);
12259 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12260 }
12261#endif
12262}
12263
12264/*
12265 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12266 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012267 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12268 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012269 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012270 * When "ignore_empty" is true don't consider a new, empty buffer to be
12271 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012272 */
12273 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012274file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012275{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012276 /* In a buffer that was never loaded the options are not valid. */
12277 if (buf->b_flags & BF_NEVERLOADED)
12278 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012279 if (ignore_empty
12280 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012281 && buf->b_ml.ml_line_count == 1
12282 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12283 return FALSE;
12284 if (buf->b_start_ffc != *buf->b_p_ff)
12285 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012286 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012287 return TRUE;
12288#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012289 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12290 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012291 if (buf->b_start_fenc == NULL)
12292 return (*buf->b_p_fenc != NUL);
12293 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12294#else
12295 return FALSE;
12296#endif
12297}
12298
12299/*
12300 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12301 */
12302 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012303check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012304{
12305 return check_opt_strings(p, p_ff_values, FALSE);
12306}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012307
12308/*
12309 * Return the effective shiftwidth value for current buffer, using the
12310 * 'tabstop' value when 'shiftwidth' is zero.
12311 */
12312 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012313get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012314{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012315 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012316}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012317
12318/*
12319 * Return the effective softtabstop value for the current buffer, using the
12320 * 'tabstop' value when 'softtabstop' is negative.
12321 */
12322 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012323get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012324{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012325 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012326}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012327
12328/*
12329 * Check matchpairs option for "*initc".
12330 * If there is a match set "*initc" to the matching character and "*findc" to
12331 * the opposite character. Set "*backwards" to the direction.
12332 * When "switchit" is TRUE swap the direction.
12333 */
12334 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012335find_mps_values(
12336 int *initc,
12337 int *findc,
12338 int *backwards,
12339 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012340{
12341 char_u *ptr;
12342
12343 ptr = curbuf->b_p_mps;
12344 while (*ptr != NUL)
12345 {
12346#ifdef FEAT_MBYTE
12347 if (has_mbyte)
12348 {
12349 char_u *prev;
12350
12351 if (mb_ptr2char(ptr) == *initc)
12352 {
12353 if (switchit)
12354 {
12355 *findc = *initc;
12356 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12357 *backwards = TRUE;
12358 }
12359 else
12360 {
12361 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12362 *backwards = FALSE;
12363 }
12364 return;
12365 }
12366 prev = ptr;
12367 ptr += mb_ptr2len(ptr) + 1;
12368 if (mb_ptr2char(ptr) == *initc)
12369 {
12370 if (switchit)
12371 {
12372 *findc = *initc;
12373 *initc = mb_ptr2char(prev);
12374 *backwards = FALSE;
12375 }
12376 else
12377 {
12378 *findc = mb_ptr2char(prev);
12379 *backwards = TRUE;
12380 }
12381 return;
12382 }
12383 ptr += mb_ptr2len(ptr);
12384 }
12385 else
12386#endif
12387 {
12388 if (*ptr == *initc)
12389 {
12390 if (switchit)
12391 {
12392 *backwards = TRUE;
12393 *findc = *initc;
12394 *initc = ptr[2];
12395 }
12396 else
12397 {
12398 *backwards = FALSE;
12399 *findc = ptr[2];
12400 }
12401 return;
12402 }
12403 ptr += 2;
12404 if (*ptr == *initc)
12405 {
12406 if (switchit)
12407 {
12408 *backwards = FALSE;
12409 *findc = *initc;
12410 *initc = ptr[-2];
12411 }
12412 else
12413 {
12414 *backwards = TRUE;
12415 *findc = ptr[-2];
12416 }
12417 return;
12418 }
12419 ++ptr;
12420 }
12421 if (*ptr == ',')
12422 ++ptr;
12423 }
12424}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012425
12426#if defined(FEAT_LINEBREAK) || defined(PROTO)
12427/*
12428 * This is called when 'breakindentopt' is changed and when a window is
12429 * initialized.
12430 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012431 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012432briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012433{
12434 char_u *p;
12435 int bri_shift = 0;
12436 long bri_min = 20;
12437 int bri_sbr = FALSE;
12438
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012439 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012440 while (*p != NUL)
12441 {
12442 if (STRNCMP(p, "shift:", 6) == 0
12443 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12444 {
12445 p += 6;
12446 bri_shift = getdigits(&p);
12447 }
12448 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12449 {
12450 p += 4;
12451 bri_min = getdigits(&p);
12452 }
12453 else if (STRNCMP(p, "sbr", 3) == 0)
12454 {
12455 p += 3;
12456 bri_sbr = TRUE;
12457 }
12458 if (*p != ',' && *p != NUL)
12459 return FAIL;
12460 if (*p == ',')
12461 ++p;
12462 }
12463
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012464 wp->w_p_brishift = bri_shift;
12465 wp->w_p_brimin = bri_min;
12466 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012467
12468 return OK;
12469}
12470#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012471
12472/*
12473 * Get the local or global value of 'backupcopy'.
12474 */
12475 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012476get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012477{
12478 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12479}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012480
12481#if defined(FEAT_SIGNS) || defined(PROTO)
12482/*
12483 * Return TRUE when window "wp" has a column to draw signs in.
12484 */
12485 int
12486signcolumn_on(win_T *wp)
12487{
12488 if (*wp->w_p_scl == 'n')
12489 return FALSE;
12490 if (*wp->w_p_scl == 'y')
12491 return TRUE;
12492 return (wp->w_buffer->b_signlist != NULL
12493# ifdef FEAT_NETBEANS_INTG
12494 || wp->w_buffer->b_has_sign_column
12495# endif
12496 );
12497}
12498#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012499
12500#if defined(FEAT_EVAL) || defined(PROTO)
12501/*
12502 * Get window or buffer local options.
12503 */
12504 dict_T *
12505get_winbuf_options(int bufopt)
12506{
12507 dict_T *d;
12508 int opt_idx;
12509
12510 d = dict_alloc();
12511 if (d == NULL)
12512 return NULL;
12513
12514 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12515 {
12516 struct vimoption *opt = &options[opt_idx];
12517
12518 if ((bufopt && (opt->indir & PV_BUF))
12519 || (!bufopt && (opt->indir & PV_WIN)))
12520 {
12521 char_u *varp = get_varp(opt);
12522
12523 if (varp != NULL)
12524 {
12525 if (opt->flags & P_STRING)
12526 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012527 else if (opt->flags & P_NUM)
12528 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012529 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012530 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012531 }
12532 }
12533 }
12534
12535 return d;
12536}
12537#endif