blob: 5a8af316b3d8c67ee64bd8c980e0ad5c4c883b09 [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 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 {(char_u *)600L, (char_u *)0L}
631#else
632 (char_u *)NULL, PV_NONE,
633 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635 SCRIPTID_INIT},
636 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
637#ifdef FEAT_BEVAL
638 (char_u *)&p_beval, PV_NONE,
639 {(char_u *)FALSE, (char_u *)0L}
640#else
641 (char_u *)NULL, PV_NONE,
642 {(char_u *)0L, (char_u *)0L}
643#endif
644 SCRIPTID_INIT},
645 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
646#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
647 (char_u *)&p_bexpr, PV_BEXPR,
648 {(char_u *)"", (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
653 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000654 {"beautify", "bf", P_BOOL|P_VI_DEF,
655 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000656 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200657 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
658 (char_u *)&p_bo, PV_NONE,
659 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000660 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
661 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000662 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000665 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000666 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
667#ifdef FEAT_MBYTE
668 (char_u *)&p_bomb, PV_BOMB,
669#else
670 (char_u *)NULL, PV_NONE,
671#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000672 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
674#ifdef FEAT_LINEBREAK
675 (char_u *)&p_breakat, PV_NONE,
676 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
677#else
678 (char_u *)NULL, PV_NONE,
679 {(char_u *)0L, (char_u *)0L}
680#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000681 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200682 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
683#ifdef FEAT_LINEBREAK
684 (char_u *)VAR_WIN, PV_BRI,
685 {(char_u *)FALSE, (char_u *)0L}
686#else
687 (char_u *)NULL, PV_NONE,
688 {(char_u *)0L, (char_u *)0L}
689#endif
690 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200691 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
692 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200693#ifdef FEAT_LINEBREAK
694 (char_u *)VAR_WIN, PV_BRIOPT,
695 {(char_u *)"", (char_u *)NULL}
696#else
697 (char_u *)NULL, PV_NONE,
698 {(char_u *)"", (char_u *)NULL}
699#endif
700 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
702#ifdef FEAT_BROWSE
703 (char_u *)&p_bsdir, PV_NONE,
704 {(char_u *)"last", (char_u *)0L}
705#else
706 (char_u *)NULL, PV_NONE,
707 {(char_u *)0L, (char_u *)0L}
708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000709 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000710 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
711#if defined(FEAT_QUICKFIX)
712 (char_u *)&p_bh, PV_BH,
713 {(char_u *)"", (char_u *)0L}
714#else
715 (char_u *)NULL, PV_NONE,
716 {(char_u *)0L, (char_u *)0L}
717#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000718 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
720 (char_u *)&p_bl, PV_BL,
721 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
724#if defined(FEAT_QUICKFIX)
725 (char_u *)&p_bt, PV_BT,
726 {(char_u *)"", (char_u *)0L}
727#else
728 (char_u *)NULL, PV_NONE,
729 {(char_u *)0L, (char_u *)0L}
730#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000731 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200732 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000733#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000734 (char_u *)&p_cmp, PV_NONE,
735 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000740 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
742#ifdef FEAT_SEARCHPATH
743 (char_u *)&p_cdpath, PV_NONE,
744 {(char_u *)",,", (char_u *)0L}
745#else
746 (char_u *)NULL, PV_NONE,
747 {(char_u *)0L, (char_u *)0L}
748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000749 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 {"cedit", NULL, P_STRING,
751#ifdef FEAT_CMDWIN
752 (char_u *)&p_cedit, PV_NONE,
753 {(char_u *)"", (char_u *)CTRL_F_STR}
754#else
755 (char_u *)NULL, PV_NONE,
756 {(char_u *)0L, (char_u *)0L}
757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000758 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
760#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
761 (char_u *)&p_ccv, PV_NONE,
762 {(char_u *)"", (char_u *)0L}
763#else
764 (char_u *)NULL, PV_NONE,
765 {(char_u *)0L, (char_u *)0L}
766#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
769#ifdef FEAT_CINDENT
770 (char_u *)&p_cin, PV_CIN,
771#else
772 (char_u *)NULL, PV_NONE,
773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000774 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200775 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776#ifdef FEAT_CINDENT
777 (char_u *)&p_cink, PV_CINK,
778 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
779#else
780 (char_u *)NULL, PV_NONE,
781 {(char_u *)0L, (char_u *)0L}
782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000783 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200784 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000785#ifdef FEAT_CINDENT
786 (char_u *)&p_cino, PV_CINO,
787#else
788 (char_u *)NULL, PV_NONE,
789#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000790 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
793 (char_u *)&p_cinw, PV_CINW,
794 {(char_u *)"if,else,while,do,for,switch",
795 (char_u *)0L}
796#else
797 (char_u *)NULL, PV_NONE,
798 {(char_u *)0L, (char_u *)0L}
799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000800 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200801 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000802#ifdef FEAT_CLIPBOARD
803 (char_u *)&p_cb, PV_NONE,
804# ifdef FEAT_XCLIPBOARD
805 {(char_u *)"autoselect,exclude:cons\\|linux",
806 (char_u *)0L}
807# else
808 {(char_u *)"", (char_u *)0L}
809# endif
810#else
811 (char_u *)NULL, PV_NONE,
812 {(char_u *)"", (char_u *)0L}
813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000814 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000815 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
816 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000817 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
819#ifdef FEAT_CMDWIN
820 (char_u *)&p_cwh, PV_NONE,
821#else
822 (char_u *)NULL, PV_NONE,
823#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000824 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200825 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200826#ifdef FEAT_SYN_HL
827 (char_u *)VAR_WIN, PV_CC,
828#else
829 (char_u *)NULL, PV_NONE,
830#endif
831 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000832 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
833 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000834 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200835 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
836 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837#ifdef FEAT_COMMENTS
838 (char_u *)&p_com, PV_COM,
839 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
840 (char_u *)0L}
841#else
842 (char_u *)NULL, PV_NONE,
843 {(char_u *)0L, (char_u *)0L}
844#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200846 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847#ifdef FEAT_FOLDING
848 (char_u *)&p_cms, PV_CMS,
849 {(char_u *)"/*%s*/", (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 Moolenaar7fd16022007-09-06 14:35:35 +0000855 /* P_PRI_MKRC isn't needed here, optval_default()
856 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000857 {"compatible", "cp", P_BOOL|P_RALL,
858 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000859 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200860 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000861#ifdef FEAT_INS_EXPAND
862 (char_u *)&p_cpt, PV_CPT,
863 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
864#else
865 (char_u *)NULL, PV_NONE,
866 {(char_u *)0L, (char_u *)0L}
867#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000868 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200869 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200870#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200871 (char_u *)VAR_WIN, PV_COCU,
872 {(char_u *)"", (char_u *)NULL}
873#else
874 (char_u *)NULL, PV_NONE,
875 {(char_u *)NULL, (char_u *)0L}
876#endif
877 SCRIPTID_INIT},
878 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
879#ifdef FEAT_CONCEAL
880 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200881#else
882 (char_u *)NULL, PV_NONE,
883#endif
884 {(char_u *)0L, (char_u *)0L}
885 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000886 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
887#ifdef FEAT_COMPL_FUNC
888 (char_u *)&p_cfu, PV_CFU,
889 {(char_u *)"", (char_u *)0L}
890#else
891 (char_u *)NULL, PV_NONE,
892 {(char_u *)0L, (char_u *)0L}
893#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000894 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200895 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000896#ifdef FEAT_INS_EXPAND
897 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000898 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000899#else
900 (char_u *)NULL, PV_NONE,
901 {(char_u *)0L, (char_u *)0L}
902#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000903 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"confirm", "cf", P_BOOL|P_VI_DEF,
905#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
906 (char_u *)&p_confirm, PV_NONE,
907#else
908 (char_u *)NULL, PV_NONE,
909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000913 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
915 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000916 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
918 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000919 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
920 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200921 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200922#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200923 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200924 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200925#else
926 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200927 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200928#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200929 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000930 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
931#ifdef FEAT_CSCOPE
932 (char_u *)&p_cspc, PV_NONE,
933#else
934 (char_u *)NULL, PV_NONE,
935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000936 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_csprg, PV_NONE,
940 {(char_u *)"cscope", (char_u *)0L}
941#else
942 (char_u *)NULL, PV_NONE,
943 {(char_u *)0L, (char_u *)0L}
944#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000945 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200946 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000947#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
948 (char_u *)&p_csqf, PV_NONE,
949 {(char_u *)"", (char_u *)0L}
950#else
951 (char_u *)NULL, PV_NONE,
952 {(char_u *)0L, (char_u *)0L}
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200955 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
956#ifdef FEAT_CSCOPE
957 (char_u *)&p_csre, PV_NONE,
958#else
959 (char_u *)NULL, PV_NONE,
960#endif
961 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
963#ifdef FEAT_CSCOPE
964 (char_u *)&p_cst, 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 Moolenaar071d4272004-06-13 20:20:40 +0000969 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
970#ifdef FEAT_CSCOPE
971 (char_u *)&p_csto, PV_NONE,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000975 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000976 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
977#ifdef FEAT_CSCOPE
978 (char_u *)&p_csverbose, PV_NONE,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200983 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
984#ifdef FEAT_CURSORBIND
985 (char_u *)VAR_WIN, PV_CRBIND,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000990 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
991#ifdef FEAT_SYN_HL
992 (char_u *)VAR_WIN, PV_CUC,
993#else
994 (char_u *)NULL, PV_NONE,
995#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000996 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100997 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000998#ifdef FEAT_SYN_HL
999 (char_u *)VAR_WIN, PV_CUL,
1000#else
1001 (char_u *)NULL, PV_NONE,
1002#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001003 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"debug", NULL, P_STRING|P_VI_DEF,
1005 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001006 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001007 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001009 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001010 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011#else
1012 (char_u *)NULL, PV_NONE,
1013 {(char_u *)NULL, (char_u *)0L}
1014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001015 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1017#ifdef FEAT_MBYTE
1018 (char_u *)&p_deco, PV_NONE,
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 Moolenaar7554da42016-11-25 22:04:13 +01001023 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001025 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026#else
1027 (char_u *)NULL, PV_NONE,
1028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001029 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1031#ifdef FEAT_DIFF
1032 (char_u *)VAR_WIN, PV_DIFF,
1033#else
1034 (char_u *)NULL, PV_NONE,
1035#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001036 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001037 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1039 (char_u *)&p_dex, PV_NONE,
1040 {(char_u *)"", (char_u *)0L}
1041#else
1042 (char_u *)NULL, PV_NONE,
1043 {(char_u *)0L, (char_u *)0L}
1044#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001045 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001046 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1047 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048#ifdef FEAT_DIFF
1049 (char_u *)&p_dip, PV_NONE,
1050 {(char_u *)"filler", (char_u *)NULL}
1051#else
1052 (char_u *)NULL, PV_NONE,
1053 {(char_u *)"", (char_u *)NULL}
1054#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001055 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1057#ifdef FEAT_DIGRAPHS
1058 (char_u *)&p_dg, PV_NONE,
1059#else
1060 (char_u *)NULL, PV_NONE,
1061#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001062 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001063 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1064 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001067 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001069 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001071#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 (char_u *)&p_ead, PV_NONE,
1073 {(char_u *)"both", (char_u *)0L}
1074#else
1075 (char_u *)NULL, PV_NONE,
1076 {(char_u *)NULL, (char_u *)0L}
1077#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001078 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1080 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001081 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001082 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1083#if defined(FEAT_MBYTE)
1084 (char_u *)&p_emoji, PV_NONE,
1085 {(char_u *)TRUE, (char_u *)0L}
1086#else
1087 (char_u *)NULL, PV_NONE,
1088 {(char_u *)0L, (char_u *)0L}
1089#endif
1090 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001091 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092#ifdef FEAT_MBYTE
1093 (char_u *)&p_enc, PV_NONE,
1094 {(char_u *)ENC_DFLT, (char_u *)0L}
1095#else
1096 (char_u *)NULL, PV_NONE,
1097 {(char_u *)0L, (char_u *)0L}
1098#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001099 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1101 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001102 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1104 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001105 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001107 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001108 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001109 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1110 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001111 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1113#ifdef FEAT_QUICKFIX
1114 (char_u *)&p_ef, PV_NONE,
1115 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1116#else
1117 (char_u *)NULL, PV_NONE,
1118 {(char_u *)NULL, (char_u *)0L}
1119#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001120 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001121 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001123 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125#else
1126 (char_u *)NULL, PV_NONE,
1127 {(char_u *)NULL, (char_u *)0L}
1128#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001129 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130 {"esckeys", "ek", P_BOOL|P_VIM,
1131 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001132 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001133 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134#ifdef FEAT_AUTOCMD
1135 (char_u *)&p_ei, PV_NONE,
1136#else
1137 (char_u *)NULL, PV_NONE,
1138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001139 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1141 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001142 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1144 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001145 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001146 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1147 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148#ifdef FEAT_MBYTE
1149 (char_u *)&p_fenc, PV_FENC,
1150 {(char_u *)"", (char_u *)0L}
1151#else
1152 (char_u *)NULL, PV_NONE,
1153 {(char_u *)0L, (char_u *)0L}
1154#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001155 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001156 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157#ifdef FEAT_MBYTE
1158 (char_u *)&p_fencs, PV_NONE,
1159 {(char_u *)"ucs-bom", (char_u *)0L}
1160#else
1161 (char_u *)NULL, PV_NONE,
1162 {(char_u *)0L, (char_u *)0L}
1163#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001164 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001165 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1166 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001169 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001170 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001171 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1172 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001173 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1174 (char_u *)&p_fic, PV_NONE,
1175 {
1176#ifdef CASE_INSENSITIVE_FILENAME
1177 (char_u *)TRUE,
1178#else
1179 (char_u *)FALSE,
1180#endif
1181 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001182 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001183#ifdef FEAT_AUTOCMD
1184 (char_u *)&p_ft, PV_FT,
1185 {(char_u *)"", (char_u *)0L}
1186#else
1187 (char_u *)NULL, PV_NONE,
1188 {(char_u *)0L, (char_u *)0L}
1189#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001190 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001191 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1193 (char_u *)&p_fcs, PV_NONE,
1194 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1195#else
1196 (char_u *)NULL, PV_NONE,
1197 {(char_u *)"", (char_u *)0L}
1198#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001199 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001200 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1201 (char_u *)&p_fixeol, PV_FIXEOL,
1202 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1204#ifdef FEAT_FKMAP
1205 (char_u *)&p_fkmap, PV_NONE,
1206#else
1207 (char_u *)NULL, PV_NONE,
1208#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001209 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 {"flash", "fl", P_BOOL|P_VI_DEF,
1211 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001212 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001213#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001214 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1218 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1221 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001222 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1224# ifdef FEAT_EVAL
1225 (char_u *)VAR_WIN, PV_FDE,
1226 {(char_u *)"0", (char_u *)NULL}
1227# else
1228 (char_u *)NULL, PV_NONE,
1229 {(char_u *)NULL, (char_u *)0L}
1230# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001231 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1233 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001234 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1236 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001238 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001239 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001240 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001241 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001242 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001243 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244 {(char_u *)"{{{,}}}", (char_u *)NULL}
1245 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001246 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1247 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001248 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1250 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001251 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001252 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1253 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001254 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001255 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001256 (char_u *)&p_fdo, PV_NONE,
1257 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001258 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001259 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1260# ifdef FEAT_EVAL
1261 (char_u *)VAR_WIN, PV_FDT,
1262 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001263# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 (char_u *)NULL, PV_NONE,
1265 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001266# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001267 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001268#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001269 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001270#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001271 (char_u *)&p_fex, PV_FEX,
1272 {(char_u *)"", (char_u *)0L}
1273#else
1274 (char_u *)NULL, PV_NONE,
1275 {(char_u *)0L, (char_u *)0L}
1276#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001277 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001278 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1279 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001280 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1281 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001282 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1283 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1285 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001287 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001288 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001289 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1290#ifdef HAVE_FSYNC
1291 (char_u *)&p_fs, PV_NONE,
1292 {(char_u *)TRUE, (char_u *)0L}
1293#else
1294 (char_u *)NULL, PV_NONE,
1295 {(char_u *)FALSE, (char_u *)0L}
1296#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001297 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1299 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001300 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301 {"graphic", "gr", P_BOOL|P_VI_DEF,
1302 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001303 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001304 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001305#ifdef FEAT_QUICKFIX
1306 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001307 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308#else
1309 (char_u *)NULL, PV_NONE,
1310 {(char_u *)NULL, (char_u *)0L}
1311#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001312 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1314#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001315 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316 {
1317# ifdef WIN3264
1318 /* may be changed to "grep -n" in os_win32.c */
1319 (char_u *)"findstr /n",
1320# else
1321# ifdef UNIX
1322 /* Add an extra file name so that grep will always
1323 * insert a file name in the match line. */
1324 (char_u *)"grep -n $* /dev/null",
1325# else
1326# ifdef VMS
1327 (char_u *)"SEARCH/NUMBERS ",
1328# else
1329 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001330# endif
1331# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001333 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334#else
1335 (char_u *)NULL, PV_NONE,
1336 {(char_u *)NULL, (char_u *)0L}
1337#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001338 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001339 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340#ifdef CURSOR_SHAPE
1341 (char_u *)&p_guicursor, PV_NONE,
1342 {
1343# ifdef FEAT_GUI
1344 (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 +01001345# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001346 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1347# endif
1348 (char_u *)0L}
1349#else
1350 (char_u *)NULL, PV_NONE,
1351 {(char_u *)NULL, (char_u *)0L}
1352#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001353 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001354 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001355#ifdef FEAT_GUI
1356 (char_u *)&p_guifont, PV_NONE,
1357 {(char_u *)"", (char_u *)0L}
1358#else
1359 (char_u *)NULL, PV_NONE,
1360 {(char_u *)NULL, (char_u *)0L}
1361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001362 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001363 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1365 (char_u *)&p_guifontset, PV_NONE,
1366 {(char_u *)"", (char_u *)0L}
1367#else
1368 (char_u *)NULL, PV_NONE,
1369 {(char_u *)NULL, (char_u *)0L}
1370#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001371 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001372 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001373#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1374 (char_u *)&p_guifontwide, PV_NONE,
1375 {(char_u *)"", (char_u *)0L}
1376#else
1377 (char_u *)NULL, PV_NONE,
1378 {(char_u *)NULL, (char_u *)0L}
1379#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001380 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001382#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 (char_u *)&p_ghr, PV_NONE,
1384#else
1385 (char_u *)NULL, PV_NONE,
1386#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001387 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001388 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001389#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390 (char_u *)&p_go, PV_NONE,
1391# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001392 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001394 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395# endif
1396#else
1397 (char_u *)NULL, PV_NONE,
1398 {(char_u *)NULL, (char_u *)0L}
1399#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401 {"guipty", NULL, P_BOOL|P_VI_DEF,
1402#if defined(FEAT_GUI)
1403 (char_u *)&p_guipty, PV_NONE,
1404#else
1405 (char_u *)NULL, PV_NONE,
1406#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001407 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001408 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001409#if defined(FEAT_GUI_TABLINE)
1410 (char_u *)&p_gtl, PV_NONE,
1411 {(char_u *)"", (char_u *)0L}
1412#else
1413 (char_u *)NULL, PV_NONE,
1414 {(char_u *)NULL, (char_u *)0L}
1415#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001416 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001417 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001418#if defined(FEAT_GUI_TABLINE)
1419 (char_u *)&p_gtt, PV_NONE,
1420 {(char_u *)"", (char_u *)0L}
1421#else
1422 (char_u *)NULL, PV_NONE,
1423 {(char_u *)NULL, (char_u *)0L}
1424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001425 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001426 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1427 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001428 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001429 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1430 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001431 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1432 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"helpheight", "hh", P_NUM|P_VI_DEF,
1434#ifdef FEAT_WINDOWS
1435 (char_u *)&p_hh, PV_NONE,
1436#else
1437 (char_u *)NULL, PV_NONE,
1438#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001439 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001440 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441#ifdef FEAT_MULTI_LANG
1442 (char_u *)&p_hlg, PV_NONE,
1443 {(char_u *)"", (char_u *)0L}
1444#else
1445 (char_u *)NULL, PV_NONE,
1446 {(char_u *)0L, (char_u *)0L}
1447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001448 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 {"hidden", "hid", P_BOOL|P_VI_DEF,
1450 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001452 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001454 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1455 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456 {"history", "hi", P_NUM|P_VIM,
1457 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001458 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1460#ifdef FEAT_RIGHTLEFT
1461 (char_u *)&p_hkmap, PV_NONE,
1462#else
1463 (char_u *)NULL, PV_NONE,
1464#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001465 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1467#ifdef FEAT_RIGHTLEFT
1468 (char_u *)&p_hkmapp, PV_NONE,
1469#else
1470 (char_u *)NULL, PV_NONE,
1471#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001472 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1474 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"icon", NULL, P_BOOL|P_VI_DEF,
1477#ifdef FEAT_TITLE
1478 (char_u *)&p_icon, PV_NONE,
1479#else
1480 (char_u *)NULL, PV_NONE,
1481#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001482 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483 {"iconstring", NULL, P_STRING|P_VI_DEF,
1484#ifdef FEAT_TITLE
1485 (char_u *)&p_iconstring, PV_NONE,
1486#else
1487 (char_u *)NULL, PV_NONE,
1488#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001489 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1491 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001493 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1494# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1495 (char_u *)&p_imaf, PV_NONE,
1496 {(char_u *)"", (char_u *)NULL}
1497# else
1498 (char_u *)NULL, PV_NONE,
1499 {(char_u *)NULL, (char_u *)0L}
1500# endif
1501 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001503#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 (char_u *)&p_imak, PV_NONE,
1505#else
1506 (char_u *)NULL, PV_NONE,
1507#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001508 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1510#ifdef USE_IM_CONTROL
1511 (char_u *)&p_imcmdline, PV_NONE,
1512#else
1513 (char_u *)NULL, PV_NONE,
1514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1517#ifdef USE_IM_CONTROL
1518 (char_u *)&p_imdisable, PV_NONE,
1519#else
1520 (char_u *)NULL, PV_NONE,
1521#endif
1522#ifdef __sgi
1523 {(char_u *)TRUE, (char_u *)0L}
1524#else
1525 {(char_u *)FALSE, (char_u *)0L}
1526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001527 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 {"iminsert", "imi", P_NUM|P_VI_DEF,
1529 (char_u *)&p_iminsert, PV_IMI,
1530#ifdef B_IMODE_IM
1531 {(char_u *)B_IMODE_IM, (char_u *)0L}
1532#else
1533 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1534#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001535 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001536 {"imsearch", "ims", P_NUM|P_VI_DEF,
1537 (char_u *)&p_imsearch, PV_IMS,
1538#ifdef B_IMODE_IM
1539 {(char_u *)B_IMODE_IM, (char_u *)0L}
1540#else
1541 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1542#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001543 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001544 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001545# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1546 (char_u *)&p_imsf, PV_NONE,
1547 {(char_u *)"", (char_u *)NULL}
1548# else
1549 (char_u *)NULL, PV_NONE,
1550 {(char_u *)NULL, (char_u *)0L}
1551# endif
1552 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001553 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1554#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001555 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001556 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1557#else
1558 (char_u *)NULL, PV_NONE,
1559 {(char_u *)0L, (char_u *)0L}
1560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001561 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001562 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1563#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1564 (char_u *)&p_inex, PV_INEX,
1565 {(char_u *)"", (char_u *)0L}
1566#else
1567 (char_u *)NULL, PV_NONE,
1568 {(char_u *)0L, (char_u *)0L}
1569#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1572 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1575#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1576 (char_u *)&p_inde, PV_INDE,
1577 {(char_u *)"", (char_u *)0L}
1578#else
1579 (char_u *)NULL, PV_NONE,
1580 {(char_u *)0L, (char_u *)0L}
1581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001582 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001583 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1585 (char_u *)&p_indk, PV_INDK,
1586 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1587#else
1588 (char_u *)NULL, PV_NONE,
1589 {(char_u *)0L, (char_u *)0L}
1590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001591 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001592 {"infercase", "inf", P_BOOL|P_VI_DEF,
1593 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001594 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1596 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001597 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001598 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1599 (char_u *)&p_isf, PV_NONE,
1600 {
1601#ifdef BACKSLASH_IN_FILENAME
1602 /* Excluded are: & and ^ are special in cmd.exe
1603 * ( and ) are used in text separating fnames */
1604 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1605#else
1606# ifdef AMIGA
1607 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1608# else
1609# ifdef VMS
1610 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1611# else /* UNIX et al. */
1612# ifdef EBCDIC
1613 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1614# else
1615 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1616# endif
1617# endif
1618# endif
1619#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001620 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001621 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1622 (char_u *)&p_isi, PV_NONE,
1623 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001624#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001625 (char_u *)"@,48-57,_,128-167,224-235",
1626#else
1627# ifdef EBCDIC
1628 /* TODO: EBCDIC Check this! @ == isalpha()*/
1629 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1630 "112-120,128,140-142,156,158,172,"
1631 "174,186,191,203-207,219-225,235-239,"
1632 "251-254",
1633# else
1634 (char_u *)"@,48-57,_,192-255",
1635# endif
1636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1639 (char_u *)&p_isk, PV_ISK,
1640 {
1641#ifdef EBCDIC
1642 (char_u *)"@,240-249,_",
1643 /* TODO: EBCDIC Check this! @ == isalpha()*/
1644 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1645 "112-120,128,140-142,156,158,172,"
1646 "174,186,191,203-207,219-225,235-239,"
1647 "251-254",
1648#else
1649 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001650# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 (char_u *)"@,48-57,_,128-167,224-235"
1652# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001653 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654# endif
1655#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001656 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001657 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1658 (char_u *)&p_isp, PV_NONE,
1659 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001660#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 || defined(VMS)
1662 (char_u *)"@,~-255",
1663#else
1664# ifdef EBCDIC
1665 /* all chars above 63 are printable */
1666 (char_u *)"63-255",
1667# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001668 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669# endif
1670#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001671 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1673 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001674 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1676#ifdef FEAT_CRYPT
1677 (char_u *)&p_key, PV_KEY,
1678 {(char_u *)"", (char_u *)0L}
1679#else
1680 (char_u *)NULL, PV_NONE,
1681 {(char_u *)0L, (char_u *)0L}
1682#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001683 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001684 {"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 +00001685#ifdef FEAT_KEYMAP
1686 (char_u *)&p_keymap, PV_KMAP,
1687 {(char_u *)"", (char_u *)0L}
1688#else
1689 (char_u *)NULL, PV_NONE,
1690 {(char_u *)"", (char_u *)0L}
1691#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001692 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001693 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001695 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001697 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001699#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 (char_u *)":help",
1701#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001702# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001704# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001705# ifdef USEMAN_S
1706 (char_u *)"man -s",
1707# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001709# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710# endif
1711#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001712 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001713 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714#ifdef FEAT_LANGMAP
1715 (char_u *)&p_langmap, PV_NONE,
1716 {(char_u *)"", /* unmatched } */
1717#else
1718 (char_u *)NULL, PV_NONE,
1719 {(char_u *)NULL,
1720#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001721 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001722 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1724 (char_u *)&p_lm, PV_NONE,
1725#else
1726 (char_u *)NULL, PV_NONE,
1727#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001728 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001729 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1730#ifdef FEAT_LANGMAP
1731 (char_u *)&p_lnr, PV_NONE,
1732#else
1733 (char_u *)NULL, PV_NONE,
1734#endif
1735 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001736 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1737#ifdef FEAT_LANGMAP
1738 (char_u *)&p_lrm, PV_NONE,
1739#else
1740 (char_u *)NULL, PV_NONE,
1741#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001742 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1744#ifdef FEAT_WINDOWS
1745 (char_u *)&p_ls, PV_NONE,
1746#else
1747 (char_u *)NULL, PV_NONE,
1748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001749 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1751 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001752 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001753 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1754#ifdef FEAT_LINEBREAK
1755 (char_u *)VAR_WIN, PV_LBR,
1756#else
1757 (char_u *)NULL, PV_NONE,
1758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001760 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1761 (char_u *)&Rows, PV_NONE,
1762 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001763#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 (char_u *)25L,
1765#else
1766 (char_u *)24L,
1767#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001768 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1770#ifdef FEAT_GUI
1771 (char_u *)&p_linespace, PV_NONE,
1772#else
1773 (char_u *)NULL, PV_NONE,
1774#endif
1775#ifdef FEAT_GUI_W32
1776 {(char_u *)1L, (char_u *)0L}
1777#else
1778 {(char_u *)0L, (char_u *)0L}
1779#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001780 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781 {"lisp", NULL, P_BOOL|P_VI_DEF,
1782#ifdef FEAT_LISP
1783 (char_u *)&p_lisp, PV_LISP,
1784#else
1785 (char_u *)NULL, PV_NONE,
1786#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001787 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001788 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001790 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1792#else
1793 (char_u *)NULL, PV_NONE,
1794 {(char_u *)"", (char_u *)0L}
1795#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001796 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1798 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001799 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001800 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001801 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001802 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1804 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001805 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001806#if defined(DYNAMIC_LUA)
Bram Moolenaara6e42502016-04-20 16:19:52 +02001807 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001808 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001809 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1810 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001811#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001812#ifdef FEAT_GUI_MAC
1813 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1814 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001815 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"magic", NULL, P_BOOL|P_VI_DEF,
1818 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001820 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001821#ifdef FEAT_QUICKFIX
1822 (char_u *)&p_mef, PV_NONE,
1823 {(char_u *)"", (char_u *)0L}
1824#else
1825 (char_u *)NULL, PV_NONE,
1826 {(char_u *)NULL, (char_u *)0L}
1827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001828 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1830#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001831 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832# ifdef VMS
1833 {(char_u *)"MMS", (char_u *)0L}
1834# else
1835 {(char_u *)"make", (char_u *)0L}
1836# endif
1837#else
1838 (char_u *)NULL, PV_NONE,
1839 {(char_u *)NULL, (char_u *)0L}
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001842 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001843 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001844 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1845 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001846 {"matchtime", "mat", P_NUM|P_VI_DEF,
1847 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001849 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001850#ifdef FEAT_MBYTE
1851 (char_u *)&p_mco, PV_NONE,
1852#else
1853 (char_u *)NULL, PV_NONE,
1854#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001855 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1857#ifdef FEAT_EVAL
1858 (char_u *)&p_mfd, PV_NONE,
1859#else
1860 (char_u *)NULL, PV_NONE,
1861#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1864 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001865 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 {"maxmem", "mm", P_NUM|P_VI_DEF,
1867 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1869 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001870 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1871 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1874 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001875 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1876 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"menuitems", "mis", P_NUM|P_VI_DEF,
1878#ifdef FEAT_MENU
1879 (char_u *)&p_mis, PV_NONE,
1880#else
1881 (char_u *)NULL, PV_NONE,
1882#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001883 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001884 {"mesg", NULL, P_BOOL|P_VI_DEF,
1885 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001886 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001887 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001888#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001889 (char_u *)&p_msm, PV_NONE,
1890 {(char_u *)"460000,2000,500", (char_u *)0L}
1891#else
1892 (char_u *)NULL, PV_NONE,
1893 {(char_u *)0L, (char_u *)0L}
1894#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001895 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"modeline", "ml", P_BOOL|P_VIM,
1897 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001898 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"modelines", "mls", P_NUM|P_VI_DEF,
1900 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001901 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1903 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001904 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1906 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001907 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 {"more", NULL, P_BOOL|P_VIM,
1909 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001910 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001911 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1912 (char_u *)&p_mouse, PV_NONE,
1913 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001914#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001915 (char_u *)"a",
1916#else
1917 (char_u *)"",
1918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1921#ifdef FEAT_GUI
1922 (char_u *)&p_mousef, PV_NONE,
1923#else
1924 (char_u *)NULL, PV_NONE,
1925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001926 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1928#ifdef FEAT_GUI
1929 (char_u *)&p_mh, PV_NONE,
1930#else
1931 (char_u *)NULL, PV_NONE,
1932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001933 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1935 (char_u *)&p_mousem, PV_NONE,
1936 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001937#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 (char_u *)"popup",
1939#else
1940# if defined(MACOS)
1941 (char_u *)"popup_setpos",
1942# else
1943 (char_u *)"extend",
1944# endif
1945#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001947 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948#ifdef FEAT_MOUSESHAPE
1949 (char_u *)&p_mouseshape, PV_NONE,
1950 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1951#else
1952 (char_u *)NULL, PV_NONE,
1953 {(char_u *)NULL, (char_u *)0L}
1954#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001955 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1957 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001959 {"mzquantum", "mzq", P_NUM,
1960#ifdef FEAT_MZSCHEME
1961 (char_u *)&p_mzq, PV_NONE,
1962#else
1963 (char_u *)NULL, PV_NONE,
1964#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001965 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001966 {"novice", NULL, P_BOOL|P_VI_DEF,
1967 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001968 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001969 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001971 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1974 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001976 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1977#ifdef FEAT_LINEBREAK
1978 (char_u *)VAR_WIN, PV_NUW,
1979#else
1980 (char_u *)NULL, PV_NONE,
1981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001982 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001983 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001984#ifdef FEAT_COMPL_FUNC
1985 (char_u *)&p_ofu, PV_OFU,
1986 {(char_u *)"", (char_u *)0L}
1987#else
1988 (char_u *)NULL, PV_NONE,
1989 {(char_u *)0L, (char_u *)0L}
1990#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"open", NULL, 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 Moolenaar043545e2006-10-10 16:44:07 +00001995 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001996#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001997 (char_u *)&p_odev, PV_NONE,
1998#else
1999 (char_u *)NULL, PV_NONE,
2000#endif
2001 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002002 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002003 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2004 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002005 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {"optimize", "opt", P_BOOL|P_VI_DEF,
2007 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002009 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002011 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002012 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2013 |P_SECURE,
2014 (char_u *)&p_pp, PV_NONE,
2015 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2016 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 {"paragraphs", "para", P_STRING|P_VI_DEF,
2018 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002019 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002020 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002021 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002023 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2025 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002026 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2028#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2029 (char_u *)&p_pex, PV_NONE,
2030 {(char_u *)"", (char_u *)0L}
2031#else
2032 (char_u *)NULL, PV_NONE,
2033 {(char_u *)0L, (char_u *)0L}
2034#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002035 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002036 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002038 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002040 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002041 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002042#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 (char_u *)".,,",
2044#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002045 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002047 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002048#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002049 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002050 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002051 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2052 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002053#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2055 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002057 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2059 (char_u *)&p_pvh, PV_NONE,
2060#else
2061 (char_u *)NULL, PV_NONE,
2062#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002063 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2065#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2066 (char_u *)VAR_WIN, PV_PVW,
2067#else
2068 (char_u *)NULL, PV_NONE,
2069#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002070 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002071 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072#ifdef FEAT_PRINTER
2073 (char_u *)&p_pdev, PV_NONE,
2074 {(char_u *)"", (char_u *)0L}
2075#else
2076 (char_u *)NULL, PV_NONE,
2077 {(char_u *)NULL, (char_u *)0L}
2078#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002079 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080 {"printencoding", "penc", P_STRING|P_VI_DEF,
2081#ifdef FEAT_POSTSCRIPT
2082 (char_u *)&p_penc, PV_NONE,
2083 {(char_u *)"", (char_u *)0L}
2084#else
2085 (char_u *)NULL, PV_NONE,
2086 {(char_u *)NULL, (char_u *)0L}
2087#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002088 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002089 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002090#ifdef FEAT_POSTSCRIPT
2091 (char_u *)&p_pexpr, PV_NONE,
2092 {(char_u *)"", (char_u *)0L}
2093#else
2094 (char_u *)NULL, PV_NONE,
2095 {(char_u *)NULL, (char_u *)0L}
2096#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002097 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 {"printfont", "pfn", P_STRING|P_VI_DEF,
2099#ifdef FEAT_PRINTER
2100 (char_u *)&p_pfn, PV_NONE,
2101 {
2102# ifdef MSWIN
2103 (char_u *)"Courier_New:h10",
2104# else
2105 (char_u *)"courier",
2106# endif
2107 (char_u *)0L}
2108#else
2109 (char_u *)NULL, PV_NONE,
2110 {(char_u *)NULL, (char_u *)0L}
2111#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2114#ifdef FEAT_PRINTER
2115 (char_u *)&p_header, PV_NONE,
2116 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2117#else
2118 (char_u *)NULL, PV_NONE,
2119 {(char_u *)NULL, (char_u *)0L}
2120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002122 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2123#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2124 (char_u *)&p_pmcs, PV_NONE,
2125 {(char_u *)"", (char_u *)0L}
2126#else
2127 (char_u *)NULL, PV_NONE,
2128 {(char_u *)NULL, (char_u *)0L}
2129#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002130 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002131 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2132#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2133 (char_u *)&p_pmfn, PV_NONE,
2134 {(char_u *)"", (char_u *)0L}
2135#else
2136 (char_u *)NULL, PV_NONE,
2137 {(char_u *)NULL, (char_u *)0L}
2138#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002139 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002140 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141#ifdef FEAT_PRINTER
2142 (char_u *)&p_popt, PV_NONE,
2143 {(char_u *)"", (char_u *)0L}
2144#else
2145 (char_u *)NULL, PV_NONE,
2146 {(char_u *)NULL, (char_u *)0L}
2147#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002148 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002150 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002151 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002152 {"pumheight", "ph", P_NUM|P_VI_DEF,
2153#ifdef FEAT_INS_EXPAND
2154 (char_u *)&p_ph, PV_NONE,
2155#else
2156 (char_u *)NULL, PV_NONE,
2157#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002158 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002159#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002160 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002161 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002162 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2163 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002164#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002165#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002166 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002167 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002168 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2169 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002170#endif
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002171 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2172#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2173 (char_u *)&p_pyx, PV_NONE,
2174#else
2175 (char_u *)NULL, PV_NONE,
2176#endif
2177 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2178 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002179 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2180#ifdef FEAT_TEXTOBJ
2181 (char_u *)&p_qe, PV_QE,
2182 {(char_u *)"\\", (char_u *)0L}
2183#else
2184 (char_u *)NULL, PV_NONE,
2185 {(char_u *)NULL, (char_u *)0L}
2186#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002187 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002188 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2189 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002190 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002191 {"redraw", NULL, P_BOOL|P_VI_DEF,
2192 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002193 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002194 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2195#ifdef FEAT_RELTIME
2196 (char_u *)&p_rdt, PV_NONE,
2197#else
2198 (char_u *)NULL, PV_NONE,
2199#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002200 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002201 {"regexpengine", "re", P_NUM|P_VI_DEF,
2202 (char_u *)&p_re, PV_NONE,
2203 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002204 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2205 (char_u *)VAR_WIN, PV_RNU,
2206 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002207 {"remap", NULL, P_BOOL|P_VI_DEF,
2208 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002209 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002210 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002211#ifdef FEAT_RENDER_OPTIONS
2212 (char_u *)&p_rop, PV_NONE,
2213 {(char_u *)"", (char_u *)0L}
2214#else
2215 (char_u *)NULL, PV_NONE,
2216 {(char_u *)NULL, (char_u *)0L}
2217#endif
2218 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002219 {"report", NULL, P_NUM|P_VI_DEF,
2220 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2223#ifdef WIN3264
2224 (char_u *)&p_rs, PV_NONE,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2230#ifdef FEAT_RIGHTLEFT
2231 (char_u *)&p_ri, PV_NONE,
2232#else
2233 (char_u *)NULL, PV_NONE,
2234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002235 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002236 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2237#ifdef FEAT_RIGHTLEFT
2238 (char_u *)VAR_WIN, PV_RL,
2239#else
2240 (char_u *)NULL, PV_NONE,
2241#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002242 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002243 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2244#ifdef FEAT_RIGHTLEFT
2245 (char_u *)VAR_WIN, PV_RLC,
2246 {(char_u *)"search", (char_u *)NULL}
2247#else
2248 (char_u *)NULL, PV_NONE,
2249 {(char_u *)NULL, (char_u *)0L}
2250#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002251 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002252#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002253 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002254 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002255 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2256 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002258 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2259#ifdef FEAT_CMDL_INFO
2260 (char_u *)&p_ru, PV_NONE,
2261#else
2262 (char_u *)NULL, PV_NONE,
2263#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002264 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2266#ifdef FEAT_STL_OPT
2267 (char_u *)&p_ruf, PV_NONE,
2268#else
2269 (char_u *)NULL, PV_NONE,
2270#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002271 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002272 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2273 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2276 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2278 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002279 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2281#ifdef FEAT_SCROLLBIND
2282 (char_u *)VAR_WIN, PV_SCBIND,
2283#else
2284 (char_u *)NULL, PV_NONE,
2285#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002286 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002287 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2288 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002289 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2291 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002293 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002294#ifdef FEAT_SCROLLBIND
2295 (char_u *)&p_sbo, PV_NONE,
2296 {(char_u *)"ver,jump", (char_u *)0L}
2297#else
2298 (char_u *)NULL, PV_NONE,
2299 {(char_u *)0L, (char_u *)0L}
2300#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"sections", "sect", P_STRING|P_VI_DEF,
2303 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2305 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2307 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002308 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002309 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002310 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 {(char_u *)"inclusive", (char_u *)0L}
2312 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002313 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002315 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002316 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002317#ifdef FEAT_SESSION
2318 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002319 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 (char_u *)0L}
2321#else
2322 (char_u *)NULL, PV_NONE,
2323 {(char_u *)0L, (char_u *)0L}
2324#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002325 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2327 (char_u *)&p_sh, PV_NONE,
2328 {
2329#ifdef VMS
2330 (char_u *)"-",
2331#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002332# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002334# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336# endif
2337#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002338 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2340 (char_u *)&p_shcf, PV_NONE,
2341 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002342#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 (char_u *)"/c",
2344#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002345 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002347 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002348 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2349#ifdef FEAT_QUICKFIX
2350 (char_u *)&p_sp, PV_NONE,
2351 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002352#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354#else
2355 (char_u *)">",
2356#endif
2357 (char_u *)0L}
2358#else
2359 (char_u *)NULL, PV_NONE,
2360 {(char_u *)0L, (char_u *)0L}
2361#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002362 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2364 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2367 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002368 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2370#ifdef BACKSLASH_IN_FILENAME
2371 (char_u *)&p_ssl, PV_NONE,
2372#else
2373 (char_u *)NULL, PV_NONE,
2374#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002376 {"shelltemp", "stmp", P_BOOL,
2377 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"shelltype", "st", P_NUM|P_VI_DEF,
2380#ifdef AMIGA
2381 (char_u *)&p_st, PV_NONE,
2382#else
2383 (char_u *)NULL, PV_NONE,
2384#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002385 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2387 (char_u *)&p_sxq, PV_NONE,
2388 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002389#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 (char_u *)"\"",
2391#else
2392 (char_u *)"",
2393#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002395 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2396 (char_u *)&p_sxe, PV_NONE,
2397 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002398#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002399 (char_u *)"\"&|<>()@^",
2400#else
2401 (char_u *)"",
2402#endif
2403 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002404 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2405 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002406 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2408 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2411 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002412 {(char_u *)"", (char_u *)"filnxtToO"}
2413 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002414 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002415 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002416 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2418#ifdef FEAT_LINEBREAK
2419 (char_u *)&p_sbr, PV_NONE,
2420#else
2421 (char_u *)NULL, PV_NONE,
2422#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002423 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"showcmd", "sc", P_BOOL|P_VIM,
2425#ifdef FEAT_CMDL_INFO
2426 (char_u *)&p_sc, PV_NONE,
2427#else
2428 (char_u *)NULL, PV_NONE,
2429#endif
2430 {(char_u *)FALSE,
2431#ifdef UNIX
2432 (char_u *)FALSE
2433#else
2434 (char_u *)TRUE
2435#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002436 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2438 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002439 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2441 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002442 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002443 {"showmode", "smd", P_BOOL|P_VIM,
2444 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002445 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002446 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2447#ifdef FEAT_WINDOWS
2448 (char_u *)&p_stal, PV_NONE,
2449#else
2450 (char_u *)NULL, PV_NONE,
2451#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002453 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2454 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002455 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002456 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2457 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002458 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002459 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2460#ifdef FEAT_SIGNS
2461 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002462 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002463#else
2464 (char_u *)NULL, PV_NONE,
2465 {(char_u *)NULL, (char_u *)0L}
2466#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002467 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2469 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002470 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2472 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002473 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2475#ifdef FEAT_SMARTINDENT
2476 (char_u *)&p_si, PV_SI,
2477#else
2478 (char_u *)NULL, PV_NONE,
2479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002480 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2482 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002483 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2485 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002486 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2488 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002489 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002490 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002491#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002492 (char_u *)VAR_WIN, PV_SPELL,
2493#else
2494 (char_u *)NULL, PV_NONE,
2495#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002496 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002497 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002498#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002499 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002500 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002501#else
2502 (char_u *)NULL, PV_NONE,
2503 {(char_u *)0L, (char_u *)0L}
2504#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002505 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002506 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2507 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002508#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002509 (char_u *)&p_spf, PV_SPF,
2510 {(char_u *)"", (char_u *)0L}
2511#else
2512 (char_u *)NULL, PV_NONE,
2513 {(char_u *)0L, (char_u *)0L}
2514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002515 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002516 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2517 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002518#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002519 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002520 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002521#else
2522 (char_u *)NULL, PV_NONE,
2523 {(char_u *)0L, (char_u *)0L}
2524#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002526 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002527#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002528 (char_u *)&p_sps, PV_NONE,
2529 {(char_u *)"best", (char_u *)0L}
2530#else
2531 (char_u *)NULL, PV_NONE,
2532 {(char_u *)0L, (char_u *)0L}
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2536#ifdef FEAT_WINDOWS
2537 (char_u *)&p_sb, PV_NONE,
2538#else
2539 (char_u *)NULL, PV_NONE,
2540#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002543#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002544 (char_u *)&p_spr, PV_NONE,
2545#else
2546 (char_u *)NULL, PV_NONE,
2547#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002548 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002549 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2550 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002551 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002552 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2553#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002554 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002555#else
2556 (char_u *)NULL, PV_NONE,
2557#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002558 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002559 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 (char_u *)&p_su, PV_NONE,
2561 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002562 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002563 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002564#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 (char_u *)&p_sua, PV_SUA,
2566 {(char_u *)"", (char_u *)0L}
2567#else
2568 (char_u *)NULL, PV_NONE,
2569 {(char_u *)0L, (char_u *)0L}
2570#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002571 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2573 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002574 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"swapsync", "sws", P_STRING|P_VI_DEF,
2576 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002577 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002578 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002580 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002581 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2582#ifdef FEAT_SYN_HL
2583 (char_u *)&p_smc, PV_SMC,
2584 {(char_u *)3000L, (char_u *)0L}
2585#else
2586 (char_u *)NULL, PV_NONE,
2587 {(char_u *)0L, (char_u *)0L}
2588#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002589 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002590 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591#ifdef FEAT_SYN_HL
2592 (char_u *)&p_syn, PV_SYN,
2593 {(char_u *)"", (char_u *)0L}
2594#else
2595 (char_u *)NULL, PV_NONE,
2596 {(char_u *)0L, (char_u *)0L}
2597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002599 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2600#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002601 (char_u *)&p_tal, PV_NONE,
2602#else
2603 (char_u *)NULL, PV_NONE,
2604#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002605 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002606 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2607#ifdef FEAT_WINDOWS
2608 (char_u *)&p_tpm, PV_NONE,
2609#else
2610 (char_u *)NULL, PV_NONE,
2611#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002612 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2614 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002615 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2617 (char_u *)&p_tbs, PV_NONE,
2618#ifdef VMS /* binary searching doesn't appear to work on VMS */
2619 {(char_u *)0L, (char_u *)0L}
2620#else
2621 {(char_u *)TRUE, (char_u *)0L}
2622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002623 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002624 {"tagcase", "tc", P_STRING|P_VIM,
2625 (char_u *)&p_tc, PV_TC,
2626 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002627 {"taglength", "tl", P_NUM|P_VI_DEF,
2628 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002629 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 {"tagrelative", "tr", P_BOOL|P_VIM,
2631 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002632 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002633 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002634 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 {
2636#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2637 (char_u *)"./tags,./TAGS,tags,TAGS",
2638#else
2639 (char_u *)"./tags,tags",
2640#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002641 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002642 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2643 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002645#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002646 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002647 (char_u *)&p_tcldll, PV_NONE,
2648 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2649 SCRIPTID_INIT},
2650#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2652 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002653 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2655#ifdef FEAT_ARABIC
2656 (char_u *)&p_tbidi, PV_NONE,
2657#else
2658 (char_u *)NULL, PV_NONE,
2659#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2662#ifdef FEAT_MBYTE
2663 (char_u *)&p_tenc, PV_NONE,
2664 {(char_u *)"", (char_u *)0L}
2665#else
2666 (char_u *)NULL, PV_NONE,
2667 {(char_u *)0L, (char_u *)0L}
2668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002669 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002670 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2671#ifdef FEAT_TERMGUICOLORS
2672 (char_u *)&p_tgc, PV_NONE,
2673 {(char_u *)FALSE, (char_u *)FALSE}
2674#else
2675 (char_u*)NULL, PV_NONE,
2676 {(char_u *)FALSE, (char_u *)FALSE}
2677#endif
2678 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679 {"terse", NULL, P_BOOL|P_VI_DEF,
2680 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002681 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 {"textauto", "ta", P_BOOL|P_VIM,
2683 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2685 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2687 (char_u *)&p_tx, PV_TX,
2688 {
2689#ifdef USE_CRNL
2690 (char_u *)TRUE,
2691#else
2692 (char_u *)FALSE,
2693#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002694 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002695 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002696 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002697 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002698 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002700 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701#else
2702 (char_u *)NULL, PV_NONE,
2703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002704 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2706 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002707 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002708 {"timeout", "to", P_BOOL|P_VI_DEF,
2709 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002710 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2712 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002714 {"title", NULL, P_BOOL|P_VI_DEF,
2715#ifdef FEAT_TITLE
2716 (char_u *)&p_title, PV_NONE,
2717#else
2718 (char_u *)NULL, PV_NONE,
2719#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002720 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {"titlelen", NULL, P_NUM|P_VI_DEF,
2722#ifdef FEAT_TITLE
2723 (char_u *)&p_titlelen, PV_NONE,
2724#else
2725 (char_u *)NULL, PV_NONE,
2726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002728 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002729#ifdef FEAT_TITLE
2730 (char_u *)&p_titleold, PV_NONE,
2731 {(char_u *)N_("Thanks for flying Vim"),
2732 (char_u *)0L}
2733#else
2734 (char_u *)NULL, PV_NONE,
2735 {(char_u *)0L, (char_u *)0L}
2736#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002737 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"titlestring", NULL, P_STRING|P_VI_DEF,
2739#ifdef FEAT_TITLE
2740 (char_u *)&p_titlestring, PV_NONE,
2741#else
2742 (char_u *)NULL, PV_NONE,
2743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002746 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002748 {(char_u *)"icons,tooltips", (char_u *)0L}
2749 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002751#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002752 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2753 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002754 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002755#endif
2756 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2757 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002759 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2760 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002761 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002762 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2763 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002764 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002765 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2766 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002767 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2769#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2770 (char_u *)&p_ttym, PV_NONE,
2771#else
2772 (char_u *)NULL, PV_NONE,
2773#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002774 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2776 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002777 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2779 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002780 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002781 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2782 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002783#ifdef FEAT_PERSISTENT_UNDO
2784 (char_u *)&p_udir, PV_NONE,
2785 {(char_u *)".", (char_u *)0L}
2786#else
2787 (char_u *)NULL, PV_NONE,
2788 {(char_u *)0L, (char_u *)0L}
2789#endif
2790 SCRIPTID_INIT},
2791 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2792#ifdef FEAT_PERSISTENT_UNDO
2793 (char_u *)&p_udf, PV_UDF,
2794#else
2795 (char_u *)NULL, PV_NONE,
2796#endif
2797 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002798 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002799 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002801#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 (char_u *)1000L,
2803#else
2804 (char_u *)100L,
2805#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002806 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002807 {"undoreload", "ur", P_NUM|P_VI_DEF,
2808 (char_u *)&p_ur, PV_NONE,
2809 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"updatecount", "uc", P_NUM|P_VI_DEF,
2811 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002812 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002813 {"updatetime", "ut", P_NUM|P_VI_DEF,
2814 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002816 {"verbose", "vbs", P_NUM|P_VI_DEF,
2817 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002819 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2820 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002821 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002822 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2823#ifdef FEAT_SESSION
2824 (char_u *)&p_vdir, PV_NONE,
2825 {(char_u *)DFLT_VDIR, (char_u *)0L}
2826#else
2827 (char_u *)NULL, PV_NONE,
2828 {(char_u *)0L, (char_u *)0L}
2829#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002830 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002831 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832#ifdef FEAT_SESSION
2833 (char_u *)&p_vop, PV_NONE,
2834 {(char_u *)"folds,options,cursor", (char_u *)0L}
2835#else
2836 (char_u *)NULL, PV_NONE,
2837 {(char_u *)0L, (char_u *)0L}
2838#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002839 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002840 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841#ifdef FEAT_VIMINFO
2842 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002843#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002844 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845#else
2846# ifdef AMIGA
2847 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002848 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002850 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851# endif
2852#endif
2853#else
2854 (char_u *)NULL, PV_NONE,
2855 {(char_u *)0L, (char_u *)0L}
2856#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002858 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2859 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860#ifdef FEAT_VIRTUALEDIT
2861 (char_u *)&p_ve, PV_NONE,
2862 {(char_u *)"", (char_u *)""}
2863#else
2864 (char_u *)NULL, PV_NONE,
2865 {(char_u *)0L, (char_u *)0L}
2866#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002867 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002868 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2869 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"w300", NULL, P_NUM|P_VI_DEF,
2872 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"w1200", NULL, P_NUM|P_VI_DEF,
2875 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {"w9600", NULL, P_NUM|P_VI_DEF,
2878 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002879 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 {"warn", NULL, P_BOOL|P_VI_DEF,
2881 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002882 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2884 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002885 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002886 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002889 {"wildchar", "wc", P_NUM|P_VIM,
2890 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002891 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2892 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002893 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002895 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002896 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002897#ifdef FEAT_WILDIGN
2898 (char_u *)&p_wig, PV_NONE,
2899#else
2900 (char_u *)NULL, PV_NONE,
2901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002902 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002903 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2904 (char_u *)&p_wic, PV_NONE,
2905 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2907#ifdef FEAT_WILDMENU
2908 (char_u *)&p_wmnu, PV_NONE,
2909#else
2910 (char_u *)NULL, PV_NONE,
2911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002913 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002915 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002916 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2917#ifdef FEAT_CMDL_COMPL
2918 (char_u *)&p_wop, PV_NONE,
2919 {(char_u *)"", (char_u *)0L}
2920#else
2921 (char_u *)NULL, PV_NONE,
2922 {(char_u *)NULL, (char_u *)0L}
2923#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002924 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2926#ifdef FEAT_WAK
2927 (char_u *)&p_wak, PV_NONE,
2928 {(char_u *)"menu", (char_u *)0L}
2929#else
2930 (char_u *)NULL, PV_NONE,
2931 {(char_u *)NULL, (char_u *)0L}
2932#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002933 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002935 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937 {"winheight", "wh", P_NUM|P_VI_DEF,
2938#ifdef FEAT_WINDOWS
2939 (char_u *)&p_wh, PV_NONE,
2940#else
2941 (char_u *)NULL, PV_NONE,
2942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002943 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002945#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946 (char_u *)VAR_WIN, PV_WFH,
2947#else
2948 (char_u *)NULL, PV_NONE,
2949#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002951 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002952#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002953 (char_u *)VAR_WIN, PV_WFW,
2954#else
2955 (char_u *)NULL, PV_NONE,
2956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2959#ifdef FEAT_WINDOWS
2960 (char_u *)&p_wmh, PV_NONE,
2961#else
2962 (char_u *)NULL, PV_NONE,
2963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002964 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002966#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 (char_u *)&p_wmw, PV_NONE,
2968#else
2969 (char_u *)NULL, PV_NONE,
2970#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002971 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002973#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 (char_u *)&p_wiw, PV_NONE,
2975#else
2976 (char_u *)NULL, PV_NONE,
2977#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002978 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2980 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002981 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2983 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002984 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2986 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 {"write", NULL, P_BOOL|P_VI_DEF,
2989 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002990 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 {"writeany", "wa", P_BOOL|P_VI_DEF,
2992 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002994 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2995 (char_u *)&p_wb, PV_NONE,
2996 {
2997#ifdef FEAT_WRITEBACKUP
2998 (char_u *)TRUE,
2999#else
3000 (char_u *)FALSE,
3001#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003002 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 {"writedelay", "wd", P_NUM|P_VI_DEF,
3004 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003005 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006
3007/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003008#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003010 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011
3012 p_term("t_AB", T_CAB)
3013 p_term("t_AF", T_CAF)
3014 p_term("t_AL", T_CAL)
3015 p_term("t_al", T_AL)
3016 p_term("t_bc", T_BC)
3017 p_term("t_cd", T_CD)
3018 p_term("t_ce", T_CE)
3019 p_term("t_cl", T_CL)
3020 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003021 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 p_term("t_Co", T_CCO)
3023 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003024 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003025 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003026#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 p_term("t_CV", T_CSV)
3028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 p_term("t_da", T_DA)
3030 p_term("t_db", T_DB)
3031 p_term("t_DL", T_CDL)
3032 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003033 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 p_term("t_fs", T_FS)
3035 p_term("t_IE", T_CIE)
3036 p_term("t_IS", T_CIS)
3037 p_term("t_ke", T_KE)
3038 p_term("t_ks", T_KS)
3039 p_term("t_le", T_LE)
3040 p_term("t_mb", T_MB)
3041 p_term("t_md", T_MD)
3042 p_term("t_me", T_ME)
3043 p_term("t_mr", T_MR)
3044 p_term("t_ms", T_MS)
3045 p_term("t_nd", T_ND)
3046 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003047 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 p_term("t_RI", T_CRI)
3049 p_term("t_RV", T_CRV)
3050 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003052 p_term("t_Sf", T_CSF)
3053 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003055 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 p_term("t_te", T_TE)
3058 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003059 p_term("t_ts", T_TS)
3060 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 p_term("t_ue", T_UE)
3062 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003063 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 p_term("t_vb", T_VB)
3065 p_term("t_ve", T_VE)
3066 p_term("t_vi", T_VI)
3067 p_term("t_vs", T_VS)
3068 p_term("t_WP", T_CWP)
3069 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003070 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 p_term("t_xs", T_XS)
3072 p_term("t_ZH", T_CZH)
3073 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003074 p_term("t_8f", T_8F)
3075 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003076 p_term("t_BE", T_BE)
3077 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078
3079/* terminal key codes are not in here */
3080
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003081 /* end marker */
3082 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083};
3084
3085#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3086
3087#ifdef FEAT_MBYTE
3088static char *(p_ambw_values[]) = {"single", "double", NULL};
3089#endif
3090static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003091static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003093#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003094static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003095#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003096#ifdef FEAT_CMDL_COMPL
3097static char *(p_wop_values[]) = {"tagfile", NULL};
3098#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099#ifdef FEAT_WAK
3100static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3101#endif
3102static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3104static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106#ifdef FEAT_BROWSE
3107static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3108#endif
3109#ifdef FEAT_SCROLLBIND
3110static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3111#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003112static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003113#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3115#endif
3116#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003117# ifdef FEAT_AUTOCMD
3118static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3119# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003121# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3123#endif
3124static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3125#ifdef FEAT_FOLDING
3126static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003127# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003129# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 NULL};
3131static char *(p_fcl_values[]) = {"all", NULL};
3132#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003133#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003134static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003135#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003136#ifdef FEAT_SIGNS
3137static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3138#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003139
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003140static void set_option_default(int, int opt_flags, int compatible);
3141static void set_options_default(int opt_flags);
3142static char_u *term_bg_default(void);
3143static void did_set_option(int opt_idx, int opt_flags, int new_value);
3144static char_u *illegal_char(char_u *, int);
3145static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003147static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148#endif
3149#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003150static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003152static char_u *option_expand(int opt_idx, char_u *val);
3153static void didset_options(void);
3154static void didset_options2(void);
3155static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003156#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003157static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003158#else
3159# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3160#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003161static void set_string_option_global(int opt_idx, char_u **varp);
3162static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3163static 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);
3164static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003165#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003166static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003167#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003168#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003169static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003171#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003172static char_u *did_set_spell_option(int is_spellfile);
3173static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003174#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003175#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003176static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003177#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003178static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3179static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3180static void check_redraw(long_u flags);
3181static int findoption(char_u *);
3182static int find_key_option(char_u *);
3183static void showoptions(int all, int opt_flags);
3184static int optval_default(struct vimoption *, char_u *varp);
3185static void showoneopt(struct vimoption *, int opt_flags);
3186static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3187static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3188static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3189static int istermoption(struct vimoption *);
3190static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3191static char_u *get_varp(struct vimoption *);
3192static void option_value2string(struct vimoption *, int opt_flags);
3193static void check_winopt(winopt_T *wop);
3194static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003196static void langmap_init(void);
3197static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003199static void paste_option_changed(void);
3200static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003202static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003204static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3205static int check_opt_strings(char_u *val, char **values, int);
3206static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003207#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003208static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003209#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210
3211/*
3212 * Initialize the options, first part.
3213 *
3214 * Called only once from main(), just after creating the first buffer.
3215 */
3216 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003217set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218{
3219 char_u *p;
3220 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003221 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222
3223#ifdef FEAT_LANGMAP
3224 langmap_init();
3225#endif
3226
3227 /* Be Vi compatible by default */
3228 p_cp = TRUE;
3229
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003230 /* Use POSIX compatibility when $VIM_POSIX is set. */
3231 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003232 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003233 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003234 set_string_default("shm", (char_u *)"A");
3235 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003236
Bram Moolenaar071d4272004-06-13 20:20:40 +00003237 /*
3238 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003239 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003240 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003241 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003242#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003243 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003245 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003246# endif
3247#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003248 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249 set_string_default("sh", p);
3250
3251#ifdef FEAT_WILDIGN
3252 /*
3253 * Set the default for 'backupskip' to include environment variables for
3254 * temp files.
3255 */
3256 {
3257# ifdef UNIX
3258 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3259# else
3260 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3261# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003262 int len;
3263 garray_T ga;
3264 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265
3266 ga_init2(&ga, 1, 100);
3267 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3268 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003269 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270# ifdef UNIX
3271 if (*names[n] == NUL)
3272 p = (char_u *)"/tmp";
3273 else
3274# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003275 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276 if (p != NULL && *p != NUL)
3277 {
3278 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003279 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280 if (ga_grow(&ga, len) == OK)
3281 {
3282 if (ga.ga_len > 0)
3283 STRCAT(ga.ga_data, ",");
3284 STRCAT(ga.ga_data, p);
3285 add_pathsep(ga.ga_data);
3286 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287 ga.ga_len += len;
3288 }
3289 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003290 if (mustfree)
3291 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292 }
3293 if (ga.ga_data != NULL)
3294 {
3295 set_string_default("bsk", ga.ga_data);
3296 vim_free(ga.ga_data);
3297 }
3298 }
3299#endif
3300
3301 /*
3302 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3303 */
3304 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003305 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003307#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3308 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3309#endif
3310 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003312 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003313 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314#else
3315# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003316 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003317 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003319 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320# endif
3321#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003323 opt_idx = findoption((char_u *)"maxmem");
3324 if (opt_idx >= 0)
3325 {
3326#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003327 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3328 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003329#endif
3330 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3331 }
3332 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 }
3334
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335#ifdef FEAT_SEARCHPATH
3336 {
3337 char_u *cdpath;
3338 char_u *buf;
3339 int i;
3340 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003341 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342
3343 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003344 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 if (cdpath != NULL)
3346 {
3347 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3348 if (buf != NULL)
3349 {
3350 buf[0] = ','; /* start with ",", current dir first */
3351 j = 1;
3352 for (i = 0; cdpath[i] != NUL; ++i)
3353 {
3354 if (vim_ispathlistsep(cdpath[i]))
3355 buf[j++] = ',';
3356 else
3357 {
3358 if (cdpath[i] == ' ' || cdpath[i] == ',')
3359 buf[j++] = '\\';
3360 buf[j++] = cdpath[i];
3361 }
3362 }
3363 buf[j] = NUL;
3364 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003365 if (opt_idx >= 0)
3366 {
3367 options[opt_idx].def_val[VI_DEFAULT] = buf;
3368 options[opt_idx].flags |= P_DEF_ALLOCED;
3369 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003370 else
3371 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003373 if (mustfree)
3374 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003375 }
3376 }
3377#endif
3378
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003379#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380 /* Set print encoding on platforms that don't default to latin1 */
3381 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003382# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 (char_u *)"cp1252"
3384# else
3385# ifdef VMS
3386 (char_u *)"dec-mcs"
3387# else
3388# ifdef EBCDIC
3389 (char_u *)"ebcdic-uk"
3390# else
3391# ifdef MAC
3392 (char_u *)"mac-roman"
3393# else /* HPUX */
3394 (char_u *)"hp-roman8"
3395# endif
3396# endif
3397# endif
3398# endif
3399 );
3400#endif
3401
3402#ifdef FEAT_POSTSCRIPT
3403 /* 'printexpr' must be allocated to be able to evaluate it. */
3404 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003405# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003406 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407# else
3408# ifdef VMS
3409 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3410
3411# else
3412 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3413# endif
3414# endif
3415 );
3416#endif
3417
3418 /*
3419 * Set all the options (except the terminal options) to their default
3420 * value. Also set the global value for local options.
3421 */
3422 set_options_default(0);
3423
3424#ifdef FEAT_GUI
3425 if (found_reverse_arg)
3426 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3427#endif
3428
3429 curbuf->b_p_initialized = TRUE;
3430 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003431 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 check_buf_options(curbuf);
3433 check_win_options(curwin);
3434 check_options();
3435
3436 /* Must be before option_expand(), because that one needs vim_isIDc() */
3437 didset_options();
3438
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003439#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003440 /* Use the current chartab for the generic chartab. This is not in
3441 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003442 init_spell_chartab();
3443#endif
3444
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445 /*
3446 * Expand environment variables and things like "~" for the defaults.
3447 * If option_expand() returns non-NULL the variable is expanded. This can
3448 * only happen for non-indirect options.
3449 * Also set the default to the expanded value, so ":set" does not list
3450 * them.
3451 * Don't set the P_ALLOCED flag, because we don't want to free the
3452 * default.
3453 */
3454 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3455 {
3456 if ((options[opt_idx].flags & P_GETTEXT)
3457 && options[opt_idx].var != NULL)
3458 p = (char_u *)_(*(char **)options[opt_idx].var);
3459 else
3460 p = option_expand(opt_idx, NULL);
3461 if (p != NULL && (p = vim_strsave(p)) != NULL)
3462 {
3463 *(char_u **)options[opt_idx].var = p;
3464 /* VIMEXP
3465 * Defaults for all expanded options are currently the same for Vi
3466 * and Vim. When this changes, add some code here! Also need to
3467 * split P_DEF_ALLOCED in two.
3468 */
3469 if (options[opt_idx].flags & P_DEF_ALLOCED)
3470 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3471 options[opt_idx].def_val[VI_DEFAULT] = p;
3472 options[opt_idx].flags |= P_DEF_ALLOCED;
3473 }
3474 }
3475
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476 save_file_ff(curbuf); /* Buffer is unchanged */
3477
Bram Moolenaar071d4272004-06-13 20:20:40 +00003478#if defined(FEAT_ARABIC)
3479 /* Detect use of mlterm.
3480 * Mlterm is a terminal emulator akin to xterm that has some special
3481 * abilities (bidi namely).
3482 * NOTE: mlterm's author is being asked to 'set' a variable
3483 * instead of an environment variable due to inheritance.
3484 */
3485 if (mch_getenv((char_u *)"MLTERM") != NULL)
3486 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3487#endif
3488
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003489 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003490
3491#ifdef FEAT_MBYTE
3492# if defined(WIN3264) && defined(FEAT_GETTEXT)
3493 /*
3494 * If $LANG isn't set, try to get a good value for it. This makes the
3495 * right language be used automatically. Don't do this for English.
3496 */
3497 if (mch_getenv((char_u *)"LANG") == NULL)
3498 {
3499 char buf[20];
3500
3501 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3502 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3503 * only the first two. */
3504 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3505 (LPTSTR)buf, 20);
3506 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3507 {
3508 /* There are a few exceptions (probably more) */
3509 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3510 STRCPY(buf, "zh_TW");
3511 else if (STRNICMP(buf, "chs", 3) == 0
3512 || STRNICMP(buf, "zhc", 3) == 0)
3513 STRCPY(buf, "zh_CN");
3514 else if (STRNICMP(buf, "jp", 2) == 0)
3515 STRCPY(buf, "ja");
3516 else
3517 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003518 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003519 }
3520 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003521# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003522# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003523 /* Moved to os_mac_conv.c to avoid dependency problems. */
3524 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003525# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526# endif
3527
3528 /* enc_locale() will try to find the encoding of the current locale. */
3529 p = enc_locale();
3530 if (p != NULL)
3531 {
3532 char_u *save_enc;
3533
3534 /* Try setting 'encoding' and check if the value is valid.
3535 * If not, go back to the default "latin1". */
3536 save_enc = p_enc;
3537 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003538 if (STRCMP(p_enc, "gb18030") == 0)
3539 {
3540 /* We don't support "gb18030", but "cp936" is a good substitute
3541 * for practical purposes, thus use that. It's not an alias to
3542 * still support conversion between gb18030 and utf-8. */
3543 p_enc = vim_strsave((char_u *)"cp936");
3544 vim_free(p);
3545 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003546 if (mb_init() == NULL)
3547 {
3548 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003549 if (opt_idx >= 0)
3550 {
3551 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3552 options[opt_idx].flags |= P_DEF_ALLOCED;
3553 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003554
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003555#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003556 if (STRCMP(p_enc, "latin1") == 0
3557# ifdef FEAT_MBYTE
3558 || enc_utf8
3559# endif
3560 )
3561 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003562 /* Adjust the default for 'isprint' and 'iskeyword' to match
3563 * latin1. Also set the defaults for when 'nocompatible' is
3564 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003565 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003566 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003567 set_string_option_direct((char_u *)"isk", -1,
3568 ISK_LATIN1, OPT_FREE, SID_NONE);
3569 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003570 if (opt_idx >= 0)
3571 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003572 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003573 if (opt_idx >= 0)
3574 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003575 (void)init_chartab();
3576 }
3577#endif
3578
Bram Moolenaar071d4272004-06-13 20:20:40 +00003579# if defined(WIN3264) && !defined(FEAT_GUI)
3580 /* Win32 console: When GetACP() returns a different value from
3581 * GetConsoleCP() set 'termencoding'. */
3582 if (GetACP() != GetConsoleCP())
3583 {
3584 char buf[50];
3585
3586 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3587 p_tenc = vim_strsave((char_u *)buf);
3588 if (p_tenc != NULL)
3589 {
3590 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003591 if (opt_idx >= 0)
3592 {
3593 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3594 options[opt_idx].flags |= P_DEF_ALLOCED;
3595 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 convert_setup(&input_conv, p_tenc, p_enc);
3597 convert_setup(&output_conv, p_enc, p_tenc);
3598 }
3599 else
3600 p_tenc = empty_option;
3601 }
3602# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003603# if defined(WIN3264) && defined(FEAT_MBYTE)
3604 /* $HOME may have characters in active code page. */
3605 init_homedir();
3606# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003607 }
3608 else
3609 {
3610 vim_free(p_enc);
3611 p_enc = save_enc;
3612 }
3613 }
3614#endif
3615
3616#ifdef FEAT_MULTI_LANG
3617 /* Set the default for 'helplang'. */
3618 set_helplang_default(get_mess_lang());
3619#endif
3620}
3621
3622/*
3623 * Set an option to its default value.
3624 * This does not take care of side effects!
3625 */
3626 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003627set_option_default(
3628 int opt_idx,
3629 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3630 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631{
3632 char_u *varp; /* pointer to variable for current option */
3633 int dvi; /* index in def_val[] */
3634 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003635 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3637
3638 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3639 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003640 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641 {
3642 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3643 if (flags & P_STRING)
3644 {
3645 /* Use set_string_option_direct() for local options to handle
3646 * freeing and allocating the value. */
3647 if (options[opt_idx].indir != PV_NONE)
3648 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003649 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650 else
3651 {
3652 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3653 free_string_option(*(char_u **)(varp));
3654 *(char_u **)varp = options[opt_idx].def_val[dvi];
3655 options[opt_idx].flags &= ~P_ALLOCED;
3656 }
3657 }
3658 else if (flags & P_NUM)
3659 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003660 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003661 win_comp_scroll(curwin);
3662 else
3663 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003664 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003665 /* May also set global value for local option. */
3666 if (both)
3667 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3668 *(long *)varp;
3669 }
3670 }
3671 else /* P_BOOL */
3672 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003673 /* the cast to long is required for Manx C, long_i is needed for
3674 * MSVC */
3675 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003676#ifdef UNIX
3677 /* 'modeline' defaults to off for root */
3678 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3679 *(int *)varp = FALSE;
3680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003681 /* May also set global value for local option. */
3682 if (both)
3683 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3684 *(int *)varp;
3685 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003686
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003687 /* The default value is not insecure. */
3688 flagsp = insecure_flag(opt_idx, opt_flags);
3689 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690 }
3691
3692#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003693 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003694#endif
3695}
3696
3697/*
3698 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003699 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700 */
3701 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003702set_options_default(
3703 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704{
3705 int i;
3706#ifdef FEAT_WINDOWS
3707 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003708 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709#endif
3710
3711 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003712 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003713#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003714 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003715 || (TRUE
3716# if defined(FEAT_MBYTE)
3717 && options[i].var != (char_u *)&p_enc
3718# endif
3719# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003720 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003721 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003722# endif
3723 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003724#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003725 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003726 set_option_default(i, opt_flags, p_cp);
3727
3728#ifdef FEAT_WINDOWS
3729 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003730 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003731 win_comp_scroll(wp);
3732#else
3733 win_comp_scroll(curwin);
3734#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003735#ifdef FEAT_CINDENT
3736 parse_cino(curbuf);
3737#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738}
3739
3740/*
3741 * Set the Vi-default value of a string option.
3742 * Used for 'sh', 'backupskip' and 'term'.
3743 */
3744 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003745set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003746{
3747 char_u *p;
3748 int opt_idx;
3749
3750 p = vim_strsave(val);
3751 if (p != NULL) /* we don't want a NULL */
3752 {
3753 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003754 if (opt_idx >= 0)
3755 {
3756 if (options[opt_idx].flags & P_DEF_ALLOCED)
3757 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3758 options[opt_idx].def_val[VI_DEFAULT] = p;
3759 options[opt_idx].flags |= P_DEF_ALLOCED;
3760 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 }
3762}
3763
3764/*
3765 * Set the Vi-default value of a number option.
3766 * Used for 'lines' and 'columns'.
3767 */
3768 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003769set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003770{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003771 int opt_idx;
3772
3773 opt_idx = findoption((char_u *)name);
3774 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003775 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776}
3777
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003778#if defined(EXITFREE) || defined(PROTO)
3779/*
3780 * Free all options.
3781 */
3782 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003783free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003784{
3785 int i;
3786
3787 for (i = 0; !istermoption(&options[i]); i++)
3788 {
3789 if (options[i].indir == PV_NONE)
3790 {
3791 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003792 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003793 free_string_option(*(char_u **)options[i].var);
3794 if (options[i].flags & P_DEF_ALLOCED)
3795 free_string_option(options[i].def_val[VI_DEFAULT]);
3796 }
3797 else if (options[i].var != VAR_WIN
3798 && (options[i].flags & P_STRING))
3799 /* buffer-local option: free global value */
3800 free_string_option(*(char_u **)options[i].var);
3801 }
3802}
3803#endif
3804
3805
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806/*
3807 * Initialize the options, part two: After getting Rows and Columns and
3808 * setting 'term'.
3809 */
3810 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003811set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003813 int idx;
3814
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 /*
3816 * 'scroll' defaults to half the window height. Note that this default is
3817 * wrong when the window height changes.
3818 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003819 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003820 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003821 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003822 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823 comp_col();
3824
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003825 /*
3826 * 'window' is only for backwards compatibility with Vi.
3827 * Default is Rows - 1.
3828 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003829 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003830 p_window = Rows - 1;
3831 set_number_default("window", Rows - 1);
3832
Bram Moolenaarf740b292006-02-16 22:11:02 +00003833 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003834#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003835 /*
3836 * If 'background' wasn't set by the user, try guessing the value,
3837 * depending on the terminal name. Only need to check for terminals
3838 * with a dark background, that can handle color.
3839 */
3840 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003841 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3842 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003844 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003845 /* don't mark it as set, when starting the GUI it may be
3846 * changed again */
3847 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 }
3849#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003850
3851#ifdef CURSOR_SHAPE
3852 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3853#endif
3854#ifdef FEAT_MOUSESHAPE
3855 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3856#endif
3857#ifdef FEAT_PRINTER
3858 (void)parse_printoptions(); /* parse 'printoptions' default value */
3859#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003860}
3861
3862/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003863 * Return "dark" or "light" depending on the kind of terminal.
3864 * This is just guessing! Recognized are:
3865 * "linux" Linux console
3866 * "screen.linux" Linux console with screen
3867 * "cygwin" Cygwin shell
3868 * "putty" Putty program
3869 * We also check the COLORFGBG environment variable, which is set by
3870 * rxvt and derivatives. This variable contains either two or three
3871 * values separated by semicolons; we want the last value in either
3872 * case. If this value is 0-6 or 8, our background is dark.
3873 */
3874 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003875term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003876{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003877#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003878 /* DOS console nearly always black */
3879 return (char_u *)"dark";
3880#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003881 char_u *p;
3882
Bram Moolenaarf740b292006-02-16 22:11:02 +00003883 if (STRCMP(T_NAME, "linux") == 0
3884 || STRCMP(T_NAME, "screen.linux") == 0
3885 || STRCMP(T_NAME, "cygwin") == 0
3886 || STRCMP(T_NAME, "putty") == 0
3887 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3888 && (p = vim_strrchr(p, ';')) != NULL
3889 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3890 && p[2] == NUL))
3891 return (char_u *)"dark";
3892 return (char_u *)"light";
3893#endif
3894}
3895
3896/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 * Initialize the options, part three: After reading the .vimrc
3898 */
3899 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003900set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003902#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903/*
3904 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3905 * This is done after other initializations, where 'shell' might have been
3906 * set, but only if they have not been set before.
3907 */
3908 char_u *p;
3909 int idx_srr;
3910 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003911# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 int idx_sp;
3913 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003914# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915
3916 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003917 if (idx_srr < 0)
3918 do_srr = FALSE;
3919 else
3920 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003921# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003923 if (idx_sp < 0)
3924 do_sp = FALSE;
3925 else
3926 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003927# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003928 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929 if (p != NULL)
3930 {
3931 /*
3932 * Default for p_sp is "| tee", for p_srr is ">".
3933 * For known shells it is changed here to include stderr.
3934 */
3935 if ( fnamecmp(p, "csh") == 0
3936 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003937# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003938 || fnamecmp(p, "csh.exe") == 0
3939 || fnamecmp(p, "tcsh.exe") == 0
3940# endif
3941 )
3942 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003943# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 if (do_sp)
3945 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003946# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003947 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003948# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003950# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3952 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003953# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 if (do_srr)
3955 {
3956 p_srr = (char_u *)">&";
3957 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3958 }
3959 }
3960 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003961 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 if ( fnamecmp(p, "sh") == 0
3963 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003964 || fnamecmp(p, "mksh") == 0
3965 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003967 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003969 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003970# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 || fnamecmp(p, "cmd") == 0
3972 || fnamecmp(p, "sh.exe") == 0
3973 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003974 || fnamecmp(p, "mksh.exe") == 0
3975 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003976 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003977 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003978 || fnamecmp(p, "bash.exe") == 0
3979 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003980# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003981 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003982 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003983# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 if (do_sp)
3985 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003986# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003987 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003988# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003990# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3992 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003993# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 if (do_srr)
3995 {
3996 p_srr = (char_u *)">%s 2>&1";
3997 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3998 }
3999 }
4000 vim_free(p);
4001 }
4002#endif
4003
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004004#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004006 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4007 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004008 * This is done after other initializations, where 'shell' might have been
4009 * set, but only if they have not been set before. Default for p_shcf is
4010 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004011 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004013 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 {
4015 int idx3;
4016
4017 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004018 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019 {
4020 p_shcf = (char_u *)"-c";
4021 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4022 }
4023
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004024# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004025 /* Somehow Win32 requires the quotes around the redirection too */
4026 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004027 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028 {
4029 p_sxq = (char_u *)"\"";
4030 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4031 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004032# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004034 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035 {
4036 p_shq = (char_u *)"\"";
4037 options[idx3].def_val[VI_DEFAULT] = p_shq;
4038 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039# endif
4040 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004041 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4042 {
4043 int idx3;
4044
4045 /*
4046 * cmd.exe on Windows will strip the first and last double quote given
4047 * on the command line, e.g. most of the time things like:
4048 * cmd /c "my path/to/echo" "my args to echo"
4049 * become:
4050 * my path/to/echo" "my args to echo
4051 * when executed.
4052 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004053 * To avoid this, set shellxquote to surround the command in
4054 * parenthesis. This appears to make most commands work, without
4055 * breaking commands that worked previously, such as
4056 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004057 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004058 idx3 = findoption((char_u *)"sxq");
4059 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4060 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004061 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004062 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4063 }
4064
Bram Moolenaara64ba222012-02-12 23:23:31 +01004065 idx3 = findoption((char_u *)"shcf");
4066 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4067 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004068 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004069 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4070 }
4071 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072#endif
4073
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004074 if (bufempty())
4075 {
4076 int idx_ffs = findoption((char_u *)"ffs");
4077
4078 /* Apply the first entry of 'fileformats' to the initial buffer. */
4079 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4080 set_fileformat(default_fileformat(), OPT_LOCAL);
4081 }
4082
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083#ifdef FEAT_TITLE
4084 set_title_defaults();
4085#endif
4086}
4087
4088#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4089/*
4090 * When 'helplang' is still at its default value, set it to "lang".
4091 * Only the first two characters of "lang" are used.
4092 */
4093 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004094set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095{
4096 int idx;
4097
4098 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4099 return;
4100 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004101 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 {
4103 if (options[idx].flags & P_ALLOCED)
4104 free_string_option(p_hlg);
4105 p_hlg = vim_strsave(lang);
4106 if (p_hlg == NULL)
4107 p_hlg = empty_option;
4108 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004109 {
4110 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4111 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4112 {
4113 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4114 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4115 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004117 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 options[idx].flags |= P_ALLOCED;
4119 }
4120}
4121#endif
4122
4123#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004124static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125
4126 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004127gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004128{
4129 if (gui_get_lightness(gui.back_pixel) < 127)
4130 return (char_u *)"dark";
4131 return (char_u *)"light";
4132}
4133
4134/*
4135 * Option initializations that can only be done after opening the GUI window.
4136 */
4137 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004138init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139{
4140 /* Set the 'background' option according to the lightness of the
4141 * background color, unless the user has set it already. */
4142 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4143 {
4144 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4145 highlight_changed();
4146 }
4147}
4148#endif
4149
4150#ifdef FEAT_TITLE
4151/*
4152 * 'title' and 'icon' only default to true if they have not been set or reset
4153 * in .vimrc and we can read the old value.
4154 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4155 * they can be reset. This reduces startup time when using X on a remote
4156 * machine.
4157 */
4158 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004159set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160{
4161 int idx1;
4162 long val;
4163
4164 /*
4165 * If GUI is (going to be) used, we can always set the window title and
4166 * icon name. Saves a bit of time, because the X11 display server does
4167 * not need to be contacted.
4168 */
4169 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004170 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 {
4172#ifdef FEAT_GUI
4173 if (gui.starting || gui.in_use)
4174 val = TRUE;
4175 else
4176#endif
4177 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004178 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179 p_title = val;
4180 }
4181 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004182 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 {
4184#ifdef FEAT_GUI
4185 if (gui.starting || gui.in_use)
4186 val = TRUE;
4187 else
4188#endif
4189 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004190 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 p_icon = val;
4192 }
4193}
4194#endif
4195
4196/*
4197 * Parse 'arg' for option settings.
4198 *
4199 * 'arg' may be IObuff, but only when no errors can be present and option
4200 * does not need to be expanded with option_expand().
4201 * "opt_flags":
4202 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004203 * OPT_GLOBAL for ":setglobal"
4204 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004205 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004206 * OPT_WINONLY to only set window-local options
4207 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004208 *
4209 * returns FAIL if an error is detected, OK otherwise
4210 */
4211 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004212do_set(
4213 char_u *arg, /* option string (may be written to!) */
4214 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004215{
4216 int opt_idx;
4217 char_u *errmsg;
4218 char_u errbuf[80];
4219 char_u *startarg;
4220 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4221 int nextchar; /* next non-white char after option name */
4222 int afterchar; /* character just after option name */
4223 int len;
4224 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004225 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004226 int key;
4227 long_u flags; /* flags for current option */
4228 char_u *varp = NULL; /* pointer to variable for current option */
4229 int did_show = FALSE; /* already showed one value */
4230 int adding; /* "opt+=arg" */
4231 int prepending; /* "opt^=arg" */
4232 int removing; /* "opt-=arg" */
4233 int cp_val = 0;
4234 char_u key_name[2];
4235
4236 if (*arg == NUL)
4237 {
4238 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004239 did_show = TRUE;
4240 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004241 }
4242
4243 while (*arg != NUL) /* loop to process all options */
4244 {
4245 errmsg = NULL;
4246 startarg = arg; /* remember for error message */
4247
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004248 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4249 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004250 {
4251 /*
4252 * ":set all" show all options.
4253 * ":set all&" set all options to their default value.
4254 */
4255 arg += 3;
4256 if (*arg == '&')
4257 {
4258 ++arg;
4259 /* Only for :set command set global value of local options. */
4260 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004261 didset_options();
4262 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004263 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004264 }
4265 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004266 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004267 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004268 did_show = TRUE;
4269 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004271 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004272 {
4273 showoptions(2, opt_flags);
4274 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004275 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004276 arg += 7;
4277 }
4278 else
4279 {
4280 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004281 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282 {
4283 prefix = 0;
4284 arg += 2;
4285 }
4286 else if (STRNCMP(arg, "inv", 3) == 0)
4287 {
4288 prefix = 2;
4289 arg += 3;
4290 }
4291
4292 /* find end of name */
4293 key = 0;
4294 if (*arg == '<')
4295 {
4296 nextchar = 0;
4297 opt_idx = -1;
4298 /* look out for <t_>;> */
4299 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4300 len = 5;
4301 else
4302 {
4303 len = 1;
4304 while (arg[len] != NUL && arg[len] != '>')
4305 ++len;
4306 }
4307 if (arg[len] != '>')
4308 {
4309 errmsg = e_invarg;
4310 goto skip;
4311 }
4312 arg[len] = NUL; /* put NUL after name */
4313 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4314 opt_idx = findoption(arg + 1);
4315 arg[len++] = '>'; /* restore '>' */
4316 if (opt_idx == -1)
4317 key = find_key_option(arg + 1);
4318 }
4319 else
4320 {
4321 len = 0;
4322 /*
4323 * The two characters after "t_" may not be alphanumeric.
4324 */
4325 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4326 len = 4;
4327 else
4328 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4329 ++len;
4330 nextchar = arg[len];
4331 arg[len] = NUL; /* put NUL after name */
4332 opt_idx = findoption(arg);
4333 arg[len] = nextchar; /* restore nextchar */
4334 if (opt_idx == -1)
4335 key = find_key_option(arg);
4336 }
4337
4338 /* remember character after option name */
4339 afterchar = arg[len];
4340
4341 /* skip white space, allow ":set ai ?" */
4342 while (vim_iswhite(arg[len]))
4343 ++len;
4344
4345 adding = FALSE;
4346 prepending = FALSE;
4347 removing = FALSE;
4348 if (arg[len] != NUL && arg[len + 1] == '=')
4349 {
4350 if (arg[len] == '+')
4351 {
4352 adding = TRUE; /* "+=" */
4353 ++len;
4354 }
4355 else if (arg[len] == '^')
4356 {
4357 prepending = TRUE; /* "^=" */
4358 ++len;
4359 }
4360 else if (arg[len] == '-')
4361 {
4362 removing = TRUE; /* "-=" */
4363 ++len;
4364 }
4365 }
4366 nextchar = arg[len];
4367
4368 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4369 {
4370 errmsg = (char_u *)N_("E518: Unknown option");
4371 goto skip;
4372 }
4373
4374 if (opt_idx >= 0)
4375 {
4376 if (options[opt_idx].var == NULL) /* hidden option: skip */
4377 {
4378 /* Only give an error message when requesting the value of
4379 * a hidden option, ignore setting it. */
4380 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4381 && (!(options[opt_idx].flags & P_BOOL)
4382 || nextchar == '?'))
4383 errmsg = (char_u *)N_("E519: Option not supported");
4384 goto skip;
4385 }
4386
4387 flags = options[opt_idx].flags;
4388 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4389 }
4390 else
4391 {
4392 flags = P_STRING;
4393 if (key < 0)
4394 {
4395 key_name[0] = KEY2TERMCAP0(key);
4396 key_name[1] = KEY2TERMCAP1(key);
4397 }
4398 else
4399 {
4400 key_name[0] = KS_KEY;
4401 key_name[1] = (key & 0xff);
4402 }
4403 }
4404
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004405 /* Skip all options that are not window-local (used when showing
4406 * an already loaded buffer in a window). */
4407 if ((opt_flags & OPT_WINONLY)
4408 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4409 goto skip;
4410
Bram Moolenaara3227e22006-03-08 21:32:40 +00004411 /* Skip all options that are window-local (used for :vimgrep). */
4412 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4413 && options[opt_idx].var == VAR_WIN)
4414 goto skip;
4415
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004416 /* Disallow changing some options from modelines. */
4417 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004418 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004419 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004420 {
4421 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4422 goto skip;
4423 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004424#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004425 /* In diff mode some options are overruled. This avoids that
4426 * 'foldmethod' becomes "marker" instead of "diff" and that
4427 * "wrap" gets set. */
4428 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004429 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004430 && (options[opt_idx].indir == PV_FDM
4431 || options[opt_idx].indir == PV_WRAP))
4432 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004433#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004434 }
4435
4436#ifdef HAVE_SANDBOX
4437 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004438 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439 {
4440 errmsg = (char_u *)_(e_sandbox);
4441 goto skip;
4442 }
4443#endif
4444
4445 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4446 {
4447 arg += len;
4448 cp_val = p_cp;
4449 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4450 {
4451 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4452 {
4453 cp_val = FALSE;
4454 arg += 3;
4455 }
4456 else /* "opt&vi": set to Vi default */
4457 {
4458 cp_val = TRUE;
4459 arg += 2;
4460 }
4461 }
4462 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4463 && arg[1] != NUL && !vim_iswhite(arg[1]))
4464 {
4465 errmsg = e_trailing;
4466 goto skip;
4467 }
4468 }
4469
4470 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004471 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4472 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004473 */
4474 if (nextchar == '?'
4475 || (prefix == 1
4476 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4477 && !(flags & P_BOOL)))
4478 {
4479 /*
4480 * print value
4481 */
4482 if (did_show)
4483 msg_putchar('\n'); /* cursor below last one */
4484 else
4485 {
4486 gotocmdline(TRUE); /* cursor at status line */
4487 did_show = TRUE; /* remember that we did a line */
4488 }
4489 if (opt_idx >= 0)
4490 {
4491 showoneopt(&options[opt_idx], opt_flags);
4492#ifdef FEAT_EVAL
4493 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004494 {
4495 /* Mention where the option was last set. */
4496 if (varp == options[opt_idx].var)
4497 last_set_msg(options[opt_idx].scriptID);
4498 else if ((int)options[opt_idx].indir & PV_WIN)
4499 last_set_msg(curwin->w_p_scriptID[
4500 (int)options[opt_idx].indir & PV_MASK]);
4501 else if ((int)options[opt_idx].indir & PV_BUF)
4502 last_set_msg(curbuf->b_p_scriptID[
4503 (int)options[opt_idx].indir & PV_MASK]);
4504 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004505#endif
4506 }
4507 else
4508 {
4509 char_u *p;
4510
4511 p = find_termcode(key_name);
4512 if (p == NULL)
4513 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004514 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004515 goto skip;
4516 }
4517 else
4518 (void)show_one_termcode(key_name, p, TRUE);
4519 }
4520 if (nextchar != '?'
4521 && nextchar != NUL && !vim_iswhite(afterchar))
4522 errmsg = e_trailing;
4523 }
4524 else
4525 {
4526 if (flags & P_BOOL) /* boolean */
4527 {
4528 if (nextchar == '=' || nextchar == ':')
4529 {
4530 errmsg = e_invarg;
4531 goto skip;
4532 }
4533
4534 /*
4535 * ":set opt!": invert
4536 * ":set opt&": reset to default value
4537 * ":set opt<": reset to global value
4538 */
4539 if (nextchar == '!')
4540 value = *(int *)(varp) ^ 1;
4541 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004542 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004543 ((flags & P_VI_DEF) || cp_val)
4544 ? VI_DEFAULT : VIM_DEFAULT];
4545 else if (nextchar == '<')
4546 {
4547 /* For 'autoread' -1 means to use global value. */
4548 if ((int *)varp == &curbuf->b_p_ar
4549 && opt_flags == OPT_LOCAL)
4550 value = -1;
4551 else
4552 value = *(int *)get_varp_scope(&(options[opt_idx]),
4553 OPT_GLOBAL);
4554 }
4555 else
4556 {
4557 /*
4558 * ":set invopt": invert
4559 * ":set opt" or ":set noopt": set or reset
4560 */
4561 if (nextchar != NUL && !vim_iswhite(afterchar))
4562 {
4563 errmsg = e_trailing;
4564 goto skip;
4565 }
4566 if (prefix == 2) /* inv */
4567 value = *(int *)(varp) ^ 1;
4568 else
4569 value = prefix;
4570 }
4571
4572 errmsg = set_bool_option(opt_idx, varp, (int)value,
4573 opt_flags);
4574 }
4575 else /* numeric or string */
4576 {
4577 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4578 || prefix != 1)
4579 {
4580 errmsg = e_invarg;
4581 goto skip;
4582 }
4583
4584 if (flags & P_NUM) /* numeric */
4585 {
4586 /*
4587 * Different ways to set a number option:
4588 * & set to default value
4589 * < set to global value
4590 * <xx> accept special key codes for 'wildchar'
4591 * c accept any non-digit for 'wildchar'
4592 * [-]0-9 set number
4593 * other error
4594 */
4595 ++arg;
4596 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004597 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004598 ((flags & P_VI_DEF) || cp_val)
4599 ? VI_DEFAULT : VIM_DEFAULT];
4600 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004601 {
4602 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4603 * use the global value. */
4604 if ((long *)varp == &curbuf->b_p_ul
4605 && opt_flags == OPT_LOCAL)
4606 value = NO_LOCAL_UNDOLEVEL;
4607 else
4608 value = *(long *)get_varp_scope(
4609 &(options[opt_idx]), OPT_GLOBAL);
4610 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611 else if (((long *)varp == &p_wc
4612 || (long *)varp == &p_wcm)
4613 && (*arg == '<'
4614 || *arg == '^'
4615 || ((!arg[1] || vim_iswhite(arg[1]))
4616 && !VIM_ISDIGIT(*arg))))
4617 {
4618 value = string_to_key(arg);
4619 if (value == 0 && (long *)varp != &p_wcm)
4620 {
4621 errmsg = e_invarg;
4622 goto skip;
4623 }
4624 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004625 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4626 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004627 /* Allow negative (for 'undolevels'), octal and
4628 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004629 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4630 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004631 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4632 {
4633 errmsg = e_invarg;
4634 goto skip;
4635 }
4636 }
4637 else
4638 {
4639 errmsg = (char_u *)N_("E521: Number required after =");
4640 goto skip;
4641 }
4642
4643 if (adding)
4644 value = *(long *)varp + value;
4645 if (prepending)
4646 value = *(long *)varp * value;
4647 if (removing)
4648 value = *(long *)varp - value;
4649 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004650 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651 }
4652 else if (opt_idx >= 0) /* string */
4653 {
4654 char_u *save_arg = NULL;
4655 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004656 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004657 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004658 char_u *origval = NULL;
4659#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4660 char_u *saved_origval = NULL;
4661#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004662 unsigned newlen;
4663 int comma;
4664 int bs;
4665 int new_value_alloced; /* new string option
4666 was allocated */
4667
4668 /* When using ":set opt=val" for a global option
4669 * with a local value the local value will be
4670 * reset, use the global value here. */
4671 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004672 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004673 varp = options[opt_idx].var;
4674
4675 /* The old value is kept until we are sure that the
4676 * new value is valid. */
4677 oldval = *(char_u **)varp;
4678 if (nextchar == '&') /* set to default val */
4679 {
4680 newval = options[opt_idx].def_val[
4681 ((flags & P_VI_DEF) || cp_val)
4682 ? VI_DEFAULT : VIM_DEFAULT];
4683 if ((char_u **)varp == &p_bg)
4684 {
4685 /* guess the value of 'background' */
4686#ifdef FEAT_GUI
4687 if (gui.in_use)
4688 newval = gui_bg_default();
4689 else
4690#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004691 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004692 }
4693
4694 /* expand environment variables and ~ (since the
4695 * default value was already expanded, only
4696 * required when an environment variable was set
4697 * later */
4698 if (newval == NULL)
4699 newval = empty_option;
4700 else
4701 {
4702 s = option_expand(opt_idx, newval);
4703 if (s == NULL)
4704 s = newval;
4705 newval = vim_strsave(s);
4706 }
4707 new_value_alloced = TRUE;
4708 }
4709 else if (nextchar == '<') /* set to global val */
4710 {
4711 newval = vim_strsave(*(char_u **)get_varp_scope(
4712 &(options[opt_idx]), OPT_GLOBAL));
4713 new_value_alloced = TRUE;
4714 }
4715 else
4716 {
4717 ++arg; /* jump to after the '=' or ':' */
4718
4719 /*
4720 * Set 'keywordprg' to ":help" if an empty
4721 * value was passed to :set by the user.
4722 * Misuse errbuf[] for the resulting string.
4723 */
4724 if (varp == (char_u *)&p_kp
4725 && (*arg == NUL || *arg == ' '))
4726 {
4727 STRCPY(errbuf, ":help");
4728 save_arg = arg;
4729 arg = errbuf;
4730 }
4731 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004732 * Convert 'backspace' number to string, for
4733 * adding, prepending and removing string.
4734 */
4735 else if (varp == (char_u *)&p_bs
4736 && VIM_ISDIGIT(**(char_u **)varp))
4737 {
4738 i = getdigits((char_u **)varp);
4739 switch (i)
4740 {
4741 case 0:
4742 *(char_u **)varp = empty_option;
4743 break;
4744 case 1:
4745 *(char_u **)varp = vim_strsave(
4746 (char_u *)"indent,eol");
4747 break;
4748 case 2:
4749 *(char_u **)varp = vim_strsave(
4750 (char_u *)"indent,eol,start");
4751 break;
4752 }
4753 vim_free(oldval);
4754 oldval = *(char_u **)varp;
4755 }
4756 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004757 * Convert 'whichwrap' number to string, for
4758 * backwards compatibility with Vim 3.0.
4759 * Misuse errbuf[] for the resulting string.
4760 */
4761 else if (varp == (char_u *)&p_ww
4762 && VIM_ISDIGIT(*arg))
4763 {
4764 *errbuf = NUL;
4765 i = getdigits(&arg);
4766 if (i & 1)
4767 STRCAT(errbuf, "b,");
4768 if (i & 2)
4769 STRCAT(errbuf, "s,");
4770 if (i & 4)
4771 STRCAT(errbuf, "h,l,");
4772 if (i & 8)
4773 STRCAT(errbuf, "<,>,");
4774 if (i & 16)
4775 STRCAT(errbuf, "[,],");
4776 if (*errbuf != NUL) /* remove trailing , */
4777 errbuf[STRLEN(errbuf) - 1] = NUL;
4778 save_arg = arg;
4779 arg = errbuf;
4780 }
4781 /*
4782 * Remove '>' before 'dir' and 'bdir', for
4783 * backwards compatibility with version 3.0
4784 */
4785 else if ( *arg == '>'
4786 && (varp == (char_u *)&p_dir
4787 || varp == (char_u *)&p_bdir))
4788 {
4789 ++arg;
4790 }
4791
4792 /* When setting the local value of a global
4793 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004794 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 && (opt_flags & OPT_LOCAL))
4796 origval = *(char_u **)get_varp(
4797 &options[opt_idx]);
4798 else
4799 origval = oldval;
4800
4801 /*
4802 * Copy the new string into allocated memory.
4803 * Can't use set_string_option_direct(), because
4804 * we need to remove the backslashes.
4805 */
4806 /* get a bit too much */
4807 newlen = (unsigned)STRLEN(arg) + 1;
4808 if (adding || prepending || removing)
4809 newlen += (unsigned)STRLEN(origval) + 1;
4810 newval = alloc(newlen);
4811 if (newval == NULL) /* out of mem, don't change */
4812 break;
4813 s = newval;
4814
4815 /*
4816 * Copy the string, skip over escaped chars.
4817 * For MS-DOS and WIN32 backslashes before normal
4818 * file name characters are not removed, and keep
4819 * backslash at start, for "\\machine\path", but
4820 * do remove it for "\\\\machine\\path".
4821 * The reverse is found in ExpandOldSetting().
4822 */
4823 while (*arg && !vim_iswhite(*arg))
4824 {
4825 if (*arg == '\\' && arg[1] != NUL
4826#ifdef BACKSLASH_IN_FILENAME
4827 && !((flags & P_EXPAND)
4828 && vim_isfilec(arg[1])
4829 && (arg[1] != '\\'
4830 || (s == newval
4831 && arg[2] != '\\')))
4832#endif
4833 )
4834 ++arg; /* remove backslash */
4835#ifdef FEAT_MBYTE
4836 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004837 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004838 {
4839 /* copy multibyte char */
4840 mch_memmove(s, arg, (size_t)i);
4841 arg += i;
4842 s += i;
4843 }
4844 else
4845#endif
4846 *s++ = *arg++;
4847 }
4848 *s = NUL;
4849
4850 /*
4851 * Expand environment variables and ~.
4852 * Don't do it when adding without inserting a
4853 * comma.
4854 */
4855 if (!(adding || prepending || removing)
4856 || (flags & P_COMMA))
4857 {
4858 s = option_expand(opt_idx, newval);
4859 if (s != NULL)
4860 {
4861 vim_free(newval);
4862 newlen = (unsigned)STRLEN(s) + 1;
4863 if (adding || prepending || removing)
4864 newlen += (unsigned)STRLEN(origval) + 1;
4865 newval = alloc(newlen);
4866 if (newval == NULL)
4867 break;
4868 STRCPY(newval, s);
4869 }
4870 }
4871
4872 /* locate newval[] in origval[] when removing it
4873 * and when adding to avoid duplicates */
4874 i = 0; /* init for GCC */
4875 if (removing || (flags & P_NODUP))
4876 {
4877 i = (int)STRLEN(newval);
4878 bs = 0;
4879 for (s = origval; *s; ++s)
4880 {
4881 if ((!(flags & P_COMMA)
4882 || s == origval
4883 || (s[-1] == ',' && !(bs & 1)))
4884 && STRNCMP(s, newval, i) == 0
4885 && (!(flags & P_COMMA)
4886 || s[i] == ','
4887 || s[i] == NUL))
4888 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004889 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004890 * even number of backslashes or a single
4891 * backslash preceded by a comma before it
4892 * is recognized as a separator */
4893 if ((s > origval + 1
4894 && s[-1] == '\\'
4895 && s[-2] != ',')
4896 || (s == origval + 1
4897 && s[-1] == '\\'))
4898
Bram Moolenaar071d4272004-06-13 20:20:40 +00004899 ++bs;
4900 else
4901 bs = 0;
4902 }
4903
4904 /* do not add if already there */
4905 if ((adding || prepending) && *s)
4906 {
4907 prepending = FALSE;
4908 adding = FALSE;
4909 STRCPY(newval, origval);
4910 }
4911 }
4912
4913 /* concatenate the two strings; add a ',' if
4914 * needed */
4915 if (adding || prepending)
4916 {
4917 comma = ((flags & P_COMMA) && *origval != NUL
4918 && *newval != NUL);
4919 if (adding)
4920 {
4921 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004922 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004923 if (comma && i > 1
4924 && (flags & P_ONECOMMA) == P_ONECOMMA
4925 && origval[i - 1] == ','
4926 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004927 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004928 mch_memmove(newval + i + comma, newval,
4929 STRLEN(newval) + 1);
4930 mch_memmove(newval, origval, (size_t)i);
4931 }
4932 else
4933 {
4934 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004935 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004936 }
4937 if (comma)
4938 newval[i] = ',';
4939 }
4940
4941 /* Remove newval[] from origval[]. (Note: "i" has
4942 * been set above and is used here). */
4943 if (removing)
4944 {
4945 STRCPY(newval, origval);
4946 if (*s)
4947 {
4948 /* may need to remove a comma */
4949 if (flags & P_COMMA)
4950 {
4951 if (s == origval)
4952 {
4953 /* include comma after string */
4954 if (s[i] == ',')
4955 ++i;
4956 }
4957 else
4958 {
4959 /* include comma before string */
4960 --s;
4961 ++i;
4962 }
4963 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004964 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004965 }
4966 }
4967
4968 if (flags & P_FLAGLIST)
4969 {
4970 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004971 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004972 {
4973 /* if options have P_FLAGLIST and
4974 * P_ONECOMMA such as 'whichwrap' */
4975 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004976 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004977 if (*s != ',' && *(s + 1) == ','
4978 && vim_strchr(s + 2, *s) != NULL)
4979 {
4980 /* Remove the duplicated value and
4981 * the next comma. */
4982 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004983 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004984 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004985 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004986 else
4987 {
4988 if ((!(flags & P_COMMA) || *s != ',')
4989 && vim_strchr(s + 1, *s) != NULL)
4990 {
4991 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004992 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004993 }
4994 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004995 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004996 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004997 }
4998
4999 if (save_arg != NULL) /* number for 'whichwrap' */
5000 arg = save_arg;
5001 new_value_alloced = TRUE;
5002 }
5003
5004 /* Set the new value. */
5005 *(char_u **)(varp) = newval;
5006
Bram Moolenaar53744302015-07-17 17:38:22 +02005007#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005008 if (!starting
5009# ifdef FEAT_CRYPT
5010 && options[opt_idx].indir != PV_KEY
5011# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02005012 && origval != NULL)
5013 /* origval may be freed by
5014 * did_set_string_option(), make a copy. */
5015 saved_origval = vim_strsave(origval);
5016#endif
5017
Bram Moolenaar071d4272004-06-13 20:20:40 +00005018 /* Handle side effects, and set the global value for
5019 * ":set" on local options. */
5020 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5021 new_value_alloced, oldval, errbuf, opt_flags);
5022
5023 /* If error detected, print the error message. */
5024 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005025 {
5026#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5027 vim_free(saved_origval);
5028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005029 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005030 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005031#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5032 if (saved_origval != NULL)
5033 {
5034 char_u buf_type[7];
5035
5036 sprintf((char *)buf_type, "%s",
5037 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005038 set_vim_var_string(VV_OPTION_NEW,
5039 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005040 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5041 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5042 apply_autocmds(EVENT_OPTIONSET,
5043 (char_u *)options[opt_idx].fullname,
5044 NULL, FALSE, NULL);
5045 reset_v_option_vars();
5046 vim_free(saved_origval);
5047 }
5048#endif
5049
Bram Moolenaar071d4272004-06-13 20:20:40 +00005050 }
5051 else /* key code option */
5052 {
5053 char_u *p;
5054
5055 if (nextchar == '&')
5056 {
5057 if (add_termcap_entry(key_name, TRUE) == FAIL)
5058 errmsg = (char_u *)N_("E522: Not found in termcap");
5059 }
5060 else
5061 {
5062 ++arg; /* jump to after the '=' or ':' */
5063 for (p = arg; *p && !vim_iswhite(*p); ++p)
5064 if (*p == '\\' && p[1] != NUL)
5065 ++p;
5066 nextchar = *p;
5067 *p = NUL;
5068 add_termcode(key_name, arg, FALSE);
5069 *p = nextchar;
5070 }
5071 if (full_screen)
5072 ttest(FALSE);
5073 redraw_all_later(CLEAR);
5074 }
5075 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005076
Bram Moolenaar071d4272004-06-13 20:20:40 +00005077 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005078 did_set_option(opt_idx, opt_flags,
5079 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005080 }
5081
5082skip:
5083 /*
5084 * Advance to next argument.
5085 * - skip until a blank found, taking care of backslashes
5086 * - skip blanks
5087 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5088 */
5089 for (i = 0; i < 2 ; ++i)
5090 {
5091 while (*arg != NUL && !vim_iswhite(*arg))
5092 if (*arg++ == '\\' && *arg != NUL)
5093 ++arg;
5094 arg = skipwhite(arg);
5095 if (*arg != '=')
5096 break;
5097 }
5098 }
5099
5100 if (errmsg != NULL)
5101 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005102 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005103 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005104 if (i + (arg - startarg) < IOSIZE)
5105 {
5106 /* append the argument with the error */
5107 STRCAT(IObuff, ": ");
5108 mch_memmove(IObuff + i, startarg, (arg - startarg));
5109 IObuff[i + (arg - startarg)] = NUL;
5110 }
5111 /* make sure all characters are printable */
5112 trans_characters(IObuff, IOSIZE);
5113
5114 ++no_wait_return; /* wait_return done later */
5115 emsg(IObuff); /* show error highlighted */
5116 --no_wait_return;
5117
5118 return FAIL;
5119 }
5120
5121 arg = skipwhite(arg);
5122 }
5123
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005124theend:
5125 if (silent_mode && did_show)
5126 {
5127 /* After displaying option values in silent mode. */
5128 silent_mode = FALSE;
5129 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5130 msg_putchar('\n');
5131 cursor_on(); /* msg_start() switches it off */
5132 out_flush();
5133 silent_mode = TRUE;
5134 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5135 }
5136
Bram Moolenaar071d4272004-06-13 20:20:40 +00005137 return OK;
5138}
5139
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005140/*
5141 * Call this when an option has been given a new value through a user command.
5142 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5143 */
5144 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005145did_set_option(
5146 int opt_idx,
5147 int opt_flags, /* possibly with OPT_MODELINE */
5148 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005149{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005150 long_u *p;
5151
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005152 options[opt_idx].flags |= P_WAS_SET;
5153
5154 /* When an option is set in the sandbox, from a modeline or in secure mode
5155 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005156 * flag. */
5157 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005158 if (secure
5159#ifdef HAVE_SANDBOX
5160 || sandbox != 0
5161#endif
5162 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005163 *p = *p | P_INSECURE;
5164 else if (new_value)
5165 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005166}
5167
Bram Moolenaar071d4272004-06-13 20:20:40 +00005168 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005169illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005170{
5171 if (errbuf == NULL)
5172 return (char_u *)"";
5173 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005174 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005175 return errbuf;
5176}
5177
5178/*
5179 * Convert a key name or string into a key value.
5180 * Used for 'wildchar' and 'cedit' options.
5181 */
5182 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005183string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005184{
5185 if (*arg == '<')
5186 return find_key_option(arg + 1);
5187 if (*arg == '^')
5188 return Ctrl_chr(arg[1]);
5189 return *arg;
5190}
5191
5192#ifdef FEAT_CMDWIN
5193/*
5194 * Check value of 'cedit' and set cedit_key.
5195 * Returns NULL if value is OK, error message otherwise.
5196 */
5197 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005198check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005199{
5200 int n;
5201
5202 if (*p_cedit == NUL)
5203 cedit_key = -1;
5204 else
5205 {
5206 n = string_to_key(p_cedit);
5207 if (vim_isprintc(n))
5208 return e_invarg;
5209 cedit_key = n;
5210 }
5211 return NULL;
5212}
5213#endif
5214
5215#ifdef FEAT_TITLE
5216/*
5217 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5218 * maketitle() to create and display it.
5219 * When switching the title or icon off, call mch_restore_title() to get
5220 * the old value back.
5221 */
5222 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005223did_set_title(
5224 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005225{
5226 if (starting != NO_SCREEN
5227#ifdef FEAT_GUI
5228 && !gui.starting
5229#endif
5230 )
5231 {
5232 maketitle();
5233 if (icon)
5234 {
5235 if (!p_icon)
5236 mch_restore_title(2);
5237 }
5238 else
5239 {
5240 if (!p_title)
5241 mch_restore_title(1);
5242 }
5243 }
5244}
5245#endif
5246
5247/*
5248 * set_options_bin - called when 'bin' changes value.
5249 */
5250 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005251set_options_bin(
5252 int oldval,
5253 int newval,
5254 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005255{
5256 /*
5257 * The option values that are changed when 'bin' changes are
5258 * copied when 'bin is set and restored when 'bin' is reset.
5259 */
5260 if (newval)
5261 {
5262 if (!oldval) /* switched on */
5263 {
5264 if (!(opt_flags & OPT_GLOBAL))
5265 {
5266 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5267 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5268 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5269 curbuf->b_p_et_nobin = curbuf->b_p_et;
5270 }
5271 if (!(opt_flags & OPT_LOCAL))
5272 {
5273 p_tw_nobin = p_tw;
5274 p_wm_nobin = p_wm;
5275 p_ml_nobin = p_ml;
5276 p_et_nobin = p_et;
5277 }
5278 }
5279
5280 if (!(opt_flags & OPT_GLOBAL))
5281 {
5282 curbuf->b_p_tw = 0; /* no automatic line wrap */
5283 curbuf->b_p_wm = 0; /* no automatic line wrap */
5284 curbuf->b_p_ml = 0; /* no modelines */
5285 curbuf->b_p_et = 0; /* no expandtab */
5286 }
5287 if (!(opt_flags & OPT_LOCAL))
5288 {
5289 p_tw = 0;
5290 p_wm = 0;
5291 p_ml = FALSE;
5292 p_et = FALSE;
5293 p_bin = TRUE; /* needed when called for the "-b" argument */
5294 }
5295 }
5296 else if (oldval) /* switched off */
5297 {
5298 if (!(opt_flags & OPT_GLOBAL))
5299 {
5300 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5301 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5302 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5303 curbuf->b_p_et = curbuf->b_p_et_nobin;
5304 }
5305 if (!(opt_flags & OPT_LOCAL))
5306 {
5307 p_tw = p_tw_nobin;
5308 p_wm = p_wm_nobin;
5309 p_ml = p_ml_nobin;
5310 p_et = p_et_nobin;
5311 }
5312 }
5313}
5314
5315#ifdef FEAT_VIMINFO
5316/*
5317 * Find the parameter represented by the given character (eg ', :, ", or /),
5318 * and return its associated value in the 'viminfo' string.
5319 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005320 * If the parameter is not specified in the string or there is no following
5321 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322 */
5323 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005324get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325{
5326 char_u *p;
5327
5328 p = find_viminfo_parameter(type);
5329 if (p != NULL && VIM_ISDIGIT(*p))
5330 return atoi((char *)p);
5331 return -1;
5332}
5333
5334/*
5335 * Find the parameter represented by the given character (eg ''', ':', '"', or
5336 * '/') in the 'viminfo' option and return a pointer to the string after it.
5337 * Return NULL if the parameter is not specified in the string.
5338 */
5339 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005340find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341{
5342 char_u *p;
5343
5344 for (p = p_viminfo; *p; ++p)
5345 {
5346 if (*p == type)
5347 return p + 1;
5348 if (*p == 'n') /* 'n' is always the last one */
5349 break;
5350 p = vim_strchr(p, ','); /* skip until next ',' */
5351 if (p == NULL) /* hit the end without finding parameter */
5352 break;
5353 }
5354 return NULL;
5355}
5356#endif
5357
5358/*
5359 * Expand environment variables for some string options.
5360 * These string options cannot be indirect!
5361 * If "val" is NULL expand the current value of the option.
5362 * Return pointer to NameBuff, or NULL when not expanded.
5363 */
5364 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005365option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005366{
5367 /* if option doesn't need expansion nothing to do */
5368 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5369 return NULL;
5370
5371 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5372 * expand_env() would truncate the string. */
5373 if (val != NULL && STRLEN(val) > MAXPATHL)
5374 return NULL;
5375
5376 if (val == NULL)
5377 val = *(char_u **)options[opt_idx].var;
5378
5379 /*
5380 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5381 * Escape spaces when expanding 'tags', they are used to separate file
5382 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005383 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005384 */
5385 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005386 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005387#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005388 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5389#endif
5390 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005391 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5392 return NULL;
5393
5394 return NameBuff;
5395}
5396
5397/*
5398 * After setting various option values: recompute variables that depend on
5399 * option values.
5400 */
5401 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005402didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005403{
5404 /* initialize the table for 'iskeyword' et.al. */
5405 (void)init_chartab();
5406
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005407#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005408 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005409#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005410 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005411 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005412#ifdef FEAT_SESSION
5413 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5414 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5415#endif
5416#ifdef FEAT_FOLDING
5417 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5418#endif
5419 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005420 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005421#ifdef FEAT_VIRTUALEDIT
5422 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5423#endif
5424#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5425 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5426#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005427#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005428 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005429 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005430 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005431 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5434 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5435#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005436#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005437 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5438#endif
5439#ifdef FEAT_CMDWIN
5440 /* set cedit_key */
5441 (void)check_cedit();
5442#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005443#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005444 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005445#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005446#ifdef FEAT_LINEBREAK
5447 /* initialize the table for 'breakat'. */
5448 fill_breakat_flags();
5449#endif
5450
5451}
5452
5453/*
5454 * More side effects of setting options.
5455 */
5456 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005457didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005458{
5459 /* Initialize the highlight_attr[] table. */
5460 (void)highlight_changed();
5461
5462 /* Parse default for 'wildmode' */
5463 check_opt_wim();
5464
5465 (void)set_chars_option(&p_lcs);
5466#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5467 /* Parse default for 'fillchars'. */
5468 (void)set_chars_option(&p_fcs);
5469#endif
5470
5471#ifdef FEAT_CLIPBOARD
5472 /* Parse default for 'clipboard' */
5473 (void)check_clipboard_option();
5474#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005475}
5476
5477/*
5478 * Check for string options that are NULL (normally only termcap options).
5479 */
5480 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005481check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005482{
5483 int opt_idx;
5484
5485 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5486 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5487 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5488}
5489
5490/*
5491 * Check string options in a buffer for NULL value.
5492 */
5493 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005494check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495{
5496#if defined(FEAT_QUICKFIX)
5497 check_string_option(&buf->b_p_bh);
5498 check_string_option(&buf->b_p_bt);
5499#endif
5500#ifdef FEAT_MBYTE
5501 check_string_option(&buf->b_p_fenc);
5502#endif
5503 check_string_option(&buf->b_p_ff);
5504#ifdef FEAT_FIND_ID
5505 check_string_option(&buf->b_p_def);
5506 check_string_option(&buf->b_p_inc);
5507# ifdef FEAT_EVAL
5508 check_string_option(&buf->b_p_inex);
5509# endif
5510#endif
5511#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5512 check_string_option(&buf->b_p_inde);
5513 check_string_option(&buf->b_p_indk);
5514#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005515#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5516 check_string_option(&buf->b_p_bexpr);
5517#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005518#if defined(FEAT_CRYPT)
5519 check_string_option(&buf->b_p_cm);
5520#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005521 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005522#if defined(FEAT_EVAL)
5523 check_string_option(&buf->b_p_fex);
5524#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005525#ifdef FEAT_CRYPT
5526 check_string_option(&buf->b_p_key);
5527#endif
5528 check_string_option(&buf->b_p_kp);
5529 check_string_option(&buf->b_p_mps);
5530 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005531 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005532 check_string_option(&buf->b_p_isk);
5533#ifdef FEAT_COMMENTS
5534 check_string_option(&buf->b_p_com);
5535#endif
5536#ifdef FEAT_FOLDING
5537 check_string_option(&buf->b_p_cms);
5538#endif
5539 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005540#ifdef FEAT_TEXTOBJ
5541 check_string_option(&buf->b_p_qe);
5542#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005543#ifdef FEAT_SYN_HL
5544 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005545 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005546#endif
5547#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005548 check_string_option(&buf->b_s.b_p_spc);
5549 check_string_option(&buf->b_s.b_p_spf);
5550 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005551#endif
5552#ifdef FEAT_SEARCHPATH
5553 check_string_option(&buf->b_p_sua);
5554#endif
5555#ifdef FEAT_CINDENT
5556 check_string_option(&buf->b_p_cink);
5557 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005558 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559#endif
5560#ifdef FEAT_AUTOCMD
5561 check_string_option(&buf->b_p_ft);
5562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005563#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5564 check_string_option(&buf->b_p_cinw);
5565#endif
5566#ifdef FEAT_INS_EXPAND
5567 check_string_option(&buf->b_p_cpt);
5568#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005569#ifdef FEAT_COMPL_FUNC
5570 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005571 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005572#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573#ifdef FEAT_KEYMAP
5574 check_string_option(&buf->b_p_keymap);
5575#endif
5576#ifdef FEAT_QUICKFIX
5577 check_string_option(&buf->b_p_gp);
5578 check_string_option(&buf->b_p_mp);
5579 check_string_option(&buf->b_p_efm);
5580#endif
5581 check_string_option(&buf->b_p_ep);
5582 check_string_option(&buf->b_p_path);
5583 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005584 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585#ifdef FEAT_INS_EXPAND
5586 check_string_option(&buf->b_p_dict);
5587 check_string_option(&buf->b_p_tsr);
5588#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005589#ifdef FEAT_LISP
5590 check_string_option(&buf->b_p_lw);
5591#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005592 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005593}
5594
5595/*
5596 * Free the string allocated for an option.
5597 * Checks for the string being empty_option. This may happen if we're out of
5598 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5599 * check_options().
5600 * Does NOT check for P_ALLOCED flag!
5601 */
5602 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005603free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005604{
5605 if (p != empty_option)
5606 vim_free(p);
5607}
5608
5609 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005610clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005611{
5612 if (*pp != empty_option)
5613 vim_free(*pp);
5614 *pp = empty_option;
5615}
5616
5617 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005618check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005619{
5620 if (*pp == NULL)
5621 *pp = empty_option;
5622}
5623
5624/*
5625 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5626 */
5627 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005628set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005629{
5630 int opt_idx;
5631
5632 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5633 if (options[opt_idx].var == (char_u *)p)
5634 {
5635 options[opt_idx].flags |= P_ALLOCED;
5636 return;
5637 }
5638 return; /* cannot happen: didn't find it! */
5639}
5640
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005641#if defined(FEAT_EVAL) || defined(PROTO)
5642/*
5643 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5644 * Return FALSE when it wasn't.
5645 * Return -1 for an unknown option.
5646 */
5647 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005648was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005649{
5650 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005651 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005652
5653 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005654 {
5655 flagp = insecure_flag(idx, opt_flags);
5656 return (*flagp & P_INSECURE) != 0;
5657 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005658 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005659 return -1;
5660}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005661
5662/*
5663 * Get a pointer to the flags used for the P_INSECURE flag of option
5664 * "opt_idx". For some local options a local flags field is used.
5665 */
5666 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005667insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005668{
5669 if (opt_flags & OPT_LOCAL)
5670 switch ((int)options[opt_idx].indir)
5671 {
5672#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005673 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005674#endif
5675#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005676# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005677 case PV_FDE: return &curwin->w_p_fde_flags;
5678 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005679# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005680# ifdef FEAT_BEVAL
5681 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5682# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005683# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005684 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005685# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005686 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005687# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005688 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005689# endif
5690#endif
5691 }
5692
5693 /* Nothing special, return global flags field. */
5694 return &options[opt_idx].flags;
5695}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005696#endif
5697
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005698#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005699static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005700
5701/*
5702 * Redraw the window title and/or tab page text later.
5703 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005704static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005705{
5706 need_maketitle = TRUE;
5707# ifdef FEAT_WINDOWS
5708 redraw_tabline = TRUE;
5709# endif
5710}
5711#endif
5712
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713/*
5714 * Set a string option to a new value (without checking the effect).
5715 * The string is copied into allocated memory.
5716 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005717 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005718 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719 */
5720 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005721set_string_option_direct(
5722 char_u *name,
5723 int opt_idx,
5724 char_u *val,
5725 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5726 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727{
5728 char_u *s;
5729 char_u **varp;
5730 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005731 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005732
Bram Moolenaar89d40322006-08-29 15:30:07 +00005733 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005734 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005735 idx = findoption(name);
5736 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005737 {
5738 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005739 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005740 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005741 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005742 }
5743
Bram Moolenaar89d40322006-08-29 15:30:07 +00005744 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745 return;
5746
5747 s = vim_strsave(val);
5748 if (s != NULL)
5749 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005750 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005752 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753 free_string_option(*varp);
5754 *varp = s;
5755
5756 /* For buffer/window local option may also set the global value. */
5757 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005758 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759
Bram Moolenaar89d40322006-08-29 15:30:07 +00005760 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005761
5762 /* When setting both values of a global option with a local value,
5763 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005764 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765 {
5766 free_string_option(*varp);
5767 *varp = empty_option;
5768 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005769# ifdef FEAT_EVAL
5770 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005771 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005772 set_sid == 0 ? current_SID : set_sid);
5773# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005774 }
5775}
5776
5777/*
5778 * Set global value for string option when it's a local option.
5779 */
5780 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005781set_string_option_global(
5782 int opt_idx, /* option index */
5783 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005784{
5785 char_u **p, *s;
5786
5787 /* the global value is always allocated */
5788 if (options[opt_idx].var == VAR_WIN)
5789 p = (char_u **)GLOBAL_WO(varp);
5790 else
5791 p = (char_u **)options[opt_idx].var;
5792 if (options[opt_idx].indir != PV_NONE
5793 && p != varp
5794 && (s = vim_strsave(*varp)) != NULL)
5795 {
5796 free_string_option(*p);
5797 *p = s;
5798 }
5799}
5800
5801/*
5802 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005803 *
5804 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005805 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005806 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005807set_string_option(
5808 int opt_idx,
5809 char_u *value,
5810 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005811{
5812 char_u *s;
5813 char_u **varp;
5814 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005815#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5816 char_u *saved_oldval = NULL;
5817#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005818 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005819
5820 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005821 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005822
5823 s = vim_strsave(value);
5824 if (s != NULL)
5825 {
5826 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5827 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005828 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005829 ? OPT_GLOBAL : OPT_LOCAL)
5830 : opt_flags);
5831 oldval = *varp;
5832 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005833
5834#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005835 if (!starting
5836# ifdef FEAT_CRYPT
5837 && options[opt_idx].indir != PV_KEY
5838# endif
5839 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005840 saved_oldval = vim_strsave(oldval);
5841#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005842 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5843 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005844 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005845
5846 /* call autocomamnd after handling side effects */
5847#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5848 if (saved_oldval != NULL)
5849 {
5850 char_u buf_type[7];
5851 sprintf((char *)buf_type, "%s",
5852 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005853 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5854 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005855 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5856 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5857 reset_v_option_vars();
5858 vim_free(saved_oldval);
5859 }
5860#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005861 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005862 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005863}
5864
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005865#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005866/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005867 * Return TRUE if "val" is a valid 'filetype' name.
5868 * Also used for 'syntax' and 'keymap'.
5869 */
5870 static int
5871valid_filetype(char_u *val)
5872{
5873 char_u *s;
5874
5875 for (s = val; *s != NUL; ++s)
5876 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5877 return FALSE;
5878 return TRUE;
5879}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005880#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005881
5882/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883 * Handle string options that need some action to perform when changed.
5884 * Returns NULL for success, or an error message for an error.
5885 */
5886 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005887did_set_string_option(
5888 int opt_idx, /* index in options[] table */
5889 char_u **varp, /* pointer to the option variable */
5890 int new_value_alloced, /* new value was allocated */
5891 char_u *oldval, /* previous value of the option */
5892 char_u *errbuf, /* buffer for errors, or NULL */
5893 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894{
5895 char_u *errmsg = NULL;
5896 char_u *s, *p;
5897 int did_chartab = FALSE;
5898 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005899 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005900#ifdef FEAT_GUI
5901 /* set when changing an option that only requires a redraw in the GUI */
5902 int redraw_gui_only = FALSE;
5903#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904
5905 /* Get the global option to compare with, otherwise we would have to check
5906 * two values for all local options. */
5907 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5908
5909 /* Disallow changing some options from secure mode */
5910 if ((secure
5911#ifdef HAVE_SANDBOX
5912 || sandbox != 0
5913#endif
5914 ) && (options[opt_idx].flags & P_SECURE))
5915 {
5916 errmsg = e_secure;
5917 }
5918
Bram Moolenaar7554da42016-11-25 22:04:13 +01005919 /* Check for a "normal" directory or file name in some options. Disallow a
5920 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005921 * are often illegal in a file name. Be more permissive if "secure" is off.
5922 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01005923 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005924 && vim_strpbrk(*varp, (char_u *)(secure
5925 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01005926 || ((options[opt_idx].flags & P_NDNAME)
5927 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005928 {
5929 errmsg = e_invarg;
5930 }
5931
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932 /* 'term' */
5933 else if (varp == &T_NAME)
5934 {
5935 if (T_NAME[0] == NUL)
5936 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5937#ifdef FEAT_GUI
5938 if (gui.in_use)
5939 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5940 else if (term_is_gui(T_NAME))
5941 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5942#endif
5943 else if (set_termname(T_NAME) == FAIL)
5944 errmsg = (char_u *)N_("E522: Not found in termcap");
5945 else
Bram Moolenaar67391142017-02-19 21:07:04 +01005946 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00005947 /* Screen colors may have changed. */
5948 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01005949
5950 /* Both 'term' and 'ttytype' point to T_NAME, only set the
5951 * P_ALLOCED flag on 'term'. */
5952 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01005953 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01005954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005955 }
5956
5957 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005958 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005960 char_u *bkc = p_bkc;
5961 unsigned int *flags = &bkc_flags;
5962
5963 if (opt_flags & OPT_LOCAL)
5964 {
5965 bkc = curbuf->b_p_bkc;
5966 flags = &curbuf->b_bkc_flags;
5967 }
5968
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005969 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5970 /* make the local value empty: use the global value */
5971 *flags = 0;
5972 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005973 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005974 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5975 errmsg = e_invarg;
5976 if ((((int)*flags & BKC_AUTO) != 0)
5977 + (((int)*flags & BKC_YES) != 0)
5978 + (((int)*flags & BKC_NO) != 0) != 1)
5979 {
5980 /* Must have exactly one of "auto", "yes" and "no". */
5981 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5982 errmsg = e_invarg;
5983 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984 }
5985 }
5986
5987 /* 'backupext' and 'patchmode' */
5988 else if (varp == &p_bex || varp == &p_pm)
5989 {
5990 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5991 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5992 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5993 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005994#ifdef FEAT_LINEBREAK
5995 /* 'breakindentopt' */
5996 else if (varp == &curwin->w_p_briopt)
5997 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005998 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005999 errmsg = e_invarg;
6000 }
6001#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006002
6003 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006004 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006006 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006007 */
6008 else if ( varp == &p_isi
6009 || varp == &(curbuf->b_p_isk)
6010 || varp == &p_isp
6011 || varp == &p_isf)
6012 {
6013 if (init_chartab() == FAIL)
6014 {
6015 did_chartab = TRUE; /* need to restore it below */
6016 errmsg = e_invarg; /* error in value */
6017 }
6018 }
6019
6020 /* 'helpfile' */
6021 else if (varp == &p_hf)
6022 {
6023 /* May compute new values for $VIM and $VIMRUNTIME */
6024 if (didset_vim)
6025 {
6026 vim_setenv((char_u *)"VIM", (char_u *)"");
6027 didset_vim = FALSE;
6028 }
6029 if (didset_vimruntime)
6030 {
6031 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6032 didset_vimruntime = FALSE;
6033 }
6034 }
6035
Bram Moolenaar1a384422010-07-14 19:53:30 +02006036#ifdef FEAT_SYN_HL
6037 /* 'colorcolumn' */
6038 else if (varp == &curwin->w_p_cc)
6039 errmsg = check_colorcolumn(curwin);
6040#endif
6041
Bram Moolenaar071d4272004-06-13 20:20:40 +00006042#ifdef FEAT_MULTI_LANG
6043 /* 'helplang' */
6044 else if (varp == &p_hlg)
6045 {
6046 /* Check for "", "ab", "ab,cd", etc. */
6047 for (s = p_hlg; *s != NUL; s += 3)
6048 {
6049 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6050 {
6051 errmsg = e_invarg;
6052 break;
6053 }
6054 if (s[2] == NUL)
6055 break;
6056 }
6057 }
6058#endif
6059
6060 /* 'highlight' */
6061 else if (varp == &p_hl)
6062 {
6063 if (highlight_changed() == FAIL)
6064 errmsg = e_invarg; /* invalid flags */
6065 }
6066
6067 /* 'nrformats' */
6068 else if (gvarp == &p_nf)
6069 {
6070 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6071 errmsg = e_invarg;
6072 }
6073
6074#ifdef FEAT_SESSION
6075 /* 'sessionoptions' */
6076 else if (varp == &p_ssop)
6077 {
6078 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6079 errmsg = e_invarg;
6080 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6081 {
6082 /* Don't allow both "sesdir" and "curdir". */
6083 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6084 errmsg = e_invarg;
6085 }
6086 }
6087 /* 'viewoptions' */
6088 else if (varp == &p_vop)
6089 {
6090 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6091 errmsg = e_invarg;
6092 }
6093#endif
6094
6095 /* 'scrollopt' */
6096#ifdef FEAT_SCROLLBIND
6097 else if (varp == &p_sbo)
6098 {
6099 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6100 errmsg = e_invarg;
6101 }
6102#endif
6103
6104 /* 'ambiwidth' */
6105#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006106 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107 {
6108 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6109 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006110 else if (set_chars_option(&p_lcs) != NULL)
6111 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6112# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6113 else if (set_chars_option(&p_fcs) != NULL)
6114 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6115# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 }
6117#endif
6118
6119 /* 'background' */
6120 else if (varp == &p_bg)
6121 {
6122 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6123 {
6124#ifdef FEAT_EVAL
6125 int dark = (*p_bg == 'd');
6126#endif
6127
6128 init_highlight(FALSE, FALSE);
6129
6130#ifdef FEAT_EVAL
6131 if (dark != (*p_bg == 'd')
6132 && get_var_value((char_u *)"g:colors_name") != NULL)
6133 {
6134 /* The color scheme must have set 'background' back to another
6135 * value, that's not what we want here. Disable the color
6136 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006137 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138 free_string_option(p_bg);
6139 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6140 check_string_option(&p_bg);
6141 init_highlight(FALSE, FALSE);
6142 }
6143#endif
6144 }
6145 else
6146 errmsg = e_invarg;
6147 }
6148
6149 /* 'wildmode' */
6150 else if (varp == &p_wim)
6151 {
6152 if (check_opt_wim() == FAIL)
6153 errmsg = e_invarg;
6154 }
6155
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006156#ifdef FEAT_CMDL_COMPL
6157 /* 'wildoptions' */
6158 else if (varp == &p_wop)
6159 {
6160 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6161 errmsg = e_invarg;
6162 }
6163#endif
6164
Bram Moolenaar071d4272004-06-13 20:20:40 +00006165#ifdef FEAT_WAK
6166 /* 'winaltkeys' */
6167 else if (varp == &p_wak)
6168 {
6169 if (*p_wak == NUL
6170 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6171 errmsg = e_invarg;
6172# ifdef FEAT_MENU
6173# ifdef FEAT_GUI_MOTIF
6174 else if (gui.in_use)
6175 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6176# else
6177# ifdef FEAT_GUI_GTK
6178 else if (gui.in_use)
6179 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6180# endif
6181# endif
6182# endif
6183 }
6184#endif
6185
6186#ifdef FEAT_AUTOCMD
6187 /* 'eventignore' */
6188 else if (varp == &p_ei)
6189 {
6190 if (check_ei() == FAIL)
6191 errmsg = e_invarg;
6192 }
6193#endif
6194
6195#ifdef FEAT_MBYTE
6196 /* 'encoding' and 'fileencoding' */
6197 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6198 {
6199 if (gvarp == &p_fenc)
6200 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006201 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 errmsg = e_modifiable;
6203 else if (vim_strchr(*varp, ',') != NULL)
6204 /* No comma allowed in 'fileencoding'; catches confusing it
6205 * with 'fileencodings'. */
6206 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006207 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006208 {
6209# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006210 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006211 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006213 /* Add 'fileencoding' to the swap file. */
6214 ml_setflags(curbuf);
6215 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006216 }
6217 if (errmsg == NULL)
6218 {
6219 /* canonize the value, so that STRCMP() can be used on it */
6220 p = enc_canonize(*varp);
6221 if (p != NULL)
6222 {
6223 vim_free(*varp);
6224 *varp = p;
6225 }
6226 if (varp == &p_enc)
6227 {
6228 errmsg = mb_init();
6229# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006230 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006231# endif
6232 }
6233 }
6234
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006235# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006236 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6237 {
6238 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6239 if (STRCMP(p_tenc, "utf-8") != 0)
6240 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6241 }
6242# endif
6243
6244 if (errmsg == NULL)
6245 {
6246# ifdef FEAT_KEYMAP
6247 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6248 * (with another encoding). */
6249 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6250 (void)keymap_init();
6251# endif
6252
6253 /* When 'termencoding' is not empty and 'encoding' changes or when
6254 * 'termencoding' changes, need to setup for keyboard input and
6255 * display output conversion. */
6256 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6257 {
6258 convert_setup(&input_conv, p_tenc, p_enc);
6259 convert_setup(&output_conv, p_enc, p_tenc);
6260 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006261
6262# if defined(WIN3264) && defined(FEAT_MBYTE)
6263 /* $HOME may have characters in active code page. */
6264 if (varp == &p_enc)
6265 init_homedir();
6266# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006267 }
6268 }
6269#endif
6270
6271#if defined(FEAT_POSTSCRIPT)
6272 else if (varp == &p_penc)
6273 {
6274 /* Canonize printencoding if VIM standard one */
6275 p = enc_canonize(p_penc);
6276 if (p != NULL)
6277 {
6278 vim_free(p_penc);
6279 p_penc = p;
6280 }
6281 else
6282 {
6283 /* Ensure lower case and '-' for '_' */
6284 for (s = p_penc; *s != NUL; s++)
6285 {
6286 if (*s == '_')
6287 *s = '-';
6288 else
6289 *s = TOLOWER_ASC(*s);
6290 }
6291 }
6292 }
6293#endif
6294
Bram Moolenaar9372a112005-12-06 19:59:18 +00006295#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296 else if (varp == &p_imak)
6297 {
6298 if (gui.in_use && !im_xim_isvalid_imactivate())
6299 errmsg = e_invarg;
6300 }
6301#endif
6302
6303#ifdef FEAT_KEYMAP
6304 else if (varp == &curbuf->b_p_keymap)
6305 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006306 if (!valid_filetype(*varp))
6307 errmsg = e_invarg;
6308 else
6309 /* load or unload key mapping tables */
6310 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006311
Bram Moolenaarfab06232009-03-04 03:13:35 +00006312 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006314 if (*curbuf->b_p_keymap != NUL)
6315 {
6316 /* Installed a new keymap, switch on using it. */
6317 curbuf->b_p_iminsert = B_IMODE_LMAP;
6318 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6319 curbuf->b_p_imsearch = B_IMODE_LMAP;
6320 }
6321 else
6322 {
6323 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6324 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6325 curbuf->b_p_iminsert = B_IMODE_NONE;
6326 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6327 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6328 }
6329 if ((opt_flags & OPT_LOCAL) == 0)
6330 {
6331 set_iminsert_global();
6332 set_imsearch_global();
6333 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334# ifdef FEAT_WINDOWS
6335 status_redraw_curbuf();
6336# endif
6337 }
6338 }
6339#endif
6340
6341 /* 'fileformat' */
6342 else if (gvarp == &p_ff)
6343 {
6344 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6345 errmsg = e_modifiable;
6346 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6347 errmsg = e_invarg;
6348 else
6349 {
6350 /* may also change 'textmode' */
6351 if (get_fileformat(curbuf) == EOL_DOS)
6352 curbuf->b_p_tx = TRUE;
6353 else
6354 curbuf->b_p_tx = FALSE;
6355#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006356 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006358 /* update flag in swap file */
6359 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006360 /* Redraw needed when switching to/from "mac": a CR in the text
6361 * will be displayed differently. */
6362 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6363 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006364 }
6365 }
6366
6367 /* 'fileformats' */
6368 else if (varp == &p_ffs)
6369 {
6370 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6371 errmsg = e_invarg;
6372 else
6373 {
6374 /* also change 'textauto' */
6375 if (*p_ffs == NUL)
6376 p_ta = FALSE;
6377 else
6378 p_ta = TRUE;
6379 }
6380 }
6381
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006382#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383 /* 'cryptkey' */
6384 else if (gvarp == &p_key)
6385 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006386# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006387 /* Make sure the ":set" command doesn't show the new value in the
6388 * history. */
6389 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006390# endif
6391 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6392 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006393 ml_set_crypt_key(curbuf, oldval,
6394 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006395 }
6396
6397 else if (gvarp == &p_cm)
6398 {
6399 if (opt_flags & OPT_LOCAL)
6400 p = curbuf->b_p_cm;
6401 else
6402 p = p_cm;
6403 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6404 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006405 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006406 errmsg = e_invarg;
6407 else
6408 {
6409 /* When setting the global value to empty, make it "zip". */
6410 if (*p_cm == NUL)
6411 {
6412 if (new_value_alloced)
6413 free_string_option(p_cm);
6414 p_cm = vim_strsave((char_u *)"zip");
6415 new_value_alloced = TRUE;
6416 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006417 /* When using ":set cm=name" the local value is going to be empty.
6418 * Do that here, otherwise the crypt functions will still use the
6419 * local value. */
6420 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6421 {
6422 free_string_option(curbuf->b_p_cm);
6423 curbuf->b_p_cm = empty_option;
6424 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006425
6426 /* Need to update the swapfile when the effective method changed.
6427 * Set "s" to the effective old value, "p" to the effective new
6428 * method and compare. */
6429 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6430 s = p_cm; /* was previously using the global value */
6431 else
6432 s = oldval;
6433 if (*curbuf->b_p_cm == NUL)
6434 p = p_cm; /* is now using the global value */
6435 else
6436 p = curbuf->b_p_cm;
6437 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006438 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006439
6440 /* If the global value changes need to update the swapfile for all
6441 * buffers using that value. */
6442 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6443 {
6444 buf_T *buf;
6445
Bram Moolenaar29323592016-07-24 22:04:11 +02006446 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006447 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006448 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006449 }
6450 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006451 }
6452#endif
6453
6454 /* 'matchpairs' */
6455 else if (gvarp == &p_mps)
6456 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006457#ifdef FEAT_MBYTE
6458 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006459 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006460 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006461 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006462 int x2 = -1;
6463 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006464
6465 if (*p != NUL)
6466 p += mb_ptr2len(p);
6467 if (*p != NUL)
6468 x2 = *p++;
6469 if (*p != NUL)
6470 {
6471 x3 = mb_ptr2char(p);
6472 p += mb_ptr2len(p);
6473 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006474 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006475 {
6476 errmsg = e_invarg;
6477 break;
6478 }
6479 if (*p == NUL)
6480 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006481 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006482 }
6483 else
6484#endif
6485 {
6486 /* Check for "x:y,x:y" */
6487 for (p = *varp; *p != NUL; p += 4)
6488 {
6489 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6490 {
6491 errmsg = e_invarg;
6492 break;
6493 }
6494 if (p[3] == NUL)
6495 break;
6496 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006497 }
6498 }
6499
6500#ifdef FEAT_COMMENTS
6501 /* 'comments' */
6502 else if (gvarp == &p_com)
6503 {
6504 for (s = *varp; *s; )
6505 {
6506 while (*s && *s != ':')
6507 {
6508 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6509 && !VIM_ISDIGIT(*s) && *s != '-')
6510 {
6511 errmsg = illegal_char(errbuf, *s);
6512 break;
6513 }
6514 ++s;
6515 }
6516 if (*s++ == NUL)
6517 errmsg = (char_u *)N_("E524: Missing colon");
6518 else if (*s == ',' || *s == NUL)
6519 errmsg = (char_u *)N_("E525: Zero length string");
6520 if (errmsg != NULL)
6521 break;
6522 while (*s && *s != ',')
6523 {
6524 if (*s == '\\' && s[1] != NUL)
6525 ++s;
6526 ++s;
6527 }
6528 s = skip_to_option_part(s);
6529 }
6530 }
6531#endif
6532
6533 /* 'listchars' */
6534 else if (varp == &p_lcs)
6535 {
6536 errmsg = set_chars_option(varp);
6537 }
6538
6539#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6540 /* 'fillchars' */
6541 else if (varp == &p_fcs)
6542 {
6543 errmsg = set_chars_option(varp);
6544 }
6545#endif
6546
6547#ifdef FEAT_CMDWIN
6548 /* 'cedit' */
6549 else if (varp == &p_cedit)
6550 {
6551 errmsg = check_cedit();
6552 }
6553#endif
6554
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006555 /* 'verbosefile' */
6556 else if (varp == &p_vfile)
6557 {
6558 verbose_stop();
6559 if (*p_vfile != NUL && verbose_open() == FAIL)
6560 errmsg = e_invarg;
6561 }
6562
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563#ifdef FEAT_VIMINFO
6564 /* 'viminfo' */
6565 else if (varp == &p_viminfo)
6566 {
6567 for (s = p_viminfo; *s;)
6568 {
6569 /* Check it's a valid character */
6570 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6571 {
6572 errmsg = illegal_char(errbuf, *s);
6573 break;
6574 }
6575 if (*s == 'n') /* name is always last one */
6576 {
6577 break;
6578 }
6579 else if (*s == 'r') /* skip until next ',' */
6580 {
6581 while (*++s && *s != ',')
6582 ;
6583 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006584 else if (*s == '%')
6585 {
6586 /* optional number */
6587 while (vim_isdigit(*++s))
6588 ;
6589 }
6590 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006591 ++s; /* no extra chars */
6592 else /* must have a number */
6593 {
6594 while (vim_isdigit(*++s))
6595 ;
6596
6597 if (!VIM_ISDIGIT(*(s - 1)))
6598 {
6599 if (errbuf != NULL)
6600 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006601 sprintf((char *)errbuf,
6602 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006603 transchar_byte(*(s - 1)));
6604 errmsg = errbuf;
6605 }
6606 else
6607 errmsg = (char_u *)"";
6608 break;
6609 }
6610 }
6611 if (*s == ',')
6612 ++s;
6613 else if (*s)
6614 {
6615 if (errbuf != NULL)
6616 errmsg = (char_u *)N_("E527: Missing comma");
6617 else
6618 errmsg = (char_u *)"";
6619 break;
6620 }
6621 }
6622 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6623 errmsg = (char_u *)N_("E528: Must specify a ' value");
6624 }
6625#endif /* FEAT_VIMINFO */
6626
6627 /* terminal options */
6628 else if (istermoption(&options[opt_idx]) && full_screen)
6629 {
6630 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6631 if (varp == &T_CCO)
6632 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006633 int colors = atoi((char *)T_CCO);
6634
6635 /* Only reinitialize colors if t_Co value has really changed to
6636 * avoid expensive reload of colorscheme if t_Co is set to the
6637 * same value multiple times. */
6638 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006639 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006640 t_colors = colors;
6641 if (t_colors <= 1)
6642 {
6643 if (new_value_alloced)
6644 vim_free(T_CCO);
6645 T_CCO = empty_option;
6646 }
6647 /* We now have a different color setup, initialize it again. */
6648 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006650 }
6651 ttest(FALSE);
6652 if (varp == &T_ME)
6653 {
6654 out_str(T_ME);
6655 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006656#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006657 /* Since t_me has been set, this probably means that the user
6658 * wants to use this as default colors. Need to reset default
6659 * background/foreground colors. */
6660 mch_set_normal_colors();
6661#endif
6662 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006663 if (varp == &T_BE && termcap_active)
6664 {
6665 if (*T_BE == NUL)
6666 /* When clearing t_BE we assume the user no longer wants
6667 * bracketed paste, thus disable it by writing t_BD. */
6668 out_str(T_BD);
6669 else
6670 out_str(T_BE);
6671 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006672 }
6673
6674#ifdef FEAT_LINEBREAK
6675 /* 'showbreak' */
6676 else if (varp == &p_sbr)
6677 {
6678 for (s = p_sbr; *s; )
6679 {
6680 if (ptr2cells(s) != 1)
6681 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006682 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006683 }
6684 }
6685#endif
6686
6687#ifdef FEAT_GUI
6688 /* 'guifont' */
6689 else if (varp == &p_guifont)
6690 {
6691 if (gui.in_use)
6692 {
6693 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006694# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006695 /*
6696 * Put up a font dialog and let the user select a new value.
6697 * If this is cancelled go back to the old value but don't
6698 * give an error message.
6699 */
6700 if (STRCMP(p, "*") == 0)
6701 {
6702 p = gui_mch_font_dialog(oldval);
6703
6704 if (new_value_alloced)
6705 free_string_option(p_guifont);
6706
6707 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6708 new_value_alloced = TRUE;
6709 }
6710# endif
6711 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6712 {
6713# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6714 if (STRCMP(p_guifont, "*") == 0)
6715 {
6716 /* Dialog was cancelled: Keep the old value without giving
6717 * an error message. */
6718 if (new_value_alloced)
6719 free_string_option(p_guifont);
6720 p_guifont = vim_strsave(oldval);
6721 new_value_alloced = TRUE;
6722 }
6723 else
6724# endif
6725 errmsg = (char_u *)N_("E596: Invalid font(s)");
6726 }
6727 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006728 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006729 }
6730# ifdef FEAT_XFONTSET
6731 else if (varp == &p_guifontset)
6732 {
6733 if (STRCMP(p_guifontset, "*") == 0)
6734 errmsg = (char_u *)N_("E597: can't select fontset");
6735 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6736 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006737 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006738 }
6739# endif
6740# ifdef FEAT_MBYTE
6741 else if (varp == &p_guifontwide)
6742 {
6743 if (STRCMP(p_guifontwide, "*") == 0)
6744 errmsg = (char_u *)N_("E533: can't select wide font");
6745 else if (gui_get_wide_font() == FAIL)
6746 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006747 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 }
6749# endif
6750#endif
6751
6752#ifdef CURSOR_SHAPE
6753 /* 'guicursor' */
6754 else if (varp == &p_guicursor)
6755 errmsg = parse_shape_opt(SHAPE_CURSOR);
6756#endif
6757
6758#ifdef FEAT_MOUSESHAPE
6759 /* 'mouseshape' */
6760 else if (varp == &p_mouseshape)
6761 {
6762 errmsg = parse_shape_opt(SHAPE_MOUSE);
6763 update_mouseshape(-1);
6764 }
6765#endif
6766
6767#ifdef FEAT_PRINTER
6768 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006769 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006770# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006771 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006772 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006773# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006774#endif
6775
6776#ifdef FEAT_LANGMAP
6777 /* 'langmap' */
6778 else if (varp == &p_langmap)
6779 langmap_set();
6780#endif
6781
6782#ifdef FEAT_LINEBREAK
6783 /* 'breakat' */
6784 else if (varp == &p_breakat)
6785 fill_breakat_flags();
6786#endif
6787
6788#ifdef FEAT_TITLE
6789 /* 'titlestring' and 'iconstring' */
6790 else if (varp == &p_titlestring || varp == &p_iconstring)
6791 {
6792# ifdef FEAT_STL_OPT
6793 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6794
6795 /* NULL => statusline syntax */
6796 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6797 stl_syntax |= flagval;
6798 else
6799 stl_syntax &= ~flagval;
6800# endif
6801 did_set_title(varp == &p_iconstring);
6802
6803 }
6804#endif
6805
6806#ifdef FEAT_GUI
6807 /* 'guioptions' */
6808 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006809 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006810 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006811 redraw_gui_only = TRUE;
6812 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006813#endif
6814
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006815#if defined(FEAT_GUI_TABLINE)
6816 /* 'guitablabel' */
6817 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006818 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006819 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006820 redraw_gui_only = TRUE;
6821 }
6822 /* 'guitabtooltip' */
6823 else if (varp == &p_gtt)
6824 {
6825 redraw_gui_only = TRUE;
6826 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006827#endif
6828
Bram Moolenaar071d4272004-06-13 20:20:40 +00006829#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6830 /* 'ttymouse' */
6831 else if (varp == &p_ttym)
6832 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006833 /* Switch the mouse off before changing the escape sequences used for
6834 * that. */
6835 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006836 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6837 errmsg = e_invarg;
6838 else
6839 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006840 if (termcap_active)
6841 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006842 }
6843#endif
6844
Bram Moolenaar071d4272004-06-13 20:20:40 +00006845 /* 'selection' */
6846 else if (varp == &p_sel)
6847 {
6848 if (*p_sel == NUL
6849 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6850 errmsg = e_invarg;
6851 }
6852
6853 /* 'selectmode' */
6854 else if (varp == &p_slm)
6855 {
6856 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6857 errmsg = e_invarg;
6858 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006859
6860#ifdef FEAT_BROWSE
6861 /* 'browsedir' */
6862 else if (varp == &p_bsdir)
6863 {
6864 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6865 && !mch_isdir(p_bsdir))
6866 errmsg = e_invarg;
6867 }
6868#endif
6869
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870 /* 'keymodel' */
6871 else if (varp == &p_km)
6872 {
6873 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6874 errmsg = e_invarg;
6875 else
6876 {
6877 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6878 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6879 }
6880 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881
6882 /* 'mousemodel' */
6883 else if (varp == &p_mousem)
6884 {
6885 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6886 errmsg = e_invarg;
6887#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6888 else if (*p_mousem != *oldval)
6889 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6890 * to create or delete the popup menus. */
6891 gui_motif_update_mousemodel(root_menu);
6892#endif
6893 }
6894
6895 /* 'switchbuf' */
6896 else if (varp == &p_swb)
6897 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006898 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 errmsg = e_invarg;
6900 }
6901
6902 /* 'debug' */
6903 else if (varp == &p_debug)
6904 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006905 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 errmsg = e_invarg;
6907 }
6908
6909 /* 'display' */
6910 else if (varp == &p_dy)
6911 {
6912 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6913 errmsg = e_invarg;
6914 else
6915 (void)init_chartab();
6916
6917 }
6918
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006919#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006920 /* 'eadirection' */
6921 else if (varp == &p_ead)
6922 {
6923 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6924 errmsg = e_invarg;
6925 }
6926#endif
6927
6928#ifdef FEAT_CLIPBOARD
6929 /* 'clipboard' */
6930 else if (varp == &p_cb)
6931 errmsg = check_clipboard_option();
6932#endif
6933
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006934#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006935 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6936 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006937 else if (varp == &(curwin->w_s->b_p_spl)
6938 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006939 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006940 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006941 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006942 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006943 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006944 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006945 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006946 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006947 /* 'spellsuggest' */
6948 else if (varp == &p_sps)
6949 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006950 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006951 errmsg = e_invarg;
6952 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006953 /* 'mkspellmem' */
6954 else if (varp == &p_msm)
6955 {
6956 if (spell_check_msm() != OK)
6957 errmsg = e_invarg;
6958 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006959#endif
6960
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961#ifdef FEAT_QUICKFIX
6962 /* When 'bufhidden' is set, check for valid value. */
6963 else if (gvarp == &p_bh)
6964 {
6965 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6966 errmsg = e_invarg;
6967 }
6968
6969 /* When 'buftype' is set, check for valid value. */
6970 else if (gvarp == &p_bt)
6971 {
6972 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6973 errmsg = e_invarg;
6974 else
6975 {
6976# ifdef FEAT_WINDOWS
6977 if (curwin->w_status_height)
6978 {
6979 curwin->w_redr_status = TRUE;
6980 redraw_later(VALID);
6981 }
6982# endif
6983 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006984# ifdef FEAT_TITLE
6985 redraw_titles();
6986# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006987 }
6988 }
6989#endif
6990
6991#ifdef FEAT_STL_OPT
6992 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006993 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006994 {
6995 int wid;
6996
6997 if (varp == &p_ruf) /* reset ru_wid first */
6998 ru_wid = 0;
6999 s = *varp;
7000 if (varp == &p_ruf && *s == '%')
7001 {
7002 /* set ru_wid if 'ruf' starts with "%99(" */
7003 if (*++s == '-') /* ignore a '-' */
7004 s++;
7005 wid = getdigits(&s);
7006 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7007 ru_wid = wid;
7008 else
7009 errmsg = check_stl_option(p_ruf);
7010 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007011 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007012 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007014 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015 comp_col();
7016 }
7017#endif
7018
7019#ifdef FEAT_INS_EXPAND
7020 /* check if it is a valid value for 'complete' -- Acevedo */
7021 else if (gvarp == &p_cpt)
7022 {
7023 for (s = *varp; *s;)
7024 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007025 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026 s++;
7027 if (!*s)
7028 break;
7029 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7030 {
7031 errmsg = illegal_char(errbuf, *s);
7032 break;
7033 }
7034 if (*++s != NUL && *s != ',' && *s != ' ')
7035 {
7036 if (s[-1] == 'k' || s[-1] == 's')
7037 {
7038 /* skip optional filename after 'k' and 's' */
7039 while (*s && *s != ',' && *s != ' ')
7040 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007041 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 ++s;
7043 ++s;
7044 }
7045 }
7046 else
7047 {
7048 if (errbuf != NULL)
7049 {
7050 sprintf((char *)errbuf,
7051 _("E535: Illegal character after <%c>"),
7052 *--s);
7053 errmsg = errbuf;
7054 }
7055 else
7056 errmsg = (char_u *)"";
7057 break;
7058 }
7059 }
7060 }
7061 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007062
7063 /* 'completeopt' */
7064 else if (varp == &p_cot)
7065 {
7066 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7067 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007068 else
7069 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007070 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007071#endif /* FEAT_INS_EXPAND */
7072
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007073#ifdef FEAT_SIGNS
7074 /* 'signcolumn' */
7075 else if (varp == &curwin->w_p_scl)
7076 {
7077 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7078 errmsg = e_invarg;
7079 }
7080#endif
7081
Bram Moolenaar071d4272004-06-13 20:20:40 +00007082
7083#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007084 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007085 else if (varp == &p_toolbar)
7086 {
7087 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7088 &toolbar_flags, TRUE) != 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
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007099#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100 /* 'toolbariconsize': GTK+ 2 only */
7101 else if (varp == &p_tbis)
7102 {
7103 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7104 errmsg = e_invarg;
7105 else
7106 {
7107 out_flush();
7108 gui_mch_show_toolbar((toolbar_flags &
7109 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7110 }
7111 }
7112#endif
7113
7114 /* 'pastetoggle': translate key codes like in a mapping */
7115 else if (varp == &p_pt)
7116 {
7117 if (*p_pt)
7118 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007119 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 if (p != NULL)
7121 {
7122 if (new_value_alloced)
7123 free_string_option(p_pt);
7124 p_pt = p;
7125 new_value_alloced = TRUE;
7126 }
7127 }
7128 }
7129
7130 /* 'backspace' */
7131 else if (varp == &p_bs)
7132 {
7133 if (VIM_ISDIGIT(*p_bs))
7134 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007135 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007136 errmsg = e_invarg;
7137 }
7138 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7139 errmsg = e_invarg;
7140 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007141 else if (varp == &p_bo)
7142 {
7143 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7144 errmsg = e_invarg;
7145 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007146
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007147 /* 'tagcase' */
7148 else if (gvarp == &p_tc)
7149 {
7150 unsigned int *flags;
7151
7152 if (opt_flags & OPT_LOCAL)
7153 {
7154 p = curbuf->b_p_tc;
7155 flags = &curbuf->b_tc_flags;
7156 }
7157 else
7158 {
7159 p = p_tc;
7160 flags = &tc_flags;
7161 }
7162
7163 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7164 /* make the local value empty: use the global value */
7165 *flags = 0;
7166 else if (*p == NUL
7167 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7168 errmsg = e_invarg;
7169 }
7170
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007171#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007172 /* 'casemap' */
7173 else if (varp == &p_cmp)
7174 {
7175 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7176 errmsg = e_invarg;
7177 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007178#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007179
7180#ifdef FEAT_DIFF
7181 /* 'diffopt' */
7182 else if (varp == &p_dip)
7183 {
7184 if (diffopt_changed() == FAIL)
7185 errmsg = e_invarg;
7186 }
7187#endif
7188
7189#ifdef FEAT_FOLDING
7190 /* 'foldmethod' */
7191 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7192 {
7193 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7194 || *curwin->w_p_fdm == NUL)
7195 errmsg = e_invarg;
7196 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007197 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007199 if (foldmethodIsDiff(curwin))
7200 newFoldLevel();
7201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007202 }
7203# ifdef FEAT_EVAL
7204 /* 'foldexpr' */
7205 else if (varp == &curwin->w_p_fde)
7206 {
7207 if (foldmethodIsExpr(curwin))
7208 foldUpdateAll(curwin);
7209 }
7210# endif
7211 /* 'foldmarker' */
7212 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7213 {
7214 p = vim_strchr(*varp, ',');
7215 if (p == NULL)
7216 errmsg = (char_u *)N_("E536: comma required");
7217 else if (p == *varp || p[1] == NUL)
7218 errmsg = e_invarg;
7219 else if (foldmethodIsMarker(curwin))
7220 foldUpdateAll(curwin);
7221 }
7222 /* 'commentstring' */
7223 else if (gvarp == &p_cms)
7224 {
7225 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7226 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7227 }
7228 /* 'foldopen' */
7229 else if (varp == &p_fdo)
7230 {
7231 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7232 errmsg = e_invarg;
7233 }
7234 /* 'foldclose' */
7235 else if (varp == &p_fcl)
7236 {
7237 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7238 errmsg = e_invarg;
7239 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007240 /* 'foldignore' */
7241 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7242 {
7243 if (foldmethodIsIndent(curwin))
7244 foldUpdateAll(curwin);
7245 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007246#endif
7247
7248#ifdef FEAT_VIRTUALEDIT
7249 /* 'virtualedit' */
7250 else if (varp == &p_ve)
7251 {
7252 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7253 errmsg = e_invarg;
7254 else if (STRCMP(p_ve, oldval) != 0)
7255 {
7256 /* Recompute cursor position in case the new 've' setting
7257 * changes something. */
7258 validate_virtcol();
7259 coladvance(curwin->w_virtcol);
7260 }
7261 }
7262#endif
7263
7264#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7265 else if (varp == &p_csqf)
7266 {
7267 if (p_csqf != NULL)
7268 {
7269 p = p_csqf;
7270 while (*p != NUL)
7271 {
7272 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7273 || p[1] == NUL
7274 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7275 || (p[2] != NUL && p[2] != ','))
7276 {
7277 errmsg = e_invarg;
7278 break;
7279 }
7280 else if (p[2] == NUL)
7281 break;
7282 else
7283 p += 3;
7284 }
7285 }
7286 }
7287#endif
7288
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007289#ifdef FEAT_CINDENT
7290 /* 'cinoptions' */
7291 else if (gvarp == &p_cino)
7292 {
7293 /* TODO: recognize errors */
7294 parse_cino(curbuf);
7295 }
7296#endif
7297
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007298#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007299 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007300 else if (varp == &p_rop && gui.in_use)
7301 {
7302 if (!gui_mch_set_rendering_options(p_rop))
7303 errmsg = e_invarg;
7304 }
7305#endif
7306
Bram Moolenaard0b51382016-11-04 15:23:45 +01007307#ifdef FEAT_AUTOCMD
7308 else if (gvarp == &p_ft)
7309 {
7310 if (!valid_filetype(*varp))
7311 errmsg = e_invarg;
7312 }
7313#endif
7314
7315#ifdef FEAT_SYN_HL
7316 else if (gvarp == &p_syn)
7317 {
7318 if (!valid_filetype(*varp))
7319 errmsg = e_invarg;
7320 }
7321#endif
7322
Bram Moolenaar071d4272004-06-13 20:20:40 +00007323 /* Options that are a list of flags. */
7324 else
7325 {
7326 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007327 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007328 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007329 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007330 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007331 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007332 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007333 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007334 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007335#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007336 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007337 p = (char_u *)COCU_ALL;
7338#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007339 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007340 {
7341#ifdef FEAT_MOUSE
7342 p = (char_u *)MOUSE_ALL;
7343#else
7344 if (*p_mouse != NUL)
7345 errmsg = (char_u *)N_("E538: No mouse support");
7346#endif
7347 }
7348#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007349 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350 p = (char_u *)GO_ALL;
7351#endif
7352 if (p != NULL)
7353 {
7354 for (s = *varp; *s; ++s)
7355 if (vim_strchr(p, *s) == NULL)
7356 {
7357 errmsg = illegal_char(errbuf, *s);
7358 break;
7359 }
7360 }
7361 }
7362
7363 /*
7364 * If error detected, restore the previous value.
7365 */
7366 if (errmsg != NULL)
7367 {
7368 if (new_value_alloced)
7369 free_string_option(*varp);
7370 *varp = oldval;
7371 /*
7372 * When resetting some values, need to act on it.
7373 */
7374 if (did_chartab)
7375 (void)init_chartab();
7376 if (varp == &p_hl)
7377 (void)highlight_changed();
7378 }
7379 else
7380 {
7381#ifdef FEAT_EVAL
7382 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007383 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007384#endif
7385 /*
7386 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007387 * Use "free_oldval", because recursiveness may change the flags under
7388 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007389 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007390 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007391 free_string_option(oldval);
7392 if (new_value_alloced)
7393 options[opt_idx].flags |= P_ALLOCED;
7394 else
7395 options[opt_idx].flags &= ~P_ALLOCED;
7396
7397 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007398 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007399 {
7400 /* global option with local value set to use global value; free
7401 * the local value and make it empty */
7402 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7403 free_string_option(*(char_u **)p);
7404 *(char_u **)p = empty_option;
7405 }
7406
7407 /* May set global value for local option. */
7408 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7409 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007410
7411#ifdef FEAT_AUTOCMD
7412 /*
7413 * Trigger the autocommand only after setting the flags.
7414 */
7415# ifdef FEAT_SYN_HL
7416 /* When 'syntax' is set, load the syntax of that name */
7417 if (varp == &(curbuf->b_p_syn))
7418 {
7419 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7420 curbuf->b_fname, TRUE, curbuf);
7421 }
7422# endif
7423 else if (varp == &(curbuf->b_p_ft))
7424 {
7425 /* 'filetype' is set, trigger the FileType autocommand */
7426 did_filetype = TRUE;
7427 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7428 curbuf->b_fname, TRUE, curbuf);
7429 }
7430#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007431#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007432 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007433 {
7434 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007435 char_u *q = curwin->w_s->b_p_spl;
7436
7437 /* Skip the first name if it is "cjk". */
7438 if (STRNCMP(q, "cjk,", 4) == 0)
7439 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007440
7441 /*
7442 * Source the spell/LANG.vim in 'runtimepath'.
7443 * They could set 'spellcapcheck' depending on the language.
7444 * Use the first name in 'spelllang' up to '_region' or
7445 * '.encoding'.
7446 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007447 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007448 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7449 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007450 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007451 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007452 }
7453#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007454 }
7455
7456#ifdef FEAT_MOUSE
7457 if (varp == &p_mouse)
7458 {
7459# ifdef FEAT_MOUSE_TTY
7460 if (*p_mouse == NUL)
7461 mch_setmouse(FALSE); /* switch mouse off */
7462 else
7463# endif
7464 setmouse(); /* in case 'mouse' changed */
7465 }
7466#endif
7467
Bram Moolenaar913077c2012-03-28 19:59:04 +02007468 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007469 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007470 curwin->w_set_curswant = TRUE;
7471
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007472#ifdef FEAT_GUI
7473 /* check redraw when it's not a GUI option or the GUI is active. */
7474 if (!redraw_gui_only || gui.in_use)
7475#endif
7476 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477
7478 return errmsg;
7479}
7480
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007481#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007482/*
7483 * Simple int comparison function for use with qsort()
7484 */
7485 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007486int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007487{
7488 return *(const int *)a - *(const int *)b;
7489}
7490
7491/*
7492 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7493 * Returns error message, NULL if it's OK.
7494 */
7495 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007496check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007497{
7498 char_u *s;
7499 int col;
7500 int count = 0;
7501 int color_cols[256];
7502 int i;
7503 int j = 0;
7504
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007505 if (wp->w_buffer == NULL)
7506 return NULL; /* buffer was closed */
7507
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007508 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007509 {
7510 if (*s == '-' || *s == '+')
7511 {
7512 /* -N and +N: add to 'textwidth' */
7513 col = (*s == '-') ? -1 : 1;
7514 ++s;
7515 if (!VIM_ISDIGIT(*s))
7516 return e_invarg;
7517 col = col * getdigits(&s);
7518 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007519 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007520 col += wp->w_buffer->b_p_tw;
7521 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007522 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007523 }
7524 else if (VIM_ISDIGIT(*s))
7525 col = getdigits(&s);
7526 else
7527 return e_invarg;
7528 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007529skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007530 if (*s == NUL)
7531 break;
7532 if (*s != ',')
7533 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007534 if (*++s == NUL)
7535 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007536 }
7537
7538 vim_free(wp->w_p_cc_cols);
7539 if (count == 0)
7540 wp->w_p_cc_cols = NULL;
7541 else
7542 {
7543 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7544 if (wp->w_p_cc_cols != NULL)
7545 {
7546 /* sort the columns for faster usage on screen redraw inside
7547 * win_line() */
7548 qsort(color_cols, count, sizeof(int), int_cmp);
7549
7550 for (i = 0; i < count; ++i)
7551 /* skip duplicates */
7552 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7553 wp->w_p_cc_cols[j++] = color_cols[i];
7554 wp->w_p_cc_cols[j] = -1; /* end marker */
7555 }
7556 }
7557
7558 return NULL; /* no error */
7559}
7560#endif
7561
Bram Moolenaar071d4272004-06-13 20:20:40 +00007562/*
7563 * Handle setting 'listchars' or 'fillchars'.
7564 * Returns error message, NULL if it's OK.
7565 */
7566 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007567set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007568{
7569 int round, i, len, entries;
7570 char_u *p, *s;
7571 int c1, c2 = 0;
7572 struct charstab
7573 {
7574 int *cp;
7575 char *name;
7576 };
7577#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7578 static struct charstab filltab[] =
7579 {
7580 {&fill_stl, "stl"},
7581 {&fill_stlnc, "stlnc"},
7582 {&fill_vert, "vert"},
7583 {&fill_fold, "fold"},
7584 {&fill_diff, "diff"},
7585 };
7586#endif
7587 static struct charstab lcstab[] =
7588 {
7589 {&lcs_eol, "eol"},
7590 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007591 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007592 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007593 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007594 {&lcs_tab2, "tab"},
7595 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007596#ifdef FEAT_CONCEAL
7597 {&lcs_conceal, "conceal"},
7598#else
7599 {NULL, "conceal"},
7600#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601 };
7602 struct charstab *tab;
7603
7604#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7605 if (varp == &p_lcs)
7606#endif
7607 {
7608 tab = lcstab;
7609 entries = sizeof(lcstab) / sizeof(struct charstab);
7610 }
7611#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7612 else
7613 {
7614 tab = filltab;
7615 entries = sizeof(filltab) / sizeof(struct charstab);
7616 }
7617#endif
7618
7619 /* first round: check for valid value, second round: assign values */
7620 for (round = 0; round <= 1; ++round)
7621 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007622 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007623 {
7624 /* After checking that the value is valid: set defaults: space for
7625 * 'fillchars', NUL for 'listchars' */
7626 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007627 if (tab[i].cp != NULL)
7628 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007629 if (varp == &p_lcs)
7630 lcs_tab1 = NUL;
7631#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7632 else
7633 fill_diff = '-';
7634#endif
7635 }
7636 p = *varp;
7637 while (*p)
7638 {
7639 for (i = 0; i < entries; ++i)
7640 {
7641 len = (int)STRLEN(tab[i].name);
7642 if (STRNCMP(p, tab[i].name, len) == 0
7643 && p[len] == ':'
7644 && p[len + 1] != NUL)
7645 {
7646 s = p + len + 1;
7647#ifdef FEAT_MBYTE
7648 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007649 if (mb_char2cells(c1) > 1)
7650 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007651#else
7652 c1 = *s++;
7653#endif
7654 if (tab[i].cp == &lcs_tab2)
7655 {
7656 if (*s == NUL)
7657 continue;
7658#ifdef FEAT_MBYTE
7659 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007660 if (mb_char2cells(c2) > 1)
7661 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662#else
7663 c2 = *s++;
7664#endif
7665 }
7666 if (*s == ',' || *s == NUL)
7667 {
7668 if (round)
7669 {
7670 if (tab[i].cp == &lcs_tab2)
7671 {
7672 lcs_tab1 = c1;
7673 lcs_tab2 = c2;
7674 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007675 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007676 *(tab[i].cp) = c1;
7677
7678 }
7679 p = s;
7680 break;
7681 }
7682 }
7683 }
7684
7685 if (i == entries)
7686 return e_invarg;
7687 if (*p == ',')
7688 ++p;
7689 }
7690 }
7691
7692 return NULL; /* no error */
7693}
7694
7695#ifdef FEAT_STL_OPT
7696/*
7697 * Check validity of options with the 'statusline' format.
7698 * Return error message or NULL.
7699 */
7700 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007701check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007702{
7703 int itemcnt = 0;
7704 int groupdepth = 0;
7705 static char_u errbuf[80];
7706
7707 while (*s && itemcnt < STL_MAX_ITEM)
7708 {
7709 /* Check for valid keys after % sequences */
7710 while (*s && *s != '%')
7711 s++;
7712 if (!*s)
7713 break;
7714 s++;
7715 if (*s != '%' && *s != ')')
7716 ++itemcnt;
7717 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7718 {
7719 s++;
7720 continue;
7721 }
7722 if (*s == ')')
7723 {
7724 s++;
7725 if (--groupdepth < 0)
7726 break;
7727 continue;
7728 }
7729 if (*s == '-')
7730 s++;
7731 while (VIM_ISDIGIT(*s))
7732 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007733 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007734 continue;
7735 if (*s == '.')
7736 {
7737 s++;
7738 while (*s && VIM_ISDIGIT(*s))
7739 s++;
7740 }
7741 if (*s == '(')
7742 {
7743 groupdepth++;
7744 continue;
7745 }
7746 if (vim_strchr(STL_ALL, *s) == NULL)
7747 {
7748 return illegal_char(errbuf, *s);
7749 }
7750 if (*s == '{')
7751 {
7752 s++;
7753 while (*s != '}' && *s)
7754 s++;
7755 if (*s != '}')
7756 return (char_u *)N_("E540: Unclosed expression sequence");
7757 }
7758 }
7759 if (itemcnt >= STL_MAX_ITEM)
7760 return (char_u *)N_("E541: too many items");
7761 if (groupdepth != 0)
7762 return (char_u *)N_("E542: unbalanced groups");
7763 return NULL;
7764}
7765#endif
7766
7767#ifdef FEAT_CLIPBOARD
7768/*
7769 * Extract the items in the 'clipboard' option and set global values.
7770 */
7771 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007772check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007773{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007774 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007775 int new_autoselect_star = FALSE;
7776 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007778 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 regprog_T *new_exclude_prog = NULL;
7780 char_u *errmsg = NULL;
7781 char_u *p;
7782
7783 for (p = p_cb; *p != NUL; )
7784 {
7785 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7786 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007787 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007788 p += 7;
7789 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007790 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007791 && (p[11] == ',' || p[11] == NUL))
7792 {
7793 new_unnamed |= CLIP_UNNAMED_PLUS;
7794 p += 11;
7795 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007796 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007797 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007799 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 p += 10;
7801 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007802 else if (STRNCMP(p, "autoselectplus", 14) == 0
7803 && (p[14] == ',' || p[14] == NUL))
7804 {
7805 new_autoselect_plus = TRUE;
7806 p += 14;
7807 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007808 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007809 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810 {
7811 new_autoselectml = TRUE;
7812 p += 12;
7813 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007814 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7815 {
7816 new_html = TRUE;
7817 p += 4;
7818 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7820 {
7821 p += 8;
7822 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7823 if (new_exclude_prog == NULL)
7824 errmsg = e_invarg;
7825 break;
7826 }
7827 else
7828 {
7829 errmsg = e_invarg;
7830 break;
7831 }
7832 if (*p == ',')
7833 ++p;
7834 }
7835 if (errmsg == NULL)
7836 {
7837 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007838 clip_autoselect_star = new_autoselect_star;
7839 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007840 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007841 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007842 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007843 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007844#ifdef FEAT_GUI_GTK
7845 if (gui.in_use)
7846 {
7847 gui_gtk_set_selection_targets();
7848 gui_gtk_set_dnd_targets();
7849 }
7850#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007851 }
7852 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007853 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007854
7855 return errmsg;
7856}
7857#endif
7858
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007859#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007860 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007861did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007862{
7863 char_u *errmsg = NULL;
7864 win_T *wp;
7865 int l;
7866
7867 if (is_spellfile)
7868 {
7869 l = (int)STRLEN(curwin->w_s->b_p_spf);
7870 if (l > 0 && (l < 4
7871 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7872 errmsg = e_invarg;
7873 }
7874
7875 if (errmsg == NULL)
7876 {
7877 FOR_ALL_WINDOWS(wp)
7878 if (wp->w_buffer == curbuf && wp->w_p_spell)
7879 {
7880 errmsg = did_set_spelllang(wp);
7881# ifdef FEAT_WINDOWS
7882 break;
7883# endif
7884 }
7885 }
7886 return errmsg;
7887}
7888
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007889/*
7890 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7891 * Return error message when failed, NULL when OK.
7892 */
7893 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007894compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007895{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007896 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007897 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007898
Bram Moolenaar860cae12010-06-05 23:22:07 +02007899 if (*synblock->b_p_spc == NUL)
7900 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007901 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007902 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007903 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007904 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007905 if (re != NULL)
7906 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007907 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007908 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007909 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007910 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007911 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007912 return e_invarg;
7913 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007914 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007915 }
7916
Bram Moolenaar473de612013-06-08 18:19:48 +02007917 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007918 return NULL;
7919}
7920#endif
7921
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007922#if defined(FEAT_EVAL) || defined(PROTO)
7923/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007924 * Set the scriptID for an option, taking care of setting the buffer- or
7925 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007926 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007927 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007928set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007929{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007930 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7931 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007932
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007933 /* Remember where the option was set. For local options need to do that
7934 * in the buffer or window structure. */
7935 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007936 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007937 if (both || (opt_flags & OPT_LOCAL))
7938 {
7939 if (indir & PV_BUF)
7940 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7941 else if (indir & PV_WIN)
7942 curwin->w_p_scriptID[indir & PV_MASK] = id;
7943 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007944}
7945#endif
7946
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947/*
7948 * Set the value of a boolean option, and take care of side effects.
7949 * Returns NULL for success, or an error message for an error.
7950 */
7951 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007952set_bool_option(
7953 int opt_idx, /* index in options[] table */
7954 char_u *varp, /* pointer to the option variable */
7955 int value, /* new value */
7956 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957{
7958 int old_value = *(int *)varp;
7959
Bram Moolenaar071d4272004-06-13 20:20:40 +00007960 /* Disallow changing some options from secure mode */
7961 if ((secure
7962#ifdef HAVE_SANDBOX
7963 || sandbox != 0
7964#endif
7965 ) && (options[opt_idx].flags & P_SECURE))
7966 return e_secure;
7967
7968 *(int *)varp = value; /* set the new value */
7969#ifdef FEAT_EVAL
7970 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007971 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972#endif
7973
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007974#ifdef FEAT_GUI
7975 need_mouse_correct = TRUE;
7976#endif
7977
Bram Moolenaar071d4272004-06-13 20:20:40 +00007978 /* May set global value for local option. */
7979 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7980 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7981
7982 /*
7983 * Handle side effects of changing a bool option.
7984 */
7985
7986 /* 'compatible' */
7987 if ((int *)varp == &p_cp)
7988 {
7989 compatible_set();
7990 }
7991
Bram Moolenaar920694c2016-08-21 17:45:02 +02007992#ifdef FEAT_LANGMAP
7993 if ((int *)varp == &p_lrm)
7994 /* 'langremap' -> !'langnoremap' */
7995 p_lnr = !p_lrm;
7996 else if ((int *)varp == &p_lnr)
7997 /* 'langnoremap' -> !'langremap' */
7998 p_lrm = !p_lnr;
7999#endif
8000
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008001#ifdef FEAT_PERSISTENT_UNDO
8002 /* 'undofile' */
8003 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8004 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008005 /* Only take action when the option was set. When reset we do not
8006 * delete the undo file, the option may be set again without making
8007 * any changes in between. */
8008 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008009 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008010 char_u hash[UNDO_HASH_SIZE];
8011 buf_T *save_curbuf = curbuf;
8012
Bram Moolenaar29323592016-07-24 22:04:11 +02008013 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008014 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008015 /* When 'undofile' is set globally: for every buffer, otherwise
8016 * only for the current buffer: Try to read in the undofile,
8017 * if one exists, the buffer wasn't changed and the buffer was
8018 * loaded */
8019 if ((curbuf == save_curbuf
8020 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8021 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8022 {
8023 u_compute_hash(hash);
8024 u_read_undo(NULL, hash, curbuf->b_fname);
8025 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008026 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008027 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008028 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008029 }
8030#endif
8031
Bram Moolenaar071d4272004-06-13 20:20:40 +00008032 else if ((int *)varp == &curbuf->b_p_ro)
8033 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008034 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8036 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008037
8038 /* when 'readonly' is set may give W10 again */
8039 if (curbuf->b_p_ro)
8040 curbuf->b_did_warn = FALSE;
8041
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008043 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008044#endif
8045 }
8046
Bram Moolenaar9c449722010-07-20 18:44:27 +02008047#ifdef FEAT_GUI
8048 else if ((int *)varp == &p_mh)
8049 {
8050 if (!p_mh)
8051 gui_mch_mousehide(FALSE);
8052 }
8053#endif
8054
Bram Moolenaara539df02010-08-01 14:35:05 +02008055#ifdef FEAT_TITLE
8056 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008057 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008058 {
8059 redraw_titles();
8060 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008061 /* when 'endofline' is changed, redraw the window title */
8062 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008063 {
8064 redraw_titles();
8065 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008066 /* when 'fixeol' is changed, redraw the window title */
8067 else if ((int *)varp == &curbuf->b_p_fixeol)
8068 {
8069 redraw_titles();
8070 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008071# ifdef FEAT_MBYTE
8072 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008073 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008074 {
8075 redraw_titles();
8076 }
8077# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008078#endif
8079
8080 /* when 'bin' is set also set some other options */
8081 else if ((int *)varp == &curbuf->b_p_bin)
8082 {
8083 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8084#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008085 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008086#endif
8087 }
8088
8089#ifdef FEAT_AUTOCMD
8090 /* when 'buflisted' changes, trigger autocommands */
8091 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8092 {
8093 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8094 NULL, NULL, TRUE, curbuf);
8095 }
8096#endif
8097
8098 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8099 else if ((int *)varp == &curbuf->b_p_swf)
8100 {
8101 if (curbuf->b_p_swf && p_uc)
8102 ml_open_file(curbuf); /* create the swap file */
8103 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008104 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8105 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008106 mf_close_file(curbuf, TRUE); /* remove the swap file */
8107 }
8108
8109 /* when 'terse' is set change 'shortmess' */
8110 else if ((int *)varp == &p_terse)
8111 {
8112 char_u *p;
8113
8114 p = vim_strchr(p_shm, SHM_SEARCH);
8115
8116 /* insert 's' in p_shm */
8117 if (p_terse && p == NULL)
8118 {
8119 STRCPY(IObuff, p_shm);
8120 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008121 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008122 }
8123 /* remove 's' from p_shm */
8124 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008125 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126 }
8127
8128 /* when 'paste' is set or reset also change other options */
8129 else if ((int *)varp == &p_paste)
8130 {
8131 paste_option_changed();
8132 }
8133
8134 /* when 'insertmode' is set from an autocommand need to do work here */
8135 else if ((int *)varp == &p_im)
8136 {
8137 if (p_im)
8138 {
8139 if ((State & INSERT) == 0)
8140 need_start_insertmode = TRUE;
8141 stop_insert_mode = FALSE;
8142 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008143 /* only reset if it was set previously */
8144 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145 {
8146 need_start_insertmode = FALSE;
8147 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008148 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 clear_cmdline = TRUE; /* remove "(insert)" */
8150 restart_edit = 0;
8151 }
8152 }
8153
8154 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8155 else if ((int *)varp == &p_ic && p_hls)
8156 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008157 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 }
8159
8160#ifdef FEAT_SEARCH_EXTRA
8161 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8162 else if ((int *)varp == &p_hls)
8163 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008164 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 }
8166#endif
8167
8168#ifdef FEAT_SCROLLBIND
8169 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8170 * at the end of normal_cmd() */
8171 else if ((int *)varp == &curwin->w_p_scb)
8172 {
8173 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008174 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008175 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008176 curwin->w_scbind_pos = curwin->w_topline;
8177 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178 }
8179#endif
8180
8181#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8182 /* There can be only one window with 'previewwindow' set. */
8183 else if ((int *)varp == &curwin->w_p_pvw)
8184 {
8185 if (curwin->w_p_pvw)
8186 {
8187 win_T *win;
8188
Bram Moolenaar29323592016-07-24 22:04:11 +02008189 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190 if (win->w_p_pvw && win != curwin)
8191 {
8192 curwin->w_p_pvw = FALSE;
8193 return (char_u *)N_("E590: A preview window already exists");
8194 }
8195 }
8196 }
8197#endif
8198
8199 /* when 'textmode' is set or reset also change 'fileformat' */
8200 else if ((int *)varp == &curbuf->b_p_tx)
8201 {
8202 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8203 }
8204
8205 /* when 'textauto' is set or reset also change 'fileformats' */
8206 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008207 set_string_option_direct((char_u *)"ffs", -1,
8208 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008209 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008210
8211 /*
8212 * When 'lisp' option changes include/exclude '-' in
8213 * keyword characters.
8214 */
8215#ifdef FEAT_LISP
8216 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8217 {
8218 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8219 }
8220#endif
8221
8222#ifdef FEAT_TITLE
8223 /* when 'title' changed, may need to change the title; same for 'icon' */
8224 else if ((int *)varp == &p_title)
8225 {
8226 did_set_title(FALSE);
8227 }
8228
8229 else if ((int *)varp == &p_icon)
8230 {
8231 did_set_title(TRUE);
8232 }
8233#endif
8234
8235 else if ((int *)varp == &curbuf->b_changed)
8236 {
8237 if (!value)
8238 save_file_ff(curbuf); /* Buffer is unchanged */
8239#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008240 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241#endif
8242#ifdef FEAT_AUTOCMD
8243 modified_was_set = value;
8244#endif
8245 }
8246
8247#ifdef BACKSLASH_IN_FILENAME
8248 else if ((int *)varp == &p_ssl)
8249 {
8250 if (p_ssl)
8251 {
8252 psepc = '/';
8253 psepcN = '\\';
8254 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008255 }
8256 else
8257 {
8258 psepc = '\\';
8259 psepcN = '/';
8260 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 }
8262
8263 /* need to adjust the file name arguments and buffer names. */
8264 buflist_slash_adjust();
8265 alist_slash_adjust();
8266# ifdef FEAT_EVAL
8267 scriptnames_slash_adjust();
8268# endif
8269 }
8270#endif
8271
8272 /* If 'wrap' is set, set w_leftcol to zero. */
8273 else if ((int *)varp == &curwin->w_p_wrap)
8274 {
8275 if (curwin->w_p_wrap)
8276 curwin->w_leftcol = 0;
8277 }
8278
8279#ifdef FEAT_WINDOWS
8280 else if ((int *)varp == &p_ea)
8281 {
8282 if (p_ea && !old_value)
8283 win_equal(curwin, FALSE, 0);
8284 }
8285#endif
8286
8287 else if ((int *)varp == &p_wiv)
8288 {
8289 /*
8290 * When 'weirdinvert' changed, set/reset 't_xs'.
8291 * Then set 'weirdinvert' according to value of 't_xs'.
8292 */
8293 if (p_wiv && !old_value)
8294 T_XS = (char_u *)"y";
8295 else if (!p_wiv && old_value)
8296 T_XS = empty_option;
8297 p_wiv = (*T_XS != NUL);
8298 }
8299
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008300#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301 else if ((int *)varp == &p_beval)
8302 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008303 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008305 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 gui_mch_disable_beval_area(balloonEval);
8307 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008308#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008309
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008310#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008311 else if ((int *)varp == &p_acd)
8312 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008313 /* Change directories when the 'acd' option is set now. */
8314 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008315 }
8316#endif
8317
8318#ifdef FEAT_DIFF
8319 /* 'diff' */
8320 else if ((int *)varp == &curwin->w_p_diff)
8321 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008322 /* May add or remove the buffer from the list of diff buffers. */
8323 diff_buf_adjust(curwin);
8324# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008325 if (foldmethodIsDiff(curwin))
8326 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008327# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008328 }
8329#endif
8330
8331#ifdef USE_IM_CONTROL
8332 /* 'imdisable' */
8333 else if ((int *)varp == &p_imdisable)
8334 {
8335 /* Only de-activate it here, it will be enabled when changing mode. */
8336 if (p_imdisable)
8337 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008338 else if (State & INSERT)
8339 /* When the option is set from an autocommand, it may need to take
8340 * effect right away. */
8341 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008342 }
8343#endif
8344
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008345#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008346 /* 'spell' */
8347 else if ((int *)varp == &curwin->w_p_spell)
8348 {
8349 if (curwin->w_p_spell)
8350 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008351 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008352 if (errmsg != NULL)
8353 EMSG(_(errmsg));
8354 }
8355 }
8356#endif
8357
Bram Moolenaar071d4272004-06-13 20:20:40 +00008358#ifdef FEAT_FKMAP
8359 else if ((int *)varp == &p_altkeymap)
8360 {
8361 if (old_value != p_altkeymap)
8362 {
8363 if (!p_altkeymap)
8364 {
8365 p_hkmap = p_fkmap;
8366 p_fkmap = 0;
8367 }
8368 else
8369 {
8370 p_fkmap = p_hkmap;
8371 p_hkmap = 0;
8372 }
8373 (void)init_chartab();
8374 }
8375 }
8376
8377 /*
8378 * In case some second language keymapping options have changed, check
8379 * and correct the setting in a consistent way.
8380 */
8381
8382 /*
8383 * If hkmap or fkmap are set, reset Arabic keymapping.
8384 */
8385 if ((p_hkmap || p_fkmap) && p_altkeymap)
8386 {
8387 p_altkeymap = p_fkmap;
8388# ifdef FEAT_ARABIC
8389 curwin->w_p_arab = FALSE;
8390# endif
8391 (void)init_chartab();
8392 }
8393
8394 /*
8395 * If hkmap set, reset Farsi keymapping.
8396 */
8397 if (p_hkmap && p_altkeymap)
8398 {
8399 p_altkeymap = 0;
8400 p_fkmap = 0;
8401# ifdef FEAT_ARABIC
8402 curwin->w_p_arab = FALSE;
8403# endif
8404 (void)init_chartab();
8405 }
8406
8407 /*
8408 * If fkmap set, reset Hebrew keymapping.
8409 */
8410 if (p_fkmap && !p_altkeymap)
8411 {
8412 p_altkeymap = 1;
8413 p_hkmap = 0;
8414# ifdef FEAT_ARABIC
8415 curwin->w_p_arab = FALSE;
8416# endif
8417 (void)init_chartab();
8418 }
8419#endif
8420
8421#ifdef FEAT_ARABIC
8422 if ((int *)varp == &curwin->w_p_arab)
8423 {
8424 if (curwin->w_p_arab)
8425 {
8426 /*
8427 * 'arabic' is set, handle various sub-settings.
8428 */
8429 if (!p_tbidi)
8430 {
8431 /* set rightleft mode */
8432 if (!curwin->w_p_rl)
8433 {
8434 curwin->w_p_rl = TRUE;
8435 changed_window_setting();
8436 }
8437
8438 /* Enable Arabic shaping (major part of what Arabic requires) */
8439 if (!p_arshape)
8440 {
8441 p_arshape = TRUE;
8442 redraw_later_clear();
8443 }
8444 }
8445
8446 /* Arabic requires a utf-8 encoding, inform the user if its not
8447 * set. */
8448 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008449 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008450 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8451
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008452 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008453 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8454#ifdef FEAT_EVAL
8455 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8456#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008457 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008458
8459# ifdef FEAT_MBYTE
8460 /* set 'delcombine' */
8461 p_deco = TRUE;
8462# endif
8463
8464# ifdef FEAT_KEYMAP
8465 /* Force-set the necessary keymap for arabic */
8466 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8467 OPT_LOCAL);
8468# endif
8469# ifdef FEAT_FKMAP
8470 p_altkeymap = 0;
8471 p_hkmap = 0;
8472 p_fkmap = 0;
8473 (void)init_chartab();
8474# endif
8475 }
8476 else
8477 {
8478 /*
8479 * 'arabic' is reset, handle various sub-settings.
8480 */
8481 if (!p_tbidi)
8482 {
8483 /* reset rightleft mode */
8484 if (curwin->w_p_rl)
8485 {
8486 curwin->w_p_rl = FALSE;
8487 changed_window_setting();
8488 }
8489
8490 /* 'arabicshape' isn't reset, it is a global option and
8491 * another window may still need it "on". */
8492 }
8493
8494 /* 'delcombine' isn't reset, it is a global option and another
8495 * window may still want it "on". */
8496
8497# ifdef FEAT_KEYMAP
8498 /* Revert to the default keymap */
8499 curbuf->b_p_iminsert = B_IMODE_NONE;
8500 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8501# endif
8502 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008503 }
8504
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008505#endif
8506
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008507#ifdef FEAT_TERMGUICOLORS
8508 /* 'termguicolors' */
8509 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008510 {
8511# ifdef FEAT_GUI
8512 if (!gui.in_use && !gui.starting)
8513# endif
8514 highlight_gui_started();
8515 }
8516#endif
8517
Bram Moolenaar071d4272004-06-13 20:20:40 +00008518 /*
8519 * End of handling side effects for bool options.
8520 */
8521
Bram Moolenaar53744302015-07-17 17:38:22 +02008522 /* after handling side effects, call autocommand */
8523
Bram Moolenaar071d4272004-06-13 20:20:40 +00008524 options[opt_idx].flags |= P_WAS_SET;
8525
Bram Moolenaar53744302015-07-17 17:38:22 +02008526#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8527 if (!starting)
8528 {
8529 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008530 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8531 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8532 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008533 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8534 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8535 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8536 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8537 reset_v_option_vars();
8538 }
8539#endif
8540
Bram Moolenaar071d4272004-06-13 20:20:40 +00008541 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008542 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008543 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008544 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008545 check_redraw(options[opt_idx].flags);
8546
8547 return NULL;
8548}
8549
8550/*
8551 * Set the value of a number option, and take care of side effects.
8552 * Returns NULL for success, or an error message for an error.
8553 */
8554 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008555set_num_option(
8556 int opt_idx, /* index in options[] table */
8557 char_u *varp, /* pointer to the option variable */
8558 long value, /* new value */
8559 char_u *errbuf, /* buffer for error messages */
8560 size_t errbuflen, /* length of "errbuf" */
8561 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008562 OPT_MODELINE */
8563{
8564 char_u *errmsg = NULL;
8565 long old_value = *(long *)varp;
8566 long old_Rows = Rows; /* remember old Rows */
8567 long old_Columns = Columns; /* remember old Columns */
8568 long *pp = (long *)varp;
8569
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008570 /* Disallow changing some options from secure mode. */
8571 if ((secure
8572#ifdef HAVE_SANDBOX
8573 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008574#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008575 ) && (options[opt_idx].flags & P_SECURE))
8576 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577
8578 *pp = value;
8579#ifdef FEAT_EVAL
8580 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008581 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008582#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008583#ifdef FEAT_GUI
8584 need_mouse_correct = TRUE;
8585#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586
Bram Moolenaar14f24742012-08-08 18:01:05 +02008587 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588 {
8589 errmsg = e_positive;
8590 curbuf->b_p_sw = curbuf->b_p_ts;
8591 }
8592
8593 /*
8594 * Number options that need some action when changed
8595 */
8596#ifdef FEAT_WINDOWS
8597 if (pp == &p_wh || pp == &p_hh)
8598 {
8599 if (p_wh < 1)
8600 {
8601 errmsg = e_positive;
8602 p_wh = 1;
8603 }
8604 if (p_wmh > p_wh)
8605 {
8606 errmsg = e_winheight;
8607 p_wh = p_wmh;
8608 }
8609 if (p_hh < 0)
8610 {
8611 errmsg = e_positive;
8612 p_hh = 0;
8613 }
8614
8615 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008616 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008617 {
8618 if (pp == &p_wh && curwin->w_height < p_wh)
8619 win_setheight((int)p_wh);
8620 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8621 win_setheight((int)p_hh);
8622 }
8623 }
8624
8625 /* 'winminheight' */
8626 else if (pp == &p_wmh)
8627 {
8628 if (p_wmh < 0)
8629 {
8630 errmsg = e_positive;
8631 p_wmh = 0;
8632 }
8633 if (p_wmh > p_wh)
8634 {
8635 errmsg = e_winheight;
8636 p_wmh = p_wh;
8637 }
8638 win_setminheight();
8639 }
8640
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008641# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008642 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008643 {
8644 if (p_wiw < 1)
8645 {
8646 errmsg = e_positive;
8647 p_wiw = 1;
8648 }
8649 if (p_wmw > p_wiw)
8650 {
8651 errmsg = e_winwidth;
8652 p_wiw = p_wmw;
8653 }
8654
8655 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008656 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008657 win_setwidth((int)p_wiw);
8658 }
8659
8660 /* 'winminwidth' */
8661 else if (pp == &p_wmw)
8662 {
8663 if (p_wmw < 0)
8664 {
8665 errmsg = e_positive;
8666 p_wmw = 0;
8667 }
8668 if (p_wmw > p_wiw)
8669 {
8670 errmsg = e_winwidth;
8671 p_wmw = p_wiw;
8672 }
8673 win_setminheight();
8674 }
8675# endif
8676
8677#endif
8678
8679#ifdef FEAT_WINDOWS
8680 /* (re)set last window status line */
8681 else if (pp == &p_ls)
8682 {
8683 last_status(FALSE);
8684 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008685
8686 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008687 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008688 {
8689 shell_new_rows(); /* recompute window positions and heights */
8690 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691#endif
8692
8693#ifdef FEAT_GUI
8694 else if (pp == &p_linespace)
8695 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008696 /* Recompute gui.char_height and resize the Vim window to keep the
8697 * same number of lines. */
8698 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008699 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008700 }
8701#endif
8702
8703#ifdef FEAT_FOLDING
8704 /* 'foldlevel' */
8705 else if (pp == &curwin->w_p_fdl)
8706 {
8707 if (curwin->w_p_fdl < 0)
8708 curwin->w_p_fdl = 0;
8709 newFoldLevel();
8710 }
8711
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008712 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008713 else if (pp == &curwin->w_p_fml)
8714 {
8715 foldUpdateAll(curwin);
8716 }
8717
8718 /* 'foldnestmax' */
8719 else if (pp == &curwin->w_p_fdn)
8720 {
8721 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8722 foldUpdateAll(curwin);
8723 }
8724
8725 /* 'foldcolumn' */
8726 else if (pp == &curwin->w_p_fdc)
8727 {
8728 if (curwin->w_p_fdc < 0)
8729 {
8730 errmsg = e_positive;
8731 curwin->w_p_fdc = 0;
8732 }
8733 else if (curwin->w_p_fdc > 12)
8734 {
8735 errmsg = e_invarg;
8736 curwin->w_p_fdc = 12;
8737 }
8738 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008739#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008741#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008742 /* 'shiftwidth' or 'tabstop' */
8743 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8744 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008745# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008746 if (foldmethodIsIndent(curwin))
8747 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008748# endif
8749# ifdef FEAT_CINDENT
8750 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8751 * parse 'cinoptions'. */
8752 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8753 parse_cino(curbuf);
8754# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008755 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008756#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008758#ifdef FEAT_MBYTE
8759 /* 'maxcombine' */
8760 else if (pp == &p_mco)
8761 {
8762 if (p_mco > MAX_MCO)
8763 p_mco = MAX_MCO;
8764 else if (p_mco < 0)
8765 p_mco = 0;
8766 screenclear(); /* will re-allocate the screen */
8767 }
8768#endif
8769
Bram Moolenaar071d4272004-06-13 20:20:40 +00008770 else if (pp == &curbuf->b_p_iminsert)
8771 {
8772 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8773 {
8774 errmsg = e_invarg;
8775 curbuf->b_p_iminsert = B_IMODE_NONE;
8776 }
8777 p_iminsert = curbuf->b_p_iminsert;
8778 if (termcap_active) /* don't do this in the alternate screen */
8779 showmode();
8780#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8781 /* Show/unshow value of 'keymap' in status lines. */
8782 status_redraw_curbuf();
8783#endif
8784 }
8785
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008786 else if (pp == &p_window)
8787 {
8788 if (p_window < 1)
8789 p_window = 1;
8790 else if (p_window >= Rows)
8791 p_window = Rows - 1;
8792 }
8793
Bram Moolenaar071d4272004-06-13 20:20:40 +00008794 else if (pp == &curbuf->b_p_imsearch)
8795 {
8796 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8797 {
8798 errmsg = e_invarg;
8799 curbuf->b_p_imsearch = B_IMODE_NONE;
8800 }
8801 p_imsearch = curbuf->b_p_imsearch;
8802 }
8803
8804#ifdef FEAT_TITLE
8805 /* if 'titlelen' has changed, redraw the title */
8806 else if (pp == &p_titlelen)
8807 {
8808 if (p_titlelen < 0)
8809 {
8810 errmsg = e_positive;
8811 p_titlelen = 85;
8812 }
8813 if (starting != NO_SCREEN && old_value != p_titlelen)
8814 need_maketitle = TRUE;
8815 }
8816#endif
8817
8818 /* if p_ch changed value, change the command line height */
8819 else if (pp == &p_ch)
8820 {
8821 if (p_ch < 1)
8822 {
8823 errmsg = e_positive;
8824 p_ch = 1;
8825 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008826 if (p_ch > Rows - min_rows() + 1)
8827 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008828
8829 /* Only compute the new window layout when startup has been
8830 * completed. Otherwise the frame sizes may be wrong. */
8831 if (p_ch != old_value && full_screen
8832#ifdef FEAT_GUI
8833 && !gui.starting
8834#endif
8835 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008836 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008837 }
8838
8839 /* when 'updatecount' changes from zero to non-zero, open swap files */
8840 else if (pp == &p_uc)
8841 {
8842 if (p_uc < 0)
8843 {
8844 errmsg = e_positive;
8845 p_uc = 100;
8846 }
8847 if (p_uc && !old_value)
8848 ml_open_files();
8849 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008850#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008851 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008852 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008853 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008854 {
8855 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008856 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008857 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008858 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008859 {
8860 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008861 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008862 }
8863 }
8864#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008865#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008866 else if (pp == &p_mzq)
8867 mzvim_reset_timer();
8868#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008869
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008870#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8871 /* 'pyxversion' */
8872 else if (pp == &p_pyx)
8873 {
8874 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8875 errmsg = e_invarg;
8876 }
8877#endif
8878
Bram Moolenaar071d4272004-06-13 20:20:40 +00008879 /* sync undo before 'undolevels' changes */
8880 else if (pp == &p_ul)
8881 {
8882 /* use the old value, otherwise u_sync() may not work properly */
8883 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008884 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008885 p_ul = value;
8886 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008887 else if (pp == &curbuf->b_p_ul)
8888 {
8889 /* use the old value, otherwise u_sync() may not work properly */
8890 curbuf->b_p_ul = old_value;
8891 u_sync(TRUE);
8892 curbuf->b_p_ul = value;
8893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008894
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008895#ifdef FEAT_LINEBREAK
8896 /* 'numberwidth' must be positive */
8897 else if (pp == &curwin->w_p_nuw)
8898 {
8899 if (curwin->w_p_nuw < 1)
8900 {
8901 errmsg = e_positive;
8902 curwin->w_p_nuw = 1;
8903 }
8904 if (curwin->w_p_nuw > 10)
8905 {
8906 errmsg = e_invarg;
8907 curwin->w_p_nuw = 10;
8908 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008909 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008910 }
8911#endif
8912
Bram Moolenaar1a384422010-07-14 19:53:30 +02008913 else if (pp == &curbuf->b_p_tw)
8914 {
8915 if (curbuf->b_p_tw < 0)
8916 {
8917 errmsg = e_positive;
8918 curbuf->b_p_tw = 0;
8919 }
8920#ifdef FEAT_SYN_HL
8921# ifdef FEAT_WINDOWS
8922 {
8923 win_T *wp;
8924 tabpage_T *tp;
8925
8926 FOR_ALL_TAB_WINDOWS(tp, wp)
8927 check_colorcolumn(wp);
8928 }
8929# else
8930 check_colorcolumn(curwin);
8931# endif
8932#endif
8933 }
8934
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935 /*
8936 * Check the bounds for numeric options here
8937 */
8938 if (Rows < min_rows() && full_screen)
8939 {
8940 if (errbuf != NULL)
8941 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008942 vim_snprintf((char *)errbuf, errbuflen,
8943 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944 errmsg = errbuf;
8945 }
8946 Rows = min_rows();
8947 }
8948 if (Columns < MIN_COLUMNS && full_screen)
8949 {
8950 if (errbuf != NULL)
8951 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008952 vim_snprintf((char *)errbuf, errbuflen,
8953 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008954 errmsg = errbuf;
8955 }
8956 Columns = MIN_COLUMNS;
8957 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008958 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008959
Bram Moolenaar071d4272004-06-13 20:20:40 +00008960 /*
8961 * If the screen (shell) height has been changed, assume it is the
8962 * physical screenheight.
8963 */
8964 if (old_Rows != Rows || old_Columns != Columns)
8965 {
8966 /* Changing the screen size is not allowed while updating the screen. */
8967 if (updating_screen)
8968 *pp = old_value;
8969 else if (full_screen
8970#ifdef FEAT_GUI
8971 && !gui.starting
8972#endif
8973 )
8974 set_shellsize((int)Columns, (int)Rows, TRUE);
8975 else
8976 {
8977 /* Postpone the resizing; check the size and cmdline position for
8978 * messages. */
8979 check_shellsize();
8980 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8981 cmdline_row = Rows - p_ch;
8982 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008983 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008984 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985 }
8986
Bram Moolenaar071d4272004-06-13 20:20:40 +00008987 if (curbuf->b_p_ts <= 0)
8988 {
8989 errmsg = e_positive;
8990 curbuf->b_p_ts = 8;
8991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008992 if (p_tm < 0)
8993 {
8994 errmsg = e_positive;
8995 p_tm = 0;
8996 }
8997 if ((curwin->w_p_scr <= 0
8998 || (curwin->w_p_scr > curwin->w_height
8999 && curwin->w_height > 0))
9000 && full_screen)
9001 {
9002 if (pp == &(curwin->w_p_scr))
9003 {
9004 if (curwin->w_p_scr != 0)
9005 errmsg = e_scroll;
9006 win_comp_scroll(curwin);
9007 }
9008 /* If 'scroll' became invalid because of a side effect silently adjust
9009 * it. */
9010 else if (curwin->w_p_scr <= 0)
9011 curwin->w_p_scr = 1;
9012 else /* curwin->w_p_scr > curwin->w_height */
9013 curwin->w_p_scr = curwin->w_height;
9014 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009015 if (p_hi < 0)
9016 {
9017 errmsg = e_positive;
9018 p_hi = 0;
9019 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009020 else if (p_hi > 10000)
9021 {
9022 errmsg = e_invarg;
9023 p_hi = 10000;
9024 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009025 if (p_re < 0 || p_re > 2)
9026 {
9027 errmsg = e_invarg;
9028 p_re = 0;
9029 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009030 if (p_report < 0)
9031 {
9032 errmsg = e_positive;
9033 p_report = 1;
9034 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009035 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009036 {
9037 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9038 p_sj = Rows / 2;
9039 else
9040 {
9041 errmsg = e_scroll;
9042 p_sj = 1;
9043 }
9044 }
9045 if (p_so < 0 && full_screen)
9046 {
9047 errmsg = e_scroll;
9048 p_so = 0;
9049 }
9050 if (p_siso < 0 && full_screen)
9051 {
9052 errmsg = e_positive;
9053 p_siso = 0;
9054 }
9055#ifdef FEAT_CMDWIN
9056 if (p_cwh < 1)
9057 {
9058 errmsg = e_positive;
9059 p_cwh = 1;
9060 }
9061#endif
9062 if (p_ut < 0)
9063 {
9064 errmsg = e_positive;
9065 p_ut = 2000;
9066 }
9067 if (p_ss < 0)
9068 {
9069 errmsg = e_positive;
9070 p_ss = 0;
9071 }
9072
9073 /* May set global value for local option. */
9074 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9075 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9076
9077 options[opt_idx].flags |= P_WAS_SET;
9078
Bram Moolenaar53744302015-07-17 17:38:22 +02009079#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9080 if (!starting && errmsg == NULL)
9081 {
9082 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009083 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9084 vim_snprintf((char *)buf_new, 10, "%ld", value);
9085 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009086 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9087 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9088 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9089 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9090 reset_v_option_vars();
9091 }
9092#endif
9093
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009095 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009096 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009097 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009098 check_redraw(options[opt_idx].flags);
9099
9100 return errmsg;
9101}
9102
9103/*
9104 * Called after an option changed: check if something needs to be redrawn.
9105 */
9106 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009107check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009108{
9109 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009110 int doclear = (flags & P_RCLR) == P_RCLR;
9111 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112
9113#ifdef FEAT_WINDOWS
9114 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9115 status_redraw_all();
9116#endif
9117
9118 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9119 changed_window_setting();
9120 if (flags & P_RBUF)
9121 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009122 if (flags & P_RWINONLY)
9123 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009124 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009125 redraw_all_later(CLEAR);
9126 else if (all)
9127 redraw_all_later(NOT_VALID);
9128}
9129
9130/*
9131 * Find index for option 'arg'.
9132 * Return -1 if not found.
9133 */
9134 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009135findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136{
9137 int opt_idx;
9138 char *s, *p;
9139 static short quick_tab[27] = {0, 0}; /* quick access table */
9140 int is_term_opt;
9141
9142 /*
9143 * For first call: Initialize the quick-access table.
9144 * It contains the index for the first option that starts with a certain
9145 * letter. There are 26 letters, plus the first "t_" option.
9146 */
9147 if (quick_tab[1] == 0)
9148 {
9149 p = options[0].fullname;
9150 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9151 {
9152 if (s[0] != p[0])
9153 {
9154 if (s[0] == 't' && s[1] == '_')
9155 quick_tab[26] = opt_idx;
9156 else
9157 quick_tab[CharOrdLow(s[0])] = opt_idx;
9158 }
9159 p = s;
9160 }
9161 }
9162
9163 /*
9164 * Check for name starting with an illegal character.
9165 */
9166#ifdef EBCDIC
9167 if (!islower(arg[0]))
9168#else
9169 if (arg[0] < 'a' || arg[0] > 'z')
9170#endif
9171 return -1;
9172
9173 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9174 if (is_term_opt)
9175 opt_idx = quick_tab[26];
9176 else
9177 opt_idx = quick_tab[CharOrdLow(arg[0])];
9178 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9179 {
9180 if (STRCMP(arg, s) == 0) /* match full name */
9181 break;
9182 }
9183 if (s == NULL && !is_term_opt)
9184 {
9185 opt_idx = quick_tab[CharOrdLow(arg[0])];
9186 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9187 {
9188 s = options[opt_idx].shortname;
9189 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9190 break;
9191 s = NULL;
9192 }
9193 }
9194 if (s == NULL)
9195 opt_idx = -1;
9196 return opt_idx;
9197}
9198
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009199#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009200/*
9201 * Get the value for an option.
9202 *
9203 * Returns:
9204 * Number or Toggle option: 1, *numval gets value.
9205 * String option: 0, *stringval gets allocated string.
9206 * Hidden Number or Toggle option: -1.
9207 * hidden String option: -2.
9208 * unknown option: -3.
9209 */
9210 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009211get_option_value(
9212 char_u *name,
9213 long *numval,
9214 char_u **stringval, /* NULL when only checking existence */
9215 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009216{
9217 int opt_idx;
9218 char_u *varp;
9219
9220 opt_idx = findoption(name);
9221 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009222 {
9223 int key;
9224
9225 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9226 && (key = find_key_option(name)) != 0)
9227 {
9228 char_u key_name[2];
9229 char_u *p;
9230
9231 if (key < 0)
9232 {
9233 key_name[0] = KEY2TERMCAP0(key);
9234 key_name[1] = KEY2TERMCAP1(key);
9235 }
9236 else
9237 {
9238 key_name[0] = KS_KEY;
9239 key_name[1] = (key & 0xff);
9240 }
9241 p = find_termcode(key_name);
9242 if (p != NULL)
9243 {
9244 if (stringval != NULL)
9245 *stringval = vim_strsave(p);
9246 return 0;
9247 }
9248 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009250 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251
9252 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9253
9254 if (options[opt_idx].flags & P_STRING)
9255 {
9256 if (varp == NULL) /* hidden option */
9257 return -2;
9258 if (stringval != NULL)
9259 {
9260#ifdef FEAT_CRYPT
9261 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009262 if ((char_u **)varp == &curbuf->b_p_key
9263 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009264 *stringval = vim_strsave((char_u *)"*****");
9265 else
9266#endif
9267 *stringval = vim_strsave(*(char_u **)(varp));
9268 }
9269 return 0;
9270 }
9271
9272 if (varp == NULL) /* hidden option */
9273 return -1;
9274 if (options[opt_idx].flags & P_NUM)
9275 *numval = *(long *)varp;
9276 else
9277 {
9278 /* Special case: 'modified' is b_changed, but we also want to consider
9279 * it set when 'ff' or 'fenc' changed. */
9280 if ((int *)varp == &curbuf->b_changed)
9281 *numval = curbufIsChanged();
9282 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009283 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009284 }
9285 return 1;
9286}
9287#endif
9288
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009289#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009290/*
9291 * Returns the option attributes and its value. Unlike the above function it
9292 * will return either global value or local value of the option depending on
9293 * what was requested, but it will never return global value if it was
9294 * requested to return local one and vice versa. Neither it will return
9295 * buffer-local value if it was requested to return window-local one.
9296 *
9297 * Pretends that option is absent if it is not present in the requested scope
9298 * (i.e. has no global, window-local or buffer-local value depending on
9299 * opt_type). Uses
9300 *
9301 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009302 * 0 hidden or unknown option, also option that does not have requested
9303 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009304 * see SOPT_* in vim.h for other flags
9305 *
9306 * Possible opt_type values: see SREQ_* in vim.h
9307 */
9308 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009309get_option_value_strict(
9310 char_u *name,
9311 long *numval,
9312 char_u **stringval, /* NULL when only obtaining attributes */
9313 int opt_type,
9314 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009315{
9316 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009317 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009318 struct vimoption *p;
9319 int r = 0;
9320
9321 opt_idx = findoption(name);
9322 if (opt_idx < 0)
9323 return 0;
9324
9325 p = &(options[opt_idx]);
9326
9327 /* Hidden option */
9328 if (p->var == NULL)
9329 return 0;
9330
9331 if (p->flags & P_BOOL)
9332 r |= SOPT_BOOL;
9333 else if (p->flags & P_NUM)
9334 r |= SOPT_NUM;
9335 else if (p->flags & P_STRING)
9336 r |= SOPT_STRING;
9337
9338 if (p->indir == PV_NONE)
9339 {
9340 if (opt_type == SREQ_GLOBAL)
9341 r |= SOPT_GLOBAL;
9342 else
9343 return 0; /* Did not request global-only option */
9344 }
9345 else
9346 {
9347 if (p->indir & PV_BOTH)
9348 r |= SOPT_GLOBAL;
9349 else if (opt_type == SREQ_GLOBAL)
9350 return 0; /* Requested global option */
9351
9352 if (p->indir & PV_WIN)
9353 {
9354 if (opt_type == SREQ_BUF)
9355 return 0; /* Did not request window-local option */
9356 else
9357 r |= SOPT_WIN;
9358 }
9359 else if (p->indir & PV_BUF)
9360 {
9361 if (opt_type == SREQ_WIN)
9362 return 0; /* Did not request buffer-local option */
9363 else
9364 r |= SOPT_BUF;
9365 }
9366 }
9367
9368 if (stringval == NULL)
9369 return r;
9370
9371 if (opt_type == SREQ_GLOBAL)
9372 varp = p->var;
9373 else
9374 {
9375 if (opt_type == SREQ_BUF)
9376 {
9377 /* Special case: 'modified' is b_changed, but we also want to
9378 * consider it set when 'ff' or 'fenc' changed. */
9379 if (p->indir == PV_MOD)
9380 {
9381 *numval = bufIsChanged((buf_T *) from);
9382 varp = NULL;
9383 }
9384#ifdef FEAT_CRYPT
9385 else if (p->indir == PV_KEY)
9386 {
9387 /* never return the value of the crypt key */
9388 *stringval = NULL;
9389 varp = NULL;
9390 }
9391#endif
9392 else
9393 {
9394 aco_save_T aco;
9395 aucmd_prepbuf(&aco, (buf_T *) from);
9396 varp = get_varp(p);
9397 aucmd_restbuf(&aco);
9398 }
9399 }
9400 else if (opt_type == SREQ_WIN)
9401 {
9402 win_T *save_curwin;
9403 save_curwin = curwin;
9404 curwin = (win_T *) from;
9405 curbuf = curwin->w_buffer;
9406 varp = get_varp(p);
9407 curwin = save_curwin;
9408 curbuf = curwin->w_buffer;
9409 }
9410 if (varp == p->var)
9411 return (r | SOPT_UNSET);
9412 }
9413
9414 if (varp != NULL)
9415 {
9416 if (p->flags & P_STRING)
9417 *stringval = vim_strsave(*(char_u **)(varp));
9418 else if (p->flags & P_NUM)
9419 *numval = *(long *) varp;
9420 else
9421 *numval = *(int *)varp;
9422 }
9423
9424 return r;
9425}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009426
9427/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009428 * Iterate over options. First argument is a pointer to a pointer to a
9429 * structure inside options[] array, second is option type like in the above
9430 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009431 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009432 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009433 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009434 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009435 * first argument to NULL.
9436 *
9437 * Returns full option name for current option on each call.
9438 */
9439 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009440option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009441{
9442 struct vimoption *ret = NULL;
9443 do
9444 {
9445 if (*option == NULL)
9446 *option = (void *) options;
9447 else if (((struct vimoption *) (*option))->fullname == NULL)
9448 {
9449 *option = NULL;
9450 return NULL;
9451 }
9452 else
9453 *option = (void *) (((struct vimoption *) (*option)) + 1);
9454
9455 ret = ((struct vimoption *) (*option));
9456
9457 /* Hidden option */
9458 if (ret->var == NULL)
9459 {
9460 ret = NULL;
9461 continue;
9462 }
9463
9464 switch (opt_type)
9465 {
9466 case SREQ_GLOBAL:
9467 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9468 ret = NULL;
9469 break;
9470 case SREQ_BUF:
9471 if (!(ret->indir & PV_BUF))
9472 ret = NULL;
9473 break;
9474 case SREQ_WIN:
9475 if (!(ret->indir & PV_WIN))
9476 ret = NULL;
9477 break;
9478 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009479 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009480 return NULL;
9481 }
9482 }
9483 while (ret == NULL);
9484
9485 return (char_u *)ret->fullname;
9486}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009487#endif
9488
Bram Moolenaar071d4272004-06-13 20:20:40 +00009489/*
9490 * Set the value of option "name".
9491 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009492 *
9493 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009494 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009495 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009496set_option_value(
9497 char_u *name,
9498 long number,
9499 char_u *string,
9500 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009501{
9502 int opt_idx;
9503 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009504 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009505
9506 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009507 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009508 {
9509 int key;
9510
9511 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9512 && (key = find_key_option(name)) != 0)
9513 {
9514 char_u key_name[2];
9515
9516 if (key < 0)
9517 {
9518 key_name[0] = KEY2TERMCAP0(key);
9519 key_name[1] = KEY2TERMCAP1(key);
9520 }
9521 else
9522 {
9523 key_name[0] = KS_KEY;
9524 key_name[1] = (key & 0xff);
9525 }
9526 add_termcode(key_name, string, FALSE);
9527 if (full_screen)
9528 ttest(FALSE);
9529 redraw_all_later(CLEAR);
9530 return NULL;
9531 }
9532
Bram Moolenaar071d4272004-06-13 20:20:40 +00009533 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009534 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009535 else
9536 {
9537 flags = options[opt_idx].flags;
9538#ifdef HAVE_SANDBOX
9539 /* Disallow changing some options in the sandbox */
9540 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009541 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009542 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009543 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009544 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009545#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009546 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009547 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009548 else
9549 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009550 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551 if (varp != NULL) /* hidden option is not changed */
9552 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009553 if (number == 0 && string != NULL)
9554 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009555 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009556
9557 /* Either we are given a string or we are setting option
9558 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009559 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009560 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009561 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009562 {
9563 /* There's another character after zeros or the string
9564 * is empty. In both cases, we are trying to set a
9565 * num option using a string. */
9566 EMSG3(_("E521: Number required: &%s = '%s'"),
9567 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009568 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009569
9570 }
9571 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009572 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009573 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009574 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009575 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009576 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009577 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009578 }
9579 }
9580 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009581 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582}
9583
9584/*
9585 * Get the terminal code for a terminal option.
9586 * Returns NULL when not found.
9587 */
9588 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009589get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590{
9591 int opt_idx;
9592 char_u *varp;
9593
9594 if (tname[0] != 't' || tname[1] != '_' ||
9595 tname[2] == NUL || tname[3] == NUL)
9596 return NULL;
9597 if ((opt_idx = findoption(tname)) >= 0)
9598 {
9599 varp = get_varp(&(options[opt_idx]));
9600 if (varp != NULL)
9601 varp = *(char_u **)(varp);
9602 return varp;
9603 }
9604 return find_termcode(tname + 2);
9605}
9606
9607 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009608get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009609{
9610 int i;
9611
9612 i = findoption((char_u *)"hl");
9613 if (i >= 0)
9614 return options[i].def_val[VI_DEFAULT];
9615 return (char_u *)NULL;
9616}
9617
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009618#if defined(FEAT_MBYTE) || defined(PROTO)
9619 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009620get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009621{
9622 int i;
9623
9624 i = findoption((char_u *)"enc");
9625 if (i >= 0)
9626 return options[i].def_val[VI_DEFAULT];
9627 return (char_u *)NULL;
9628}
9629#endif
9630
Bram Moolenaar071d4272004-06-13 20:20:40 +00009631/*
9632 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9633 */
9634 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009635find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009636{
9637 int key;
9638 int modifiers;
9639
9640 /*
9641 * Don't use get_special_key_code() for t_xx, we don't want it to call
9642 * add_termcap_entry().
9643 */
9644 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9645 key = TERMCAP2KEY(arg[2], arg[3]);
9646 else
9647 {
9648 --arg; /* put arg at the '<' */
9649 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009650 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009651 if (modifiers) /* can't handle modifiers here */
9652 key = 0;
9653 }
9654 return key;
9655}
9656
9657/*
9658 * if 'all' == 0: show changed options
9659 * if 'all' == 1: show all normal options
9660 * if 'all' == 2: show all terminal options
9661 */
9662 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009663showoptions(
9664 int all,
9665 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009666{
9667 struct vimoption *p;
9668 int col;
9669 int isterm;
9670 char_u *varp;
9671 struct vimoption **items;
9672 int item_count;
9673 int run;
9674 int row, rows;
9675 int cols;
9676 int i;
9677 int len;
9678
9679#define INC 20
9680#define GAP 3
9681
9682 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9683 PARAM_COUNT));
9684 if (items == NULL)
9685 return;
9686
9687 /* Highlight title */
9688 if (all == 2)
9689 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9690 else if (opt_flags & OPT_GLOBAL)
9691 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9692 else if (opt_flags & OPT_LOCAL)
9693 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9694 else
9695 MSG_PUTS_TITLE(_("\n--- Options ---"));
9696
9697 /*
9698 * do the loop two times:
9699 * 1. display the short items
9700 * 2. display the long items (only strings and numbers)
9701 */
9702 for (run = 1; run <= 2 && !got_int; ++run)
9703 {
9704 /*
9705 * collect the items in items[]
9706 */
9707 item_count = 0;
9708 for (p = &options[0]; p->fullname != NULL; p++)
9709 {
9710 varp = NULL;
9711 isterm = istermoption(p);
9712 if (opt_flags != 0)
9713 {
9714 if (p->indir != PV_NONE && !isterm)
9715 varp = get_varp_scope(p, opt_flags);
9716 }
9717 else
9718 varp = get_varp(p);
9719 if (varp != NULL
9720 && ((all == 2 && isterm)
9721 || (all == 1 && !isterm)
9722 || (all == 0 && !optval_default(p, varp))))
9723 {
9724 if (p->flags & P_BOOL)
9725 len = 1; /* a toggle option fits always */
9726 else
9727 {
9728 option_value2string(p, opt_flags);
9729 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9730 }
9731 if ((len <= INC - GAP && run == 1) ||
9732 (len > INC - GAP && run == 2))
9733 items[item_count++] = p;
9734 }
9735 }
9736
9737 /*
9738 * display the items
9739 */
9740 if (run == 1)
9741 {
9742 cols = (Columns + GAP - 3) / INC;
9743 if (cols == 0)
9744 cols = 1;
9745 rows = (item_count + cols - 1) / cols;
9746 }
9747 else /* run == 2 */
9748 rows = item_count;
9749 for (row = 0; row < rows && !got_int; ++row)
9750 {
9751 msg_putchar('\n'); /* go to next line */
9752 if (got_int) /* 'q' typed in more */
9753 break;
9754 col = 0;
9755 for (i = row; i < item_count; i += rows)
9756 {
9757 msg_col = col; /* make columns */
9758 showoneopt(items[i], opt_flags);
9759 col += INC;
9760 }
9761 out_flush();
9762 ui_breakcheck();
9763 }
9764 }
9765 vim_free(items);
9766}
9767
9768/*
9769 * Return TRUE if option "p" has its default value.
9770 */
9771 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009772optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009773{
9774 int dvi;
9775
9776 if (varp == NULL)
9777 return TRUE; /* hidden option is always at default */
9778 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9779 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009780 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009781 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009782 /* the cast to long is required for Manx C, long_i is
9783 * needed for MSVC */
9784 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009785 /* P_STRING */
9786 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9787}
9788
9789/*
9790 * showoneopt: show the value of one option
9791 * must not be called with a hidden option!
9792 */
9793 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009794showoneopt(
9795 struct vimoption *p,
9796 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009797{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009798 char_u *varp;
9799 int save_silent = silent_mode;
9800
9801 silent_mode = FALSE;
9802 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009803
9804 varp = get_varp_scope(p, opt_flags);
9805
9806 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9807 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9808 ? !curbufIsChanged() : !*(int *)varp))
9809 MSG_PUTS("no");
9810 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9811 MSG_PUTS("--");
9812 else
9813 MSG_PUTS(" ");
9814 MSG_PUTS(p->fullname);
9815 if (!(p->flags & P_BOOL))
9816 {
9817 msg_putchar('=');
9818 /* put value string in NameBuff */
9819 option_value2string(p, opt_flags);
9820 msg_outtrans(NameBuff);
9821 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009822
9823 silent_mode = save_silent;
9824 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009825}
9826
9827/*
9828 * Write modified options as ":set" commands to a file.
9829 *
9830 * There are three values for "opt_flags":
9831 * OPT_GLOBAL: Write global option values and fresh values of
9832 * buffer-local options (used for start of a session
9833 * file).
9834 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9835 * curwin (used for a vimrc file).
9836 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9837 * and local values for window-local options of
9838 * curwin. Local values are also written when at the
9839 * default value, because a modeline or autocommand
9840 * may have set them when doing ":edit file" and the
9841 * user has set them back at the default or fresh
9842 * value.
9843 * When "local_only" is TRUE, don't write fresh
9844 * values, only local values (for ":mkview").
9845 * (fresh value = value used for a new buffer or window for a local option).
9846 *
9847 * Return FAIL on error, OK otherwise.
9848 */
9849 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009850makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009851{
9852 struct vimoption *p;
9853 char_u *varp; /* currently used value */
9854 char_u *varp_fresh; /* local value */
9855 char_u *varp_local = NULL; /* fresh value */
9856 char *cmd;
9857 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009858 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009859
9860 /*
9861 * The options that don't have a default (terminal name, columns, lines)
9862 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009863 * Do the loop over "options[]" twice: once for options with the
9864 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009866 for (pri = 1; pri >= 0; --pri)
9867 {
9868 for (p = &options[0]; !istermoption(p); p++)
9869 if (!(p->flags & P_NO_MKRC)
9870 && !istermoption(p)
9871 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009872 {
9873 /* skip global option when only doing locals */
9874 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9875 continue;
9876
9877 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9878 * file, they are always buffer-specific. */
9879 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9880 continue;
9881
9882 /* Global values are only written when not at the default value. */
9883 varp = get_varp_scope(p, opt_flags);
9884 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9885 continue;
9886
9887 round = 2;
9888 if (p->indir != PV_NONE)
9889 {
9890 if (p->var == VAR_WIN)
9891 {
9892 /* skip window-local option when only doing globals */
9893 if (!(opt_flags & OPT_LOCAL))
9894 continue;
9895 /* When fresh value of window-local option is not at the
9896 * default, need to write it too. */
9897 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9898 {
9899 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9900 if (!optval_default(p, varp_fresh))
9901 {
9902 round = 1;
9903 varp_local = varp;
9904 varp = varp_fresh;
9905 }
9906 }
9907 }
9908 }
9909
9910 /* Round 1: fresh value for window-local options.
9911 * Round 2: other values */
9912 for ( ; round <= 2; varp = varp_local, ++round)
9913 {
9914 if (round == 1 || (opt_flags & OPT_GLOBAL))
9915 cmd = "set";
9916 else
9917 cmd = "setlocal";
9918
9919 if (p->flags & P_BOOL)
9920 {
9921 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9922 return FAIL;
9923 }
9924 else if (p->flags & P_NUM)
9925 {
9926 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9927 return FAIL;
9928 }
9929 else /* P_STRING */
9930 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009931#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9932 int do_endif = FALSE;
9933
Bram Moolenaar071d4272004-06-13 20:20:40 +00009934 /* Don't set 'syntax' and 'filetype' again if the value is
9935 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009936 if (
9937# if defined(FEAT_SYN_HL)
9938 p->indir == PV_SYN
9939# if defined(FEAT_AUTOCMD)
9940 ||
9941# endif
9942# endif
9943# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009944 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009945# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009946 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009947 {
9948 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9949 *(char_u **)(varp)) < 0
9950 || put_eol(fd) < 0)
9951 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009952 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009953 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009954#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009955 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9956 (p->flags & P_EXPAND) != 0) == FAIL)
9957 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009958#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9959 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009960 {
9961 if (put_line(fd, "endif") == FAIL)
9962 return FAIL;
9963 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009964#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009965 }
9966 }
9967 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009969 return OK;
9970}
9971
9972#if defined(FEAT_FOLDING) || defined(PROTO)
9973/*
9974 * Generate set commands for the local fold options only. Used when
9975 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9976 */
9977 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009978makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009979{
9980 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9981# ifdef FEAT_EVAL
9982 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9983 == FAIL
9984# endif
9985 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9986 == FAIL
9987 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9988 == FAIL
9989 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9990 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9991 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9992 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9993 )
9994 return FAIL;
9995
9996 return OK;
9997}
9998#endif
9999
10000 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010001put_setstring(
10002 FILE *fd,
10003 char *cmd,
10004 char *name,
10005 char_u **valuep,
10006 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010007{
10008 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010009 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010010
10011 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10012 return FAIL;
10013 if (*valuep != NULL)
10014 {
10015 /* Output 'pastetoggle' as key names. For other
10016 * options some characters have to be escaped with
10017 * CTRL-V or backslash */
10018 if (valuep == &p_pt)
10019 {
10020 s = *valuep;
10021 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010022 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010023 return FAIL;
10024 }
10025 else if (expand)
10026 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010027 buf = alloc(MAXPATHL);
10028 if (buf == NULL)
10029 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10031 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010032 {
10033 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010034 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010035 }
10036 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010037 }
10038 else if (put_escstr(fd, *valuep, 2) == FAIL)
10039 return FAIL;
10040 }
10041 if (put_eol(fd) < 0)
10042 return FAIL;
10043 return OK;
10044}
10045
10046 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010047put_setnum(
10048 FILE *fd,
10049 char *cmd,
10050 char *name,
10051 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052{
10053 long wc;
10054
10055 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10056 return FAIL;
10057 if (wc_use_keyname((char_u *)valuep, &wc))
10058 {
10059 /* print 'wildchar' and 'wildcharm' as a key name */
10060 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10061 return FAIL;
10062 }
10063 else if (fprintf(fd, "%ld", *valuep) < 0)
10064 return FAIL;
10065 if (put_eol(fd) < 0)
10066 return FAIL;
10067 return OK;
10068}
10069
10070 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010071put_setbool(
10072 FILE *fd,
10073 char *cmd,
10074 char *name,
10075 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010076{
Bram Moolenaar893de922007-10-02 18:40:57 +000010077 if (value < 0) /* global/local option using global value */
10078 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010079 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10080 || put_eol(fd) < 0)
10081 return FAIL;
10082 return OK;
10083}
10084
10085/*
10086 * Clear all the terminal options.
10087 * If the option has been allocated, free the memory.
10088 * Terminal options are never hidden or indirect.
10089 */
10090 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010091clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010092{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010093 /*
10094 * Reset a few things before clearing the old options. This may cause
10095 * outputting a few things that the terminal doesn't understand, but the
10096 * screen will be cleared later, so this is OK.
10097 */
10098#ifdef FEAT_MOUSE_TTY
10099 mch_setmouse(FALSE); /* switch mouse off */
10100#endif
10101#ifdef FEAT_TITLE
10102 mch_restore_title(3); /* restore window titles */
10103#endif
10104#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10105 /* When starting the GUI close the display opened for the clipboard.
10106 * After restoring the title, because that will need the display. */
10107 if (gui.starting)
10108 clear_xterm_clip();
10109#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010110 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010111
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010112 free_termoptions();
10113}
10114
10115 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010116free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010117{
10118 struct vimoption *p;
10119
Bram Moolenaar071d4272004-06-13 20:20:40 +000010120 for (p = &options[0]; p->fullname != NULL; p++)
10121 if (istermoption(p))
10122 {
10123 if (p->flags & P_ALLOCED)
10124 free_string_option(*(char_u **)(p->var));
10125 if (p->flags & P_DEF_ALLOCED)
10126 free_string_option(p->def_val[VI_DEFAULT]);
10127 *(char_u **)(p->var) = empty_option;
10128 p->def_val[VI_DEFAULT] = empty_option;
10129 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10130 }
10131 clear_termcodes();
10132}
10133
10134/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010135 * Free the string for one term option, if it was allocated.
10136 * Set the string to empty_option and clear allocated flag.
10137 * "var" points to the option value.
10138 */
10139 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010140free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010141{
10142 struct vimoption *p;
10143
10144 for (p = &options[0]; p->fullname != NULL; p++)
10145 if (p->var == var)
10146 {
10147 if (p->flags & P_ALLOCED)
10148 free_string_option(*(char_u **)(p->var));
10149 *(char_u **)(p->var) = empty_option;
10150 p->flags &= ~P_ALLOCED;
10151 break;
10152 }
10153}
10154
10155/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010156 * Set the terminal option defaults to the current value.
10157 * Used after setting the terminal name.
10158 */
10159 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010160set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161{
10162 struct vimoption *p;
10163
10164 for (p = &options[0]; p->fullname != NULL; p++)
10165 {
10166 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10167 {
10168 if (p->flags & P_DEF_ALLOCED)
10169 {
10170 free_string_option(p->def_val[VI_DEFAULT]);
10171 p->flags &= ~P_DEF_ALLOCED;
10172 }
10173 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10174 if (p->flags & P_ALLOCED)
10175 {
10176 p->flags |= P_DEF_ALLOCED;
10177 p->flags &= ~P_ALLOCED; /* don't free the value now */
10178 }
10179 }
10180 }
10181}
10182
10183/*
10184 * return TRUE if 'p' starts with 't_'
10185 */
10186 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010187istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188{
10189 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10190}
10191
10192/*
10193 * Compute columns for ruler and shown command. 'sc_col' is also used to
10194 * decide what the maximum length of a message on the status line can be.
10195 * If there is a status line for the last window, 'sc_col' is independent
10196 * of 'ru_col'.
10197 */
10198
10199#define COL_RULER 17 /* columns needed by standard ruler */
10200
10201 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010202comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203{
10204#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010205 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010206
10207 sc_col = 0;
10208 ru_col = 0;
10209 if (p_ru)
10210 {
10211#ifdef FEAT_STL_OPT
10212 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10213#else
10214 ru_col = COL_RULER + 1;
10215#endif
10216 /* no last status line, adjust sc_col */
10217 if (!last_has_status)
10218 sc_col = ru_col;
10219 }
10220 if (p_sc)
10221 {
10222 sc_col += SHOWCMD_COLS;
10223 if (!p_ru || last_has_status) /* no need for separating space */
10224 ++sc_col;
10225 }
10226 sc_col = Columns - sc_col;
10227 ru_col = Columns - ru_col;
10228 if (sc_col <= 0) /* screen too narrow, will become a mess */
10229 sc_col = 1;
10230 if (ru_col <= 0)
10231 ru_col = 1;
10232#else
10233 sc_col = Columns;
10234 ru_col = Columns;
10235#endif
10236}
10237
10238/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010239 * Unset local option value, similar to ":set opt<".
10240 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010241 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010242unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010243{
10244 struct vimoption *p;
10245 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010246 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010247
10248 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010249 if (opt_idx < 0)
10250 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010251 p = &(options[opt_idx]);
10252
10253 switch ((int)p->indir)
10254 {
10255 /* global option with local value: use local value if it's been set */
10256 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010257 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010258 break;
10259 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010260 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010261 break;
10262 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010263 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010264 break;
10265 case PV_AR:
10266 buf->b_p_ar = -1;
10267 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010268 case PV_BKC:
10269 clear_string_option(&buf->b_p_bkc);
10270 buf->b_bkc_flags = 0;
10271 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010272 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010273 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010274 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010275 case PV_TC:
10276 clear_string_option(&buf->b_p_tc);
10277 buf->b_tc_flags = 0;
10278 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010279#ifdef FEAT_FIND_ID
10280 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010281 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010282 break;
10283 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010284 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010285 break;
10286#endif
10287#ifdef FEAT_INS_EXPAND
10288 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010289 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010290 break;
10291 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010292 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010293 break;
10294#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010295 case PV_FP:
10296 clear_string_option(&buf->b_p_fp);
10297 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010298#ifdef FEAT_QUICKFIX
10299 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010300 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010301 break;
10302 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010303 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010304 break;
10305 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010306 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010307 break;
10308#endif
10309#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10310 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010311 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010312 break;
10313#endif
10314#if defined(FEAT_CRYPT)
10315 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010316 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010317 break;
10318#endif
10319#ifdef FEAT_STL_OPT
10320 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010321 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010322 break;
10323#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010324 case PV_UL:
10325 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10326 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010327#ifdef FEAT_LISP
10328 case PV_LW:
10329 clear_string_option(&buf->b_p_lw);
10330 break;
10331#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010332 }
10333}
10334
10335/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010336 * Get pointer to option variable, depending on local or global scope.
10337 */
10338 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010339get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010340{
10341 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10342 {
10343 if (p->var == VAR_WIN)
10344 return (char_u *)GLOBAL_WO(get_varp(p));
10345 return p->var;
10346 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010347 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348 {
10349 switch ((int)p->indir)
10350 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010351 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010353 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10354 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10355 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010357 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10358 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10359 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010360 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010361 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010362 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010364 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10365 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010366#endif
10367#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010368 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10369 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010370#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010371#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10372 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10373#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010374#if defined(FEAT_CRYPT)
10375 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10376#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010377#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010378 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010379#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010380 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010381#ifdef FEAT_LISP
10382 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10383#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010384 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010385 }
10386 return NULL; /* "cannot happen" */
10387 }
10388 return get_varp(p);
10389}
10390
10391/*
10392 * Get pointer to option variable.
10393 */
10394 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010395get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010396{
10397 /* hidden option, always return NULL */
10398 if (p->var == NULL)
10399 return NULL;
10400
10401 switch ((int)p->indir)
10402 {
10403 case PV_NONE: return p->var;
10404
10405 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010406 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010408 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010409 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010410 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010411 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010412 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010414 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010416 case PV_TC: return *curbuf->b_p_tc != NUL
10417 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010418 case PV_BKC: return *curbuf->b_p_bkc != NUL
10419 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010421 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010422 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010423 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010424 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10425#endif
10426#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010427 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010428 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010429 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010430 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10431#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010432 case PV_FP: return *curbuf->b_p_fp != NUL
10433 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010435 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010436 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010437 case PV_GP: return *curbuf->b_p_gp != NUL
10438 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10439 case PV_MP: return *curbuf->b_p_mp != NUL
10440 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010441#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010442#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10443 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10444 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10445#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010446#if defined(FEAT_CRYPT)
10447 case PV_CM: return *curbuf->b_p_cm != NUL
10448 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10449#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010450#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010451 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010452 ? (char_u *)&(curwin->w_p_stl) : p->var;
10453#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010454 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10455 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010456#ifdef FEAT_LISP
10457 case PV_LW: return *curbuf->b_p_lw != NUL
10458 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010460
10461#ifdef FEAT_ARABIC
10462 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10463#endif
10464 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010465#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010466 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10467#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010468#ifdef FEAT_SYN_HL
10469 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10470 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010471 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010472#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010473#ifdef FEAT_DIFF
10474 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10475#endif
10476#ifdef FEAT_FOLDING
10477 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10478 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10479 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10480 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10481 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10482 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10483 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10484# ifdef FEAT_EVAL
10485 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10486 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10487# endif
10488 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10489#endif
10490 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010491 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010492#ifdef FEAT_LINEBREAK
10493 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10494#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010495#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010496 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010497 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10498#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10500 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10501#endif
10502#ifdef FEAT_RIGHTLEFT
10503 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10504 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10505#endif
10506 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10507 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10508#ifdef FEAT_LINEBREAK
10509 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010510 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10511 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010512#endif
10513#ifdef FEAT_SCROLLBIND
10514 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10515#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010516#ifdef FEAT_CURSORBIND
10517 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10518#endif
10519#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010520 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10521 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010522#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010523
10524 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10525 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10526#ifdef FEAT_MBYTE
10527 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10528#endif
10529#if defined(FEAT_QUICKFIX)
10530 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10531 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10532#endif
10533 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10534 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10535#ifdef FEAT_CINDENT
10536 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10537 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10538 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10539#endif
10540#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10541 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10542#endif
10543#ifdef FEAT_COMMENTS
10544 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10545#endif
10546#ifdef FEAT_FOLDING
10547 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10548#endif
10549#ifdef FEAT_INS_EXPAND
10550 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10551#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010552#ifdef FEAT_COMPL_FUNC
10553 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010554 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010555#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010557 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10559#ifdef FEAT_MBYTE
10560 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10561#endif
10562 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10563#ifdef FEAT_AUTOCMD
10564 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10565#endif
10566 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010567 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10569 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10570 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10571 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10572#ifdef FEAT_FIND_ID
10573# ifdef FEAT_EVAL
10574 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10575# endif
10576#endif
10577#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10578 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10579 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10580#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010581#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010582 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010584#ifdef FEAT_CRYPT
10585 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10586#endif
10587#ifdef FEAT_LISP
10588 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10589#endif
10590 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10591 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10592 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10593 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10594 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010596#ifdef FEAT_TEXTOBJ
10597 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10598#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010599 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10600#ifdef FEAT_SMARTINDENT
10601 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10602#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10605#ifdef FEAT_SEARCHPATH
10606 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10607#endif
10608 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10609#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010610 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010611 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10612#endif
10613#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010614 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10615 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10616 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617#endif
10618 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10619 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10620 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10621 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010622#ifdef FEAT_PERSISTENT_UNDO
10623 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10624#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010625 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10626#ifdef FEAT_KEYMAP
10627 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10628#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010629#ifdef FEAT_SIGNS
10630 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10631#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010632 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633 }
10634 /* always return a valid pointer to avoid a crash! */
10635 return (char_u *)&(curbuf->b_p_wm);
10636}
10637
10638/*
10639 * Get the value of 'equalprg', either the buffer-local one or the global one.
10640 */
10641 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010642get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010643{
10644 if (*curbuf->b_p_ep == NUL)
10645 return p_ep;
10646 return curbuf->b_p_ep;
10647}
10648
10649#if defined(FEAT_WINDOWS) || defined(PROTO)
10650/*
10651 * Copy options from one window to another.
10652 * Used when splitting a window.
10653 */
10654 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010655win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010656{
10657 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10658 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10659# ifdef FEAT_RIGHTLEFT
10660# ifdef FEAT_FKMAP
10661 /* Is this right? */
10662 wp_to->w_farsi = wp_from->w_farsi;
10663# endif
10664# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010665#if defined(FEAT_LINEBREAK)
10666 briopt_check(wp_to);
10667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010668}
10669#endif
10670
10671/*
10672 * Copy the options from one winopt_T to another.
10673 * Doesn't free the old option values in "to", use clear_winopt() for that.
10674 * The 'scroll' option is not copied, because it depends on the window height.
10675 * The 'previewwindow' option is reset, there can be only one preview window.
10676 */
10677 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010678copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679{
10680#ifdef FEAT_ARABIC
10681 to->wo_arab = from->wo_arab;
10682#endif
10683 to->wo_list = from->wo_list;
10684 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010685 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010686#ifdef FEAT_LINEBREAK
10687 to->wo_nuw = from->wo_nuw;
10688#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689#ifdef FEAT_RIGHTLEFT
10690 to->wo_rl = from->wo_rl;
10691 to->wo_rlc = vim_strsave(from->wo_rlc);
10692#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010693#ifdef FEAT_STL_OPT
10694 to->wo_stl = vim_strsave(from->wo_stl);
10695#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010696 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010697#ifdef FEAT_DIFF
10698 to->wo_wrap_save = from->wo_wrap_save;
10699#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010700#ifdef FEAT_LINEBREAK
10701 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010702 to->wo_bri = from->wo_bri;
10703 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010704#endif
10705#ifdef FEAT_SCROLLBIND
10706 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010707 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010709#ifdef FEAT_CURSORBIND
10710 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010711 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010712#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010713#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010714 to->wo_spell = from->wo_spell;
10715#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010716#ifdef FEAT_SYN_HL
10717 to->wo_cuc = from->wo_cuc;
10718 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010719 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010720#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721#ifdef FEAT_DIFF
10722 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010723 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010724#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010725#ifdef FEAT_CONCEAL
10726 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010727 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729#ifdef FEAT_FOLDING
10730 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010731 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010733 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734 to->wo_fdi = vim_strsave(from->wo_fdi);
10735 to->wo_fml = from->wo_fml;
10736 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010737 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010739 to->wo_fdm_save = from->wo_diff_saved
10740 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741 to->wo_fdn = from->wo_fdn;
10742# ifdef FEAT_EVAL
10743 to->wo_fde = vim_strsave(from->wo_fde);
10744 to->wo_fdt = vim_strsave(from->wo_fdt);
10745# endif
10746 to->wo_fmr = vim_strsave(from->wo_fmr);
10747#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010748#ifdef FEAT_SIGNS
10749 to->wo_scl = vim_strsave(from->wo_scl);
10750#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751 check_winopt(to); /* don't want NULL pointers */
10752}
10753
10754/*
10755 * Check string options in a window for a NULL value.
10756 */
10757 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010758check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759{
10760 check_winopt(&win->w_onebuf_opt);
10761 check_winopt(&win->w_allbuf_opt);
10762}
10763
10764/*
10765 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10766 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010767 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010768check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010769{
10770#ifdef FEAT_FOLDING
10771 check_string_option(&wop->wo_fdi);
10772 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010773 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774# ifdef FEAT_EVAL
10775 check_string_option(&wop->wo_fde);
10776 check_string_option(&wop->wo_fdt);
10777# endif
10778 check_string_option(&wop->wo_fmr);
10779#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010780#ifdef FEAT_SIGNS
10781 check_string_option(&wop->wo_scl);
10782#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783#ifdef FEAT_RIGHTLEFT
10784 check_string_option(&wop->wo_rlc);
10785#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010786#ifdef FEAT_STL_OPT
10787 check_string_option(&wop->wo_stl);
10788#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010789#ifdef FEAT_SYN_HL
10790 check_string_option(&wop->wo_cc);
10791#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010792#ifdef FEAT_CONCEAL
10793 check_string_option(&wop->wo_cocu);
10794#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010795#ifdef FEAT_LINEBREAK
10796 check_string_option(&wop->wo_briopt);
10797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798}
10799
10800/*
10801 * Free the allocated memory inside a winopt_T.
10802 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010804clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010805{
10806#ifdef FEAT_FOLDING
10807 clear_string_option(&wop->wo_fdi);
10808 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010809 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010810# ifdef FEAT_EVAL
10811 clear_string_option(&wop->wo_fde);
10812 clear_string_option(&wop->wo_fdt);
10813# endif
10814 clear_string_option(&wop->wo_fmr);
10815#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010816#ifdef FEAT_SIGNS
10817 clear_string_option(&wop->wo_scl);
10818#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010819#ifdef FEAT_LINEBREAK
10820 clear_string_option(&wop->wo_briopt);
10821#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822#ifdef FEAT_RIGHTLEFT
10823 clear_string_option(&wop->wo_rlc);
10824#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010825#ifdef FEAT_STL_OPT
10826 clear_string_option(&wop->wo_stl);
10827#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010828#ifdef FEAT_SYN_HL
10829 clear_string_option(&wop->wo_cc);
10830#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010831#ifdef FEAT_CONCEAL
10832 clear_string_option(&wop->wo_cocu);
10833#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010834}
10835
10836/*
10837 * Copy global option values to local options for one buffer.
10838 * Used when creating a new buffer and sometimes when entering a buffer.
10839 * flags:
10840 * BCO_ENTER We will enter the buf buffer.
10841 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10842 * appropriate.
10843 * BCO_NOHELP Don't copy the values to a help buffer.
10844 */
10845 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010846buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010847{
10848 int should_copy = TRUE;
10849 char_u *save_p_isk = NULL; /* init for GCC */
10850 int dont_do_help;
10851 int did_isk = FALSE;
10852
10853 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854 * Skip this when the option defaults have not been set yet. Happens when
10855 * main() allocates the first buffer.
10856 */
10857 if (p_cpo != NULL)
10858 {
10859 /*
10860 * Always copy when entering and 'cpo' contains 'S'.
10861 * Don't copy when already initialized.
10862 * Don't copy when 'cpo' contains 's' and not entering.
10863 * 'S' BCO_ENTER initialized 's' should_copy
10864 * yes yes X X TRUE
10865 * yes no yes X FALSE
10866 * no X yes X FALSE
10867 * X no no yes FALSE
10868 * X no no no TRUE
10869 * no yes no X TRUE
10870 */
10871 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10872 && (buf->b_p_initialized
10873 || (!(flags & BCO_ENTER)
10874 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10875 should_copy = FALSE;
10876
10877 if (should_copy || (flags & BCO_ALWAYS))
10878 {
10879 /* Don't copy the options specific to a help buffer when
10880 * BCO_NOHELP is given or the options were initialized already
10881 * (jumping back to a help file with CTRL-T or CTRL-O) */
10882 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10883 || buf->b_p_initialized;
10884 if (dont_do_help) /* don't free b_p_isk */
10885 {
10886 save_p_isk = buf->b_p_isk;
10887 buf->b_p_isk = NULL;
10888 }
10889 /*
10890 * Always free the allocated strings.
10891 * If not already initialized, set 'readonly' and copy 'fileformat'.
10892 */
10893 if (!buf->b_p_initialized)
10894 {
10895 free_buf_options(buf, TRUE);
10896 buf->b_p_ro = FALSE; /* don't copy readonly */
10897 buf->b_p_tx = p_tx;
10898#ifdef FEAT_MBYTE
10899 buf->b_p_fenc = vim_strsave(p_fenc);
10900#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020010901 switch (*p_ffs)
10902 {
10903 case 'm':
10904 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
10905 case 'd':
10906 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
10907 case 'u':
10908 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
10909 default:
10910 buf->b_p_ff = vim_strsave(p_ff);
10911 }
10912 if (buf->b_p_ff != NULL)
10913 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914#if defined(FEAT_QUICKFIX)
10915 buf->b_p_bh = empty_option;
10916 buf->b_p_bt = empty_option;
10917#endif
10918 }
10919 else
10920 free_buf_options(buf, FALSE);
10921
10922 buf->b_p_ai = p_ai;
10923 buf->b_p_ai_nopaste = p_ai_nopaste;
10924 buf->b_p_sw = p_sw;
10925 buf->b_p_tw = p_tw;
10926 buf->b_p_tw_nopaste = p_tw_nopaste;
10927 buf->b_p_tw_nobin = p_tw_nobin;
10928 buf->b_p_wm = p_wm;
10929 buf->b_p_wm_nopaste = p_wm_nopaste;
10930 buf->b_p_wm_nobin = p_wm_nobin;
10931 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010932#ifdef FEAT_MBYTE
10933 buf->b_p_bomb = p_bomb;
10934#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010935 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936 buf->b_p_et = p_et;
10937 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010938 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939 buf->b_p_ml = p_ml;
10940 buf->b_p_ml_nobin = p_ml_nobin;
10941 buf->b_p_inf = p_inf;
10942 buf->b_p_swf = p_swf;
10943#ifdef FEAT_INS_EXPAND
10944 buf->b_p_cpt = vim_strsave(p_cpt);
10945#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010946#ifdef FEAT_COMPL_FUNC
10947 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010948 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010949#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010950 buf->b_p_sts = p_sts;
10951 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010952 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010953#ifdef FEAT_COMMENTS
10954 buf->b_p_com = vim_strsave(p_com);
10955#endif
10956#ifdef FEAT_FOLDING
10957 buf->b_p_cms = vim_strsave(p_cms);
10958#endif
10959 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010960 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961 buf->b_p_nf = vim_strsave(p_nf);
10962 buf->b_p_mps = vim_strsave(p_mps);
10963#ifdef FEAT_SMARTINDENT
10964 buf->b_p_si = p_si;
10965#endif
10966 buf->b_p_ci = p_ci;
10967#ifdef FEAT_CINDENT
10968 buf->b_p_cin = p_cin;
10969 buf->b_p_cink = vim_strsave(p_cink);
10970 buf->b_p_cino = vim_strsave(p_cino);
10971#endif
10972#ifdef FEAT_AUTOCMD
10973 /* Don't copy 'filetype', it must be detected */
10974 buf->b_p_ft = empty_option;
10975#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010976 buf->b_p_pi = p_pi;
10977#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10978 buf->b_p_cinw = vim_strsave(p_cinw);
10979#endif
10980#ifdef FEAT_LISP
10981 buf->b_p_lisp = p_lisp;
10982#endif
10983#ifdef FEAT_SYN_HL
10984 /* Don't copy 'syntax', it must be set */
10985 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010986 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010987 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010988#endif
10989#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010990 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010991 (void)compile_cap_prog(&buf->b_s);
10992 buf->b_s.b_p_spf = vim_strsave(p_spf);
10993 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994#endif
10995#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10996 buf->b_p_inde = vim_strsave(p_inde);
10997 buf->b_p_indk = vim_strsave(p_indk);
10998#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010999 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011000#if defined(FEAT_EVAL)
11001 buf->b_p_fex = vim_strsave(p_fex);
11002#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011003#ifdef FEAT_CRYPT
11004 buf->b_p_key = vim_strsave(p_key);
11005#endif
11006#ifdef FEAT_SEARCHPATH
11007 buf->b_p_sua = vim_strsave(p_sua);
11008#endif
11009#ifdef FEAT_KEYMAP
11010 buf->b_p_keymap = vim_strsave(p_keymap);
11011 buf->b_kmap_state |= KEYMAP_INIT;
11012#endif
11013 /* This isn't really an option, but copying the langmap and IME
11014 * state from the current buffer is better than resetting it. */
11015 buf->b_p_iminsert = p_iminsert;
11016 buf->b_p_imsearch = p_imsearch;
11017
11018 /* options that are normally global but also have a local value
11019 * are not copied, start using the global value */
11020 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011021 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011022 buf->b_p_bkc = empty_option;
11023 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011024#ifdef FEAT_QUICKFIX
11025 buf->b_p_gp = empty_option;
11026 buf->b_p_mp = empty_option;
11027 buf->b_p_efm = empty_option;
11028#endif
11029 buf->b_p_ep = empty_option;
11030 buf->b_p_kp = empty_option;
11031 buf->b_p_path = empty_option;
11032 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011033 buf->b_p_tc = empty_option;
11034 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035#ifdef FEAT_FIND_ID
11036 buf->b_p_def = empty_option;
11037 buf->b_p_inc = empty_option;
11038# ifdef FEAT_EVAL
11039 buf->b_p_inex = vim_strsave(p_inex);
11040# endif
11041#endif
11042#ifdef FEAT_INS_EXPAND
11043 buf->b_p_dict = empty_option;
11044 buf->b_p_tsr = empty_option;
11045#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011046#ifdef FEAT_TEXTOBJ
11047 buf->b_p_qe = vim_strsave(p_qe);
11048#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011049#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11050 buf->b_p_bexpr = empty_option;
11051#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011052#if defined(FEAT_CRYPT)
11053 buf->b_p_cm = empty_option;
11054#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011055#ifdef FEAT_PERSISTENT_UNDO
11056 buf->b_p_udf = p_udf;
11057#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011058#ifdef FEAT_LISP
11059 buf->b_p_lw = empty_option;
11060#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011061
11062 /*
11063 * Don't copy the options set by ex_help(), use the saved values,
11064 * when going from a help buffer to a non-help buffer.
11065 * Don't touch these at all when BCO_NOHELP is used and going from
11066 * or to a help buffer.
11067 */
11068 if (dont_do_help)
11069 buf->b_p_isk = save_p_isk;
11070 else
11071 {
11072 buf->b_p_isk = vim_strsave(p_isk);
11073 did_isk = TRUE;
11074 buf->b_p_ts = p_ts;
11075 buf->b_help = FALSE;
11076#ifdef FEAT_QUICKFIX
11077 if (buf->b_p_bt[0] == 'h')
11078 clear_string_option(&buf->b_p_bt);
11079#endif
11080 buf->b_p_ma = p_ma;
11081 }
11082 }
11083
11084 /*
11085 * When the options should be copied (ignoring BCO_ALWAYS), set the
11086 * flag that indicates that the options have been initialized.
11087 */
11088 if (should_copy)
11089 buf->b_p_initialized = TRUE;
11090 }
11091
11092 check_buf_options(buf); /* make sure we don't have NULLs */
11093 if (did_isk)
11094 (void)buf_init_chartab(buf, FALSE);
11095}
11096
11097/*
11098 * Reset the 'modifiable' option and its default value.
11099 */
11100 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011101reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102{
11103 int opt_idx;
11104
11105 curbuf->b_p_ma = FALSE;
11106 p_ma = FALSE;
11107 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011108 if (opt_idx >= 0)
11109 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011110}
11111
11112/*
11113 * Set the global value for 'iminsert' to the local value.
11114 */
11115 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011116set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011117{
11118 p_iminsert = curbuf->b_p_iminsert;
11119}
11120
11121/*
11122 * Set the global value for 'imsearch' to the local value.
11123 */
11124 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011125set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011126{
11127 p_imsearch = curbuf->b_p_imsearch;
11128}
11129
11130#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11131static int expand_option_idx = -1;
11132static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11133static int expand_option_flags = 0;
11134
11135 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011136set_context_in_set_cmd(
11137 expand_T *xp,
11138 char_u *arg,
11139 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011140{
11141 int nextchar;
11142 long_u flags = 0; /* init for GCC */
11143 int opt_idx = 0; /* init for GCC */
11144 char_u *p;
11145 char_u *s;
11146 int is_term_option = FALSE;
11147 int key;
11148
11149 expand_option_flags = opt_flags;
11150
11151 xp->xp_context = EXPAND_SETTINGS;
11152 if (*arg == NUL)
11153 {
11154 xp->xp_pattern = arg;
11155 return;
11156 }
11157 p = arg + STRLEN(arg) - 1;
11158 if (*p == ' ' && *(p - 1) != '\\')
11159 {
11160 xp->xp_pattern = p + 1;
11161 return;
11162 }
11163 while (p > arg)
11164 {
11165 s = p;
11166 /* count number of backslashes before ' ' or ',' */
11167 if (*p == ' ' || *p == ',')
11168 {
11169 while (s > arg && *(s - 1) == '\\')
11170 --s;
11171 }
11172 /* break at a space with an even number of backslashes */
11173 if (*p == ' ' && ((p - s) & 1) == 0)
11174 {
11175 ++p;
11176 break;
11177 }
11178 --p;
11179 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011180 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181 {
11182 xp->xp_context = EXPAND_BOOL_SETTINGS;
11183 p += 2;
11184 }
11185 if (STRNCMP(p, "inv", 3) == 0)
11186 {
11187 xp->xp_context = EXPAND_BOOL_SETTINGS;
11188 p += 3;
11189 }
11190 xp->xp_pattern = arg = p;
11191 if (*arg == '<')
11192 {
11193 while (*p != '>')
11194 if (*p++ == NUL) /* expand terminal option name */
11195 return;
11196 key = get_special_key_code(arg + 1);
11197 if (key == 0) /* unknown name */
11198 {
11199 xp->xp_context = EXPAND_NOTHING;
11200 return;
11201 }
11202 nextchar = *++p;
11203 is_term_option = TRUE;
11204 expand_option_name[2] = KEY2TERMCAP0(key);
11205 expand_option_name[3] = KEY2TERMCAP1(key);
11206 }
11207 else
11208 {
11209 if (p[0] == 't' && p[1] == '_')
11210 {
11211 p += 2;
11212 if (*p != NUL)
11213 ++p;
11214 if (*p == NUL)
11215 return; /* expand option name */
11216 nextchar = *++p;
11217 is_term_option = TRUE;
11218 expand_option_name[2] = p[-2];
11219 expand_option_name[3] = p[-1];
11220 }
11221 else
11222 {
11223 /* Allow * wildcard */
11224 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11225 p++;
11226 if (*p == NUL)
11227 return;
11228 nextchar = *p;
11229 *p = NUL;
11230 opt_idx = findoption(arg);
11231 *p = nextchar;
11232 if (opt_idx == -1 || options[opt_idx].var == NULL)
11233 {
11234 xp->xp_context = EXPAND_NOTHING;
11235 return;
11236 }
11237 flags = options[opt_idx].flags;
11238 if (flags & P_BOOL)
11239 {
11240 xp->xp_context = EXPAND_NOTHING;
11241 return;
11242 }
11243 }
11244 }
11245 /* handle "-=" and "+=" */
11246 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11247 {
11248 ++p;
11249 nextchar = '=';
11250 }
11251 if ((nextchar != '=' && nextchar != ':')
11252 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11253 {
11254 xp->xp_context = EXPAND_UNSUCCESSFUL;
11255 return;
11256 }
11257 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11258 {
11259 xp->xp_context = EXPAND_OLD_SETTING;
11260 if (is_term_option)
11261 expand_option_idx = -1;
11262 else
11263 expand_option_idx = opt_idx;
11264 xp->xp_pattern = p + 1;
11265 return;
11266 }
11267 xp->xp_context = EXPAND_NOTHING;
11268 if (is_term_option || (flags & P_NUM))
11269 return;
11270
11271 xp->xp_pattern = p + 1;
11272
11273 if (flags & P_EXPAND)
11274 {
11275 p = options[opt_idx].var;
11276 if (p == (char_u *)&p_bdir
11277 || p == (char_u *)&p_dir
11278 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011279 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011280 || p == (char_u *)&p_rtp
11281#ifdef FEAT_SEARCHPATH
11282 || p == (char_u *)&p_cdpath
11283#endif
11284#ifdef FEAT_SESSION
11285 || p == (char_u *)&p_vdir
11286#endif
11287 )
11288 {
11289 xp->xp_context = EXPAND_DIRECTORIES;
11290 if (p == (char_u *)&p_path
11291#ifdef FEAT_SEARCHPATH
11292 || p == (char_u *)&p_cdpath
11293#endif
11294 )
11295 xp->xp_backslash = XP_BS_THREE;
11296 else
11297 xp->xp_backslash = XP_BS_ONE;
11298 }
11299 else
11300 {
11301 xp->xp_context = EXPAND_FILES;
11302 /* for 'tags' need three backslashes for a space */
11303 if (p == (char_u *)&p_tags)
11304 xp->xp_backslash = XP_BS_THREE;
11305 else
11306 xp->xp_backslash = XP_BS_ONE;
11307 }
11308 }
11309
11310 /* For an option that is a list of file names, find the start of the
11311 * last file name. */
11312 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11313 {
11314 /* count number of backslashes before ' ' or ',' */
11315 if (*p == ' ' || *p == ',')
11316 {
11317 s = p;
11318 while (s > xp->xp_pattern && *(s - 1) == '\\')
11319 --s;
11320 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11321 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11322 {
11323 xp->xp_pattern = p + 1;
11324 break;
11325 }
11326 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011327
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011328#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011329 /* for 'spellsuggest' start at "file:" */
11330 if (options[opt_idx].var == (char_u *)&p_sps
11331 && STRNCMP(p, "file:", 5) == 0)
11332 {
11333 xp->xp_pattern = p + 5;
11334 break;
11335 }
11336#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011337 }
11338
11339 return;
11340}
11341
11342 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011343ExpandSettings(
11344 expand_T *xp,
11345 regmatch_T *regmatch,
11346 int *num_file,
11347 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011348{
11349 int num_normal = 0; /* Nr of matching non-term-code settings */
11350 int num_term = 0; /* Nr of matching terminal code settings */
11351 int opt_idx;
11352 int match;
11353 int count = 0;
11354 char_u *str;
11355 int loop;
11356 int is_term_opt;
11357 char_u name_buf[MAX_KEY_NAME_LEN];
11358 static char *(names[]) = {"all", "termcap"};
11359 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11360
11361 /* do this loop twice:
11362 * loop == 0: count the number of matching options
11363 * loop == 1: copy the matching options into allocated memory
11364 */
11365 for (loop = 0; loop <= 1; ++loop)
11366 {
11367 regmatch->rm_ic = ic;
11368 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11369 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011370 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11371 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11373 {
11374 if (loop == 0)
11375 num_normal++;
11376 else
11377 (*file)[count++] = vim_strsave((char_u *)names[match]);
11378 }
11379 }
11380 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11381 opt_idx++)
11382 {
11383 if (options[opt_idx].var == NULL)
11384 continue;
11385 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11386 && !(options[opt_idx].flags & P_BOOL))
11387 continue;
11388 is_term_opt = istermoption(&options[opt_idx]);
11389 if (is_term_opt && num_normal > 0)
11390 continue;
11391 match = FALSE;
11392 if (vim_regexec(regmatch, str, (colnr_T)0)
11393 || (options[opt_idx].shortname != NULL
11394 && vim_regexec(regmatch,
11395 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11396 match = TRUE;
11397 else if (is_term_opt)
11398 {
11399 name_buf[0] = '<';
11400 name_buf[1] = 't';
11401 name_buf[2] = '_';
11402 name_buf[3] = str[2];
11403 name_buf[4] = str[3];
11404 name_buf[5] = '>';
11405 name_buf[6] = NUL;
11406 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11407 {
11408 match = TRUE;
11409 str = name_buf;
11410 }
11411 }
11412 if (match)
11413 {
11414 if (loop == 0)
11415 {
11416 if (is_term_opt)
11417 num_term++;
11418 else
11419 num_normal++;
11420 }
11421 else
11422 (*file)[count++] = vim_strsave(str);
11423 }
11424 }
11425 /*
11426 * Check terminal key codes, these are not in the option table
11427 */
11428 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11429 {
11430 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11431 {
11432 if (!isprint(str[0]) || !isprint(str[1]))
11433 continue;
11434
11435 name_buf[0] = 't';
11436 name_buf[1] = '_';
11437 name_buf[2] = str[0];
11438 name_buf[3] = str[1];
11439 name_buf[4] = NUL;
11440
11441 match = FALSE;
11442 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11443 match = TRUE;
11444 else
11445 {
11446 name_buf[0] = '<';
11447 name_buf[1] = 't';
11448 name_buf[2] = '_';
11449 name_buf[3] = str[0];
11450 name_buf[4] = str[1];
11451 name_buf[5] = '>';
11452 name_buf[6] = NUL;
11453
11454 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11455 match = TRUE;
11456 }
11457 if (match)
11458 {
11459 if (loop == 0)
11460 num_term++;
11461 else
11462 (*file)[count++] = vim_strsave(name_buf);
11463 }
11464 }
11465
11466 /*
11467 * Check special key names.
11468 */
11469 regmatch->rm_ic = TRUE; /* ignore case here */
11470 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11471 {
11472 name_buf[0] = '<';
11473 STRCPY(name_buf + 1, str);
11474 STRCAT(name_buf, ">");
11475
11476 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11477 {
11478 if (loop == 0)
11479 num_term++;
11480 else
11481 (*file)[count++] = vim_strsave(name_buf);
11482 }
11483 }
11484 }
11485 if (loop == 0)
11486 {
11487 if (num_normal > 0)
11488 *num_file = num_normal;
11489 else if (num_term > 0)
11490 *num_file = num_term;
11491 else
11492 return OK;
11493 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11494 if (*file == NULL)
11495 {
11496 *file = (char_u **)"";
11497 return FAIL;
11498 }
11499 }
11500 }
11501 return OK;
11502}
11503
11504 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011505ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011506{
11507 char_u *var = NULL; /* init for GCC */
11508 char_u *buf;
11509
11510 *num_file = 0;
11511 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11512 if (*file == NULL)
11513 return FAIL;
11514
11515 /*
11516 * For a terminal key code expand_option_idx is < 0.
11517 */
11518 if (expand_option_idx < 0)
11519 {
11520 var = find_termcode(expand_option_name + 2);
11521 if (var == NULL)
11522 expand_option_idx = findoption(expand_option_name);
11523 }
11524
11525 if (expand_option_idx >= 0)
11526 {
11527 /* put string of option value in NameBuff */
11528 option_value2string(&options[expand_option_idx], expand_option_flags);
11529 var = NameBuff;
11530 }
11531 else if (var == NULL)
11532 var = (char_u *)"";
11533
11534 /* A backslash is required before some characters. This is the reverse of
11535 * what happens in do_set(). */
11536 buf = vim_strsave_escaped(var, escape_chars);
11537
11538 if (buf == NULL)
11539 {
11540 vim_free(*file);
11541 *file = NULL;
11542 return FAIL;
11543 }
11544
11545#ifdef BACKSLASH_IN_FILENAME
11546 /* For MS-Windows et al. we don't double backslashes at the start and
11547 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011548 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011549 if (var[0] == '\\' && var[1] == '\\'
11550 && expand_option_idx >= 0
11551 && (options[expand_option_idx].flags & P_EXPAND)
11552 && vim_isfilec(var[2])
11553 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011554 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011555#endif
11556
11557 *file[0] = buf;
11558 *num_file = 1;
11559 return OK;
11560}
11561#endif
11562
11563/*
11564 * Get the value for the numeric or string option *opp in a nice format into
11565 * NameBuff[]. Must not be called with a hidden option!
11566 */
11567 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011568option_value2string(
11569 struct vimoption *opp,
11570 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011571{
11572 char_u *varp;
11573
11574 varp = get_varp_scope(opp, opt_flags);
11575
11576 if (opp->flags & P_NUM)
11577 {
11578 long wc = 0;
11579
11580 if (wc_use_keyname(varp, &wc))
11581 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11582 else if (wc != 0)
11583 STRCPY(NameBuff, transchar((int)wc));
11584 else
11585 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11586 }
11587 else /* P_STRING */
11588 {
11589 varp = *(char_u **)(varp);
11590 if (varp == NULL) /* just in case */
11591 NameBuff[0] = NUL;
11592#ifdef FEAT_CRYPT
11593 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011594 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011595 STRCPY(NameBuff, "*****");
11596#endif
11597 else if (opp->flags & P_EXPAND)
11598 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11599 /* Translate 'pastetoggle' into special key names */
11600 else if ((char_u **)opp->var == &p_pt)
11601 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11602 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011603 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011604 }
11605}
11606
11607/*
11608 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11609 * printed as a keyname.
11610 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11611 */
11612 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011613wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011614{
11615 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11616 {
11617 *wcp = *(long *)varp;
11618 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11619 return TRUE;
11620 }
11621 return FALSE;
11622}
11623
Bram Moolenaar01615492015-02-03 13:00:38 +010011624#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011625/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011626 * Any character has an equivalent 'langmap' character. This is used for
11627 * keyboards that have a special language mode that sends characters above
11628 * 128 (although other characters can be translated too). The "to" field is a
11629 * Vim command character. This avoids having to switch the keyboard back to
11630 * ASCII mode when leaving Insert mode.
11631 *
11632 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11633 * commands.
11634 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11635 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11636 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011637 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011638# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011639/*
11640 * With multi-byte support use growarray for 'langmap' chars >= 256
11641 */
11642typedef struct
11643{
11644 int from;
11645 int to;
11646} langmap_entry_T;
11647
11648static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011649static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011650
11651/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011652 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11653 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011654 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011655 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011656langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011657{
11658 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011659 int a = 0;
11660 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011661
11662 /* Do a binary search for an existing entry. */
11663 while (a != b)
11664 {
11665 int i = (a + b) / 2;
11666 int d = entries[i].from - from;
11667
11668 if (d == 0)
11669 {
11670 entries[i].to = to;
11671 return;
11672 }
11673 if (d < 0)
11674 a = i + 1;
11675 else
11676 b = i;
11677 }
11678
11679 if (ga_grow(&langmap_mapga, 1) != OK)
11680 return; /* out of memory */
11681
11682 /* insert new entry at position "a" */
11683 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11684 mch_memmove(entries + 1, entries,
11685 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11686 ++langmap_mapga.ga_len;
11687 entries[0].from = from;
11688 entries[0].to = to;
11689}
11690
11691/*
11692 * Apply 'langmap' to multi-byte character "c" and return the result.
11693 */
11694 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011695langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011696{
11697 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11698 int a = 0;
11699 int b = langmap_mapga.ga_len;
11700
11701 while (a != b)
11702 {
11703 int i = (a + b) / 2;
11704 int d = entries[i].from - c;
11705
11706 if (d == 0)
11707 return entries[i].to; /* found matching entry */
11708 if (d < 0)
11709 a = i + 1;
11710 else
11711 b = i;
11712 }
11713 return c; /* no entry found, return "c" unmodified */
11714}
11715# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011716
11717 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011718langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011719{
11720 int i;
11721
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011722 for (i = 0; i < 256; i++)
11723 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11724# ifdef FEAT_MBYTE
11725 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11726# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011727}
11728
11729/*
11730 * Called when langmap option is set; the language map can be
11731 * changed at any time!
11732 */
11733 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011734langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011735{
11736 char_u *p;
11737 char_u *p2;
11738 int from, to;
11739
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011740#ifdef FEAT_MBYTE
11741 ga_clear(&langmap_mapga); /* clear the previous map first */
11742#endif
11743 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011744
11745 for (p = p_langmap; p[0] != NUL; )
11746 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011747 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11748 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011749 {
11750 if (p2[0] == '\\' && p2[1] != NUL)
11751 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752 }
11753 if (p2[0] == ';')
11754 ++p2; /* abcd;ABCD form, p2 points to A */
11755 else
11756 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11757 while (p[0])
11758 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011759 if (p[0] == ',')
11760 {
11761 ++p;
11762 break;
11763 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011764 if (p[0] == '\\' && p[1] != NUL)
11765 ++p;
11766#ifdef FEAT_MBYTE
11767 from = (*mb_ptr2char)(p);
11768#else
11769 from = p[0];
11770#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011771 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011772 if (p2 == NULL)
11773 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011774 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011775 if (p[0] != ',')
11776 {
11777 if (p[0] == '\\')
11778 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011779#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011780 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011782 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011783#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011784 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011785 }
11786 else
11787 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011788 if (p2[0] != ',')
11789 {
11790 if (p2[0] == '\\')
11791 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011792#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011793 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011795 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011796#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011797 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011798 }
11799 if (to == NUL)
11800 {
11801 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11802 transchar(from));
11803 return;
11804 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011805
11806#ifdef FEAT_MBYTE
11807 if (from >= 256)
11808 langmap_set_entry(from, to);
11809 else
11810#endif
11811 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011812
11813 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011814 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011815 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011816 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011817 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011818 if (*p == ';')
11819 {
11820 p = p2;
11821 if (p[0] != NUL)
11822 {
11823 if (p[0] != ',')
11824 {
11825 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11826 return;
11827 }
11828 ++p;
11829 }
11830 break;
11831 }
11832 }
11833 }
11834 }
11835}
11836#endif
11837
11838/*
11839 * Return TRUE if format option 'x' is in effect.
11840 * Take care of no formatting when 'paste' is set.
11841 */
11842 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011843has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011844{
11845 if (p_paste)
11846 return FALSE;
11847 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11848}
11849
11850/*
11851 * Return TRUE if "x" is present in 'shortmess' option, or
11852 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11853 */
11854 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011855shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011856{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011857 return p_shm != NULL &&
11858 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011859 || (vim_strchr(p_shm, 'a') != NULL
11860 && vim_strchr((char_u *)SHM_A, x) != NULL));
11861}
11862
11863/*
11864 * paste_option_changed() - Called after p_paste was set or reset.
11865 */
11866 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011867paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868{
11869 static int old_p_paste = FALSE;
11870 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011871 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011872#ifdef FEAT_CMDL_INFO
11873 static int save_ru = 0;
11874#endif
11875#ifdef FEAT_RIGHTLEFT
11876 static int save_ri = 0;
11877 static int save_hkmap = 0;
11878#endif
11879 buf_T *buf;
11880
11881 if (p_paste)
11882 {
11883 /*
11884 * Paste switched from off to on.
11885 * Save the current values, so they can be restored later.
11886 */
11887 if (!old_p_paste)
11888 {
11889 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011890 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011891 {
11892 buf->b_p_tw_nopaste = buf->b_p_tw;
11893 buf->b_p_wm_nopaste = buf->b_p_wm;
11894 buf->b_p_sts_nopaste = buf->b_p_sts;
11895 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011896 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011897 }
11898
11899 /* save global options */
11900 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011901 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902#ifdef FEAT_CMDL_INFO
11903 save_ru = p_ru;
11904#endif
11905#ifdef FEAT_RIGHTLEFT
11906 save_ri = p_ri;
11907 save_hkmap = p_hkmap;
11908#endif
11909 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011910 p_ai_nopaste = p_ai;
11911 p_et_nopaste = p_et;
11912 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011913 p_tw_nopaste = p_tw;
11914 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011915 }
11916
11917 /*
11918 * Always set the option values, also when 'paste' is set when it is
11919 * already on.
11920 */
11921 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011922 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011923 {
11924 buf->b_p_tw = 0; /* textwidth is 0 */
11925 buf->b_p_wm = 0; /* wrapmargin is 0 */
11926 buf->b_p_sts = 0; /* softtabstop is 0 */
11927 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011928 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011929 }
11930
11931 /* set global options */
11932 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011933 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011934#ifdef FEAT_CMDL_INFO
11935# ifdef FEAT_WINDOWS
11936 if (p_ru)
11937 status_redraw_all(); /* redraw to remove the ruler */
11938# endif
11939 p_ru = 0; /* no ruler */
11940#endif
11941#ifdef FEAT_RIGHTLEFT
11942 p_ri = 0; /* no reverse insert */
11943 p_hkmap = 0; /* no Hebrew keyboard */
11944#endif
11945 /* set global values for local buffer options */
11946 p_tw = 0;
11947 p_wm = 0;
11948 p_sts = 0;
11949 p_ai = 0;
11950 }
11951
11952 /*
11953 * Paste switched from on to off: Restore saved values.
11954 */
11955 else if (old_p_paste)
11956 {
11957 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011958 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011959 {
11960 buf->b_p_tw = buf->b_p_tw_nopaste;
11961 buf->b_p_wm = buf->b_p_wm_nopaste;
11962 buf->b_p_sts = buf->b_p_sts_nopaste;
11963 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011964 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965 }
11966
11967 /* restore global options */
11968 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011969 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011970#ifdef FEAT_CMDL_INFO
11971# ifdef FEAT_WINDOWS
11972 if (p_ru != save_ru)
11973 status_redraw_all(); /* redraw to draw the ruler */
11974# endif
11975 p_ru = save_ru;
11976#endif
11977#ifdef FEAT_RIGHTLEFT
11978 p_ri = save_ri;
11979 p_hkmap = save_hkmap;
11980#endif
11981 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011982 p_ai = p_ai_nopaste;
11983 p_et = p_et_nopaste;
11984 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985 p_tw = p_tw_nopaste;
11986 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011987 }
11988
11989 old_p_paste = p_paste;
11990}
11991
11992/*
11993 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11994 *
11995 * Reset 'compatible' and set the values for options that didn't get set yet
11996 * to the Vim defaults.
11997 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011998 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999 */
12000 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012001vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012002{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012003 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012004 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012005 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012006
12007 if (!option_was_set((char_u *)"cp"))
12008 {
12009 p_cp = FALSE;
12010 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12011 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12012 set_option_default(opt_idx, OPT_FREE, FALSE);
12013 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012014 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012015 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012016
12017 if (fname != NULL)
12018 {
12019 p = vim_getenv(envname, &dofree);
12020 if (p == NULL)
12021 {
12022 /* Set $MYVIMRC to the first vimrc file found. */
12023 p = FullName_save(fname, FALSE);
12024 if (p != NULL)
12025 {
12026 vim_setenv(envname, p);
12027 vim_free(p);
12028 }
12029 }
12030 else if (dofree)
12031 vim_free(p);
12032 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012033}
12034
12035/*
12036 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12037 */
12038 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012039change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012040{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012041 int opt_idx;
12042
Bram Moolenaar071d4272004-06-13 20:20:40 +000012043 if (p_cp != on)
12044 {
12045 p_cp = on;
12046 compatible_set();
12047 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012048 opt_idx = findoption((char_u *)"cp");
12049 if (opt_idx >= 0)
12050 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012051}
12052
12053/*
12054 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012055 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056 */
12057 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012058option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012059{
12060 int idx;
12061
12062 idx = findoption(name);
12063 if (idx < 0) /* unknown option */
12064 return FALSE;
12065 if (options[idx].flags & P_WAS_SET)
12066 return TRUE;
12067 return FALSE;
12068}
12069
12070/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012071 * Reset the flag indicating option "name" was set.
12072 */
12073 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012074reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012075{
12076 int idx = findoption(name);
12077
12078 if (idx >= 0)
12079 options[idx].flags &= ~P_WAS_SET;
12080}
12081
12082/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012083 * compatible_set() - Called when 'compatible' has been set or unset.
12084 *
12085 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12086 * flag) to a Vi compatible value.
12087 * When 'compatible' is unset: Set all options that have a different default
12088 * for Vim (without the P_VI_DEF flag) to that default.
12089 */
12090 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012091compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092{
12093 int opt_idx;
12094
12095 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12096 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12097 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12098 set_option_default(opt_idx, OPT_FREE, p_cp);
12099 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012100 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012101}
12102
12103#ifdef FEAT_LINEBREAK
12104
12105# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12106 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012107 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108# endif
12109
12110/*
12111 * fill_breakat_flags() -- called when 'breakat' changes value.
12112 */
12113 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012114fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012115{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012116 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012117 int i;
12118
12119 for (i = 0; i < 256; i++)
12120 breakat_flags[i] = FALSE;
12121
12122 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012123 for (p = p_breakat; *p; p++)
12124 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012125}
12126
12127# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012128 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012129# endif
12130
12131#endif
12132
12133/*
12134 * Check an option that can be a range of string values.
12135 *
12136 * Return OK for correct value, FAIL otherwise.
12137 * Empty is always OK.
12138 */
12139 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012140check_opt_strings(
12141 char_u *val,
12142 char **values,
12143 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012144{
12145 return opt_strings_flags(val, values, NULL, list);
12146}
12147
12148/*
12149 * Handle an option that can be a range of string values.
12150 * Set a flag in "*flagp" for each string present.
12151 *
12152 * Return OK for correct value, FAIL otherwise.
12153 * Empty is always OK.
12154 */
12155 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012156opt_strings_flags(
12157 char_u *val, /* new value */
12158 char **values, /* array of valid string values */
12159 unsigned *flagp,
12160 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161{
12162 int i;
12163 int len;
12164 unsigned new_flags = 0;
12165
12166 while (*val)
12167 {
12168 for (i = 0; ; ++i)
12169 {
12170 if (values[i] == NULL) /* val not found in values[] */
12171 return FAIL;
12172
12173 len = (int)STRLEN(values[i]);
12174 if (STRNCMP(values[i], val, len) == 0
12175 && ((list && val[len] == ',') || val[len] == NUL))
12176 {
12177 val += len + (val[len] == ',');
12178 new_flags |= (1 << i);
12179 break; /* check next item in val list */
12180 }
12181 }
12182 }
12183 if (flagp != NULL)
12184 *flagp = new_flags;
12185
12186 return OK;
12187}
12188
12189/*
12190 * Read the 'wildmode' option, fill wim_flags[].
12191 */
12192 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012193check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012194{
12195 char_u new_wim_flags[4];
12196 char_u *p;
12197 int i;
12198 int idx = 0;
12199
12200 for (i = 0; i < 4; ++i)
12201 new_wim_flags[i] = 0;
12202
12203 for (p = p_wim; *p; ++p)
12204 {
12205 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12206 ;
12207 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12208 return FAIL;
12209 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12210 new_wim_flags[idx] |= WIM_LONGEST;
12211 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12212 new_wim_flags[idx] |= WIM_FULL;
12213 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12214 new_wim_flags[idx] |= WIM_LIST;
12215 else
12216 return FAIL;
12217 p += i;
12218 if (*p == NUL)
12219 break;
12220 if (*p == ',')
12221 {
12222 if (idx == 3)
12223 return FAIL;
12224 ++idx;
12225 }
12226 }
12227
12228 /* fill remaining entries with last flag */
12229 while (idx < 3)
12230 {
12231 new_wim_flags[idx + 1] = new_wim_flags[idx];
12232 ++idx;
12233 }
12234
12235 /* only when there are no errors, wim_flags[] is changed */
12236 for (i = 0; i < 4; ++i)
12237 wim_flags[i] = new_wim_flags[i];
12238 return OK;
12239}
12240
12241/*
12242 * Check if backspacing over something is allowed.
12243 */
12244 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012245can_bs(
12246 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012247{
12248 switch (*p_bs)
12249 {
12250 case '2': return TRUE;
12251 case '1': return (what != BS_START);
12252 case '0': return FALSE;
12253 }
12254 return vim_strchr(p_bs, what) != NULL;
12255}
12256
12257/*
12258 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12259 * the file must be considered changed when the value is different.
12260 */
12261 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012262save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012263{
12264 buf->b_start_ffc = *buf->b_p_ff;
12265 buf->b_start_eol = buf->b_p_eol;
12266#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012267 buf->b_start_bomb = buf->b_p_bomb;
12268
Bram Moolenaar071d4272004-06-13 20:20:40 +000012269 /* Only use free/alloc when necessary, they take time. */
12270 if (buf->b_start_fenc == NULL
12271 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12272 {
12273 vim_free(buf->b_start_fenc);
12274 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12275 }
12276#endif
12277}
12278
12279/*
12280 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12281 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012282 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12283 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012284 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012285 * When "ignore_empty" is true don't consider a new, empty buffer to be
12286 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012287 */
12288 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012289file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012290{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012291 /* In a buffer that was never loaded the options are not valid. */
12292 if (buf->b_flags & BF_NEVERLOADED)
12293 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012294 if (ignore_empty
12295 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012296 && buf->b_ml.ml_line_count == 1
12297 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12298 return FALSE;
12299 if (buf->b_start_ffc != *buf->b_p_ff)
12300 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012301 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012302 return TRUE;
12303#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012304 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12305 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306 if (buf->b_start_fenc == NULL)
12307 return (*buf->b_p_fenc != NUL);
12308 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12309#else
12310 return FALSE;
12311#endif
12312}
12313
12314/*
12315 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12316 */
12317 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012318check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012319{
12320 return check_opt_strings(p, p_ff_values, FALSE);
12321}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012322
12323/*
12324 * Return the effective shiftwidth value for current buffer, using the
12325 * 'tabstop' value when 'shiftwidth' is zero.
12326 */
12327 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012328get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012329{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012330 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012331}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012332
12333/*
12334 * Return the effective softtabstop value for the current buffer, using the
12335 * 'tabstop' value when 'softtabstop' is negative.
12336 */
12337 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012338get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012339{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012340 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012341}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012342
12343/*
12344 * Check matchpairs option for "*initc".
12345 * If there is a match set "*initc" to the matching character and "*findc" to
12346 * the opposite character. Set "*backwards" to the direction.
12347 * When "switchit" is TRUE swap the direction.
12348 */
12349 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012350find_mps_values(
12351 int *initc,
12352 int *findc,
12353 int *backwards,
12354 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012355{
12356 char_u *ptr;
12357
12358 ptr = curbuf->b_p_mps;
12359 while (*ptr != NUL)
12360 {
12361#ifdef FEAT_MBYTE
12362 if (has_mbyte)
12363 {
12364 char_u *prev;
12365
12366 if (mb_ptr2char(ptr) == *initc)
12367 {
12368 if (switchit)
12369 {
12370 *findc = *initc;
12371 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12372 *backwards = TRUE;
12373 }
12374 else
12375 {
12376 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12377 *backwards = FALSE;
12378 }
12379 return;
12380 }
12381 prev = ptr;
12382 ptr += mb_ptr2len(ptr) + 1;
12383 if (mb_ptr2char(ptr) == *initc)
12384 {
12385 if (switchit)
12386 {
12387 *findc = *initc;
12388 *initc = mb_ptr2char(prev);
12389 *backwards = FALSE;
12390 }
12391 else
12392 {
12393 *findc = mb_ptr2char(prev);
12394 *backwards = TRUE;
12395 }
12396 return;
12397 }
12398 ptr += mb_ptr2len(ptr);
12399 }
12400 else
12401#endif
12402 {
12403 if (*ptr == *initc)
12404 {
12405 if (switchit)
12406 {
12407 *backwards = TRUE;
12408 *findc = *initc;
12409 *initc = ptr[2];
12410 }
12411 else
12412 {
12413 *backwards = FALSE;
12414 *findc = ptr[2];
12415 }
12416 return;
12417 }
12418 ptr += 2;
12419 if (*ptr == *initc)
12420 {
12421 if (switchit)
12422 {
12423 *backwards = FALSE;
12424 *findc = *initc;
12425 *initc = ptr[-2];
12426 }
12427 else
12428 {
12429 *backwards = TRUE;
12430 *findc = ptr[-2];
12431 }
12432 return;
12433 }
12434 ++ptr;
12435 }
12436 if (*ptr == ',')
12437 ++ptr;
12438 }
12439}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012440
12441#if defined(FEAT_LINEBREAK) || defined(PROTO)
12442/*
12443 * This is called when 'breakindentopt' is changed and when a window is
12444 * initialized.
12445 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012446 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012447briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012448{
12449 char_u *p;
12450 int bri_shift = 0;
12451 long bri_min = 20;
12452 int bri_sbr = FALSE;
12453
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012454 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012455 while (*p != NUL)
12456 {
12457 if (STRNCMP(p, "shift:", 6) == 0
12458 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12459 {
12460 p += 6;
12461 bri_shift = getdigits(&p);
12462 }
12463 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12464 {
12465 p += 4;
12466 bri_min = getdigits(&p);
12467 }
12468 else if (STRNCMP(p, "sbr", 3) == 0)
12469 {
12470 p += 3;
12471 bri_sbr = TRUE;
12472 }
12473 if (*p != ',' && *p != NUL)
12474 return FAIL;
12475 if (*p == ',')
12476 ++p;
12477 }
12478
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012479 wp->w_p_brishift = bri_shift;
12480 wp->w_p_brimin = bri_min;
12481 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012482
12483 return OK;
12484}
12485#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012486
12487/*
12488 * Get the local or global value of 'backupcopy'.
12489 */
12490 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012491get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012492{
12493 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12494}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012495
12496#if defined(FEAT_SIGNS) || defined(PROTO)
12497/*
12498 * Return TRUE when window "wp" has a column to draw signs in.
12499 */
12500 int
12501signcolumn_on(win_T *wp)
12502{
12503 if (*wp->w_p_scl == 'n')
12504 return FALSE;
12505 if (*wp->w_p_scl == 'y')
12506 return TRUE;
12507 return (wp->w_buffer->b_signlist != NULL
12508# ifdef FEAT_NETBEANS_INTG
12509 || wp->w_buffer->b_has_sign_column
12510# endif
12511 );
12512}
12513#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012514
12515#if defined(FEAT_EVAL) || defined(PROTO)
12516/*
12517 * Get window or buffer local options.
12518 */
12519 dict_T *
12520get_winbuf_options(int bufopt)
12521{
12522 dict_T *d;
12523 int opt_idx;
12524
12525 d = dict_alloc();
12526 if (d == NULL)
12527 return NULL;
12528
12529 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12530 {
12531 struct vimoption *opt = &options[opt_idx];
12532
12533 if ((bufopt && (opt->indir & PV_BUF))
12534 || (!bufopt && (opt->indir & PV_WIN)))
12535 {
12536 char_u *varp = get_varp(opt);
12537
12538 if (varp != NULL)
12539 {
12540 if (opt->flags & P_STRING)
12541 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012542 else if (opt->flags & P_NUM)
12543 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012544 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012545 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012546 }
12547 }
12548 }
12549
12550 return d;
12551}
12552#endif