blob: 459179e2e1b5f37f3ee7f75b9c5dc53428908f17 [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 Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100563#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100565 {(char_u *)FALSE, (char_u *)0L}
566#else
567 (char_u *)NULL, PV_NONE,
568 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +0100570 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autoindent", "ai", P_BOOL|P_VI_DEF,
572 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000573 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autoprint", "ap", P_BOOL|P_VI_DEF,
575 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000576 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000578 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000579 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"autowrite", "aw", P_BOOL|P_VI_DEF,
581 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"autowriteall","awa", P_BOOL|P_VI_DEF,
584 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000585 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
587 (char_u *)&p_bg, PV_NONE,
588 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100589#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 (char_u *)"dark",
591#else
592 (char_u *)"light",
593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000594 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200595 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000596 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000597 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000598 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
599 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000600 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200601 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200602 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000603#ifdef UNIX
604 {(char_u *)"yes", (char_u *)"auto"}
605#else
606 {(char_u *)"auto", (char_u *)"auto"}
607#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200609 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
610 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000612 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000613 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000614 (char_u *)&p_bex, PV_NONE,
615 {
616#ifdef VMS
617 (char_u *)"_",
618#else
619 (char_u *)"~",
620#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000621 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200622 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000623#ifdef FEAT_WILDIGN
624 (char_u *)&p_bsk, PV_NONE,
625 {(char_u *)"", (char_u *)0L}
626#else
627 (char_u *)NULL, PV_NONE,
628 {(char_u *)0L, (char_u *)0L}
629#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000630 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100632#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100634 {(char_u *)600L, (char_u *)0L}
635#else
636 (char_u *)NULL, PV_NONE,
637 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000638#endif
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100639 SCRIPTID_INIT},
640 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
641#ifdef FEAT_BEVAL
642 (char_u *)&p_beval, PV_NONE,
643 {(char_u *)FALSE, (char_u *)0L}
644#else
645 (char_u *)NULL, PV_NONE,
646 {(char_u *)0L, (char_u *)0L}
647#endif
648 SCRIPTID_INIT},
649 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
650#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
651 (char_u *)&p_bexpr, PV_BEXPR,
652 {(char_u *)"", (char_u *)0L}
653#else
654 (char_u *)NULL, PV_NONE,
655 {(char_u *)0L, (char_u *)0L}
656#endif
657 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000658 {"beautify", "bf", P_BOOL|P_VI_DEF,
659 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000660 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200661 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
662 (char_u *)&p_bo, PV_NONE,
663 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
665 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000666 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000669 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
671#ifdef FEAT_MBYTE
672 (char_u *)&p_bomb, PV_BOMB,
673#else
674 (char_u *)NULL, PV_NONE,
675#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000676 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
678#ifdef FEAT_LINEBREAK
679 (char_u *)&p_breakat, PV_NONE,
680 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
681#else
682 (char_u *)NULL, PV_NONE,
683 {(char_u *)0L, (char_u *)0L}
684#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000685 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200686 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
687#ifdef FEAT_LINEBREAK
688 (char_u *)VAR_WIN, PV_BRI,
689 {(char_u *)FALSE, (char_u *)0L}
690#else
691 (char_u *)NULL, PV_NONE,
692 {(char_u *)0L, (char_u *)0L}
693#endif
694 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200695 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
696 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200697#ifdef FEAT_LINEBREAK
698 (char_u *)VAR_WIN, PV_BRIOPT,
699 {(char_u *)"", (char_u *)NULL}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)"", (char_u *)NULL}
703#endif
704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
706#ifdef FEAT_BROWSE
707 (char_u *)&p_bsdir, PV_NONE,
708 {(char_u *)"last", (char_u *)0L}
709#else
710 (char_u *)NULL, PV_NONE,
711 {(char_u *)0L, (char_u *)0L}
712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000713 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
715#if defined(FEAT_QUICKFIX)
716 (char_u *)&p_bh, PV_BH,
717 {(char_u *)"", (char_u *)0L}
718#else
719 (char_u *)NULL, PV_NONE,
720 {(char_u *)0L, (char_u *)0L}
721#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000722 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
724 (char_u *)&p_bl, PV_BL,
725 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
728#if defined(FEAT_QUICKFIX)
729 (char_u *)&p_bt, PV_BT,
730 {(char_u *)"", (char_u *)0L}
731#else
732 (char_u *)NULL, PV_NONE,
733 {(char_u *)0L, (char_u *)0L}
734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000735 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200736 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000737#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738 (char_u *)&p_cmp, PV_NONE,
739 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000740#else
741 (char_u *)NULL, PV_NONE,
742 {(char_u *)0L, (char_u *)0L}
743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000744 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
746#ifdef FEAT_SEARCHPATH
747 (char_u *)&p_cdpath, PV_NONE,
748 {(char_u *)",,", (char_u *)0L}
749#else
750 (char_u *)NULL, PV_NONE,
751 {(char_u *)0L, (char_u *)0L}
752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754 {"cedit", NULL, P_STRING,
755#ifdef FEAT_CMDWIN
756 (char_u *)&p_cedit, PV_NONE,
757 {(char_u *)"", (char_u *)CTRL_F_STR}
758#else
759 (char_u *)NULL, PV_NONE,
760 {(char_u *)0L, (char_u *)0L}
761#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000762 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000763 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
764#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
765 (char_u *)&p_ccv, PV_NONE,
766 {(char_u *)"", (char_u *)0L}
767#else
768 (char_u *)NULL, PV_NONE,
769 {(char_u *)0L, (char_u *)0L}
770#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000771 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000772 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
773#ifdef FEAT_CINDENT
774 (char_u *)&p_cin, PV_CIN,
775#else
776 (char_u *)NULL, PV_NONE,
777#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000778 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200779 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780#ifdef FEAT_CINDENT
781 (char_u *)&p_cink, PV_CINK,
782 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
783#else
784 (char_u *)NULL, PV_NONE,
785 {(char_u *)0L, (char_u *)0L}
786#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000787 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200788 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000789#ifdef FEAT_CINDENT
790 (char_u *)&p_cino, PV_CINO,
791#else
792 (char_u *)NULL, PV_NONE,
793#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000794 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200795 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000796#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
797 (char_u *)&p_cinw, PV_CINW,
798 {(char_u *)"if,else,while,do,for,switch",
799 (char_u *)0L}
800#else
801 (char_u *)NULL, PV_NONE,
802 {(char_u *)0L, (char_u *)0L}
803#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000804 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200805 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806#ifdef FEAT_CLIPBOARD
807 (char_u *)&p_cb, PV_NONE,
808# ifdef FEAT_XCLIPBOARD
809 {(char_u *)"autoselect,exclude:cons\\|linux",
810 (char_u *)0L}
811# else
812 {(char_u *)"", (char_u *)0L}
813# endif
814#else
815 (char_u *)NULL, PV_NONE,
816 {(char_u *)"", (char_u *)0L}
817#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000818 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
820 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000821 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
823#ifdef FEAT_CMDWIN
824 (char_u *)&p_cwh, PV_NONE,
825#else
826 (char_u *)NULL, PV_NONE,
827#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000828 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200829 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200830#ifdef FEAT_SYN_HL
831 (char_u *)VAR_WIN, PV_CC,
832#else
833 (char_u *)NULL, PV_NONE,
834#endif
835 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
837 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000838 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200839 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
840 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841#ifdef FEAT_COMMENTS
842 (char_u *)&p_com, PV_COM,
843 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
844 (char_u *)0L}
845#else
846 (char_u *)NULL, PV_NONE,
847 {(char_u *)0L, (char_u *)0L}
848#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000849 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200850 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000851#ifdef FEAT_FOLDING
852 (char_u *)&p_cms, PV_CMS,
853 {(char_u *)"/*%s*/", (char_u *)0L}
854#else
855 (char_u *)NULL, PV_NONE,
856 {(char_u *)0L, (char_u *)0L}
857#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000858 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000859 /* P_PRI_MKRC isn't needed here, optval_default()
860 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000861 {"compatible", "cp", P_BOOL|P_RALL,
862 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000863 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200864 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000865#ifdef FEAT_INS_EXPAND
866 (char_u *)&p_cpt, PV_CPT,
867 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
868#else
869 (char_u *)NULL, PV_NONE,
870 {(char_u *)0L, (char_u *)0L}
871#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000872 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200873 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200874#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200875 (char_u *)VAR_WIN, PV_COCU,
876 {(char_u *)"", (char_u *)NULL}
877#else
878 (char_u *)NULL, PV_NONE,
879 {(char_u *)NULL, (char_u *)0L}
880#endif
881 SCRIPTID_INIT},
882 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
883#ifdef FEAT_CONCEAL
884 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200885#else
886 (char_u *)NULL, PV_NONE,
887#endif
888 {(char_u *)0L, (char_u *)0L}
889 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000890 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
891#ifdef FEAT_COMPL_FUNC
892 (char_u *)&p_cfu, PV_CFU,
893 {(char_u *)"", (char_u *)0L}
894#else
895 (char_u *)NULL, PV_NONE,
896 {(char_u *)0L, (char_u *)0L}
897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000898 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200899 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000900#ifdef FEAT_INS_EXPAND
901 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000902 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000903#else
904 (char_u *)NULL, PV_NONE,
905 {(char_u *)0L, (char_u *)0L}
906#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000907 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908 {"confirm", "cf", P_BOOL|P_VI_DEF,
909#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
910 (char_u *)&p_confirm, PV_NONE,
911#else
912 (char_u *)NULL, PV_NONE,
913#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000914 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000915 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000917 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000918 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
919 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000920 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
922 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000923 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
924 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200925 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200926#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200927 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200928 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200929#else
930 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200931 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200932#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200933 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
935#ifdef FEAT_CSCOPE
936 (char_u *)&p_cspc, PV_NONE,
937#else
938 (char_u *)NULL, PV_NONE,
939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000940 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000941 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
942#ifdef FEAT_CSCOPE
943 (char_u *)&p_csprg, PV_NONE,
944 {(char_u *)"cscope", (char_u *)0L}
945#else
946 (char_u *)NULL, PV_NONE,
947 {(char_u *)0L, (char_u *)0L}
948#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000949 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200950 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000951#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
952 (char_u *)&p_csqf, PV_NONE,
953 {(char_u *)"", (char_u *)0L}
954#else
955 (char_u *)NULL, PV_NONE,
956 {(char_u *)0L, (char_u *)0L}
957#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000958 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200959 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
960#ifdef FEAT_CSCOPE
961 (char_u *)&p_csre, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
965 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
967#ifdef FEAT_CSCOPE
968 (char_u *)&p_cst, PV_NONE,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000972 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000973 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
974#ifdef FEAT_CSCOPE
975 (char_u *)&p_csto, PV_NONE,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000979 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000980 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
981#ifdef FEAT_CSCOPE
982 (char_u *)&p_csverbose, PV_NONE,
983#else
984 (char_u *)NULL, PV_NONE,
985#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000986 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200987 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
988#ifdef FEAT_CURSORBIND
989 (char_u *)VAR_WIN, PV_CRBIND,
990#else
991 (char_u *)NULL, PV_NONE,
992#endif
993 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000994 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
995#ifdef FEAT_SYN_HL
996 (char_u *)VAR_WIN, PV_CUC,
997#else
998 (char_u *)NULL, PV_NONE,
999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001000 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +01001001 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001002#ifdef FEAT_SYN_HL
1003 (char_u *)VAR_WIN, PV_CUL,
1004#else
1005 (char_u *)NULL, PV_NONE,
1006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001007 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008 {"debug", NULL, P_STRING|P_VI_DEF,
1009 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001010 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001011 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001013 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001014 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015#else
1016 (char_u *)NULL, PV_NONE,
1017 {(char_u *)NULL, (char_u *)0L}
1018#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001019 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1021#ifdef FEAT_MBYTE
1022 (char_u *)&p_deco, PV_NONE,
1023#else
1024 (char_u *)NULL, PV_NONE,
1025#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001026 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001027 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001028#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001029 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030#else
1031 (char_u *)NULL, PV_NONE,
1032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001033 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1035#ifdef FEAT_DIFF
1036 (char_u *)VAR_WIN, PV_DIFF,
1037#else
1038 (char_u *)NULL, PV_NONE,
1039#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001040 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001041 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1043 (char_u *)&p_dex, PV_NONE,
1044 {(char_u *)"", (char_u *)0L}
1045#else
1046 (char_u *)NULL, PV_NONE,
1047 {(char_u *)0L, (char_u *)0L}
1048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001049 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001050 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1051 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052#ifdef FEAT_DIFF
1053 (char_u *)&p_dip, PV_NONE,
1054 {(char_u *)"filler", (char_u *)NULL}
1055#else
1056 (char_u *)NULL, PV_NONE,
1057 {(char_u *)"", (char_u *)NULL}
1058#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001059 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1061#ifdef FEAT_DIGRAPHS
1062 (char_u *)&p_dg, PV_NONE,
1063#else
1064 (char_u *)NULL, PV_NONE,
1065#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001066 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001067 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1068 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001070 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001071 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001073 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001075#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 (char_u *)&p_ead, PV_NONE,
1077 {(char_u *)"both", (char_u *)0L}
1078#else
1079 (char_u *)NULL, PV_NONE,
1080 {(char_u *)NULL, (char_u *)0L}
1081#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001082 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1084 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001086 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1087#if defined(FEAT_MBYTE)
1088 (char_u *)&p_emoji, PV_NONE,
1089 {(char_u *)TRUE, (char_u *)0L}
1090#else
1091 (char_u *)NULL, PV_NONE,
1092 {(char_u *)0L, (char_u *)0L}
1093#endif
1094 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001095 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096#ifdef FEAT_MBYTE
1097 (char_u *)&p_enc, PV_NONE,
1098 {(char_u *)ENC_DFLT, (char_u *)0L}
1099#else
1100 (char_u *)NULL, PV_NONE,
1101 {(char_u *)0L, (char_u *)0L}
1102#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001103 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1105 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1108 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001109 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001111 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001112 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1114 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1117#ifdef FEAT_QUICKFIX
1118 (char_u *)&p_ef, PV_NONE,
1119 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1120#else
1121 (char_u *)NULL, PV_NONE,
1122 {(char_u *)NULL, (char_u *)0L}
1123#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001125 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001127 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001128 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129#else
1130 (char_u *)NULL, PV_NONE,
1131 {(char_u *)NULL, (char_u *)0L}
1132#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001133 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134 {"esckeys", "ek", P_BOOL|P_VIM,
1135 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001136 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001137 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001138#ifdef FEAT_AUTOCMD
1139 (char_u *)&p_ei, PV_NONE,
1140#else
1141 (char_u *)NULL, PV_NONE,
1142#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001143 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001144 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1145 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001146 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1148 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001149 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001150 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1151 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001152#ifdef FEAT_MBYTE
1153 (char_u *)&p_fenc, PV_FENC,
1154 {(char_u *)"", (char_u *)0L}
1155#else
1156 (char_u *)NULL, PV_NONE,
1157 {(char_u *)0L, (char_u *)0L}
1158#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001159 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001160 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161#ifdef FEAT_MBYTE
1162 (char_u *)&p_fencs, PV_NONE,
1163 {(char_u *)"ucs-bom", (char_u *)0L}
1164#else
1165 (char_u *)NULL, PV_NONE,
1166 {(char_u *)0L, (char_u *)0L}
1167#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001168 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001169 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1170 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001171 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001172 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001173 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001174 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001175 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1176 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001177 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1178 (char_u *)&p_fic, PV_NONE,
1179 {
1180#ifdef CASE_INSENSITIVE_FILENAME
1181 (char_u *)TRUE,
1182#else
1183 (char_u *)FALSE,
1184#endif
1185 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001186 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187#ifdef FEAT_AUTOCMD
1188 (char_u *)&p_ft, PV_FT,
1189 {(char_u *)"", (char_u *)0L}
1190#else
1191 (char_u *)NULL, PV_NONE,
1192 {(char_u *)0L, (char_u *)0L}
1193#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001194 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001195 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1197 (char_u *)&p_fcs, PV_NONE,
1198 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1199#else
1200 (char_u *)NULL, PV_NONE,
1201 {(char_u *)"", (char_u *)0L}
1202#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001203 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001204 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1205 (char_u *)&p_fixeol, PV_FIXEOL,
1206 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1208#ifdef FEAT_FKMAP
1209 (char_u *)&p_fkmap, PV_NONE,
1210#else
1211 (char_u *)NULL, PV_NONE,
1212#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001213 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 {"flash", "fl", P_BOOL|P_VI_DEF,
1215 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001216 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001217 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001218#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001220 {(char_u *)"", (char_u *)0L}
1221#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001224#endif
1225 SCRIPTID_INIT},
1226 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1227#ifdef FEAT_FOLDING
1228 (char_u *)VAR_WIN, PV_FDC,
1229 {(char_u *)FALSE, (char_u *)0L}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)NULL, (char_u *)0L}
1233#endif
1234 SCRIPTID_INIT},
1235 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1236#ifdef FEAT_FOLDING
1237 (char_u *)VAR_WIN, PV_FEN,
1238 {(char_u *)TRUE, (char_u *)0L}
1239#else
1240 (char_u *)NULL, PV_NONE,
1241 {(char_u *)NULL, (char_u *)0L}
1242#endif
1243 SCRIPTID_INIT},
1244 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1245#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1246 (char_u *)VAR_WIN, PV_FDE,
1247 {(char_u *)"0", (char_u *)NULL}
1248#else
1249 (char_u *)NULL, PV_NONE,
1250 {(char_u *)NULL, (char_u *)0L}
1251#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001252 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001253 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001254#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001256 {(char_u *)"#", (char_u *)NULL}
1257#else
1258 (char_u *)NULL, PV_NONE,
1259 {(char_u *)NULL, (char_u *)0L}
1260#endif
1261 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001262 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001263#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001265 {(char_u *)0L, (char_u *)0L}
1266#else
1267 (char_u *)NULL, PV_NONE,
1268 {(char_u *)NULL, (char_u *)0L}
1269#endif
1270 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001271 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001272#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001273 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001274 {(char_u *)-1L, (char_u *)0L}
1275#else
1276 (char_u *)NULL, PV_NONE,
1277 {(char_u *)NULL, (char_u *)0L}
1278#endif
1279 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001281 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001282#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001283 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001285#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001286 (char_u *)NULL, PV_NONE,
1287 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001289 SCRIPTID_INIT},
1290 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1291#ifdef FEAT_FOLDING
1292 (char_u *)VAR_WIN, PV_FDM,
1293 {(char_u *)"manual", (char_u *)NULL}
1294#else
1295 (char_u *)NULL, PV_NONE,
1296 {(char_u *)NULL, (char_u *)0L}
1297#endif
1298 SCRIPTID_INIT},
1299 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1300#ifdef FEAT_FOLDING
1301 (char_u *)VAR_WIN, PV_FML,
1302 {(char_u *)1L, (char_u *)0L}
1303#else
1304 (char_u *)NULL, PV_NONE,
1305 {(char_u *)NULL, (char_u *)0L}
1306#endif
1307 SCRIPTID_INIT},
1308 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1309#ifdef FEAT_FOLDING
1310 (char_u *)VAR_WIN, PV_FDN,
1311 {(char_u *)20L, (char_u *)0L}
1312#else
1313 (char_u *)NULL, PV_NONE,
1314 {(char_u *)NULL, (char_u *)0L}
1315#endif
1316 SCRIPTID_INIT},
1317 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1318#ifdef FEAT_FOLDING
1319 (char_u *)&p_fdo, PV_NONE,
1320 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1321 (char_u *)0L}
1322#else
1323 (char_u *)NULL, PV_NONE,
1324 {(char_u *)NULL, (char_u *)0L}
1325#endif
1326 SCRIPTID_INIT},
1327 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1328#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1329 (char_u *)VAR_WIN, PV_FDT,
1330 {(char_u *)"foldtext()", (char_u *)NULL}
1331#else
1332 (char_u *)NULL, PV_NONE,
1333 {(char_u *)NULL, (char_u *)0L}
1334#endif
1335 SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001336 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001337#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001338 (char_u *)&p_fex, PV_FEX,
1339 {(char_u *)"", (char_u *)0L}
1340#else
1341 (char_u *)NULL, PV_NONE,
1342 {(char_u *)0L, (char_u *)0L}
1343#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001344 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001345 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1346 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001347 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1348 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001349 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1350 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001351 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1352 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001354 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001355 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001356 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1357#ifdef HAVE_FSYNC
1358 (char_u *)&p_fs, PV_NONE,
1359 {(char_u *)TRUE, (char_u *)0L}
1360#else
1361 (char_u *)NULL, PV_NONE,
1362 {(char_u *)FALSE, (char_u *)0L}
1363#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001364 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1366 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001367 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368 {"graphic", "gr", P_BOOL|P_VI_DEF,
1369 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001370 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001371 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372#ifdef FEAT_QUICKFIX
1373 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001374 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375#else
1376 (char_u *)NULL, PV_NONE,
1377 {(char_u *)NULL, (char_u *)0L}
1378#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001379 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001380 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1381#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001382 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 {
1384# ifdef WIN3264
1385 /* may be changed to "grep -n" in os_win32.c */
1386 (char_u *)"findstr /n",
1387# else
1388# ifdef UNIX
1389 /* Add an extra file name so that grep will always
1390 * insert a file name in the match line. */
1391 (char_u *)"grep -n $* /dev/null",
1392# else
1393# ifdef VMS
1394 (char_u *)"SEARCH/NUMBERS ",
1395# else
1396 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001397# endif
1398# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001400 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001401#else
1402 (char_u *)NULL, PV_NONE,
1403 {(char_u *)NULL, (char_u *)0L}
1404#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001405 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001406 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407#ifdef CURSOR_SHAPE
1408 (char_u *)&p_guicursor, PV_NONE,
1409 {
1410# ifdef FEAT_GUI
1411 (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 +01001412# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1414# endif
1415 (char_u *)0L}
1416#else
1417 (char_u *)NULL, PV_NONE,
1418 {(char_u *)NULL, (char_u *)0L}
1419#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001420 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001421 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001422#ifdef FEAT_GUI
1423 (char_u *)&p_guifont, PV_NONE,
1424 {(char_u *)"", (char_u *)0L}
1425#else
1426 (char_u *)NULL, PV_NONE,
1427 {(char_u *)NULL, (char_u *)0L}
1428#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001429 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001430 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1432 (char_u *)&p_guifontset, PV_NONE,
1433 {(char_u *)"", (char_u *)0L}
1434#else
1435 (char_u *)NULL, PV_NONE,
1436 {(char_u *)NULL, (char_u *)0L}
1437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001438 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001439 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1441 (char_u *)&p_guifontwide, PV_NONE,
1442 {(char_u *)"", (char_u *)0L}
1443#else
1444 (char_u *)NULL, PV_NONE,
1445 {(char_u *)NULL, (char_u *)0L}
1446#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001447 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001449#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 (char_u *)&p_ghr, PV_NONE,
1451#else
1452 (char_u *)NULL, PV_NONE,
1453#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001454 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001456#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 (char_u *)&p_go, PV_NONE,
1458# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001459 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001461 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462# endif
1463#else
1464 (char_u *)NULL, PV_NONE,
1465 {(char_u *)NULL, (char_u *)0L}
1466#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001467 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001468 {"guipty", NULL, P_BOOL|P_VI_DEF,
1469#if defined(FEAT_GUI)
1470 (char_u *)&p_guipty, PV_NONE,
1471#else
1472 (char_u *)NULL, PV_NONE,
1473#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001474 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001475 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001476#if defined(FEAT_GUI_TABLINE)
1477 (char_u *)&p_gtl, PV_NONE,
1478 {(char_u *)"", (char_u *)0L}
1479#else
1480 (char_u *)NULL, PV_NONE,
1481 {(char_u *)NULL, (char_u *)0L}
1482#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001483 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001484 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001485#if defined(FEAT_GUI_TABLINE)
1486 (char_u *)&p_gtt, PV_NONE,
1487 {(char_u *)"", (char_u *)0L}
1488#else
1489 (char_u *)NULL, PV_NONE,
1490 {(char_u *)NULL, (char_u *)0L}
1491#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001492 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001493 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1494 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001495 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1497 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001498 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1499 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"helpheight", "hh", P_NUM|P_VI_DEF,
1501#ifdef FEAT_WINDOWS
1502 (char_u *)&p_hh, PV_NONE,
1503#else
1504 (char_u *)NULL, PV_NONE,
1505#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001506 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001507 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508#ifdef FEAT_MULTI_LANG
1509 (char_u *)&p_hlg, PV_NONE,
1510 {(char_u *)"", (char_u *)0L}
1511#else
1512 (char_u *)NULL, PV_NONE,
1513 {(char_u *)0L, (char_u *)0L}
1514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001515 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516 {"hidden", "hid", P_BOOL|P_VI_DEF,
1517 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001518 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001519 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1522 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 {"history", "hi", P_NUM|P_VIM,
1524 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001525 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001526 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1527#ifdef FEAT_RIGHTLEFT
1528 (char_u *)&p_hkmap, PV_NONE,
1529#else
1530 (char_u *)NULL, PV_NONE,
1531#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001532 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001533 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1534#ifdef FEAT_RIGHTLEFT
1535 (char_u *)&p_hkmapp, PV_NONE,
1536#else
1537 (char_u *)NULL, PV_NONE,
1538#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001539 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1541 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001542 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"icon", NULL, P_BOOL|P_VI_DEF,
1544#ifdef FEAT_TITLE
1545 (char_u *)&p_icon, PV_NONE,
1546#else
1547 (char_u *)NULL, PV_NONE,
1548#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001549 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001550 {"iconstring", NULL, P_STRING|P_VI_DEF,
1551#ifdef FEAT_TITLE
1552 (char_u *)&p_iconstring, PV_NONE,
1553#else
1554 (char_u *)NULL, PV_NONE,
1555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1558 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001560 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1561# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1562 (char_u *)&p_imaf, PV_NONE,
1563 {(char_u *)"", (char_u *)NULL}
1564# else
1565 (char_u *)NULL, PV_NONE,
1566 {(char_u *)NULL, (char_u *)0L}
1567# endif
1568 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001569 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001570#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571 (char_u *)&p_imak, PV_NONE,
1572#else
1573 (char_u *)NULL, PV_NONE,
1574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001575 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1577#ifdef USE_IM_CONTROL
1578 (char_u *)&p_imcmdline, PV_NONE,
1579#else
1580 (char_u *)NULL, PV_NONE,
1581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001583 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1584#ifdef USE_IM_CONTROL
1585 (char_u *)&p_imdisable, PV_NONE,
1586#else
1587 (char_u *)NULL, PV_NONE,
1588#endif
1589#ifdef __sgi
1590 {(char_u *)TRUE, (char_u *)0L}
1591#else
1592 {(char_u *)FALSE, (char_u *)0L}
1593#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001594 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001595 {"iminsert", "imi", P_NUM|P_VI_DEF,
1596 (char_u *)&p_iminsert, PV_IMI,
1597#ifdef B_IMODE_IM
1598 {(char_u *)B_IMODE_IM, (char_u *)0L}
1599#else
1600 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1601#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001602 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001603 {"imsearch", "ims", P_NUM|P_VI_DEF,
1604 (char_u *)&p_imsearch, PV_IMS,
1605#ifdef B_IMODE_IM
1606 {(char_u *)B_IMODE_IM, (char_u *)0L}
1607#else
1608 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1609#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001610 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001611 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001612# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1613 (char_u *)&p_imsf, PV_NONE,
1614 {(char_u *)"", (char_u *)NULL}
1615# else
1616 (char_u *)NULL, PV_NONE,
1617 {(char_u *)NULL, (char_u *)0L}
1618# endif
1619 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001620 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1621#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001622 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001623 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1624#else
1625 (char_u *)NULL, PV_NONE,
1626 {(char_u *)0L, (char_u *)0L}
1627#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001628 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1630#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1631 (char_u *)&p_inex, PV_INEX,
1632 {(char_u *)"", (char_u *)0L}
1633#else
1634 (char_u *)NULL, PV_NONE,
1635 {(char_u *)0L, (char_u *)0L}
1636#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001637 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1639 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001640 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1642#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1643 (char_u *)&p_inde, PV_INDE,
1644 {(char_u *)"", (char_u *)0L}
1645#else
1646 (char_u *)NULL, PV_NONE,
1647 {(char_u *)0L, (char_u *)0L}
1648#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001649 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001650 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1652 (char_u *)&p_indk, PV_INDK,
1653 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1654#else
1655 (char_u *)NULL, PV_NONE,
1656 {(char_u *)0L, (char_u *)0L}
1657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001658 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659 {"infercase", "inf", P_BOOL|P_VI_DEF,
1660 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001661 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1663 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001664 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1666 (char_u *)&p_isf, PV_NONE,
1667 {
1668#ifdef BACKSLASH_IN_FILENAME
1669 /* Excluded are: & and ^ are special in cmd.exe
1670 * ( and ) are used in text separating fnames */
1671 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1672#else
1673# ifdef AMIGA
1674 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1675# else
1676# ifdef VMS
1677 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1678# else /* UNIX et al. */
1679# ifdef EBCDIC
1680 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1681# else
1682 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1683# endif
1684# endif
1685# endif
1686#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001687 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1689 (char_u *)&p_isi, PV_NONE,
1690 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001691#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 (char_u *)"@,48-57,_,128-167,224-235",
1693#else
1694# ifdef EBCDIC
1695 /* TODO: EBCDIC Check this! @ == isalpha()*/
1696 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1697 "112-120,128,140-142,156,158,172,"
1698 "174,186,191,203-207,219-225,235-239,"
1699 "251-254",
1700# else
1701 (char_u *)"@,48-57,_,192-255",
1702# endif
1703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001704 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1706 (char_u *)&p_isk, PV_ISK,
1707 {
1708#ifdef EBCDIC
1709 (char_u *)"@,240-249,_",
1710 /* TODO: EBCDIC Check this! @ == isalpha()*/
1711 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1712 "112-120,128,140-142,156,158,172,"
1713 "174,186,191,203-207,219-225,235-239,"
1714 "251-254",
1715#else
1716 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001717# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001718 (char_u *)"@,48-57,_,128-167,224-235"
1719# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001720 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001721# endif
1722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001723 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001724 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1725 (char_u *)&p_isp, PV_NONE,
1726 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001727#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001728 || defined(VMS)
1729 (char_u *)"@,~-255",
1730#else
1731# ifdef EBCDIC
1732 /* all chars above 63 are printable */
1733 (char_u *)"63-255",
1734# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001735 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736# endif
1737#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001738 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1740 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001741 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1743#ifdef FEAT_CRYPT
1744 (char_u *)&p_key, PV_KEY,
1745 {(char_u *)"", (char_u *)0L}
1746#else
1747 (char_u *)NULL, PV_NONE,
1748 {(char_u *)0L, (char_u *)0L}
1749#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001750 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001751 {"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 +00001752#ifdef FEAT_KEYMAP
1753 (char_u *)&p_keymap, PV_KMAP,
1754 {(char_u *)"", (char_u *)0L}
1755#else
1756 (char_u *)NULL, PV_NONE,
1757 {(char_u *)"", (char_u *)0L}
1758#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001759 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001760 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001762 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001764 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001766#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 (char_u *)":help",
1768#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001769# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001770 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001771# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001772# ifdef USEMAN_S
1773 (char_u *)"man -s",
1774# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001776# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777# endif
1778#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001779 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001780 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001781#ifdef FEAT_LANGMAP
1782 (char_u *)&p_langmap, PV_NONE,
1783 {(char_u *)"", /* unmatched } */
1784#else
1785 (char_u *)NULL, PV_NONE,
1786 {(char_u *)NULL,
1787#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001789 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1791 (char_u *)&p_lm, PV_NONE,
1792#else
1793 (char_u *)NULL, PV_NONE,
1794#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001795 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001796 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1797#ifdef FEAT_LANGMAP
1798 (char_u *)&p_lnr, PV_NONE,
1799#else
1800 (char_u *)NULL, PV_NONE,
1801#endif
1802 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001803 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1804#ifdef FEAT_LANGMAP
1805 (char_u *)&p_lrm, PV_NONE,
1806#else
1807 (char_u *)NULL, PV_NONE,
1808#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001809 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1811#ifdef FEAT_WINDOWS
1812 (char_u *)&p_ls, PV_NONE,
1813#else
1814 (char_u *)NULL, PV_NONE,
1815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001816 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001817 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1818 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001819 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1821#ifdef FEAT_LINEBREAK
1822 (char_u *)VAR_WIN, PV_LBR,
1823#else
1824 (char_u *)NULL, PV_NONE,
1825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001826 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1828 (char_u *)&Rows, PV_NONE,
1829 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001830#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831 (char_u *)25L,
1832#else
1833 (char_u *)24L,
1834#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001835 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1837#ifdef FEAT_GUI
1838 (char_u *)&p_linespace, PV_NONE,
1839#else
1840 (char_u *)NULL, PV_NONE,
1841#endif
1842#ifdef FEAT_GUI_W32
1843 {(char_u *)1L, (char_u *)0L}
1844#else
1845 {(char_u *)0L, (char_u *)0L}
1846#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001847 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 {"lisp", NULL, P_BOOL|P_VI_DEF,
1849#ifdef FEAT_LISP
1850 (char_u *)&p_lisp, PV_LISP,
1851#else
1852 (char_u *)NULL, PV_NONE,
1853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001854 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001855 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001857 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1859#else
1860 (char_u *)NULL, PV_NONE,
1861 {(char_u *)"", (char_u *)0L}
1862#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001864 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1865 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001866 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001867 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1871 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001873 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001874#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001875 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001876 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001877#else
1878 (char_u *)NULL, PV_NONE,
1879 {(char_u *)"", (char_u *)0L}
1880#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001881 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001882 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001883#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001884 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001885 {(char_u *)TRUE, (char_u *)0L}
1886#else
1887 (char_u *)NULL, PV_NONE,
1888 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001889#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01001890 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"magic", NULL, P_BOOL|P_VI_DEF,
1892 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001894 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895#ifdef FEAT_QUICKFIX
1896 (char_u *)&p_mef, PV_NONE,
1897 {(char_u *)"", (char_u *)0L}
1898#else
1899 (char_u *)NULL, PV_NONE,
1900 {(char_u *)NULL, (char_u *)0L}
1901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001902 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1904#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001905 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906# ifdef VMS
1907 {(char_u *)"MMS", (char_u *)0L}
1908# else
1909 {(char_u *)"make", (char_u *)0L}
1910# endif
1911#else
1912 (char_u *)NULL, PV_NONE,
1913 {(char_u *)NULL, (char_u *)0L}
1914#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001915 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001916 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001918 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"matchtime", "mat", P_NUM|P_VI_DEF,
1921 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001922 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001923 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001924#ifdef FEAT_MBYTE
1925 (char_u *)&p_mco, PV_NONE,
1926#else
1927 (char_u *)NULL, PV_NONE,
1928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001929 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001930 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1931#ifdef FEAT_EVAL
1932 (char_u *)&p_mfd, PV_NONE,
1933#else
1934 (char_u *)NULL, PV_NONE,
1935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001936 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1938 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001939 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001940 {"maxmem", "mm", P_NUM|P_VI_DEF,
1941 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001942 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1943 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001944 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1945 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001946 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1948 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001949 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1950 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 {"menuitems", "mis", P_NUM|P_VI_DEF,
1952#ifdef FEAT_MENU
1953 (char_u *)&p_mis, PV_NONE,
1954#else
1955 (char_u *)NULL, PV_NONE,
1956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001957 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001958 {"mesg", NULL, P_BOOL|P_VI_DEF,
1959 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001960 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001961 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001962#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001963 (char_u *)&p_msm, PV_NONE,
1964 {(char_u *)"460000,2000,500", (char_u *)0L}
1965#else
1966 (char_u *)NULL, PV_NONE,
1967 {(char_u *)0L, (char_u *)0L}
1968#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001969 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001970 {"modeline", "ml", P_BOOL|P_VIM,
1971 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001972 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"modelines", "mls", P_NUM|P_VI_DEF,
1974 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001975 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1977 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001978 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001979 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1980 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001981 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"more", NULL, P_BOOL|P_VIM,
1983 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001984 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1986 (char_u *)&p_mouse, PV_NONE,
1987 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001988#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 (char_u *)"a",
1990#else
1991 (char_u *)"",
1992#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001993 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1995#ifdef FEAT_GUI
1996 (char_u *)&p_mousef, PV_NONE,
1997#else
1998 (char_u *)NULL, PV_NONE,
1999#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002000 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002001 {"mousehide", "mh", P_BOOL|P_VI_DEF,
2002#ifdef FEAT_GUI
2003 (char_u *)&p_mh, PV_NONE,
2004#else
2005 (char_u *)NULL, PV_NONE,
2006#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002007 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
2009 (char_u *)&p_mousem, PV_NONE,
2010 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002011#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002012 (char_u *)"popup",
2013#else
2014# if defined(MACOS)
2015 (char_u *)"popup_setpos",
2016# else
2017 (char_u *)"extend",
2018# endif
2019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002020 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002021 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022#ifdef FEAT_MOUSESHAPE
2023 (char_u *)&p_mouseshape, PV_NONE,
2024 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
2025#else
2026 (char_u *)NULL, PV_NONE,
2027 {(char_u *)NULL, (char_u *)0L}
2028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030 {"mousetime", "mouset", P_NUM|P_VI_DEF,
2031 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002032 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00002033 {"mzquantum", "mzq", P_NUM,
2034#ifdef FEAT_MZSCHEME
2035 (char_u *)&p_mzq, PV_NONE,
2036#else
2037 (char_u *)NULL, PV_NONE,
2038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002039 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 {"novice", NULL, P_BOOL|P_VI_DEF,
2041 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002043 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01002045 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002046 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002047 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
2048 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002050 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2051#ifdef FEAT_LINEBREAK
2052 (char_u *)VAR_WIN, PV_NUW,
2053#else
2054 (char_u *)NULL, PV_NONE,
2055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002057 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002058#ifdef FEAT_COMPL_FUNC
2059 (char_u *)&p_ofu, PV_OFU,
2060 {(char_u *)"", (char_u *)0L}
2061#else
2062 (char_u *)NULL, PV_NONE,
2063 {(char_u *)0L, (char_u *)0L}
2064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002065 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 {"open", NULL, P_BOOL|P_VI_DEF,
2067 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002068 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002069 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002070#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002071 (char_u *)&p_odev, PV_NONE,
2072#else
2073 (char_u *)NULL, PV_NONE,
2074#endif
2075 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002076 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002077 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2078 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002079 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002080 {"optimize", "opt", P_BOOL|P_VI_DEF,
2081 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002082 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02002085 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002086 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2087 |P_SECURE,
2088 (char_u *)&p_pp, PV_NONE,
2089 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2090 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 {"paragraphs", "para", P_STRING|P_VI_DEF,
2092 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002093 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002094 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002095 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002096 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002098 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2099 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002100 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002101 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2102#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2103 (char_u *)&p_pex, PV_NONE,
2104 {(char_u *)"", (char_u *)0L}
2105#else
2106 (char_u *)NULL, PV_NONE,
2107 {(char_u *)0L, (char_u *)0L}
2108#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002109 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002110 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002112 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002113 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002114 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002116#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 (char_u *)".,,",
2118#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002119 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002120#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002121 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002122 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002123#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002124 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002125 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002126#else
2127 (char_u *)NULL, PV_NONE,
2128 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002129#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002130 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002131 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2132 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002133 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002134 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2136 (char_u *)&p_pvh, PV_NONE,
2137#else
2138 (char_u *)NULL, PV_NONE,
2139#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002140 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2142#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2143 (char_u *)VAR_WIN, PV_PVW,
2144#else
2145 (char_u *)NULL, PV_NONE,
2146#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002147 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002148 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149#ifdef FEAT_PRINTER
2150 (char_u *)&p_pdev, PV_NONE,
2151 {(char_u *)"", (char_u *)0L}
2152#else
2153 (char_u *)NULL, PV_NONE,
2154 {(char_u *)NULL, (char_u *)0L}
2155#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002156 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002157 {"printencoding", "penc", P_STRING|P_VI_DEF,
2158#ifdef FEAT_POSTSCRIPT
2159 (char_u *)&p_penc, PV_NONE,
2160 {(char_u *)"", (char_u *)0L}
2161#else
2162 (char_u *)NULL, PV_NONE,
2163 {(char_u *)NULL, (char_u *)0L}
2164#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002165 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002166 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002167#ifdef FEAT_POSTSCRIPT
2168 (char_u *)&p_pexpr, PV_NONE,
2169 {(char_u *)"", (char_u *)0L}
2170#else
2171 (char_u *)NULL, PV_NONE,
2172 {(char_u *)NULL, (char_u *)0L}
2173#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002174 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002175 {"printfont", "pfn", P_STRING|P_VI_DEF,
2176#ifdef FEAT_PRINTER
2177 (char_u *)&p_pfn, PV_NONE,
2178 {
2179# ifdef MSWIN
2180 (char_u *)"Courier_New:h10",
2181# else
2182 (char_u *)"courier",
2183# endif
2184 (char_u *)0L}
2185#else
2186 (char_u *)NULL, PV_NONE,
2187 {(char_u *)NULL, (char_u *)0L}
2188#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002189 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002190 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2191#ifdef FEAT_PRINTER
2192 (char_u *)&p_header, PV_NONE,
2193 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2194#else
2195 (char_u *)NULL, PV_NONE,
2196 {(char_u *)NULL, (char_u *)0L}
2197#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002198 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002199 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2200#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2201 (char_u *)&p_pmcs, PV_NONE,
2202 {(char_u *)"", (char_u *)0L}
2203#else
2204 (char_u *)NULL, PV_NONE,
2205 {(char_u *)NULL, (char_u *)0L}
2206#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002208 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2209#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2210 (char_u *)&p_pmfn, PV_NONE,
2211 {(char_u *)"", (char_u *)0L}
2212#else
2213 (char_u *)NULL, PV_NONE,
2214 {(char_u *)NULL, (char_u *)0L}
2215#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002216 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002217 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002218#ifdef FEAT_PRINTER
2219 (char_u *)&p_popt, PV_NONE,
2220 {(char_u *)"", (char_u *)0L}
2221#else
2222 (char_u *)NULL, PV_NONE,
2223 {(char_u *)NULL, (char_u *)0L}
2224#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002225 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002226 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002227 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002229 {"pumheight", "ph", P_NUM|P_VI_DEF,
2230#ifdef FEAT_INS_EXPAND
2231 (char_u *)&p_ph, PV_NONE,
2232#else
2233 (char_u *)NULL, PV_NONE,
2234#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002235 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002236 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002237#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002238 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002239 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002240#else
2241 (char_u *)NULL, PV_NONE,
2242 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002243#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002244 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002245 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002246#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002247 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002248 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002249#else
2250 (char_u *)NULL, PV_NONE,
2251 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002252#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002253 SCRIPTID_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002254 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2255#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2256 (char_u *)&p_pyx, PV_NONE,
2257#else
2258 (char_u *)NULL, PV_NONE,
2259#endif
2260 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2261 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002262 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2263#ifdef FEAT_TEXTOBJ
2264 (char_u *)&p_qe, PV_QE,
2265 {(char_u *)"\\", (char_u *)0L}
2266#else
2267 (char_u *)NULL, PV_NONE,
2268 {(char_u *)NULL, (char_u *)0L}
2269#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002270 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002271 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2272 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002273 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 {"redraw", NULL, P_BOOL|P_VI_DEF,
2275 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002276 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002277 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2278#ifdef FEAT_RELTIME
2279 (char_u *)&p_rdt, PV_NONE,
2280#else
2281 (char_u *)NULL, PV_NONE,
2282#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002283 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002284 {"regexpengine", "re", P_NUM|P_VI_DEF,
2285 (char_u *)&p_re, PV_NONE,
2286 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002287 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2288 (char_u *)VAR_WIN, PV_RNU,
2289 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 {"remap", NULL, P_BOOL|P_VI_DEF,
2291 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002292 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002293 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002294#ifdef FEAT_RENDER_OPTIONS
2295 (char_u *)&p_rop, PV_NONE,
2296 {(char_u *)"", (char_u *)0L}
2297#else
2298 (char_u *)NULL, PV_NONE,
2299 {(char_u *)NULL, (char_u *)0L}
2300#endif
2301 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002302 {"report", NULL, P_NUM|P_VI_DEF,
2303 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002304 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002305 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2306#ifdef WIN3264
2307 (char_u *)&p_rs, PV_NONE,
2308#else
2309 (char_u *)NULL, PV_NONE,
2310#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2313#ifdef FEAT_RIGHTLEFT
2314 (char_u *)&p_ri, PV_NONE,
2315#else
2316 (char_u *)NULL, PV_NONE,
2317#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002318 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2320#ifdef FEAT_RIGHTLEFT
2321 (char_u *)VAR_WIN, PV_RL,
2322#else
2323 (char_u *)NULL, PV_NONE,
2324#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002325 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2327#ifdef FEAT_RIGHTLEFT
2328 (char_u *)VAR_WIN, PV_RLC,
2329 {(char_u *)"search", (char_u *)NULL}
2330#else
2331 (char_u *)NULL, PV_NONE,
2332 {(char_u *)NULL, (char_u *)0L}
2333#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002334 SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002335 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002336#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002337 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002338 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002339#else
2340 (char_u *)NULL, PV_NONE,
2341 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002342#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002343 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2345#ifdef FEAT_CMDL_INFO
2346 (char_u *)&p_ru, PV_NONE,
2347#else
2348 (char_u *)NULL, PV_NONE,
2349#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002350 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2352#ifdef FEAT_STL_OPT
2353 (char_u *)&p_ruf, PV_NONE,
2354#else
2355 (char_u *)NULL, PV_NONE,
2356#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002357 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002358 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2359 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2362 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2364 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2367#ifdef FEAT_SCROLLBIND
2368 (char_u *)VAR_WIN, PV_SCBIND,
2369#else
2370 (char_u *)NULL, PV_NONE,
2371#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002372 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2374 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002375 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2377 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002378 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002379 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380#ifdef FEAT_SCROLLBIND
2381 (char_u *)&p_sbo, PV_NONE,
2382 {(char_u *)"ver,jump", (char_u *)0L}
2383#else
2384 (char_u *)NULL, PV_NONE,
2385 {(char_u *)0L, (char_u *)0L}
2386#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002387 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"sections", "sect", P_STRING|P_VI_DEF,
2389 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002390 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2391 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2393 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002394 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002397 {(char_u *)"inclusive", (char_u *)0L}
2398 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002399 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002401 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002402 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403#ifdef FEAT_SESSION
2404 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002405 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 (char_u *)0L}
2407#else
2408 (char_u *)NULL, PV_NONE,
2409 {(char_u *)0L, (char_u *)0L}
2410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002412 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2413 (char_u *)&p_sh, PV_NONE,
2414 {
2415#ifdef VMS
2416 (char_u *)"-",
2417#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002418# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002420# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002422# endif
2423#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002424 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002425 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2426 (char_u *)&p_shcf, PV_NONE,
2427 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002428#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 (char_u *)"/c",
2430#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002431 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002432#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002433 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2435#ifdef FEAT_QUICKFIX
2436 (char_u *)&p_sp, PV_NONE,
2437 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002438#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440#else
2441 (char_u *)">",
2442#endif
2443 (char_u *)0L}
2444#else
2445 (char_u *)NULL, PV_NONE,
2446 {(char_u *)0L, (char_u *)0L}
2447#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002448 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002449 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2450 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002451 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2453 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002454 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2456#ifdef BACKSLASH_IN_FILENAME
2457 (char_u *)&p_ssl, PV_NONE,
2458#else
2459 (char_u *)NULL, PV_NONE,
2460#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002462 {"shelltemp", "stmp", P_BOOL,
2463 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002464 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"shelltype", "st", P_NUM|P_VI_DEF,
2466#ifdef AMIGA
2467 (char_u *)&p_st, PV_NONE,
2468#else
2469 (char_u *)NULL, PV_NONE,
2470#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002471 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002472 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2473 (char_u *)&p_sxq, PV_NONE,
2474 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002475#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002476 (char_u *)"\"",
2477#else
2478 (char_u *)"",
2479#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002480 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002481 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2482 (char_u *)&p_sxe, PV_NONE,
2483 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002484#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002485 (char_u *)"\"&|<>()@^",
2486#else
2487 (char_u *)"",
2488#endif
2489 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2491 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002492 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2494 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002495 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2497 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002498 {(char_u *)"", (char_u *)"filnxtToO"}
2499 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002500 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002502 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2504#ifdef FEAT_LINEBREAK
2505 (char_u *)&p_sbr, PV_NONE,
2506#else
2507 (char_u *)NULL, PV_NONE,
2508#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002509 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"showcmd", "sc", P_BOOL|P_VIM,
2511#ifdef FEAT_CMDL_INFO
2512 (char_u *)&p_sc, PV_NONE,
2513#else
2514 (char_u *)NULL, PV_NONE,
2515#endif
2516 {(char_u *)FALSE,
2517#ifdef UNIX
2518 (char_u *)FALSE
2519#else
2520 (char_u *)TRUE
2521#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002522 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2524 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002525 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002526 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2527 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002528 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002529 {"showmode", "smd", P_BOOL|P_VIM,
2530 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002531 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002532 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2533#ifdef FEAT_WINDOWS
2534 (char_u *)&p_stal, PV_NONE,
2535#else
2536 (char_u *)NULL, PV_NONE,
2537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002538 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002539 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2540 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002541 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002542 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2543 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002545 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2546#ifdef FEAT_SIGNS
2547 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002548 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002549#else
2550 (char_u *)NULL, PV_NONE,
2551 {(char_u *)NULL, (char_u *)0L}
2552#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002553 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002554 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2555 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002556 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002557 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2558 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002560 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2561#ifdef FEAT_SMARTINDENT
2562 (char_u *)&p_si, PV_SI,
2563#else
2564 (char_u *)NULL, PV_NONE,
2565#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002567 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2568 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002570 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2571 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002572 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002573 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2574 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002576 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002577#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002578 (char_u *)VAR_WIN, PV_SPELL,
2579#else
2580 (char_u *)NULL, PV_NONE,
2581#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002582 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002583 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002584#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002585 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002586 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002587#else
2588 (char_u *)NULL, PV_NONE,
2589 {(char_u *)0L, (char_u *)0L}
2590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002592 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2593 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002594#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002595 (char_u *)&p_spf, PV_SPF,
2596 {(char_u *)"", (char_u *)0L}
2597#else
2598 (char_u *)NULL, PV_NONE,
2599 {(char_u *)0L, (char_u *)0L}
2600#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002602 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2603 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002604#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002605 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002606 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002607#else
2608 (char_u *)NULL, PV_NONE,
2609 {(char_u *)0L, (char_u *)0L}
2610#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002611 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002612 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002613#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002614 (char_u *)&p_sps, PV_NONE,
2615 {(char_u *)"best", (char_u *)0L}
2616#else
2617 (char_u *)NULL, PV_NONE,
2618 {(char_u *)0L, (char_u *)0L}
2619#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002620 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2622#ifdef FEAT_WINDOWS
2623 (char_u *)&p_sb, PV_NONE,
2624#else
2625 (char_u *)NULL, PV_NONE,
2626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002629#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002630 (char_u *)&p_spr, PV_NONE,
2631#else
2632 (char_u *)NULL, PV_NONE,
2633#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002634 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002635 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2636 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002637 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002638 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2639#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002640 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641#else
2642 (char_u *)NULL, PV_NONE,
2643#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002644 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002645 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002646 (char_u *)&p_su, PV_NONE,
2647 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002648 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002649 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002650#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 (char_u *)&p_sua, PV_SUA,
2652 {(char_u *)"", (char_u *)0L}
2653#else
2654 (char_u *)NULL, PV_NONE,
2655 {(char_u *)0L, (char_u *)0L}
2656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002657 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002658 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2659 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002660 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002661 {"swapsync", "sws", P_STRING|P_VI_DEF,
2662 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002663 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002664 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002666 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002667 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2668#ifdef FEAT_SYN_HL
2669 (char_u *)&p_smc, PV_SMC,
2670 {(char_u *)3000L, (char_u *)0L}
2671#else
2672 (char_u *)NULL, PV_NONE,
2673 {(char_u *)0L, (char_u *)0L}
2674#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002675 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002676 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677#ifdef FEAT_SYN_HL
2678 (char_u *)&p_syn, PV_SYN,
2679 {(char_u *)"", (char_u *)0L}
2680#else
2681 (char_u *)NULL, PV_NONE,
2682 {(char_u *)0L, (char_u *)0L}
2683#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002684 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002685 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2686#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002687 (char_u *)&p_tal, PV_NONE,
2688#else
2689 (char_u *)NULL, PV_NONE,
2690#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002691 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002692 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2693#ifdef FEAT_WINDOWS
2694 (char_u *)&p_tpm, PV_NONE,
2695#else
2696 (char_u *)NULL, PV_NONE,
2697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002698 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002699 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2700 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002701 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2703 (char_u *)&p_tbs, PV_NONE,
2704#ifdef VMS /* binary searching doesn't appear to work on VMS */
2705 {(char_u *)0L, (char_u *)0L}
2706#else
2707 {(char_u *)TRUE, (char_u *)0L}
2708#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002709 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002710 {"tagcase", "tc", P_STRING|P_VIM,
2711 (char_u *)&p_tc, PV_TC,
2712 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 {"taglength", "tl", P_NUM|P_VI_DEF,
2714 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002715 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002716 {"tagrelative", "tr", P_BOOL|P_VIM,
2717 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002718 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002719 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002720 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002721 {
2722#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2723 (char_u *)"./tags,./TAGS,tags,TAGS",
2724#else
2725 (char_u *)"./tags,tags",
2726#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002727 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2729 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002731 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002732#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002733 (char_u *)&p_tcldll, PV_NONE,
2734 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002735#else
2736 (char_u *)NULL, PV_NONE,
2737 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002738#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002739 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002740 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2741 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002742 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002743 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2744#ifdef FEAT_ARABIC
2745 (char_u *)&p_tbidi, PV_NONE,
2746#else
2747 (char_u *)NULL, PV_NONE,
2748#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002749 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2751#ifdef FEAT_MBYTE
2752 (char_u *)&p_tenc, PV_NONE,
2753 {(char_u *)"", (char_u *)0L}
2754#else
2755 (char_u *)NULL, PV_NONE,
2756 {(char_u *)0L, (char_u *)0L}
2757#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002759 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2760#ifdef FEAT_TERMGUICOLORS
2761 (char_u *)&p_tgc, PV_NONE,
2762 {(char_u *)FALSE, (char_u *)FALSE}
2763#else
2764 (char_u*)NULL, PV_NONE,
2765 {(char_u *)FALSE, (char_u *)FALSE}
2766#endif
2767 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"terse", NULL, P_BOOL|P_VI_DEF,
2769 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002770 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002771 {"textauto", "ta", P_BOOL|P_VIM,
2772 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002773 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2774 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2776 (char_u *)&p_tx, PV_TX,
2777 {
2778#ifdef USE_CRNL
2779 (char_u *)TRUE,
2780#else
2781 (char_u *)FALSE,
2782#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002783 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002784 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002786 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002787 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002789 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002790#else
2791 (char_u *)NULL, PV_NONE,
2792#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002793 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002794 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2795 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002796 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002797 {"timeout", "to", P_BOOL|P_VI_DEF,
2798 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002799 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2801 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002802 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002803 {"title", NULL, P_BOOL|P_VI_DEF,
2804#ifdef FEAT_TITLE
2805 (char_u *)&p_title, PV_NONE,
2806#else
2807 (char_u *)NULL, PV_NONE,
2808#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002809 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810 {"titlelen", NULL, P_NUM|P_VI_DEF,
2811#ifdef FEAT_TITLE
2812 (char_u *)&p_titlelen, PV_NONE,
2813#else
2814 (char_u *)NULL, PV_NONE,
2815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002817 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818#ifdef FEAT_TITLE
2819 (char_u *)&p_titleold, PV_NONE,
2820 {(char_u *)N_("Thanks for flying Vim"),
2821 (char_u *)0L}
2822#else
2823 (char_u *)NULL, PV_NONE,
2824 {(char_u *)0L, (char_u *)0L}
2825#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 {"titlestring", NULL, P_STRING|P_VI_DEF,
2828#ifdef FEAT_TITLE
2829 (char_u *)&p_titlestring, PV_NONE,
2830#else
2831 (char_u *)NULL, PV_NONE,
2832#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002833 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002834 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002835#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002837 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002838#else
2839 (char_u *)NULL, PV_NONE,
2840 {(char_u *)0L, (char_u *)0L}
2841#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002842 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002844#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002846 {(char_u *)"small", (char_u *)0L}
2847#else
2848 (char_u *)NULL, PV_NONE,
2849 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850#endif
Bram Moolenaara713ff82017-02-25 22:18:43 +01002851 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2853 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002854 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2856 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002857 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002858 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2859 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002860 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002861 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2862 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002863 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002864 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2865#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2866 (char_u *)&p_ttym, PV_NONE,
2867#else
2868 (char_u *)NULL, PV_NONE,
2869#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002870 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002871 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2872 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002873 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2875 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002876 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002877 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2878 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002879#ifdef FEAT_PERSISTENT_UNDO
2880 (char_u *)&p_udir, PV_NONE,
2881 {(char_u *)".", (char_u *)0L}
2882#else
2883 (char_u *)NULL, PV_NONE,
2884 {(char_u *)0L, (char_u *)0L}
2885#endif
2886 SCRIPTID_INIT},
2887 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2888#ifdef FEAT_PERSISTENT_UNDO
2889 (char_u *)&p_udf, PV_UDF,
2890#else
2891 (char_u *)NULL, PV_NONE,
2892#endif
2893 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002894 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002895 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002896 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002897#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 (char_u *)1000L,
2899#else
2900 (char_u *)100L,
2901#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002902 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002903 {"undoreload", "ur", P_NUM|P_VI_DEF,
2904 (char_u *)&p_ur, PV_NONE,
2905 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002906 {"updatecount", "uc", P_NUM|P_VI_DEF,
2907 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002908 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002909 {"updatetime", "ut", P_NUM|P_VI_DEF,
2910 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002911 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {"verbose", "vbs", P_NUM|P_VI_DEF,
2913 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002914 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002915 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2916 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002917 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2919#ifdef FEAT_SESSION
2920 (char_u *)&p_vdir, PV_NONE,
2921 {(char_u *)DFLT_VDIR, (char_u *)0L}
2922#else
2923 (char_u *)NULL, PV_NONE,
2924 {(char_u *)0L, (char_u *)0L}
2925#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002926 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002927 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928#ifdef FEAT_SESSION
2929 (char_u *)&p_vop, PV_NONE,
2930 {(char_u *)"folds,options,cursor", (char_u *)0L}
2931#else
2932 (char_u *)NULL, PV_NONE,
2933 {(char_u *)0L, (char_u *)0L}
2934#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002935 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002936 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937#ifdef FEAT_VIMINFO
2938 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002939#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002940 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941#else
2942# ifdef AMIGA
2943 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002944 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002946 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947# endif
2948#endif
2949#else
2950 (char_u *)NULL, PV_NONE,
2951 {(char_u *)0L, (char_u *)0L}
2952#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002953 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002954 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2955 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956#ifdef FEAT_VIRTUALEDIT
2957 (char_u *)&p_ve, PV_NONE,
2958 {(char_u *)"", (char_u *)""}
2959#else
2960 (char_u *)NULL, PV_NONE,
2961 {(char_u *)0L, (char_u *)0L}
2962#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002963 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2965 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002966 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 {"w300", NULL, P_NUM|P_VI_DEF,
2968 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002969 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 {"w1200", NULL, P_NUM|P_VI_DEF,
2971 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002972 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 {"w9600", NULL, P_NUM|P_VI_DEF,
2974 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002975 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 {"warn", NULL, P_BOOL|P_VI_DEF,
2977 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002978 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2980 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002981 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002982 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002984 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 {"wildchar", "wc", P_NUM|P_VIM,
2986 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002987 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2988 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002989 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002991 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002992 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002993#ifdef FEAT_WILDIGN
2994 (char_u *)&p_wig, PV_NONE,
2995#else
2996 (char_u *)NULL, PV_NONE,
2997#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002998 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002999 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3000 (char_u *)&p_wic, PV_NONE,
3001 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3003#ifdef FEAT_WILDMENU
3004 (char_u *)&p_wmnu, PV_NONE,
3005#else
3006 (char_u *)NULL, PV_NONE,
3007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003009 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003010 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003011 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003012 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3013#ifdef FEAT_CMDL_COMPL
3014 (char_u *)&p_wop, PV_NONE,
3015 {(char_u *)"", (char_u *)0L}
3016#else
3017 (char_u *)NULL, PV_NONE,
3018 {(char_u *)NULL, (char_u *)0L}
3019#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003020 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3022#ifdef FEAT_WAK
3023 (char_u *)&p_wak, PV_NONE,
3024 {(char_u *)"menu", (char_u *)0L}
3025#else
3026 (char_u *)NULL, PV_NONE,
3027 {(char_u *)NULL, (char_u *)0L}
3028#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003029 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003030 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003031 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003032 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003033 {"winheight", "wh", P_NUM|P_VI_DEF,
3034#ifdef FEAT_WINDOWS
3035 (char_u *)&p_wh, PV_NONE,
3036#else
3037 (char_u *)NULL, PV_NONE,
3038#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003039 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003041#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 (char_u *)VAR_WIN, PV_WFH,
3043#else
3044 (char_u *)NULL, PV_NONE,
3045#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003046 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003047 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003048#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003049 (char_u *)VAR_WIN, PV_WFW,
3050#else
3051 (char_u *)NULL, PV_NONE,
3052#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003053 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 {"winminheight", "wmh", P_NUM|P_VI_DEF,
3055#ifdef FEAT_WINDOWS
3056 (char_u *)&p_wmh, PV_NONE,
3057#else
3058 (char_u *)NULL, PV_NONE,
3059#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003060 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003062#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 (char_u *)&p_wmw, PV_NONE,
3064#else
3065 (char_u *)NULL, PV_NONE,
3066#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003067 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003069#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 (char_u *)&p_wiw, PV_NONE,
3071#else
3072 (char_u *)NULL, PV_NONE,
3073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003074 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3076 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003077 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3079 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003080 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3082 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003083 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 {"write", NULL, P_BOOL|P_VI_DEF,
3085 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003086 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003087 {"writeany", "wa", P_BOOL|P_VI_DEF,
3088 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003089 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003090 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3091 (char_u *)&p_wb, PV_NONE,
3092 {
3093#ifdef FEAT_WRITEBACKUP
3094 (char_u *)TRUE,
3095#else
3096 (char_u *)FALSE,
3097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003098 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 {"writedelay", "wd", P_NUM|P_VI_DEF,
3100 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003101 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102
3103/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003104#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003105 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003106 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107
3108 p_term("t_AB", T_CAB)
3109 p_term("t_AF", T_CAF)
3110 p_term("t_AL", T_CAL)
3111 p_term("t_al", T_AL)
3112 p_term("t_bc", T_BC)
3113 p_term("t_cd", T_CD)
3114 p_term("t_ce", T_CE)
3115 p_term("t_cl", T_CL)
3116 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003117 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 p_term("t_Co", T_CCO)
3119 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003120 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003122#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_CV", T_CSV)
3124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 p_term("t_da", T_DA)
3126 p_term("t_db", T_DB)
3127 p_term("t_DL", T_CDL)
3128 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003129 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 p_term("t_fs", T_FS)
3131 p_term("t_IE", T_CIE)
3132 p_term("t_IS", T_CIS)
3133 p_term("t_ke", T_KE)
3134 p_term("t_ks", T_KS)
3135 p_term("t_le", T_LE)
3136 p_term("t_mb", T_MB)
3137 p_term("t_md", T_MD)
3138 p_term("t_me", T_ME)
3139 p_term("t_mr", T_MR)
3140 p_term("t_ms", T_MS)
3141 p_term("t_nd", T_ND)
3142 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003143 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 p_term("t_RI", T_CRI)
3145 p_term("t_RV", T_CRV)
3146 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003148 p_term("t_Sf", T_CSF)
3149 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003151 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_te", T_TE)
3154 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003155 p_term("t_ts", T_TS)
3156 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_ue", T_UE)
3158 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003159 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003160 p_term("t_vb", T_VB)
3161 p_term("t_ve", T_VE)
3162 p_term("t_vi", T_VI)
3163 p_term("t_vs", T_VS)
3164 p_term("t_WP", T_CWP)
3165 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003166 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 p_term("t_xs", T_XS)
3168 p_term("t_ZH", T_CZH)
3169 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003170 p_term("t_8f", T_8F)
3171 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003172 p_term("t_BE", T_BE)
3173 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174
3175/* terminal key codes are not in here */
3176
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003177 /* end marker */
3178 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179};
3180
3181#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3182
3183#ifdef FEAT_MBYTE
3184static char *(p_ambw_values[]) = {"single", "double", NULL};
3185#endif
3186static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003187static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003189#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003190static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003191#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003192#ifdef FEAT_CMDL_COMPL
3193static char *(p_wop_values[]) = {"tagfile", NULL};
3194#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195#ifdef FEAT_WAK
3196static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3197#endif
3198static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003199static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3200static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202#ifdef FEAT_BROWSE
3203static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3204#endif
3205#ifdef FEAT_SCROLLBIND
3206static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3207#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003208static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003209#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003210static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3211#endif
3212#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003213# ifdef FEAT_AUTOCMD
3214static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3215# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003217# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3219#endif
3220static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3221#ifdef FEAT_FOLDING
3222static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003223# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003225# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 NULL};
3227static char *(p_fcl_values[]) = {"all", NULL};
3228#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003229#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003230static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003231#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003232#ifdef FEAT_SIGNS
3233static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3234#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003236static void set_option_default(int, int opt_flags, int compatible);
3237static void set_options_default(int opt_flags);
3238static char_u *term_bg_default(void);
3239static void did_set_option(int opt_idx, int opt_flags, int new_value);
3240static char_u *illegal_char(char_u *, int);
3241static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003243static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003244#endif
3245#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003246static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003248static char_u *option_expand(int opt_idx, char_u *val);
3249static void didset_options(void);
3250static void didset_options2(void);
3251static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003252#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003253static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003254#else
3255# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3256#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003257static void set_string_option_global(int opt_idx, char_u **varp);
3258static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3259static 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);
3260static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003261#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003262static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003263#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003264#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003265static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003267#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static char_u *did_set_spell_option(int is_spellfile);
3269static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003270#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003271#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003272static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003273#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3275static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3276static void check_redraw(long_u flags);
3277static int findoption(char_u *);
3278static int find_key_option(char_u *);
3279static void showoptions(int all, int opt_flags);
3280static int optval_default(struct vimoption *, char_u *varp);
3281static void showoneopt(struct vimoption *, int opt_flags);
3282static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3283static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3284static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3285static int istermoption(struct vimoption *);
3286static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3287static char_u *get_varp(struct vimoption *);
3288static void option_value2string(struct vimoption *, int opt_flags);
3289static void check_winopt(winopt_T *wop);
3290static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003292static void langmap_init(void);
3293static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003295static void paste_option_changed(void);
3296static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003298static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003300static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3301static int check_opt_strings(char_u *val, char **values, int);
3302static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003303#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003304static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306
3307/*
3308 * Initialize the options, first part.
3309 *
3310 * Called only once from main(), just after creating the first buffer.
3311 */
3312 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003313set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003314{
3315 char_u *p;
3316 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003317 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003318
3319#ifdef FEAT_LANGMAP
3320 langmap_init();
3321#endif
3322
3323 /* Be Vi compatible by default */
3324 p_cp = TRUE;
3325
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003326 /* Use POSIX compatibility when $VIM_POSIX is set. */
3327 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003328 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003329 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003330 set_string_default("shm", (char_u *)"A");
3331 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003332
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 /*
3334 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003335 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003337 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003338#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003339 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003341 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003342# endif
3343#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003344 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 set_string_default("sh", p);
3346
3347#ifdef FEAT_WILDIGN
3348 /*
3349 * Set the default for 'backupskip' to include environment variables for
3350 * temp files.
3351 */
3352 {
3353# ifdef UNIX
3354 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3355# else
3356 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3357# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003358 int len;
3359 garray_T ga;
3360 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361
3362 ga_init2(&ga, 1, 100);
3363 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3364 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003365 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366# ifdef UNIX
3367 if (*names[n] == NUL)
3368 p = (char_u *)"/tmp";
3369 else
3370# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003371 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003372 if (p != NULL && *p != NUL)
3373 {
3374 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003375 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376 if (ga_grow(&ga, len) == OK)
3377 {
3378 if (ga.ga_len > 0)
3379 STRCAT(ga.ga_data, ",");
3380 STRCAT(ga.ga_data, p);
3381 add_pathsep(ga.ga_data);
3382 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383 ga.ga_len += len;
3384 }
3385 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003386 if (mustfree)
3387 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 }
3389 if (ga.ga_data != NULL)
3390 {
3391 set_string_default("bsk", ga.ga_data);
3392 vim_free(ga.ga_data);
3393 }
3394 }
3395#endif
3396
3397 /*
3398 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3399 */
3400 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003401 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003403#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3404 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3405#endif
3406 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003408 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003409 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003410#else
3411# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003412 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003413 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003415 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003416# endif
3417#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003419 opt_idx = findoption((char_u *)"maxmem");
3420 if (opt_idx >= 0)
3421 {
3422#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003423 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3424 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003425#endif
3426 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3427 }
3428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 }
3430
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431#ifdef FEAT_SEARCHPATH
3432 {
3433 char_u *cdpath;
3434 char_u *buf;
3435 int i;
3436 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003437 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003438
3439 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003440 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003441 if (cdpath != NULL)
3442 {
3443 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3444 if (buf != NULL)
3445 {
3446 buf[0] = ','; /* start with ",", current dir first */
3447 j = 1;
3448 for (i = 0; cdpath[i] != NUL; ++i)
3449 {
3450 if (vim_ispathlistsep(cdpath[i]))
3451 buf[j++] = ',';
3452 else
3453 {
3454 if (cdpath[i] == ' ' || cdpath[i] == ',')
3455 buf[j++] = '\\';
3456 buf[j++] = cdpath[i];
3457 }
3458 }
3459 buf[j] = NUL;
3460 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003461 if (opt_idx >= 0)
3462 {
3463 options[opt_idx].def_val[VI_DEFAULT] = buf;
3464 options[opt_idx].flags |= P_DEF_ALLOCED;
3465 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003466 else
3467 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003468 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003469 if (mustfree)
3470 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003471 }
3472 }
3473#endif
3474
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003475#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476 /* Set print encoding on platforms that don't default to latin1 */
3477 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003478# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003479 (char_u *)"cp1252"
3480# else
3481# ifdef VMS
3482 (char_u *)"dec-mcs"
3483# else
3484# ifdef EBCDIC
3485 (char_u *)"ebcdic-uk"
3486# else
3487# ifdef MAC
3488 (char_u *)"mac-roman"
3489# else /* HPUX */
3490 (char_u *)"hp-roman8"
3491# endif
3492# endif
3493# endif
3494# endif
3495 );
3496#endif
3497
3498#ifdef FEAT_POSTSCRIPT
3499 /* 'printexpr' must be allocated to be able to evaluate it. */
3500 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003501# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003502 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003503# else
3504# ifdef VMS
3505 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3506
3507# else
3508 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3509# endif
3510# endif
3511 );
3512#endif
3513
3514 /*
3515 * Set all the options (except the terminal options) to their default
3516 * value. Also set the global value for local options.
3517 */
3518 set_options_default(0);
3519
3520#ifdef FEAT_GUI
3521 if (found_reverse_arg)
3522 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3523#endif
3524
3525 curbuf->b_p_initialized = TRUE;
3526 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003527 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 check_buf_options(curbuf);
3529 check_win_options(curwin);
3530 check_options();
3531
3532 /* Must be before option_expand(), because that one needs vim_isIDc() */
3533 didset_options();
3534
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003535#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003536 /* Use the current chartab for the generic chartab. This is not in
3537 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003538 init_spell_chartab();
3539#endif
3540
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541 /*
3542 * Expand environment variables and things like "~" for the defaults.
3543 * If option_expand() returns non-NULL the variable is expanded. This can
3544 * only happen for non-indirect options.
3545 * Also set the default to the expanded value, so ":set" does not list
3546 * them.
3547 * Don't set the P_ALLOCED flag, because we don't want to free the
3548 * default.
3549 */
3550 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3551 {
3552 if ((options[opt_idx].flags & P_GETTEXT)
3553 && options[opt_idx].var != NULL)
3554 p = (char_u *)_(*(char **)options[opt_idx].var);
3555 else
3556 p = option_expand(opt_idx, NULL);
3557 if (p != NULL && (p = vim_strsave(p)) != NULL)
3558 {
3559 *(char_u **)options[opt_idx].var = p;
3560 /* VIMEXP
3561 * Defaults for all expanded options are currently the same for Vi
3562 * and Vim. When this changes, add some code here! Also need to
3563 * split P_DEF_ALLOCED in two.
3564 */
3565 if (options[opt_idx].flags & P_DEF_ALLOCED)
3566 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3567 options[opt_idx].def_val[VI_DEFAULT] = p;
3568 options[opt_idx].flags |= P_DEF_ALLOCED;
3569 }
3570 }
3571
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 save_file_ff(curbuf); /* Buffer is unchanged */
3573
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574#if defined(FEAT_ARABIC)
3575 /* Detect use of mlterm.
3576 * Mlterm is a terminal emulator akin to xterm that has some special
3577 * abilities (bidi namely).
3578 * NOTE: mlterm's author is being asked to 'set' a variable
3579 * instead of an environment variable due to inheritance.
3580 */
3581 if (mch_getenv((char_u *)"MLTERM") != NULL)
3582 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3583#endif
3584
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003585 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586
3587#ifdef FEAT_MBYTE
3588# if defined(WIN3264) && defined(FEAT_GETTEXT)
3589 /*
3590 * If $LANG isn't set, try to get a good value for it. This makes the
3591 * right language be used automatically. Don't do this for English.
3592 */
3593 if (mch_getenv((char_u *)"LANG") == NULL)
3594 {
3595 char buf[20];
3596
3597 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3598 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3599 * only the first two. */
3600 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3601 (LPTSTR)buf, 20);
3602 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3603 {
3604 /* There are a few exceptions (probably more) */
3605 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3606 STRCPY(buf, "zh_TW");
3607 else if (STRNICMP(buf, "chs", 3) == 0
3608 || STRNICMP(buf, "zhc", 3) == 0)
3609 STRCPY(buf, "zh_CN");
3610 else if (STRNICMP(buf, "jp", 2) == 0)
3611 STRCPY(buf, "ja");
3612 else
3613 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003614 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003615 }
3616 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003617# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003618# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003619 /* Moved to os_mac_conv.c to avoid dependency problems. */
3620 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003621# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622# endif
3623
3624 /* enc_locale() will try to find the encoding of the current locale. */
3625 p = enc_locale();
3626 if (p != NULL)
3627 {
3628 char_u *save_enc;
3629
3630 /* Try setting 'encoding' and check if the value is valid.
3631 * If not, go back to the default "latin1". */
3632 save_enc = p_enc;
3633 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003634 if (STRCMP(p_enc, "gb18030") == 0)
3635 {
3636 /* We don't support "gb18030", but "cp936" is a good substitute
3637 * for practical purposes, thus use that. It's not an alias to
3638 * still support conversion between gb18030 and utf-8. */
3639 p_enc = vim_strsave((char_u *)"cp936");
3640 vim_free(p);
3641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003642 if (mb_init() == NULL)
3643 {
3644 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003645 if (opt_idx >= 0)
3646 {
3647 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3648 options[opt_idx].flags |= P_DEF_ALLOCED;
3649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003651#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003652 if (STRCMP(p_enc, "latin1") == 0
3653# ifdef FEAT_MBYTE
3654 || enc_utf8
3655# endif
3656 )
3657 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003658 /* Adjust the default for 'isprint' and 'iskeyword' to match
3659 * latin1. Also set the defaults for when 'nocompatible' is
3660 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003661 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003662 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003663 set_string_option_direct((char_u *)"isk", -1,
3664 ISK_LATIN1, OPT_FREE, SID_NONE);
3665 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003666 if (opt_idx >= 0)
3667 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003668 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003669 if (opt_idx >= 0)
3670 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003671 (void)init_chartab();
3672 }
3673#endif
3674
Bram Moolenaar071d4272004-06-13 20:20:40 +00003675# if defined(WIN3264) && !defined(FEAT_GUI)
3676 /* Win32 console: When GetACP() returns a different value from
3677 * GetConsoleCP() set 'termencoding'. */
3678 if (GetACP() != GetConsoleCP())
3679 {
3680 char buf[50];
3681
3682 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3683 p_tenc = vim_strsave((char_u *)buf);
3684 if (p_tenc != NULL)
3685 {
3686 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003687 if (opt_idx >= 0)
3688 {
3689 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3690 options[opt_idx].flags |= P_DEF_ALLOCED;
3691 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692 convert_setup(&input_conv, p_tenc, p_enc);
3693 convert_setup(&output_conv, p_enc, p_tenc);
3694 }
3695 else
3696 p_tenc = empty_option;
3697 }
3698# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003699# if defined(WIN3264) && defined(FEAT_MBYTE)
3700 /* $HOME may have characters in active code page. */
3701 init_homedir();
3702# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703 }
3704 else
3705 {
3706 vim_free(p_enc);
3707 p_enc = save_enc;
3708 }
3709 }
3710#endif
3711
3712#ifdef FEAT_MULTI_LANG
3713 /* Set the default for 'helplang'. */
3714 set_helplang_default(get_mess_lang());
3715#endif
3716}
3717
3718/*
3719 * Set an option to its default value.
3720 * This does not take care of side effects!
3721 */
3722 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003723set_option_default(
3724 int opt_idx,
3725 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3726 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003727{
3728 char_u *varp; /* pointer to variable for current option */
3729 int dvi; /* index in def_val[] */
3730 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003731 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3733
3734 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3735 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003736 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 {
3738 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3739 if (flags & P_STRING)
3740 {
3741 /* Use set_string_option_direct() for local options to handle
3742 * freeing and allocating the value. */
3743 if (options[opt_idx].indir != PV_NONE)
3744 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003745 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003746 else
3747 {
3748 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3749 free_string_option(*(char_u **)(varp));
3750 *(char_u **)varp = options[opt_idx].def_val[dvi];
3751 options[opt_idx].flags &= ~P_ALLOCED;
3752 }
3753 }
3754 else if (flags & P_NUM)
3755 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003756 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757 win_comp_scroll(curwin);
3758 else
3759 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003760 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 /* May also set global value for local option. */
3762 if (both)
3763 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3764 *(long *)varp;
3765 }
3766 }
3767 else /* P_BOOL */
3768 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003769 /* the cast to long is required for Manx C, long_i is needed for
3770 * MSVC */
3771 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003772#ifdef UNIX
3773 /* 'modeline' defaults to off for root */
3774 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3775 *(int *)varp = FALSE;
3776#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 /* May also set global value for local option. */
3778 if (both)
3779 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3780 *(int *)varp;
3781 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003782
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003783 /* The default value is not insecure. */
3784 flagsp = insecure_flag(opt_idx, opt_flags);
3785 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003786 }
3787
3788#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003789 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790#endif
3791}
3792
3793/*
3794 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003795 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003796 */
3797 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003798set_options_default(
3799 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003800{
3801 int i;
3802#ifdef FEAT_WINDOWS
3803 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003804 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805#endif
3806
3807 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003808 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003809#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003810 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003811 || (TRUE
3812# if defined(FEAT_MBYTE)
3813 && options[i].var != (char_u *)&p_enc
3814# endif
3815# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003816 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003817 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003818# endif
3819 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003820#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003821 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 set_option_default(i, opt_flags, p_cp);
3823
3824#ifdef FEAT_WINDOWS
3825 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003826 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003827 win_comp_scroll(wp);
3828#else
3829 win_comp_scroll(curwin);
3830#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003831#ifdef FEAT_CINDENT
3832 parse_cino(curbuf);
3833#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834}
3835
3836/*
3837 * Set the Vi-default value of a string option.
3838 * Used for 'sh', 'backupskip' and 'term'.
3839 */
3840 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003841set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842{
3843 char_u *p;
3844 int opt_idx;
3845
3846 p = vim_strsave(val);
3847 if (p != NULL) /* we don't want a NULL */
3848 {
3849 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003850 if (opt_idx >= 0)
3851 {
3852 if (options[opt_idx].flags & P_DEF_ALLOCED)
3853 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3854 options[opt_idx].def_val[VI_DEFAULT] = p;
3855 options[opt_idx].flags |= P_DEF_ALLOCED;
3856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003857 }
3858}
3859
3860/*
3861 * Set the Vi-default value of a number option.
3862 * Used for 'lines' and 'columns'.
3863 */
3864 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003865set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003866{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003867 int opt_idx;
3868
3869 opt_idx = findoption((char_u *)name);
3870 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003871 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872}
3873
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003874#if defined(EXITFREE) || defined(PROTO)
3875/*
3876 * Free all options.
3877 */
3878 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003879free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003880{
3881 int i;
3882
3883 for (i = 0; !istermoption(&options[i]); i++)
3884 {
3885 if (options[i].indir == PV_NONE)
3886 {
3887 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003888 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003889 free_string_option(*(char_u **)options[i].var);
3890 if (options[i].flags & P_DEF_ALLOCED)
3891 free_string_option(options[i].def_val[VI_DEFAULT]);
3892 }
3893 else if (options[i].var != VAR_WIN
3894 && (options[i].flags & P_STRING))
3895 /* buffer-local option: free global value */
3896 free_string_option(*(char_u **)options[i].var);
3897 }
3898}
3899#endif
3900
3901
Bram Moolenaar071d4272004-06-13 20:20:40 +00003902/*
3903 * Initialize the options, part two: After getting Rows and Columns and
3904 * setting 'term'.
3905 */
3906 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003907set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003909 int idx;
3910
Bram Moolenaar071d4272004-06-13 20:20:40 +00003911 /*
3912 * 'scroll' defaults to half the window height. Note that this default is
3913 * wrong when the window height changes.
3914 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003915 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003916 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003917 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003918 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919 comp_col();
3920
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003921 /*
3922 * 'window' is only for backwards compatibility with Vi.
3923 * Default is Rows - 1.
3924 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003925 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003926 p_window = Rows - 1;
3927 set_number_default("window", Rows - 1);
3928
Bram Moolenaarf740b292006-02-16 22:11:02 +00003929 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003930#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003931 /*
3932 * If 'background' wasn't set by the user, try guessing the value,
3933 * depending on the terminal name. Only need to check for terminals
3934 * with a dark background, that can handle color.
3935 */
3936 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003937 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3938 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003939 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003940 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003941 /* don't mark it as set, when starting the GUI it may be
3942 * changed again */
3943 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003944 }
3945#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003946
3947#ifdef CURSOR_SHAPE
3948 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3949#endif
3950#ifdef FEAT_MOUSESHAPE
3951 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3952#endif
3953#ifdef FEAT_PRINTER
3954 (void)parse_printoptions(); /* parse 'printoptions' default value */
3955#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956}
3957
3958/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003959 * Return "dark" or "light" depending on the kind of terminal.
3960 * This is just guessing! Recognized are:
3961 * "linux" Linux console
3962 * "screen.linux" Linux console with screen
3963 * "cygwin" Cygwin shell
3964 * "putty" Putty program
3965 * We also check the COLORFGBG environment variable, which is set by
3966 * rxvt and derivatives. This variable contains either two or three
3967 * values separated by semicolons; we want the last value in either
3968 * case. If this value is 0-6 or 8, our background is dark.
3969 */
3970 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003971term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003972{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003973#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003974 /* DOS console nearly always black */
3975 return (char_u *)"dark";
3976#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003977 char_u *p;
3978
Bram Moolenaarf740b292006-02-16 22:11:02 +00003979 if (STRCMP(T_NAME, "linux") == 0
3980 || STRCMP(T_NAME, "screen.linux") == 0
3981 || STRCMP(T_NAME, "cygwin") == 0
3982 || STRCMP(T_NAME, "putty") == 0
3983 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3984 && (p = vim_strrchr(p, ';')) != NULL
3985 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3986 && p[2] == NUL))
3987 return (char_u *)"dark";
3988 return (char_u *)"light";
3989#endif
3990}
3991
3992/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993 * Initialize the options, part three: After reading the .vimrc
3994 */
3995 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003996set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003997{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003998#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003999/*
4000 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4001 * This is done after other initializations, where 'shell' might have been
4002 * set, but only if they have not been set before.
4003 */
4004 char_u *p;
4005 int idx_srr;
4006 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004007# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004008 int idx_sp;
4009 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004010# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011
4012 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004013 if (idx_srr < 0)
4014 do_srr = FALSE;
4015 else
4016 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004017# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004019 if (idx_sp < 0)
4020 do_sp = FALSE;
4021 else
4022 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004023# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004024 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004025 if (p != NULL)
4026 {
4027 /*
4028 * Default for p_sp is "| tee", for p_srr is ">".
4029 * For known shells it is changed here to include stderr.
4030 */
4031 if ( fnamecmp(p, "csh") == 0
4032 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004033# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004034 || fnamecmp(p, "csh.exe") == 0
4035 || fnamecmp(p, "tcsh.exe") == 0
4036# endif
4037 )
4038 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004039# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 if (do_sp)
4041 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004042# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004043 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004044# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004046# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4048 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004049# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050 if (do_srr)
4051 {
4052 p_srr = (char_u *)">&";
4053 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4054 }
4055 }
4056 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004057 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 if ( fnamecmp(p, "sh") == 0
4059 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004060 || fnamecmp(p, "mksh") == 0
4061 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004063 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004064 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004065 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004066# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 || fnamecmp(p, "cmd") == 0
4068 || fnamecmp(p, "sh.exe") == 0
4069 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004070 || fnamecmp(p, "mksh.exe") == 0
4071 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004073 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 || fnamecmp(p, "bash.exe") == 0
4075 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004077 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 if (do_sp)
4081 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004082# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004084# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4088 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 if (do_srr)
4091 {
4092 p_srr = (char_u *)">%s 2>&1";
4093 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4094 }
4095 }
4096 vim_free(p);
4097 }
4098#endif
4099
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004100#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004102 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4103 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 * This is done after other initializations, where 'shell' might have been
4105 * set, but only if they have not been set before. Default for p_shcf is
4106 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004107 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004108 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004109 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 {
4111 int idx3;
4112
4113 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004114 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 {
4116 p_shcf = (char_u *)"-c";
4117 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4118 }
4119
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004120# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 /* Somehow Win32 requires the quotes around the redirection too */
4122 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004123 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 {
4125 p_sxq = (char_u *)"\"";
4126 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4127 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004128# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004130 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 {
4132 p_shq = (char_u *)"\"";
4133 options[idx3].def_val[VI_DEFAULT] = p_shq;
4134 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135# endif
4136 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004137 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4138 {
4139 int idx3;
4140
4141 /*
4142 * cmd.exe on Windows will strip the first and last double quote given
4143 * on the command line, e.g. most of the time things like:
4144 * cmd /c "my path/to/echo" "my args to echo"
4145 * become:
4146 * my path/to/echo" "my args to echo
4147 * when executed.
4148 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004149 * To avoid this, set shellxquote to surround the command in
4150 * parenthesis. This appears to make most commands work, without
4151 * breaking commands that worked previously, such as
4152 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004153 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004154 idx3 = findoption((char_u *)"sxq");
4155 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4156 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004157 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004158 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4159 }
4160
Bram Moolenaara64ba222012-02-12 23:23:31 +01004161 idx3 = findoption((char_u *)"shcf");
4162 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4163 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004164 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004165 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4166 }
4167 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004168#endif
4169
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004170 if (bufempty())
4171 {
4172 int idx_ffs = findoption((char_u *)"ffs");
4173
4174 /* Apply the first entry of 'fileformats' to the initial buffer. */
4175 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4176 set_fileformat(default_fileformat(), OPT_LOCAL);
4177 }
4178
Bram Moolenaar071d4272004-06-13 20:20:40 +00004179#ifdef FEAT_TITLE
4180 set_title_defaults();
4181#endif
4182}
4183
4184#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4185/*
4186 * When 'helplang' is still at its default value, set it to "lang".
4187 * Only the first two characters of "lang" are used.
4188 */
4189 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004190set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191{
4192 int idx;
4193
4194 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4195 return;
4196 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004197 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004198 {
4199 if (options[idx].flags & P_ALLOCED)
4200 free_string_option(p_hlg);
4201 p_hlg = vim_strsave(lang);
4202 if (p_hlg == NULL)
4203 p_hlg = empty_option;
4204 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004205 {
4206 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4207 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4208 {
4209 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4210 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4211 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004213 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004214 options[idx].flags |= P_ALLOCED;
4215 }
4216}
4217#endif
4218
4219#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004220static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221
4222 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004223gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224{
4225 if (gui_get_lightness(gui.back_pixel) < 127)
4226 return (char_u *)"dark";
4227 return (char_u *)"light";
4228}
4229
4230/*
4231 * Option initializations that can only be done after opening the GUI window.
4232 */
4233 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004234init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235{
4236 /* Set the 'background' option according to the lightness of the
4237 * background color, unless the user has set it already. */
4238 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4239 {
4240 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4241 highlight_changed();
4242 }
4243}
4244#endif
4245
4246#ifdef FEAT_TITLE
4247/*
4248 * 'title' and 'icon' only default to true if they have not been set or reset
4249 * in .vimrc and we can read the old value.
4250 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4251 * they can be reset. This reduces startup time when using X on a remote
4252 * machine.
4253 */
4254 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004255set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256{
4257 int idx1;
4258 long val;
4259
4260 /*
4261 * If GUI is (going to be) used, we can always set the window title and
4262 * icon name. Saves a bit of time, because the X11 display server does
4263 * not need to be contacted.
4264 */
4265 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004266 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004267 {
4268#ifdef FEAT_GUI
4269 if (gui.starting || gui.in_use)
4270 val = TRUE;
4271 else
4272#endif
4273 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004274 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004275 p_title = val;
4276 }
4277 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004278 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279 {
4280#ifdef FEAT_GUI
4281 if (gui.starting || gui.in_use)
4282 val = TRUE;
4283 else
4284#endif
4285 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004286 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004287 p_icon = val;
4288 }
4289}
4290#endif
4291
4292/*
4293 * Parse 'arg' for option settings.
4294 *
4295 * 'arg' may be IObuff, but only when no errors can be present and option
4296 * does not need to be expanded with option_expand().
4297 * "opt_flags":
4298 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004299 * OPT_GLOBAL for ":setglobal"
4300 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004301 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004302 * OPT_WINONLY to only set window-local options
4303 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004304 *
4305 * returns FAIL if an error is detected, OK otherwise
4306 */
4307 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004308do_set(
4309 char_u *arg, /* option string (may be written to!) */
4310 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311{
4312 int opt_idx;
4313 char_u *errmsg;
4314 char_u errbuf[80];
4315 char_u *startarg;
4316 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4317 int nextchar; /* next non-white char after option name */
4318 int afterchar; /* character just after option name */
4319 int len;
4320 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004321 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004322 int key;
4323 long_u flags; /* flags for current option */
4324 char_u *varp = NULL; /* pointer to variable for current option */
4325 int did_show = FALSE; /* already showed one value */
4326 int adding; /* "opt+=arg" */
4327 int prepending; /* "opt^=arg" */
4328 int removing; /* "opt-=arg" */
4329 int cp_val = 0;
4330 char_u key_name[2];
4331
4332 if (*arg == NUL)
4333 {
4334 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004335 did_show = TRUE;
4336 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004337 }
4338
4339 while (*arg != NUL) /* loop to process all options */
4340 {
4341 errmsg = NULL;
4342 startarg = arg; /* remember for error message */
4343
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004344 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4345 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 {
4347 /*
4348 * ":set all" show all options.
4349 * ":set all&" set all options to their default value.
4350 */
4351 arg += 3;
4352 if (*arg == '&')
4353 {
4354 ++arg;
4355 /* Only for :set command set global value of local options. */
4356 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004357 didset_options();
4358 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004359 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004360 }
4361 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004362 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004363 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004364 did_show = TRUE;
4365 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004366 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004367 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004368 {
4369 showoptions(2, opt_flags);
4370 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004371 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004372 arg += 7;
4373 }
4374 else
4375 {
4376 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004377 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004378 {
4379 prefix = 0;
4380 arg += 2;
4381 }
4382 else if (STRNCMP(arg, "inv", 3) == 0)
4383 {
4384 prefix = 2;
4385 arg += 3;
4386 }
4387
4388 /* find end of name */
4389 key = 0;
4390 if (*arg == '<')
4391 {
4392 nextchar = 0;
4393 opt_idx = -1;
4394 /* look out for <t_>;> */
4395 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4396 len = 5;
4397 else
4398 {
4399 len = 1;
4400 while (arg[len] != NUL && arg[len] != '>')
4401 ++len;
4402 }
4403 if (arg[len] != '>')
4404 {
4405 errmsg = e_invarg;
4406 goto skip;
4407 }
4408 arg[len] = NUL; /* put NUL after name */
4409 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4410 opt_idx = findoption(arg + 1);
4411 arg[len++] = '>'; /* restore '>' */
4412 if (opt_idx == -1)
4413 key = find_key_option(arg + 1);
4414 }
4415 else
4416 {
4417 len = 0;
4418 /*
4419 * The two characters after "t_" may not be alphanumeric.
4420 */
4421 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4422 len = 4;
4423 else
4424 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4425 ++len;
4426 nextchar = arg[len];
4427 arg[len] = NUL; /* put NUL after name */
4428 opt_idx = findoption(arg);
4429 arg[len] = nextchar; /* restore nextchar */
4430 if (opt_idx == -1)
4431 key = find_key_option(arg);
4432 }
4433
4434 /* remember character after option name */
4435 afterchar = arg[len];
4436
4437 /* skip white space, allow ":set ai ?" */
4438 while (vim_iswhite(arg[len]))
4439 ++len;
4440
4441 adding = FALSE;
4442 prepending = FALSE;
4443 removing = FALSE;
4444 if (arg[len] != NUL && arg[len + 1] == '=')
4445 {
4446 if (arg[len] == '+')
4447 {
4448 adding = TRUE; /* "+=" */
4449 ++len;
4450 }
4451 else if (arg[len] == '^')
4452 {
4453 prepending = TRUE; /* "^=" */
4454 ++len;
4455 }
4456 else if (arg[len] == '-')
4457 {
4458 removing = TRUE; /* "-=" */
4459 ++len;
4460 }
4461 }
4462 nextchar = arg[len];
4463
4464 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4465 {
4466 errmsg = (char_u *)N_("E518: Unknown option");
4467 goto skip;
4468 }
4469
4470 if (opt_idx >= 0)
4471 {
4472 if (options[opt_idx].var == NULL) /* hidden option: skip */
4473 {
4474 /* Only give an error message when requesting the value of
4475 * a hidden option, ignore setting it. */
4476 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4477 && (!(options[opt_idx].flags & P_BOOL)
4478 || nextchar == '?'))
4479 errmsg = (char_u *)N_("E519: Option not supported");
4480 goto skip;
4481 }
4482
4483 flags = options[opt_idx].flags;
4484 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4485 }
4486 else
4487 {
4488 flags = P_STRING;
4489 if (key < 0)
4490 {
4491 key_name[0] = KEY2TERMCAP0(key);
4492 key_name[1] = KEY2TERMCAP1(key);
4493 }
4494 else
4495 {
4496 key_name[0] = KS_KEY;
4497 key_name[1] = (key & 0xff);
4498 }
4499 }
4500
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004501 /* Skip all options that are not window-local (used when showing
4502 * an already loaded buffer in a window). */
4503 if ((opt_flags & OPT_WINONLY)
4504 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4505 goto skip;
4506
Bram Moolenaara3227e22006-03-08 21:32:40 +00004507 /* Skip all options that are window-local (used for :vimgrep). */
4508 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4509 && options[opt_idx].var == VAR_WIN)
4510 goto skip;
4511
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004512 /* Disallow changing some options from modelines. */
4513 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004514 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004515 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004516 {
4517 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4518 goto skip;
4519 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004520#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004521 /* In diff mode some options are overruled. This avoids that
4522 * 'foldmethod' becomes "marker" instead of "diff" and that
4523 * "wrap" gets set. */
4524 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004525 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004526 && (options[opt_idx].indir == PV_FDM
4527 || options[opt_idx].indir == PV_WRAP))
4528 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004529#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004530 }
4531
4532#ifdef HAVE_SANDBOX
4533 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004534 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004535 {
4536 errmsg = (char_u *)_(e_sandbox);
4537 goto skip;
4538 }
4539#endif
4540
4541 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4542 {
4543 arg += len;
4544 cp_val = p_cp;
4545 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4546 {
4547 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4548 {
4549 cp_val = FALSE;
4550 arg += 3;
4551 }
4552 else /* "opt&vi": set to Vi default */
4553 {
4554 cp_val = TRUE;
4555 arg += 2;
4556 }
4557 }
4558 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4559 && arg[1] != NUL && !vim_iswhite(arg[1]))
4560 {
4561 errmsg = e_trailing;
4562 goto skip;
4563 }
4564 }
4565
4566 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004567 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4568 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004569 */
4570 if (nextchar == '?'
4571 || (prefix == 1
4572 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4573 && !(flags & P_BOOL)))
4574 {
4575 /*
4576 * print value
4577 */
4578 if (did_show)
4579 msg_putchar('\n'); /* cursor below last one */
4580 else
4581 {
4582 gotocmdline(TRUE); /* cursor at status line */
4583 did_show = TRUE; /* remember that we did a line */
4584 }
4585 if (opt_idx >= 0)
4586 {
4587 showoneopt(&options[opt_idx], opt_flags);
4588#ifdef FEAT_EVAL
4589 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004590 {
4591 /* Mention where the option was last set. */
4592 if (varp == options[opt_idx].var)
4593 last_set_msg(options[opt_idx].scriptID);
4594 else if ((int)options[opt_idx].indir & PV_WIN)
4595 last_set_msg(curwin->w_p_scriptID[
4596 (int)options[opt_idx].indir & PV_MASK]);
4597 else if ((int)options[opt_idx].indir & PV_BUF)
4598 last_set_msg(curbuf->b_p_scriptID[
4599 (int)options[opt_idx].indir & PV_MASK]);
4600 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004601#endif
4602 }
4603 else
4604 {
4605 char_u *p;
4606
4607 p = find_termcode(key_name);
4608 if (p == NULL)
4609 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004610 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611 goto skip;
4612 }
4613 else
4614 (void)show_one_termcode(key_name, p, TRUE);
4615 }
4616 if (nextchar != '?'
4617 && nextchar != NUL && !vim_iswhite(afterchar))
4618 errmsg = e_trailing;
4619 }
4620 else
4621 {
4622 if (flags & P_BOOL) /* boolean */
4623 {
4624 if (nextchar == '=' || nextchar == ':')
4625 {
4626 errmsg = e_invarg;
4627 goto skip;
4628 }
4629
4630 /*
4631 * ":set opt!": invert
4632 * ":set opt&": reset to default value
4633 * ":set opt<": reset to global value
4634 */
4635 if (nextchar == '!')
4636 value = *(int *)(varp) ^ 1;
4637 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004638 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004639 ((flags & P_VI_DEF) || cp_val)
4640 ? VI_DEFAULT : VIM_DEFAULT];
4641 else if (nextchar == '<')
4642 {
4643 /* For 'autoread' -1 means to use global value. */
4644 if ((int *)varp == &curbuf->b_p_ar
4645 && opt_flags == OPT_LOCAL)
4646 value = -1;
4647 else
4648 value = *(int *)get_varp_scope(&(options[opt_idx]),
4649 OPT_GLOBAL);
4650 }
4651 else
4652 {
4653 /*
4654 * ":set invopt": invert
4655 * ":set opt" or ":set noopt": set or reset
4656 */
4657 if (nextchar != NUL && !vim_iswhite(afterchar))
4658 {
4659 errmsg = e_trailing;
4660 goto skip;
4661 }
4662 if (prefix == 2) /* inv */
4663 value = *(int *)(varp) ^ 1;
4664 else
4665 value = prefix;
4666 }
4667
4668 errmsg = set_bool_option(opt_idx, varp, (int)value,
4669 opt_flags);
4670 }
4671 else /* numeric or string */
4672 {
4673 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4674 || prefix != 1)
4675 {
4676 errmsg = e_invarg;
4677 goto skip;
4678 }
4679
4680 if (flags & P_NUM) /* numeric */
4681 {
4682 /*
4683 * Different ways to set a number option:
4684 * & set to default value
4685 * < set to global value
4686 * <xx> accept special key codes for 'wildchar'
4687 * c accept any non-digit for 'wildchar'
4688 * [-]0-9 set number
4689 * other error
4690 */
4691 ++arg;
4692 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004693 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004694 ((flags & P_VI_DEF) || cp_val)
4695 ? VI_DEFAULT : VIM_DEFAULT];
4696 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004697 {
4698 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4699 * use the global value. */
4700 if ((long *)varp == &curbuf->b_p_ul
4701 && opt_flags == OPT_LOCAL)
4702 value = NO_LOCAL_UNDOLEVEL;
4703 else
4704 value = *(long *)get_varp_scope(
4705 &(options[opt_idx]), OPT_GLOBAL);
4706 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004707 else if (((long *)varp == &p_wc
4708 || (long *)varp == &p_wcm)
4709 && (*arg == '<'
4710 || *arg == '^'
Bram Moolenaara12e4032017-02-25 21:37:57 +01004711 || (*arg != NUL && (!arg[1] || vim_iswhite(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004712 && !VIM_ISDIGIT(*arg))))
4713 {
4714 value = string_to_key(arg);
4715 if (value == 0 && (long *)varp != &p_wcm)
4716 {
4717 errmsg = e_invarg;
4718 goto skip;
4719 }
4720 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004721 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4722 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004723 /* Allow negative (for 'undolevels'), octal and
4724 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004725 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4726 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004727 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4728 {
4729 errmsg = e_invarg;
4730 goto skip;
4731 }
4732 }
4733 else
4734 {
4735 errmsg = (char_u *)N_("E521: Number required after =");
4736 goto skip;
4737 }
4738
4739 if (adding)
4740 value = *(long *)varp + value;
4741 if (prepending)
4742 value = *(long *)varp * value;
4743 if (removing)
4744 value = *(long *)varp - value;
4745 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004746 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004747 }
4748 else if (opt_idx >= 0) /* string */
4749 {
4750 char_u *save_arg = NULL;
4751 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004752 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004753 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004754 char_u *origval = NULL;
4755#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4756 char_u *saved_origval = NULL;
4757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004758 unsigned newlen;
4759 int comma;
4760 int bs;
4761 int new_value_alloced; /* new string option
4762 was allocated */
4763
4764 /* When using ":set opt=val" for a global option
4765 * with a local value the local value will be
4766 * reset, use the global value here. */
4767 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004768 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769 varp = options[opt_idx].var;
4770
4771 /* The old value is kept until we are sure that the
4772 * new value is valid. */
4773 oldval = *(char_u **)varp;
4774 if (nextchar == '&') /* set to default val */
4775 {
4776 newval = options[opt_idx].def_val[
4777 ((flags & P_VI_DEF) || cp_val)
4778 ? VI_DEFAULT : VIM_DEFAULT];
4779 if ((char_u **)varp == &p_bg)
4780 {
4781 /* guess the value of 'background' */
4782#ifdef FEAT_GUI
4783 if (gui.in_use)
4784 newval = gui_bg_default();
4785 else
4786#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004787 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004788 }
4789
4790 /* expand environment variables and ~ (since the
4791 * default value was already expanded, only
4792 * required when an environment variable was set
4793 * later */
4794 if (newval == NULL)
4795 newval = empty_option;
4796 else
4797 {
4798 s = option_expand(opt_idx, newval);
4799 if (s == NULL)
4800 s = newval;
4801 newval = vim_strsave(s);
4802 }
4803 new_value_alloced = TRUE;
4804 }
4805 else if (nextchar == '<') /* set to global val */
4806 {
4807 newval = vim_strsave(*(char_u **)get_varp_scope(
4808 &(options[opt_idx]), OPT_GLOBAL));
4809 new_value_alloced = TRUE;
4810 }
4811 else
4812 {
4813 ++arg; /* jump to after the '=' or ':' */
4814
4815 /*
4816 * Set 'keywordprg' to ":help" if an empty
4817 * value was passed to :set by the user.
4818 * Misuse errbuf[] for the resulting string.
4819 */
4820 if (varp == (char_u *)&p_kp
4821 && (*arg == NUL || *arg == ' '))
4822 {
4823 STRCPY(errbuf, ":help");
4824 save_arg = arg;
4825 arg = errbuf;
4826 }
4827 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004828 * Convert 'backspace' number to string, for
4829 * adding, prepending and removing string.
4830 */
4831 else if (varp == (char_u *)&p_bs
4832 && VIM_ISDIGIT(**(char_u **)varp))
4833 {
4834 i = getdigits((char_u **)varp);
4835 switch (i)
4836 {
4837 case 0:
4838 *(char_u **)varp = empty_option;
4839 break;
4840 case 1:
4841 *(char_u **)varp = vim_strsave(
4842 (char_u *)"indent,eol");
4843 break;
4844 case 2:
4845 *(char_u **)varp = vim_strsave(
4846 (char_u *)"indent,eol,start");
4847 break;
4848 }
4849 vim_free(oldval);
4850 oldval = *(char_u **)varp;
4851 }
4852 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004853 * Convert 'whichwrap' number to string, for
4854 * backwards compatibility with Vim 3.0.
4855 * Misuse errbuf[] for the resulting string.
4856 */
4857 else if (varp == (char_u *)&p_ww
4858 && VIM_ISDIGIT(*arg))
4859 {
4860 *errbuf = NUL;
4861 i = getdigits(&arg);
4862 if (i & 1)
4863 STRCAT(errbuf, "b,");
4864 if (i & 2)
4865 STRCAT(errbuf, "s,");
4866 if (i & 4)
4867 STRCAT(errbuf, "h,l,");
4868 if (i & 8)
4869 STRCAT(errbuf, "<,>,");
4870 if (i & 16)
4871 STRCAT(errbuf, "[,],");
4872 if (*errbuf != NUL) /* remove trailing , */
4873 errbuf[STRLEN(errbuf) - 1] = NUL;
4874 save_arg = arg;
4875 arg = errbuf;
4876 }
4877 /*
4878 * Remove '>' before 'dir' and 'bdir', for
4879 * backwards compatibility with version 3.0
4880 */
4881 else if ( *arg == '>'
4882 && (varp == (char_u *)&p_dir
4883 || varp == (char_u *)&p_bdir))
4884 {
4885 ++arg;
4886 }
4887
4888 /* When setting the local value of a global
4889 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004890 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004891 && (opt_flags & OPT_LOCAL))
4892 origval = *(char_u **)get_varp(
4893 &options[opt_idx]);
4894 else
4895 origval = oldval;
4896
4897 /*
4898 * Copy the new string into allocated memory.
4899 * Can't use set_string_option_direct(), because
4900 * we need to remove the backslashes.
4901 */
4902 /* get a bit too much */
4903 newlen = (unsigned)STRLEN(arg) + 1;
4904 if (adding || prepending || removing)
4905 newlen += (unsigned)STRLEN(origval) + 1;
4906 newval = alloc(newlen);
4907 if (newval == NULL) /* out of mem, don't change */
4908 break;
4909 s = newval;
4910
4911 /*
4912 * Copy the string, skip over escaped chars.
4913 * For MS-DOS and WIN32 backslashes before normal
4914 * file name characters are not removed, and keep
4915 * backslash at start, for "\\machine\path", but
4916 * do remove it for "\\\\machine\\path".
4917 * The reverse is found in ExpandOldSetting().
4918 */
4919 while (*arg && !vim_iswhite(*arg))
4920 {
4921 if (*arg == '\\' && arg[1] != NUL
4922#ifdef BACKSLASH_IN_FILENAME
4923 && !((flags & P_EXPAND)
4924 && vim_isfilec(arg[1])
4925 && (arg[1] != '\\'
4926 || (s == newval
4927 && arg[2] != '\\')))
4928#endif
4929 )
4930 ++arg; /* remove backslash */
4931#ifdef FEAT_MBYTE
4932 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004933 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004934 {
4935 /* copy multibyte char */
4936 mch_memmove(s, arg, (size_t)i);
4937 arg += i;
4938 s += i;
4939 }
4940 else
4941#endif
4942 *s++ = *arg++;
4943 }
4944 *s = NUL;
4945
4946 /*
4947 * Expand environment variables and ~.
4948 * Don't do it when adding without inserting a
4949 * comma.
4950 */
4951 if (!(adding || prepending || removing)
4952 || (flags & P_COMMA))
4953 {
4954 s = option_expand(opt_idx, newval);
4955 if (s != NULL)
4956 {
4957 vim_free(newval);
4958 newlen = (unsigned)STRLEN(s) + 1;
4959 if (adding || prepending || removing)
4960 newlen += (unsigned)STRLEN(origval) + 1;
4961 newval = alloc(newlen);
4962 if (newval == NULL)
4963 break;
4964 STRCPY(newval, s);
4965 }
4966 }
4967
4968 /* locate newval[] in origval[] when removing it
4969 * and when adding to avoid duplicates */
4970 i = 0; /* init for GCC */
4971 if (removing || (flags & P_NODUP))
4972 {
4973 i = (int)STRLEN(newval);
4974 bs = 0;
4975 for (s = origval; *s; ++s)
4976 {
4977 if ((!(flags & P_COMMA)
4978 || s == origval
4979 || (s[-1] == ',' && !(bs & 1)))
4980 && STRNCMP(s, newval, i) == 0
4981 && (!(flags & P_COMMA)
4982 || s[i] == ','
4983 || s[i] == NUL))
4984 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004985 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004986 * even number of backslashes or a single
4987 * backslash preceded by a comma before it
4988 * is recognized as a separator */
4989 if ((s > origval + 1
4990 && s[-1] == '\\'
4991 && s[-2] != ',')
4992 || (s == origval + 1
4993 && s[-1] == '\\'))
4994
Bram Moolenaar071d4272004-06-13 20:20:40 +00004995 ++bs;
4996 else
4997 bs = 0;
4998 }
4999
5000 /* do not add if already there */
5001 if ((adding || prepending) && *s)
5002 {
5003 prepending = FALSE;
5004 adding = FALSE;
5005 STRCPY(newval, origval);
5006 }
5007 }
5008
5009 /* concatenate the two strings; add a ',' if
5010 * needed */
5011 if (adding || prepending)
5012 {
5013 comma = ((flags & P_COMMA) && *origval != NUL
5014 && *newval != NUL);
5015 if (adding)
5016 {
5017 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005018 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005019 if (comma && i > 1
5020 && (flags & P_ONECOMMA) == P_ONECOMMA
5021 && origval[i - 1] == ','
5022 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005023 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005024 mch_memmove(newval + i + comma, newval,
5025 STRLEN(newval) + 1);
5026 mch_memmove(newval, origval, (size_t)i);
5027 }
5028 else
5029 {
5030 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005031 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005032 }
5033 if (comma)
5034 newval[i] = ',';
5035 }
5036
5037 /* Remove newval[] from origval[]. (Note: "i" has
5038 * been set above and is used here). */
5039 if (removing)
5040 {
5041 STRCPY(newval, origval);
5042 if (*s)
5043 {
5044 /* may need to remove a comma */
5045 if (flags & P_COMMA)
5046 {
5047 if (s == origval)
5048 {
5049 /* include comma after string */
5050 if (s[i] == ',')
5051 ++i;
5052 }
5053 else
5054 {
5055 /* include comma before string */
5056 --s;
5057 ++i;
5058 }
5059 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005060 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005061 }
5062 }
5063
5064 if (flags & P_FLAGLIST)
5065 {
5066 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005067 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005068 {
5069 /* if options have P_FLAGLIST and
5070 * P_ONECOMMA such as 'whichwrap' */
5071 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005072 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005073 if (*s != ',' && *(s + 1) == ','
5074 && vim_strchr(s + 2, *s) != NULL)
5075 {
5076 /* Remove the duplicated value and
5077 * the next comma. */
5078 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005079 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005080 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005081 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005082 else
5083 {
5084 if ((!(flags & P_COMMA) || *s != ',')
5085 && vim_strchr(s + 1, *s) != NULL)
5086 {
5087 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005088 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005089 }
5090 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005091 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005092 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005093 }
5094
5095 if (save_arg != NULL) /* number for 'whichwrap' */
5096 arg = save_arg;
5097 new_value_alloced = TRUE;
5098 }
5099
5100 /* Set the new value. */
5101 *(char_u **)(varp) = newval;
5102
Bram Moolenaar53744302015-07-17 17:38:22 +02005103#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005104 if (!starting
5105# ifdef FEAT_CRYPT
5106 && options[opt_idx].indir != PV_KEY
5107# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02005108 && origval != NULL)
5109 /* origval may be freed by
5110 * did_set_string_option(), make a copy. */
5111 saved_origval = vim_strsave(origval);
5112#endif
5113
Bram Moolenaar071d4272004-06-13 20:20:40 +00005114 /* Handle side effects, and set the global value for
5115 * ":set" on local options. */
5116 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5117 new_value_alloced, oldval, errbuf, opt_flags);
5118
5119 /* If error detected, print the error message. */
5120 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005121 {
5122#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5123 vim_free(saved_origval);
5124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005125 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005126 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005127#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5128 if (saved_origval != NULL)
5129 {
5130 char_u buf_type[7];
5131
5132 sprintf((char *)buf_type, "%s",
5133 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005134 set_vim_var_string(VV_OPTION_NEW,
5135 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005136 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5137 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5138 apply_autocmds(EVENT_OPTIONSET,
5139 (char_u *)options[opt_idx].fullname,
5140 NULL, FALSE, NULL);
5141 reset_v_option_vars();
5142 vim_free(saved_origval);
5143 }
5144#endif
5145
Bram Moolenaar071d4272004-06-13 20:20:40 +00005146 }
5147 else /* key code option */
5148 {
5149 char_u *p;
5150
5151 if (nextchar == '&')
5152 {
5153 if (add_termcap_entry(key_name, TRUE) == FAIL)
5154 errmsg = (char_u *)N_("E522: Not found in termcap");
5155 }
5156 else
5157 {
5158 ++arg; /* jump to after the '=' or ':' */
5159 for (p = arg; *p && !vim_iswhite(*p); ++p)
5160 if (*p == '\\' && p[1] != NUL)
5161 ++p;
5162 nextchar = *p;
5163 *p = NUL;
5164 add_termcode(key_name, arg, FALSE);
5165 *p = nextchar;
5166 }
5167 if (full_screen)
5168 ttest(FALSE);
5169 redraw_all_later(CLEAR);
5170 }
5171 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005172
Bram Moolenaar071d4272004-06-13 20:20:40 +00005173 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005174 did_set_option(opt_idx, opt_flags,
5175 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005176 }
5177
5178skip:
5179 /*
5180 * Advance to next argument.
5181 * - skip until a blank found, taking care of backslashes
5182 * - skip blanks
5183 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5184 */
5185 for (i = 0; i < 2 ; ++i)
5186 {
5187 while (*arg != NUL && !vim_iswhite(*arg))
5188 if (*arg++ == '\\' && *arg != NUL)
5189 ++arg;
5190 arg = skipwhite(arg);
5191 if (*arg != '=')
5192 break;
5193 }
5194 }
5195
5196 if (errmsg != NULL)
5197 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005198 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005199 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005200 if (i + (arg - startarg) < IOSIZE)
5201 {
5202 /* append the argument with the error */
5203 STRCAT(IObuff, ": ");
5204 mch_memmove(IObuff + i, startarg, (arg - startarg));
5205 IObuff[i + (arg - startarg)] = NUL;
5206 }
5207 /* make sure all characters are printable */
5208 trans_characters(IObuff, IOSIZE);
5209
5210 ++no_wait_return; /* wait_return done later */
5211 emsg(IObuff); /* show error highlighted */
5212 --no_wait_return;
5213
5214 return FAIL;
5215 }
5216
5217 arg = skipwhite(arg);
5218 }
5219
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005220theend:
5221 if (silent_mode && did_show)
5222 {
5223 /* After displaying option values in silent mode. */
5224 silent_mode = FALSE;
5225 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5226 msg_putchar('\n');
5227 cursor_on(); /* msg_start() switches it off */
5228 out_flush();
5229 silent_mode = TRUE;
5230 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5231 }
5232
Bram Moolenaar071d4272004-06-13 20:20:40 +00005233 return OK;
5234}
5235
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005236/*
5237 * Call this when an option has been given a new value through a user command.
5238 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5239 */
5240 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005241did_set_option(
5242 int opt_idx,
5243 int opt_flags, /* possibly with OPT_MODELINE */
5244 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005245{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005246 long_u *p;
5247
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005248 options[opt_idx].flags |= P_WAS_SET;
5249
5250 /* When an option is set in the sandbox, from a modeline or in secure mode
5251 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005252 * flag. */
5253 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005254 if (secure
5255#ifdef HAVE_SANDBOX
5256 || sandbox != 0
5257#endif
5258 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005259 *p = *p | P_INSECURE;
5260 else if (new_value)
5261 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005262}
5263
Bram Moolenaar071d4272004-06-13 20:20:40 +00005264 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005265illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005266{
5267 if (errbuf == NULL)
5268 return (char_u *)"";
5269 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005270 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005271 return errbuf;
5272}
5273
5274/*
5275 * Convert a key name or string into a key value.
5276 * Used for 'wildchar' and 'cedit' options.
5277 */
5278 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005279string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005280{
5281 if (*arg == '<')
5282 return find_key_option(arg + 1);
5283 if (*arg == '^')
5284 return Ctrl_chr(arg[1]);
5285 return *arg;
5286}
5287
5288#ifdef FEAT_CMDWIN
5289/*
5290 * Check value of 'cedit' and set cedit_key.
5291 * Returns NULL if value is OK, error message otherwise.
5292 */
5293 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005294check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005295{
5296 int n;
5297
5298 if (*p_cedit == NUL)
5299 cedit_key = -1;
5300 else
5301 {
5302 n = string_to_key(p_cedit);
5303 if (vim_isprintc(n))
5304 return e_invarg;
5305 cedit_key = n;
5306 }
5307 return NULL;
5308}
5309#endif
5310
5311#ifdef FEAT_TITLE
5312/*
5313 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5314 * maketitle() to create and display it.
5315 * When switching the title or icon off, call mch_restore_title() to get
5316 * the old value back.
5317 */
5318 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005319did_set_title(
5320 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005321{
5322 if (starting != NO_SCREEN
5323#ifdef FEAT_GUI
5324 && !gui.starting
5325#endif
5326 )
5327 {
5328 maketitle();
5329 if (icon)
5330 {
5331 if (!p_icon)
5332 mch_restore_title(2);
5333 }
5334 else
5335 {
5336 if (!p_title)
5337 mch_restore_title(1);
5338 }
5339 }
5340}
5341#endif
5342
5343/*
5344 * set_options_bin - called when 'bin' changes value.
5345 */
5346 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005347set_options_bin(
5348 int oldval,
5349 int newval,
5350 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351{
5352 /*
5353 * The option values that are changed when 'bin' changes are
5354 * copied when 'bin is set and restored when 'bin' is reset.
5355 */
5356 if (newval)
5357 {
5358 if (!oldval) /* switched on */
5359 {
5360 if (!(opt_flags & OPT_GLOBAL))
5361 {
5362 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5363 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5364 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5365 curbuf->b_p_et_nobin = curbuf->b_p_et;
5366 }
5367 if (!(opt_flags & OPT_LOCAL))
5368 {
5369 p_tw_nobin = p_tw;
5370 p_wm_nobin = p_wm;
5371 p_ml_nobin = p_ml;
5372 p_et_nobin = p_et;
5373 }
5374 }
5375
5376 if (!(opt_flags & OPT_GLOBAL))
5377 {
5378 curbuf->b_p_tw = 0; /* no automatic line wrap */
5379 curbuf->b_p_wm = 0; /* no automatic line wrap */
5380 curbuf->b_p_ml = 0; /* no modelines */
5381 curbuf->b_p_et = 0; /* no expandtab */
5382 }
5383 if (!(opt_flags & OPT_LOCAL))
5384 {
5385 p_tw = 0;
5386 p_wm = 0;
5387 p_ml = FALSE;
5388 p_et = FALSE;
5389 p_bin = TRUE; /* needed when called for the "-b" argument */
5390 }
5391 }
5392 else if (oldval) /* switched off */
5393 {
5394 if (!(opt_flags & OPT_GLOBAL))
5395 {
5396 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5397 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5398 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5399 curbuf->b_p_et = curbuf->b_p_et_nobin;
5400 }
5401 if (!(opt_flags & OPT_LOCAL))
5402 {
5403 p_tw = p_tw_nobin;
5404 p_wm = p_wm_nobin;
5405 p_ml = p_ml_nobin;
5406 p_et = p_et_nobin;
5407 }
5408 }
5409}
5410
5411#ifdef FEAT_VIMINFO
5412/*
5413 * Find the parameter represented by the given character (eg ', :, ", or /),
5414 * and return its associated value in the 'viminfo' string.
5415 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005416 * If the parameter is not specified in the string or there is no following
5417 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005418 */
5419 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005420get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005421{
5422 char_u *p;
5423
5424 p = find_viminfo_parameter(type);
5425 if (p != NULL && VIM_ISDIGIT(*p))
5426 return atoi((char *)p);
5427 return -1;
5428}
5429
5430/*
5431 * Find the parameter represented by the given character (eg ''', ':', '"', or
5432 * '/') in the 'viminfo' option and return a pointer to the string after it.
5433 * Return NULL if the parameter is not specified in the string.
5434 */
5435 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005436find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005437{
5438 char_u *p;
5439
5440 for (p = p_viminfo; *p; ++p)
5441 {
5442 if (*p == type)
5443 return p + 1;
5444 if (*p == 'n') /* 'n' is always the last one */
5445 break;
5446 p = vim_strchr(p, ','); /* skip until next ',' */
5447 if (p == NULL) /* hit the end without finding parameter */
5448 break;
5449 }
5450 return NULL;
5451}
5452#endif
5453
5454/*
5455 * Expand environment variables for some string options.
5456 * These string options cannot be indirect!
5457 * If "val" is NULL expand the current value of the option.
5458 * Return pointer to NameBuff, or NULL when not expanded.
5459 */
5460 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005461option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462{
5463 /* if option doesn't need expansion nothing to do */
5464 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5465 return NULL;
5466
5467 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5468 * expand_env() would truncate the string. */
5469 if (val != NULL && STRLEN(val) > MAXPATHL)
5470 return NULL;
5471
5472 if (val == NULL)
5473 val = *(char_u **)options[opt_idx].var;
5474
5475 /*
5476 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5477 * Escape spaces when expanding 'tags', they are used to separate file
5478 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005479 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005480 */
5481 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005482 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005483#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005484 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5485#endif
5486 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005487 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5488 return NULL;
5489
5490 return NameBuff;
5491}
5492
5493/*
5494 * After setting various option values: recompute variables that depend on
5495 * option values.
5496 */
5497 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005498didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005499{
5500 /* initialize the table for 'iskeyword' et.al. */
5501 (void)init_chartab();
5502
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005503#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005505#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005506 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005507 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508#ifdef FEAT_SESSION
5509 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5510 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5511#endif
5512#ifdef FEAT_FOLDING
5513 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5514#endif
5515 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005516 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517#ifdef FEAT_VIRTUALEDIT
5518 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5519#endif
5520#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5521 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5522#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005523#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005524 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005525 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005526 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005527 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005528#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5530 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5531#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005532#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5534#endif
5535#ifdef FEAT_CMDWIN
5536 /* set cedit_key */
5537 (void)check_cedit();
5538#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005539#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005540 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005541#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005542#ifdef FEAT_LINEBREAK
5543 /* initialize the table for 'breakat'. */
5544 fill_breakat_flags();
5545#endif
5546
5547}
5548
5549/*
5550 * More side effects of setting options.
5551 */
5552 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005553didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005554{
5555 /* Initialize the highlight_attr[] table. */
5556 (void)highlight_changed();
5557
5558 /* Parse default for 'wildmode' */
5559 check_opt_wim();
5560
5561 (void)set_chars_option(&p_lcs);
5562#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5563 /* Parse default for 'fillchars'. */
5564 (void)set_chars_option(&p_fcs);
5565#endif
5566
5567#ifdef FEAT_CLIPBOARD
5568 /* Parse default for 'clipboard' */
5569 (void)check_clipboard_option();
5570#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571}
5572
5573/*
5574 * Check for string options that are NULL (normally only termcap options).
5575 */
5576 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005577check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578{
5579 int opt_idx;
5580
5581 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5582 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5583 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5584}
5585
5586/*
5587 * Check string options in a buffer for NULL value.
5588 */
5589 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005590check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591{
5592#if defined(FEAT_QUICKFIX)
5593 check_string_option(&buf->b_p_bh);
5594 check_string_option(&buf->b_p_bt);
5595#endif
5596#ifdef FEAT_MBYTE
5597 check_string_option(&buf->b_p_fenc);
5598#endif
5599 check_string_option(&buf->b_p_ff);
5600#ifdef FEAT_FIND_ID
5601 check_string_option(&buf->b_p_def);
5602 check_string_option(&buf->b_p_inc);
5603# ifdef FEAT_EVAL
5604 check_string_option(&buf->b_p_inex);
5605# endif
5606#endif
5607#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5608 check_string_option(&buf->b_p_inde);
5609 check_string_option(&buf->b_p_indk);
5610#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005611#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5612 check_string_option(&buf->b_p_bexpr);
5613#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005614#if defined(FEAT_CRYPT)
5615 check_string_option(&buf->b_p_cm);
5616#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005617 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005618#if defined(FEAT_EVAL)
5619 check_string_option(&buf->b_p_fex);
5620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005621#ifdef FEAT_CRYPT
5622 check_string_option(&buf->b_p_key);
5623#endif
5624 check_string_option(&buf->b_p_kp);
5625 check_string_option(&buf->b_p_mps);
5626 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005627 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005628 check_string_option(&buf->b_p_isk);
5629#ifdef FEAT_COMMENTS
5630 check_string_option(&buf->b_p_com);
5631#endif
5632#ifdef FEAT_FOLDING
5633 check_string_option(&buf->b_p_cms);
5634#endif
5635 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005636#ifdef FEAT_TEXTOBJ
5637 check_string_option(&buf->b_p_qe);
5638#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639#ifdef FEAT_SYN_HL
5640 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005641 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005642#endif
5643#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005644 check_string_option(&buf->b_s.b_p_spc);
5645 check_string_option(&buf->b_s.b_p_spf);
5646 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005647#endif
5648#ifdef FEAT_SEARCHPATH
5649 check_string_option(&buf->b_p_sua);
5650#endif
5651#ifdef FEAT_CINDENT
5652 check_string_option(&buf->b_p_cink);
5653 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005654 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005655#endif
5656#ifdef FEAT_AUTOCMD
5657 check_string_option(&buf->b_p_ft);
5658#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005659#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5660 check_string_option(&buf->b_p_cinw);
5661#endif
5662#ifdef FEAT_INS_EXPAND
5663 check_string_option(&buf->b_p_cpt);
5664#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005665#ifdef FEAT_COMPL_FUNC
5666 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005667 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005668#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005669#ifdef FEAT_KEYMAP
5670 check_string_option(&buf->b_p_keymap);
5671#endif
5672#ifdef FEAT_QUICKFIX
5673 check_string_option(&buf->b_p_gp);
5674 check_string_option(&buf->b_p_mp);
5675 check_string_option(&buf->b_p_efm);
5676#endif
5677 check_string_option(&buf->b_p_ep);
5678 check_string_option(&buf->b_p_path);
5679 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005680 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681#ifdef FEAT_INS_EXPAND
5682 check_string_option(&buf->b_p_dict);
5683 check_string_option(&buf->b_p_tsr);
5684#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005685#ifdef FEAT_LISP
5686 check_string_option(&buf->b_p_lw);
5687#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005688 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689}
5690
5691/*
5692 * Free the string allocated for an option.
5693 * Checks for the string being empty_option. This may happen if we're out of
5694 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5695 * check_options().
5696 * Does NOT check for P_ALLOCED flag!
5697 */
5698 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005699free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700{
5701 if (p != empty_option)
5702 vim_free(p);
5703}
5704
5705 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005706clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707{
5708 if (*pp != empty_option)
5709 vim_free(*pp);
5710 *pp = empty_option;
5711}
5712
5713 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005714check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005715{
5716 if (*pp == NULL)
5717 *pp = empty_option;
5718}
5719
5720/*
5721 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5722 */
5723 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005724set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725{
5726 int opt_idx;
5727
5728 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5729 if (options[opt_idx].var == (char_u *)p)
5730 {
5731 options[opt_idx].flags |= P_ALLOCED;
5732 return;
5733 }
5734 return; /* cannot happen: didn't find it! */
5735}
5736
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005737#if defined(FEAT_EVAL) || defined(PROTO)
5738/*
5739 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5740 * Return FALSE when it wasn't.
5741 * Return -1 for an unknown option.
5742 */
5743 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005744was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005745{
5746 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005747 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005748
5749 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005750 {
5751 flagp = insecure_flag(idx, opt_flags);
5752 return (*flagp & P_INSECURE) != 0;
5753 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005754 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005755 return -1;
5756}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005757
5758/*
5759 * Get a pointer to the flags used for the P_INSECURE flag of option
5760 * "opt_idx". For some local options a local flags field is used.
5761 */
5762 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005763insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005764{
5765 if (opt_flags & OPT_LOCAL)
5766 switch ((int)options[opt_idx].indir)
5767 {
5768#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005769 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005770#endif
5771#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005772# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005773 case PV_FDE: return &curwin->w_p_fde_flags;
5774 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005775# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005776# ifdef FEAT_BEVAL
5777 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5778# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005779# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005780 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005781# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005782 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005783# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005784 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005785# endif
5786#endif
5787 }
5788
5789 /* Nothing special, return global flags field. */
5790 return &options[opt_idx].flags;
5791}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005792#endif
5793
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005794#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005795static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005796
5797/*
5798 * Redraw the window title and/or tab page text later.
5799 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005800static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005801{
5802 need_maketitle = TRUE;
5803# ifdef FEAT_WINDOWS
5804 redraw_tabline = TRUE;
5805# endif
5806}
5807#endif
5808
Bram Moolenaar071d4272004-06-13 20:20:40 +00005809/*
5810 * Set a string option to a new value (without checking the effect).
5811 * The string is copied into allocated memory.
5812 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005813 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005814 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005815 */
5816 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005817set_string_option_direct(
5818 char_u *name,
5819 int opt_idx,
5820 char_u *val,
5821 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5822 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005823{
5824 char_u *s;
5825 char_u **varp;
5826 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005827 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005828
Bram Moolenaar89d40322006-08-29 15:30:07 +00005829 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005830 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005831 idx = findoption(name);
5832 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005833 {
5834 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005835 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005836 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005837 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005838 }
5839
Bram Moolenaar89d40322006-08-29 15:30:07 +00005840 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005841 return;
5842
5843 s = vim_strsave(val);
5844 if (s != NULL)
5845 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005846 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005848 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849 free_string_option(*varp);
5850 *varp = s;
5851
5852 /* For buffer/window local option may also set the global value. */
5853 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005854 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005855
Bram Moolenaar89d40322006-08-29 15:30:07 +00005856 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005857
5858 /* When setting both values of a global option with a local value,
5859 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005860 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005861 {
5862 free_string_option(*varp);
5863 *varp = empty_option;
5864 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005865# ifdef FEAT_EVAL
5866 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005867 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005868 set_sid == 0 ? current_SID : set_sid);
5869# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870 }
5871}
5872
5873/*
5874 * Set global value for string option when it's a local option.
5875 */
5876 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005877set_string_option_global(
5878 int opt_idx, /* option index */
5879 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880{
5881 char_u **p, *s;
5882
5883 /* the global value is always allocated */
5884 if (options[opt_idx].var == VAR_WIN)
5885 p = (char_u **)GLOBAL_WO(varp);
5886 else
5887 p = (char_u **)options[opt_idx].var;
5888 if (options[opt_idx].indir != PV_NONE
5889 && p != varp
5890 && (s = vim_strsave(*varp)) != NULL)
5891 {
5892 free_string_option(*p);
5893 *p = s;
5894 }
5895}
5896
5897/*
5898 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005899 *
5900 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005901 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005902 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005903set_string_option(
5904 int opt_idx,
5905 char_u *value,
5906 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907{
5908 char_u *s;
5909 char_u **varp;
5910 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005911#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5912 char_u *saved_oldval = NULL;
5913#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005914 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005915
5916 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005917 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918
5919 s = vim_strsave(value);
5920 if (s != NULL)
5921 {
5922 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5923 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005924 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005925 ? OPT_GLOBAL : OPT_LOCAL)
5926 : opt_flags);
5927 oldval = *varp;
5928 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005929
5930#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005931 if (!starting
5932# ifdef FEAT_CRYPT
5933 && options[opt_idx].indir != PV_KEY
5934# endif
5935 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005936 saved_oldval = vim_strsave(oldval);
5937#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005938 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5939 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005940 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005941
Bram Moolenaara12e4032017-02-25 21:37:57 +01005942 /* call autocommand after handling side effects */
Bram Moolenaar53744302015-07-17 17:38:22 +02005943#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5944 if (saved_oldval != NULL)
5945 {
5946 char_u buf_type[7];
5947 sprintf((char *)buf_type, "%s",
5948 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005949 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5950 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005951 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5952 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5953 reset_v_option_vars();
5954 vim_free(saved_oldval);
5955 }
5956#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005957 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005958 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959}
5960
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005961#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005962/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005963 * Return TRUE if "val" is a valid 'filetype' name.
5964 * Also used for 'syntax' and 'keymap'.
5965 */
5966 static int
5967valid_filetype(char_u *val)
5968{
5969 char_u *s;
5970
5971 for (s = val; *s != NUL; ++s)
5972 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5973 return FALSE;
5974 return TRUE;
5975}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005976#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005977
5978/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005979 * Handle string options that need some action to perform when changed.
5980 * Returns NULL for success, or an error message for an error.
5981 */
5982 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005983did_set_string_option(
5984 int opt_idx, /* index in options[] table */
5985 char_u **varp, /* pointer to the option variable */
5986 int new_value_alloced, /* new value was allocated */
5987 char_u *oldval, /* previous value of the option */
5988 char_u *errbuf, /* buffer for errors, or NULL */
5989 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990{
5991 char_u *errmsg = NULL;
5992 char_u *s, *p;
5993 int did_chartab = FALSE;
5994 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005995 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005996#ifdef FEAT_GUI
5997 /* set when changing an option that only requires a redraw in the GUI */
5998 int redraw_gui_only = FALSE;
5999#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006000
6001 /* Get the global option to compare with, otherwise we would have to check
6002 * two values for all local options. */
6003 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6004
6005 /* Disallow changing some options from secure mode */
6006 if ((secure
6007#ifdef HAVE_SANDBOX
6008 || sandbox != 0
6009#endif
6010 ) && (options[opt_idx].flags & P_SECURE))
6011 {
6012 errmsg = e_secure;
6013 }
6014
Bram Moolenaar7554da42016-11-25 22:04:13 +01006015 /* Check for a "normal" directory or file name in some options. Disallow a
6016 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006017 * are often illegal in a file name. Be more permissive if "secure" is off.
6018 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01006019 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006020 && vim_strpbrk(*varp, (char_u *)(secure
6021 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006022 || ((options[opt_idx].flags & P_NDNAME)
6023 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006024 {
6025 errmsg = e_invarg;
6026 }
6027
Bram Moolenaar071d4272004-06-13 20:20:40 +00006028 /* 'term' */
6029 else if (varp == &T_NAME)
6030 {
6031 if (T_NAME[0] == NUL)
6032 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
6033#ifdef FEAT_GUI
6034 if (gui.in_use)
6035 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
6036 else if (term_is_gui(T_NAME))
6037 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
6038#endif
6039 else if (set_termname(T_NAME) == FAIL)
6040 errmsg = (char_u *)N_("E522: Not found in termcap");
6041 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006042 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006043 /* Screen colors may have changed. */
6044 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006045
6046 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6047 * P_ALLOCED flag on 'term'. */
6048 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006049 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006050 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006051 }
6052
6053 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006054 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006055 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006056 char_u *bkc = p_bkc;
6057 unsigned int *flags = &bkc_flags;
6058
6059 if (opt_flags & OPT_LOCAL)
6060 {
6061 bkc = curbuf->b_p_bkc;
6062 flags = &curbuf->b_bkc_flags;
6063 }
6064
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006065 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6066 /* make the local value empty: use the global value */
6067 *flags = 0;
6068 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006069 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006070 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6071 errmsg = e_invarg;
6072 if ((((int)*flags & BKC_AUTO) != 0)
6073 + (((int)*flags & BKC_YES) != 0)
6074 + (((int)*flags & BKC_NO) != 0) != 1)
6075 {
6076 /* Must have exactly one of "auto", "yes" and "no". */
6077 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6078 errmsg = e_invarg;
6079 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006080 }
6081 }
6082
6083 /* 'backupext' and 'patchmode' */
6084 else if (varp == &p_bex || varp == &p_pm)
6085 {
6086 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6087 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
6088 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
6089 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006090#ifdef FEAT_LINEBREAK
6091 /* 'breakindentopt' */
6092 else if (varp == &curwin->w_p_briopt)
6093 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006094 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006095 errmsg = e_invarg;
6096 }
6097#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006098
6099 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006100 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006102 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006103 */
6104 else if ( varp == &p_isi
6105 || varp == &(curbuf->b_p_isk)
6106 || varp == &p_isp
6107 || varp == &p_isf)
6108 {
6109 if (init_chartab() == FAIL)
6110 {
6111 did_chartab = TRUE; /* need to restore it below */
6112 errmsg = e_invarg; /* error in value */
6113 }
6114 }
6115
6116 /* 'helpfile' */
6117 else if (varp == &p_hf)
6118 {
6119 /* May compute new values for $VIM and $VIMRUNTIME */
6120 if (didset_vim)
6121 {
6122 vim_setenv((char_u *)"VIM", (char_u *)"");
6123 didset_vim = FALSE;
6124 }
6125 if (didset_vimruntime)
6126 {
6127 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6128 didset_vimruntime = FALSE;
6129 }
6130 }
6131
Bram Moolenaar1a384422010-07-14 19:53:30 +02006132#ifdef FEAT_SYN_HL
6133 /* 'colorcolumn' */
6134 else if (varp == &curwin->w_p_cc)
6135 errmsg = check_colorcolumn(curwin);
6136#endif
6137
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138#ifdef FEAT_MULTI_LANG
6139 /* 'helplang' */
6140 else if (varp == &p_hlg)
6141 {
6142 /* Check for "", "ab", "ab,cd", etc. */
6143 for (s = p_hlg; *s != NUL; s += 3)
6144 {
6145 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6146 {
6147 errmsg = e_invarg;
6148 break;
6149 }
6150 if (s[2] == NUL)
6151 break;
6152 }
6153 }
6154#endif
6155
6156 /* 'highlight' */
6157 else if (varp == &p_hl)
6158 {
6159 if (highlight_changed() == FAIL)
6160 errmsg = e_invarg; /* invalid flags */
6161 }
6162
6163 /* 'nrformats' */
6164 else if (gvarp == &p_nf)
6165 {
6166 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6167 errmsg = e_invarg;
6168 }
6169
6170#ifdef FEAT_SESSION
6171 /* 'sessionoptions' */
6172 else if (varp == &p_ssop)
6173 {
6174 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6175 errmsg = e_invarg;
6176 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6177 {
6178 /* Don't allow both "sesdir" and "curdir". */
6179 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6180 errmsg = e_invarg;
6181 }
6182 }
6183 /* 'viewoptions' */
6184 else if (varp == &p_vop)
6185 {
6186 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6187 errmsg = e_invarg;
6188 }
6189#endif
6190
6191 /* 'scrollopt' */
6192#ifdef FEAT_SCROLLBIND
6193 else if (varp == &p_sbo)
6194 {
6195 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6196 errmsg = e_invarg;
6197 }
6198#endif
6199
6200 /* 'ambiwidth' */
6201#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006202 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006203 {
6204 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6205 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006206 else if (set_chars_option(&p_lcs) != NULL)
6207 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6208# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6209 else if (set_chars_option(&p_fcs) != NULL)
6210 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6211# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212 }
6213#endif
6214
6215 /* 'background' */
6216 else if (varp == &p_bg)
6217 {
6218 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6219 {
6220#ifdef FEAT_EVAL
6221 int dark = (*p_bg == 'd');
6222#endif
6223
6224 init_highlight(FALSE, FALSE);
6225
6226#ifdef FEAT_EVAL
6227 if (dark != (*p_bg == 'd')
6228 && get_var_value((char_u *)"g:colors_name") != NULL)
6229 {
6230 /* The color scheme must have set 'background' back to another
6231 * value, that's not what we want here. Disable the color
6232 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006233 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006234 free_string_option(p_bg);
6235 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6236 check_string_option(&p_bg);
6237 init_highlight(FALSE, FALSE);
6238 }
6239#endif
6240 }
6241 else
6242 errmsg = e_invarg;
6243 }
6244
6245 /* 'wildmode' */
6246 else if (varp == &p_wim)
6247 {
6248 if (check_opt_wim() == FAIL)
6249 errmsg = e_invarg;
6250 }
6251
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006252#ifdef FEAT_CMDL_COMPL
6253 /* 'wildoptions' */
6254 else if (varp == &p_wop)
6255 {
6256 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6257 errmsg = e_invarg;
6258 }
6259#endif
6260
Bram Moolenaar071d4272004-06-13 20:20:40 +00006261#ifdef FEAT_WAK
6262 /* 'winaltkeys' */
6263 else if (varp == &p_wak)
6264 {
6265 if (*p_wak == NUL
6266 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6267 errmsg = e_invarg;
6268# ifdef FEAT_MENU
6269# ifdef FEAT_GUI_MOTIF
6270 else if (gui.in_use)
6271 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6272# else
6273# ifdef FEAT_GUI_GTK
6274 else if (gui.in_use)
6275 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6276# endif
6277# endif
6278# endif
6279 }
6280#endif
6281
6282#ifdef FEAT_AUTOCMD
6283 /* 'eventignore' */
6284 else if (varp == &p_ei)
6285 {
6286 if (check_ei() == FAIL)
6287 errmsg = e_invarg;
6288 }
6289#endif
6290
6291#ifdef FEAT_MBYTE
6292 /* 'encoding' and 'fileencoding' */
6293 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6294 {
6295 if (gvarp == &p_fenc)
6296 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006297 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006298 errmsg = e_modifiable;
6299 else if (vim_strchr(*varp, ',') != NULL)
6300 /* No comma allowed in 'fileencoding'; catches confusing it
6301 * with 'fileencodings'. */
6302 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006304 {
6305# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006306 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006307 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006308# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006309 /* Add 'fileencoding' to the swap file. */
6310 ml_setflags(curbuf);
6311 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006312 }
6313 if (errmsg == NULL)
6314 {
6315 /* canonize the value, so that STRCMP() can be used on it */
6316 p = enc_canonize(*varp);
6317 if (p != NULL)
6318 {
6319 vim_free(*varp);
6320 *varp = p;
6321 }
6322 if (varp == &p_enc)
6323 {
6324 errmsg = mb_init();
6325# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006326 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006327# endif
6328 }
6329 }
6330
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006331# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006332 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6333 {
6334 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6335 if (STRCMP(p_tenc, "utf-8") != 0)
6336 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6337 }
6338# endif
6339
6340 if (errmsg == NULL)
6341 {
6342# ifdef FEAT_KEYMAP
6343 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6344 * (with another encoding). */
6345 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6346 (void)keymap_init();
6347# endif
6348
6349 /* When 'termencoding' is not empty and 'encoding' changes or when
6350 * 'termencoding' changes, need to setup for keyboard input and
6351 * display output conversion. */
6352 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6353 {
6354 convert_setup(&input_conv, p_tenc, p_enc);
6355 convert_setup(&output_conv, p_enc, p_tenc);
6356 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006357
6358# if defined(WIN3264) && defined(FEAT_MBYTE)
6359 /* $HOME may have characters in active code page. */
6360 if (varp == &p_enc)
6361 init_homedir();
6362# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363 }
6364 }
6365#endif
6366
6367#if defined(FEAT_POSTSCRIPT)
6368 else if (varp == &p_penc)
6369 {
6370 /* Canonize printencoding if VIM standard one */
6371 p = enc_canonize(p_penc);
6372 if (p != NULL)
6373 {
6374 vim_free(p_penc);
6375 p_penc = p;
6376 }
6377 else
6378 {
6379 /* Ensure lower case and '-' for '_' */
6380 for (s = p_penc; *s != NUL; s++)
6381 {
6382 if (*s == '_')
6383 *s = '-';
6384 else
6385 *s = TOLOWER_ASC(*s);
6386 }
6387 }
6388 }
6389#endif
6390
Bram Moolenaar9372a112005-12-06 19:59:18 +00006391#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392 else if (varp == &p_imak)
6393 {
6394 if (gui.in_use && !im_xim_isvalid_imactivate())
6395 errmsg = e_invarg;
6396 }
6397#endif
6398
6399#ifdef FEAT_KEYMAP
6400 else if (varp == &curbuf->b_p_keymap)
6401 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006402 if (!valid_filetype(*varp))
6403 errmsg = e_invarg;
6404 else
6405 /* load or unload key mapping tables */
6406 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006407
Bram Moolenaarfab06232009-03-04 03:13:35 +00006408 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006409 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006410 if (*curbuf->b_p_keymap != NUL)
6411 {
6412 /* Installed a new keymap, switch on using it. */
6413 curbuf->b_p_iminsert = B_IMODE_LMAP;
6414 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6415 curbuf->b_p_imsearch = B_IMODE_LMAP;
6416 }
6417 else
6418 {
6419 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6420 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6421 curbuf->b_p_iminsert = B_IMODE_NONE;
6422 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6423 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6424 }
6425 if ((opt_flags & OPT_LOCAL) == 0)
6426 {
6427 set_iminsert_global();
6428 set_imsearch_global();
6429 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430# ifdef FEAT_WINDOWS
6431 status_redraw_curbuf();
6432# endif
6433 }
6434 }
6435#endif
6436
6437 /* 'fileformat' */
6438 else if (gvarp == &p_ff)
6439 {
6440 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6441 errmsg = e_modifiable;
6442 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6443 errmsg = e_invarg;
6444 else
6445 {
6446 /* may also change 'textmode' */
6447 if (get_fileformat(curbuf) == EOL_DOS)
6448 curbuf->b_p_tx = TRUE;
6449 else
6450 curbuf->b_p_tx = FALSE;
6451#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006452 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006453#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006454 /* update flag in swap file */
6455 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006456 /* Redraw needed when switching to/from "mac": a CR in the text
6457 * will be displayed differently. */
6458 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6459 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006460 }
6461 }
6462
6463 /* 'fileformats' */
6464 else if (varp == &p_ffs)
6465 {
6466 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6467 errmsg = e_invarg;
6468 else
6469 {
6470 /* also change 'textauto' */
6471 if (*p_ffs == NUL)
6472 p_ta = FALSE;
6473 else
6474 p_ta = TRUE;
6475 }
6476 }
6477
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006478#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006479 /* 'cryptkey' */
6480 else if (gvarp == &p_key)
6481 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006482# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483 /* Make sure the ":set" command doesn't show the new value in the
6484 * history. */
6485 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006486# endif
6487 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6488 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006489 ml_set_crypt_key(curbuf, oldval,
6490 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006491 }
6492
6493 else if (gvarp == &p_cm)
6494 {
6495 if (opt_flags & OPT_LOCAL)
6496 p = curbuf->b_p_cm;
6497 else
6498 p = p_cm;
6499 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6500 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006501 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006502 errmsg = e_invarg;
6503 else
6504 {
6505 /* When setting the global value to empty, make it "zip". */
6506 if (*p_cm == NUL)
6507 {
6508 if (new_value_alloced)
6509 free_string_option(p_cm);
6510 p_cm = vim_strsave((char_u *)"zip");
6511 new_value_alloced = TRUE;
6512 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006513 /* When using ":set cm=name" the local value is going to be empty.
6514 * Do that here, otherwise the crypt functions will still use the
6515 * local value. */
6516 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6517 {
6518 free_string_option(curbuf->b_p_cm);
6519 curbuf->b_p_cm = empty_option;
6520 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006521
6522 /* Need to update the swapfile when the effective method changed.
6523 * Set "s" to the effective old value, "p" to the effective new
6524 * method and compare. */
6525 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6526 s = p_cm; /* was previously using the global value */
6527 else
6528 s = oldval;
6529 if (*curbuf->b_p_cm == NUL)
6530 p = p_cm; /* is now using the global value */
6531 else
6532 p = curbuf->b_p_cm;
6533 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006534 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006535
6536 /* If the global value changes need to update the swapfile for all
6537 * buffers using that value. */
6538 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6539 {
6540 buf_T *buf;
6541
Bram Moolenaar29323592016-07-24 22:04:11 +02006542 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006543 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006544 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006545 }
6546 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006547 }
6548#endif
6549
6550 /* 'matchpairs' */
6551 else if (gvarp == &p_mps)
6552 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006553#ifdef FEAT_MBYTE
6554 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006556 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006558 int x2 = -1;
6559 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006560
6561 if (*p != NUL)
6562 p += mb_ptr2len(p);
6563 if (*p != NUL)
6564 x2 = *p++;
6565 if (*p != NUL)
6566 {
6567 x3 = mb_ptr2char(p);
6568 p += mb_ptr2len(p);
6569 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006570 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006571 {
6572 errmsg = e_invarg;
6573 break;
6574 }
6575 if (*p == NUL)
6576 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006577 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006578 }
6579 else
6580#endif
6581 {
6582 /* Check for "x:y,x:y" */
6583 for (p = *varp; *p != NUL; p += 4)
6584 {
6585 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6586 {
6587 errmsg = e_invarg;
6588 break;
6589 }
6590 if (p[3] == NUL)
6591 break;
6592 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006593 }
6594 }
6595
6596#ifdef FEAT_COMMENTS
6597 /* 'comments' */
6598 else if (gvarp == &p_com)
6599 {
6600 for (s = *varp; *s; )
6601 {
6602 while (*s && *s != ':')
6603 {
6604 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6605 && !VIM_ISDIGIT(*s) && *s != '-')
6606 {
6607 errmsg = illegal_char(errbuf, *s);
6608 break;
6609 }
6610 ++s;
6611 }
6612 if (*s++ == NUL)
6613 errmsg = (char_u *)N_("E524: Missing colon");
6614 else if (*s == ',' || *s == NUL)
6615 errmsg = (char_u *)N_("E525: Zero length string");
6616 if (errmsg != NULL)
6617 break;
6618 while (*s && *s != ',')
6619 {
6620 if (*s == '\\' && s[1] != NUL)
6621 ++s;
6622 ++s;
6623 }
6624 s = skip_to_option_part(s);
6625 }
6626 }
6627#endif
6628
6629 /* 'listchars' */
6630 else if (varp == &p_lcs)
6631 {
6632 errmsg = set_chars_option(varp);
6633 }
6634
6635#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6636 /* 'fillchars' */
6637 else if (varp == &p_fcs)
6638 {
6639 errmsg = set_chars_option(varp);
6640 }
6641#endif
6642
6643#ifdef FEAT_CMDWIN
6644 /* 'cedit' */
6645 else if (varp == &p_cedit)
6646 {
6647 errmsg = check_cedit();
6648 }
6649#endif
6650
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006651 /* 'verbosefile' */
6652 else if (varp == &p_vfile)
6653 {
6654 verbose_stop();
6655 if (*p_vfile != NUL && verbose_open() == FAIL)
6656 errmsg = e_invarg;
6657 }
6658
Bram Moolenaar071d4272004-06-13 20:20:40 +00006659#ifdef FEAT_VIMINFO
6660 /* 'viminfo' */
6661 else if (varp == &p_viminfo)
6662 {
6663 for (s = p_viminfo; *s;)
6664 {
6665 /* Check it's a valid character */
6666 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6667 {
6668 errmsg = illegal_char(errbuf, *s);
6669 break;
6670 }
6671 if (*s == 'n') /* name is always last one */
6672 {
6673 break;
6674 }
6675 else if (*s == 'r') /* skip until next ',' */
6676 {
6677 while (*++s && *s != ',')
6678 ;
6679 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006680 else if (*s == '%')
6681 {
6682 /* optional number */
6683 while (vim_isdigit(*++s))
6684 ;
6685 }
6686 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006687 ++s; /* no extra chars */
6688 else /* must have a number */
6689 {
6690 while (vim_isdigit(*++s))
6691 ;
6692
6693 if (!VIM_ISDIGIT(*(s - 1)))
6694 {
6695 if (errbuf != NULL)
6696 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006697 sprintf((char *)errbuf,
6698 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006699 transchar_byte(*(s - 1)));
6700 errmsg = errbuf;
6701 }
6702 else
6703 errmsg = (char_u *)"";
6704 break;
6705 }
6706 }
6707 if (*s == ',')
6708 ++s;
6709 else if (*s)
6710 {
6711 if (errbuf != NULL)
6712 errmsg = (char_u *)N_("E527: Missing comma");
6713 else
6714 errmsg = (char_u *)"";
6715 break;
6716 }
6717 }
6718 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6719 errmsg = (char_u *)N_("E528: Must specify a ' value");
6720 }
6721#endif /* FEAT_VIMINFO */
6722
6723 /* terminal options */
6724 else if (istermoption(&options[opt_idx]) && full_screen)
6725 {
6726 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6727 if (varp == &T_CCO)
6728 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006729 int colors = atoi((char *)T_CCO);
6730
6731 /* Only reinitialize colors if t_Co value has really changed to
6732 * avoid expensive reload of colorscheme if t_Co is set to the
6733 * same value multiple times. */
6734 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006735 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006736 t_colors = colors;
6737 if (t_colors <= 1)
6738 {
6739 if (new_value_alloced)
6740 vim_free(T_CCO);
6741 T_CCO = empty_option;
6742 }
6743 /* We now have a different color setup, initialize it again. */
6744 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006746 }
6747 ttest(FALSE);
6748 if (varp == &T_ME)
6749 {
6750 out_str(T_ME);
6751 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006752#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753 /* Since t_me has been set, this probably means that the user
6754 * wants to use this as default colors. Need to reset default
6755 * background/foreground colors. */
6756 mch_set_normal_colors();
6757#endif
6758 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006759 if (varp == &T_BE && termcap_active)
6760 {
6761 if (*T_BE == NUL)
6762 /* When clearing t_BE we assume the user no longer wants
6763 * bracketed paste, thus disable it by writing t_BD. */
6764 out_str(T_BD);
6765 else
6766 out_str(T_BE);
6767 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006768 }
6769
6770#ifdef FEAT_LINEBREAK
6771 /* 'showbreak' */
6772 else if (varp == &p_sbr)
6773 {
6774 for (s = p_sbr; *s; )
6775 {
6776 if (ptr2cells(s) != 1)
6777 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006778 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779 }
6780 }
6781#endif
6782
6783#ifdef FEAT_GUI
6784 /* 'guifont' */
6785 else if (varp == &p_guifont)
6786 {
6787 if (gui.in_use)
6788 {
6789 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006790# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006791 /*
6792 * Put up a font dialog and let the user select a new value.
6793 * If this is cancelled go back to the old value but don't
6794 * give an error message.
6795 */
6796 if (STRCMP(p, "*") == 0)
6797 {
6798 p = gui_mch_font_dialog(oldval);
6799
6800 if (new_value_alloced)
6801 free_string_option(p_guifont);
6802
6803 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6804 new_value_alloced = TRUE;
6805 }
6806# endif
6807 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6808 {
6809# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6810 if (STRCMP(p_guifont, "*") == 0)
6811 {
6812 /* Dialog was cancelled: Keep the old value without giving
6813 * an error message. */
6814 if (new_value_alloced)
6815 free_string_option(p_guifont);
6816 p_guifont = vim_strsave(oldval);
6817 new_value_alloced = TRUE;
6818 }
6819 else
6820# endif
6821 errmsg = (char_u *)N_("E596: Invalid font(s)");
6822 }
6823 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006824 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006825 }
6826# ifdef FEAT_XFONTSET
6827 else if (varp == &p_guifontset)
6828 {
6829 if (STRCMP(p_guifontset, "*") == 0)
6830 errmsg = (char_u *)N_("E597: can't select fontset");
6831 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6832 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006833 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006834 }
6835# endif
6836# ifdef FEAT_MBYTE
6837 else if (varp == &p_guifontwide)
6838 {
6839 if (STRCMP(p_guifontwide, "*") == 0)
6840 errmsg = (char_u *)N_("E533: can't select wide font");
6841 else if (gui_get_wide_font() == FAIL)
6842 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006843 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006844 }
6845# endif
6846#endif
6847
6848#ifdef CURSOR_SHAPE
6849 /* 'guicursor' */
6850 else if (varp == &p_guicursor)
6851 errmsg = parse_shape_opt(SHAPE_CURSOR);
6852#endif
6853
6854#ifdef FEAT_MOUSESHAPE
6855 /* 'mouseshape' */
6856 else if (varp == &p_mouseshape)
6857 {
6858 errmsg = parse_shape_opt(SHAPE_MOUSE);
6859 update_mouseshape(-1);
6860 }
6861#endif
6862
6863#ifdef FEAT_PRINTER
6864 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006865 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006866# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006867 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006868 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006869# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870#endif
6871
6872#ifdef FEAT_LANGMAP
6873 /* 'langmap' */
6874 else if (varp == &p_langmap)
6875 langmap_set();
6876#endif
6877
6878#ifdef FEAT_LINEBREAK
6879 /* 'breakat' */
6880 else if (varp == &p_breakat)
6881 fill_breakat_flags();
6882#endif
6883
6884#ifdef FEAT_TITLE
6885 /* 'titlestring' and 'iconstring' */
6886 else if (varp == &p_titlestring || varp == &p_iconstring)
6887 {
6888# ifdef FEAT_STL_OPT
6889 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6890
6891 /* NULL => statusline syntax */
6892 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6893 stl_syntax |= flagval;
6894 else
6895 stl_syntax &= ~flagval;
6896# endif
6897 did_set_title(varp == &p_iconstring);
6898
6899 }
6900#endif
6901
6902#ifdef FEAT_GUI
6903 /* 'guioptions' */
6904 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006905 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006906 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006907 redraw_gui_only = TRUE;
6908 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909#endif
6910
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006911#if defined(FEAT_GUI_TABLINE)
6912 /* 'guitablabel' */
6913 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006914 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006915 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006916 redraw_gui_only = TRUE;
6917 }
6918 /* 'guitabtooltip' */
6919 else if (varp == &p_gtt)
6920 {
6921 redraw_gui_only = TRUE;
6922 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006923#endif
6924
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6926 /* 'ttymouse' */
6927 else if (varp == &p_ttym)
6928 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006929 /* Switch the mouse off before changing the escape sequences used for
6930 * that. */
6931 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006932 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6933 errmsg = e_invarg;
6934 else
6935 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006936 if (termcap_active)
6937 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938 }
6939#endif
6940
Bram Moolenaar071d4272004-06-13 20:20:40 +00006941 /* 'selection' */
6942 else if (varp == &p_sel)
6943 {
6944 if (*p_sel == NUL
6945 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6946 errmsg = e_invarg;
6947 }
6948
6949 /* 'selectmode' */
6950 else if (varp == &p_slm)
6951 {
6952 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6953 errmsg = e_invarg;
6954 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006955
6956#ifdef FEAT_BROWSE
6957 /* 'browsedir' */
6958 else if (varp == &p_bsdir)
6959 {
6960 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6961 && !mch_isdir(p_bsdir))
6962 errmsg = e_invarg;
6963 }
6964#endif
6965
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966 /* 'keymodel' */
6967 else if (varp == &p_km)
6968 {
6969 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6970 errmsg = e_invarg;
6971 else
6972 {
6973 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6974 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6975 }
6976 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006977
6978 /* 'mousemodel' */
6979 else if (varp == &p_mousem)
6980 {
6981 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6982 errmsg = e_invarg;
6983#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6984 else if (*p_mousem != *oldval)
6985 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6986 * to create or delete the popup menus. */
6987 gui_motif_update_mousemodel(root_menu);
6988#endif
6989 }
6990
6991 /* 'switchbuf' */
6992 else if (varp == &p_swb)
6993 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006994 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006995 errmsg = e_invarg;
6996 }
6997
6998 /* 'debug' */
6999 else if (varp == &p_debug)
7000 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007001 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002 errmsg = e_invarg;
7003 }
7004
7005 /* 'display' */
7006 else if (varp == &p_dy)
7007 {
7008 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7009 errmsg = e_invarg;
7010 else
7011 (void)init_chartab();
7012
7013 }
7014
Bram Moolenaar44a2f922016-03-19 22:11:51 +01007015#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00007016 /* 'eadirection' */
7017 else if (varp == &p_ead)
7018 {
7019 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7020 errmsg = e_invarg;
7021 }
7022#endif
7023
7024#ifdef FEAT_CLIPBOARD
7025 /* 'clipboard' */
7026 else if (varp == &p_cb)
7027 errmsg = check_clipboard_option();
7028#endif
7029
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007030#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007031 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7032 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007033 else if (varp == &(curwin->w_s->b_p_spl)
7034 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007035 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007036 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007037 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007038 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007039 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007040 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007041 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007042 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007043 /* 'spellsuggest' */
7044 else if (varp == &p_sps)
7045 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007046 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007047 errmsg = e_invarg;
7048 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007049 /* 'mkspellmem' */
7050 else if (varp == &p_msm)
7051 {
7052 if (spell_check_msm() != OK)
7053 errmsg = e_invarg;
7054 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007055#endif
7056
Bram Moolenaar071d4272004-06-13 20:20:40 +00007057#ifdef FEAT_QUICKFIX
7058 /* When 'bufhidden' is set, check for valid value. */
7059 else if (gvarp == &p_bh)
7060 {
7061 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7062 errmsg = e_invarg;
7063 }
7064
7065 /* When 'buftype' is set, check for valid value. */
7066 else if (gvarp == &p_bt)
7067 {
7068 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7069 errmsg = e_invarg;
7070 else
7071 {
7072# ifdef FEAT_WINDOWS
7073 if (curwin->w_status_height)
7074 {
7075 curwin->w_redr_status = TRUE;
7076 redraw_later(VALID);
7077 }
7078# endif
7079 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007080# ifdef FEAT_TITLE
7081 redraw_titles();
7082# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007083 }
7084 }
7085#endif
7086
7087#ifdef FEAT_STL_OPT
7088 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007089 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007090 {
7091 int wid;
7092
7093 if (varp == &p_ruf) /* reset ru_wid first */
7094 ru_wid = 0;
7095 s = *varp;
7096 if (varp == &p_ruf && *s == '%')
7097 {
7098 /* set ru_wid if 'ruf' starts with "%99(" */
7099 if (*++s == '-') /* ignore a '-' */
7100 s++;
7101 wid = getdigits(&s);
7102 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7103 ru_wid = wid;
7104 else
7105 errmsg = check_stl_option(p_ruf);
7106 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007107 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007108 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007109 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007110 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111 comp_col();
7112 }
7113#endif
7114
7115#ifdef FEAT_INS_EXPAND
7116 /* check if it is a valid value for 'complete' -- Acevedo */
7117 else if (gvarp == &p_cpt)
7118 {
7119 for (s = *varp; *s;)
7120 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007121 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007122 s++;
7123 if (!*s)
7124 break;
7125 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7126 {
7127 errmsg = illegal_char(errbuf, *s);
7128 break;
7129 }
7130 if (*++s != NUL && *s != ',' && *s != ' ')
7131 {
7132 if (s[-1] == 'k' || s[-1] == 's')
7133 {
7134 /* skip optional filename after 'k' and 's' */
7135 while (*s && *s != ',' && *s != ' ')
7136 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007137 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007138 ++s;
7139 ++s;
7140 }
7141 }
7142 else
7143 {
7144 if (errbuf != NULL)
7145 {
7146 sprintf((char *)errbuf,
7147 _("E535: Illegal character after <%c>"),
7148 *--s);
7149 errmsg = errbuf;
7150 }
7151 else
7152 errmsg = (char_u *)"";
7153 break;
7154 }
7155 }
7156 }
7157 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007158
7159 /* 'completeopt' */
7160 else if (varp == &p_cot)
7161 {
7162 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7163 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007164 else
7165 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007167#endif /* FEAT_INS_EXPAND */
7168
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007169#ifdef FEAT_SIGNS
7170 /* 'signcolumn' */
7171 else if (varp == &curwin->w_p_scl)
7172 {
7173 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7174 errmsg = e_invarg;
7175 }
7176#endif
7177
Bram Moolenaar071d4272004-06-13 20:20:40 +00007178
7179#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007180 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 else if (varp == &p_toolbar)
7182 {
7183 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7184 &toolbar_flags, TRUE) != OK)
7185 errmsg = e_invarg;
7186 else
7187 {
7188 out_flush();
7189 gui_mch_show_toolbar((toolbar_flags &
7190 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7191 }
7192 }
7193#endif
7194
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007195#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007196 /* 'toolbariconsize': GTK+ 2 only */
7197 else if (varp == &p_tbis)
7198 {
7199 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7200 errmsg = e_invarg;
7201 else
7202 {
7203 out_flush();
7204 gui_mch_show_toolbar((toolbar_flags &
7205 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7206 }
7207 }
7208#endif
7209
7210 /* 'pastetoggle': translate key codes like in a mapping */
7211 else if (varp == &p_pt)
7212 {
7213 if (*p_pt)
7214 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007215 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007216 if (p != NULL)
7217 {
7218 if (new_value_alloced)
7219 free_string_option(p_pt);
7220 p_pt = p;
7221 new_value_alloced = TRUE;
7222 }
7223 }
7224 }
7225
7226 /* 'backspace' */
7227 else if (varp == &p_bs)
7228 {
7229 if (VIM_ISDIGIT(*p_bs))
7230 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007231 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007232 errmsg = e_invarg;
7233 }
7234 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7235 errmsg = e_invarg;
7236 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007237 else if (varp == &p_bo)
7238 {
7239 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7240 errmsg = e_invarg;
7241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007243 /* 'tagcase' */
7244 else if (gvarp == &p_tc)
7245 {
7246 unsigned int *flags;
7247
7248 if (opt_flags & OPT_LOCAL)
7249 {
7250 p = curbuf->b_p_tc;
7251 flags = &curbuf->b_tc_flags;
7252 }
7253 else
7254 {
7255 p = p_tc;
7256 flags = &tc_flags;
7257 }
7258
7259 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7260 /* make the local value empty: use the global value */
7261 *flags = 0;
7262 else if (*p == NUL
7263 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7264 errmsg = e_invarg;
7265 }
7266
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007267#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007268 /* 'casemap' */
7269 else if (varp == &p_cmp)
7270 {
7271 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7272 errmsg = e_invarg;
7273 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007275
7276#ifdef FEAT_DIFF
7277 /* 'diffopt' */
7278 else if (varp == &p_dip)
7279 {
7280 if (diffopt_changed() == FAIL)
7281 errmsg = e_invarg;
7282 }
7283#endif
7284
7285#ifdef FEAT_FOLDING
7286 /* 'foldmethod' */
7287 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7288 {
7289 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7290 || *curwin->w_p_fdm == NUL)
7291 errmsg = e_invarg;
7292 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007293 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007294 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007295 if (foldmethodIsDiff(curwin))
7296 newFoldLevel();
7297 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007298 }
7299# ifdef FEAT_EVAL
7300 /* 'foldexpr' */
7301 else if (varp == &curwin->w_p_fde)
7302 {
7303 if (foldmethodIsExpr(curwin))
7304 foldUpdateAll(curwin);
7305 }
7306# endif
7307 /* 'foldmarker' */
7308 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7309 {
7310 p = vim_strchr(*varp, ',');
7311 if (p == NULL)
7312 errmsg = (char_u *)N_("E536: comma required");
7313 else if (p == *varp || p[1] == NUL)
7314 errmsg = e_invarg;
7315 else if (foldmethodIsMarker(curwin))
7316 foldUpdateAll(curwin);
7317 }
7318 /* 'commentstring' */
7319 else if (gvarp == &p_cms)
7320 {
7321 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7322 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7323 }
7324 /* 'foldopen' */
7325 else if (varp == &p_fdo)
7326 {
7327 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7328 errmsg = e_invarg;
7329 }
7330 /* 'foldclose' */
7331 else if (varp == &p_fcl)
7332 {
7333 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7334 errmsg = e_invarg;
7335 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007336 /* 'foldignore' */
7337 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7338 {
7339 if (foldmethodIsIndent(curwin))
7340 foldUpdateAll(curwin);
7341 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007342#endif
7343
7344#ifdef FEAT_VIRTUALEDIT
7345 /* 'virtualedit' */
7346 else if (varp == &p_ve)
7347 {
7348 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7349 errmsg = e_invarg;
7350 else if (STRCMP(p_ve, oldval) != 0)
7351 {
7352 /* Recompute cursor position in case the new 've' setting
7353 * changes something. */
7354 validate_virtcol();
7355 coladvance(curwin->w_virtcol);
7356 }
7357 }
7358#endif
7359
7360#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7361 else if (varp == &p_csqf)
7362 {
7363 if (p_csqf != NULL)
7364 {
7365 p = p_csqf;
7366 while (*p != NUL)
7367 {
7368 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7369 || p[1] == NUL
7370 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7371 || (p[2] != NUL && p[2] != ','))
7372 {
7373 errmsg = e_invarg;
7374 break;
7375 }
7376 else if (p[2] == NUL)
7377 break;
7378 else
7379 p += 3;
7380 }
7381 }
7382 }
7383#endif
7384
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007385#ifdef FEAT_CINDENT
7386 /* 'cinoptions' */
7387 else if (gvarp == &p_cino)
7388 {
7389 /* TODO: recognize errors */
7390 parse_cino(curbuf);
7391 }
7392#endif
7393
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007394#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007395 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007396 else if (varp == &p_rop && gui.in_use)
7397 {
7398 if (!gui_mch_set_rendering_options(p_rop))
7399 errmsg = e_invarg;
7400 }
7401#endif
7402
Bram Moolenaard0b51382016-11-04 15:23:45 +01007403#ifdef FEAT_AUTOCMD
7404 else if (gvarp == &p_ft)
7405 {
7406 if (!valid_filetype(*varp))
7407 errmsg = e_invarg;
7408 }
7409#endif
7410
7411#ifdef FEAT_SYN_HL
7412 else if (gvarp == &p_syn)
7413 {
7414 if (!valid_filetype(*varp))
7415 errmsg = e_invarg;
7416 }
7417#endif
7418
Bram Moolenaar071d4272004-06-13 20:20:40 +00007419 /* Options that are a list of flags. */
7420 else
7421 {
7422 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007423 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007424 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007425 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007426 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007427 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007428 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007429 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007430 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007431#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007432 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007433 p = (char_u *)COCU_ALL;
7434#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007435 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007436 {
7437#ifdef FEAT_MOUSE
7438 p = (char_u *)MOUSE_ALL;
7439#else
7440 if (*p_mouse != NUL)
7441 errmsg = (char_u *)N_("E538: No mouse support");
7442#endif
7443 }
7444#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007445 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007446 p = (char_u *)GO_ALL;
7447#endif
7448 if (p != NULL)
7449 {
7450 for (s = *varp; *s; ++s)
7451 if (vim_strchr(p, *s) == NULL)
7452 {
7453 errmsg = illegal_char(errbuf, *s);
7454 break;
7455 }
7456 }
7457 }
7458
7459 /*
7460 * If error detected, restore the previous value.
7461 */
7462 if (errmsg != NULL)
7463 {
7464 if (new_value_alloced)
7465 free_string_option(*varp);
7466 *varp = oldval;
7467 /*
7468 * When resetting some values, need to act on it.
7469 */
7470 if (did_chartab)
7471 (void)init_chartab();
7472 if (varp == &p_hl)
7473 (void)highlight_changed();
7474 }
7475 else
7476 {
7477#ifdef FEAT_EVAL
7478 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007479 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007480#endif
7481 /*
7482 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007483 * Use "free_oldval", because recursiveness may change the flags under
7484 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007485 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007486 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007487 free_string_option(oldval);
7488 if (new_value_alloced)
7489 options[opt_idx].flags |= P_ALLOCED;
7490 else
7491 options[opt_idx].flags &= ~P_ALLOCED;
7492
7493 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007494 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007495 {
7496 /* global option with local value set to use global value; free
7497 * the local value and make it empty */
7498 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7499 free_string_option(*(char_u **)p);
7500 *(char_u **)p = empty_option;
7501 }
7502
7503 /* May set global value for local option. */
7504 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7505 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007506
7507#ifdef FEAT_AUTOCMD
7508 /*
7509 * Trigger the autocommand only after setting the flags.
7510 */
7511# ifdef FEAT_SYN_HL
7512 /* When 'syntax' is set, load the syntax of that name */
7513 if (varp == &(curbuf->b_p_syn))
7514 {
7515 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7516 curbuf->b_fname, TRUE, curbuf);
7517 }
7518# endif
7519 else if (varp == &(curbuf->b_p_ft))
7520 {
7521 /* 'filetype' is set, trigger the FileType autocommand */
7522 did_filetype = TRUE;
7523 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7524 curbuf->b_fname, TRUE, curbuf);
7525 }
7526#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007527#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007528 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007529 {
7530 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007531 char_u *q = curwin->w_s->b_p_spl;
7532
7533 /* Skip the first name if it is "cjk". */
7534 if (STRNCMP(q, "cjk,", 4) == 0)
7535 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007536
7537 /*
7538 * Source the spell/LANG.vim in 'runtimepath'.
7539 * They could set 'spellcapcheck' depending on the language.
7540 * Use the first name in 'spelllang' up to '_region' or
7541 * '.encoding'.
7542 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007543 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007544 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7545 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007546 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007547 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007548 }
7549#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007550 }
7551
7552#ifdef FEAT_MOUSE
7553 if (varp == &p_mouse)
7554 {
7555# ifdef FEAT_MOUSE_TTY
7556 if (*p_mouse == NUL)
7557 mch_setmouse(FALSE); /* switch mouse off */
7558 else
7559# endif
7560 setmouse(); /* in case 'mouse' changed */
7561 }
7562#endif
7563
Bram Moolenaar913077c2012-03-28 19:59:04 +02007564 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007565 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007566 curwin->w_set_curswant = TRUE;
7567
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007568#ifdef FEAT_GUI
7569 /* check redraw when it's not a GUI option or the GUI is active. */
7570 if (!redraw_gui_only || gui.in_use)
7571#endif
7572 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573
7574 return errmsg;
7575}
7576
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007577#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007578/*
7579 * Simple int comparison function for use with qsort()
7580 */
7581 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007582int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007583{
7584 return *(const int *)a - *(const int *)b;
7585}
7586
7587/*
7588 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7589 * Returns error message, NULL if it's OK.
7590 */
7591 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007592check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007593{
7594 char_u *s;
7595 int col;
7596 int count = 0;
7597 int color_cols[256];
7598 int i;
7599 int j = 0;
7600
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007601 if (wp->w_buffer == NULL)
7602 return NULL; /* buffer was closed */
7603
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007604 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007605 {
7606 if (*s == '-' || *s == '+')
7607 {
7608 /* -N and +N: add to 'textwidth' */
7609 col = (*s == '-') ? -1 : 1;
7610 ++s;
7611 if (!VIM_ISDIGIT(*s))
7612 return e_invarg;
7613 col = col * getdigits(&s);
7614 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007615 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007616 col += wp->w_buffer->b_p_tw;
7617 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007618 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007619 }
7620 else if (VIM_ISDIGIT(*s))
7621 col = getdigits(&s);
7622 else
7623 return e_invarg;
7624 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007625skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007626 if (*s == NUL)
7627 break;
7628 if (*s != ',')
7629 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007630 if (*++s == NUL)
7631 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007632 }
7633
7634 vim_free(wp->w_p_cc_cols);
7635 if (count == 0)
7636 wp->w_p_cc_cols = NULL;
7637 else
7638 {
7639 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7640 if (wp->w_p_cc_cols != NULL)
7641 {
7642 /* sort the columns for faster usage on screen redraw inside
7643 * win_line() */
7644 qsort(color_cols, count, sizeof(int), int_cmp);
7645
7646 for (i = 0; i < count; ++i)
7647 /* skip duplicates */
7648 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7649 wp->w_p_cc_cols[j++] = color_cols[i];
7650 wp->w_p_cc_cols[j] = -1; /* end marker */
7651 }
7652 }
7653
7654 return NULL; /* no error */
7655}
7656#endif
7657
Bram Moolenaar071d4272004-06-13 20:20:40 +00007658/*
7659 * Handle setting 'listchars' or 'fillchars'.
7660 * Returns error message, NULL if it's OK.
7661 */
7662 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007663set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007664{
7665 int round, i, len, entries;
7666 char_u *p, *s;
7667 int c1, c2 = 0;
7668 struct charstab
7669 {
7670 int *cp;
7671 char *name;
7672 };
7673#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7674 static struct charstab filltab[] =
7675 {
7676 {&fill_stl, "stl"},
7677 {&fill_stlnc, "stlnc"},
7678 {&fill_vert, "vert"},
7679 {&fill_fold, "fold"},
7680 {&fill_diff, "diff"},
7681 };
7682#endif
7683 static struct charstab lcstab[] =
7684 {
7685 {&lcs_eol, "eol"},
7686 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007687 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007688 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007689 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007690 {&lcs_tab2, "tab"},
7691 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007692#ifdef FEAT_CONCEAL
7693 {&lcs_conceal, "conceal"},
7694#else
7695 {NULL, "conceal"},
7696#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007697 };
7698 struct charstab *tab;
7699
7700#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7701 if (varp == &p_lcs)
7702#endif
7703 {
7704 tab = lcstab;
7705 entries = sizeof(lcstab) / sizeof(struct charstab);
7706 }
7707#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7708 else
7709 {
7710 tab = filltab;
7711 entries = sizeof(filltab) / sizeof(struct charstab);
7712 }
7713#endif
7714
7715 /* first round: check for valid value, second round: assign values */
7716 for (round = 0; round <= 1; ++round)
7717 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007718 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007719 {
7720 /* After checking that the value is valid: set defaults: space for
7721 * 'fillchars', NUL for 'listchars' */
7722 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007723 if (tab[i].cp != NULL)
7724 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007725 if (varp == &p_lcs)
7726 lcs_tab1 = NUL;
7727#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7728 else
7729 fill_diff = '-';
7730#endif
7731 }
7732 p = *varp;
7733 while (*p)
7734 {
7735 for (i = 0; i < entries; ++i)
7736 {
7737 len = (int)STRLEN(tab[i].name);
7738 if (STRNCMP(p, tab[i].name, len) == 0
7739 && p[len] == ':'
7740 && p[len + 1] != NUL)
7741 {
7742 s = p + len + 1;
7743#ifdef FEAT_MBYTE
7744 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007745 if (mb_char2cells(c1) > 1)
7746 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007747#else
7748 c1 = *s++;
7749#endif
7750 if (tab[i].cp == &lcs_tab2)
7751 {
7752 if (*s == NUL)
7753 continue;
7754#ifdef FEAT_MBYTE
7755 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007756 if (mb_char2cells(c2) > 1)
7757 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758#else
7759 c2 = *s++;
7760#endif
7761 }
7762 if (*s == ',' || *s == NUL)
7763 {
7764 if (round)
7765 {
7766 if (tab[i].cp == &lcs_tab2)
7767 {
7768 lcs_tab1 = c1;
7769 lcs_tab2 = c2;
7770 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007771 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007772 *(tab[i].cp) = c1;
7773
7774 }
7775 p = s;
7776 break;
7777 }
7778 }
7779 }
7780
7781 if (i == entries)
7782 return e_invarg;
7783 if (*p == ',')
7784 ++p;
7785 }
7786 }
7787
7788 return NULL; /* no error */
7789}
7790
7791#ifdef FEAT_STL_OPT
7792/*
7793 * Check validity of options with the 'statusline' format.
7794 * Return error message or NULL.
7795 */
7796 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007797check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798{
7799 int itemcnt = 0;
7800 int groupdepth = 0;
7801 static char_u errbuf[80];
7802
7803 while (*s && itemcnt < STL_MAX_ITEM)
7804 {
7805 /* Check for valid keys after % sequences */
7806 while (*s && *s != '%')
7807 s++;
7808 if (!*s)
7809 break;
7810 s++;
7811 if (*s != '%' && *s != ')')
7812 ++itemcnt;
7813 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7814 {
7815 s++;
7816 continue;
7817 }
7818 if (*s == ')')
7819 {
7820 s++;
7821 if (--groupdepth < 0)
7822 break;
7823 continue;
7824 }
7825 if (*s == '-')
7826 s++;
7827 while (VIM_ISDIGIT(*s))
7828 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007829 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007830 continue;
7831 if (*s == '.')
7832 {
7833 s++;
7834 while (*s && VIM_ISDIGIT(*s))
7835 s++;
7836 }
7837 if (*s == '(')
7838 {
7839 groupdepth++;
7840 continue;
7841 }
7842 if (vim_strchr(STL_ALL, *s) == NULL)
7843 {
7844 return illegal_char(errbuf, *s);
7845 }
7846 if (*s == '{')
7847 {
7848 s++;
7849 while (*s != '}' && *s)
7850 s++;
7851 if (*s != '}')
7852 return (char_u *)N_("E540: Unclosed expression sequence");
7853 }
7854 }
7855 if (itemcnt >= STL_MAX_ITEM)
7856 return (char_u *)N_("E541: too many items");
7857 if (groupdepth != 0)
7858 return (char_u *)N_("E542: unbalanced groups");
7859 return NULL;
7860}
7861#endif
7862
7863#ifdef FEAT_CLIPBOARD
7864/*
7865 * Extract the items in the 'clipboard' option and set global values.
7866 */
7867 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007868check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007870 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007871 int new_autoselect_star = FALSE;
7872 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007874 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007875 regprog_T *new_exclude_prog = NULL;
7876 char_u *errmsg = NULL;
7877 char_u *p;
7878
7879 for (p = p_cb; *p != NUL; )
7880 {
7881 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7882 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007883 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007884 p += 7;
7885 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007886 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007887 && (p[11] == ',' || p[11] == NUL))
7888 {
7889 new_unnamed |= CLIP_UNNAMED_PLUS;
7890 p += 11;
7891 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007892 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007893 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007894 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007895 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007896 p += 10;
7897 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007898 else if (STRNCMP(p, "autoselectplus", 14) == 0
7899 && (p[14] == ',' || p[14] == NUL))
7900 {
7901 new_autoselect_plus = TRUE;
7902 p += 14;
7903 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007904 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007905 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007906 {
7907 new_autoselectml = TRUE;
7908 p += 12;
7909 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007910 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7911 {
7912 new_html = TRUE;
7913 p += 4;
7914 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007915 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7916 {
7917 p += 8;
7918 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7919 if (new_exclude_prog == NULL)
7920 errmsg = e_invarg;
7921 break;
7922 }
7923 else
7924 {
7925 errmsg = e_invarg;
7926 break;
7927 }
7928 if (*p == ',')
7929 ++p;
7930 }
7931 if (errmsg == NULL)
7932 {
7933 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007934 clip_autoselect_star = new_autoselect_star;
7935 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007937 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007938 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007940#ifdef FEAT_GUI_GTK
7941 if (gui.in_use)
7942 {
7943 gui_gtk_set_selection_targets();
7944 gui_gtk_set_dnd_targets();
7945 }
7946#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 }
7948 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007949 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007950
7951 return errmsg;
7952}
7953#endif
7954
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007955#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007956 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007957did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007958{
7959 char_u *errmsg = NULL;
7960 win_T *wp;
7961 int l;
7962
7963 if (is_spellfile)
7964 {
7965 l = (int)STRLEN(curwin->w_s->b_p_spf);
7966 if (l > 0 && (l < 4
7967 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7968 errmsg = e_invarg;
7969 }
7970
7971 if (errmsg == NULL)
7972 {
7973 FOR_ALL_WINDOWS(wp)
7974 if (wp->w_buffer == curbuf && wp->w_p_spell)
7975 {
7976 errmsg = did_set_spelllang(wp);
7977# ifdef FEAT_WINDOWS
7978 break;
7979# endif
7980 }
7981 }
7982 return errmsg;
7983}
7984
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007985/*
7986 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7987 * Return error message when failed, NULL when OK.
7988 */
7989 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007990compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007991{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007992 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007993 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007994
Bram Moolenaar860cae12010-06-05 23:22:07 +02007995 if (*synblock->b_p_spc == NUL)
7996 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007997 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007998 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007999 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008000 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008001 if (re != NULL)
8002 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008003 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008004 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008005 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008006 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008007 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008008 return e_invarg;
8009 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008010 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008011 }
8012
Bram Moolenaar473de612013-06-08 18:19:48 +02008013 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008014 return NULL;
8015}
8016#endif
8017
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008018#if defined(FEAT_EVAL) || defined(PROTO)
8019/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008020 * Set the scriptID for an option, taking care of setting the buffer- or
8021 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008022 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008023 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01008024set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008025{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008026 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8027 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008028
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008029 /* Remember where the option was set. For local options need to do that
8030 * in the buffer or window structure. */
8031 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008032 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008033 if (both || (opt_flags & OPT_LOCAL))
8034 {
8035 if (indir & PV_BUF)
8036 curbuf->b_p_scriptID[indir & PV_MASK] = id;
8037 else if (indir & PV_WIN)
8038 curwin->w_p_scriptID[indir & PV_MASK] = id;
8039 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008040}
8041#endif
8042
Bram Moolenaar071d4272004-06-13 20:20:40 +00008043/*
8044 * Set the value of a boolean option, and take care of side effects.
8045 * Returns NULL for success, or an error message for an error.
8046 */
8047 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008048set_bool_option(
8049 int opt_idx, /* index in options[] table */
8050 char_u *varp, /* pointer to the option variable */
8051 int value, /* new value */
8052 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008053{
8054 int old_value = *(int *)varp;
8055
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 /* Disallow changing some options from secure mode */
8057 if ((secure
8058#ifdef HAVE_SANDBOX
8059 || sandbox != 0
8060#endif
8061 ) && (options[opt_idx].flags & P_SECURE))
8062 return e_secure;
8063
8064 *(int *)varp = value; /* set the new value */
8065#ifdef FEAT_EVAL
8066 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008067 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008068#endif
8069
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008070#ifdef FEAT_GUI
8071 need_mouse_correct = TRUE;
8072#endif
8073
Bram Moolenaar071d4272004-06-13 20:20:40 +00008074 /* May set global value for local option. */
8075 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8076 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8077
8078 /*
8079 * Handle side effects of changing a bool option.
8080 */
8081
8082 /* 'compatible' */
8083 if ((int *)varp == &p_cp)
8084 {
8085 compatible_set();
8086 }
8087
Bram Moolenaar920694c2016-08-21 17:45:02 +02008088#ifdef FEAT_LANGMAP
8089 if ((int *)varp == &p_lrm)
8090 /* 'langremap' -> !'langnoremap' */
8091 p_lnr = !p_lrm;
8092 else if ((int *)varp == &p_lnr)
8093 /* 'langnoremap' -> !'langremap' */
8094 p_lrm = !p_lnr;
8095#endif
8096
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008097#ifdef FEAT_PERSISTENT_UNDO
8098 /* 'undofile' */
8099 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8100 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008101 /* Only take action when the option was set. When reset we do not
8102 * delete the undo file, the option may be set again without making
8103 * any changes in between. */
8104 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008105 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008106 char_u hash[UNDO_HASH_SIZE];
8107 buf_T *save_curbuf = curbuf;
8108
Bram Moolenaar29323592016-07-24 22:04:11 +02008109 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008110 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008111 /* When 'undofile' is set globally: for every buffer, otherwise
8112 * only for the current buffer: Try to read in the undofile,
8113 * if one exists, the buffer wasn't changed and the buffer was
8114 * loaded */
8115 if ((curbuf == save_curbuf
8116 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8117 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8118 {
8119 u_compute_hash(hash);
8120 u_read_undo(NULL, hash, curbuf->b_fname);
8121 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008122 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008123 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008124 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008125 }
8126#endif
8127
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128 else if ((int *)varp == &curbuf->b_p_ro)
8129 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008130 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008131 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8132 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008133
8134 /* when 'readonly' is set may give W10 again */
8135 if (curbuf->b_p_ro)
8136 curbuf->b_did_warn = FALSE;
8137
Bram Moolenaar071d4272004-06-13 20:20:40 +00008138#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008139 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008140#endif
8141 }
8142
Bram Moolenaar9c449722010-07-20 18:44:27 +02008143#ifdef FEAT_GUI
8144 else if ((int *)varp == &p_mh)
8145 {
8146 if (!p_mh)
8147 gui_mch_mousehide(FALSE);
8148 }
8149#endif
8150
Bram Moolenaara539df02010-08-01 14:35:05 +02008151#ifdef FEAT_TITLE
8152 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008154 {
8155 redraw_titles();
8156 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 /* when 'endofline' is changed, redraw the window title */
8158 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008159 {
8160 redraw_titles();
8161 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008162 /* when 'fixeol' is changed, redraw the window title */
8163 else if ((int *)varp == &curbuf->b_p_fixeol)
8164 {
8165 redraw_titles();
8166 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008167# ifdef FEAT_MBYTE
8168 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008169 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008170 {
8171 redraw_titles();
8172 }
8173# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008174#endif
8175
8176 /* when 'bin' is set also set some other options */
8177 else if ((int *)varp == &curbuf->b_p_bin)
8178 {
8179 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8180#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008181 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008182#endif
8183 }
8184
8185#ifdef FEAT_AUTOCMD
8186 /* when 'buflisted' changes, trigger autocommands */
8187 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8188 {
8189 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8190 NULL, NULL, TRUE, curbuf);
8191 }
8192#endif
8193
8194 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8195 else if ((int *)varp == &curbuf->b_p_swf)
8196 {
8197 if (curbuf->b_p_swf && p_uc)
8198 ml_open_file(curbuf); /* create the swap file */
8199 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008200 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8201 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 mf_close_file(curbuf, TRUE); /* remove the swap file */
8203 }
8204
8205 /* when 'terse' is set change 'shortmess' */
8206 else if ((int *)varp == &p_terse)
8207 {
8208 char_u *p;
8209
8210 p = vim_strchr(p_shm, SHM_SEARCH);
8211
8212 /* insert 's' in p_shm */
8213 if (p_terse && p == NULL)
8214 {
8215 STRCPY(IObuff, p_shm);
8216 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008217 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218 }
8219 /* remove 's' from p_shm */
8220 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008221 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222 }
8223
8224 /* when 'paste' is set or reset also change other options */
8225 else if ((int *)varp == &p_paste)
8226 {
8227 paste_option_changed();
8228 }
8229
8230 /* when 'insertmode' is set from an autocommand need to do work here */
8231 else if ((int *)varp == &p_im)
8232 {
8233 if (p_im)
8234 {
8235 if ((State & INSERT) == 0)
8236 need_start_insertmode = TRUE;
8237 stop_insert_mode = FALSE;
8238 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008239 /* only reset if it was set previously */
8240 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241 {
8242 need_start_insertmode = FALSE;
8243 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008244 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245 clear_cmdline = TRUE; /* remove "(insert)" */
8246 restart_edit = 0;
8247 }
8248 }
8249
8250 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8251 else if ((int *)varp == &p_ic && p_hls)
8252 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008253 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008254 }
8255
8256#ifdef FEAT_SEARCH_EXTRA
8257 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8258 else if ((int *)varp == &p_hls)
8259 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008260 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 }
8262#endif
8263
8264#ifdef FEAT_SCROLLBIND
8265 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8266 * at the end of normal_cmd() */
8267 else if ((int *)varp == &curwin->w_p_scb)
8268 {
8269 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008270 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008271 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008272 curwin->w_scbind_pos = curwin->w_topline;
8273 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008274 }
8275#endif
8276
8277#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8278 /* There can be only one window with 'previewwindow' set. */
8279 else if ((int *)varp == &curwin->w_p_pvw)
8280 {
8281 if (curwin->w_p_pvw)
8282 {
8283 win_T *win;
8284
Bram Moolenaar29323592016-07-24 22:04:11 +02008285 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008286 if (win->w_p_pvw && win != curwin)
8287 {
8288 curwin->w_p_pvw = FALSE;
8289 return (char_u *)N_("E590: A preview window already exists");
8290 }
8291 }
8292 }
8293#endif
8294
8295 /* when 'textmode' is set or reset also change 'fileformat' */
8296 else if ((int *)varp == &curbuf->b_p_tx)
8297 {
8298 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8299 }
8300
8301 /* when 'textauto' is set or reset also change 'fileformats' */
8302 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008303 set_string_option_direct((char_u *)"ffs", -1,
8304 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008305 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306
8307 /*
8308 * When 'lisp' option changes include/exclude '-' in
8309 * keyword characters.
8310 */
8311#ifdef FEAT_LISP
8312 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8313 {
8314 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8315 }
8316#endif
8317
8318#ifdef FEAT_TITLE
8319 /* when 'title' changed, may need to change the title; same for 'icon' */
8320 else if ((int *)varp == &p_title)
8321 {
8322 did_set_title(FALSE);
8323 }
8324
8325 else if ((int *)varp == &p_icon)
8326 {
8327 did_set_title(TRUE);
8328 }
8329#endif
8330
8331 else if ((int *)varp == &curbuf->b_changed)
8332 {
8333 if (!value)
8334 save_file_ff(curbuf); /* Buffer is unchanged */
8335#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008336 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337#endif
8338#ifdef FEAT_AUTOCMD
8339 modified_was_set = value;
8340#endif
8341 }
8342
8343#ifdef BACKSLASH_IN_FILENAME
8344 else if ((int *)varp == &p_ssl)
8345 {
8346 if (p_ssl)
8347 {
8348 psepc = '/';
8349 psepcN = '\\';
8350 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351 }
8352 else
8353 {
8354 psepc = '\\';
8355 psepcN = '/';
8356 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008357 }
8358
8359 /* need to adjust the file name arguments and buffer names. */
8360 buflist_slash_adjust();
8361 alist_slash_adjust();
8362# ifdef FEAT_EVAL
8363 scriptnames_slash_adjust();
8364# endif
8365 }
8366#endif
8367
8368 /* If 'wrap' is set, set w_leftcol to zero. */
8369 else if ((int *)varp == &curwin->w_p_wrap)
8370 {
8371 if (curwin->w_p_wrap)
8372 curwin->w_leftcol = 0;
8373 }
8374
8375#ifdef FEAT_WINDOWS
8376 else if ((int *)varp == &p_ea)
8377 {
8378 if (p_ea && !old_value)
8379 win_equal(curwin, FALSE, 0);
8380 }
8381#endif
8382
8383 else if ((int *)varp == &p_wiv)
8384 {
8385 /*
8386 * When 'weirdinvert' changed, set/reset 't_xs'.
8387 * Then set 'weirdinvert' according to value of 't_xs'.
8388 */
8389 if (p_wiv && !old_value)
8390 T_XS = (char_u *)"y";
8391 else if (!p_wiv && old_value)
8392 T_XS = empty_option;
8393 p_wiv = (*T_XS != NUL);
8394 }
8395
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008396#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008397 else if ((int *)varp == &p_beval)
8398 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008399 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008400 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008401 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008402 gui_mch_disable_beval_area(balloonEval);
8403 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008406#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 else if ((int *)varp == &p_acd)
8408 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008409 /* Change directories when the 'acd' option is set now. */
8410 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008411 }
8412#endif
8413
8414#ifdef FEAT_DIFF
8415 /* 'diff' */
8416 else if ((int *)varp == &curwin->w_p_diff)
8417 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008418 /* May add or remove the buffer from the list of diff buffers. */
8419 diff_buf_adjust(curwin);
8420# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421 if (foldmethodIsDiff(curwin))
8422 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008423# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008424 }
8425#endif
8426
8427#ifdef USE_IM_CONTROL
8428 /* 'imdisable' */
8429 else if ((int *)varp == &p_imdisable)
8430 {
8431 /* Only de-activate it here, it will be enabled when changing mode. */
8432 if (p_imdisable)
8433 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008434 else if (State & INSERT)
8435 /* When the option is set from an autocommand, it may need to take
8436 * effect right away. */
8437 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008438 }
8439#endif
8440
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008441#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008442 /* 'spell' */
8443 else if ((int *)varp == &curwin->w_p_spell)
8444 {
8445 if (curwin->w_p_spell)
8446 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008447 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008448 if (errmsg != NULL)
8449 EMSG(_(errmsg));
8450 }
8451 }
8452#endif
8453
Bram Moolenaar071d4272004-06-13 20:20:40 +00008454#ifdef FEAT_FKMAP
8455 else if ((int *)varp == &p_altkeymap)
8456 {
8457 if (old_value != p_altkeymap)
8458 {
8459 if (!p_altkeymap)
8460 {
8461 p_hkmap = p_fkmap;
8462 p_fkmap = 0;
8463 }
8464 else
8465 {
8466 p_fkmap = p_hkmap;
8467 p_hkmap = 0;
8468 }
8469 (void)init_chartab();
8470 }
8471 }
8472
8473 /*
8474 * In case some second language keymapping options have changed, check
8475 * and correct the setting in a consistent way.
8476 */
8477
8478 /*
8479 * If hkmap or fkmap are set, reset Arabic keymapping.
8480 */
8481 if ((p_hkmap || p_fkmap) && p_altkeymap)
8482 {
8483 p_altkeymap = p_fkmap;
8484# ifdef FEAT_ARABIC
8485 curwin->w_p_arab = FALSE;
8486# endif
8487 (void)init_chartab();
8488 }
8489
8490 /*
8491 * If hkmap set, reset Farsi keymapping.
8492 */
8493 if (p_hkmap && p_altkeymap)
8494 {
8495 p_altkeymap = 0;
8496 p_fkmap = 0;
8497# ifdef FEAT_ARABIC
8498 curwin->w_p_arab = FALSE;
8499# endif
8500 (void)init_chartab();
8501 }
8502
8503 /*
8504 * If fkmap set, reset Hebrew keymapping.
8505 */
8506 if (p_fkmap && !p_altkeymap)
8507 {
8508 p_altkeymap = 1;
8509 p_hkmap = 0;
8510# ifdef FEAT_ARABIC
8511 curwin->w_p_arab = FALSE;
8512# endif
8513 (void)init_chartab();
8514 }
8515#endif
8516
8517#ifdef FEAT_ARABIC
8518 if ((int *)varp == &curwin->w_p_arab)
8519 {
8520 if (curwin->w_p_arab)
8521 {
8522 /*
8523 * 'arabic' is set, handle various sub-settings.
8524 */
8525 if (!p_tbidi)
8526 {
8527 /* set rightleft mode */
8528 if (!curwin->w_p_rl)
8529 {
8530 curwin->w_p_rl = TRUE;
8531 changed_window_setting();
8532 }
8533
8534 /* Enable Arabic shaping (major part of what Arabic requires) */
8535 if (!p_arshape)
8536 {
8537 p_arshape = TRUE;
8538 redraw_later_clear();
8539 }
8540 }
8541
8542 /* Arabic requires a utf-8 encoding, inform the user if its not
8543 * set. */
8544 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008545 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008546 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8547
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008548 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008549 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8550#ifdef FEAT_EVAL
8551 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8552#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008553 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008554
8555# ifdef FEAT_MBYTE
8556 /* set 'delcombine' */
8557 p_deco = TRUE;
8558# endif
8559
8560# ifdef FEAT_KEYMAP
8561 /* Force-set the necessary keymap for arabic */
8562 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8563 OPT_LOCAL);
8564# endif
8565# ifdef FEAT_FKMAP
8566 p_altkeymap = 0;
8567 p_hkmap = 0;
8568 p_fkmap = 0;
8569 (void)init_chartab();
8570# endif
8571 }
8572 else
8573 {
8574 /*
8575 * 'arabic' is reset, handle various sub-settings.
8576 */
8577 if (!p_tbidi)
8578 {
8579 /* reset rightleft mode */
8580 if (curwin->w_p_rl)
8581 {
8582 curwin->w_p_rl = FALSE;
8583 changed_window_setting();
8584 }
8585
8586 /* 'arabicshape' isn't reset, it is a global option and
8587 * another window may still need it "on". */
8588 }
8589
8590 /* 'delcombine' isn't reset, it is a global option and another
8591 * window may still want it "on". */
8592
8593# ifdef FEAT_KEYMAP
8594 /* Revert to the default keymap */
8595 curbuf->b_p_iminsert = B_IMODE_NONE;
8596 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8597# endif
8598 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008599 }
8600
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008601#endif
8602
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008603#ifdef FEAT_TERMGUICOLORS
8604 /* 'termguicolors' */
8605 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008606 {
8607# ifdef FEAT_GUI
8608 if (!gui.in_use && !gui.starting)
8609# endif
8610 highlight_gui_started();
8611 }
8612#endif
8613
Bram Moolenaar071d4272004-06-13 20:20:40 +00008614 /*
8615 * End of handling side effects for bool options.
8616 */
8617
Bram Moolenaar53744302015-07-17 17:38:22 +02008618 /* after handling side effects, call autocommand */
8619
Bram Moolenaar071d4272004-06-13 20:20:40 +00008620 options[opt_idx].flags |= P_WAS_SET;
8621
Bram Moolenaar53744302015-07-17 17:38:22 +02008622#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8623 if (!starting)
8624 {
8625 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008626 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8627 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8628 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008629 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8630 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8631 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8632 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8633 reset_v_option_vars();
8634 }
8635#endif
8636
Bram Moolenaar071d4272004-06-13 20:20:40 +00008637 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008638 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008639 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008640 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 check_redraw(options[opt_idx].flags);
8642
8643 return NULL;
8644}
8645
8646/*
8647 * Set the value of a number option, and take care of side effects.
8648 * Returns NULL for success, or an error message for an error.
8649 */
8650 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008651set_num_option(
8652 int opt_idx, /* index in options[] table */
8653 char_u *varp, /* pointer to the option variable */
8654 long value, /* new value */
8655 char_u *errbuf, /* buffer for error messages */
8656 size_t errbuflen, /* length of "errbuf" */
8657 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008658 OPT_MODELINE */
8659{
8660 char_u *errmsg = NULL;
8661 long old_value = *(long *)varp;
8662 long old_Rows = Rows; /* remember old Rows */
8663 long old_Columns = Columns; /* remember old Columns */
8664 long *pp = (long *)varp;
8665
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008666 /* Disallow changing some options from secure mode. */
8667 if ((secure
8668#ifdef HAVE_SANDBOX
8669 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008670#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008671 ) && (options[opt_idx].flags & P_SECURE))
8672 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008673
8674 *pp = value;
8675#ifdef FEAT_EVAL
8676 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008677 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008678#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008679#ifdef FEAT_GUI
8680 need_mouse_correct = TRUE;
8681#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682
Bram Moolenaar14f24742012-08-08 18:01:05 +02008683 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684 {
8685 errmsg = e_positive;
8686 curbuf->b_p_sw = curbuf->b_p_ts;
8687 }
8688
8689 /*
8690 * Number options that need some action when changed
8691 */
8692#ifdef FEAT_WINDOWS
8693 if (pp == &p_wh || pp == &p_hh)
8694 {
8695 if (p_wh < 1)
8696 {
8697 errmsg = e_positive;
8698 p_wh = 1;
8699 }
8700 if (p_wmh > p_wh)
8701 {
8702 errmsg = e_winheight;
8703 p_wh = p_wmh;
8704 }
8705 if (p_hh < 0)
8706 {
8707 errmsg = e_positive;
8708 p_hh = 0;
8709 }
8710
8711 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008712 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008713 {
8714 if (pp == &p_wh && curwin->w_height < p_wh)
8715 win_setheight((int)p_wh);
8716 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8717 win_setheight((int)p_hh);
8718 }
8719 }
8720
8721 /* 'winminheight' */
8722 else if (pp == &p_wmh)
8723 {
8724 if (p_wmh < 0)
8725 {
8726 errmsg = e_positive;
8727 p_wmh = 0;
8728 }
8729 if (p_wmh > p_wh)
8730 {
8731 errmsg = e_winheight;
8732 p_wmh = p_wh;
8733 }
8734 win_setminheight();
8735 }
8736
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008737# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008738 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008739 {
8740 if (p_wiw < 1)
8741 {
8742 errmsg = e_positive;
8743 p_wiw = 1;
8744 }
8745 if (p_wmw > p_wiw)
8746 {
8747 errmsg = e_winwidth;
8748 p_wiw = p_wmw;
8749 }
8750
8751 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008752 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008753 win_setwidth((int)p_wiw);
8754 }
8755
8756 /* 'winminwidth' */
8757 else if (pp == &p_wmw)
8758 {
8759 if (p_wmw < 0)
8760 {
8761 errmsg = e_positive;
8762 p_wmw = 0;
8763 }
8764 if (p_wmw > p_wiw)
8765 {
8766 errmsg = e_winwidth;
8767 p_wmw = p_wiw;
8768 }
8769 win_setminheight();
8770 }
8771# endif
8772
8773#endif
8774
8775#ifdef FEAT_WINDOWS
8776 /* (re)set last window status line */
8777 else if (pp == &p_ls)
8778 {
8779 last_status(FALSE);
8780 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008781
8782 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008783 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008784 {
8785 shell_new_rows(); /* recompute window positions and heights */
8786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008787#endif
8788
8789#ifdef FEAT_GUI
8790 else if (pp == &p_linespace)
8791 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008792 /* Recompute gui.char_height and resize the Vim window to keep the
8793 * same number of lines. */
8794 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008795 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796 }
8797#endif
8798
8799#ifdef FEAT_FOLDING
8800 /* 'foldlevel' */
8801 else if (pp == &curwin->w_p_fdl)
8802 {
8803 if (curwin->w_p_fdl < 0)
8804 curwin->w_p_fdl = 0;
8805 newFoldLevel();
8806 }
8807
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008808 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 else if (pp == &curwin->w_p_fml)
8810 {
8811 foldUpdateAll(curwin);
8812 }
8813
8814 /* 'foldnestmax' */
8815 else if (pp == &curwin->w_p_fdn)
8816 {
8817 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8818 foldUpdateAll(curwin);
8819 }
8820
8821 /* 'foldcolumn' */
8822 else if (pp == &curwin->w_p_fdc)
8823 {
8824 if (curwin->w_p_fdc < 0)
8825 {
8826 errmsg = e_positive;
8827 curwin->w_p_fdc = 0;
8828 }
8829 else if (curwin->w_p_fdc > 12)
8830 {
8831 errmsg = e_invarg;
8832 curwin->w_p_fdc = 12;
8833 }
8834 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008835#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008836
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008837#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008838 /* 'shiftwidth' or 'tabstop' */
8839 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8840 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008841# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008842 if (foldmethodIsIndent(curwin))
8843 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008844# endif
8845# ifdef FEAT_CINDENT
8846 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8847 * parse 'cinoptions'. */
8848 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8849 parse_cino(curbuf);
8850# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008851 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008852#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008854#ifdef FEAT_MBYTE
8855 /* 'maxcombine' */
8856 else if (pp == &p_mco)
8857 {
8858 if (p_mco > MAX_MCO)
8859 p_mco = MAX_MCO;
8860 else if (p_mco < 0)
8861 p_mco = 0;
8862 screenclear(); /* will re-allocate the screen */
8863 }
8864#endif
8865
Bram Moolenaar071d4272004-06-13 20:20:40 +00008866 else if (pp == &curbuf->b_p_iminsert)
8867 {
8868 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8869 {
8870 errmsg = e_invarg;
8871 curbuf->b_p_iminsert = B_IMODE_NONE;
8872 }
8873 p_iminsert = curbuf->b_p_iminsert;
8874 if (termcap_active) /* don't do this in the alternate screen */
8875 showmode();
8876#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8877 /* Show/unshow value of 'keymap' in status lines. */
8878 status_redraw_curbuf();
8879#endif
8880 }
8881
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008882 else if (pp == &p_window)
8883 {
8884 if (p_window < 1)
8885 p_window = 1;
8886 else if (p_window >= Rows)
8887 p_window = Rows - 1;
8888 }
8889
Bram Moolenaar071d4272004-06-13 20:20:40 +00008890 else if (pp == &curbuf->b_p_imsearch)
8891 {
8892 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8893 {
8894 errmsg = e_invarg;
8895 curbuf->b_p_imsearch = B_IMODE_NONE;
8896 }
8897 p_imsearch = curbuf->b_p_imsearch;
8898 }
8899
8900#ifdef FEAT_TITLE
8901 /* if 'titlelen' has changed, redraw the title */
8902 else if (pp == &p_titlelen)
8903 {
8904 if (p_titlelen < 0)
8905 {
8906 errmsg = e_positive;
8907 p_titlelen = 85;
8908 }
8909 if (starting != NO_SCREEN && old_value != p_titlelen)
8910 need_maketitle = TRUE;
8911 }
8912#endif
8913
8914 /* if p_ch changed value, change the command line height */
8915 else if (pp == &p_ch)
8916 {
8917 if (p_ch < 1)
8918 {
8919 errmsg = e_positive;
8920 p_ch = 1;
8921 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008922 if (p_ch > Rows - min_rows() + 1)
8923 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924
8925 /* Only compute the new window layout when startup has been
8926 * completed. Otherwise the frame sizes may be wrong. */
8927 if (p_ch != old_value && full_screen
8928#ifdef FEAT_GUI
8929 && !gui.starting
8930#endif
8931 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008932 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008933 }
8934
8935 /* when 'updatecount' changes from zero to non-zero, open swap files */
8936 else if (pp == &p_uc)
8937 {
8938 if (p_uc < 0)
8939 {
8940 errmsg = e_positive;
8941 p_uc = 100;
8942 }
8943 if (p_uc && !old_value)
8944 ml_open_files();
8945 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008946#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008947 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008948 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008949 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008950 {
8951 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008952 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008953 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008954 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008955 {
8956 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008957 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008958 }
8959 }
8960#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008961#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008962 else if (pp == &p_mzq)
8963 mzvim_reset_timer();
8964#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008966#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8967 /* 'pyxversion' */
8968 else if (pp == &p_pyx)
8969 {
8970 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8971 errmsg = e_invarg;
8972 }
8973#endif
8974
Bram Moolenaar071d4272004-06-13 20:20:40 +00008975 /* sync undo before 'undolevels' changes */
8976 else if (pp == &p_ul)
8977 {
8978 /* use the old value, otherwise u_sync() may not work properly */
8979 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008980 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008981 p_ul = value;
8982 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008983 else if (pp == &curbuf->b_p_ul)
8984 {
8985 /* use the old value, otherwise u_sync() may not work properly */
8986 curbuf->b_p_ul = old_value;
8987 u_sync(TRUE);
8988 curbuf->b_p_ul = value;
8989 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008990
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008991#ifdef FEAT_LINEBREAK
8992 /* 'numberwidth' must be positive */
8993 else if (pp == &curwin->w_p_nuw)
8994 {
8995 if (curwin->w_p_nuw < 1)
8996 {
8997 errmsg = e_positive;
8998 curwin->w_p_nuw = 1;
8999 }
9000 if (curwin->w_p_nuw > 10)
9001 {
9002 errmsg = e_invarg;
9003 curwin->w_p_nuw = 10;
9004 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009005 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009006 }
9007#endif
9008
Bram Moolenaar1a384422010-07-14 19:53:30 +02009009 else if (pp == &curbuf->b_p_tw)
9010 {
9011 if (curbuf->b_p_tw < 0)
9012 {
9013 errmsg = e_positive;
9014 curbuf->b_p_tw = 0;
9015 }
9016#ifdef FEAT_SYN_HL
9017# ifdef FEAT_WINDOWS
9018 {
9019 win_T *wp;
9020 tabpage_T *tp;
9021
9022 FOR_ALL_TAB_WINDOWS(tp, wp)
9023 check_colorcolumn(wp);
9024 }
9025# else
9026 check_colorcolumn(curwin);
9027# endif
9028#endif
9029 }
9030
Bram Moolenaar071d4272004-06-13 20:20:40 +00009031 /*
9032 * Check the bounds for numeric options here
9033 */
9034 if (Rows < min_rows() && full_screen)
9035 {
9036 if (errbuf != NULL)
9037 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009038 vim_snprintf((char *)errbuf, errbuflen,
9039 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009040 errmsg = errbuf;
9041 }
9042 Rows = min_rows();
9043 }
9044 if (Columns < MIN_COLUMNS && full_screen)
9045 {
9046 if (errbuf != NULL)
9047 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009048 vim_snprintf((char *)errbuf, errbuflen,
9049 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050 errmsg = errbuf;
9051 }
9052 Columns = MIN_COLUMNS;
9053 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009054 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009055
Bram Moolenaar071d4272004-06-13 20:20:40 +00009056 /*
9057 * If the screen (shell) height has been changed, assume it is the
9058 * physical screenheight.
9059 */
9060 if (old_Rows != Rows || old_Columns != Columns)
9061 {
9062 /* Changing the screen size is not allowed while updating the screen. */
9063 if (updating_screen)
9064 *pp = old_value;
9065 else if (full_screen
9066#ifdef FEAT_GUI
9067 && !gui.starting
9068#endif
9069 )
9070 set_shellsize((int)Columns, (int)Rows, TRUE);
9071 else
9072 {
9073 /* Postpone the resizing; check the size and cmdline position for
9074 * messages. */
9075 check_shellsize();
9076 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9077 cmdline_row = Rows - p_ch;
9078 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009079 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009080 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009081 }
9082
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083 if (curbuf->b_p_ts <= 0)
9084 {
9085 errmsg = e_positive;
9086 curbuf->b_p_ts = 8;
9087 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009088 if (p_tm < 0)
9089 {
9090 errmsg = e_positive;
9091 p_tm = 0;
9092 }
9093 if ((curwin->w_p_scr <= 0
9094 || (curwin->w_p_scr > curwin->w_height
9095 && curwin->w_height > 0))
9096 && full_screen)
9097 {
9098 if (pp == &(curwin->w_p_scr))
9099 {
9100 if (curwin->w_p_scr != 0)
9101 errmsg = e_scroll;
9102 win_comp_scroll(curwin);
9103 }
9104 /* If 'scroll' became invalid because of a side effect silently adjust
9105 * it. */
9106 else if (curwin->w_p_scr <= 0)
9107 curwin->w_p_scr = 1;
9108 else /* curwin->w_p_scr > curwin->w_height */
9109 curwin->w_p_scr = curwin->w_height;
9110 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009111 if (p_hi < 0)
9112 {
9113 errmsg = e_positive;
9114 p_hi = 0;
9115 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009116 else if (p_hi > 10000)
9117 {
9118 errmsg = e_invarg;
9119 p_hi = 10000;
9120 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009121 if (p_re < 0 || p_re > 2)
9122 {
9123 errmsg = e_invarg;
9124 p_re = 0;
9125 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009126 if (p_report < 0)
9127 {
9128 errmsg = e_positive;
9129 p_report = 1;
9130 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009131 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009132 {
9133 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9134 p_sj = Rows / 2;
9135 else
9136 {
9137 errmsg = e_scroll;
9138 p_sj = 1;
9139 }
9140 }
9141 if (p_so < 0 && full_screen)
9142 {
9143 errmsg = e_scroll;
9144 p_so = 0;
9145 }
9146 if (p_siso < 0 && full_screen)
9147 {
9148 errmsg = e_positive;
9149 p_siso = 0;
9150 }
9151#ifdef FEAT_CMDWIN
9152 if (p_cwh < 1)
9153 {
9154 errmsg = e_positive;
9155 p_cwh = 1;
9156 }
9157#endif
9158 if (p_ut < 0)
9159 {
9160 errmsg = e_positive;
9161 p_ut = 2000;
9162 }
9163 if (p_ss < 0)
9164 {
9165 errmsg = e_positive;
9166 p_ss = 0;
9167 }
9168
9169 /* May set global value for local option. */
9170 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9171 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9172
9173 options[opt_idx].flags |= P_WAS_SET;
9174
Bram Moolenaar53744302015-07-17 17:38:22 +02009175#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9176 if (!starting && errmsg == NULL)
9177 {
9178 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009179 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9180 vim_snprintf((char *)buf_new, 10, "%ld", value);
9181 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009182 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9183 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9184 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9185 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9186 reset_v_option_vars();
9187 }
9188#endif
9189
Bram Moolenaar071d4272004-06-13 20:20:40 +00009190 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009191 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009192 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009193 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009194 check_redraw(options[opt_idx].flags);
9195
9196 return errmsg;
9197}
9198
9199/*
9200 * Called after an option changed: check if something needs to be redrawn.
9201 */
9202 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009203check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009204{
9205 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009206 int doclear = (flags & P_RCLR) == P_RCLR;
9207 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009208
9209#ifdef FEAT_WINDOWS
9210 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9211 status_redraw_all();
9212#endif
9213
9214 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9215 changed_window_setting();
9216 if (flags & P_RBUF)
9217 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009218 if (flags & P_RWINONLY)
9219 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009220 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009221 redraw_all_later(CLEAR);
9222 else if (all)
9223 redraw_all_later(NOT_VALID);
9224}
9225
9226/*
9227 * Find index for option 'arg'.
9228 * Return -1 if not found.
9229 */
9230 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009231findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009232{
9233 int opt_idx;
9234 char *s, *p;
9235 static short quick_tab[27] = {0, 0}; /* quick access table */
9236 int is_term_opt;
9237
9238 /*
9239 * For first call: Initialize the quick-access table.
9240 * It contains the index for the first option that starts with a certain
9241 * letter. There are 26 letters, plus the first "t_" option.
9242 */
9243 if (quick_tab[1] == 0)
9244 {
9245 p = options[0].fullname;
9246 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9247 {
9248 if (s[0] != p[0])
9249 {
9250 if (s[0] == 't' && s[1] == '_')
9251 quick_tab[26] = opt_idx;
9252 else
9253 quick_tab[CharOrdLow(s[0])] = opt_idx;
9254 }
9255 p = s;
9256 }
9257 }
9258
9259 /*
9260 * Check for name starting with an illegal character.
9261 */
9262#ifdef EBCDIC
9263 if (!islower(arg[0]))
9264#else
9265 if (arg[0] < 'a' || arg[0] > 'z')
9266#endif
9267 return -1;
9268
9269 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9270 if (is_term_opt)
9271 opt_idx = quick_tab[26];
9272 else
9273 opt_idx = quick_tab[CharOrdLow(arg[0])];
9274 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9275 {
9276 if (STRCMP(arg, s) == 0) /* match full name */
9277 break;
9278 }
9279 if (s == NULL && !is_term_opt)
9280 {
9281 opt_idx = quick_tab[CharOrdLow(arg[0])];
9282 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9283 {
9284 s = options[opt_idx].shortname;
9285 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9286 break;
9287 s = NULL;
9288 }
9289 }
9290 if (s == NULL)
9291 opt_idx = -1;
9292 return opt_idx;
9293}
9294
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009295#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009296/*
9297 * Get the value for an option.
9298 *
9299 * Returns:
9300 * Number or Toggle option: 1, *numval gets value.
9301 * String option: 0, *stringval gets allocated string.
9302 * Hidden Number or Toggle option: -1.
9303 * hidden String option: -2.
9304 * unknown option: -3.
9305 */
9306 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009307get_option_value(
9308 char_u *name,
9309 long *numval,
9310 char_u **stringval, /* NULL when only checking existence */
9311 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312{
9313 int opt_idx;
9314 char_u *varp;
9315
9316 opt_idx = findoption(name);
9317 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009318 {
9319 int key;
9320
9321 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9322 && (key = find_key_option(name)) != 0)
9323 {
9324 char_u key_name[2];
9325 char_u *p;
9326
9327 if (key < 0)
9328 {
9329 key_name[0] = KEY2TERMCAP0(key);
9330 key_name[1] = KEY2TERMCAP1(key);
9331 }
9332 else
9333 {
9334 key_name[0] = KS_KEY;
9335 key_name[1] = (key & 0xff);
9336 }
9337 p = find_termcode(key_name);
9338 if (p != NULL)
9339 {
9340 if (stringval != NULL)
9341 *stringval = vim_strsave(p);
9342 return 0;
9343 }
9344 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009346 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347
9348 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9349
9350 if (options[opt_idx].flags & P_STRING)
9351 {
9352 if (varp == NULL) /* hidden option */
9353 return -2;
9354 if (stringval != NULL)
9355 {
9356#ifdef FEAT_CRYPT
9357 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009358 if ((char_u **)varp == &curbuf->b_p_key
9359 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009360 *stringval = vim_strsave((char_u *)"*****");
9361 else
9362#endif
9363 *stringval = vim_strsave(*(char_u **)(varp));
9364 }
9365 return 0;
9366 }
9367
9368 if (varp == NULL) /* hidden option */
9369 return -1;
9370 if (options[opt_idx].flags & P_NUM)
9371 *numval = *(long *)varp;
9372 else
9373 {
9374 /* Special case: 'modified' is b_changed, but we also want to consider
9375 * it set when 'ff' or 'fenc' changed. */
9376 if ((int *)varp == &curbuf->b_changed)
9377 *numval = curbufIsChanged();
9378 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009379 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009380 }
9381 return 1;
9382}
9383#endif
9384
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009385#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009386/*
9387 * Returns the option attributes and its value. Unlike the above function it
9388 * will return either global value or local value of the option depending on
9389 * what was requested, but it will never return global value if it was
9390 * requested to return local one and vice versa. Neither it will return
9391 * buffer-local value if it was requested to return window-local one.
9392 *
9393 * Pretends that option is absent if it is not present in the requested scope
9394 * (i.e. has no global, window-local or buffer-local value depending on
9395 * opt_type). Uses
9396 *
9397 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009398 * 0 hidden or unknown option, also option that does not have requested
9399 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009400 * see SOPT_* in vim.h for other flags
9401 *
9402 * Possible opt_type values: see SREQ_* in vim.h
9403 */
9404 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009405get_option_value_strict(
9406 char_u *name,
9407 long *numval,
9408 char_u **stringval, /* NULL when only obtaining attributes */
9409 int opt_type,
9410 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009411{
9412 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009413 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009414 struct vimoption *p;
9415 int r = 0;
9416
9417 opt_idx = findoption(name);
9418 if (opt_idx < 0)
9419 return 0;
9420
9421 p = &(options[opt_idx]);
9422
9423 /* Hidden option */
9424 if (p->var == NULL)
9425 return 0;
9426
9427 if (p->flags & P_BOOL)
9428 r |= SOPT_BOOL;
9429 else if (p->flags & P_NUM)
9430 r |= SOPT_NUM;
9431 else if (p->flags & P_STRING)
9432 r |= SOPT_STRING;
9433
9434 if (p->indir == PV_NONE)
9435 {
9436 if (opt_type == SREQ_GLOBAL)
9437 r |= SOPT_GLOBAL;
9438 else
9439 return 0; /* Did not request global-only option */
9440 }
9441 else
9442 {
9443 if (p->indir & PV_BOTH)
9444 r |= SOPT_GLOBAL;
9445 else if (opt_type == SREQ_GLOBAL)
9446 return 0; /* Requested global option */
9447
9448 if (p->indir & PV_WIN)
9449 {
9450 if (opt_type == SREQ_BUF)
9451 return 0; /* Did not request window-local option */
9452 else
9453 r |= SOPT_WIN;
9454 }
9455 else if (p->indir & PV_BUF)
9456 {
9457 if (opt_type == SREQ_WIN)
9458 return 0; /* Did not request buffer-local option */
9459 else
9460 r |= SOPT_BUF;
9461 }
9462 }
9463
9464 if (stringval == NULL)
9465 return r;
9466
9467 if (opt_type == SREQ_GLOBAL)
9468 varp = p->var;
9469 else
9470 {
9471 if (opt_type == SREQ_BUF)
9472 {
9473 /* Special case: 'modified' is b_changed, but we also want to
9474 * consider it set when 'ff' or 'fenc' changed. */
9475 if (p->indir == PV_MOD)
9476 {
9477 *numval = bufIsChanged((buf_T *) from);
9478 varp = NULL;
9479 }
9480#ifdef FEAT_CRYPT
9481 else if (p->indir == PV_KEY)
9482 {
9483 /* never return the value of the crypt key */
9484 *stringval = NULL;
9485 varp = NULL;
9486 }
9487#endif
9488 else
9489 {
9490 aco_save_T aco;
9491 aucmd_prepbuf(&aco, (buf_T *) from);
9492 varp = get_varp(p);
9493 aucmd_restbuf(&aco);
9494 }
9495 }
9496 else if (opt_type == SREQ_WIN)
9497 {
9498 win_T *save_curwin;
9499 save_curwin = curwin;
9500 curwin = (win_T *) from;
9501 curbuf = curwin->w_buffer;
9502 varp = get_varp(p);
9503 curwin = save_curwin;
9504 curbuf = curwin->w_buffer;
9505 }
9506 if (varp == p->var)
9507 return (r | SOPT_UNSET);
9508 }
9509
9510 if (varp != NULL)
9511 {
9512 if (p->flags & P_STRING)
9513 *stringval = vim_strsave(*(char_u **)(varp));
9514 else if (p->flags & P_NUM)
9515 *numval = *(long *) varp;
9516 else
9517 *numval = *(int *)varp;
9518 }
9519
9520 return r;
9521}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009522
9523/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009524 * Iterate over options. First argument is a pointer to a pointer to a
9525 * structure inside options[] array, second is option type like in the above
9526 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009527 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009528 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009529 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009530 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009531 * first argument to NULL.
9532 *
9533 * Returns full option name for current option on each call.
9534 */
9535 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009536option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009537{
9538 struct vimoption *ret = NULL;
9539 do
9540 {
9541 if (*option == NULL)
9542 *option = (void *) options;
9543 else if (((struct vimoption *) (*option))->fullname == NULL)
9544 {
9545 *option = NULL;
9546 return NULL;
9547 }
9548 else
9549 *option = (void *) (((struct vimoption *) (*option)) + 1);
9550
9551 ret = ((struct vimoption *) (*option));
9552
9553 /* Hidden option */
9554 if (ret->var == NULL)
9555 {
9556 ret = NULL;
9557 continue;
9558 }
9559
9560 switch (opt_type)
9561 {
9562 case SREQ_GLOBAL:
9563 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9564 ret = NULL;
9565 break;
9566 case SREQ_BUF:
9567 if (!(ret->indir & PV_BUF))
9568 ret = NULL;
9569 break;
9570 case SREQ_WIN:
9571 if (!(ret->indir & PV_WIN))
9572 ret = NULL;
9573 break;
9574 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009575 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009576 return NULL;
9577 }
9578 }
9579 while (ret == NULL);
9580
9581 return (char_u *)ret->fullname;
9582}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009583#endif
9584
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585/*
9586 * Set the value of option "name".
9587 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009588 *
9589 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009590 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009591 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009592set_option_value(
9593 char_u *name,
9594 long number,
9595 char_u *string,
9596 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009597{
9598 int opt_idx;
9599 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009600 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009601
9602 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009603 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009604 {
9605 int key;
9606
9607 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9608 && (key = find_key_option(name)) != 0)
9609 {
9610 char_u key_name[2];
9611
9612 if (key < 0)
9613 {
9614 key_name[0] = KEY2TERMCAP0(key);
9615 key_name[1] = KEY2TERMCAP1(key);
9616 }
9617 else
9618 {
9619 key_name[0] = KS_KEY;
9620 key_name[1] = (key & 0xff);
9621 }
9622 add_termcode(key_name, string, FALSE);
9623 if (full_screen)
9624 ttest(FALSE);
9625 redraw_all_later(CLEAR);
9626 return NULL;
9627 }
9628
Bram Moolenaar071d4272004-06-13 20:20:40 +00009629 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009630 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009631 else
9632 {
9633 flags = options[opt_idx].flags;
9634#ifdef HAVE_SANDBOX
9635 /* Disallow changing some options in the sandbox */
9636 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009637 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009638 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009639 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009640 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009641#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009642 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009643 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644 else
9645 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009646 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009647 if (varp != NULL) /* hidden option is not changed */
9648 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009649 if (number == 0 && string != NULL)
9650 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009651 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009652
9653 /* Either we are given a string or we are setting option
9654 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009655 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009656 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009657 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009658 {
9659 /* There's another character after zeros or the string
9660 * is empty. In both cases, we are trying to set a
9661 * num option using a string. */
9662 EMSG3(_("E521: Number required: &%s = '%s'"),
9663 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009664 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009665
9666 }
9667 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009668 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009669 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009670 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009671 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009672 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009673 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009674 }
9675 }
9676 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009677 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009678}
9679
9680/*
9681 * Get the terminal code for a terminal option.
9682 * Returns NULL when not found.
9683 */
9684 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009685get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009686{
9687 int opt_idx;
9688 char_u *varp;
9689
9690 if (tname[0] != 't' || tname[1] != '_' ||
9691 tname[2] == NUL || tname[3] == NUL)
9692 return NULL;
9693 if ((opt_idx = findoption(tname)) >= 0)
9694 {
9695 varp = get_varp(&(options[opt_idx]));
9696 if (varp != NULL)
9697 varp = *(char_u **)(varp);
9698 return varp;
9699 }
9700 return find_termcode(tname + 2);
9701}
9702
9703 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009704get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009705{
9706 int i;
9707
9708 i = findoption((char_u *)"hl");
9709 if (i >= 0)
9710 return options[i].def_val[VI_DEFAULT];
9711 return (char_u *)NULL;
9712}
9713
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009714#if defined(FEAT_MBYTE) || defined(PROTO)
9715 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009716get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009717{
9718 int i;
9719
9720 i = findoption((char_u *)"enc");
9721 if (i >= 0)
9722 return options[i].def_val[VI_DEFAULT];
9723 return (char_u *)NULL;
9724}
9725#endif
9726
Bram Moolenaar071d4272004-06-13 20:20:40 +00009727/*
9728 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9729 */
9730 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009731find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009732{
9733 int key;
9734 int modifiers;
9735
9736 /*
9737 * Don't use get_special_key_code() for t_xx, we don't want it to call
9738 * add_termcap_entry().
9739 */
9740 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9741 key = TERMCAP2KEY(arg[2], arg[3]);
9742 else
9743 {
9744 --arg; /* put arg at the '<' */
9745 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009746 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009747 if (modifiers) /* can't handle modifiers here */
9748 key = 0;
9749 }
9750 return key;
9751}
9752
9753/*
9754 * if 'all' == 0: show changed options
9755 * if 'all' == 1: show all normal options
9756 * if 'all' == 2: show all terminal options
9757 */
9758 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009759showoptions(
9760 int all,
9761 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009762{
9763 struct vimoption *p;
9764 int col;
9765 int isterm;
9766 char_u *varp;
9767 struct vimoption **items;
9768 int item_count;
9769 int run;
9770 int row, rows;
9771 int cols;
9772 int i;
9773 int len;
9774
9775#define INC 20
9776#define GAP 3
9777
9778 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9779 PARAM_COUNT));
9780 if (items == NULL)
9781 return;
9782
9783 /* Highlight title */
9784 if (all == 2)
9785 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9786 else if (opt_flags & OPT_GLOBAL)
9787 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9788 else if (opt_flags & OPT_LOCAL)
9789 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9790 else
9791 MSG_PUTS_TITLE(_("\n--- Options ---"));
9792
9793 /*
9794 * do the loop two times:
9795 * 1. display the short items
9796 * 2. display the long items (only strings and numbers)
9797 */
9798 for (run = 1; run <= 2 && !got_int; ++run)
9799 {
9800 /*
9801 * collect the items in items[]
9802 */
9803 item_count = 0;
9804 for (p = &options[0]; p->fullname != NULL; p++)
9805 {
9806 varp = NULL;
9807 isterm = istermoption(p);
9808 if (opt_flags != 0)
9809 {
9810 if (p->indir != PV_NONE && !isterm)
9811 varp = get_varp_scope(p, opt_flags);
9812 }
9813 else
9814 varp = get_varp(p);
9815 if (varp != NULL
9816 && ((all == 2 && isterm)
9817 || (all == 1 && !isterm)
9818 || (all == 0 && !optval_default(p, varp))))
9819 {
9820 if (p->flags & P_BOOL)
9821 len = 1; /* a toggle option fits always */
9822 else
9823 {
9824 option_value2string(p, opt_flags);
9825 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9826 }
9827 if ((len <= INC - GAP && run == 1) ||
9828 (len > INC - GAP && run == 2))
9829 items[item_count++] = p;
9830 }
9831 }
9832
9833 /*
9834 * display the items
9835 */
9836 if (run == 1)
9837 {
9838 cols = (Columns + GAP - 3) / INC;
9839 if (cols == 0)
9840 cols = 1;
9841 rows = (item_count + cols - 1) / cols;
9842 }
9843 else /* run == 2 */
9844 rows = item_count;
9845 for (row = 0; row < rows && !got_int; ++row)
9846 {
9847 msg_putchar('\n'); /* go to next line */
9848 if (got_int) /* 'q' typed in more */
9849 break;
9850 col = 0;
9851 for (i = row; i < item_count; i += rows)
9852 {
9853 msg_col = col; /* make columns */
9854 showoneopt(items[i], opt_flags);
9855 col += INC;
9856 }
9857 out_flush();
9858 ui_breakcheck();
9859 }
9860 }
9861 vim_free(items);
9862}
9863
9864/*
9865 * Return TRUE if option "p" has its default value.
9866 */
9867 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009868optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009869{
9870 int dvi;
9871
9872 if (varp == NULL)
9873 return TRUE; /* hidden option is always at default */
9874 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9875 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009876 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009878 /* the cast to long is required for Manx C, long_i is
9879 * needed for MSVC */
9880 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009881 /* P_STRING */
9882 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9883}
9884
9885/*
9886 * showoneopt: show the value of one option
9887 * must not be called with a hidden option!
9888 */
9889 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009890showoneopt(
9891 struct vimoption *p,
9892 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009893{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009894 char_u *varp;
9895 int save_silent = silent_mode;
9896
9897 silent_mode = FALSE;
9898 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899
9900 varp = get_varp_scope(p, opt_flags);
9901
9902 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9903 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9904 ? !curbufIsChanged() : !*(int *)varp))
9905 MSG_PUTS("no");
9906 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9907 MSG_PUTS("--");
9908 else
9909 MSG_PUTS(" ");
9910 MSG_PUTS(p->fullname);
9911 if (!(p->flags & P_BOOL))
9912 {
9913 msg_putchar('=');
9914 /* put value string in NameBuff */
9915 option_value2string(p, opt_flags);
9916 msg_outtrans(NameBuff);
9917 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009918
9919 silent_mode = save_silent;
9920 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921}
9922
9923/*
9924 * Write modified options as ":set" commands to a file.
9925 *
9926 * There are three values for "opt_flags":
9927 * OPT_GLOBAL: Write global option values and fresh values of
9928 * buffer-local options (used for start of a session
9929 * file).
9930 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9931 * curwin (used for a vimrc file).
9932 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9933 * and local values for window-local options of
9934 * curwin. Local values are also written when at the
9935 * default value, because a modeline or autocommand
9936 * may have set them when doing ":edit file" and the
9937 * user has set them back at the default or fresh
9938 * value.
9939 * When "local_only" is TRUE, don't write fresh
9940 * values, only local values (for ":mkview").
9941 * (fresh value = value used for a new buffer or window for a local option).
9942 *
9943 * Return FAIL on error, OK otherwise.
9944 */
9945 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009946makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009947{
9948 struct vimoption *p;
9949 char_u *varp; /* currently used value */
9950 char_u *varp_fresh; /* local value */
9951 char_u *varp_local = NULL; /* fresh value */
9952 char *cmd;
9953 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009954 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009955
9956 /*
9957 * The options that don't have a default (terminal name, columns, lines)
9958 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009959 * Do the loop over "options[]" twice: once for options with the
9960 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009961 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009962 for (pri = 1; pri >= 0; --pri)
9963 {
9964 for (p = &options[0]; !istermoption(p); p++)
9965 if (!(p->flags & P_NO_MKRC)
9966 && !istermoption(p)
9967 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009968 {
9969 /* skip global option when only doing locals */
9970 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9971 continue;
9972
9973 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9974 * file, they are always buffer-specific. */
9975 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9976 continue;
9977
9978 /* Global values are only written when not at the default value. */
9979 varp = get_varp_scope(p, opt_flags);
9980 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9981 continue;
9982
9983 round = 2;
9984 if (p->indir != PV_NONE)
9985 {
9986 if (p->var == VAR_WIN)
9987 {
9988 /* skip window-local option when only doing globals */
9989 if (!(opt_flags & OPT_LOCAL))
9990 continue;
9991 /* When fresh value of window-local option is not at the
9992 * default, need to write it too. */
9993 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9994 {
9995 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9996 if (!optval_default(p, varp_fresh))
9997 {
9998 round = 1;
9999 varp_local = varp;
10000 varp = varp_fresh;
10001 }
10002 }
10003 }
10004 }
10005
10006 /* Round 1: fresh value for window-local options.
10007 * Round 2: other values */
10008 for ( ; round <= 2; varp = varp_local, ++round)
10009 {
10010 if (round == 1 || (opt_flags & OPT_GLOBAL))
10011 cmd = "set";
10012 else
10013 cmd = "setlocal";
10014
10015 if (p->flags & P_BOOL)
10016 {
10017 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10018 return FAIL;
10019 }
10020 else if (p->flags & P_NUM)
10021 {
10022 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10023 return FAIL;
10024 }
10025 else /* P_STRING */
10026 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010027#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10028 int do_endif = FALSE;
10029
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030 /* Don't set 'syntax' and 'filetype' again if the value is
10031 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010032 if (
10033# if defined(FEAT_SYN_HL)
10034 p->indir == PV_SYN
10035# if defined(FEAT_AUTOCMD)
10036 ||
10037# endif
10038# endif
10039# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010040 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010041# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +000010042 )
Bram Moolenaar071d4272004-06-13 20:20:40 +000010043 {
10044 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10045 *(char_u **)(varp)) < 0
10046 || put_eol(fd) < 0)
10047 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010048 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010049 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010051 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10052 (p->flags & P_EXPAND) != 0) == FAIL)
10053 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010054#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
10055 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010056 {
10057 if (put_line(fd, "endif") == FAIL)
10058 return FAIL;
10059 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010060#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010061 }
10062 }
10063 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010064 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010065 return OK;
10066}
10067
10068#if defined(FEAT_FOLDING) || defined(PROTO)
10069/*
10070 * Generate set commands for the local fold options only. Used when
10071 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10072 */
10073 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010074makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010075{
10076 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10077# ifdef FEAT_EVAL
10078 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10079 == FAIL
10080# endif
10081 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10082 == FAIL
10083 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10084 == FAIL
10085 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10086 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10087 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10088 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10089 )
10090 return FAIL;
10091
10092 return OK;
10093}
10094#endif
10095
10096 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010097put_setstring(
10098 FILE *fd,
10099 char *cmd,
10100 char *name,
10101 char_u **valuep,
10102 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010103{
10104 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010105 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010106
10107 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10108 return FAIL;
10109 if (*valuep != NULL)
10110 {
10111 /* Output 'pastetoggle' as key names. For other
10112 * options some characters have to be escaped with
10113 * CTRL-V or backslash */
10114 if (valuep == &p_pt)
10115 {
10116 s = *valuep;
10117 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010118 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010119 return FAIL;
10120 }
10121 else if (expand)
10122 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010123 buf = alloc(MAXPATHL);
10124 if (buf == NULL)
10125 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010126 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10127 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010128 {
10129 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010130 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010131 }
10132 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133 }
10134 else if (put_escstr(fd, *valuep, 2) == FAIL)
10135 return FAIL;
10136 }
10137 if (put_eol(fd) < 0)
10138 return FAIL;
10139 return OK;
10140}
10141
10142 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010143put_setnum(
10144 FILE *fd,
10145 char *cmd,
10146 char *name,
10147 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010148{
10149 long wc;
10150
10151 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10152 return FAIL;
10153 if (wc_use_keyname((char_u *)valuep, &wc))
10154 {
10155 /* print 'wildchar' and 'wildcharm' as a key name */
10156 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10157 return FAIL;
10158 }
10159 else if (fprintf(fd, "%ld", *valuep) < 0)
10160 return FAIL;
10161 if (put_eol(fd) < 0)
10162 return FAIL;
10163 return OK;
10164}
10165
10166 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010167put_setbool(
10168 FILE *fd,
10169 char *cmd,
10170 char *name,
10171 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172{
Bram Moolenaar893de922007-10-02 18:40:57 +000010173 if (value < 0) /* global/local option using global value */
10174 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10176 || put_eol(fd) < 0)
10177 return FAIL;
10178 return OK;
10179}
10180
10181/*
10182 * Clear all the terminal options.
10183 * If the option has been allocated, free the memory.
10184 * Terminal options are never hidden or indirect.
10185 */
10186 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010187clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 /*
10190 * Reset a few things before clearing the old options. This may cause
10191 * outputting a few things that the terminal doesn't understand, but the
10192 * screen will be cleared later, so this is OK.
10193 */
10194#ifdef FEAT_MOUSE_TTY
10195 mch_setmouse(FALSE); /* switch mouse off */
10196#endif
10197#ifdef FEAT_TITLE
10198 mch_restore_title(3); /* restore window titles */
10199#endif
10200#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10201 /* When starting the GUI close the display opened for the clipboard.
10202 * After restoring the title, because that will need the display. */
10203 if (gui.starting)
10204 clear_xterm_clip();
10205#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010206 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010208 free_termoptions();
10209}
10210
10211 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010212free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010213{
10214 struct vimoption *p;
10215
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216 for (p = &options[0]; p->fullname != NULL; p++)
10217 if (istermoption(p))
10218 {
10219 if (p->flags & P_ALLOCED)
10220 free_string_option(*(char_u **)(p->var));
10221 if (p->flags & P_DEF_ALLOCED)
10222 free_string_option(p->def_val[VI_DEFAULT]);
10223 *(char_u **)(p->var) = empty_option;
10224 p->def_val[VI_DEFAULT] = empty_option;
10225 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10226 }
10227 clear_termcodes();
10228}
10229
10230/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010231 * Free the string for one term option, if it was allocated.
10232 * Set the string to empty_option and clear allocated flag.
10233 * "var" points to the option value.
10234 */
10235 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010236free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010237{
10238 struct vimoption *p;
10239
10240 for (p = &options[0]; p->fullname != NULL; p++)
10241 if (p->var == var)
10242 {
10243 if (p->flags & P_ALLOCED)
10244 free_string_option(*(char_u **)(p->var));
10245 *(char_u **)(p->var) = empty_option;
10246 p->flags &= ~P_ALLOCED;
10247 break;
10248 }
10249}
10250
10251/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252 * Set the terminal option defaults to the current value.
10253 * Used after setting the terminal name.
10254 */
10255 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010256set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257{
10258 struct vimoption *p;
10259
10260 for (p = &options[0]; p->fullname != NULL; p++)
10261 {
10262 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10263 {
10264 if (p->flags & P_DEF_ALLOCED)
10265 {
10266 free_string_option(p->def_val[VI_DEFAULT]);
10267 p->flags &= ~P_DEF_ALLOCED;
10268 }
10269 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10270 if (p->flags & P_ALLOCED)
10271 {
10272 p->flags |= P_DEF_ALLOCED;
10273 p->flags &= ~P_ALLOCED; /* don't free the value now */
10274 }
10275 }
10276 }
10277}
10278
10279/*
10280 * return TRUE if 'p' starts with 't_'
10281 */
10282 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010283istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010284{
10285 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10286}
10287
10288/*
10289 * Compute columns for ruler and shown command. 'sc_col' is also used to
10290 * decide what the maximum length of a message on the status line can be.
10291 * If there is a status line for the last window, 'sc_col' is independent
10292 * of 'ru_col'.
10293 */
10294
10295#define COL_RULER 17 /* columns needed by standard ruler */
10296
10297 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010298comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010299{
10300#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010301 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302
10303 sc_col = 0;
10304 ru_col = 0;
10305 if (p_ru)
10306 {
10307#ifdef FEAT_STL_OPT
10308 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10309#else
10310 ru_col = COL_RULER + 1;
10311#endif
10312 /* no last status line, adjust sc_col */
10313 if (!last_has_status)
10314 sc_col = ru_col;
10315 }
10316 if (p_sc)
10317 {
10318 sc_col += SHOWCMD_COLS;
10319 if (!p_ru || last_has_status) /* no need for separating space */
10320 ++sc_col;
10321 }
10322 sc_col = Columns - sc_col;
10323 ru_col = Columns - ru_col;
10324 if (sc_col <= 0) /* screen too narrow, will become a mess */
10325 sc_col = 1;
10326 if (ru_col <= 0)
10327 ru_col = 1;
10328#else
10329 sc_col = Columns;
10330 ru_col = Columns;
10331#endif
10332}
10333
10334/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010335 * Unset local option value, similar to ":set opt<".
10336 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010337 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010338unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010339{
10340 struct vimoption *p;
10341 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010342 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010343
10344 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010345 if (opt_idx < 0)
10346 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010347 p = &(options[opt_idx]);
10348
10349 switch ((int)p->indir)
10350 {
10351 /* global option with local value: use local value if it's been set */
10352 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010353 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010354 break;
10355 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010356 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010357 break;
10358 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010359 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010360 break;
10361 case PV_AR:
10362 buf->b_p_ar = -1;
10363 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010364 case PV_BKC:
10365 clear_string_option(&buf->b_p_bkc);
10366 buf->b_bkc_flags = 0;
10367 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010368 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010369 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010370 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010371 case PV_TC:
10372 clear_string_option(&buf->b_p_tc);
10373 buf->b_tc_flags = 0;
10374 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010375#ifdef FEAT_FIND_ID
10376 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010377 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010378 break;
10379 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010380 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010381 break;
10382#endif
10383#ifdef FEAT_INS_EXPAND
10384 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010385 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010386 break;
10387 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010388 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010389 break;
10390#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010391 case PV_FP:
10392 clear_string_option(&buf->b_p_fp);
10393 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010394#ifdef FEAT_QUICKFIX
10395 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010396 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010397 break;
10398 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010399 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010400 break;
10401 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010402 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010403 break;
10404#endif
10405#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10406 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010407 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010408 break;
10409#endif
10410#if defined(FEAT_CRYPT)
10411 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010412 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010413 break;
10414#endif
10415#ifdef FEAT_STL_OPT
10416 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010417 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010418 break;
10419#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010420 case PV_UL:
10421 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10422 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010423#ifdef FEAT_LISP
10424 case PV_LW:
10425 clear_string_option(&buf->b_p_lw);
10426 break;
10427#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010428 }
10429}
10430
10431/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432 * Get pointer to option variable, depending on local or global scope.
10433 */
10434 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010435get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010436{
10437 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10438 {
10439 if (p->var == VAR_WIN)
10440 return (char_u *)GLOBAL_WO(get_varp(p));
10441 return p->var;
10442 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010443 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010444 {
10445 switch ((int)p->indir)
10446 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010447 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010449 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10450 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10451 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010453 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10454 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10455 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010456 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010457 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010458 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010460 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10461 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010462#endif
10463#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010464 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10465 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010466#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010467#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10468 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10469#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010470#if defined(FEAT_CRYPT)
10471 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10472#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010473#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010474 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010475#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010476 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010477#ifdef FEAT_LISP
10478 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10479#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010480 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481 }
10482 return NULL; /* "cannot happen" */
10483 }
10484 return get_varp(p);
10485}
10486
10487/*
10488 * Get pointer to option variable.
10489 */
10490 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010491get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010492{
10493 /* hidden option, always return NULL */
10494 if (p->var == NULL)
10495 return NULL;
10496
10497 switch ((int)p->indir)
10498 {
10499 case PV_NONE: return p->var;
10500
10501 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010502 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010503 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010504 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010505 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010506 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010508 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010509 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010510 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010512 case PV_TC: return *curbuf->b_p_tc != NUL
10513 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010514 case PV_BKC: return *curbuf->b_p_bkc != NUL
10515 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010517 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010518 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010519 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10521#endif
10522#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010523 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010525 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010526 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10527#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010528 case PV_FP: return *curbuf->b_p_fp != NUL
10529 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010530#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010531 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010532 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010533 case PV_GP: return *curbuf->b_p_gp != NUL
10534 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10535 case PV_MP: return *curbuf->b_p_mp != NUL
10536 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010538#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10539 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10540 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10541#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010542#if defined(FEAT_CRYPT)
10543 case PV_CM: return *curbuf->b_p_cm != NUL
10544 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10545#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010546#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010547 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010548 ? (char_u *)&(curwin->w_p_stl) : p->var;
10549#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010550 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10551 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010552#ifdef FEAT_LISP
10553 case PV_LW: return *curbuf->b_p_lw != NUL
10554 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10555#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556
10557#ifdef FEAT_ARABIC
10558 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10559#endif
10560 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010561#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010562 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10563#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010564#ifdef FEAT_SYN_HL
10565 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10566 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010567 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010568#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010569#ifdef FEAT_DIFF
10570 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10571#endif
10572#ifdef FEAT_FOLDING
10573 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10574 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10575 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10576 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10577 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10578 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10579 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10580# ifdef FEAT_EVAL
10581 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10582 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10583# endif
10584 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10585#endif
10586 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010587 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010588#ifdef FEAT_LINEBREAK
10589 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10590#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010591#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010593 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10594#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10596 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10597#endif
10598#ifdef FEAT_RIGHTLEFT
10599 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10600 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10601#endif
10602 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10603 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10604#ifdef FEAT_LINEBREAK
10605 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010606 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10607 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608#endif
10609#ifdef FEAT_SCROLLBIND
10610 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10611#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010612#ifdef FEAT_CURSORBIND
10613 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10614#endif
10615#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010616 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10617 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010618#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619
10620 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10621 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10622#ifdef FEAT_MBYTE
10623 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10624#endif
10625#if defined(FEAT_QUICKFIX)
10626 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10627 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10628#endif
10629 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10630 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10631#ifdef FEAT_CINDENT
10632 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10633 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10634 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10635#endif
10636#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10637 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10638#endif
10639#ifdef FEAT_COMMENTS
10640 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10641#endif
10642#ifdef FEAT_FOLDING
10643 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10644#endif
10645#ifdef FEAT_INS_EXPAND
10646 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10647#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010648#ifdef FEAT_COMPL_FUNC
10649 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010650 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010651#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010652 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010653 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010654 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10655#ifdef FEAT_MBYTE
10656 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10657#endif
10658 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10659#ifdef FEAT_AUTOCMD
10660 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10661#endif
10662 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010663 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010664 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10665 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10666 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10667 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10668#ifdef FEAT_FIND_ID
10669# ifdef FEAT_EVAL
10670 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10671# endif
10672#endif
10673#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10674 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10675 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10676#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010677#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010678 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10679#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010680#ifdef FEAT_CRYPT
10681 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10682#endif
10683#ifdef FEAT_LISP
10684 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10685#endif
10686 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10687 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10688 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10689 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10690 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010692#ifdef FEAT_TEXTOBJ
10693 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10694#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010695 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10696#ifdef FEAT_SMARTINDENT
10697 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010700 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10701#ifdef FEAT_SEARCHPATH
10702 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10703#endif
10704 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10705#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010706 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010707 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10708#endif
10709#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010710 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10711 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10712 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713#endif
10714 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10715 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10716 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10717 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010718#ifdef FEAT_PERSISTENT_UNDO
10719 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10720#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10722#ifdef FEAT_KEYMAP
10723 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10724#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010725#ifdef FEAT_SIGNS
10726 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10727#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010728 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 }
10730 /* always return a valid pointer to avoid a crash! */
10731 return (char_u *)&(curbuf->b_p_wm);
10732}
10733
10734/*
10735 * Get the value of 'equalprg', either the buffer-local one or the global one.
10736 */
10737 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010738get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739{
10740 if (*curbuf->b_p_ep == NUL)
10741 return p_ep;
10742 return curbuf->b_p_ep;
10743}
10744
10745#if defined(FEAT_WINDOWS) || defined(PROTO)
10746/*
10747 * Copy options from one window to another.
10748 * Used when splitting a window.
10749 */
10750 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010751win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752{
10753 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10754 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10755# ifdef FEAT_RIGHTLEFT
10756# ifdef FEAT_FKMAP
10757 /* Is this right? */
10758 wp_to->w_farsi = wp_from->w_farsi;
10759# endif
10760# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010761#if defined(FEAT_LINEBREAK)
10762 briopt_check(wp_to);
10763#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764}
10765#endif
10766
10767/*
10768 * Copy the options from one winopt_T to another.
10769 * Doesn't free the old option values in "to", use clear_winopt() for that.
10770 * The 'scroll' option is not copied, because it depends on the window height.
10771 * The 'previewwindow' option is reset, there can be only one preview window.
10772 */
10773 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010774copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775{
10776#ifdef FEAT_ARABIC
10777 to->wo_arab = from->wo_arab;
10778#endif
10779 to->wo_list = from->wo_list;
10780 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010781 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010782#ifdef FEAT_LINEBREAK
10783 to->wo_nuw = from->wo_nuw;
10784#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010785#ifdef FEAT_RIGHTLEFT
10786 to->wo_rl = from->wo_rl;
10787 to->wo_rlc = vim_strsave(from->wo_rlc);
10788#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010789#ifdef FEAT_STL_OPT
10790 to->wo_stl = vim_strsave(from->wo_stl);
10791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010792 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010793#ifdef FEAT_DIFF
10794 to->wo_wrap_save = from->wo_wrap_save;
10795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796#ifdef FEAT_LINEBREAK
10797 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010798 to->wo_bri = from->wo_bri;
10799 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010800#endif
10801#ifdef FEAT_SCROLLBIND
10802 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010803 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010804#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010805#ifdef FEAT_CURSORBIND
10806 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010807 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010808#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010809#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010810 to->wo_spell = from->wo_spell;
10811#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010812#ifdef FEAT_SYN_HL
10813 to->wo_cuc = from->wo_cuc;
10814 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010815 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817#ifdef FEAT_DIFF
10818 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010819 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010820#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010821#ifdef FEAT_CONCEAL
10822 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010823 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010824#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825#ifdef FEAT_FOLDING
10826 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010827 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010829 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010830 to->wo_fdi = vim_strsave(from->wo_fdi);
10831 to->wo_fml = from->wo_fml;
10832 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010833 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010834 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010835 to->wo_fdm_save = from->wo_diff_saved
10836 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837 to->wo_fdn = from->wo_fdn;
10838# ifdef FEAT_EVAL
10839 to->wo_fde = vim_strsave(from->wo_fde);
10840 to->wo_fdt = vim_strsave(from->wo_fdt);
10841# endif
10842 to->wo_fmr = vim_strsave(from->wo_fmr);
10843#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010844#ifdef FEAT_SIGNS
10845 to->wo_scl = vim_strsave(from->wo_scl);
10846#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010847 check_winopt(to); /* don't want NULL pointers */
10848}
10849
10850/*
10851 * Check string options in a window for a NULL value.
10852 */
10853 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010854check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855{
10856 check_winopt(&win->w_onebuf_opt);
10857 check_winopt(&win->w_allbuf_opt);
10858}
10859
10860/*
10861 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10862 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010863 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010864check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865{
10866#ifdef FEAT_FOLDING
10867 check_string_option(&wop->wo_fdi);
10868 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010869 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010870# ifdef FEAT_EVAL
10871 check_string_option(&wop->wo_fde);
10872 check_string_option(&wop->wo_fdt);
10873# endif
10874 check_string_option(&wop->wo_fmr);
10875#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010876#ifdef FEAT_SIGNS
10877 check_string_option(&wop->wo_scl);
10878#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879#ifdef FEAT_RIGHTLEFT
10880 check_string_option(&wop->wo_rlc);
10881#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010882#ifdef FEAT_STL_OPT
10883 check_string_option(&wop->wo_stl);
10884#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010885#ifdef FEAT_SYN_HL
10886 check_string_option(&wop->wo_cc);
10887#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010888#ifdef FEAT_CONCEAL
10889 check_string_option(&wop->wo_cocu);
10890#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010891#ifdef FEAT_LINEBREAK
10892 check_string_option(&wop->wo_briopt);
10893#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010894}
10895
10896/*
10897 * Free the allocated memory inside a winopt_T.
10898 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010899 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010900clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010901{
10902#ifdef FEAT_FOLDING
10903 clear_string_option(&wop->wo_fdi);
10904 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010905 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010906# ifdef FEAT_EVAL
10907 clear_string_option(&wop->wo_fde);
10908 clear_string_option(&wop->wo_fdt);
10909# endif
10910 clear_string_option(&wop->wo_fmr);
10911#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010912#ifdef FEAT_SIGNS
10913 clear_string_option(&wop->wo_scl);
10914#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010915#ifdef FEAT_LINEBREAK
10916 clear_string_option(&wop->wo_briopt);
10917#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918#ifdef FEAT_RIGHTLEFT
10919 clear_string_option(&wop->wo_rlc);
10920#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010921#ifdef FEAT_STL_OPT
10922 clear_string_option(&wop->wo_stl);
10923#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010924#ifdef FEAT_SYN_HL
10925 clear_string_option(&wop->wo_cc);
10926#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010927#ifdef FEAT_CONCEAL
10928 clear_string_option(&wop->wo_cocu);
10929#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010930}
10931
10932/*
10933 * Copy global option values to local options for one buffer.
10934 * Used when creating a new buffer and sometimes when entering a buffer.
10935 * flags:
10936 * BCO_ENTER We will enter the buf buffer.
10937 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10938 * appropriate.
10939 * BCO_NOHELP Don't copy the values to a help buffer.
10940 */
10941 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010942buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943{
10944 int should_copy = TRUE;
10945 char_u *save_p_isk = NULL; /* init for GCC */
10946 int dont_do_help;
10947 int did_isk = FALSE;
10948
10949 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010950 * Skip this when the option defaults have not been set yet. Happens when
10951 * main() allocates the first buffer.
10952 */
10953 if (p_cpo != NULL)
10954 {
10955 /*
10956 * Always copy when entering and 'cpo' contains 'S'.
10957 * Don't copy when already initialized.
10958 * Don't copy when 'cpo' contains 's' and not entering.
10959 * 'S' BCO_ENTER initialized 's' should_copy
10960 * yes yes X X TRUE
10961 * yes no yes X FALSE
10962 * no X yes X FALSE
10963 * X no no yes FALSE
10964 * X no no no TRUE
10965 * no yes no X TRUE
10966 */
10967 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10968 && (buf->b_p_initialized
10969 || (!(flags & BCO_ENTER)
10970 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10971 should_copy = FALSE;
10972
10973 if (should_copy || (flags & BCO_ALWAYS))
10974 {
10975 /* Don't copy the options specific to a help buffer when
10976 * BCO_NOHELP is given or the options were initialized already
10977 * (jumping back to a help file with CTRL-T or CTRL-O) */
10978 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10979 || buf->b_p_initialized;
10980 if (dont_do_help) /* don't free b_p_isk */
10981 {
10982 save_p_isk = buf->b_p_isk;
10983 buf->b_p_isk = NULL;
10984 }
10985 /*
10986 * Always free the allocated strings.
10987 * If not already initialized, set 'readonly' and copy 'fileformat'.
10988 */
10989 if (!buf->b_p_initialized)
10990 {
10991 free_buf_options(buf, TRUE);
10992 buf->b_p_ro = FALSE; /* don't copy readonly */
10993 buf->b_p_tx = p_tx;
10994#ifdef FEAT_MBYTE
10995 buf->b_p_fenc = vim_strsave(p_fenc);
10996#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020010997 switch (*p_ffs)
10998 {
10999 case 'm':
11000 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11001 case 'd':
11002 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11003 case 'u':
11004 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11005 default:
11006 buf->b_p_ff = vim_strsave(p_ff);
11007 }
11008 if (buf->b_p_ff != NULL)
11009 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010#if defined(FEAT_QUICKFIX)
11011 buf->b_p_bh = empty_option;
11012 buf->b_p_bt = empty_option;
11013#endif
11014 }
11015 else
11016 free_buf_options(buf, FALSE);
11017
11018 buf->b_p_ai = p_ai;
11019 buf->b_p_ai_nopaste = p_ai_nopaste;
11020 buf->b_p_sw = p_sw;
11021 buf->b_p_tw = p_tw;
11022 buf->b_p_tw_nopaste = p_tw_nopaste;
11023 buf->b_p_tw_nobin = p_tw_nobin;
11024 buf->b_p_wm = p_wm;
11025 buf->b_p_wm_nopaste = p_wm_nopaste;
11026 buf->b_p_wm_nobin = p_wm_nobin;
11027 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011028#ifdef FEAT_MBYTE
11029 buf->b_p_bomb = p_bomb;
11030#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020011031 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011032 buf->b_p_et = p_et;
11033 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011034 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035 buf->b_p_ml = p_ml;
11036 buf->b_p_ml_nobin = p_ml_nobin;
11037 buf->b_p_inf = p_inf;
11038 buf->b_p_swf = p_swf;
11039#ifdef FEAT_INS_EXPAND
11040 buf->b_p_cpt = vim_strsave(p_cpt);
11041#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011042#ifdef FEAT_COMPL_FUNC
11043 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011044 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011045#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011046 buf->b_p_sts = p_sts;
11047 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011048 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011049#ifdef FEAT_COMMENTS
11050 buf->b_p_com = vim_strsave(p_com);
11051#endif
11052#ifdef FEAT_FOLDING
11053 buf->b_p_cms = vim_strsave(p_cms);
11054#endif
11055 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011056 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011057 buf->b_p_nf = vim_strsave(p_nf);
11058 buf->b_p_mps = vim_strsave(p_mps);
11059#ifdef FEAT_SMARTINDENT
11060 buf->b_p_si = p_si;
11061#endif
11062 buf->b_p_ci = p_ci;
11063#ifdef FEAT_CINDENT
11064 buf->b_p_cin = p_cin;
11065 buf->b_p_cink = vim_strsave(p_cink);
11066 buf->b_p_cino = vim_strsave(p_cino);
11067#endif
11068#ifdef FEAT_AUTOCMD
11069 /* Don't copy 'filetype', it must be detected */
11070 buf->b_p_ft = empty_option;
11071#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072 buf->b_p_pi = p_pi;
11073#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11074 buf->b_p_cinw = vim_strsave(p_cinw);
11075#endif
11076#ifdef FEAT_LISP
11077 buf->b_p_lisp = p_lisp;
11078#endif
11079#ifdef FEAT_SYN_HL
11080 /* Don't copy 'syntax', it must be set */
11081 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011082 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011083 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011084#endif
11085#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011086 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011087 (void)compile_cap_prog(&buf->b_s);
11088 buf->b_s.b_p_spf = vim_strsave(p_spf);
11089 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011090#endif
11091#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11092 buf->b_p_inde = vim_strsave(p_inde);
11093 buf->b_p_indk = vim_strsave(p_indk);
11094#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011095 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011096#if defined(FEAT_EVAL)
11097 buf->b_p_fex = vim_strsave(p_fex);
11098#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099#ifdef FEAT_CRYPT
11100 buf->b_p_key = vim_strsave(p_key);
11101#endif
11102#ifdef FEAT_SEARCHPATH
11103 buf->b_p_sua = vim_strsave(p_sua);
11104#endif
11105#ifdef FEAT_KEYMAP
11106 buf->b_p_keymap = vim_strsave(p_keymap);
11107 buf->b_kmap_state |= KEYMAP_INIT;
11108#endif
11109 /* This isn't really an option, but copying the langmap and IME
11110 * state from the current buffer is better than resetting it. */
11111 buf->b_p_iminsert = p_iminsert;
11112 buf->b_p_imsearch = p_imsearch;
11113
11114 /* options that are normally global but also have a local value
11115 * are not copied, start using the global value */
11116 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011117 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011118 buf->b_p_bkc = empty_option;
11119 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011120#ifdef FEAT_QUICKFIX
11121 buf->b_p_gp = empty_option;
11122 buf->b_p_mp = empty_option;
11123 buf->b_p_efm = empty_option;
11124#endif
11125 buf->b_p_ep = empty_option;
11126 buf->b_p_kp = empty_option;
11127 buf->b_p_path = empty_option;
11128 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011129 buf->b_p_tc = empty_option;
11130 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011131#ifdef FEAT_FIND_ID
11132 buf->b_p_def = empty_option;
11133 buf->b_p_inc = empty_option;
11134# ifdef FEAT_EVAL
11135 buf->b_p_inex = vim_strsave(p_inex);
11136# endif
11137#endif
11138#ifdef FEAT_INS_EXPAND
11139 buf->b_p_dict = empty_option;
11140 buf->b_p_tsr = empty_option;
11141#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011142#ifdef FEAT_TEXTOBJ
11143 buf->b_p_qe = vim_strsave(p_qe);
11144#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011145#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11146 buf->b_p_bexpr = empty_option;
11147#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011148#if defined(FEAT_CRYPT)
11149 buf->b_p_cm = empty_option;
11150#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011151#ifdef FEAT_PERSISTENT_UNDO
11152 buf->b_p_udf = p_udf;
11153#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011154#ifdef FEAT_LISP
11155 buf->b_p_lw = empty_option;
11156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011157
11158 /*
11159 * Don't copy the options set by ex_help(), use the saved values,
11160 * when going from a help buffer to a non-help buffer.
11161 * Don't touch these at all when BCO_NOHELP is used and going from
11162 * or to a help buffer.
11163 */
11164 if (dont_do_help)
11165 buf->b_p_isk = save_p_isk;
11166 else
11167 {
11168 buf->b_p_isk = vim_strsave(p_isk);
11169 did_isk = TRUE;
11170 buf->b_p_ts = p_ts;
11171 buf->b_help = FALSE;
11172#ifdef FEAT_QUICKFIX
11173 if (buf->b_p_bt[0] == 'h')
11174 clear_string_option(&buf->b_p_bt);
11175#endif
11176 buf->b_p_ma = p_ma;
11177 }
11178 }
11179
11180 /*
11181 * When the options should be copied (ignoring BCO_ALWAYS), set the
11182 * flag that indicates that the options have been initialized.
11183 */
11184 if (should_copy)
11185 buf->b_p_initialized = TRUE;
11186 }
11187
11188 check_buf_options(buf); /* make sure we don't have NULLs */
11189 if (did_isk)
11190 (void)buf_init_chartab(buf, FALSE);
11191}
11192
11193/*
11194 * Reset the 'modifiable' option and its default value.
11195 */
11196 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011197reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011198{
11199 int opt_idx;
11200
11201 curbuf->b_p_ma = FALSE;
11202 p_ma = FALSE;
11203 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011204 if (opt_idx >= 0)
11205 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206}
11207
11208/*
11209 * Set the global value for 'iminsert' to the local value.
11210 */
11211 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011212set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011213{
11214 p_iminsert = curbuf->b_p_iminsert;
11215}
11216
11217/*
11218 * Set the global value for 'imsearch' to the local value.
11219 */
11220 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011221set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011222{
11223 p_imsearch = curbuf->b_p_imsearch;
11224}
11225
11226#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11227static int expand_option_idx = -1;
11228static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11229static int expand_option_flags = 0;
11230
11231 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011232set_context_in_set_cmd(
11233 expand_T *xp,
11234 char_u *arg,
11235 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236{
11237 int nextchar;
11238 long_u flags = 0; /* init for GCC */
11239 int opt_idx = 0; /* init for GCC */
11240 char_u *p;
11241 char_u *s;
11242 int is_term_option = FALSE;
11243 int key;
11244
11245 expand_option_flags = opt_flags;
11246
11247 xp->xp_context = EXPAND_SETTINGS;
11248 if (*arg == NUL)
11249 {
11250 xp->xp_pattern = arg;
11251 return;
11252 }
11253 p = arg + STRLEN(arg) - 1;
11254 if (*p == ' ' && *(p - 1) != '\\')
11255 {
11256 xp->xp_pattern = p + 1;
11257 return;
11258 }
11259 while (p > arg)
11260 {
11261 s = p;
11262 /* count number of backslashes before ' ' or ',' */
11263 if (*p == ' ' || *p == ',')
11264 {
11265 while (s > arg && *(s - 1) == '\\')
11266 --s;
11267 }
11268 /* break at a space with an even number of backslashes */
11269 if (*p == ' ' && ((p - s) & 1) == 0)
11270 {
11271 ++p;
11272 break;
11273 }
11274 --p;
11275 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011276 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011277 {
11278 xp->xp_context = EXPAND_BOOL_SETTINGS;
11279 p += 2;
11280 }
11281 if (STRNCMP(p, "inv", 3) == 0)
11282 {
11283 xp->xp_context = EXPAND_BOOL_SETTINGS;
11284 p += 3;
11285 }
11286 xp->xp_pattern = arg = p;
11287 if (*arg == '<')
11288 {
11289 while (*p != '>')
11290 if (*p++ == NUL) /* expand terminal option name */
11291 return;
11292 key = get_special_key_code(arg + 1);
11293 if (key == 0) /* unknown name */
11294 {
11295 xp->xp_context = EXPAND_NOTHING;
11296 return;
11297 }
11298 nextchar = *++p;
11299 is_term_option = TRUE;
11300 expand_option_name[2] = KEY2TERMCAP0(key);
11301 expand_option_name[3] = KEY2TERMCAP1(key);
11302 }
11303 else
11304 {
11305 if (p[0] == 't' && p[1] == '_')
11306 {
11307 p += 2;
11308 if (*p != NUL)
11309 ++p;
11310 if (*p == NUL)
11311 return; /* expand option name */
11312 nextchar = *++p;
11313 is_term_option = TRUE;
11314 expand_option_name[2] = p[-2];
11315 expand_option_name[3] = p[-1];
11316 }
11317 else
11318 {
11319 /* Allow * wildcard */
11320 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11321 p++;
11322 if (*p == NUL)
11323 return;
11324 nextchar = *p;
11325 *p = NUL;
11326 opt_idx = findoption(arg);
11327 *p = nextchar;
11328 if (opt_idx == -1 || options[opt_idx].var == NULL)
11329 {
11330 xp->xp_context = EXPAND_NOTHING;
11331 return;
11332 }
11333 flags = options[opt_idx].flags;
11334 if (flags & P_BOOL)
11335 {
11336 xp->xp_context = EXPAND_NOTHING;
11337 return;
11338 }
11339 }
11340 }
11341 /* handle "-=" and "+=" */
11342 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11343 {
11344 ++p;
11345 nextchar = '=';
11346 }
11347 if ((nextchar != '=' && nextchar != ':')
11348 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11349 {
11350 xp->xp_context = EXPAND_UNSUCCESSFUL;
11351 return;
11352 }
11353 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11354 {
11355 xp->xp_context = EXPAND_OLD_SETTING;
11356 if (is_term_option)
11357 expand_option_idx = -1;
11358 else
11359 expand_option_idx = opt_idx;
11360 xp->xp_pattern = p + 1;
11361 return;
11362 }
11363 xp->xp_context = EXPAND_NOTHING;
11364 if (is_term_option || (flags & P_NUM))
11365 return;
11366
11367 xp->xp_pattern = p + 1;
11368
11369 if (flags & P_EXPAND)
11370 {
11371 p = options[opt_idx].var;
11372 if (p == (char_u *)&p_bdir
11373 || p == (char_u *)&p_dir
11374 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011375 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376 || p == (char_u *)&p_rtp
11377#ifdef FEAT_SEARCHPATH
11378 || p == (char_u *)&p_cdpath
11379#endif
11380#ifdef FEAT_SESSION
11381 || p == (char_u *)&p_vdir
11382#endif
11383 )
11384 {
11385 xp->xp_context = EXPAND_DIRECTORIES;
11386 if (p == (char_u *)&p_path
11387#ifdef FEAT_SEARCHPATH
11388 || p == (char_u *)&p_cdpath
11389#endif
11390 )
11391 xp->xp_backslash = XP_BS_THREE;
11392 else
11393 xp->xp_backslash = XP_BS_ONE;
11394 }
11395 else
11396 {
11397 xp->xp_context = EXPAND_FILES;
11398 /* for 'tags' need three backslashes for a space */
11399 if (p == (char_u *)&p_tags)
11400 xp->xp_backslash = XP_BS_THREE;
11401 else
11402 xp->xp_backslash = XP_BS_ONE;
11403 }
11404 }
11405
11406 /* For an option that is a list of file names, find the start of the
11407 * last file name. */
11408 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11409 {
11410 /* count number of backslashes before ' ' or ',' */
11411 if (*p == ' ' || *p == ',')
11412 {
11413 s = p;
11414 while (s > xp->xp_pattern && *(s - 1) == '\\')
11415 --s;
11416 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11417 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11418 {
11419 xp->xp_pattern = p + 1;
11420 break;
11421 }
11422 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011423
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011424#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011425 /* for 'spellsuggest' start at "file:" */
11426 if (options[opt_idx].var == (char_u *)&p_sps
11427 && STRNCMP(p, "file:", 5) == 0)
11428 {
11429 xp->xp_pattern = p + 5;
11430 break;
11431 }
11432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011433 }
11434
11435 return;
11436}
11437
11438 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011439ExpandSettings(
11440 expand_T *xp,
11441 regmatch_T *regmatch,
11442 int *num_file,
11443 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011444{
11445 int num_normal = 0; /* Nr of matching non-term-code settings */
11446 int num_term = 0; /* Nr of matching terminal code settings */
11447 int opt_idx;
11448 int match;
11449 int count = 0;
11450 char_u *str;
11451 int loop;
11452 int is_term_opt;
11453 char_u name_buf[MAX_KEY_NAME_LEN];
11454 static char *(names[]) = {"all", "termcap"};
11455 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11456
11457 /* do this loop twice:
11458 * loop == 0: count the number of matching options
11459 * loop == 1: copy the matching options into allocated memory
11460 */
11461 for (loop = 0; loop <= 1; ++loop)
11462 {
11463 regmatch->rm_ic = ic;
11464 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11465 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011466 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11467 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011468 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11469 {
11470 if (loop == 0)
11471 num_normal++;
11472 else
11473 (*file)[count++] = vim_strsave((char_u *)names[match]);
11474 }
11475 }
11476 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11477 opt_idx++)
11478 {
11479 if (options[opt_idx].var == NULL)
11480 continue;
11481 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11482 && !(options[opt_idx].flags & P_BOOL))
11483 continue;
11484 is_term_opt = istermoption(&options[opt_idx]);
11485 if (is_term_opt && num_normal > 0)
11486 continue;
11487 match = FALSE;
11488 if (vim_regexec(regmatch, str, (colnr_T)0)
11489 || (options[opt_idx].shortname != NULL
11490 && vim_regexec(regmatch,
11491 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11492 match = TRUE;
11493 else if (is_term_opt)
11494 {
11495 name_buf[0] = '<';
11496 name_buf[1] = 't';
11497 name_buf[2] = '_';
11498 name_buf[3] = str[2];
11499 name_buf[4] = str[3];
11500 name_buf[5] = '>';
11501 name_buf[6] = NUL;
11502 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11503 {
11504 match = TRUE;
11505 str = name_buf;
11506 }
11507 }
11508 if (match)
11509 {
11510 if (loop == 0)
11511 {
11512 if (is_term_opt)
11513 num_term++;
11514 else
11515 num_normal++;
11516 }
11517 else
11518 (*file)[count++] = vim_strsave(str);
11519 }
11520 }
11521 /*
11522 * Check terminal key codes, these are not in the option table
11523 */
11524 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11525 {
11526 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11527 {
11528 if (!isprint(str[0]) || !isprint(str[1]))
11529 continue;
11530
11531 name_buf[0] = 't';
11532 name_buf[1] = '_';
11533 name_buf[2] = str[0];
11534 name_buf[3] = str[1];
11535 name_buf[4] = NUL;
11536
11537 match = FALSE;
11538 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11539 match = TRUE;
11540 else
11541 {
11542 name_buf[0] = '<';
11543 name_buf[1] = 't';
11544 name_buf[2] = '_';
11545 name_buf[3] = str[0];
11546 name_buf[4] = str[1];
11547 name_buf[5] = '>';
11548 name_buf[6] = NUL;
11549
11550 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11551 match = TRUE;
11552 }
11553 if (match)
11554 {
11555 if (loop == 0)
11556 num_term++;
11557 else
11558 (*file)[count++] = vim_strsave(name_buf);
11559 }
11560 }
11561
11562 /*
11563 * Check special key names.
11564 */
11565 regmatch->rm_ic = TRUE; /* ignore case here */
11566 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11567 {
11568 name_buf[0] = '<';
11569 STRCPY(name_buf + 1, str);
11570 STRCAT(name_buf, ">");
11571
11572 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11573 {
11574 if (loop == 0)
11575 num_term++;
11576 else
11577 (*file)[count++] = vim_strsave(name_buf);
11578 }
11579 }
11580 }
11581 if (loop == 0)
11582 {
11583 if (num_normal > 0)
11584 *num_file = num_normal;
11585 else if (num_term > 0)
11586 *num_file = num_term;
11587 else
11588 return OK;
11589 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11590 if (*file == NULL)
11591 {
11592 *file = (char_u **)"";
11593 return FAIL;
11594 }
11595 }
11596 }
11597 return OK;
11598}
11599
11600 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011601ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011602{
11603 char_u *var = NULL; /* init for GCC */
11604 char_u *buf;
11605
11606 *num_file = 0;
11607 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11608 if (*file == NULL)
11609 return FAIL;
11610
11611 /*
11612 * For a terminal key code expand_option_idx is < 0.
11613 */
11614 if (expand_option_idx < 0)
11615 {
11616 var = find_termcode(expand_option_name + 2);
11617 if (var == NULL)
11618 expand_option_idx = findoption(expand_option_name);
11619 }
11620
11621 if (expand_option_idx >= 0)
11622 {
11623 /* put string of option value in NameBuff */
11624 option_value2string(&options[expand_option_idx], expand_option_flags);
11625 var = NameBuff;
11626 }
11627 else if (var == NULL)
11628 var = (char_u *)"";
11629
11630 /* A backslash is required before some characters. This is the reverse of
11631 * what happens in do_set(). */
11632 buf = vim_strsave_escaped(var, escape_chars);
11633
11634 if (buf == NULL)
11635 {
11636 vim_free(*file);
11637 *file = NULL;
11638 return FAIL;
11639 }
11640
11641#ifdef BACKSLASH_IN_FILENAME
11642 /* For MS-Windows et al. we don't double backslashes at the start and
11643 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011644 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011645 if (var[0] == '\\' && var[1] == '\\'
11646 && expand_option_idx >= 0
11647 && (options[expand_option_idx].flags & P_EXPAND)
11648 && vim_isfilec(var[2])
11649 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011650 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011651#endif
11652
11653 *file[0] = buf;
11654 *num_file = 1;
11655 return OK;
11656}
11657#endif
11658
11659/*
11660 * Get the value for the numeric or string option *opp in a nice format into
11661 * NameBuff[]. Must not be called with a hidden option!
11662 */
11663 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011664option_value2string(
11665 struct vimoption *opp,
11666 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011667{
11668 char_u *varp;
11669
11670 varp = get_varp_scope(opp, opt_flags);
11671
11672 if (opp->flags & P_NUM)
11673 {
11674 long wc = 0;
11675
11676 if (wc_use_keyname(varp, &wc))
11677 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11678 else if (wc != 0)
11679 STRCPY(NameBuff, transchar((int)wc));
11680 else
11681 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11682 }
11683 else /* P_STRING */
11684 {
11685 varp = *(char_u **)(varp);
11686 if (varp == NULL) /* just in case */
11687 NameBuff[0] = NUL;
11688#ifdef FEAT_CRYPT
11689 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011690 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011691 STRCPY(NameBuff, "*****");
11692#endif
11693 else if (opp->flags & P_EXPAND)
11694 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11695 /* Translate 'pastetoggle' into special key names */
11696 else if ((char_u **)opp->var == &p_pt)
11697 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11698 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011699 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011700 }
11701}
11702
11703/*
11704 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11705 * printed as a keyname.
11706 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11707 */
11708 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011709wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011710{
11711 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11712 {
11713 *wcp = *(long *)varp;
11714 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11715 return TRUE;
11716 }
11717 return FALSE;
11718}
11719
Bram Moolenaar01615492015-02-03 13:00:38 +010011720#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011721/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011722 * Any character has an equivalent 'langmap' character. This is used for
11723 * keyboards that have a special language mode that sends characters above
11724 * 128 (although other characters can be translated too). The "to" field is a
11725 * Vim command character. This avoids having to switch the keyboard back to
11726 * ASCII mode when leaving Insert mode.
11727 *
11728 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11729 * commands.
11730 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11731 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11732 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011733 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011734# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011735/*
11736 * With multi-byte support use growarray for 'langmap' chars >= 256
11737 */
11738typedef struct
11739{
11740 int from;
11741 int to;
11742} langmap_entry_T;
11743
11744static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011745static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746
11747/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011748 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11749 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011750 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011751 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011752langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011753{
11754 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011755 int a = 0;
11756 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011757
11758 /* Do a binary search for an existing entry. */
11759 while (a != b)
11760 {
11761 int i = (a + b) / 2;
11762 int d = entries[i].from - from;
11763
11764 if (d == 0)
11765 {
11766 entries[i].to = to;
11767 return;
11768 }
11769 if (d < 0)
11770 a = i + 1;
11771 else
11772 b = i;
11773 }
11774
11775 if (ga_grow(&langmap_mapga, 1) != OK)
11776 return; /* out of memory */
11777
11778 /* insert new entry at position "a" */
11779 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11780 mch_memmove(entries + 1, entries,
11781 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11782 ++langmap_mapga.ga_len;
11783 entries[0].from = from;
11784 entries[0].to = to;
11785}
11786
11787/*
11788 * Apply 'langmap' to multi-byte character "c" and return the result.
11789 */
11790 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011791langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011792{
11793 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11794 int a = 0;
11795 int b = langmap_mapga.ga_len;
11796
11797 while (a != b)
11798 {
11799 int i = (a + b) / 2;
11800 int d = entries[i].from - c;
11801
11802 if (d == 0)
11803 return entries[i].to; /* found matching entry */
11804 if (d < 0)
11805 a = i + 1;
11806 else
11807 b = i;
11808 }
11809 return c; /* no entry found, return "c" unmodified */
11810}
11811# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011812
11813 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011814langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011815{
11816 int i;
11817
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011818 for (i = 0; i < 256; i++)
11819 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11820# ifdef FEAT_MBYTE
11821 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11822# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823}
11824
11825/*
11826 * Called when langmap option is set; the language map can be
11827 * changed at any time!
11828 */
11829 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011830langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011831{
11832 char_u *p;
11833 char_u *p2;
11834 int from, to;
11835
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011836#ifdef FEAT_MBYTE
11837 ga_clear(&langmap_mapga); /* clear the previous map first */
11838#endif
11839 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011840
11841 for (p = p_langmap; p[0] != NUL; )
11842 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011843 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11844 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845 {
11846 if (p2[0] == '\\' && p2[1] != NUL)
11847 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011848 }
11849 if (p2[0] == ';')
11850 ++p2; /* abcd;ABCD form, p2 points to A */
11851 else
11852 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11853 while (p[0])
11854 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011855 if (p[0] == ',')
11856 {
11857 ++p;
11858 break;
11859 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011860 if (p[0] == '\\' && p[1] != NUL)
11861 ++p;
11862#ifdef FEAT_MBYTE
11863 from = (*mb_ptr2char)(p);
11864#else
11865 from = p[0];
11866#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011867 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011868 if (p2 == NULL)
11869 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011870 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011871 if (p[0] != ',')
11872 {
11873 if (p[0] == '\\')
11874 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011875#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011876 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011878 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011879#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011880 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881 }
11882 else
11883 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011884 if (p2[0] != ',')
11885 {
11886 if (p2[0] == '\\')
11887 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011888#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011889 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011890#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011891 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011892#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011894 }
11895 if (to == NUL)
11896 {
11897 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11898 transchar(from));
11899 return;
11900 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011901
11902#ifdef FEAT_MBYTE
11903 if (from >= 256)
11904 langmap_set_entry(from, to);
11905 else
11906#endif
11907 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011908
11909 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011910 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011911 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011912 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011913 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011914 if (*p == ';')
11915 {
11916 p = p2;
11917 if (p[0] != NUL)
11918 {
11919 if (p[0] != ',')
11920 {
11921 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11922 return;
11923 }
11924 ++p;
11925 }
11926 break;
11927 }
11928 }
11929 }
11930 }
11931}
11932#endif
11933
11934/*
11935 * Return TRUE if format option 'x' is in effect.
11936 * Take care of no formatting when 'paste' is set.
11937 */
11938 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011939has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011940{
11941 if (p_paste)
11942 return FALSE;
11943 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11944}
11945
11946/*
11947 * Return TRUE if "x" is present in 'shortmess' option, or
11948 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11949 */
11950 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011951shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011952{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011953 return p_shm != NULL &&
11954 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 || (vim_strchr(p_shm, 'a') != NULL
11956 && vim_strchr((char_u *)SHM_A, x) != NULL));
11957}
11958
11959/*
11960 * paste_option_changed() - Called after p_paste was set or reset.
11961 */
11962 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011963paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011964{
11965 static int old_p_paste = FALSE;
11966 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011967 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011968#ifdef FEAT_CMDL_INFO
11969 static int save_ru = 0;
11970#endif
11971#ifdef FEAT_RIGHTLEFT
11972 static int save_ri = 0;
11973 static int save_hkmap = 0;
11974#endif
11975 buf_T *buf;
11976
11977 if (p_paste)
11978 {
11979 /*
11980 * Paste switched from off to on.
11981 * Save the current values, so they can be restored later.
11982 */
11983 if (!old_p_paste)
11984 {
11985 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011986 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011987 {
11988 buf->b_p_tw_nopaste = buf->b_p_tw;
11989 buf->b_p_wm_nopaste = buf->b_p_wm;
11990 buf->b_p_sts_nopaste = buf->b_p_sts;
11991 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011992 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993 }
11994
11995 /* save global options */
11996 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011997 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011998#ifdef FEAT_CMDL_INFO
11999 save_ru = p_ru;
12000#endif
12001#ifdef FEAT_RIGHTLEFT
12002 save_ri = p_ri;
12003 save_hkmap = p_hkmap;
12004#endif
12005 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012006 p_ai_nopaste = p_ai;
12007 p_et_nopaste = p_et;
12008 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012009 p_tw_nopaste = p_tw;
12010 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012011 }
12012
12013 /*
12014 * Always set the option values, also when 'paste' is set when it is
12015 * already on.
12016 */
12017 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012018 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012019 {
12020 buf->b_p_tw = 0; /* textwidth is 0 */
12021 buf->b_p_wm = 0; /* wrapmargin is 0 */
12022 buf->b_p_sts = 0; /* softtabstop is 0 */
12023 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012024 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025 }
12026
12027 /* set global options */
12028 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012029 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012030#ifdef FEAT_CMDL_INFO
12031# ifdef FEAT_WINDOWS
12032 if (p_ru)
12033 status_redraw_all(); /* redraw to remove the ruler */
12034# endif
12035 p_ru = 0; /* no ruler */
12036#endif
12037#ifdef FEAT_RIGHTLEFT
12038 p_ri = 0; /* no reverse insert */
12039 p_hkmap = 0; /* no Hebrew keyboard */
12040#endif
12041 /* set global values for local buffer options */
12042 p_tw = 0;
12043 p_wm = 0;
12044 p_sts = 0;
12045 p_ai = 0;
12046 }
12047
12048 /*
12049 * Paste switched from on to off: Restore saved values.
12050 */
12051 else if (old_p_paste)
12052 {
12053 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012054 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055 {
12056 buf->b_p_tw = buf->b_p_tw_nopaste;
12057 buf->b_p_wm = buf->b_p_wm_nopaste;
12058 buf->b_p_sts = buf->b_p_sts_nopaste;
12059 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012060 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061 }
12062
12063 /* restore global options */
12064 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012065 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012066#ifdef FEAT_CMDL_INFO
12067# ifdef FEAT_WINDOWS
12068 if (p_ru != save_ru)
12069 status_redraw_all(); /* redraw to draw the ruler */
12070# endif
12071 p_ru = save_ru;
12072#endif
12073#ifdef FEAT_RIGHTLEFT
12074 p_ri = save_ri;
12075 p_hkmap = save_hkmap;
12076#endif
12077 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012078 p_ai = p_ai_nopaste;
12079 p_et = p_et_nopaste;
12080 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012081 p_tw = p_tw_nopaste;
12082 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012083 }
12084
12085 old_p_paste = p_paste;
12086}
12087
12088/*
12089 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12090 *
12091 * Reset 'compatible' and set the values for options that didn't get set yet
12092 * to the Vim defaults.
12093 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012094 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 */
12096 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012097vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012098{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012099 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012100 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012101 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012102
12103 if (!option_was_set((char_u *)"cp"))
12104 {
12105 p_cp = FALSE;
12106 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12107 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12108 set_option_default(opt_idx, OPT_FREE, FALSE);
12109 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012110 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012111 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012112
12113 if (fname != NULL)
12114 {
12115 p = vim_getenv(envname, &dofree);
12116 if (p == NULL)
12117 {
12118 /* Set $MYVIMRC to the first vimrc file found. */
12119 p = FullName_save(fname, FALSE);
12120 if (p != NULL)
12121 {
12122 vim_setenv(envname, p);
12123 vim_free(p);
12124 }
12125 }
12126 else if (dofree)
12127 vim_free(p);
12128 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012129}
12130
12131/*
12132 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12133 */
12134 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012135change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012137 int opt_idx;
12138
Bram Moolenaar071d4272004-06-13 20:20:40 +000012139 if (p_cp != on)
12140 {
12141 p_cp = on;
12142 compatible_set();
12143 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012144 opt_idx = findoption((char_u *)"cp");
12145 if (opt_idx >= 0)
12146 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012147}
12148
12149/*
12150 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012151 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152 */
12153 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012154option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012155{
12156 int idx;
12157
12158 idx = findoption(name);
12159 if (idx < 0) /* unknown option */
12160 return FALSE;
12161 if (options[idx].flags & P_WAS_SET)
12162 return TRUE;
12163 return FALSE;
12164}
12165
12166/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012167 * Reset the flag indicating option "name" was set.
12168 */
12169 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012170reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012171{
12172 int idx = findoption(name);
12173
12174 if (idx >= 0)
12175 options[idx].flags &= ~P_WAS_SET;
12176}
12177
12178/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012179 * compatible_set() - Called when 'compatible' has been set or unset.
12180 *
12181 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12182 * flag) to a Vi compatible value.
12183 * When 'compatible' is unset: Set all options that have a different default
12184 * for Vim (without the P_VI_DEF flag) to that default.
12185 */
12186 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012187compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012188{
12189 int opt_idx;
12190
12191 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12192 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12193 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12194 set_option_default(opt_idx, OPT_FREE, p_cp);
12195 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012196 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012197}
12198
12199#ifdef FEAT_LINEBREAK
12200
12201# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12202 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012203 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012204# endif
12205
12206/*
12207 * fill_breakat_flags() -- called when 'breakat' changes value.
12208 */
12209 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012210fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012211{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012212 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012213 int i;
12214
12215 for (i = 0; i < 256; i++)
12216 breakat_flags[i] = FALSE;
12217
12218 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012219 for (p = p_breakat; *p; p++)
12220 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221}
12222
12223# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012224 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012225# endif
12226
12227#endif
12228
12229/*
12230 * Check an option that can be a range of string values.
12231 *
12232 * Return OK for correct value, FAIL otherwise.
12233 * Empty is always OK.
12234 */
12235 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012236check_opt_strings(
12237 char_u *val,
12238 char **values,
12239 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012240{
12241 return opt_strings_flags(val, values, NULL, list);
12242}
12243
12244/*
12245 * Handle an option that can be a range of string values.
12246 * Set a flag in "*flagp" for each string present.
12247 *
12248 * Return OK for correct value, FAIL otherwise.
12249 * Empty is always OK.
12250 */
12251 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012252opt_strings_flags(
12253 char_u *val, /* new value */
12254 char **values, /* array of valid string values */
12255 unsigned *flagp,
12256 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257{
12258 int i;
12259 int len;
12260 unsigned new_flags = 0;
12261
12262 while (*val)
12263 {
12264 for (i = 0; ; ++i)
12265 {
12266 if (values[i] == NULL) /* val not found in values[] */
12267 return FAIL;
12268
12269 len = (int)STRLEN(values[i]);
12270 if (STRNCMP(values[i], val, len) == 0
12271 && ((list && val[len] == ',') || val[len] == NUL))
12272 {
12273 val += len + (val[len] == ',');
12274 new_flags |= (1 << i);
12275 break; /* check next item in val list */
12276 }
12277 }
12278 }
12279 if (flagp != NULL)
12280 *flagp = new_flags;
12281
12282 return OK;
12283}
12284
12285/*
12286 * Read the 'wildmode' option, fill wim_flags[].
12287 */
12288 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012289check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012290{
12291 char_u new_wim_flags[4];
12292 char_u *p;
12293 int i;
12294 int idx = 0;
12295
12296 for (i = 0; i < 4; ++i)
12297 new_wim_flags[i] = 0;
12298
12299 for (p = p_wim; *p; ++p)
12300 {
12301 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12302 ;
12303 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12304 return FAIL;
12305 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12306 new_wim_flags[idx] |= WIM_LONGEST;
12307 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12308 new_wim_flags[idx] |= WIM_FULL;
12309 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12310 new_wim_flags[idx] |= WIM_LIST;
12311 else
12312 return FAIL;
12313 p += i;
12314 if (*p == NUL)
12315 break;
12316 if (*p == ',')
12317 {
12318 if (idx == 3)
12319 return FAIL;
12320 ++idx;
12321 }
12322 }
12323
12324 /* fill remaining entries with last flag */
12325 while (idx < 3)
12326 {
12327 new_wim_flags[idx + 1] = new_wim_flags[idx];
12328 ++idx;
12329 }
12330
12331 /* only when there are no errors, wim_flags[] is changed */
12332 for (i = 0; i < 4; ++i)
12333 wim_flags[i] = new_wim_flags[i];
12334 return OK;
12335}
12336
12337/*
12338 * Check if backspacing over something is allowed.
12339 */
12340 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012341can_bs(
12342 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012343{
12344 switch (*p_bs)
12345 {
12346 case '2': return TRUE;
12347 case '1': return (what != BS_START);
12348 case '0': return FALSE;
12349 }
12350 return vim_strchr(p_bs, what) != NULL;
12351}
12352
12353/*
12354 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12355 * the file must be considered changed when the value is different.
12356 */
12357 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012358save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012359{
12360 buf->b_start_ffc = *buf->b_p_ff;
12361 buf->b_start_eol = buf->b_p_eol;
12362#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012363 buf->b_start_bomb = buf->b_p_bomb;
12364
Bram Moolenaar071d4272004-06-13 20:20:40 +000012365 /* Only use free/alloc when necessary, they take time. */
12366 if (buf->b_start_fenc == NULL
12367 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12368 {
12369 vim_free(buf->b_start_fenc);
12370 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12371 }
12372#endif
12373}
12374
12375/*
12376 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12377 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012378 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12379 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012380 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012381 * When "ignore_empty" is true don't consider a new, empty buffer to be
12382 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012383 */
12384 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012385file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012386{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012387 /* In a buffer that was never loaded the options are not valid. */
12388 if (buf->b_flags & BF_NEVERLOADED)
12389 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012390 if (ignore_empty
12391 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012392 && buf->b_ml.ml_line_count == 1
12393 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12394 return FALSE;
12395 if (buf->b_start_ffc != *buf->b_p_ff)
12396 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012397 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012398 return TRUE;
12399#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012400 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12401 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012402 if (buf->b_start_fenc == NULL)
12403 return (*buf->b_p_fenc != NUL);
12404 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12405#else
12406 return FALSE;
12407#endif
12408}
12409
12410/*
12411 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12412 */
12413 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012414check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012415{
12416 return check_opt_strings(p, p_ff_values, FALSE);
12417}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012418
12419/*
12420 * Return the effective shiftwidth value for current buffer, using the
12421 * 'tabstop' value when 'shiftwidth' is zero.
12422 */
12423 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012424get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012425{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012426 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012427}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012428
12429/*
12430 * Return the effective softtabstop value for the current buffer, using the
12431 * 'tabstop' value when 'softtabstop' is negative.
12432 */
12433 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012434get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012435{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012436 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012437}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012438
12439/*
12440 * Check matchpairs option for "*initc".
12441 * If there is a match set "*initc" to the matching character and "*findc" to
12442 * the opposite character. Set "*backwards" to the direction.
12443 * When "switchit" is TRUE swap the direction.
12444 */
12445 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012446find_mps_values(
12447 int *initc,
12448 int *findc,
12449 int *backwards,
12450 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012451{
12452 char_u *ptr;
12453
12454 ptr = curbuf->b_p_mps;
12455 while (*ptr != NUL)
12456 {
12457#ifdef FEAT_MBYTE
12458 if (has_mbyte)
12459 {
12460 char_u *prev;
12461
12462 if (mb_ptr2char(ptr) == *initc)
12463 {
12464 if (switchit)
12465 {
12466 *findc = *initc;
12467 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12468 *backwards = TRUE;
12469 }
12470 else
12471 {
12472 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12473 *backwards = FALSE;
12474 }
12475 return;
12476 }
12477 prev = ptr;
12478 ptr += mb_ptr2len(ptr) + 1;
12479 if (mb_ptr2char(ptr) == *initc)
12480 {
12481 if (switchit)
12482 {
12483 *findc = *initc;
12484 *initc = mb_ptr2char(prev);
12485 *backwards = FALSE;
12486 }
12487 else
12488 {
12489 *findc = mb_ptr2char(prev);
12490 *backwards = TRUE;
12491 }
12492 return;
12493 }
12494 ptr += mb_ptr2len(ptr);
12495 }
12496 else
12497#endif
12498 {
12499 if (*ptr == *initc)
12500 {
12501 if (switchit)
12502 {
12503 *backwards = TRUE;
12504 *findc = *initc;
12505 *initc = ptr[2];
12506 }
12507 else
12508 {
12509 *backwards = FALSE;
12510 *findc = ptr[2];
12511 }
12512 return;
12513 }
12514 ptr += 2;
12515 if (*ptr == *initc)
12516 {
12517 if (switchit)
12518 {
12519 *backwards = FALSE;
12520 *findc = *initc;
12521 *initc = ptr[-2];
12522 }
12523 else
12524 {
12525 *backwards = TRUE;
12526 *findc = ptr[-2];
12527 }
12528 return;
12529 }
12530 ++ptr;
12531 }
12532 if (*ptr == ',')
12533 ++ptr;
12534 }
12535}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012536
12537#if defined(FEAT_LINEBREAK) || defined(PROTO)
12538/*
12539 * This is called when 'breakindentopt' is changed and when a window is
12540 * initialized.
12541 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012542 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012543briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012544{
12545 char_u *p;
12546 int bri_shift = 0;
12547 long bri_min = 20;
12548 int bri_sbr = FALSE;
12549
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012550 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012551 while (*p != NUL)
12552 {
12553 if (STRNCMP(p, "shift:", 6) == 0
12554 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12555 {
12556 p += 6;
12557 bri_shift = getdigits(&p);
12558 }
12559 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12560 {
12561 p += 4;
12562 bri_min = getdigits(&p);
12563 }
12564 else if (STRNCMP(p, "sbr", 3) == 0)
12565 {
12566 p += 3;
12567 bri_sbr = TRUE;
12568 }
12569 if (*p != ',' && *p != NUL)
12570 return FAIL;
12571 if (*p == ',')
12572 ++p;
12573 }
12574
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012575 wp->w_p_brishift = bri_shift;
12576 wp->w_p_brimin = bri_min;
12577 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012578
12579 return OK;
12580}
12581#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012582
12583/*
12584 * Get the local or global value of 'backupcopy'.
12585 */
12586 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012587get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012588{
12589 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12590}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012591
12592#if defined(FEAT_SIGNS) || defined(PROTO)
12593/*
12594 * Return TRUE when window "wp" has a column to draw signs in.
12595 */
12596 int
12597signcolumn_on(win_T *wp)
12598{
12599 if (*wp->w_p_scl == 'n')
12600 return FALSE;
12601 if (*wp->w_p_scl == 'y')
12602 return TRUE;
12603 return (wp->w_buffer->b_signlist != NULL
12604# ifdef FEAT_NETBEANS_INTG
12605 || wp->w_buffer->b_has_sign_column
12606# endif
12607 );
12608}
12609#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012610
12611#if defined(FEAT_EVAL) || defined(PROTO)
12612/*
12613 * Get window or buffer local options.
12614 */
12615 dict_T *
12616get_winbuf_options(int bufopt)
12617{
12618 dict_T *d;
12619 int opt_idx;
12620
12621 d = dict_alloc();
12622 if (d == NULL)
12623 return NULL;
12624
12625 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12626 {
12627 struct vimoption *opt = &options[opt_idx];
12628
12629 if ((bufopt && (opt->indir & PV_BUF))
12630 || (!bufopt && (opt->indir & PV_WIN)))
12631 {
12632 char_u *varp = get_varp(opt);
12633
12634 if (varp != NULL)
12635 {
12636 if (opt->flags & P_STRING)
12637 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012638 else if (opt->flags & P_NUM)
12639 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012640 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012641 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012642 }
12643 }
12644 }
12645
12646 return d;
12647}
12648#endif