blob: 32e97c99ba6e9acd98ae2e6d5e19b15dc8612548 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000060#ifdef FEAT_QUICKFIX
Bram Moolenaara23ccb82006-02-27 00:08:02 +000061# define PV_BH OPT_BUF(BV_BH)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062# define PV_BT OPT_BUF(BV_BT)
63# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000069#ifdef FEAT_MBYTE
70# define PV_BOMB OPT_BUF(BV_BOMB)
71#endif
72#define PV_CI OPT_BUF(BV_CI)
73#ifdef FEAT_CINDENT
74# define PV_CIN OPT_BUF(BV_CIN)
75# define PV_CINK OPT_BUF(BV_CINK)
76# define PV_CINO OPT_BUF(BV_CINO)
77#endif
78#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
79# define PV_CINW OPT_BUF(BV_CINW)
80#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020081#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000082#ifdef FEAT_FOLDING
83# define PV_CMS OPT_BUF(BV_CMS)
84#endif
85#ifdef FEAT_COMMENTS
86# define PV_COM OPT_BUF(BV_COM)
87#endif
88#ifdef FEAT_INS_EXPAND
89# define PV_CPT OPT_BUF(BV_CPT)
90# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
91# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
92#endif
93#ifdef FEAT_COMPL_FUNC
94# define PV_CFU OPT_BUF(BV_CFU)
95#endif
96#ifdef FEAT_FIND_ID
97# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
98# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
99#endif
100#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200101#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000102#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
103#define PV_ET OPT_BUF(BV_ET)
104#ifdef FEAT_MBYTE
105# define PV_FENC OPT_BUF(BV_FENC)
106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
108# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
109#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100110#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000111#ifdef FEAT_EVAL
112# define PV_FEX OPT_BUF(BV_FEX)
113#endif
114#define PV_FF OPT_BUF(BV_FF)
115#define PV_FLP OPT_BUF(BV_FLP)
116#define PV_FO OPT_BUF(BV_FO)
117#ifdef FEAT_AUTOCMD
118# define PV_FT OPT_BUF(BV_FT)
119#endif
120#define PV_IMI OPT_BUF(BV_IMI)
121#define PV_IMS OPT_BUF(BV_IMS)
122#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
123# define PV_INDE OPT_BUF(BV_INDE)
124# define PV_INDK OPT_BUF(BV_INDK)
125#endif
126#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
127# define PV_INEX OPT_BUF(BV_INEX)
128#endif
129#define PV_INF OPT_BUF(BV_INF)
130#define PV_ISK OPT_BUF(BV_ISK)
131#ifdef FEAT_CRYPT
132# define PV_KEY OPT_BUF(BV_KEY)
133#endif
134#ifdef FEAT_KEYMAP
135# define PV_KMAP OPT_BUF(BV_KMAP)
136#endif
137#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
138#ifdef FEAT_LISP
139# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100140# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#endif
142#define PV_MA OPT_BUF(BV_MA)
143#define PV_ML OPT_BUF(BV_ML)
144#define PV_MOD OPT_BUF(BV_MOD)
145#define PV_MPS OPT_BUF(BV_MPS)
146#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000147#ifdef FEAT_COMPL_FUNC
148# define PV_OFU OPT_BUF(BV_OFU)
149#endif
150#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
151#define PV_PI OPT_BUF(BV_PI)
152#ifdef FEAT_TEXTOBJ
153# define PV_QE OPT_BUF(BV_QE)
154#endif
155#define PV_RO OPT_BUF(BV_RO)
156#ifdef FEAT_SMARTINDENT
157# define PV_SI OPT_BUF(BV_SI)
158#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100159#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000160#ifdef FEAT_SYN_HL
161# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000162# define PV_SYN OPT_BUF(BV_SYN)
163#endif
164#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000165# define PV_SPC OPT_BUF(BV_SPC)
166# define PV_SPF OPT_BUF(BV_SPF)
167# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000168#endif
169#define PV_STS OPT_BUF(BV_STS)
170#ifdef FEAT_SEARCHPATH
171# define PV_SUA OPT_BUF(BV_SUA)
172#endif
173#define PV_SW OPT_BUF(BV_SW)
174#define PV_SWF OPT_BUF(BV_SWF)
175#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100176#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000177#define PV_TS OPT_BUF(BV_TS)
178#define PV_TW OPT_BUF(BV_TW)
179#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200180#ifdef FEAT_PERSISTENT_UNDO
181# define PV_UDF OPT_BUF(BV_UDF)
182#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000183#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000184
185/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000186 * Definition of the PV_ values for window-local options.
187 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189#define PV_LIST OPT_WIN(WV_LIST)
190#ifdef FEAT_ARABIC
191# define PV_ARAB OPT_WIN(WV_ARAB)
192#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200193#ifdef FEAT_LINEBREAK
194# define PV_BRI OPT_WIN(WV_BRI)
195# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
196#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000197#ifdef FEAT_DIFF
198# define PV_DIFF OPT_WIN(WV_DIFF)
199#endif
200#ifdef FEAT_FOLDING
201# define PV_FDC OPT_WIN(WV_FDC)
202# define PV_FEN OPT_WIN(WV_FEN)
203# define PV_FDI OPT_WIN(WV_FDI)
204# define PV_FDL OPT_WIN(WV_FDL)
205# define PV_FDM OPT_WIN(WV_FDM)
206# define PV_FML OPT_WIN(WV_FML)
207# define PV_FDN OPT_WIN(WV_FDN)
208# ifdef FEAT_EVAL
209# define PV_FDE OPT_WIN(WV_FDE)
210# define PV_FDT OPT_WIN(WV_FDT)
211# endif
212# define PV_FMR OPT_WIN(WV_FMR)
213#endif
214#ifdef FEAT_LINEBREAK
215# define PV_LBR OPT_WIN(WV_LBR)
216#endif
217#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200218#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000219#ifdef FEAT_LINEBREAK
220# define PV_NUW OPT_WIN(WV_NUW)
221#endif
222#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
223# define PV_PVW OPT_WIN(WV_PVW)
224#endif
225#ifdef FEAT_RIGHTLEFT
226# define PV_RL OPT_WIN(WV_RL)
227# define PV_RLC OPT_WIN(WV_RLC)
228#endif
229#ifdef FEAT_SCROLLBIND
230# define PV_SCBIND OPT_WIN(WV_SCBIND)
231#endif
232#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000233#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000234# define PV_SPELL OPT_WIN(WV_SPELL)
235#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SYN_HL
237# define PV_CUC OPT_WIN(WV_CUC)
238# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200239# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000240#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000241#ifdef FEAT_STL_OPT
242# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
243#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100244#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000245#ifdef FEAT_WINDOWS
246# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000247# define PV_WFW OPT_WIN(WV_WFW)
248#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000249#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200250#ifdef FEAT_CURSORBIND
251# define PV_CRBIND OPT_WIN(WV_CRBIND)
252#endif
253#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200254# define PV_COCU OPT_WIN(WV_COCU)
255# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200256#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200257#ifdef FEAT_SIGNS
258# define PV_SCL OPT_WIN(WV_SCL)
259#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000260
261/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000262typedef enum
263{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000264 PV_NONE = 0,
265 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266} idopt_T;
267
268/*
269 * Options local to a window have a value local to a buffer and global to all
270 * buffers. Indicate this by setting "var" to VAR_WIN.
271 */
272#define VAR_WIN ((char_u *)-1)
273
274/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000275 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000276 * Only to be used in option.c!
277 */
278static int p_ai;
279static int p_bin;
280#ifdef FEAT_MBYTE
281static int p_bomb;
282#endif
283#if defined(FEAT_QUICKFIX)
284static char_u *p_bh;
285static char_u *p_bt;
286#endif
287static int p_bl;
288static int p_ci;
289#ifdef FEAT_CINDENT
290static int p_cin;
291static char_u *p_cink;
292static char_u *p_cino;
293#endif
294#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
295static char_u *p_cinw;
296#endif
297#ifdef FEAT_COMMENTS
298static char_u *p_com;
299#endif
300#ifdef FEAT_FOLDING
301static char_u *p_cms;
302#endif
303#ifdef FEAT_INS_EXPAND
304static char_u *p_cpt;
305#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#ifdef FEAT_COMPL_FUNC
307static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000308static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200311static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static int p_et;
313#ifdef FEAT_MBYTE
314static char_u *p_fenc;
315#endif
316static char_u *p_ff;
317static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000318static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319#ifdef FEAT_AUTOCMD
320static char_u *p_ft;
321#endif
322static long p_iminsert;
323static long p_imsearch;
324#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
325static char_u *p_inex;
326#endif
327#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
328static char_u *p_inde;
329static char_u *p_indk;
330#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000331#if defined(FEAT_EVAL)
332static char_u *p_fex;
333#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334static int p_inf;
335static char_u *p_isk;
336#ifdef FEAT_CRYPT
337static char_u *p_key;
338#endif
339#ifdef FEAT_LISP
340static int p_lisp;
341#endif
342static int p_ml;
343static int p_ma;
344static int p_mod;
345static char_u *p_mps;
346static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000348#ifdef FEAT_TEXTOBJ
349static char_u *p_qe;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_ro;
352#ifdef FEAT_SMARTINDENT
353static int p_si;
354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000356static long p_sts;
357#if defined(FEAT_SEARCHPATH)
358static char_u *p_sua;
359#endif
360static long p_sw;
361static int p_swf;
362#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000363static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000364static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000365#endif
366#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000367static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000368static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000369static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000370#endif
371static long p_ts;
372static long p_tw;
373static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200374#ifdef FEAT_PERSISTENT_UNDO
375static int p_udf;
376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000377static long p_wm;
378#ifdef FEAT_KEYMAP
379static char_u *p_keymap;
380#endif
381
382/* Saved values for when 'bin' is set. */
383static int p_et_nobin;
384static int p_ml_nobin;
385static long p_tw_nobin;
386static long p_wm_nobin;
387
388/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200389static int p_ai_nopaste;
390static int p_et_nopaste;
391static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000392static long p_tw_nopaste;
393static long p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394
395struct vimoption
396{
397 char *fullname; /* full option name */
398 char *shortname; /* permissible abbreviation */
399 long_u flags; /* see below */
400 char_u *var; /* global option: pointer to variable;
401 * window-local option: VAR_WIN;
402 * buffer-local option: global value */
403 idopt_T indir; /* global option: PV_NONE;
404 * local option: indirect option index */
405 char_u *def_val[2]; /* default values for variable (vi and vim) */
406#ifdef FEAT_EVAL
407 scid_T scriptID; /* script in which the option was last set */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000408# define SCRIPTID_INIT , 0
409#else
410# define SCRIPTID_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411#endif
412};
413
414#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
415#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
416
417/*
418 * Flags
419 */
420#define P_BOOL 0x01 /* the option is boolean */
421#define P_NUM 0x02 /* the option is numeric */
422#define P_STRING 0x04 /* the option is a string */
423#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000424 must use free_string_option() when
425 assigning new value. Not set if default is
426 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000427#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
428 never be used for local or hidden options! */
429#define P_NODEFAULT 0x40 /* don't set to default value */
430#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
431 use vim_free() when assigning new value */
432#define P_WAS_SET 0x100 /* option has been set/reset */
433#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
434#define P_VI_DEF 0x400 /* Use Vi default for Vim */
435#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
436
437 /* when option changed, what to display: */
438#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100439#define P_RWIN 0x2000 /* redraw current window and recompute text */
440#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000441#define P_RALL 0x6000 /* redraw all windows */
442#define P_RCLR 0x7000 /* clear and redraw all */
443
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200444#define P_COMMA 0x8000 /* comma separated list */
445#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
446 * commas */
447#define P_NODUP 0x20000L /* don't allow duplicate strings */
448#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200450#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
451#define P_GETTEXT 0x100000L /* expand default value with _() */
452#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
453#define P_NFNAME 0x400000L /* only normal file name chars allowed */
454#define P_INSECURE 0x800000L /* option was set from a modeline */
455#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100456 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200457#define P_NO_ML 0x2000000L /* not allowed in modeline */
458#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200459 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100460#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100461#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000462
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000463#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
464
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000465/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
466 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100467#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000468# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000469#else
470# define ISP_LATIN1 (char_u *)"@,161-255"
471#endif
472
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100473/* Make the string as short as possible when compiling with few features. */
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000474#if defined(FEAT_DIFF) || defined(FEAT_FOLDING) || defined(FEAT_SPELL) \
Bram Moolenaar44a2f922016-03-19 22:11:51 +0100475 || defined(FEAT_WINDOWS) || defined(FEAT_CLIPBOARD) \
Bram Moolenaar860cae12010-06-05 23:22:07 +0200476 || defined(FEAT_INS_EXPAND) || defined(FEAT_SYN_HL) || defined(FEAT_CONCEAL)
Bram Moolenaar58b85342016-08-14 19:54:54 +0200477# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000478#else
Bram Moolenaar06ca5132012-03-23 16:25:17 +0100479# define HIGHLIGHT_INIT "8:SpecialKey,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,t:Title,v:Visual,w:WarningMsg,W:WildMenu,>:SignColumn,*:TabLine,#:TabLineSel,_:TabLineFill"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000480#endif
481
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100482/* Default python version for pyx* commands */
483#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
484# define DEFAULT_PYTHON_VER 0
485#elif defined(FEAT_PYTHON3)
486# define DEFAULT_PYTHON_VER 3
487#elif defined(FEAT_PYTHON)
488# define DEFAULT_PYTHON_VER 2
489#else
490# define DEFAULT_PYTHON_VER 0
491#endif
492
Bram Moolenaar071d4272004-06-13 20:20:40 +0000493/*
494 * options[] is initialized here.
495 * The order of the options MUST be alphabetic for ":set all" and findoption().
496 * All option names MUST start with a lowercase letter (for findoption()).
497 * Exception: "t_" options are at the end.
498 * The options with a NULL variable are 'hidden': a set command for them is
499 * ignored and they are not printed.
500 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100501static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000502{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200503 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504#ifdef FEAT_RIGHTLEFT
505 (char_u *)&p_aleph, PV_NONE,
506#else
507 (char_u *)NULL, PV_NONE,
508#endif
509 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100510#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511 (char_u *)128L,
512#else
513 (char_u *)224L,
514#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000515 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
517#if defined(FEAT_GUI) && defined(MACOS_X)
518 (char_u *)&p_antialias, PV_NONE,
519 {(char_u *)FALSE, (char_u *)FALSE}
520#else
521 (char_u *)NULL, PV_NONE,
522 {(char_u *)FALSE, (char_u *)FALSE}
523#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000524 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200525 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526#ifdef FEAT_ARABIC
527 (char_u *)VAR_WIN, PV_ARAB,
528#else
529 (char_u *)NULL, PV_NONE,
530#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000531 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
533#ifdef FEAT_ARABIC
534 (char_u *)&p_arshape, PV_NONE,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000538 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
540#ifdef FEAT_RIGHTLEFT
541 (char_u *)&p_ari, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000545 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
547#ifdef FEAT_FKMAP
548 (char_u *)&p_altkeymap, PV_NONE,
549#else
550 (char_u *)NULL, PV_NONE,
551#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000552 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
554#if defined(FEAT_MBYTE)
555 (char_u *)&p_ambw, PV_NONE,
556 {(char_u *)"single", (char_u *)0L}
557#else
558 (char_u *)NULL, PV_NONE,
559 {(char_u *)0L, (char_u *)0L}
560#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000561 SCRIPTID_INIT},
Bram Moolenaar8dff8182006-04-06 20:18:50 +0000562#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563 {"autochdir", "acd", P_BOOL|P_VI_DEF,
564 (char_u *)&p_acd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000565 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566#endif
567 {"autoindent", "ai", P_BOOL|P_VI_DEF,
568 (char_u *)&p_ai, PV_AI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000569 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autoprint", "ap", P_BOOL|P_VI_DEF,
571 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000572 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000574 (char_u *)&p_ar, PV_AR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000575 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"autowrite", "aw", P_BOOL|P_VI_DEF,
577 (char_u *)&p_aw, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000578 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"autowriteall","awa", P_BOOL|P_VI_DEF,
580 (char_u *)&p_awa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000581 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
583 (char_u *)&p_bg, PV_NONE,
584 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100585#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)"dark",
587#else
588 (char_u *)"light",
589#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000590 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000593 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
595 (char_u *)&p_bk, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000596 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200598 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599#ifdef UNIX
600 {(char_u *)"yes", (char_u *)"auto"}
601#else
602 {(char_u *)"auto", (char_u *)"auto"}
603#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000604 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200605 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
606 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000608 {(char_u *)DFLT_BDIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000609 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610 (char_u *)&p_bex, PV_NONE,
611 {
612#ifdef VMS
613 (char_u *)"_",
614#else
615 (char_u *)"~",
616#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000617 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200618 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_WILDIGN
620 (char_u *)&p_bsk, PV_NONE,
621 {(char_u *)"", (char_u *)0L}
622#else
623 (char_u *)NULL, PV_NONE,
624 {(char_u *)0L, (char_u *)0L}
625#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000626 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627#ifdef FEAT_BEVAL
628 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
629 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000630 {(char_u *)600L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
632 (char_u *)&p_beval, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000633 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000634# ifdef FEAT_EVAL
Bram Moolenaar39f05632006-03-19 22:15:26 +0000635 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000636 (char_u *)&p_bexpr, PV_BEXPR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000637 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +0000638# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000639#endif
640 {"beautify", "bf", P_BOOL|P_VI_DEF,
641 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000642 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200643 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
644 (char_u *)&p_bo, PV_NONE,
645 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
647 (char_u *)&p_bin, PV_BIN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000648 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000649 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000650 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000651 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000652 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
653#ifdef FEAT_MBYTE
654 (char_u *)&p_bomb, PV_BOMB,
655#else
656 (char_u *)NULL, PV_NONE,
657#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000658 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000659 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
660#ifdef FEAT_LINEBREAK
661 (char_u *)&p_breakat, PV_NONE,
662 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
663#else
664 (char_u *)NULL, PV_NONE,
665 {(char_u *)0L, (char_u *)0L}
666#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000667 SCRIPTID_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200668 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
669#ifdef FEAT_LINEBREAK
670 (char_u *)VAR_WIN, PV_BRI,
671 {(char_u *)FALSE, (char_u *)0L}
672#else
673 (char_u *)NULL, PV_NONE,
674 {(char_u *)0L, (char_u *)0L}
675#endif
676 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200677 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
678 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200679#ifdef FEAT_LINEBREAK
680 (char_u *)VAR_WIN, PV_BRIOPT,
681 {(char_u *)"", (char_u *)NULL}
682#else
683 (char_u *)NULL, PV_NONE,
684 {(char_u *)"", (char_u *)NULL}
685#endif
686 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000687 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
688#ifdef FEAT_BROWSE
689 (char_u *)&p_bsdir, PV_NONE,
690 {(char_u *)"last", (char_u *)0L}
691#else
692 (char_u *)NULL, PV_NONE,
693 {(char_u *)0L, (char_u *)0L}
694#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000695 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000696 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
697#if defined(FEAT_QUICKFIX)
698 (char_u *)&p_bh, PV_BH,
699 {(char_u *)"", (char_u *)0L}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)0L, (char_u *)0L}
703#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000704 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
706 (char_u *)&p_bl, PV_BL,
707 {(char_u *)1L, (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000708 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
710#if defined(FEAT_QUICKFIX)
711 (char_u *)&p_bt, PV_BT,
712 {(char_u *)"", (char_u *)0L}
713#else
714 (char_u *)NULL, PV_NONE,
715 {(char_u *)0L, (char_u *)0L}
716#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000717 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200718 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000719#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 (char_u *)&p_cmp, PV_NONE,
721 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarfa1d1402006-03-25 21:59:56 +0000722#else
723 (char_u *)NULL, PV_NONE,
724 {(char_u *)0L, (char_u *)0L}
725#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000726 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
728#ifdef FEAT_SEARCHPATH
729 (char_u *)&p_cdpath, PV_NONE,
730 {(char_u *)",,", (char_u *)0L}
731#else
732 (char_u *)NULL, PV_NONE,
733 {(char_u *)0L, (char_u *)0L}
734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000736 {"cedit", NULL, P_STRING,
737#ifdef FEAT_CMDWIN
738 (char_u *)&p_cedit, PV_NONE,
739 {(char_u *)"", (char_u *)CTRL_F_STR}
740#else
741 (char_u *)NULL, PV_NONE,
742 {(char_u *)0L, (char_u *)0L}
743#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000744 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000745 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
746#if defined(FEAT_MBYTE) && defined(FEAT_EVAL)
747 (char_u *)&p_ccv, PV_NONE,
748 {(char_u *)"", (char_u *)0L}
749#else
750 (char_u *)NULL, PV_NONE,
751 {(char_u *)0L, (char_u *)0L}
752#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000753 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000754 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
755#ifdef FEAT_CINDENT
756 (char_u *)&p_cin, PV_CIN,
757#else
758 (char_u *)NULL, PV_NONE,
759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000760 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200761 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000762#ifdef FEAT_CINDENT
763 (char_u *)&p_cink, PV_CINK,
764 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
765#else
766 (char_u *)NULL, PV_NONE,
767 {(char_u *)0L, (char_u *)0L}
768#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000769 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200770 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771#ifdef FEAT_CINDENT
772 (char_u *)&p_cino, PV_CINO,
773#else
774 (char_u *)NULL, PV_NONE,
775#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000776 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200777 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000778#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
779 (char_u *)&p_cinw, PV_CINW,
780 {(char_u *)"if,else,while,do,for,switch",
781 (char_u *)0L}
782#else
783 (char_u *)NULL, PV_NONE,
784 {(char_u *)0L, (char_u *)0L}
785#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000786 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200787 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000788#ifdef FEAT_CLIPBOARD
789 (char_u *)&p_cb, PV_NONE,
790# ifdef FEAT_XCLIPBOARD
791 {(char_u *)"autoselect,exclude:cons\\|linux",
792 (char_u *)0L}
793# else
794 {(char_u *)"", (char_u *)0L}
795# endif
796#else
797 (char_u *)NULL, PV_NONE,
798 {(char_u *)"", (char_u *)0L}
799#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000800 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
802 (char_u *)&p_ch, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000803 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
805#ifdef FEAT_CMDWIN
806 (char_u *)&p_cwh, PV_NONE,
807#else
808 (char_u *)NULL, PV_NONE,
809#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000810 {(char_u *)7L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200811 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200812#ifdef FEAT_SYN_HL
813 (char_u *)VAR_WIN, PV_CC,
814#else
815 (char_u *)NULL, PV_NONE,
816#endif
817 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000818 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
819 (char_u *)&Columns, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000820 {(char_u *)80L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200821 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
822 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823#ifdef FEAT_COMMENTS
824 (char_u *)&p_com, PV_COM,
825 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
826 (char_u *)0L}
827#else
828 (char_u *)NULL, PV_NONE,
829 {(char_u *)0L, (char_u *)0L}
830#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000831 SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200832 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000833#ifdef FEAT_FOLDING
834 (char_u *)&p_cms, PV_CMS,
835 {(char_u *)"/*%s*/", (char_u *)0L}
836#else
837 (char_u *)NULL, PV_NONE,
838 {(char_u *)0L, (char_u *)0L}
839#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000840 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000841 /* P_PRI_MKRC isn't needed here, optval_default()
842 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843 {"compatible", "cp", P_BOOL|P_RALL,
844 (char_u *)&p_cp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000845 {(char_u *)TRUE, (char_u *)FALSE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200846 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847#ifdef FEAT_INS_EXPAND
848 (char_u *)&p_cpt, PV_CPT,
849 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
850#else
851 (char_u *)NULL, PV_NONE,
852 {(char_u *)0L, (char_u *)0L}
853#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000854 SCRIPTID_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200855 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200856#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200857 (char_u *)VAR_WIN, PV_COCU,
858 {(char_u *)"", (char_u *)NULL}
859#else
860 (char_u *)NULL, PV_NONE,
861 {(char_u *)NULL, (char_u *)0L}
862#endif
863 SCRIPTID_INIT},
864 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
865#ifdef FEAT_CONCEAL
866 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200867#else
868 (char_u *)NULL, PV_NONE,
869#endif
870 {(char_u *)0L, (char_u *)0L}
871 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000872 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
873#ifdef FEAT_COMPL_FUNC
874 (char_u *)&p_cfu, PV_CFU,
875 {(char_u *)"", (char_u *)0L}
876#else
877 (char_u *)NULL, PV_NONE,
878 {(char_u *)0L, (char_u *)0L}
879#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000880 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200881 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000882#ifdef FEAT_INS_EXPAND
883 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000884 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000885#else
886 (char_u *)NULL, PV_NONE,
887 {(char_u *)0L, (char_u *)0L}
888#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000889 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890 {"confirm", "cf", P_BOOL|P_VI_DEF,
891#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
892 (char_u *)&p_confirm, PV_NONE,
893#else
894 (char_u *)NULL, PV_NONE,
895#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000896 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000897 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000898 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000899 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
901 (char_u *)&p_ci, PV_CI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000902 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
904 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000905 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
906 SCRIPTID_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200907 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200908#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200909 (char_u *)&p_cm, PV_CM,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200910 {(char_u *)"zip", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200911#else
912 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200913 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200914#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +0200915 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000916 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
917#ifdef FEAT_CSCOPE
918 (char_u *)&p_cspc, PV_NONE,
919#else
920 (char_u *)NULL, PV_NONE,
921#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000922 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000923 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
924#ifdef FEAT_CSCOPE
925 (char_u *)&p_csprg, PV_NONE,
926 {(char_u *)"cscope", (char_u *)0L}
927#else
928 (char_u *)NULL, PV_NONE,
929 {(char_u *)0L, (char_u *)0L}
930#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000931 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200932 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000933#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
934 (char_u *)&p_csqf, PV_NONE,
935 {(char_u *)"", (char_u *)0L}
936#else
937 (char_u *)NULL, PV_NONE,
938 {(char_u *)0L, (char_u *)0L}
939#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000940 SCRIPTID_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200941 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
942#ifdef FEAT_CSCOPE
943 (char_u *)&p_csre, PV_NONE,
944#else
945 (char_u *)NULL, PV_NONE,
946#endif
947 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000948 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
949#ifdef FEAT_CSCOPE
950 (char_u *)&p_cst, PV_NONE,
951#else
952 (char_u *)NULL, PV_NONE,
953#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000954 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
956#ifdef FEAT_CSCOPE
957 (char_u *)&p_csto, PV_NONE,
958#else
959 (char_u *)NULL, PV_NONE,
960#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000961 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000962 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
963#ifdef FEAT_CSCOPE
964 (char_u *)&p_csverbose, PV_NONE,
965#else
966 (char_u *)NULL, PV_NONE,
967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000968 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200969 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
970#ifdef FEAT_CURSORBIND
971 (char_u *)VAR_WIN, PV_CRBIND,
972#else
973 (char_u *)NULL, PV_NONE,
974#endif
975 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000976 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWIN,
977#ifdef FEAT_SYN_HL
978 (char_u *)VAR_WIN, PV_CUC,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000982 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100983 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000984#ifdef FEAT_SYN_HL
985 (char_u *)VAR_WIN, PV_CUL,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000989 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000990 {"debug", NULL, P_STRING|P_VI_DEF,
991 (char_u *)&p_debug, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000992 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200993 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000995 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000996 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000997#else
998 (char_u *)NULL, PV_NONE,
999 {(char_u *)NULL, (char_u *)0L}
1000#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001001 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
1003#ifdef FEAT_MBYTE
1004 (char_u *)&p_deco, PV_NONE,
1005#else
1006 (char_u *)NULL, PV_NONE,
1007#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001008 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001009 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001010#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001011 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#else
1013 (char_u *)NULL, PV_NONE,
1014#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001015 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1017#ifdef FEAT_DIFF
1018 (char_u *)VAR_WIN, PV_DIFF,
1019#else
1020 (char_u *)NULL, PV_NONE,
1021#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001022 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001023 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001024#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1025 (char_u *)&p_dex, PV_NONE,
1026 {(char_u *)"", (char_u *)0L}
1027#else
1028 (char_u *)NULL, PV_NONE,
1029 {(char_u *)0L, (char_u *)0L}
1030#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001031 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001032 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1033 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034#ifdef FEAT_DIFF
1035 (char_u *)&p_dip, PV_NONE,
1036 {(char_u *)"filler", (char_u *)NULL}
1037#else
1038 (char_u *)NULL, PV_NONE,
1039 {(char_u *)"", (char_u *)NULL}
1040#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001041 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1043#ifdef FEAT_DIGRAPHS
1044 (char_u *)&p_dg, PV_NONE,
1045#else
1046 (char_u *)NULL, PV_NONE,
1047#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001048 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001049 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1050 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 (char_u *)&p_dir, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001052 {(char_u *)DFLT_DIR, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001053 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 (char_u *)&p_dy, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001055 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01001057#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 (char_u *)&p_ead, PV_NONE,
1059 {(char_u *)"both", (char_u *)0L}
1060#else
1061 (char_u *)NULL, PV_NONE,
1062 {(char_u *)NULL, (char_u *)0L}
1063#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001064 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1066 (char_u *)&p_ed, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001067 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001068 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
1069#if defined(FEAT_MBYTE)
1070 (char_u *)&p_emoji, PV_NONE,
1071 {(char_u *)TRUE, (char_u *)0L}
1072#else
1073 (char_u *)NULL, PV_NONE,
1074 {(char_u *)0L, (char_u *)0L}
1075#endif
1076 SCRIPTID_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001077 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078#ifdef FEAT_MBYTE
1079 (char_u *)&p_enc, PV_NONE,
1080 {(char_u *)ENC_DFLT, (char_u *)0L}
1081#else
1082 (char_u *)NULL, PV_NONE,
1083 {(char_u *)0L, (char_u *)0L}
1084#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001085 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1087 (char_u *)&p_eol, PV_EOL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001088 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1090 (char_u *)&p_ea, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001091 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001093 (char_u *)&p_ep, PV_EP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001094 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1096 (char_u *)&p_eb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001097 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1099#ifdef FEAT_QUICKFIX
1100 (char_u *)&p_ef, PV_NONE,
1101 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)NULL, (char_u *)0L}
1105#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001106 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001107 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001109 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001110 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111#else
1112 (char_u *)NULL, PV_NONE,
1113 {(char_u *)NULL, (char_u *)0L}
1114#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001115 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"esckeys", "ek", P_BOOL|P_VIM,
1117 (char_u *)&p_ek, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001118 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001119 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120#ifdef FEAT_AUTOCMD
1121 (char_u *)&p_ei, PV_NONE,
1122#else
1123 (char_u *)NULL, PV_NONE,
1124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001126 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1127 (char_u *)&p_et, PV_ET,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001128 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001129 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1130 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001131 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001132 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1133 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134#ifdef FEAT_MBYTE
1135 (char_u *)&p_fenc, PV_FENC,
1136 {(char_u *)"", (char_u *)0L}
1137#else
1138 (char_u *)NULL, PV_NONE,
1139 {(char_u *)0L, (char_u *)0L}
1140#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001141 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001142 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001143#ifdef FEAT_MBYTE
1144 (char_u *)&p_fencs, PV_NONE,
1145 {(char_u *)"ucs-bom", (char_u *)0L}
1146#else
1147 (char_u *)NULL, PV_NONE,
1148 {(char_u *)0L, (char_u *)0L}
1149#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001150 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001151 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1152 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153 (char_u *)&p_ff, PV_FF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001154 {(char_u *)DFLT_FF, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001155 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001157 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
1158 SCRIPTID_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001159 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1160 (char_u *)&p_fic, PV_NONE,
1161 {
1162#ifdef CASE_INSENSITIVE_FILENAME
1163 (char_u *)TRUE,
1164#else
1165 (char_u *)FALSE,
1166#endif
1167 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001168 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001169#ifdef FEAT_AUTOCMD
1170 (char_u *)&p_ft, PV_FT,
1171 {(char_u *)"", (char_u *)0L}
1172#else
1173 (char_u *)NULL, PV_NONE,
1174 {(char_u *)0L, (char_u *)0L}
1175#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001176 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001177 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001178#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
1179 (char_u *)&p_fcs, PV_NONE,
1180 {(char_u *)"vert:|,fold:-", (char_u *)0L}
1181#else
1182 (char_u *)NULL, PV_NONE,
1183 {(char_u *)"", (char_u *)0L}
1184#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001185 SCRIPTID_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001186 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1187 (char_u *)&p_fixeol, PV_FIXEOL,
1188 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1190#ifdef FEAT_FKMAP
1191 (char_u *)&p_fkmap, PV_NONE,
1192#else
1193 (char_u *)NULL, PV_NONE,
1194#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001195 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {"flash", "fl", P_BOOL|P_VI_DEF,
1197 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001198 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199#ifdef FEAT_FOLDING
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001200 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001202 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001203 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1204 (char_u *)VAR_WIN, PV_FDC,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001205 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001206 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1207 (char_u *)VAR_WIN, PV_FEN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001208 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1210# ifdef FEAT_EVAL
1211 (char_u *)VAR_WIN, PV_FDE,
1212 {(char_u *)"0", (char_u *)NULL}
1213# else
1214 (char_u *)NULL, PV_NONE,
1215 {(char_u *)NULL, (char_u *)0L}
1216# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001217 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1219 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)"#", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
1222 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001223 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001224 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001226 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001227 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001228 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001230 {(char_u *)"{{{,}}}", (char_u *)NULL}
1231 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1233 (char_u *)VAR_WIN, PV_FDM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001234 {(char_u *)"manual", (char_u *)NULL} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001235 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1236 (char_u *)VAR_WIN, PV_FML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001237 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001238 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1239 (char_u *)VAR_WIN, PV_FDN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001240 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001241 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001242 (char_u *)&p_fdo, PV_NONE,
1243 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001244 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001245 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1246# ifdef FEAT_EVAL
1247 (char_u *)VAR_WIN, PV_FDT,
1248 {(char_u *)"foldtext()", (char_u *)NULL}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001249# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001250 (char_u *)NULL, PV_NONE,
1251 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar7b0294c2004-10-11 10:16:09 +00001252# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001253 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001254#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001255 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001256#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001257 (char_u *)&p_fex, PV_FEX,
1258 {(char_u *)"", (char_u *)0L}
1259#else
1260 (char_u *)NULL, PV_NONE,
1261 {(char_u *)0L, (char_u *)0L}
1262#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001263 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001264 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1265 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001266 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
1267 SCRIPTID_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001268 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1269 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001270 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
1271 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001272 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001273 (char_u *)&p_fp, PV_FP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001274 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001275 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1276#ifdef HAVE_FSYNC
1277 (char_u *)&p_fs, PV_NONE,
1278 {(char_u *)TRUE, (char_u *)0L}
1279#else
1280 (char_u *)NULL, PV_NONE,
1281 {(char_u *)FALSE, (char_u *)0L}
1282#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001283 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1285 (char_u *)&p_gd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001286 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287 {"graphic", "gr", P_BOOL|P_VI_DEF,
1288 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001289 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001290 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001291#ifdef FEAT_QUICKFIX
1292 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001293 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294#else
1295 (char_u *)NULL, PV_NONE,
1296 {(char_u *)NULL, (char_u *)0L}
1297#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001298 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1300#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001301 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 {
1303# ifdef WIN3264
1304 /* may be changed to "grep -n" in os_win32.c */
1305 (char_u *)"findstr /n",
1306# else
1307# ifdef UNIX
1308 /* Add an extra file name so that grep will always
1309 * insert a file name in the match line. */
1310 (char_u *)"grep -n $* /dev/null",
1311# else
1312# ifdef VMS
1313 (char_u *)"SEARCH/NUMBERS ",
1314# else
1315 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001316# endif
1317# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001319 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320#else
1321 (char_u *)NULL, PV_NONE,
1322 {(char_u *)NULL, (char_u *)0L}
1323#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001324 SCRIPTID_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001325 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001326#ifdef CURSOR_SHAPE
1327 (char_u *)&p_guicursor, PV_NONE,
1328 {
1329# ifdef FEAT_GUI
1330 (char_u *)"n-v-c:block-Cursor/lCursor,ve:ver35-Cursor,o:hor50-Cursor,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor,sm:block-Cursor-blinkwait175-blinkoff150-blinkon175",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001331# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1333# endif
1334 (char_u *)0L}
1335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001339 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001340 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341#ifdef FEAT_GUI
1342 (char_u *)&p_guifont, PV_NONE,
1343 {(char_u *)"", (char_u *)0L}
1344#else
1345 (char_u *)NULL, PV_NONE,
1346 {(char_u *)NULL, (char_u *)0L}
1347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001348 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001349 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1351 (char_u *)&p_guifontset, PV_NONE,
1352 {(char_u *)"", (char_u *)0L}
1353#else
1354 (char_u *)NULL, PV_NONE,
1355 {(char_u *)NULL, (char_u *)0L}
1356#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001357 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001358 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359#if defined(FEAT_GUI) && defined(FEAT_MBYTE)
1360 (char_u *)&p_guifontwide, PV_NONE,
1361 {(char_u *)"", (char_u *)0L}
1362#else
1363 (char_u *)NULL, PV_NONE,
1364 {(char_u *)NULL, (char_u *)0L}
1365#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001366 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001368#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001369 (char_u *)&p_ghr, PV_NONE,
1370#else
1371 (char_u *)NULL, PV_NONE,
1372#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001373 {(char_u *)50L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001374 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001375#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 (char_u *)&p_go, PV_NONE,
1377# if defined(UNIX) && !defined(MACOS)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001378 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001380 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381# endif
1382#else
1383 (char_u *)NULL, PV_NONE,
1384 {(char_u *)NULL, (char_u *)0L}
1385#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001386 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387 {"guipty", NULL, P_BOOL|P_VI_DEF,
1388#if defined(FEAT_GUI)
1389 (char_u *)&p_guipty, PV_NONE,
1390#else
1391 (char_u *)NULL, PV_NONE,
1392#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001393 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001394 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001395#if defined(FEAT_GUI_TABLINE)
1396 (char_u *)&p_gtl, PV_NONE,
1397 {(char_u *)"", (char_u *)0L}
1398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001402 SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001403 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001404#if defined(FEAT_GUI_TABLINE)
1405 (char_u *)&p_gtt, PV_NONE,
1406 {(char_u *)"", (char_u *)0L}
1407#else
1408 (char_u *)NULL, PV_NONE,
1409 {(char_u *)NULL, (char_u *)0L}
1410#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001411 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001412 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1413 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001414 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001415 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1416 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001417 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
1418 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001419 {"helpheight", "hh", P_NUM|P_VI_DEF,
1420#ifdef FEAT_WINDOWS
1421 (char_u *)&p_hh, PV_NONE,
1422#else
1423 (char_u *)NULL, PV_NONE,
1424#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001425 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001426 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427#ifdef FEAT_MULTI_LANG
1428 (char_u *)&p_hlg, PV_NONE,
1429 {(char_u *)"", (char_u *)0L}
1430#else
1431 (char_u *)NULL, PV_NONE,
1432 {(char_u *)0L, (char_u *)0L}
1433#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"hidden", "hid", P_BOOL|P_VI_DEF,
1436 (char_u *)&p_hid, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001437 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001438 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001439 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001440 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
1441 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 {"history", "hi", P_NUM|P_VIM,
1443 (char_u *)&p_hi, PV_NONE,
Bram Moolenaar78159bb2014-06-25 11:48:54 +02001444 {(char_u *)0L, (char_u *)50L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1446#ifdef FEAT_RIGHTLEFT
1447 (char_u *)&p_hkmap, PV_NONE,
1448#else
1449 (char_u *)NULL, PV_NONE,
1450#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1453#ifdef FEAT_RIGHTLEFT
1454 (char_u *)&p_hkmapp, PV_NONE,
1455#else
1456 (char_u *)NULL, PV_NONE,
1457#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001458 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1460 (char_u *)&p_hls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001461 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001462 {"icon", NULL, P_BOOL|P_VI_DEF,
1463#ifdef FEAT_TITLE
1464 (char_u *)&p_icon, PV_NONE,
1465#else
1466 (char_u *)NULL, PV_NONE,
1467#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001468 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001469 {"iconstring", NULL, P_STRING|P_VI_DEF,
1470#ifdef FEAT_TITLE
1471 (char_u *)&p_iconstring, PV_NONE,
1472#else
1473 (char_u *)NULL, PV_NONE,
1474#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001475 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1477 (char_u *)&p_ic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001478 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001479 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
1480# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1481 (char_u *)&p_imaf, PV_NONE,
1482 {(char_u *)"", (char_u *)NULL}
1483# else
1484 (char_u *)NULL, PV_NONE,
1485 {(char_u *)NULL, (char_u *)0L}
1486# endif
1487 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001489#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 (char_u *)&p_imak, PV_NONE,
1491#else
1492 (char_u *)NULL, PV_NONE,
1493#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001494 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001495 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
1496#ifdef USE_IM_CONTROL
1497 (char_u *)&p_imcmdline, PV_NONE,
1498#else
1499 (char_u *)NULL, PV_NONE,
1500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001501 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502 {"imdisable", "imd", P_BOOL|P_VI_DEF,
1503#ifdef USE_IM_CONTROL
1504 (char_u *)&p_imdisable, PV_NONE,
1505#else
1506 (char_u *)NULL, PV_NONE,
1507#endif
1508#ifdef __sgi
1509 {(char_u *)TRUE, (char_u *)0L}
1510#else
1511 {(char_u *)FALSE, (char_u *)0L}
1512#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001513 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"iminsert", "imi", P_NUM|P_VI_DEF,
1515 (char_u *)&p_iminsert, PV_IMI,
1516#ifdef B_IMODE_IM
1517 {(char_u *)B_IMODE_IM, (char_u *)0L}
1518#else
1519 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1520#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001521 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"imsearch", "ims", P_NUM|P_VI_DEF,
1523 (char_u *)&p_imsearch, PV_IMS,
1524#ifdef B_IMODE_IM
1525 {(char_u *)B_IMODE_IM, (char_u *)0L}
1526#else
1527 {(char_u *)B_IMODE_NONE, (char_u *)0L}
1528#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001529 SCRIPTID_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001530 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001531# if defined(FEAT_EVAL) && defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1532 (char_u *)&p_imsf, PV_NONE,
1533 {(char_u *)"", (char_u *)NULL}
1534# else
1535 (char_u *)NULL, PV_NONE,
1536 {(char_u *)NULL, (char_u *)0L}
1537# endif
1538 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001539 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1540#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001541 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001542 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1543#else
1544 (char_u *)NULL, PV_NONE,
1545 {(char_u *)0L, (char_u *)0L}
1546#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001547 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1549#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1550 (char_u *)&p_inex, PV_INEX,
1551 {(char_u *)"", (char_u *)0L}
1552#else
1553 (char_u *)NULL, PV_NONE,
1554 {(char_u *)0L, (char_u *)0L}
1555#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001556 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1558 (char_u *)&p_is, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001559 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001560 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1561#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1562 (char_u *)&p_inde, PV_INDE,
1563 {(char_u *)"", (char_u *)0L}
1564#else
1565 (char_u *)NULL, PV_NONE,
1566 {(char_u *)0L, (char_u *)0L}
1567#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001568 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001569 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001570#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1571 (char_u *)&p_indk, PV_INDK,
1572 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1573#else
1574 (char_u *)NULL, PV_NONE,
1575 {(char_u *)0L, (char_u *)0L}
1576#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001577 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001578 {"infercase", "inf", P_BOOL|P_VI_DEF,
1579 (char_u *)&p_inf, PV_INF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001580 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001581 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1582 (char_u *)&p_im, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001583 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001584 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1585 (char_u *)&p_isf, PV_NONE,
1586 {
1587#ifdef BACKSLASH_IN_FILENAME
1588 /* Excluded are: & and ^ are special in cmd.exe
1589 * ( and ) are used in text separating fnames */
1590 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1591#else
1592# ifdef AMIGA
1593 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1594# else
1595# ifdef VMS
1596 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1597# else /* UNIX et al. */
1598# ifdef EBCDIC
1599 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1600# else
1601 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1602# endif
1603# endif
1604# endif
1605#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001606 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001607 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1608 (char_u *)&p_isi, PV_NONE,
1609 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001610#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 (char_u *)"@,48-57,_,128-167,224-235",
1612#else
1613# ifdef EBCDIC
1614 /* TODO: EBCDIC Check this! @ == isalpha()*/
1615 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1616 "112-120,128,140-142,156,158,172,"
1617 "174,186,191,203-207,219-225,235-239,"
1618 "251-254",
1619# else
1620 (char_u *)"@,48-57,_,192-255",
1621# endif
1622#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001623 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001624 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1625 (char_u *)&p_isk, PV_ISK,
1626 {
1627#ifdef EBCDIC
1628 (char_u *)"@,240-249,_",
1629 /* TODO: EBCDIC Check this! @ == isalpha()*/
1630 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1631 "112-120,128,140-142,156,158,172,"
1632 "174,186,191,203-207,219-225,235-239,"
1633 "251-254",
1634#else
1635 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001636# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001637 (char_u *)"@,48-57,_,128-167,224-235"
1638# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001639 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001640# endif
1641#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001642 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1644 (char_u *)&p_isp, PV_NONE,
1645 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001646#if defined(MSWIN) || (defined(MACOS) && !defined(MACOS_X)) \
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 || defined(VMS)
1648 (char_u *)"@,~-255",
1649#else
1650# ifdef EBCDIC
1651 /* all chars above 63 are printable */
1652 (char_u *)"63-255",
1653# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001654 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655# endif
1656#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001657 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1659 (char_u *)&p_js, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001660 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1662#ifdef FEAT_CRYPT
1663 (char_u *)&p_key, PV_KEY,
1664 {(char_u *)"", (char_u *)0L}
1665#else
1666 (char_u *)NULL, PV_NONE,
1667 {(char_u *)0L, (char_u *)0L}
1668#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001669 SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001670 {"keymap", "kmp", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF|P_RSTAT|P_NFNAME|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001671#ifdef FEAT_KEYMAP
1672 (char_u *)&p_keymap, PV_KMAP,
1673 {(char_u *)"", (char_u *)0L}
1674#else
1675 (char_u *)NULL, PV_NONE,
1676 {(char_u *)"", (char_u *)0L}
1677#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001678 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001679 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001680 (char_u *)&p_km, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001681 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001682 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001683 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001685#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 (char_u *)":help",
1687#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001688# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001690# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001691# ifdef USEMAN_S
1692 (char_u *)"man -s",
1693# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001695# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696# endif
1697#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001698 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001699 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700#ifdef FEAT_LANGMAP
1701 (char_u *)&p_langmap, PV_NONE,
1702 {(char_u *)"", /* unmatched } */
1703#else
1704 (char_u *)NULL, PV_NONE,
1705 {(char_u *)NULL,
1706#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001707 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001708 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1710 (char_u *)&p_lm, PV_NONE,
1711#else
1712 (char_u *)NULL, PV_NONE,
1713#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001714 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001715 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1716#ifdef FEAT_LANGMAP
1717 (char_u *)&p_lnr, PV_NONE,
1718#else
1719 (char_u *)NULL, PV_NONE,
1720#endif
1721 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001722 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1723#ifdef FEAT_LANGMAP
1724 (char_u *)&p_lrm, PV_NONE,
1725#else
1726 (char_u *)NULL, PV_NONE,
1727#endif
Bram Moolenaarda9ce2c2016-09-02 19:34:10 +02001728 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
1730#ifdef FEAT_WINDOWS
1731 (char_u *)&p_ls, PV_NONE,
1732#else
1733 (char_u *)NULL, PV_NONE,
1734#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001735 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1737 (char_u *)&p_lz, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001738 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1740#ifdef FEAT_LINEBREAK
1741 (char_u *)VAR_WIN, PV_LBR,
1742#else
1743 (char_u *)NULL, PV_NONE,
1744#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001745 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1747 (char_u *)&Rows, PV_NONE,
1748 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001749#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 (char_u *)25L,
1751#else
1752 (char_u *)24L,
1753#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001754 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1756#ifdef FEAT_GUI
1757 (char_u *)&p_linespace, PV_NONE,
1758#else
1759 (char_u *)NULL, PV_NONE,
1760#endif
1761#ifdef FEAT_GUI_W32
1762 {(char_u *)1L, (char_u *)0L}
1763#else
1764 {(char_u *)0L, (char_u *)0L}
1765#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001766 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 {"lisp", NULL, P_BOOL|P_VI_DEF,
1768#ifdef FEAT_LISP
1769 (char_u *)&p_lisp, PV_LISP,
1770#else
1771 (char_u *)NULL, PV_NONE,
1772#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001773 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001774 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001776 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1778#else
1779 (char_u *)NULL, PV_NONE,
1780 {(char_u *)"", (char_u *)0L}
1781#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001782 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1784 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001785 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001786 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001788 {(char_u *)"eol:$", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1790 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001791 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001792#if defined(DYNAMIC_LUA)
Bram Moolenaara6e42502016-04-20 16:19:52 +02001793 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01001794 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001795 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
1796 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01001797#endif
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001798#ifdef FEAT_GUI_MAC
1799 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
1800 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001801 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001802#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001803 {"magic", NULL, P_BOOL|P_VI_DEF,
1804 (char_u *)&p_magic, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001805 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001806 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807#ifdef FEAT_QUICKFIX
1808 (char_u *)&p_mef, PV_NONE,
1809 {(char_u *)"", (char_u *)0L}
1810#else
1811 (char_u *)NULL, PV_NONE,
1812 {(char_u *)NULL, (char_u *)0L}
1813#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001814 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1816#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001817 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001818# ifdef VMS
1819 {(char_u *)"MMS", (char_u *)0L}
1820# else
1821 {(char_u *)"make", (char_u *)0L}
1822# endif
1823#else
1824 (char_u *)NULL, PV_NONE,
1825 {(char_u *)NULL, (char_u *)0L}
1826#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001827 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001828 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001830 {(char_u *)"(:),{:},[:]", (char_u *)0L}
1831 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001832 {"matchtime", "mat", P_NUM|P_VI_DEF,
1833 (char_u *)&p_mat, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001834 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001835 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001836#ifdef FEAT_MBYTE
1837 (char_u *)&p_mco, PV_NONE,
1838#else
1839 (char_u *)NULL, PV_NONE,
1840#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)2, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1843#ifdef FEAT_EVAL
1844 (char_u *)&p_mfd, PV_NONE,
1845#else
1846 (char_u *)NULL, PV_NONE,
1847#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001848 {(char_u *)100L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1850 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"maxmem", "mm", P_NUM|P_VI_DEF,
1853 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001854 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
1855 SCRIPTID_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001856 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1857 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001858 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1860 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
1862 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001863 {"menuitems", "mis", P_NUM|P_VI_DEF,
1864#ifdef FEAT_MENU
1865 (char_u *)&p_mis, PV_NONE,
1866#else
1867 (char_u *)NULL, PV_NONE,
1868#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)25L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"mesg", NULL, P_BOOL|P_VI_DEF,
1871 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001872 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001873 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001874#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001875 (char_u *)&p_msm, PV_NONE,
1876 {(char_u *)"460000,2000,500", (char_u *)0L}
1877#else
1878 (char_u *)NULL, PV_NONE,
1879 {(char_u *)0L, (char_u *)0L}
1880#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001881 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882 {"modeline", "ml", P_BOOL|P_VIM,
1883 (char_u *)&p_ml, PV_ML,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001884 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885 {"modelines", "mls", P_NUM|P_VI_DEF,
1886 (char_u *)&p_mls, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001887 {(char_u *)5L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1889 (char_u *)&p_ma, PV_MA,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001890 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1892 (char_u *)&p_mod, PV_MOD,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001893 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"more", NULL, P_BOOL|P_VIM,
1895 (char_u *)&p_more, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001896 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1898 (char_u *)&p_mouse, PV_NONE,
1899 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001900#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901 (char_u *)"a",
1902#else
1903 (char_u *)"",
1904#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001905 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1907#ifdef FEAT_GUI
1908 (char_u *)&p_mousef, PV_NONE,
1909#else
1910 (char_u *)NULL, PV_NONE,
1911#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001912 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1914#ifdef FEAT_GUI
1915 (char_u *)&p_mh, PV_NONE,
1916#else
1917 (char_u *)NULL, PV_NONE,
1918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001919 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001920 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1921 (char_u *)&p_mousem, PV_NONE,
1922 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001923#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 (char_u *)"popup",
1925#else
1926# if defined(MACOS)
1927 (char_u *)"popup_setpos",
1928# else
1929 (char_u *)"extend",
1930# endif
1931#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001932 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001933 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934#ifdef FEAT_MOUSESHAPE
1935 (char_u *)&p_mouseshape, PV_NONE,
1936 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1937#else
1938 (char_u *)NULL, PV_NONE,
1939 {(char_u *)NULL, (char_u *)0L}
1940#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001941 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001942 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1943 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001944 {(char_u *)500L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001945 {"mzquantum", "mzq", P_NUM,
1946#ifdef FEAT_MZSCHEME
1947 (char_u *)&p_mzq, PV_NONE,
1948#else
1949 (char_u *)NULL, PV_NONE,
1950#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001951 {(char_u *)100L, (char_u *)100L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"novice", NULL, P_BOOL|P_VI_DEF,
1953 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001954 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001955 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001956 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001957 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001958 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1960 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001961 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001962 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1963#ifdef FEAT_LINEBREAK
1964 (char_u *)VAR_WIN, PV_NUW,
1965#else
1966 (char_u *)NULL, PV_NONE,
1967#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001968 {(char_u *)8L, (char_u *)4L} SCRIPTID_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001969 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001970#ifdef FEAT_COMPL_FUNC
1971 (char_u *)&p_ofu, PV_OFU,
1972 {(char_u *)"", (char_u *)0L}
1973#else
1974 (char_u *)NULL, PV_NONE,
1975 {(char_u *)0L, (char_u *)0L}
1976#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001977 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001978 {"open", NULL, P_BOOL|P_VI_DEF,
1979 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001980 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00001981 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001982#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00001983 (char_u *)&p_odev, PV_NONE,
1984#else
1985 (char_u *)NULL, PV_NONE,
1986#endif
1987 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001988 SCRIPTID_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00001989 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
1990 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001991 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001992 {"optimize", "opt", P_BOOL|P_VI_DEF,
1993 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001994 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001995 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001996 (char_u *)NULL, PV_NONE,
Bram Moolenaarb07269a2011-05-19 13:41:14 +02001997 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01001998 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
1999 |P_SECURE,
2000 (char_u *)&p_pp, PV_NONE,
2001 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2002 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002003 {"paragraphs", "para", P_STRING|P_VI_DEF,
2004 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002005 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002006 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002007 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 (char_u *)&p_paste, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002009 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002010 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2011 (char_u *)&p_pt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002012 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2014#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2015 (char_u *)&p_pex, PV_NONE,
2016 {(char_u *)"", (char_u *)0L}
2017#else
2018 (char_u *)NULL, PV_NONE,
2019 {(char_u *)0L, (char_u *)0L}
2020#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002021 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002022 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 (char_u *)&p_pm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002024 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002026 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002028#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029 (char_u *)".,,",
2030#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002033 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002034#if defined(DYNAMIC_PERL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002035 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002036 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002037 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
2038 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2041 (char_u *)&p_pi, PV_PI,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002042 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002043 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2045 (char_u *)&p_pvh, PV_NONE,
2046#else
2047 (char_u *)NULL, PV_NONE,
2048#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002049 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2051#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
2052 (char_u *)VAR_WIN, PV_PVW,
2053#else
2054 (char_u *)NULL, PV_NONE,
2055#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002056 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002057 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058#ifdef FEAT_PRINTER
2059 (char_u *)&p_pdev, PV_NONE,
2060 {(char_u *)"", (char_u *)0L}
2061#else
2062 (char_u *)NULL, PV_NONE,
2063 {(char_u *)NULL, (char_u *)0L}
2064#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002065 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002066 {"printencoding", "penc", P_STRING|P_VI_DEF,
2067#ifdef FEAT_POSTSCRIPT
2068 (char_u *)&p_penc, PV_NONE,
2069 {(char_u *)"", (char_u *)0L}
2070#else
2071 (char_u *)NULL, PV_NONE,
2072 {(char_u *)NULL, (char_u *)0L}
2073#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002074 SCRIPTID_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002075 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076#ifdef FEAT_POSTSCRIPT
2077 (char_u *)&p_pexpr, PV_NONE,
2078 {(char_u *)"", (char_u *)0L}
2079#else
2080 (char_u *)NULL, PV_NONE,
2081 {(char_u *)NULL, (char_u *)0L}
2082#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002083 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002084 {"printfont", "pfn", P_STRING|P_VI_DEF,
2085#ifdef FEAT_PRINTER
2086 (char_u *)&p_pfn, PV_NONE,
2087 {
2088# ifdef MSWIN
2089 (char_u *)"Courier_New:h10",
2090# else
2091 (char_u *)"courier",
2092# endif
2093 (char_u *)0L}
2094#else
2095 (char_u *)NULL, PV_NONE,
2096 {(char_u *)NULL, (char_u *)0L}
2097#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002098 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2100#ifdef FEAT_PRINTER
2101 (char_u *)&p_header, PV_NONE,
2102 {(char_u *)N_("%<%f%h%m%=Page %N"), (char_u *)0L}
2103#else
2104 (char_u *)NULL, PV_NONE,
2105 {(char_u *)NULL, (char_u *)0L}
2106#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002107 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002108 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
2109#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2110 (char_u *)&p_pmcs, PV_NONE,
2111 {(char_u *)"", (char_u *)0L}
2112#else
2113 (char_u *)NULL, PV_NONE,
2114 {(char_u *)NULL, (char_u *)0L}
2115#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002116 SCRIPTID_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002117 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
2118#if defined(FEAT_POSTSCRIPT) && defined(FEAT_MBYTE)
2119 (char_u *)&p_pmfn, PV_NONE,
2120 {(char_u *)"", (char_u *)0L}
2121#else
2122 (char_u *)NULL, PV_NONE,
2123 {(char_u *)NULL, (char_u *)0L}
2124#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002125 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002126 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002127#ifdef FEAT_PRINTER
2128 (char_u *)&p_popt, PV_NONE,
2129 {(char_u *)"", (char_u *)0L}
2130#else
2131 (char_u *)NULL, PV_NONE,
2132 {(char_u *)NULL, (char_u *)0L}
2133#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002134 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002135 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002136 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002137 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002138 {"pumheight", "ph", P_NUM|P_VI_DEF,
2139#ifdef FEAT_INS_EXPAND
2140 (char_u *)&p_ph, PV_NONE,
2141#else
2142 (char_u *)NULL, PV_NONE,
2143#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002144 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002145#if defined(DYNAMIC_PYTHON3)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002146 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002147 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002148 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
2149 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002150#endif
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002151#if defined(DYNAMIC_PYTHON)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002152 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002153 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002154 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
2155 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002156#endif
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002157 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2158#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2159 (char_u *)&p_pyx, PV_NONE,
2160#else
2161 (char_u *)NULL, PV_NONE,
2162#endif
2163 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
2164 SCRIPTID_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002165 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2166#ifdef FEAT_TEXTOBJ
2167 (char_u *)&p_qe, PV_QE,
2168 {(char_u *)"\\", (char_u *)0L}
2169#else
2170 (char_u *)NULL, PV_NONE,
2171 {(char_u *)NULL, (char_u *)0L}
2172#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002173 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002174 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2175 (char_u *)&p_ro, PV_RO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002176 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002177 {"redraw", NULL, P_BOOL|P_VI_DEF,
2178 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002179 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002180 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2181#ifdef FEAT_RELTIME
2182 (char_u *)&p_rdt, PV_NONE,
2183#else
2184 (char_u *)NULL, PV_NONE,
2185#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002186 {(char_u *)2000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002187 {"regexpengine", "re", P_NUM|P_VI_DEF,
2188 (char_u *)&p_re, PV_NONE,
2189 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002190 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2191 (char_u *)VAR_WIN, PV_RNU,
2192 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002193 {"remap", NULL, P_BOOL|P_VI_DEF,
2194 (char_u *)&p_remap, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002195 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002196 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002197#ifdef FEAT_RENDER_OPTIONS
2198 (char_u *)&p_rop, PV_NONE,
2199 {(char_u *)"", (char_u *)0L}
2200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
2203#endif
2204 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002205 {"report", NULL, P_NUM|P_VI_DEF,
2206 (char_u *)&p_report, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002207 {(char_u *)2L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002208 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2209#ifdef WIN3264
2210 (char_u *)&p_rs, PV_NONE,
2211#else
2212 (char_u *)NULL, PV_NONE,
2213#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002214 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002215 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2216#ifdef FEAT_RIGHTLEFT
2217 (char_u *)&p_ri, PV_NONE,
2218#else
2219 (char_u *)NULL, PV_NONE,
2220#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002221 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002222 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2223#ifdef FEAT_RIGHTLEFT
2224 (char_u *)VAR_WIN, PV_RL,
2225#else
2226 (char_u *)NULL, PV_NONE,
2227#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002228 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002229 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2230#ifdef FEAT_RIGHTLEFT
2231 (char_u *)VAR_WIN, PV_RLC,
2232 {(char_u *)"search", (char_u *)NULL}
2233#else
2234 (char_u *)NULL, PV_NONE,
2235 {(char_u *)NULL, (char_u *)0L}
2236#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002237 SCRIPTID_INIT},
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002238#if defined(DYNAMIC_RUBY)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002239 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaard94464e2015-11-02 15:28:18 +01002240 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002241 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
2242 SCRIPTID_INIT},
Bram Moolenaard94464e2015-11-02 15:28:18 +01002243#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2245#ifdef FEAT_CMDL_INFO
2246 (char_u *)&p_ru, PV_NONE,
2247#else
2248 (char_u *)NULL, PV_NONE,
2249#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002250 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2252#ifdef FEAT_STL_OPT
2253 (char_u *)&p_ruf, PV_NONE,
2254#else
2255 (char_u *)NULL, PV_NONE,
2256#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002257 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002258 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2259 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002261 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
2262 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002263 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2264 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002265 {(char_u *)12L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002266 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
2267#ifdef FEAT_SCROLLBIND
2268 (char_u *)VAR_WIN, PV_SCBIND,
2269#else
2270 (char_u *)NULL, PV_NONE,
2271#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002272 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002273 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2274 (char_u *)&p_sj, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002275 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002276 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2277 (char_u *)&p_so, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002278 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002279 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280#ifdef FEAT_SCROLLBIND
2281 (char_u *)&p_sbo, PV_NONE,
2282 {(char_u *)"ver,jump", (char_u *)0L}
2283#else
2284 (char_u *)NULL, PV_NONE,
2285 {(char_u *)0L, (char_u *)0L}
2286#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002287 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002288 {"sections", "sect", P_STRING|P_VI_DEF,
2289 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002290 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
2291 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002292 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2293 (char_u *)&p_secure, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002294 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002295 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002297 {(char_u *)"inclusive", (char_u *)0L}
2298 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002299 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002300 (char_u *)&p_slm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002301 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002302 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303#ifdef FEAT_SESSION
2304 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00002305 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002306 (char_u *)0L}
2307#else
2308 (char_u *)NULL, PV_NONE,
2309 {(char_u *)0L, (char_u *)0L}
2310#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002311 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002312 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2313 (char_u *)&p_sh, PV_NONE,
2314 {
2315#ifdef VMS
2316 (char_u *)"-",
2317#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002318# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002320# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322# endif
2323#endif /* VMS */
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002325 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2326 (char_u *)&p_shcf, PV_NONE,
2327 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002328#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 (char_u *)"/c",
2330#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002331 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002333 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2335#ifdef FEAT_QUICKFIX
2336 (char_u *)&p_sp, PV_NONE,
2337 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002338#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340#else
2341 (char_u *)">",
2342#endif
2343 (char_u *)0L}
2344#else
2345 (char_u *)NULL, PV_NONE,
2346 {(char_u *)0L, (char_u *)0L}
2347#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2350 (char_u *)&p_shq, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002352 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2353 (char_u *)&p_srr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002354 {(char_u *)">", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002355 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2356#ifdef BACKSLASH_IN_FILENAME
2357 (char_u *)&p_ssl, PV_NONE,
2358#else
2359 (char_u *)NULL, PV_NONE,
2360#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002361 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002362 {"shelltemp", "stmp", P_BOOL,
2363 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002364 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 {"shelltype", "st", P_NUM|P_VI_DEF,
2366#ifdef AMIGA
2367 (char_u *)&p_st, PV_NONE,
2368#else
2369 (char_u *)NULL, PV_NONE,
2370#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002371 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2373 (char_u *)&p_sxq, PV_NONE,
2374 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002375#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 (char_u *)"\"",
2377#else
2378 (char_u *)"",
2379#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002380 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002381 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2382 (char_u *)&p_sxe, PV_NONE,
2383 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002384#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002385 (char_u *)"\"&|<>()@^",
2386#else
2387 (char_u *)"",
2388#endif
2389 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2391 (char_u *)&p_sr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002392 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2394 (char_u *)&p_sw, PV_SW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002395 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002396 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2397 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002398 {(char_u *)"", (char_u *)"filnxtToO"}
2399 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401 (char_u *)&p_sn, PV_SN,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002402 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2404#ifdef FEAT_LINEBREAK
2405 (char_u *)&p_sbr, PV_NONE,
2406#else
2407 (char_u *)NULL, PV_NONE,
2408#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002409 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"showcmd", "sc", P_BOOL|P_VIM,
2411#ifdef FEAT_CMDL_INFO
2412 (char_u *)&p_sc, PV_NONE,
2413#else
2414 (char_u *)NULL, PV_NONE,
2415#endif
2416 {(char_u *)FALSE,
2417#ifdef UNIX
2418 (char_u *)FALSE
2419#else
2420 (char_u *)TRUE
2421#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002422 } SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2424 (char_u *)&p_sft, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002425 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2427 (char_u *)&p_sm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002428 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002429 {"showmode", "smd", P_BOOL|P_VIM,
2430 (char_u *)&p_smd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002431 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002432 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
2433#ifdef FEAT_WINDOWS
2434 (char_u *)&p_stal, PV_NONE,
2435#else
2436 (char_u *)NULL, PV_NONE,
2437#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002438 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002439 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2440 (char_u *)&p_ss, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002441 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002442 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2443 (char_u *)&p_siso, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002444 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002445 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2446#ifdef FEAT_SIGNS
2447 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002448 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002449#else
2450 (char_u *)NULL, PV_NONE,
2451 {(char_u *)NULL, (char_u *)0L}
2452#endif
Bram Moolenaarb3384832016-08-12 18:51:58 +02002453 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2455 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002456 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2458 (char_u *)&p_scs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002459 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002460 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2461#ifdef FEAT_SMARTINDENT
2462 (char_u *)&p_si, PV_SI,
2463#else
2464 (char_u *)NULL, PV_NONE,
2465#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002466 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002467 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2468 (char_u *)&p_sta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002469 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2471 (char_u *)&p_sts, PV_STS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002472 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002473 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2474 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002475 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002476 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002477#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002478 (char_u *)VAR_WIN, PV_SPELL,
2479#else
2480 (char_u *)NULL, PV_NONE,
2481#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002482 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002483 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002484#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002485 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002486 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002487#else
2488 (char_u *)NULL, PV_NONE,
2489 {(char_u *)0L, (char_u *)0L}
2490#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002491 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002492 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2493 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002494#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002495 (char_u *)&p_spf, PV_SPF,
2496 {(char_u *)"", (char_u *)0L}
2497#else
2498 (char_u *)NULL, PV_NONE,
2499 {(char_u *)0L, (char_u *)0L}
2500#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002501 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002502 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2503 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002504#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002505 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002506 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002507#else
2508 (char_u *)NULL, PV_NONE,
2509 {(char_u *)0L, (char_u *)0L}
2510#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002511 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002512 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002513#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002514 (char_u *)&p_sps, PV_NONE,
2515 {(char_u *)"best", (char_u *)0L}
2516#else
2517 (char_u *)NULL, PV_NONE,
2518 {(char_u *)0L, (char_u *)0L}
2519#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002520 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
2522#ifdef FEAT_WINDOWS
2523 (char_u *)&p_sb, PV_NONE,
2524#else
2525 (char_u *)NULL, PV_NONE,
2526#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002527 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002528 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002529#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 (char_u *)&p_spr, PV_NONE,
2531#else
2532 (char_u *)NULL, PV_NONE,
2533#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002534 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2536 (char_u *)&p_sol, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002537 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2539#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002540 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002541#else
2542 (char_u *)NULL, PV_NONE,
2543#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002544 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002545 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002546 (char_u *)&p_su, PV_NONE,
2547 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002548 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002549 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002550#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002551 (char_u *)&p_sua, PV_SUA,
2552 {(char_u *)"", (char_u *)0L}
2553#else
2554 (char_u *)NULL, PV_NONE,
2555 {(char_u *)0L, (char_u *)0L}
2556#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002557 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002558 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2559 (char_u *)&p_swf, PV_SWF,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002560 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002561 {"swapsync", "sws", P_STRING|P_VI_DEF,
2562 (char_u *)&p_sws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002563 {(char_u *)"fsync", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002564 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002565 (char_u *)&p_swb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002566 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002567 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2568#ifdef FEAT_SYN_HL
2569 (char_u *)&p_smc, PV_SMC,
2570 {(char_u *)3000L, (char_u *)0L}
2571#else
2572 (char_u *)NULL, PV_NONE,
2573 {(char_u *)0L, (char_u *)0L}
2574#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002575 SCRIPTID_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002576 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577#ifdef FEAT_SYN_HL
2578 (char_u *)&p_syn, PV_SYN,
2579 {(char_u *)"", (char_u *)0L}
2580#else
2581 (char_u *)NULL, PV_NONE,
2582 {(char_u *)0L, (char_u *)0L}
2583#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002584 SCRIPTID_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002585 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2586#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002587 (char_u *)&p_tal, PV_NONE,
2588#else
2589 (char_u *)NULL, PV_NONE,
2590#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002591 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002592 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
2593#ifdef FEAT_WINDOWS
2594 (char_u *)&p_tpm, PV_NONE,
2595#else
2596 (char_u *)NULL, PV_NONE,
2597#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002598 {(char_u *)10L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002599 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2600 (char_u *)&p_ts, PV_TS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002601 {(char_u *)8L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2603 (char_u *)&p_tbs, PV_NONE,
2604#ifdef VMS /* binary searching doesn't appear to work on VMS */
2605 {(char_u *)0L, (char_u *)0L}
2606#else
2607 {(char_u *)TRUE, (char_u *)0L}
2608#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002609 SCRIPTID_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002610 {"tagcase", "tc", P_STRING|P_VIM,
2611 (char_u *)&p_tc, PV_TC,
2612 {(char_u *)"followic", (char_u *)"followic"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002613 {"taglength", "tl", P_NUM|P_VI_DEF,
2614 (char_u *)&p_tl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002615 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616 {"tagrelative", "tr", P_BOOL|P_VIM,
2617 (char_u *)&p_tr, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002618 {(char_u *)FALSE, (char_u *)TRUE} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002619 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002620 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 {
2622#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2623 (char_u *)"./tags,./TAGS,tags,TAGS",
2624#else
2625 (char_u *)"./tags,tags",
2626#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002627 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002628 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2629 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002630 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002631#if defined(DYNAMIC_TCL)
Bram Moolenaara6e42502016-04-20 16:19:52 +02002632 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002633 (char_u *)&p_tcldll, PV_NONE,
2634 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
2635 SCRIPTID_INIT},
2636#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2638 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002639 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2641#ifdef FEAT_ARABIC
2642 (char_u *)&p_tbidi, PV_NONE,
2643#else
2644 (char_u *)NULL, PV_NONE,
2645#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002646 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
2648#ifdef FEAT_MBYTE
2649 (char_u *)&p_tenc, PV_NONE,
2650 {(char_u *)"", (char_u *)0L}
2651#else
2652 (char_u *)NULL, PV_NONE,
2653 {(char_u *)0L, (char_u *)0L}
2654#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002655 SCRIPTID_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002656 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2657#ifdef FEAT_TERMGUICOLORS
2658 (char_u *)&p_tgc, PV_NONE,
2659 {(char_u *)FALSE, (char_u *)FALSE}
2660#else
2661 (char_u*)NULL, PV_NONE,
2662 {(char_u *)FALSE, (char_u *)FALSE}
2663#endif
2664 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002665 {"terse", NULL, P_BOOL|P_VI_DEF,
2666 (char_u *)&p_terse, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002667 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {"textauto", "ta", P_BOOL|P_VIM,
2669 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002670 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
2671 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2673 (char_u *)&p_tx, PV_TX,
2674 {
2675#ifdef USE_CRNL
2676 (char_u *)TRUE,
2677#else
2678 (char_u *)FALSE,
2679#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002680 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002681 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 (char_u *)&p_tw, PV_TW,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002683 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002684 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002686 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687#else
2688 (char_u *)NULL, PV_NONE,
2689#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002690 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2692 (char_u *)&p_to, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002693 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 {"timeout", "to", P_BOOL|P_VI_DEF,
2695 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002696 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2698 (char_u *)&p_tm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002699 {(char_u *)1000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002700 {"title", NULL, P_BOOL|P_VI_DEF,
2701#ifdef FEAT_TITLE
2702 (char_u *)&p_title, PV_NONE,
2703#else
2704 (char_u *)NULL, PV_NONE,
2705#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002706 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002707 {"titlelen", NULL, P_NUM|P_VI_DEF,
2708#ifdef FEAT_TITLE
2709 (char_u *)&p_titlelen, PV_NONE,
2710#else
2711 (char_u *)NULL, PV_NONE,
2712#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002713 {(char_u *)85L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002714 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002715#ifdef FEAT_TITLE
2716 (char_u *)&p_titleold, PV_NONE,
2717 {(char_u *)N_("Thanks for flying Vim"),
2718 (char_u *)0L}
2719#else
2720 (char_u *)NULL, PV_NONE,
2721 {(char_u *)0L, (char_u *)0L}
2722#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002723 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002724 {"titlestring", NULL, P_STRING|P_VI_DEF,
2725#ifdef FEAT_TITLE
2726 (char_u *)&p_titlestring, PV_NONE,
2727#else
2728 (char_u *)NULL, PV_NONE,
2729#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002731#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002732 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002733 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002734 {(char_u *)"icons,tooltips", (char_u *)0L}
2735 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002736#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02002737#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002738 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
2739 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002740 {(char_u *)"small", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002741#endif
2742 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2743 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002744 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2746 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002747 {(char_u *)-1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002748 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2749 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002750 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2752 (char_u *)&p_tf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002753 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2755#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2756 (char_u *)&p_ttym, PV_NONE,
2757#else
2758 (char_u *)NULL, PV_NONE,
2759#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002760 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2762 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002763 {(char_u *)999L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2765 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002767 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2768 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002769#ifdef FEAT_PERSISTENT_UNDO
2770 (char_u *)&p_udir, PV_NONE,
2771 {(char_u *)".", (char_u *)0L}
2772#else
2773 (char_u *)NULL, PV_NONE,
2774 {(char_u *)0L, (char_u *)0L}
2775#endif
2776 SCRIPTID_INIT},
2777 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2778#ifdef FEAT_PERSISTENT_UNDO
2779 (char_u *)&p_udf, PV_UDF,
2780#else
2781 (char_u *)NULL, PV_NONE,
2782#endif
2783 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002785 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002787#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 (char_u *)1000L,
2789#else
2790 (char_u *)100L,
2791#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002792 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002793 {"undoreload", "ur", P_NUM|P_VI_DEF,
2794 (char_u *)&p_ur, PV_NONE,
2795 { (char_u *)10000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796 {"updatecount", "uc", P_NUM|P_VI_DEF,
2797 (char_u *)&p_uc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002798 {(char_u *)200L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"updatetime", "ut", P_NUM|P_VI_DEF,
2800 (char_u *)&p_ut, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002801 {(char_u *)4000L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"verbose", "vbs", P_NUM|P_VI_DEF,
2803 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002804 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002805 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2806 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002807 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002808 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2809#ifdef FEAT_SESSION
2810 (char_u *)&p_vdir, PV_NONE,
2811 {(char_u *)DFLT_VDIR, (char_u *)0L}
2812#else
2813 (char_u *)NULL, PV_NONE,
2814 {(char_u *)0L, (char_u *)0L}
2815#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002816 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002817 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818#ifdef FEAT_SESSION
2819 (char_u *)&p_vop, PV_NONE,
2820 {(char_u *)"folds,options,cursor", (char_u *)0L}
2821#else
2822 (char_u *)NULL, PV_NONE,
2823 {(char_u *)0L, (char_u *)0L}
2824#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002825 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002826 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827#ifdef FEAT_VIMINFO
2828 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002829#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002830 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831#else
2832# ifdef AMIGA
2833 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002834 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002836 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837# endif
2838#endif
2839#else
2840 (char_u *)NULL, PV_NONE,
2841 {(char_u *)0L, (char_u *)0L}
2842#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002843 SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002844 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2845 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846#ifdef FEAT_VIRTUALEDIT
2847 (char_u *)&p_ve, PV_NONE,
2848 {(char_u *)"", (char_u *)""}
2849#else
2850 (char_u *)NULL, PV_NONE,
2851 {(char_u *)0L, (char_u *)0L}
2852#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002853 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002854 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2855 (char_u *)&p_vb, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002856 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002857 {"w300", NULL, P_NUM|P_VI_DEF,
2858 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002859 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"w1200", NULL, P_NUM|P_VI_DEF,
2861 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002862 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"w9600", NULL, P_NUM|P_VI_DEF,
2864 (char_u *)NULL, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002865 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"warn", NULL, P_BOOL|P_VI_DEF,
2867 (char_u *)&p_warn, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002868 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002869 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2870 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002871 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002872 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002873 (char_u *)&p_ww, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002874 {(char_u *)"", (char_u *)"b,s"} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 {"wildchar", "wc", P_NUM|P_VIM,
2876 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002877 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
2878 SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002879 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002881 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002882 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883#ifdef FEAT_WILDIGN
2884 (char_u *)&p_wig, PV_NONE,
2885#else
2886 (char_u *)NULL, PV_NONE,
2887#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002888 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002889 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2890 (char_u *)&p_wic, PV_NONE,
2891 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002892 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2893#ifdef FEAT_WILDMENU
2894 (char_u *)&p_wmnu, PV_NONE,
2895#else
2896 (char_u *)NULL, PV_NONE,
2897#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002898 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002899 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002900 (char_u *)&p_wim, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002901 {(char_u *)"full", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002902 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2903#ifdef FEAT_CMDL_COMPL
2904 (char_u *)&p_wop, PV_NONE,
2905 {(char_u *)"", (char_u *)0L}
2906#else
2907 (char_u *)NULL, PV_NONE,
2908 {(char_u *)NULL, (char_u *)0L}
2909#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002910 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
2912#ifdef FEAT_WAK
2913 (char_u *)&p_wak, PV_NONE,
2914 {(char_u *)"menu", (char_u *)0L}
2915#else
2916 (char_u *)NULL, PV_NONE,
2917 {(char_u *)NULL, (char_u *)0L}
2918#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002919 SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002920 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00002921 (char_u *)&p_window, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002922 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923 {"winheight", "wh", P_NUM|P_VI_DEF,
2924#ifdef FEAT_WINDOWS
2925 (char_u *)&p_wh, PV_NONE,
2926#else
2927 (char_u *)NULL, PV_NONE,
2928#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002929 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002930 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002931#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932 (char_u *)VAR_WIN, PV_WFH,
2933#else
2934 (char_u *)NULL, PV_NONE,
2935#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002936 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002937 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002938#ifdef FEAT_WINDOWS
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00002939 (char_u *)VAR_WIN, PV_WFW,
2940#else
2941 (char_u *)NULL, PV_NONE,
2942#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002943 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944 {"winminheight", "wmh", P_NUM|P_VI_DEF,
2945#ifdef FEAT_WINDOWS
2946 (char_u *)&p_wmh, PV_NONE,
2947#else
2948 (char_u *)NULL, PV_NONE,
2949#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002950 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002952#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953 (char_u *)&p_wmw, PV_NONE,
2954#else
2955 (char_u *)NULL, PV_NONE,
2956#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002957 {(char_u *)1L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar44a2f922016-03-19 22:11:51 +01002959#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 (char_u *)&p_wiw, PV_NONE,
2961#else
2962 (char_u *)NULL, PV_NONE,
2963#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002964 {(char_u *)20L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
2966 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002967 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002968 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
2969 (char_u *)&p_wm, PV_WM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002970 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
2972 (char_u *)&p_ws, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002973 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 {"write", NULL, P_BOOL|P_VI_DEF,
2975 (char_u *)&p_write, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002976 {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 {"writeany", "wa", P_BOOL|P_VI_DEF,
2978 (char_u *)&p_wa, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002979 {(char_u *)FALSE, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
2981 (char_u *)&p_wb, PV_NONE,
2982 {
2983#ifdef FEAT_WRITEBACKUP
2984 (char_u *)TRUE,
2985#else
2986 (char_u *)FALSE,
2987#endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002988 (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 {"writedelay", "wd", P_NUM|P_VI_DEF,
2990 (char_u *)&p_wd, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002991 {(char_u *)0L, (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992
2993/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002994#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 (char_u *)&vvv, PV_NONE, \
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002996 {(char_u *)"", (char_u *)0L} SCRIPTID_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002997
2998 p_term("t_AB", T_CAB)
2999 p_term("t_AF", T_CAF)
3000 p_term("t_AL", T_CAL)
3001 p_term("t_al", T_AL)
3002 p_term("t_bc", T_BC)
3003 p_term("t_cd", T_CD)
3004 p_term("t_ce", T_CE)
3005 p_term("t_cl", T_CL)
3006 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003007 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 p_term("t_Co", T_CCO)
3009 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003010 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 p_term("t_cs", T_CS)
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003012#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003013 p_term("t_CV", T_CSV)
3014#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 p_term("t_da", T_DA)
3016 p_term("t_db", T_DB)
3017 p_term("t_DL", T_CDL)
3018 p_term("t_dl", T_DL)
Bram Moolenaare5401222015-06-25 19:16:56 +02003019 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 p_term("t_fs", T_FS)
3021 p_term("t_IE", T_CIE)
3022 p_term("t_IS", T_CIS)
3023 p_term("t_ke", T_KE)
3024 p_term("t_ks", T_KS)
3025 p_term("t_le", T_LE)
3026 p_term("t_mb", T_MB)
3027 p_term("t_md", T_MD)
3028 p_term("t_me", T_ME)
3029 p_term("t_mr", T_MR)
3030 p_term("t_ms", T_MS)
3031 p_term("t_nd", T_ND)
3032 p_term("t_op", T_OP)
Bram Moolenaare5401222015-06-25 19:16:56 +02003033 p_term("t_RB", T_RBG)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 p_term("t_RI", T_CRI)
3035 p_term("t_RV", T_CRV)
3036 p_term("t_Sb", T_CSB)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003038 p_term("t_Sf", T_CSF)
3039 p_term("t_SI", T_CSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003041 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 p_term("t_sr", T_SR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043 p_term("t_te", T_TE)
3044 p_term("t_ti", T_TI)
Bram Moolenaare5401222015-06-25 19:16:56 +02003045 p_term("t_ts", T_TS)
3046 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 p_term("t_ue", T_UE)
3048 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003049 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 p_term("t_vb", T_VB)
3051 p_term("t_ve", T_VE)
3052 p_term("t_vi", T_VI)
3053 p_term("t_vs", T_VS)
3054 p_term("t_WP", T_CWP)
3055 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003056 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 p_term("t_xs", T_XS)
3058 p_term("t_ZH", T_CZH)
3059 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003060 p_term("t_8f", T_8F)
3061 p_term("t_8b", T_8B)
Bram Moolenaarec2da362017-01-21 20:04:22 +01003062 p_term("t_BE", T_BE)
3063 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064
3065/* terminal key codes are not in here */
3066
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003067 /* end marker */
3068 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCRIPTID_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069};
3070
3071#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3072
3073#ifdef FEAT_MBYTE
3074static char *(p_ambw_values[]) = {"single", "double", NULL};
3075#endif
3076static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003077static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003079#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003080static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003081#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003082#ifdef FEAT_CMDL_COMPL
3083static char *(p_wop_values[]) = {"tagfile", NULL};
3084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085#ifdef FEAT_WAK
3086static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3087#endif
3088static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3090static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092#ifdef FEAT_BROWSE
3093static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3094#endif
3095#ifdef FEAT_SCROLLBIND
3096static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
3097#endif
Bram Moolenaar57657d82006-04-21 22:12:41 +00003098static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar44a2f922016-03-19 22:11:51 +01003099#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
3101#endif
3102#if defined(FEAT_QUICKFIX)
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003103# ifdef FEAT_AUTOCMD
3104static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "acwrite", NULL};
3105# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003106static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", NULL};
Bram Moolenaar21cf8232004-07-16 20:18:37 +00003107# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003108static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
3109#endif
3110static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3111#ifdef FEAT_FOLDING
3112static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003113# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003115# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116 NULL};
3117static char *(p_fcl_values[]) = {"all", NULL};
3118#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003119#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003120static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003121#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003122#ifdef FEAT_SIGNS
3123static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003126static void set_option_default(int, int opt_flags, int compatible);
3127static void set_options_default(int opt_flags);
3128static char_u *term_bg_default(void);
3129static void did_set_option(int opt_idx, int opt_flags, int new_value);
3130static char_u *illegal_char(char_u *, int);
3131static int string_to_key(char_u *arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003132#ifdef FEAT_CMDWIN
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003133static char_u *check_cedit(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134#endif
3135#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003136static void did_set_title(int icon);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003137#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003138static char_u *option_expand(int opt_idx, char_u *val);
3139static void didset_options(void);
3140static void didset_options2(void);
3141static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003142#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003143static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003144#else
3145# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3146#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003147static void set_string_option_global(int opt_idx, char_u **varp);
3148static char_u *set_string_option(int opt_idx, char_u *value, int opt_flags);
3149static char_u *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char_u *errbuf, int opt_flags);
3150static char_u *set_chars_option(char_u **varp);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003151#ifdef FEAT_SYN_HL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003152static int int_cmp(const void *a, const void *b);
Bram Moolenaar1a384422010-07-14 19:53:30 +02003153#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154#ifdef FEAT_CLIPBOARD
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003155static char_u *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003157#ifdef FEAT_SPELL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003158static char_u *did_set_spell_option(int is_spellfile);
3159static char_u *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003160#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003161#ifdef FEAT_EVAL
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003162static void set_option_scriptID_idx(int opt_idx, int opt_flags, int id);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003163#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003164static char_u *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3165static char_u *set_num_option(int opt_idx, char_u *varp, long value, char_u *errbuf, size_t errbuflen, int opt_flags);
3166static void check_redraw(long_u flags);
3167static int findoption(char_u *);
3168static int find_key_option(char_u *);
3169static void showoptions(int all, int opt_flags);
3170static int optval_default(struct vimoption *, char_u *varp);
3171static void showoneopt(struct vimoption *, int opt_flags);
3172static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3173static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3174static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3175static int istermoption(struct vimoption *);
3176static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3177static char_u *get_varp(struct vimoption *);
3178static void option_value2string(struct vimoption *, int opt_flags);
3179static void check_winopt(winopt_T *wop);
3180static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003182static void langmap_init(void);
3183static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003184#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003185static void paste_option_changed(void);
3186static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003188static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003190static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3191static int check_opt_strings(char_u *val, char **values, int);
3192static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003193#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003194static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003195#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196
3197/*
3198 * Initialize the options, first part.
3199 *
3200 * Called only once from main(), just after creating the first buffer.
3201 */
3202 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003203set_init_1(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204{
3205 char_u *p;
3206 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003207 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208
3209#ifdef FEAT_LANGMAP
3210 langmap_init();
3211#endif
3212
3213 /* Be Vi compatible by default */
3214 p_cp = TRUE;
3215
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003216 /* Use POSIX compatibility when $VIM_POSIX is set. */
3217 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003218 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003219 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003220 set_string_default("shm", (char_u *)"A");
3221 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003222
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223 /*
3224 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003225 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003227 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003228#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003229 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003231 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003232# endif
3233#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003234 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003235 set_string_default("sh", p);
3236
3237#ifdef FEAT_WILDIGN
3238 /*
3239 * Set the default for 'backupskip' to include environment variables for
3240 * temp files.
3241 */
3242 {
3243# ifdef UNIX
3244 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3245# else
3246 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3247# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003248 int len;
3249 garray_T ga;
3250 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251
3252 ga_init2(&ga, 1, 100);
3253 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3254 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003255 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256# ifdef UNIX
3257 if (*names[n] == NUL)
3258 p = (char_u *)"/tmp";
3259 else
3260# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003261 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003262 if (p != NULL && *p != NUL)
3263 {
3264 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003265 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003266 if (ga_grow(&ga, len) == OK)
3267 {
3268 if (ga.ga_len > 0)
3269 STRCAT(ga.ga_data, ",");
3270 STRCAT(ga.ga_data, p);
3271 add_pathsep(ga.ga_data);
3272 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003273 ga.ga_len += len;
3274 }
3275 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003276 if (mustfree)
3277 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278 }
3279 if (ga.ga_data != NULL)
3280 {
3281 set_string_default("bsk", ga.ga_data);
3282 vim_free(ga.ga_data);
3283 }
3284 }
3285#endif
3286
3287 /*
3288 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3289 */
3290 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003291 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003293#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3294 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3295#endif
3296 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003297#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003298 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003299 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#else
3301# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003302 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003303 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003304# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003305 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306# endif
3307#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003308 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003309 opt_idx = findoption((char_u *)"maxmem");
3310 if (opt_idx >= 0)
3311 {
3312#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003313 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3314 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003315#endif
3316 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3317 }
3318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003319 }
3320
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321#ifdef FEAT_SEARCHPATH
3322 {
3323 char_u *cdpath;
3324 char_u *buf;
3325 int i;
3326 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003327 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328
3329 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003330 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331 if (cdpath != NULL)
3332 {
3333 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3334 if (buf != NULL)
3335 {
3336 buf[0] = ','; /* start with ",", current dir first */
3337 j = 1;
3338 for (i = 0; cdpath[i] != NUL; ++i)
3339 {
3340 if (vim_ispathlistsep(cdpath[i]))
3341 buf[j++] = ',';
3342 else
3343 {
3344 if (cdpath[i] == ' ' || cdpath[i] == ',')
3345 buf[j++] = '\\';
3346 buf[j++] = cdpath[i];
3347 }
3348 }
3349 buf[j] = NUL;
3350 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003351 if (opt_idx >= 0)
3352 {
3353 options[opt_idx].def_val[VI_DEFAULT] = buf;
3354 options[opt_idx].flags |= P_DEF_ALLOCED;
3355 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003356 else
3357 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003359 if (mustfree)
3360 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361 }
3362 }
3363#endif
3364
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003365#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366 /* Set print encoding on platforms that don't default to latin1 */
3367 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003368# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369 (char_u *)"cp1252"
3370# else
3371# ifdef VMS
3372 (char_u *)"dec-mcs"
3373# else
3374# ifdef EBCDIC
3375 (char_u *)"ebcdic-uk"
3376# else
3377# ifdef MAC
3378 (char_u *)"mac-roman"
3379# else /* HPUX */
3380 (char_u *)"hp-roman8"
3381# endif
3382# endif
3383# endif
3384# endif
3385 );
3386#endif
3387
3388#ifdef FEAT_POSTSCRIPT
3389 /* 'printexpr' must be allocated to be able to evaluate it. */
3390 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003391# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003392 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393# else
3394# ifdef VMS
3395 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3396
3397# else
3398 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3399# endif
3400# endif
3401 );
3402#endif
3403
3404 /*
3405 * Set all the options (except the terminal options) to their default
3406 * value. Also set the global value for local options.
3407 */
3408 set_options_default(0);
3409
3410#ifdef FEAT_GUI
3411 if (found_reverse_arg)
3412 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3413#endif
3414
3415 curbuf->b_p_initialized = TRUE;
3416 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003417 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418 check_buf_options(curbuf);
3419 check_win_options(curwin);
3420 check_options();
3421
3422 /* Must be before option_expand(), because that one needs vim_isIDc() */
3423 didset_options();
3424
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003425#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003426 /* Use the current chartab for the generic chartab. This is not in
3427 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003428 init_spell_chartab();
3429#endif
3430
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431 /*
3432 * Expand environment variables and things like "~" for the defaults.
3433 * If option_expand() returns non-NULL the variable is expanded. This can
3434 * only happen for non-indirect options.
3435 * Also set the default to the expanded value, so ":set" does not list
3436 * them.
3437 * Don't set the P_ALLOCED flag, because we don't want to free the
3438 * default.
3439 */
3440 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3441 {
3442 if ((options[opt_idx].flags & P_GETTEXT)
3443 && options[opt_idx].var != NULL)
3444 p = (char_u *)_(*(char **)options[opt_idx].var);
3445 else
3446 p = option_expand(opt_idx, NULL);
3447 if (p != NULL && (p = vim_strsave(p)) != NULL)
3448 {
3449 *(char_u **)options[opt_idx].var = p;
3450 /* VIMEXP
3451 * Defaults for all expanded options are currently the same for Vi
3452 * and Vim. When this changes, add some code here! Also need to
3453 * split P_DEF_ALLOCED in two.
3454 */
3455 if (options[opt_idx].flags & P_DEF_ALLOCED)
3456 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3457 options[opt_idx].def_val[VI_DEFAULT] = p;
3458 options[opt_idx].flags |= P_DEF_ALLOCED;
3459 }
3460 }
3461
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462 save_file_ff(curbuf); /* Buffer is unchanged */
3463
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464#if defined(FEAT_ARABIC)
3465 /* Detect use of mlterm.
3466 * Mlterm is a terminal emulator akin to xterm that has some special
3467 * abilities (bidi namely).
3468 * NOTE: mlterm's author is being asked to 'set' a variable
3469 * instead of an environment variable due to inheritance.
3470 */
3471 if (mch_getenv((char_u *)"MLTERM") != NULL)
3472 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3473#endif
3474
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003475 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003476
3477#ifdef FEAT_MBYTE
3478# if defined(WIN3264) && defined(FEAT_GETTEXT)
3479 /*
3480 * If $LANG isn't set, try to get a good value for it. This makes the
3481 * right language be used automatically. Don't do this for English.
3482 */
3483 if (mch_getenv((char_u *)"LANG") == NULL)
3484 {
3485 char buf[20];
3486
3487 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3488 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3489 * only the first two. */
3490 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3491 (LPTSTR)buf, 20);
3492 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3493 {
3494 /* There are a few exceptions (probably more) */
3495 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3496 STRCPY(buf, "zh_TW");
3497 else if (STRNICMP(buf, "chs", 3) == 0
3498 || STRNICMP(buf, "zhc", 3) == 0)
3499 STRCPY(buf, "zh_CN");
3500 else if (STRNICMP(buf, "jp", 2) == 0)
3501 STRCPY(buf, "ja");
3502 else
3503 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003504 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003505 }
3506 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003507# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003508# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003509 /* Moved to os_mac_conv.c to avoid dependency problems. */
3510 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003511# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003512# endif
3513
3514 /* enc_locale() will try to find the encoding of the current locale. */
3515 p = enc_locale();
3516 if (p != NULL)
3517 {
3518 char_u *save_enc;
3519
3520 /* Try setting 'encoding' and check if the value is valid.
3521 * If not, go back to the default "latin1". */
3522 save_enc = p_enc;
3523 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003524 if (STRCMP(p_enc, "gb18030") == 0)
3525 {
3526 /* We don't support "gb18030", but "cp936" is a good substitute
3527 * for practical purposes, thus use that. It's not an alias to
3528 * still support conversion between gb18030 and utf-8. */
3529 p_enc = vim_strsave((char_u *)"cp936");
3530 vim_free(p);
3531 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003532 if (mb_init() == NULL)
3533 {
3534 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003535 if (opt_idx >= 0)
3536 {
3537 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3538 options[opt_idx].flags |= P_DEF_ALLOCED;
3539 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003540
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003541#if defined(MSWIN) || defined(MACOS) || defined(VMS)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003542 if (STRCMP(p_enc, "latin1") == 0
3543# ifdef FEAT_MBYTE
3544 || enc_utf8
3545# endif
3546 )
3547 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003548 /* Adjust the default for 'isprint' and 'iskeyword' to match
3549 * latin1. Also set the defaults for when 'nocompatible' is
3550 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003551 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003552 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003553 set_string_option_direct((char_u *)"isk", -1,
3554 ISK_LATIN1, OPT_FREE, SID_NONE);
3555 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003556 if (opt_idx >= 0)
3557 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003558 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003559 if (opt_idx >= 0)
3560 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003561 (void)init_chartab();
3562 }
3563#endif
3564
Bram Moolenaar071d4272004-06-13 20:20:40 +00003565# if defined(WIN3264) && !defined(FEAT_GUI)
3566 /* Win32 console: When GetACP() returns a different value from
3567 * GetConsoleCP() set 'termencoding'. */
3568 if (GetACP() != GetConsoleCP())
3569 {
3570 char buf[50];
3571
3572 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3573 p_tenc = vim_strsave((char_u *)buf);
3574 if (p_tenc != NULL)
3575 {
3576 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003577 if (opt_idx >= 0)
3578 {
3579 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3580 options[opt_idx].flags |= P_DEF_ALLOCED;
3581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582 convert_setup(&input_conv, p_tenc, p_enc);
3583 convert_setup(&output_conv, p_enc, p_tenc);
3584 }
3585 else
3586 p_tenc = empty_option;
3587 }
3588# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003589# if defined(WIN3264) && defined(FEAT_MBYTE)
3590 /* $HOME may have characters in active code page. */
3591 init_homedir();
3592# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003593 }
3594 else
3595 {
3596 vim_free(p_enc);
3597 p_enc = save_enc;
3598 }
3599 }
3600#endif
3601
3602#ifdef FEAT_MULTI_LANG
3603 /* Set the default for 'helplang'. */
3604 set_helplang_default(get_mess_lang());
3605#endif
3606}
3607
3608/*
3609 * Set an option to its default value.
3610 * This does not take care of side effects!
3611 */
3612 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003613set_option_default(
3614 int opt_idx,
3615 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3616 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003617{
3618 char_u *varp; /* pointer to variable for current option */
3619 int dvi; /* index in def_val[] */
3620 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003621 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3623
3624 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3625 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003626 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627 {
3628 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3629 if (flags & P_STRING)
3630 {
3631 /* Use set_string_option_direct() for local options to handle
3632 * freeing and allocating the value. */
3633 if (options[opt_idx].indir != PV_NONE)
3634 set_string_option_direct(NULL, opt_idx,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003635 options[opt_idx].def_val[dvi], opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 else
3637 {
3638 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3639 free_string_option(*(char_u **)(varp));
3640 *(char_u **)varp = options[opt_idx].def_val[dvi];
3641 options[opt_idx].flags &= ~P_ALLOCED;
3642 }
3643 }
3644 else if (flags & P_NUM)
3645 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003646 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003647 win_comp_scroll(curwin);
3648 else
3649 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003650 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003651 /* May also set global value for local option. */
3652 if (both)
3653 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3654 *(long *)varp;
3655 }
3656 }
3657 else /* P_BOOL */
3658 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003659 /* the cast to long is required for Manx C, long_i is needed for
3660 * MSVC */
3661 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003662#ifdef UNIX
3663 /* 'modeline' defaults to off for root */
3664 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3665 *(int *)varp = FALSE;
3666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003667 /* May also set global value for local option. */
3668 if (both)
3669 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3670 *(int *)varp;
3671 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003672
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003673 /* The default value is not insecure. */
3674 flagsp = insecure_flag(opt_idx, opt_flags);
3675 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003676 }
3677
3678#ifdef FEAT_EVAL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003679 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680#endif
3681}
3682
3683/*
3684 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003685 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686 */
3687 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003688set_options_default(
3689 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003690{
3691 int i;
3692#ifdef FEAT_WINDOWS
3693 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003694 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695#endif
3696
3697 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003698 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003699#if defined(FEAT_MBYTE) || defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003700 && (opt_flags == 0
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003701 || (TRUE
3702# if defined(FEAT_MBYTE)
3703 && options[i].var != (char_u *)&p_enc
3704# endif
3705# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003706 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003707 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003708# endif
3709 ))
Bram Moolenaar80606872015-08-25 21:27:35 +02003710#endif
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003711 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003712 set_option_default(i, opt_flags, p_cp);
3713
3714#ifdef FEAT_WINDOWS
3715 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003716 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003717 win_comp_scroll(wp);
3718#else
3719 win_comp_scroll(curwin);
3720#endif
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003721#ifdef FEAT_CINDENT
3722 parse_cino(curbuf);
3723#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003724}
3725
3726/*
3727 * Set the Vi-default value of a string option.
3728 * Used for 'sh', 'backupskip' and 'term'.
3729 */
3730 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003731set_string_default(char *name, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732{
3733 char_u *p;
3734 int opt_idx;
3735
3736 p = vim_strsave(val);
3737 if (p != NULL) /* we don't want a NULL */
3738 {
3739 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003740 if (opt_idx >= 0)
3741 {
3742 if (options[opt_idx].flags & P_DEF_ALLOCED)
3743 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3744 options[opt_idx].def_val[VI_DEFAULT] = p;
3745 options[opt_idx].flags |= P_DEF_ALLOCED;
3746 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003747 }
3748}
3749
3750/*
3751 * Set the Vi-default value of a number option.
3752 * Used for 'lines' and 'columns'.
3753 */
3754 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003755set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003756{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003757 int opt_idx;
3758
3759 opt_idx = findoption((char_u *)name);
3760 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003761 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762}
3763
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003764#if defined(EXITFREE) || defined(PROTO)
3765/*
3766 * Free all options.
3767 */
3768 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003769free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003770{
3771 int i;
3772
3773 for (i = 0; !istermoption(&options[i]); i++)
3774 {
3775 if (options[i].indir == PV_NONE)
3776 {
3777 /* global option: free value and default value. */
3778 if (options[i].flags & P_ALLOCED && options[i].var != NULL)
3779 free_string_option(*(char_u **)options[i].var);
3780 if (options[i].flags & P_DEF_ALLOCED)
3781 free_string_option(options[i].def_val[VI_DEFAULT]);
3782 }
3783 else if (options[i].var != VAR_WIN
3784 && (options[i].flags & P_STRING))
3785 /* buffer-local option: free global value */
3786 free_string_option(*(char_u **)options[i].var);
3787 }
3788}
3789#endif
3790
3791
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792/*
3793 * Initialize the options, part two: After getting Rows and Columns and
3794 * setting 'term'.
3795 */
3796 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003797set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003799 int idx;
3800
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 /*
3802 * 'scroll' defaults to half the window height. Note that this default is
3803 * wrong when the window height changes.
3804 */
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003805 set_number_default("scroll", (long)((long_u)Rows >> 1));
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003806 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003807 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003808 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 comp_col();
3810
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003811 /*
3812 * 'window' is only for backwards compatibility with Vi.
3813 * Default is Rows - 1.
3814 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003815 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003816 p_window = Rows - 1;
3817 set_number_default("window", Rows - 1);
3818
Bram Moolenaarf740b292006-02-16 22:11:02 +00003819 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003820#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003821 /*
3822 * If 'background' wasn't set by the user, try guessing the value,
3823 * depending on the terminal name. Only need to check for terminals
3824 * with a dark background, that can handle color.
3825 */
3826 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003827 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3828 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003830 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003831 /* don't mark it as set, when starting the GUI it may be
3832 * changed again */
3833 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 }
3835#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003836
3837#ifdef CURSOR_SHAPE
3838 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3839#endif
3840#ifdef FEAT_MOUSESHAPE
3841 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3842#endif
3843#ifdef FEAT_PRINTER
3844 (void)parse_printoptions(); /* parse 'printoptions' default value */
3845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846}
3847
3848/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003849 * Return "dark" or "light" depending on the kind of terminal.
3850 * This is just guessing! Recognized are:
3851 * "linux" Linux console
3852 * "screen.linux" Linux console with screen
3853 * "cygwin" Cygwin shell
3854 * "putty" Putty program
3855 * We also check the COLORFGBG environment variable, which is set by
3856 * rxvt and derivatives. This variable contains either two or three
3857 * values separated by semicolons; we want the last value in either
3858 * case. If this value is 0-6 or 8, our background is dark.
3859 */
3860 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003861term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003862{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003863#if defined(WIN3264)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003864 /* DOS console nearly always black */
3865 return (char_u *)"dark";
3866#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003867 char_u *p;
3868
Bram Moolenaarf740b292006-02-16 22:11:02 +00003869 if (STRCMP(T_NAME, "linux") == 0
3870 || STRCMP(T_NAME, "screen.linux") == 0
3871 || STRCMP(T_NAME, "cygwin") == 0
3872 || STRCMP(T_NAME, "putty") == 0
3873 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3874 && (p = vim_strrchr(p, ';')) != NULL
3875 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3876 && p[2] == NUL))
3877 return (char_u *)"dark";
3878 return (char_u *)"light";
3879#endif
3880}
3881
3882/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883 * Initialize the options, part three: After reading the .vimrc
3884 */
3885 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003886set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003888#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889/*
3890 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3891 * This is done after other initializations, where 'shell' might have been
3892 * set, but only if they have not been set before.
3893 */
3894 char_u *p;
3895 int idx_srr;
3896 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003897# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003898 int idx_sp;
3899 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003900# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003901
3902 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003903 if (idx_srr < 0)
3904 do_srr = FALSE;
3905 else
3906 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003907# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003908 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003909 if (idx_sp < 0)
3910 do_sp = FALSE;
3911 else
3912 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003913# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003914 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915 if (p != NULL)
3916 {
3917 /*
3918 * Default for p_sp is "| tee", for p_srr is ">".
3919 * For known shells it is changed here to include stderr.
3920 */
3921 if ( fnamecmp(p, "csh") == 0
3922 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003923# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 || fnamecmp(p, "csh.exe") == 0
3925 || fnamecmp(p, "tcsh.exe") == 0
3926# endif
3927 )
3928 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003929# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003930 if (do_sp)
3931 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003932# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003933 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003934# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003937 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3938 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003939# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003940 if (do_srr)
3941 {
3942 p_srr = (char_u *)">&";
3943 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3944 }
3945 }
3946 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003947 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003948 if ( fnamecmp(p, "sh") == 0
3949 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003950 || fnamecmp(p, "mksh") == 0
3951 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003953 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003955 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003956# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003957 || fnamecmp(p, "cmd") == 0
3958 || fnamecmp(p, "sh.exe") == 0
3959 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02003960 || fnamecmp(p, "mksh.exe") == 0
3961 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00003963 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 || fnamecmp(p, "bash.exe") == 0
3965 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003967 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003969# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 if (do_sp)
3971 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003972# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00003973 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003974# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003976# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
3978 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003979# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003980 if (do_srr)
3981 {
3982 p_srr = (char_u *)">%s 2>&1";
3983 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
3984 }
3985 }
3986 vim_free(p);
3987 }
3988#endif
3989
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003990#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01003992 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
3993 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003994 * This is done after other initializations, where 'shell' might have been
3995 * set, but only if they have not been set before. Default for p_shcf is
3996 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003997 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00003999 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004000 {
4001 int idx3;
4002
4003 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004004 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 {
4006 p_shcf = (char_u *)"-c";
4007 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4008 }
4009
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004010# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011 /* Somehow Win32 requires the quotes around the redirection too */
4012 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004013 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004014 {
4015 p_sxq = (char_u *)"\"";
4016 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4017 }
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004018# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004019 idx3 = findoption((char_u *)"shq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004020 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021 {
4022 p_shq = (char_u *)"\"";
4023 options[idx3].def_val[VI_DEFAULT] = p_shq;
4024 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004025# endif
4026 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004027 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4028 {
4029 int idx3;
4030
4031 /*
4032 * cmd.exe on Windows will strip the first and last double quote given
4033 * on the command line, e.g. most of the time things like:
4034 * cmd /c "my path/to/echo" "my args to echo"
4035 * become:
4036 * my path/to/echo" "my args to echo
4037 * when executed.
4038 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004039 * To avoid this, set shellxquote to surround the command in
4040 * parenthesis. This appears to make most commands work, without
4041 * breaking commands that worked previously, such as
4042 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004043 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004044 idx3 = findoption((char_u *)"sxq");
4045 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4046 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004047 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004048 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4049 }
4050
Bram Moolenaara64ba222012-02-12 23:23:31 +01004051 idx3 = findoption((char_u *)"shcf");
4052 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4053 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004054 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004055 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4056 }
4057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058#endif
4059
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004060 if (bufempty())
4061 {
4062 int idx_ffs = findoption((char_u *)"ffs");
4063
4064 /* Apply the first entry of 'fileformats' to the initial buffer. */
4065 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4066 set_fileformat(default_fileformat(), OPT_LOCAL);
4067 }
4068
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069#ifdef FEAT_TITLE
4070 set_title_defaults();
4071#endif
4072}
4073
4074#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4075/*
4076 * When 'helplang' is still at its default value, set it to "lang".
4077 * Only the first two characters of "lang" are used.
4078 */
4079 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004080set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081{
4082 int idx;
4083
4084 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4085 return;
4086 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004087 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 {
4089 if (options[idx].flags & P_ALLOCED)
4090 free_string_option(p_hlg);
4091 p_hlg = vim_strsave(lang);
4092 if (p_hlg == NULL)
4093 p_hlg = empty_option;
4094 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004095 {
4096 /* zh_CN becomes "cn", zh_TW becomes "tw". */
4097 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4098 {
4099 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4100 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4101 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004103 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 options[idx].flags |= P_ALLOCED;
4105 }
4106}
4107#endif
4108
4109#ifdef FEAT_GUI
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01004110static char_u *gui_bg_default(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111
4112 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004113gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114{
4115 if (gui_get_lightness(gui.back_pixel) < 127)
4116 return (char_u *)"dark";
4117 return (char_u *)"light";
4118}
4119
4120/*
4121 * Option initializations that can only be done after opening the GUI window.
4122 */
4123 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004124init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125{
4126 /* Set the 'background' option according to the lightness of the
4127 * background color, unless the user has set it already. */
4128 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4129 {
4130 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4131 highlight_changed();
4132 }
4133}
4134#endif
4135
4136#ifdef FEAT_TITLE
4137/*
4138 * 'title' and 'icon' only default to true if they have not been set or reset
4139 * in .vimrc and we can read the old value.
4140 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4141 * they can be reset. This reduces startup time when using X on a remote
4142 * machine.
4143 */
4144 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004145set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004146{
4147 int idx1;
4148 long val;
4149
4150 /*
4151 * If GUI is (going to be) used, we can always set the window title and
4152 * icon name. Saves a bit of time, because the X11 display server does
4153 * not need to be contacted.
4154 */
4155 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004156 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 {
4158#ifdef FEAT_GUI
4159 if (gui.starting || gui.in_use)
4160 val = TRUE;
4161 else
4162#endif
4163 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004164 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004165 p_title = val;
4166 }
4167 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004168 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 {
4170#ifdef FEAT_GUI
4171 if (gui.starting || gui.in_use)
4172 val = TRUE;
4173 else
4174#endif
4175 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004176 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004177 p_icon = val;
4178 }
4179}
4180#endif
4181
4182/*
4183 * Parse 'arg' for option settings.
4184 *
4185 * 'arg' may be IObuff, but only when no errors can be present and option
4186 * does not need to be expanded with option_expand().
4187 * "opt_flags":
4188 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004189 * OPT_GLOBAL for ":setglobal"
4190 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004191 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004192 * OPT_WINONLY to only set window-local options
4193 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194 *
4195 * returns FAIL if an error is detected, OK otherwise
4196 */
4197 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004198do_set(
4199 char_u *arg, /* option string (may be written to!) */
4200 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201{
4202 int opt_idx;
4203 char_u *errmsg;
4204 char_u errbuf[80];
4205 char_u *startarg;
4206 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4207 int nextchar; /* next non-white char after option name */
4208 int afterchar; /* character just after option name */
4209 int len;
4210 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004211 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004212 int key;
4213 long_u flags; /* flags for current option */
4214 char_u *varp = NULL; /* pointer to variable for current option */
4215 int did_show = FALSE; /* already showed one value */
4216 int adding; /* "opt+=arg" */
4217 int prepending; /* "opt^=arg" */
4218 int removing; /* "opt-=arg" */
4219 int cp_val = 0;
4220 char_u key_name[2];
4221
4222 if (*arg == NUL)
4223 {
4224 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004225 did_show = TRUE;
4226 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 }
4228
4229 while (*arg != NUL) /* loop to process all options */
4230 {
4231 errmsg = NULL;
4232 startarg = arg; /* remember for error message */
4233
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004234 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4235 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 {
4237 /*
4238 * ":set all" show all options.
4239 * ":set all&" set all options to their default value.
4240 */
4241 arg += 3;
4242 if (*arg == '&')
4243 {
4244 ++arg;
4245 /* Only for :set command set global value of local options. */
4246 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004247 didset_options();
4248 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004249 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004250 }
4251 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004252 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004253 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004254 did_show = TRUE;
4255 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004257 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004258 {
4259 showoptions(2, opt_flags);
4260 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004261 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262 arg += 7;
4263 }
4264 else
4265 {
4266 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004267 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268 {
4269 prefix = 0;
4270 arg += 2;
4271 }
4272 else if (STRNCMP(arg, "inv", 3) == 0)
4273 {
4274 prefix = 2;
4275 arg += 3;
4276 }
4277
4278 /* find end of name */
4279 key = 0;
4280 if (*arg == '<')
4281 {
4282 nextchar = 0;
4283 opt_idx = -1;
4284 /* look out for <t_>;> */
4285 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4286 len = 5;
4287 else
4288 {
4289 len = 1;
4290 while (arg[len] != NUL && arg[len] != '>')
4291 ++len;
4292 }
4293 if (arg[len] != '>')
4294 {
4295 errmsg = e_invarg;
4296 goto skip;
4297 }
4298 arg[len] = NUL; /* put NUL after name */
4299 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4300 opt_idx = findoption(arg + 1);
4301 arg[len++] = '>'; /* restore '>' */
4302 if (opt_idx == -1)
4303 key = find_key_option(arg + 1);
4304 }
4305 else
4306 {
4307 len = 0;
4308 /*
4309 * The two characters after "t_" may not be alphanumeric.
4310 */
4311 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4312 len = 4;
4313 else
4314 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4315 ++len;
4316 nextchar = arg[len];
4317 arg[len] = NUL; /* put NUL after name */
4318 opt_idx = findoption(arg);
4319 arg[len] = nextchar; /* restore nextchar */
4320 if (opt_idx == -1)
4321 key = find_key_option(arg);
4322 }
4323
4324 /* remember character after option name */
4325 afterchar = arg[len];
4326
4327 /* skip white space, allow ":set ai ?" */
4328 while (vim_iswhite(arg[len]))
4329 ++len;
4330
4331 adding = FALSE;
4332 prepending = FALSE;
4333 removing = FALSE;
4334 if (arg[len] != NUL && arg[len + 1] == '=')
4335 {
4336 if (arg[len] == '+')
4337 {
4338 adding = TRUE; /* "+=" */
4339 ++len;
4340 }
4341 else if (arg[len] == '^')
4342 {
4343 prepending = TRUE; /* "^=" */
4344 ++len;
4345 }
4346 else if (arg[len] == '-')
4347 {
4348 removing = TRUE; /* "-=" */
4349 ++len;
4350 }
4351 }
4352 nextchar = arg[len];
4353
4354 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4355 {
4356 errmsg = (char_u *)N_("E518: Unknown option");
4357 goto skip;
4358 }
4359
4360 if (opt_idx >= 0)
4361 {
4362 if (options[opt_idx].var == NULL) /* hidden option: skip */
4363 {
4364 /* Only give an error message when requesting the value of
4365 * a hidden option, ignore setting it. */
4366 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4367 && (!(options[opt_idx].flags & P_BOOL)
4368 || nextchar == '?'))
4369 errmsg = (char_u *)N_("E519: Option not supported");
4370 goto skip;
4371 }
4372
4373 flags = options[opt_idx].flags;
4374 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4375 }
4376 else
4377 {
4378 flags = P_STRING;
4379 if (key < 0)
4380 {
4381 key_name[0] = KEY2TERMCAP0(key);
4382 key_name[1] = KEY2TERMCAP1(key);
4383 }
4384 else
4385 {
4386 key_name[0] = KS_KEY;
4387 key_name[1] = (key & 0xff);
4388 }
4389 }
4390
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004391 /* Skip all options that are not window-local (used when showing
4392 * an already loaded buffer in a window). */
4393 if ((opt_flags & OPT_WINONLY)
4394 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4395 goto skip;
4396
Bram Moolenaara3227e22006-03-08 21:32:40 +00004397 /* Skip all options that are window-local (used for :vimgrep). */
4398 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4399 && options[opt_idx].var == VAR_WIN)
4400 goto skip;
4401
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004402 /* Disallow changing some options from modelines. */
4403 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004404 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004405 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004406 {
4407 errmsg = (char_u *)_("E520: Not allowed in a modeline");
4408 goto skip;
4409 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004410#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004411 /* In diff mode some options are overruled. This avoids that
4412 * 'foldmethod' becomes "marker" instead of "diff" and that
4413 * "wrap" gets set. */
4414 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004415 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004416 && (options[opt_idx].indir == PV_FDM
4417 || options[opt_idx].indir == PV_WRAP))
4418 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004420 }
4421
4422#ifdef HAVE_SANDBOX
4423 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004424 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 {
4426 errmsg = (char_u *)_(e_sandbox);
4427 goto skip;
4428 }
4429#endif
4430
4431 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4432 {
4433 arg += len;
4434 cp_val = p_cp;
4435 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4436 {
4437 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4438 {
4439 cp_val = FALSE;
4440 arg += 3;
4441 }
4442 else /* "opt&vi": set to Vi default */
4443 {
4444 cp_val = TRUE;
4445 arg += 2;
4446 }
4447 }
4448 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
4449 && arg[1] != NUL && !vim_iswhite(arg[1]))
4450 {
4451 errmsg = e_trailing;
4452 goto skip;
4453 }
4454 }
4455
4456 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004457 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4458 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004459 */
4460 if (nextchar == '?'
4461 || (prefix == 1
4462 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4463 && !(flags & P_BOOL)))
4464 {
4465 /*
4466 * print value
4467 */
4468 if (did_show)
4469 msg_putchar('\n'); /* cursor below last one */
4470 else
4471 {
4472 gotocmdline(TRUE); /* cursor at status line */
4473 did_show = TRUE; /* remember that we did a line */
4474 }
4475 if (opt_idx >= 0)
4476 {
4477 showoneopt(&options[opt_idx], opt_flags);
4478#ifdef FEAT_EVAL
4479 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004480 {
4481 /* Mention where the option was last set. */
4482 if (varp == options[opt_idx].var)
4483 last_set_msg(options[opt_idx].scriptID);
4484 else if ((int)options[opt_idx].indir & PV_WIN)
4485 last_set_msg(curwin->w_p_scriptID[
4486 (int)options[opt_idx].indir & PV_MASK]);
4487 else if ((int)options[opt_idx].indir & PV_BUF)
4488 last_set_msg(curbuf->b_p_scriptID[
4489 (int)options[opt_idx].indir & PV_MASK]);
4490 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004491#endif
4492 }
4493 else
4494 {
4495 char_u *p;
4496
4497 p = find_termcode(key_name);
4498 if (p == NULL)
4499 {
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004500 errmsg = (char_u *)N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004501 goto skip;
4502 }
4503 else
4504 (void)show_one_termcode(key_name, p, TRUE);
4505 }
4506 if (nextchar != '?'
4507 && nextchar != NUL && !vim_iswhite(afterchar))
4508 errmsg = e_trailing;
4509 }
4510 else
4511 {
4512 if (flags & P_BOOL) /* boolean */
4513 {
4514 if (nextchar == '=' || nextchar == ':')
4515 {
4516 errmsg = e_invarg;
4517 goto skip;
4518 }
4519
4520 /*
4521 * ":set opt!": invert
4522 * ":set opt&": reset to default value
4523 * ":set opt<": reset to global value
4524 */
4525 if (nextchar == '!')
4526 value = *(int *)(varp) ^ 1;
4527 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004528 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004529 ((flags & P_VI_DEF) || cp_val)
4530 ? VI_DEFAULT : VIM_DEFAULT];
4531 else if (nextchar == '<')
4532 {
4533 /* For 'autoread' -1 means to use global value. */
4534 if ((int *)varp == &curbuf->b_p_ar
4535 && opt_flags == OPT_LOCAL)
4536 value = -1;
4537 else
4538 value = *(int *)get_varp_scope(&(options[opt_idx]),
4539 OPT_GLOBAL);
4540 }
4541 else
4542 {
4543 /*
4544 * ":set invopt": invert
4545 * ":set opt" or ":set noopt": set or reset
4546 */
4547 if (nextchar != NUL && !vim_iswhite(afterchar))
4548 {
4549 errmsg = e_trailing;
4550 goto skip;
4551 }
4552 if (prefix == 2) /* inv */
4553 value = *(int *)(varp) ^ 1;
4554 else
4555 value = prefix;
4556 }
4557
4558 errmsg = set_bool_option(opt_idx, varp, (int)value,
4559 opt_flags);
4560 }
4561 else /* numeric or string */
4562 {
4563 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4564 || prefix != 1)
4565 {
4566 errmsg = e_invarg;
4567 goto skip;
4568 }
4569
4570 if (flags & P_NUM) /* numeric */
4571 {
4572 /*
4573 * Different ways to set a number option:
4574 * & set to default value
4575 * < set to global value
4576 * <xx> accept special key codes for 'wildchar'
4577 * c accept any non-digit for 'wildchar'
4578 * [-]0-9 set number
4579 * other error
4580 */
4581 ++arg;
4582 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004583 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004584 ((flags & P_VI_DEF) || cp_val)
4585 ? VI_DEFAULT : VIM_DEFAULT];
4586 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004587 {
4588 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4589 * use the global value. */
4590 if ((long *)varp == &curbuf->b_p_ul
4591 && opt_flags == OPT_LOCAL)
4592 value = NO_LOCAL_UNDOLEVEL;
4593 else
4594 value = *(long *)get_varp_scope(
4595 &(options[opt_idx]), OPT_GLOBAL);
4596 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004597 else if (((long *)varp == &p_wc
4598 || (long *)varp == &p_wcm)
4599 && (*arg == '<'
4600 || *arg == '^'
4601 || ((!arg[1] || vim_iswhite(arg[1]))
4602 && !VIM_ISDIGIT(*arg))))
4603 {
4604 value = string_to_key(arg);
4605 if (value == 0 && (long *)varp != &p_wcm)
4606 {
4607 errmsg = e_invarg;
4608 goto skip;
4609 }
4610 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004611 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4612 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004613 /* Allow negative (for 'undolevels'), octal and
4614 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004615 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4616 &value, NULL, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617 if (arg[i] != NUL && !vim_iswhite(arg[i]))
4618 {
4619 errmsg = e_invarg;
4620 goto skip;
4621 }
4622 }
4623 else
4624 {
4625 errmsg = (char_u *)N_("E521: Number required after =");
4626 goto skip;
4627 }
4628
4629 if (adding)
4630 value = *(long *)varp + value;
4631 if (prepending)
4632 value = *(long *)varp * value;
4633 if (removing)
4634 value = *(long *)varp - value;
4635 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004636 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004637 }
4638 else if (opt_idx >= 0) /* string */
4639 {
4640 char_u *save_arg = NULL;
4641 char_u *s = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004642 char_u *oldval = NULL; /* previous value if *varp */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004643 char_u *newval;
Bram Moolenaar53744302015-07-17 17:38:22 +02004644 char_u *origval = NULL;
4645#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
4646 char_u *saved_origval = NULL;
4647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004648 unsigned newlen;
4649 int comma;
4650 int bs;
4651 int new_value_alloced; /* new string option
4652 was allocated */
4653
4654 /* When using ":set opt=val" for a global option
4655 * with a local value the local value will be
4656 * reset, use the global value here. */
4657 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004658 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004659 varp = options[opt_idx].var;
4660
4661 /* The old value is kept until we are sure that the
4662 * new value is valid. */
4663 oldval = *(char_u **)varp;
4664 if (nextchar == '&') /* set to default val */
4665 {
4666 newval = options[opt_idx].def_val[
4667 ((flags & P_VI_DEF) || cp_val)
4668 ? VI_DEFAULT : VIM_DEFAULT];
4669 if ((char_u **)varp == &p_bg)
4670 {
4671 /* guess the value of 'background' */
4672#ifdef FEAT_GUI
4673 if (gui.in_use)
4674 newval = gui_bg_default();
4675 else
4676#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004677 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004678 }
4679
4680 /* expand environment variables and ~ (since the
4681 * default value was already expanded, only
4682 * required when an environment variable was set
4683 * later */
4684 if (newval == NULL)
4685 newval = empty_option;
4686 else
4687 {
4688 s = option_expand(opt_idx, newval);
4689 if (s == NULL)
4690 s = newval;
4691 newval = vim_strsave(s);
4692 }
4693 new_value_alloced = TRUE;
4694 }
4695 else if (nextchar == '<') /* set to global val */
4696 {
4697 newval = vim_strsave(*(char_u **)get_varp_scope(
4698 &(options[opt_idx]), OPT_GLOBAL));
4699 new_value_alloced = TRUE;
4700 }
4701 else
4702 {
4703 ++arg; /* jump to after the '=' or ':' */
4704
4705 /*
4706 * Set 'keywordprg' to ":help" if an empty
4707 * value was passed to :set by the user.
4708 * Misuse errbuf[] for the resulting string.
4709 */
4710 if (varp == (char_u *)&p_kp
4711 && (*arg == NUL || *arg == ' '))
4712 {
4713 STRCPY(errbuf, ":help");
4714 save_arg = arg;
4715 arg = errbuf;
4716 }
4717 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004718 * Convert 'backspace' number to string, for
4719 * adding, prepending and removing string.
4720 */
4721 else if (varp == (char_u *)&p_bs
4722 && VIM_ISDIGIT(**(char_u **)varp))
4723 {
4724 i = getdigits((char_u **)varp);
4725 switch (i)
4726 {
4727 case 0:
4728 *(char_u **)varp = empty_option;
4729 break;
4730 case 1:
4731 *(char_u **)varp = vim_strsave(
4732 (char_u *)"indent,eol");
4733 break;
4734 case 2:
4735 *(char_u **)varp = vim_strsave(
4736 (char_u *)"indent,eol,start");
4737 break;
4738 }
4739 vim_free(oldval);
4740 oldval = *(char_u **)varp;
4741 }
4742 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004743 * Convert 'whichwrap' number to string, for
4744 * backwards compatibility with Vim 3.0.
4745 * Misuse errbuf[] for the resulting string.
4746 */
4747 else if (varp == (char_u *)&p_ww
4748 && VIM_ISDIGIT(*arg))
4749 {
4750 *errbuf = NUL;
4751 i = getdigits(&arg);
4752 if (i & 1)
4753 STRCAT(errbuf, "b,");
4754 if (i & 2)
4755 STRCAT(errbuf, "s,");
4756 if (i & 4)
4757 STRCAT(errbuf, "h,l,");
4758 if (i & 8)
4759 STRCAT(errbuf, "<,>,");
4760 if (i & 16)
4761 STRCAT(errbuf, "[,],");
4762 if (*errbuf != NUL) /* remove trailing , */
4763 errbuf[STRLEN(errbuf) - 1] = NUL;
4764 save_arg = arg;
4765 arg = errbuf;
4766 }
4767 /*
4768 * Remove '>' before 'dir' and 'bdir', for
4769 * backwards compatibility with version 3.0
4770 */
4771 else if ( *arg == '>'
4772 && (varp == (char_u *)&p_dir
4773 || varp == (char_u *)&p_bdir))
4774 {
4775 ++arg;
4776 }
4777
4778 /* When setting the local value of a global
4779 * option, the old value may be the global value. */
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004780 if (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004781 && (opt_flags & OPT_LOCAL))
4782 origval = *(char_u **)get_varp(
4783 &options[opt_idx]);
4784 else
4785 origval = oldval;
4786
4787 /*
4788 * Copy the new string into allocated memory.
4789 * Can't use set_string_option_direct(), because
4790 * we need to remove the backslashes.
4791 */
4792 /* get a bit too much */
4793 newlen = (unsigned)STRLEN(arg) + 1;
4794 if (adding || prepending || removing)
4795 newlen += (unsigned)STRLEN(origval) + 1;
4796 newval = alloc(newlen);
4797 if (newval == NULL) /* out of mem, don't change */
4798 break;
4799 s = newval;
4800
4801 /*
4802 * Copy the string, skip over escaped chars.
4803 * For MS-DOS and WIN32 backslashes before normal
4804 * file name characters are not removed, and keep
4805 * backslash at start, for "\\machine\path", but
4806 * do remove it for "\\\\machine\\path".
4807 * The reverse is found in ExpandOldSetting().
4808 */
4809 while (*arg && !vim_iswhite(*arg))
4810 {
4811 if (*arg == '\\' && arg[1] != NUL
4812#ifdef BACKSLASH_IN_FILENAME
4813 && !((flags & P_EXPAND)
4814 && vim_isfilec(arg[1])
4815 && (arg[1] != '\\'
4816 || (s == newval
4817 && arg[2] != '\\')))
4818#endif
4819 )
4820 ++arg; /* remove backslash */
4821#ifdef FEAT_MBYTE
4822 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004823 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004824 {
4825 /* copy multibyte char */
4826 mch_memmove(s, arg, (size_t)i);
4827 arg += i;
4828 s += i;
4829 }
4830 else
4831#endif
4832 *s++ = *arg++;
4833 }
4834 *s = NUL;
4835
4836 /*
4837 * Expand environment variables and ~.
4838 * Don't do it when adding without inserting a
4839 * comma.
4840 */
4841 if (!(adding || prepending || removing)
4842 || (flags & P_COMMA))
4843 {
4844 s = option_expand(opt_idx, newval);
4845 if (s != NULL)
4846 {
4847 vim_free(newval);
4848 newlen = (unsigned)STRLEN(s) + 1;
4849 if (adding || prepending || removing)
4850 newlen += (unsigned)STRLEN(origval) + 1;
4851 newval = alloc(newlen);
4852 if (newval == NULL)
4853 break;
4854 STRCPY(newval, s);
4855 }
4856 }
4857
4858 /* locate newval[] in origval[] when removing it
4859 * and when adding to avoid duplicates */
4860 i = 0; /* init for GCC */
4861 if (removing || (flags & P_NODUP))
4862 {
4863 i = (int)STRLEN(newval);
4864 bs = 0;
4865 for (s = origval; *s; ++s)
4866 {
4867 if ((!(flags & P_COMMA)
4868 || s == origval
4869 || (s[-1] == ',' && !(bs & 1)))
4870 && STRNCMP(s, newval, i) == 0
4871 && (!(flags & P_COMMA)
4872 || s[i] == ','
4873 || s[i] == NUL))
4874 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004875 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004876 * even number of backslashes or a single
4877 * backslash preceded by a comma before it
4878 * is recognized as a separator */
4879 if ((s > origval + 1
4880 && s[-1] == '\\'
4881 && s[-2] != ',')
4882 || (s == origval + 1
4883 && s[-1] == '\\'))
4884
Bram Moolenaar071d4272004-06-13 20:20:40 +00004885 ++bs;
4886 else
4887 bs = 0;
4888 }
4889
4890 /* do not add if already there */
4891 if ((adding || prepending) && *s)
4892 {
4893 prepending = FALSE;
4894 adding = FALSE;
4895 STRCPY(newval, origval);
4896 }
4897 }
4898
4899 /* concatenate the two strings; add a ',' if
4900 * needed */
4901 if (adding || prepending)
4902 {
4903 comma = ((flags & P_COMMA) && *origval != NUL
4904 && *newval != NUL);
4905 if (adding)
4906 {
4907 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004908 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01004909 if (comma && i > 1
4910 && (flags & P_ONECOMMA) == P_ONECOMMA
4911 && origval[i - 1] == ','
4912 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02004913 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004914 mch_memmove(newval + i + comma, newval,
4915 STRLEN(newval) + 1);
4916 mch_memmove(newval, origval, (size_t)i);
4917 }
4918 else
4919 {
4920 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004921 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004922 }
4923 if (comma)
4924 newval[i] = ',';
4925 }
4926
4927 /* Remove newval[] from origval[]. (Note: "i" has
4928 * been set above and is used here). */
4929 if (removing)
4930 {
4931 STRCPY(newval, origval);
4932 if (*s)
4933 {
4934 /* may need to remove a comma */
4935 if (flags & P_COMMA)
4936 {
4937 if (s == origval)
4938 {
4939 /* include comma after string */
4940 if (s[i] == ',')
4941 ++i;
4942 }
4943 else
4944 {
4945 /* include comma before string */
4946 --s;
4947 ++i;
4948 }
4949 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00004950 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004951 }
4952 }
4953
4954 if (flags & P_FLAGLIST)
4955 {
4956 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004957 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004958 {
4959 /* if options have P_FLAGLIST and
4960 * P_ONECOMMA such as 'whichwrap' */
4961 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004962 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004963 if (*s != ',' && *(s + 1) == ','
4964 && vim_strchr(s + 2, *s) != NULL)
4965 {
4966 /* Remove the duplicated value and
4967 * the next comma. */
4968 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004969 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004971 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004972 else
4973 {
4974 if ((!(flags & P_COMMA) || *s != ',')
4975 && vim_strchr(s + 1, *s) != NULL)
4976 {
4977 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004978 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004979 }
4980 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01004981 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02004982 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004983 }
4984
4985 if (save_arg != NULL) /* number for 'whichwrap' */
4986 arg = save_arg;
4987 new_value_alloced = TRUE;
4988 }
4989
4990 /* Set the new value. */
4991 *(char_u **)(varp) = newval;
4992
Bram Moolenaar53744302015-07-17 17:38:22 +02004993#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004994 if (!starting
4995# ifdef FEAT_CRYPT
4996 && options[opt_idx].indir != PV_KEY
4997# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004998 && origval != NULL)
4999 /* origval may be freed by
5000 * did_set_string_option(), make a copy. */
5001 saved_origval = vim_strsave(origval);
5002#endif
5003
Bram Moolenaar071d4272004-06-13 20:20:40 +00005004 /* Handle side effects, and set the global value for
5005 * ":set" on local options. */
5006 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5007 new_value_alloced, oldval, errbuf, opt_flags);
5008
5009 /* If error detected, print the error message. */
5010 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005011 {
5012#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5013 vim_free(saved_origval);
5014#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005015 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005016 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005017#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5018 if (saved_origval != NULL)
5019 {
5020 char_u buf_type[7];
5021
5022 sprintf((char *)buf_type, "%s",
5023 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005024 set_vim_var_string(VV_OPTION_NEW,
5025 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005026 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5027 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5028 apply_autocmds(EVENT_OPTIONSET,
5029 (char_u *)options[opt_idx].fullname,
5030 NULL, FALSE, NULL);
5031 reset_v_option_vars();
5032 vim_free(saved_origval);
5033 }
5034#endif
5035
Bram Moolenaar071d4272004-06-13 20:20:40 +00005036 }
5037 else /* key code option */
5038 {
5039 char_u *p;
5040
5041 if (nextchar == '&')
5042 {
5043 if (add_termcap_entry(key_name, TRUE) == FAIL)
5044 errmsg = (char_u *)N_("E522: Not found in termcap");
5045 }
5046 else
5047 {
5048 ++arg; /* jump to after the '=' or ':' */
5049 for (p = arg; *p && !vim_iswhite(*p); ++p)
5050 if (*p == '\\' && p[1] != NUL)
5051 ++p;
5052 nextchar = *p;
5053 *p = NUL;
5054 add_termcode(key_name, arg, FALSE);
5055 *p = nextchar;
5056 }
5057 if (full_screen)
5058 ttest(FALSE);
5059 redraw_all_later(CLEAR);
5060 }
5061 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005062
Bram Moolenaar071d4272004-06-13 20:20:40 +00005063 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005064 did_set_option(opt_idx, opt_flags,
5065 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005066 }
5067
5068skip:
5069 /*
5070 * Advance to next argument.
5071 * - skip until a blank found, taking care of backslashes
5072 * - skip blanks
5073 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5074 */
5075 for (i = 0; i < 2 ; ++i)
5076 {
5077 while (*arg != NUL && !vim_iswhite(*arg))
5078 if (*arg++ == '\\' && *arg != NUL)
5079 ++arg;
5080 arg = skipwhite(arg);
5081 if (*arg != '=')
5082 break;
5083 }
5084 }
5085
5086 if (errmsg != NULL)
5087 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005088 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005089 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005090 if (i + (arg - startarg) < IOSIZE)
5091 {
5092 /* append the argument with the error */
5093 STRCAT(IObuff, ": ");
5094 mch_memmove(IObuff + i, startarg, (arg - startarg));
5095 IObuff[i + (arg - startarg)] = NUL;
5096 }
5097 /* make sure all characters are printable */
5098 trans_characters(IObuff, IOSIZE);
5099
5100 ++no_wait_return; /* wait_return done later */
5101 emsg(IObuff); /* show error highlighted */
5102 --no_wait_return;
5103
5104 return FAIL;
5105 }
5106
5107 arg = skipwhite(arg);
5108 }
5109
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005110theend:
5111 if (silent_mode && did_show)
5112 {
5113 /* After displaying option values in silent mode. */
5114 silent_mode = FALSE;
5115 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5116 msg_putchar('\n');
5117 cursor_on(); /* msg_start() switches it off */
5118 out_flush();
5119 silent_mode = TRUE;
5120 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5121 }
5122
Bram Moolenaar071d4272004-06-13 20:20:40 +00005123 return OK;
5124}
5125
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005126/*
5127 * Call this when an option has been given a new value through a user command.
5128 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5129 */
5130 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005131did_set_option(
5132 int opt_idx,
5133 int opt_flags, /* possibly with OPT_MODELINE */
5134 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005135{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005136 long_u *p;
5137
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005138 options[opt_idx].flags |= P_WAS_SET;
5139
5140 /* When an option is set in the sandbox, from a modeline or in secure mode
5141 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005142 * flag. */
5143 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005144 if (secure
5145#ifdef HAVE_SANDBOX
5146 || sandbox != 0
5147#endif
5148 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005149 *p = *p | P_INSECURE;
5150 else if (new_value)
5151 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005152}
5153
Bram Moolenaar071d4272004-06-13 20:20:40 +00005154 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005155illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005156{
5157 if (errbuf == NULL)
5158 return (char_u *)"";
5159 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005160 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005161 return errbuf;
5162}
5163
5164/*
5165 * Convert a key name or string into a key value.
5166 * Used for 'wildchar' and 'cedit' options.
5167 */
5168 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005169string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005170{
5171 if (*arg == '<')
5172 return find_key_option(arg + 1);
5173 if (*arg == '^')
5174 return Ctrl_chr(arg[1]);
5175 return *arg;
5176}
5177
5178#ifdef FEAT_CMDWIN
5179/*
5180 * Check value of 'cedit' and set cedit_key.
5181 * Returns NULL if value is OK, error message otherwise.
5182 */
5183 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005184check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005185{
5186 int n;
5187
5188 if (*p_cedit == NUL)
5189 cedit_key = -1;
5190 else
5191 {
5192 n = string_to_key(p_cedit);
5193 if (vim_isprintc(n))
5194 return e_invarg;
5195 cedit_key = n;
5196 }
5197 return NULL;
5198}
5199#endif
5200
5201#ifdef FEAT_TITLE
5202/*
5203 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5204 * maketitle() to create and display it.
5205 * When switching the title or icon off, call mch_restore_title() to get
5206 * the old value back.
5207 */
5208 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005209did_set_title(
5210 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211{
5212 if (starting != NO_SCREEN
5213#ifdef FEAT_GUI
5214 && !gui.starting
5215#endif
5216 )
5217 {
5218 maketitle();
5219 if (icon)
5220 {
5221 if (!p_icon)
5222 mch_restore_title(2);
5223 }
5224 else
5225 {
5226 if (!p_title)
5227 mch_restore_title(1);
5228 }
5229 }
5230}
5231#endif
5232
5233/*
5234 * set_options_bin - called when 'bin' changes value.
5235 */
5236 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005237set_options_bin(
5238 int oldval,
5239 int newval,
5240 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005241{
5242 /*
5243 * The option values that are changed when 'bin' changes are
5244 * copied when 'bin is set and restored when 'bin' is reset.
5245 */
5246 if (newval)
5247 {
5248 if (!oldval) /* switched on */
5249 {
5250 if (!(opt_flags & OPT_GLOBAL))
5251 {
5252 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5253 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5254 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5255 curbuf->b_p_et_nobin = curbuf->b_p_et;
5256 }
5257 if (!(opt_flags & OPT_LOCAL))
5258 {
5259 p_tw_nobin = p_tw;
5260 p_wm_nobin = p_wm;
5261 p_ml_nobin = p_ml;
5262 p_et_nobin = p_et;
5263 }
5264 }
5265
5266 if (!(opt_flags & OPT_GLOBAL))
5267 {
5268 curbuf->b_p_tw = 0; /* no automatic line wrap */
5269 curbuf->b_p_wm = 0; /* no automatic line wrap */
5270 curbuf->b_p_ml = 0; /* no modelines */
5271 curbuf->b_p_et = 0; /* no expandtab */
5272 }
5273 if (!(opt_flags & OPT_LOCAL))
5274 {
5275 p_tw = 0;
5276 p_wm = 0;
5277 p_ml = FALSE;
5278 p_et = FALSE;
5279 p_bin = TRUE; /* needed when called for the "-b" argument */
5280 }
5281 }
5282 else if (oldval) /* switched off */
5283 {
5284 if (!(opt_flags & OPT_GLOBAL))
5285 {
5286 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5287 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5288 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5289 curbuf->b_p_et = curbuf->b_p_et_nobin;
5290 }
5291 if (!(opt_flags & OPT_LOCAL))
5292 {
5293 p_tw = p_tw_nobin;
5294 p_wm = p_wm_nobin;
5295 p_ml = p_ml_nobin;
5296 p_et = p_et_nobin;
5297 }
5298 }
5299}
5300
5301#ifdef FEAT_VIMINFO
5302/*
5303 * Find the parameter represented by the given character (eg ', :, ", or /),
5304 * and return its associated value in the 'viminfo' string.
5305 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005306 * If the parameter is not specified in the string or there is no following
5307 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308 */
5309 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005310get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005311{
5312 char_u *p;
5313
5314 p = find_viminfo_parameter(type);
5315 if (p != NULL && VIM_ISDIGIT(*p))
5316 return atoi((char *)p);
5317 return -1;
5318}
5319
5320/*
5321 * Find the parameter represented by the given character (eg ''', ':', '"', or
5322 * '/') in the 'viminfo' option and return a pointer to the string after it.
5323 * Return NULL if the parameter is not specified in the string.
5324 */
5325 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005326find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327{
5328 char_u *p;
5329
5330 for (p = p_viminfo; *p; ++p)
5331 {
5332 if (*p == type)
5333 return p + 1;
5334 if (*p == 'n') /* 'n' is always the last one */
5335 break;
5336 p = vim_strchr(p, ','); /* skip until next ',' */
5337 if (p == NULL) /* hit the end without finding parameter */
5338 break;
5339 }
5340 return NULL;
5341}
5342#endif
5343
5344/*
5345 * Expand environment variables for some string options.
5346 * These string options cannot be indirect!
5347 * If "val" is NULL expand the current value of the option.
5348 * Return pointer to NameBuff, or NULL when not expanded.
5349 */
5350 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005351option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352{
5353 /* if option doesn't need expansion nothing to do */
5354 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5355 return NULL;
5356
5357 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5358 * expand_env() would truncate the string. */
5359 if (val != NULL && STRLEN(val) > MAXPATHL)
5360 return NULL;
5361
5362 if (val == NULL)
5363 val = *(char_u **)options[opt_idx].var;
5364
5365 /*
5366 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5367 * Escape spaces when expanding 'tags', they are used to separate file
5368 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005369 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005370 */
5371 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005372 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005373#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005374 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5375#endif
5376 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005377 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5378 return NULL;
5379
5380 return NameBuff;
5381}
5382
5383/*
5384 * After setting various option values: recompute variables that depend on
5385 * option values.
5386 */
5387 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005388didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005389{
5390 /* initialize the table for 'iskeyword' et.al. */
5391 (void)init_chartab();
5392
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005393#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005394 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005396 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005397 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005398#ifdef FEAT_SESSION
5399 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5400 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5401#endif
5402#ifdef FEAT_FOLDING
5403 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5404#endif
5405 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005406 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005407#ifdef FEAT_VIRTUALEDIT
5408 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5409#endif
5410#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5411 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5412#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005413#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005414 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005415 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005416 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005417 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005419#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5420 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5421#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005422#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005423 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5424#endif
5425#ifdef FEAT_CMDWIN
5426 /* set cedit_key */
5427 (void)check_cedit();
5428#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005429#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005430 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005431#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005432#ifdef FEAT_LINEBREAK
5433 /* initialize the table for 'breakat'. */
5434 fill_breakat_flags();
5435#endif
5436
5437}
5438
5439/*
5440 * More side effects of setting options.
5441 */
5442 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005443didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005444{
5445 /* Initialize the highlight_attr[] table. */
5446 (void)highlight_changed();
5447
5448 /* Parse default for 'wildmode' */
5449 check_opt_wim();
5450
5451 (void)set_chars_option(&p_lcs);
5452#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5453 /* Parse default for 'fillchars'. */
5454 (void)set_chars_option(&p_fcs);
5455#endif
5456
5457#ifdef FEAT_CLIPBOARD
5458 /* Parse default for 'clipboard' */
5459 (void)check_clipboard_option();
5460#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005461}
5462
5463/*
5464 * Check for string options that are NULL (normally only termcap options).
5465 */
5466 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005467check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005468{
5469 int opt_idx;
5470
5471 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5472 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5473 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5474}
5475
5476/*
5477 * Check string options in a buffer for NULL value.
5478 */
5479 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005480check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005481{
5482#if defined(FEAT_QUICKFIX)
5483 check_string_option(&buf->b_p_bh);
5484 check_string_option(&buf->b_p_bt);
5485#endif
5486#ifdef FEAT_MBYTE
5487 check_string_option(&buf->b_p_fenc);
5488#endif
5489 check_string_option(&buf->b_p_ff);
5490#ifdef FEAT_FIND_ID
5491 check_string_option(&buf->b_p_def);
5492 check_string_option(&buf->b_p_inc);
5493# ifdef FEAT_EVAL
5494 check_string_option(&buf->b_p_inex);
5495# endif
5496#endif
5497#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5498 check_string_option(&buf->b_p_inde);
5499 check_string_option(&buf->b_p_indk);
5500#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005501#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5502 check_string_option(&buf->b_p_bexpr);
5503#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005504#if defined(FEAT_CRYPT)
5505 check_string_option(&buf->b_p_cm);
5506#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005507 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005508#if defined(FEAT_EVAL)
5509 check_string_option(&buf->b_p_fex);
5510#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005511#ifdef FEAT_CRYPT
5512 check_string_option(&buf->b_p_key);
5513#endif
5514 check_string_option(&buf->b_p_kp);
5515 check_string_option(&buf->b_p_mps);
5516 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005517 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005518 check_string_option(&buf->b_p_isk);
5519#ifdef FEAT_COMMENTS
5520 check_string_option(&buf->b_p_com);
5521#endif
5522#ifdef FEAT_FOLDING
5523 check_string_option(&buf->b_p_cms);
5524#endif
5525 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005526#ifdef FEAT_TEXTOBJ
5527 check_string_option(&buf->b_p_qe);
5528#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529#ifdef FEAT_SYN_HL
5530 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005531 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005532#endif
5533#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005534 check_string_option(&buf->b_s.b_p_spc);
5535 check_string_option(&buf->b_s.b_p_spf);
5536 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005537#endif
5538#ifdef FEAT_SEARCHPATH
5539 check_string_option(&buf->b_p_sua);
5540#endif
5541#ifdef FEAT_CINDENT
5542 check_string_option(&buf->b_p_cink);
5543 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005544 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545#endif
5546#ifdef FEAT_AUTOCMD
5547 check_string_option(&buf->b_p_ft);
5548#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005549#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5550 check_string_option(&buf->b_p_cinw);
5551#endif
5552#ifdef FEAT_INS_EXPAND
5553 check_string_option(&buf->b_p_cpt);
5554#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005555#ifdef FEAT_COMPL_FUNC
5556 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005557 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005558#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559#ifdef FEAT_KEYMAP
5560 check_string_option(&buf->b_p_keymap);
5561#endif
5562#ifdef FEAT_QUICKFIX
5563 check_string_option(&buf->b_p_gp);
5564 check_string_option(&buf->b_p_mp);
5565 check_string_option(&buf->b_p_efm);
5566#endif
5567 check_string_option(&buf->b_p_ep);
5568 check_string_option(&buf->b_p_path);
5569 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005570 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571#ifdef FEAT_INS_EXPAND
5572 check_string_option(&buf->b_p_dict);
5573 check_string_option(&buf->b_p_tsr);
5574#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005575#ifdef FEAT_LISP
5576 check_string_option(&buf->b_p_lw);
5577#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005578 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005579}
5580
5581/*
5582 * Free the string allocated for an option.
5583 * Checks for the string being empty_option. This may happen if we're out of
5584 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5585 * check_options().
5586 * Does NOT check for P_ALLOCED flag!
5587 */
5588 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005589free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005590{
5591 if (p != empty_option)
5592 vim_free(p);
5593}
5594
5595 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005596clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005597{
5598 if (*pp != empty_option)
5599 vim_free(*pp);
5600 *pp = empty_option;
5601}
5602
5603 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005604check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605{
5606 if (*pp == NULL)
5607 *pp = empty_option;
5608}
5609
5610/*
5611 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5612 */
5613 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005614set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615{
5616 int opt_idx;
5617
5618 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5619 if (options[opt_idx].var == (char_u *)p)
5620 {
5621 options[opt_idx].flags |= P_ALLOCED;
5622 return;
5623 }
5624 return; /* cannot happen: didn't find it! */
5625}
5626
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005627#if defined(FEAT_EVAL) || defined(PROTO)
5628/*
5629 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5630 * Return FALSE when it wasn't.
5631 * Return -1 for an unknown option.
5632 */
5633 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005634was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005635{
5636 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005637 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005638
5639 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005640 {
5641 flagp = insecure_flag(idx, opt_flags);
5642 return (*flagp & P_INSECURE) != 0;
5643 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005644 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005645 return -1;
5646}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005647
5648/*
5649 * Get a pointer to the flags used for the P_INSECURE flag of option
5650 * "opt_idx". For some local options a local flags field is used.
5651 */
5652 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005653insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005654{
5655 if (opt_flags & OPT_LOCAL)
5656 switch ((int)options[opt_idx].indir)
5657 {
5658#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005659 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005660#endif
5661#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005662# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005663 case PV_FDE: return &curwin->w_p_fde_flags;
5664 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005665# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005666# ifdef FEAT_BEVAL
5667 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5668# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005669# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005670 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005671# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005672 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005673# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005674 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005675# endif
5676#endif
5677 }
5678
5679 /* Nothing special, return global flags field. */
5680 return &options[opt_idx].flags;
5681}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005682#endif
5683
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005684#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005685static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005686
5687/*
5688 * Redraw the window title and/or tab page text later.
5689 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005690static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005691{
5692 need_maketitle = TRUE;
5693# ifdef FEAT_WINDOWS
5694 redraw_tabline = TRUE;
5695# endif
5696}
5697#endif
5698
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699/*
5700 * Set a string option to a new value (without checking the effect).
5701 * The string is copied into allocated memory.
5702 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005703 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005704 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705 */
5706 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005707set_string_option_direct(
5708 char_u *name,
5709 int opt_idx,
5710 char_u *val,
5711 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5712 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713{
5714 char_u *s;
5715 char_u **varp;
5716 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005717 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005718
Bram Moolenaar89d40322006-08-29 15:30:07 +00005719 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005720 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005721 idx = findoption(name);
5722 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005723 {
5724 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005725 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005727 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728 }
5729
Bram Moolenaar89d40322006-08-29 15:30:07 +00005730 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005731 return;
5732
5733 s = vim_strsave(val);
5734 if (s != NULL)
5735 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005736 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005738 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739 free_string_option(*varp);
5740 *varp = s;
5741
5742 /* For buffer/window local option may also set the global value. */
5743 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005744 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745
Bram Moolenaar89d40322006-08-29 15:30:07 +00005746 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005747
5748 /* When setting both values of a global option with a local value,
5749 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005750 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005751 {
5752 free_string_option(*varp);
5753 *varp = empty_option;
5754 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005755# ifdef FEAT_EVAL
5756 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005757 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005758 set_sid == 0 ? current_SID : set_sid);
5759# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005760 }
5761}
5762
5763/*
5764 * Set global value for string option when it's a local option.
5765 */
5766 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005767set_string_option_global(
5768 int opt_idx, /* option index */
5769 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005770{
5771 char_u **p, *s;
5772
5773 /* the global value is always allocated */
5774 if (options[opt_idx].var == VAR_WIN)
5775 p = (char_u **)GLOBAL_WO(varp);
5776 else
5777 p = (char_u **)options[opt_idx].var;
5778 if (options[opt_idx].indir != PV_NONE
5779 && p != varp
5780 && (s = vim_strsave(*varp)) != NULL)
5781 {
5782 free_string_option(*p);
5783 *p = s;
5784 }
5785}
5786
5787/*
5788 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005789 *
5790 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005791 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005792 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005793set_string_option(
5794 int opt_idx,
5795 char_u *value,
5796 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005797{
5798 char_u *s;
5799 char_u **varp;
5800 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005801#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5802 char_u *saved_oldval = NULL;
5803#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005804 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005805
5806 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005807 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005808
5809 s = vim_strsave(value);
5810 if (s != NULL)
5811 {
5812 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5813 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005814 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005815 ? OPT_GLOBAL : OPT_LOCAL)
5816 : opt_flags);
5817 oldval = *varp;
5818 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005819
5820#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005821 if (!starting
5822# ifdef FEAT_CRYPT
5823 && options[opt_idx].indir != PV_KEY
5824# endif
5825 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005826 saved_oldval = vim_strsave(oldval);
5827#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005828 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5829 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005830 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005831
5832 /* call autocomamnd after handling side effects */
5833#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5834 if (saved_oldval != NULL)
5835 {
5836 char_u buf_type[7];
5837 sprintf((char *)buf_type, "%s",
5838 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005839 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5840 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005841 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5842 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5843 reset_v_option_vars();
5844 vim_free(saved_oldval);
5845 }
5846#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005848 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005849}
5850
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005851#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005853 * Return TRUE if "val" is a valid 'filetype' name.
5854 * Also used for 'syntax' and 'keymap'.
5855 */
5856 static int
5857valid_filetype(char_u *val)
5858{
5859 char_u *s;
5860
5861 for (s = val; *s != NUL; ++s)
5862 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5863 return FALSE;
5864 return TRUE;
5865}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005866#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005867
5868/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 * Handle string options that need some action to perform when changed.
5870 * Returns NULL for success, or an error message for an error.
5871 */
5872 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005873did_set_string_option(
5874 int opt_idx, /* index in options[] table */
5875 char_u **varp, /* pointer to the option variable */
5876 int new_value_alloced, /* new value was allocated */
5877 char_u *oldval, /* previous value of the option */
5878 char_u *errbuf, /* buffer for errors, or NULL */
5879 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880{
5881 char_u *errmsg = NULL;
5882 char_u *s, *p;
5883 int did_chartab = FALSE;
5884 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005885 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005886#ifdef FEAT_GUI
5887 /* set when changing an option that only requires a redraw in the GUI */
5888 int redraw_gui_only = FALSE;
5889#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890
5891 /* Get the global option to compare with, otherwise we would have to check
5892 * two values for all local options. */
5893 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5894
5895 /* Disallow changing some options from secure mode */
5896 if ((secure
5897#ifdef HAVE_SANDBOX
5898 || sandbox != 0
5899#endif
5900 ) && (options[opt_idx].flags & P_SECURE))
5901 {
5902 errmsg = e_secure;
5903 }
5904
Bram Moolenaar7554da42016-11-25 22:04:13 +01005905 /* Check for a "normal" directory or file name in some options. Disallow a
5906 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005907 * are often illegal in a file name. Be more permissive if "secure" is off.
5908 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01005909 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005910 && vim_strpbrk(*varp, (char_u *)(secure
5911 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01005912 || ((options[opt_idx].flags & P_NDNAME)
5913 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005914 {
5915 errmsg = e_invarg;
5916 }
5917
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 /* 'term' */
5919 else if (varp == &T_NAME)
5920 {
5921 if (T_NAME[0] == NUL)
5922 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5923#ifdef FEAT_GUI
5924 if (gui.in_use)
5925 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5926 else if (term_is_gui(T_NAME))
5927 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5928#endif
5929 else if (set_termname(T_NAME) == FAIL)
5930 errmsg = (char_u *)N_("E522: Not found in termcap");
5931 else
5932 /* Screen colors may have changed. */
5933 redraw_later_clear();
5934 }
5935
5936 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005937 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005938 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005939 char_u *bkc = p_bkc;
5940 unsigned int *flags = &bkc_flags;
5941
5942 if (opt_flags & OPT_LOCAL)
5943 {
5944 bkc = curbuf->b_p_bkc;
5945 flags = &curbuf->b_bkc_flags;
5946 }
5947
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005948 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5949 /* make the local value empty: use the global value */
5950 *flags = 0;
5951 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005952 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005953 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5954 errmsg = e_invarg;
5955 if ((((int)*flags & BKC_AUTO) != 0)
5956 + (((int)*flags & BKC_YES) != 0)
5957 + (((int)*flags & BKC_NO) != 0) != 1)
5958 {
5959 /* Must have exactly one of "auto", "yes" and "no". */
5960 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5961 errmsg = e_invarg;
5962 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 }
5964 }
5965
5966 /* 'backupext' and 'patchmode' */
5967 else if (varp == &p_bex || varp == &p_pm)
5968 {
5969 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5970 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5971 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5972 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005973#ifdef FEAT_LINEBREAK
5974 /* 'breakindentopt' */
5975 else if (varp == &curwin->w_p_briopt)
5976 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005977 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005978 errmsg = e_invarg;
5979 }
5980#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005981
5982 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005983 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005985 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005986 */
5987 else if ( varp == &p_isi
5988 || varp == &(curbuf->b_p_isk)
5989 || varp == &p_isp
5990 || varp == &p_isf)
5991 {
5992 if (init_chartab() == FAIL)
5993 {
5994 did_chartab = TRUE; /* need to restore it below */
5995 errmsg = e_invarg; /* error in value */
5996 }
5997 }
5998
5999 /* 'helpfile' */
6000 else if (varp == &p_hf)
6001 {
6002 /* May compute new values for $VIM and $VIMRUNTIME */
6003 if (didset_vim)
6004 {
6005 vim_setenv((char_u *)"VIM", (char_u *)"");
6006 didset_vim = FALSE;
6007 }
6008 if (didset_vimruntime)
6009 {
6010 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6011 didset_vimruntime = FALSE;
6012 }
6013 }
6014
Bram Moolenaar1a384422010-07-14 19:53:30 +02006015#ifdef FEAT_SYN_HL
6016 /* 'colorcolumn' */
6017 else if (varp == &curwin->w_p_cc)
6018 errmsg = check_colorcolumn(curwin);
6019#endif
6020
Bram Moolenaar071d4272004-06-13 20:20:40 +00006021#ifdef FEAT_MULTI_LANG
6022 /* 'helplang' */
6023 else if (varp == &p_hlg)
6024 {
6025 /* Check for "", "ab", "ab,cd", etc. */
6026 for (s = p_hlg; *s != NUL; s += 3)
6027 {
6028 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6029 {
6030 errmsg = e_invarg;
6031 break;
6032 }
6033 if (s[2] == NUL)
6034 break;
6035 }
6036 }
6037#endif
6038
6039 /* 'highlight' */
6040 else if (varp == &p_hl)
6041 {
6042 if (highlight_changed() == FAIL)
6043 errmsg = e_invarg; /* invalid flags */
6044 }
6045
6046 /* 'nrformats' */
6047 else if (gvarp == &p_nf)
6048 {
6049 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6050 errmsg = e_invarg;
6051 }
6052
6053#ifdef FEAT_SESSION
6054 /* 'sessionoptions' */
6055 else if (varp == &p_ssop)
6056 {
6057 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6058 errmsg = e_invarg;
6059 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6060 {
6061 /* Don't allow both "sesdir" and "curdir". */
6062 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6063 errmsg = e_invarg;
6064 }
6065 }
6066 /* 'viewoptions' */
6067 else if (varp == &p_vop)
6068 {
6069 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6070 errmsg = e_invarg;
6071 }
6072#endif
6073
6074 /* 'scrollopt' */
6075#ifdef FEAT_SCROLLBIND
6076 else if (varp == &p_sbo)
6077 {
6078 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6079 errmsg = e_invarg;
6080 }
6081#endif
6082
6083 /* 'ambiwidth' */
6084#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006085 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006086 {
6087 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6088 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006089 else if (set_chars_option(&p_lcs) != NULL)
6090 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6091# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6092 else if (set_chars_option(&p_fcs) != NULL)
6093 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6094# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006095 }
6096#endif
6097
6098 /* 'background' */
6099 else if (varp == &p_bg)
6100 {
6101 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6102 {
6103#ifdef FEAT_EVAL
6104 int dark = (*p_bg == 'd');
6105#endif
6106
6107 init_highlight(FALSE, FALSE);
6108
6109#ifdef FEAT_EVAL
6110 if (dark != (*p_bg == 'd')
6111 && get_var_value((char_u *)"g:colors_name") != NULL)
6112 {
6113 /* The color scheme must have set 'background' back to another
6114 * value, that's not what we want here. Disable the color
6115 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006116 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 free_string_option(p_bg);
6118 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6119 check_string_option(&p_bg);
6120 init_highlight(FALSE, FALSE);
6121 }
6122#endif
6123 }
6124 else
6125 errmsg = e_invarg;
6126 }
6127
6128 /* 'wildmode' */
6129 else if (varp == &p_wim)
6130 {
6131 if (check_opt_wim() == FAIL)
6132 errmsg = e_invarg;
6133 }
6134
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006135#ifdef FEAT_CMDL_COMPL
6136 /* 'wildoptions' */
6137 else if (varp == &p_wop)
6138 {
6139 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6140 errmsg = e_invarg;
6141 }
6142#endif
6143
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144#ifdef FEAT_WAK
6145 /* 'winaltkeys' */
6146 else if (varp == &p_wak)
6147 {
6148 if (*p_wak == NUL
6149 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6150 errmsg = e_invarg;
6151# ifdef FEAT_MENU
6152# ifdef FEAT_GUI_MOTIF
6153 else if (gui.in_use)
6154 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6155# else
6156# ifdef FEAT_GUI_GTK
6157 else if (gui.in_use)
6158 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6159# endif
6160# endif
6161# endif
6162 }
6163#endif
6164
6165#ifdef FEAT_AUTOCMD
6166 /* 'eventignore' */
6167 else if (varp == &p_ei)
6168 {
6169 if (check_ei() == FAIL)
6170 errmsg = e_invarg;
6171 }
6172#endif
6173
6174#ifdef FEAT_MBYTE
6175 /* 'encoding' and 'fileencoding' */
6176 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6177 {
6178 if (gvarp == &p_fenc)
6179 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006180 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006181 errmsg = e_modifiable;
6182 else if (vim_strchr(*varp, ',') != NULL)
6183 /* No comma allowed in 'fileencoding'; catches confusing it
6184 * with 'fileencodings'. */
6185 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006186 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006187 {
6188# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006189 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006190 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006191# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006192 /* Add 'fileencoding' to the swap file. */
6193 ml_setflags(curbuf);
6194 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006195 }
6196 if (errmsg == NULL)
6197 {
6198 /* canonize the value, so that STRCMP() can be used on it */
6199 p = enc_canonize(*varp);
6200 if (p != NULL)
6201 {
6202 vim_free(*varp);
6203 *varp = p;
6204 }
6205 if (varp == &p_enc)
6206 {
6207 errmsg = mb_init();
6208# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006209 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006210# endif
6211 }
6212 }
6213
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006214# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006215 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6216 {
6217 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6218 if (STRCMP(p_tenc, "utf-8") != 0)
6219 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6220 }
6221# endif
6222
6223 if (errmsg == NULL)
6224 {
6225# ifdef FEAT_KEYMAP
6226 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6227 * (with another encoding). */
6228 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6229 (void)keymap_init();
6230# endif
6231
6232 /* When 'termencoding' is not empty and 'encoding' changes or when
6233 * 'termencoding' changes, need to setup for keyboard input and
6234 * display output conversion. */
6235 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6236 {
6237 convert_setup(&input_conv, p_tenc, p_enc);
6238 convert_setup(&output_conv, p_enc, p_tenc);
6239 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006240
6241# if defined(WIN3264) && defined(FEAT_MBYTE)
6242 /* $HOME may have characters in active code page. */
6243 if (varp == &p_enc)
6244 init_homedir();
6245# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006246 }
6247 }
6248#endif
6249
6250#if defined(FEAT_POSTSCRIPT)
6251 else if (varp == &p_penc)
6252 {
6253 /* Canonize printencoding if VIM standard one */
6254 p = enc_canonize(p_penc);
6255 if (p != NULL)
6256 {
6257 vim_free(p_penc);
6258 p_penc = p;
6259 }
6260 else
6261 {
6262 /* Ensure lower case and '-' for '_' */
6263 for (s = p_penc; *s != NUL; s++)
6264 {
6265 if (*s == '_')
6266 *s = '-';
6267 else
6268 *s = TOLOWER_ASC(*s);
6269 }
6270 }
6271 }
6272#endif
6273
Bram Moolenaar9372a112005-12-06 19:59:18 +00006274#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006275 else if (varp == &p_imak)
6276 {
6277 if (gui.in_use && !im_xim_isvalid_imactivate())
6278 errmsg = e_invarg;
6279 }
6280#endif
6281
6282#ifdef FEAT_KEYMAP
6283 else if (varp == &curbuf->b_p_keymap)
6284 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006285 if (!valid_filetype(*varp))
6286 errmsg = e_invarg;
6287 else
6288 /* load or unload key mapping tables */
6289 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006290
Bram Moolenaarfab06232009-03-04 03:13:35 +00006291 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006292 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006293 if (*curbuf->b_p_keymap != NUL)
6294 {
6295 /* Installed a new keymap, switch on using it. */
6296 curbuf->b_p_iminsert = B_IMODE_LMAP;
6297 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6298 curbuf->b_p_imsearch = B_IMODE_LMAP;
6299 }
6300 else
6301 {
6302 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6303 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6304 curbuf->b_p_iminsert = B_IMODE_NONE;
6305 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6306 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6307 }
6308 if ((opt_flags & OPT_LOCAL) == 0)
6309 {
6310 set_iminsert_global();
6311 set_imsearch_global();
6312 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313# ifdef FEAT_WINDOWS
6314 status_redraw_curbuf();
6315# endif
6316 }
6317 }
6318#endif
6319
6320 /* 'fileformat' */
6321 else if (gvarp == &p_ff)
6322 {
6323 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6324 errmsg = e_modifiable;
6325 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6326 errmsg = e_invarg;
6327 else
6328 {
6329 /* may also change 'textmode' */
6330 if (get_fileformat(curbuf) == EOL_DOS)
6331 curbuf->b_p_tx = TRUE;
6332 else
6333 curbuf->b_p_tx = FALSE;
6334#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006335 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006336#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006337 /* update flag in swap file */
6338 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006339 /* Redraw needed when switching to/from "mac": a CR in the text
6340 * will be displayed differently. */
6341 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6342 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343 }
6344 }
6345
6346 /* 'fileformats' */
6347 else if (varp == &p_ffs)
6348 {
6349 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6350 errmsg = e_invarg;
6351 else
6352 {
6353 /* also change 'textauto' */
6354 if (*p_ffs == NUL)
6355 p_ta = FALSE;
6356 else
6357 p_ta = TRUE;
6358 }
6359 }
6360
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006361#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006362 /* 'cryptkey' */
6363 else if (gvarp == &p_key)
6364 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006365# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006366 /* Make sure the ":set" command doesn't show the new value in the
6367 * history. */
6368 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006369# endif
6370 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6371 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006372 ml_set_crypt_key(curbuf, oldval,
6373 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006374 }
6375
6376 else if (gvarp == &p_cm)
6377 {
6378 if (opt_flags & OPT_LOCAL)
6379 p = curbuf->b_p_cm;
6380 else
6381 p = p_cm;
6382 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6383 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006384 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006385 errmsg = e_invarg;
6386 else
6387 {
6388 /* When setting the global value to empty, make it "zip". */
6389 if (*p_cm == NUL)
6390 {
6391 if (new_value_alloced)
6392 free_string_option(p_cm);
6393 p_cm = vim_strsave((char_u *)"zip");
6394 new_value_alloced = TRUE;
6395 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006396 /* When using ":set cm=name" the local value is going to be empty.
6397 * Do that here, otherwise the crypt functions will still use the
6398 * local value. */
6399 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6400 {
6401 free_string_option(curbuf->b_p_cm);
6402 curbuf->b_p_cm = empty_option;
6403 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006404
6405 /* Need to update the swapfile when the effective method changed.
6406 * Set "s" to the effective old value, "p" to the effective new
6407 * method and compare. */
6408 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6409 s = p_cm; /* was previously using the global value */
6410 else
6411 s = oldval;
6412 if (*curbuf->b_p_cm == NUL)
6413 p = p_cm; /* is now using the global value */
6414 else
6415 p = curbuf->b_p_cm;
6416 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006417 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006418
6419 /* If the global value changes need to update the swapfile for all
6420 * buffers using that value. */
6421 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6422 {
6423 buf_T *buf;
6424
Bram Moolenaar29323592016-07-24 22:04:11 +02006425 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006426 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006427 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006428 }
6429 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430 }
6431#endif
6432
6433 /* 'matchpairs' */
6434 else if (gvarp == &p_mps)
6435 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006436#ifdef FEAT_MBYTE
6437 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006438 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006439 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006440 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006441 int x2 = -1;
6442 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006443
6444 if (*p != NUL)
6445 p += mb_ptr2len(p);
6446 if (*p != NUL)
6447 x2 = *p++;
6448 if (*p != NUL)
6449 {
6450 x3 = mb_ptr2char(p);
6451 p += mb_ptr2len(p);
6452 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006453 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006454 {
6455 errmsg = e_invarg;
6456 break;
6457 }
6458 if (*p == NUL)
6459 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006460 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006461 }
6462 else
6463#endif
6464 {
6465 /* Check for "x:y,x:y" */
6466 for (p = *varp; *p != NUL; p += 4)
6467 {
6468 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6469 {
6470 errmsg = e_invarg;
6471 break;
6472 }
6473 if (p[3] == NUL)
6474 break;
6475 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006476 }
6477 }
6478
6479#ifdef FEAT_COMMENTS
6480 /* 'comments' */
6481 else if (gvarp == &p_com)
6482 {
6483 for (s = *varp; *s; )
6484 {
6485 while (*s && *s != ':')
6486 {
6487 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6488 && !VIM_ISDIGIT(*s) && *s != '-')
6489 {
6490 errmsg = illegal_char(errbuf, *s);
6491 break;
6492 }
6493 ++s;
6494 }
6495 if (*s++ == NUL)
6496 errmsg = (char_u *)N_("E524: Missing colon");
6497 else if (*s == ',' || *s == NUL)
6498 errmsg = (char_u *)N_("E525: Zero length string");
6499 if (errmsg != NULL)
6500 break;
6501 while (*s && *s != ',')
6502 {
6503 if (*s == '\\' && s[1] != NUL)
6504 ++s;
6505 ++s;
6506 }
6507 s = skip_to_option_part(s);
6508 }
6509 }
6510#endif
6511
6512 /* 'listchars' */
6513 else if (varp == &p_lcs)
6514 {
6515 errmsg = set_chars_option(varp);
6516 }
6517
6518#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6519 /* 'fillchars' */
6520 else if (varp == &p_fcs)
6521 {
6522 errmsg = set_chars_option(varp);
6523 }
6524#endif
6525
6526#ifdef FEAT_CMDWIN
6527 /* 'cedit' */
6528 else if (varp == &p_cedit)
6529 {
6530 errmsg = check_cedit();
6531 }
6532#endif
6533
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006534 /* 'verbosefile' */
6535 else if (varp == &p_vfile)
6536 {
6537 verbose_stop();
6538 if (*p_vfile != NUL && verbose_open() == FAIL)
6539 errmsg = e_invarg;
6540 }
6541
Bram Moolenaar071d4272004-06-13 20:20:40 +00006542#ifdef FEAT_VIMINFO
6543 /* 'viminfo' */
6544 else if (varp == &p_viminfo)
6545 {
6546 for (s = p_viminfo; *s;)
6547 {
6548 /* Check it's a valid character */
6549 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6550 {
6551 errmsg = illegal_char(errbuf, *s);
6552 break;
6553 }
6554 if (*s == 'n') /* name is always last one */
6555 {
6556 break;
6557 }
6558 else if (*s == 'r') /* skip until next ',' */
6559 {
6560 while (*++s && *s != ',')
6561 ;
6562 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006563 else if (*s == '%')
6564 {
6565 /* optional number */
6566 while (vim_isdigit(*++s))
6567 ;
6568 }
6569 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006570 ++s; /* no extra chars */
6571 else /* must have a number */
6572 {
6573 while (vim_isdigit(*++s))
6574 ;
6575
6576 if (!VIM_ISDIGIT(*(s - 1)))
6577 {
6578 if (errbuf != NULL)
6579 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006580 sprintf((char *)errbuf,
6581 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 transchar_byte(*(s - 1)));
6583 errmsg = errbuf;
6584 }
6585 else
6586 errmsg = (char_u *)"";
6587 break;
6588 }
6589 }
6590 if (*s == ',')
6591 ++s;
6592 else if (*s)
6593 {
6594 if (errbuf != NULL)
6595 errmsg = (char_u *)N_("E527: Missing comma");
6596 else
6597 errmsg = (char_u *)"";
6598 break;
6599 }
6600 }
6601 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6602 errmsg = (char_u *)N_("E528: Must specify a ' value");
6603 }
6604#endif /* FEAT_VIMINFO */
6605
6606 /* terminal options */
6607 else if (istermoption(&options[opt_idx]) && full_screen)
6608 {
6609 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6610 if (varp == &T_CCO)
6611 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006612 int colors = atoi((char *)T_CCO);
6613
6614 /* Only reinitialize colors if t_Co value has really changed to
6615 * avoid expensive reload of colorscheme if t_Co is set to the
6616 * same value multiple times. */
6617 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006619 t_colors = colors;
6620 if (t_colors <= 1)
6621 {
6622 if (new_value_alloced)
6623 vim_free(T_CCO);
6624 T_CCO = empty_option;
6625 }
6626 /* We now have a different color setup, initialize it again. */
6627 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006628 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006629 }
6630 ttest(FALSE);
6631 if (varp == &T_ME)
6632 {
6633 out_str(T_ME);
6634 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006635#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006636 /* Since t_me has been set, this probably means that the user
6637 * wants to use this as default colors. Need to reset default
6638 * background/foreground colors. */
6639 mch_set_normal_colors();
6640#endif
6641 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006642 if (varp == &T_BE && termcap_active)
6643 {
6644 if (*T_BE == NUL)
6645 /* When clearing t_BE we assume the user no longer wants
6646 * bracketed paste, thus disable it by writing t_BD. */
6647 out_str(T_BD);
6648 else
6649 out_str(T_BE);
6650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006651 }
6652
6653#ifdef FEAT_LINEBREAK
6654 /* 'showbreak' */
6655 else if (varp == &p_sbr)
6656 {
6657 for (s = p_sbr; *s; )
6658 {
6659 if (ptr2cells(s) != 1)
6660 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006661 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006662 }
6663 }
6664#endif
6665
6666#ifdef FEAT_GUI
6667 /* 'guifont' */
6668 else if (varp == &p_guifont)
6669 {
6670 if (gui.in_use)
6671 {
6672 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006673# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006674 /*
6675 * Put up a font dialog and let the user select a new value.
6676 * If this is cancelled go back to the old value but don't
6677 * give an error message.
6678 */
6679 if (STRCMP(p, "*") == 0)
6680 {
6681 p = gui_mch_font_dialog(oldval);
6682
6683 if (new_value_alloced)
6684 free_string_option(p_guifont);
6685
6686 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6687 new_value_alloced = TRUE;
6688 }
6689# endif
6690 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6691 {
6692# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6693 if (STRCMP(p_guifont, "*") == 0)
6694 {
6695 /* Dialog was cancelled: Keep the old value without giving
6696 * an error message. */
6697 if (new_value_alloced)
6698 free_string_option(p_guifont);
6699 p_guifont = vim_strsave(oldval);
6700 new_value_alloced = TRUE;
6701 }
6702 else
6703# endif
6704 errmsg = (char_u *)N_("E596: Invalid font(s)");
6705 }
6706 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006707 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006708 }
6709# ifdef FEAT_XFONTSET
6710 else if (varp == &p_guifontset)
6711 {
6712 if (STRCMP(p_guifontset, "*") == 0)
6713 errmsg = (char_u *)N_("E597: can't select fontset");
6714 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6715 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006716 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006717 }
6718# endif
6719# ifdef FEAT_MBYTE
6720 else if (varp == &p_guifontwide)
6721 {
6722 if (STRCMP(p_guifontwide, "*") == 0)
6723 errmsg = (char_u *)N_("E533: can't select wide font");
6724 else if (gui_get_wide_font() == FAIL)
6725 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006726 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006727 }
6728# endif
6729#endif
6730
6731#ifdef CURSOR_SHAPE
6732 /* 'guicursor' */
6733 else if (varp == &p_guicursor)
6734 errmsg = parse_shape_opt(SHAPE_CURSOR);
6735#endif
6736
6737#ifdef FEAT_MOUSESHAPE
6738 /* 'mouseshape' */
6739 else if (varp == &p_mouseshape)
6740 {
6741 errmsg = parse_shape_opt(SHAPE_MOUSE);
6742 update_mouseshape(-1);
6743 }
6744#endif
6745
6746#ifdef FEAT_PRINTER
6747 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006748 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006749# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006750 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006751 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006752# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006753#endif
6754
6755#ifdef FEAT_LANGMAP
6756 /* 'langmap' */
6757 else if (varp == &p_langmap)
6758 langmap_set();
6759#endif
6760
6761#ifdef FEAT_LINEBREAK
6762 /* 'breakat' */
6763 else if (varp == &p_breakat)
6764 fill_breakat_flags();
6765#endif
6766
6767#ifdef FEAT_TITLE
6768 /* 'titlestring' and 'iconstring' */
6769 else if (varp == &p_titlestring || varp == &p_iconstring)
6770 {
6771# ifdef FEAT_STL_OPT
6772 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6773
6774 /* NULL => statusline syntax */
6775 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6776 stl_syntax |= flagval;
6777 else
6778 stl_syntax &= ~flagval;
6779# endif
6780 did_set_title(varp == &p_iconstring);
6781
6782 }
6783#endif
6784
6785#ifdef FEAT_GUI
6786 /* 'guioptions' */
6787 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006788 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006789 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006790 redraw_gui_only = TRUE;
6791 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792#endif
6793
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006794#if defined(FEAT_GUI_TABLINE)
6795 /* 'guitablabel' */
6796 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006797 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006798 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006799 redraw_gui_only = TRUE;
6800 }
6801 /* 'guitabtooltip' */
6802 else if (varp == &p_gtt)
6803 {
6804 redraw_gui_only = TRUE;
6805 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006806#endif
6807
Bram Moolenaar071d4272004-06-13 20:20:40 +00006808#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6809 /* 'ttymouse' */
6810 else if (varp == &p_ttym)
6811 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006812 /* Switch the mouse off before changing the escape sequences used for
6813 * that. */
6814 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6816 errmsg = e_invarg;
6817 else
6818 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006819 if (termcap_active)
6820 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006821 }
6822#endif
6823
Bram Moolenaar071d4272004-06-13 20:20:40 +00006824 /* 'selection' */
6825 else if (varp == &p_sel)
6826 {
6827 if (*p_sel == NUL
6828 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6829 errmsg = e_invarg;
6830 }
6831
6832 /* 'selectmode' */
6833 else if (varp == &p_slm)
6834 {
6835 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6836 errmsg = e_invarg;
6837 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006838
6839#ifdef FEAT_BROWSE
6840 /* 'browsedir' */
6841 else if (varp == &p_bsdir)
6842 {
6843 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6844 && !mch_isdir(p_bsdir))
6845 errmsg = e_invarg;
6846 }
6847#endif
6848
Bram Moolenaar071d4272004-06-13 20:20:40 +00006849 /* 'keymodel' */
6850 else if (varp == &p_km)
6851 {
6852 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6853 errmsg = e_invarg;
6854 else
6855 {
6856 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6857 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6858 }
6859 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006860
6861 /* 'mousemodel' */
6862 else if (varp == &p_mousem)
6863 {
6864 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6865 errmsg = e_invarg;
6866#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6867 else if (*p_mousem != *oldval)
6868 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6869 * to create or delete the popup menus. */
6870 gui_motif_update_mousemodel(root_menu);
6871#endif
6872 }
6873
6874 /* 'switchbuf' */
6875 else if (varp == &p_swb)
6876 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006877 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006878 errmsg = e_invarg;
6879 }
6880
6881 /* 'debug' */
6882 else if (varp == &p_debug)
6883 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006884 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006885 errmsg = e_invarg;
6886 }
6887
6888 /* 'display' */
6889 else if (varp == &p_dy)
6890 {
6891 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6892 errmsg = e_invarg;
6893 else
6894 (void)init_chartab();
6895
6896 }
6897
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006898#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006899 /* 'eadirection' */
6900 else if (varp == &p_ead)
6901 {
6902 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6903 errmsg = e_invarg;
6904 }
6905#endif
6906
6907#ifdef FEAT_CLIPBOARD
6908 /* 'clipboard' */
6909 else if (varp == &p_cb)
6910 errmsg = check_clipboard_option();
6911#endif
6912
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006913#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006914 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6915 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006916 else if (varp == &(curwin->w_s->b_p_spl)
6917 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006918 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006919 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006920 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006921 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006922 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006923 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006924 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006925 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006926 /* 'spellsuggest' */
6927 else if (varp == &p_sps)
6928 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006929 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006930 errmsg = e_invarg;
6931 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006932 /* 'mkspellmem' */
6933 else if (varp == &p_msm)
6934 {
6935 if (spell_check_msm() != OK)
6936 errmsg = e_invarg;
6937 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006938#endif
6939
Bram Moolenaar071d4272004-06-13 20:20:40 +00006940#ifdef FEAT_QUICKFIX
6941 /* When 'bufhidden' is set, check for valid value. */
6942 else if (gvarp == &p_bh)
6943 {
6944 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6945 errmsg = e_invarg;
6946 }
6947
6948 /* When 'buftype' is set, check for valid value. */
6949 else if (gvarp == &p_bt)
6950 {
6951 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6952 errmsg = e_invarg;
6953 else
6954 {
6955# ifdef FEAT_WINDOWS
6956 if (curwin->w_status_height)
6957 {
6958 curwin->w_redr_status = TRUE;
6959 redraw_later(VALID);
6960 }
6961# endif
6962 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006963# ifdef FEAT_TITLE
6964 redraw_titles();
6965# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966 }
6967 }
6968#endif
6969
6970#ifdef FEAT_STL_OPT
6971 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006972 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973 {
6974 int wid;
6975
6976 if (varp == &p_ruf) /* reset ru_wid first */
6977 ru_wid = 0;
6978 s = *varp;
6979 if (varp == &p_ruf && *s == '%')
6980 {
6981 /* set ru_wid if 'ruf' starts with "%99(" */
6982 if (*++s == '-') /* ignore a '-' */
6983 s++;
6984 wid = getdigits(&s);
6985 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6986 ru_wid = wid;
6987 else
6988 errmsg = check_stl_option(p_ruf);
6989 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006990 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006991 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006993 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006994 comp_col();
6995 }
6996#endif
6997
6998#ifdef FEAT_INS_EXPAND
6999 /* check if it is a valid value for 'complete' -- Acevedo */
7000 else if (gvarp == &p_cpt)
7001 {
7002 for (s = *varp; *s;)
7003 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007004 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007005 s++;
7006 if (!*s)
7007 break;
7008 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7009 {
7010 errmsg = illegal_char(errbuf, *s);
7011 break;
7012 }
7013 if (*++s != NUL && *s != ',' && *s != ' ')
7014 {
7015 if (s[-1] == 'k' || s[-1] == 's')
7016 {
7017 /* skip optional filename after 'k' and 's' */
7018 while (*s && *s != ',' && *s != ' ')
7019 {
7020 if (*s == '\\')
7021 ++s;
7022 ++s;
7023 }
7024 }
7025 else
7026 {
7027 if (errbuf != NULL)
7028 {
7029 sprintf((char *)errbuf,
7030 _("E535: Illegal character after <%c>"),
7031 *--s);
7032 errmsg = errbuf;
7033 }
7034 else
7035 errmsg = (char_u *)"";
7036 break;
7037 }
7038 }
7039 }
7040 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007041
7042 /* 'completeopt' */
7043 else if (varp == &p_cot)
7044 {
7045 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7046 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007047 else
7048 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007049 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050#endif /* FEAT_INS_EXPAND */
7051
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007052#ifdef FEAT_SIGNS
7053 /* 'signcolumn' */
7054 else if (varp == &curwin->w_p_scl)
7055 {
7056 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7057 errmsg = e_invarg;
7058 }
7059#endif
7060
Bram Moolenaar071d4272004-06-13 20:20:40 +00007061
7062#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007063 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007064 else if (varp == &p_toolbar)
7065 {
7066 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7067 &toolbar_flags, TRUE) != OK)
7068 errmsg = e_invarg;
7069 else
7070 {
7071 out_flush();
7072 gui_mch_show_toolbar((toolbar_flags &
7073 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7074 }
7075 }
7076#endif
7077
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007078#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007079 /* 'toolbariconsize': GTK+ 2 only */
7080 else if (varp == &p_tbis)
7081 {
7082 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7083 errmsg = e_invarg;
7084 else
7085 {
7086 out_flush();
7087 gui_mch_show_toolbar((toolbar_flags &
7088 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7089 }
7090 }
7091#endif
7092
7093 /* 'pastetoggle': translate key codes like in a mapping */
7094 else if (varp == &p_pt)
7095 {
7096 if (*p_pt)
7097 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007098 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099 if (p != NULL)
7100 {
7101 if (new_value_alloced)
7102 free_string_option(p_pt);
7103 p_pt = p;
7104 new_value_alloced = TRUE;
7105 }
7106 }
7107 }
7108
7109 /* 'backspace' */
7110 else if (varp == &p_bs)
7111 {
7112 if (VIM_ISDIGIT(*p_bs))
7113 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007114 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007115 errmsg = e_invarg;
7116 }
7117 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7118 errmsg = e_invarg;
7119 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007120 else if (varp == &p_bo)
7121 {
7122 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7123 errmsg = e_invarg;
7124 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007126 /* 'tagcase' */
7127 else if (gvarp == &p_tc)
7128 {
7129 unsigned int *flags;
7130
7131 if (opt_flags & OPT_LOCAL)
7132 {
7133 p = curbuf->b_p_tc;
7134 flags = &curbuf->b_tc_flags;
7135 }
7136 else
7137 {
7138 p = p_tc;
7139 flags = &tc_flags;
7140 }
7141
7142 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7143 /* make the local value empty: use the global value */
7144 *flags = 0;
7145 else if (*p == NUL
7146 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7147 errmsg = e_invarg;
7148 }
7149
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007150#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007151 /* 'casemap' */
7152 else if (varp == &p_cmp)
7153 {
7154 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7155 errmsg = e_invarg;
7156 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007157#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158
7159#ifdef FEAT_DIFF
7160 /* 'diffopt' */
7161 else if (varp == &p_dip)
7162 {
7163 if (diffopt_changed() == FAIL)
7164 errmsg = e_invarg;
7165 }
7166#endif
7167
7168#ifdef FEAT_FOLDING
7169 /* 'foldmethod' */
7170 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7171 {
7172 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7173 || *curwin->w_p_fdm == NUL)
7174 errmsg = e_invarg;
7175 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007176 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007177 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007178 if (foldmethodIsDiff(curwin))
7179 newFoldLevel();
7180 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 }
7182# ifdef FEAT_EVAL
7183 /* 'foldexpr' */
7184 else if (varp == &curwin->w_p_fde)
7185 {
7186 if (foldmethodIsExpr(curwin))
7187 foldUpdateAll(curwin);
7188 }
7189# endif
7190 /* 'foldmarker' */
7191 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7192 {
7193 p = vim_strchr(*varp, ',');
7194 if (p == NULL)
7195 errmsg = (char_u *)N_("E536: comma required");
7196 else if (p == *varp || p[1] == NUL)
7197 errmsg = e_invarg;
7198 else if (foldmethodIsMarker(curwin))
7199 foldUpdateAll(curwin);
7200 }
7201 /* 'commentstring' */
7202 else if (gvarp == &p_cms)
7203 {
7204 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7205 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7206 }
7207 /* 'foldopen' */
7208 else if (varp == &p_fdo)
7209 {
7210 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7211 errmsg = e_invarg;
7212 }
7213 /* 'foldclose' */
7214 else if (varp == &p_fcl)
7215 {
7216 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7217 errmsg = e_invarg;
7218 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007219 /* 'foldignore' */
7220 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7221 {
7222 if (foldmethodIsIndent(curwin))
7223 foldUpdateAll(curwin);
7224 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007225#endif
7226
7227#ifdef FEAT_VIRTUALEDIT
7228 /* 'virtualedit' */
7229 else if (varp == &p_ve)
7230 {
7231 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7232 errmsg = e_invarg;
7233 else if (STRCMP(p_ve, oldval) != 0)
7234 {
7235 /* Recompute cursor position in case the new 've' setting
7236 * changes something. */
7237 validate_virtcol();
7238 coladvance(curwin->w_virtcol);
7239 }
7240 }
7241#endif
7242
7243#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7244 else if (varp == &p_csqf)
7245 {
7246 if (p_csqf != NULL)
7247 {
7248 p = p_csqf;
7249 while (*p != NUL)
7250 {
7251 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7252 || p[1] == NUL
7253 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7254 || (p[2] != NUL && p[2] != ','))
7255 {
7256 errmsg = e_invarg;
7257 break;
7258 }
7259 else if (p[2] == NUL)
7260 break;
7261 else
7262 p += 3;
7263 }
7264 }
7265 }
7266#endif
7267
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007268#ifdef FEAT_CINDENT
7269 /* 'cinoptions' */
7270 else if (gvarp == &p_cino)
7271 {
7272 /* TODO: recognize errors */
7273 parse_cino(curbuf);
7274 }
7275#endif
7276
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007277#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007278 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007279 else if (varp == &p_rop && gui.in_use)
7280 {
7281 if (!gui_mch_set_rendering_options(p_rop))
7282 errmsg = e_invarg;
7283 }
7284#endif
7285
Bram Moolenaard0b51382016-11-04 15:23:45 +01007286#ifdef FEAT_AUTOCMD
7287 else if (gvarp == &p_ft)
7288 {
7289 if (!valid_filetype(*varp))
7290 errmsg = e_invarg;
7291 }
7292#endif
7293
7294#ifdef FEAT_SYN_HL
7295 else if (gvarp == &p_syn)
7296 {
7297 if (!valid_filetype(*varp))
7298 errmsg = e_invarg;
7299 }
7300#endif
7301
Bram Moolenaar071d4272004-06-13 20:20:40 +00007302 /* Options that are a list of flags. */
7303 else
7304 {
7305 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007306 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007307 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007308 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007309 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007310 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007312 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007314#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007315 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007316 p = (char_u *)COCU_ALL;
7317#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007318 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007319 {
7320#ifdef FEAT_MOUSE
7321 p = (char_u *)MOUSE_ALL;
7322#else
7323 if (*p_mouse != NUL)
7324 errmsg = (char_u *)N_("E538: No mouse support");
7325#endif
7326 }
7327#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007328 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007329 p = (char_u *)GO_ALL;
7330#endif
7331 if (p != NULL)
7332 {
7333 for (s = *varp; *s; ++s)
7334 if (vim_strchr(p, *s) == NULL)
7335 {
7336 errmsg = illegal_char(errbuf, *s);
7337 break;
7338 }
7339 }
7340 }
7341
7342 /*
7343 * If error detected, restore the previous value.
7344 */
7345 if (errmsg != NULL)
7346 {
7347 if (new_value_alloced)
7348 free_string_option(*varp);
7349 *varp = oldval;
7350 /*
7351 * When resetting some values, need to act on it.
7352 */
7353 if (did_chartab)
7354 (void)init_chartab();
7355 if (varp == &p_hl)
7356 (void)highlight_changed();
7357 }
7358 else
7359 {
7360#ifdef FEAT_EVAL
7361 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007362 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007363#endif
7364 /*
7365 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007366 * Use "free_oldval", because recursiveness may change the flags under
7367 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007368 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007369 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007370 free_string_option(oldval);
7371 if (new_value_alloced)
7372 options[opt_idx].flags |= P_ALLOCED;
7373 else
7374 options[opt_idx].flags &= ~P_ALLOCED;
7375
7376 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007377 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007378 {
7379 /* global option with local value set to use global value; free
7380 * the local value and make it empty */
7381 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7382 free_string_option(*(char_u **)p);
7383 *(char_u **)p = empty_option;
7384 }
7385
7386 /* May set global value for local option. */
7387 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7388 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007389
7390#ifdef FEAT_AUTOCMD
7391 /*
7392 * Trigger the autocommand only after setting the flags.
7393 */
7394# ifdef FEAT_SYN_HL
7395 /* When 'syntax' is set, load the syntax of that name */
7396 if (varp == &(curbuf->b_p_syn))
7397 {
7398 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7399 curbuf->b_fname, TRUE, curbuf);
7400 }
7401# endif
7402 else if (varp == &(curbuf->b_p_ft))
7403 {
7404 /* 'filetype' is set, trigger the FileType autocommand */
7405 did_filetype = TRUE;
7406 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7407 curbuf->b_fname, TRUE, curbuf);
7408 }
7409#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007410#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007411 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007412 {
7413 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007414 char_u *q = curwin->w_s->b_p_spl;
7415
7416 /* Skip the first name if it is "cjk". */
7417 if (STRNCMP(q, "cjk,", 4) == 0)
7418 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007419
7420 /*
7421 * Source the spell/LANG.vim in 'runtimepath'.
7422 * They could set 'spellcapcheck' depending on the language.
7423 * Use the first name in 'spelllang' up to '_region' or
7424 * '.encoding'.
7425 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007426 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007427 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7428 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007429 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007430 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007431 }
7432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007433 }
7434
7435#ifdef FEAT_MOUSE
7436 if (varp == &p_mouse)
7437 {
7438# ifdef FEAT_MOUSE_TTY
7439 if (*p_mouse == NUL)
7440 mch_setmouse(FALSE); /* switch mouse off */
7441 else
7442# endif
7443 setmouse(); /* in case 'mouse' changed */
7444 }
7445#endif
7446
Bram Moolenaar913077c2012-03-28 19:59:04 +02007447 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007448 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007449 curwin->w_set_curswant = TRUE;
7450
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007451#ifdef FEAT_GUI
7452 /* check redraw when it's not a GUI option or the GUI is active. */
7453 if (!redraw_gui_only || gui.in_use)
7454#endif
7455 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007456
7457 return errmsg;
7458}
7459
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007460#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007461/*
7462 * Simple int comparison function for use with qsort()
7463 */
7464 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007465int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007466{
7467 return *(const int *)a - *(const int *)b;
7468}
7469
7470/*
7471 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7472 * Returns error message, NULL if it's OK.
7473 */
7474 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007475check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007476{
7477 char_u *s;
7478 int col;
7479 int count = 0;
7480 int color_cols[256];
7481 int i;
7482 int j = 0;
7483
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007484 if (wp->w_buffer == NULL)
7485 return NULL; /* buffer was closed */
7486
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007487 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007488 {
7489 if (*s == '-' || *s == '+')
7490 {
7491 /* -N and +N: add to 'textwidth' */
7492 col = (*s == '-') ? -1 : 1;
7493 ++s;
7494 if (!VIM_ISDIGIT(*s))
7495 return e_invarg;
7496 col = col * getdigits(&s);
7497 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007498 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007499 col += wp->w_buffer->b_p_tw;
7500 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007501 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007502 }
7503 else if (VIM_ISDIGIT(*s))
7504 col = getdigits(&s);
7505 else
7506 return e_invarg;
7507 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007508skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007509 if (*s == NUL)
7510 break;
7511 if (*s != ',')
7512 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007513 if (*++s == NUL)
7514 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007515 }
7516
7517 vim_free(wp->w_p_cc_cols);
7518 if (count == 0)
7519 wp->w_p_cc_cols = NULL;
7520 else
7521 {
7522 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7523 if (wp->w_p_cc_cols != NULL)
7524 {
7525 /* sort the columns for faster usage on screen redraw inside
7526 * win_line() */
7527 qsort(color_cols, count, sizeof(int), int_cmp);
7528
7529 for (i = 0; i < count; ++i)
7530 /* skip duplicates */
7531 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7532 wp->w_p_cc_cols[j++] = color_cols[i];
7533 wp->w_p_cc_cols[j] = -1; /* end marker */
7534 }
7535 }
7536
7537 return NULL; /* no error */
7538}
7539#endif
7540
Bram Moolenaar071d4272004-06-13 20:20:40 +00007541/*
7542 * Handle setting 'listchars' or 'fillchars'.
7543 * Returns error message, NULL if it's OK.
7544 */
7545 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007546set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007547{
7548 int round, i, len, entries;
7549 char_u *p, *s;
7550 int c1, c2 = 0;
7551 struct charstab
7552 {
7553 int *cp;
7554 char *name;
7555 };
7556#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7557 static struct charstab filltab[] =
7558 {
7559 {&fill_stl, "stl"},
7560 {&fill_stlnc, "stlnc"},
7561 {&fill_vert, "vert"},
7562 {&fill_fold, "fold"},
7563 {&fill_diff, "diff"},
7564 };
7565#endif
7566 static struct charstab lcstab[] =
7567 {
7568 {&lcs_eol, "eol"},
7569 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007570 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007571 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007572 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007573 {&lcs_tab2, "tab"},
7574 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007575#ifdef FEAT_CONCEAL
7576 {&lcs_conceal, "conceal"},
7577#else
7578 {NULL, "conceal"},
7579#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007580 };
7581 struct charstab *tab;
7582
7583#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7584 if (varp == &p_lcs)
7585#endif
7586 {
7587 tab = lcstab;
7588 entries = sizeof(lcstab) / sizeof(struct charstab);
7589 }
7590#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7591 else
7592 {
7593 tab = filltab;
7594 entries = sizeof(filltab) / sizeof(struct charstab);
7595 }
7596#endif
7597
7598 /* first round: check for valid value, second round: assign values */
7599 for (round = 0; round <= 1; ++round)
7600 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007601 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007602 {
7603 /* After checking that the value is valid: set defaults: space for
7604 * 'fillchars', NUL for 'listchars' */
7605 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007606 if (tab[i].cp != NULL)
7607 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007608 if (varp == &p_lcs)
7609 lcs_tab1 = NUL;
7610#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7611 else
7612 fill_diff = '-';
7613#endif
7614 }
7615 p = *varp;
7616 while (*p)
7617 {
7618 for (i = 0; i < entries; ++i)
7619 {
7620 len = (int)STRLEN(tab[i].name);
7621 if (STRNCMP(p, tab[i].name, len) == 0
7622 && p[len] == ':'
7623 && p[len + 1] != NUL)
7624 {
7625 s = p + len + 1;
7626#ifdef FEAT_MBYTE
7627 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007628 if (mb_char2cells(c1) > 1)
7629 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007630#else
7631 c1 = *s++;
7632#endif
7633 if (tab[i].cp == &lcs_tab2)
7634 {
7635 if (*s == NUL)
7636 continue;
7637#ifdef FEAT_MBYTE
7638 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007639 if (mb_char2cells(c2) > 1)
7640 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007641#else
7642 c2 = *s++;
7643#endif
7644 }
7645 if (*s == ',' || *s == NUL)
7646 {
7647 if (round)
7648 {
7649 if (tab[i].cp == &lcs_tab2)
7650 {
7651 lcs_tab1 = c1;
7652 lcs_tab2 = c2;
7653 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007654 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007655 *(tab[i].cp) = c1;
7656
7657 }
7658 p = s;
7659 break;
7660 }
7661 }
7662 }
7663
7664 if (i == entries)
7665 return e_invarg;
7666 if (*p == ',')
7667 ++p;
7668 }
7669 }
7670
7671 return NULL; /* no error */
7672}
7673
7674#ifdef FEAT_STL_OPT
7675/*
7676 * Check validity of options with the 'statusline' format.
7677 * Return error message or NULL.
7678 */
7679 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007680check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007681{
7682 int itemcnt = 0;
7683 int groupdepth = 0;
7684 static char_u errbuf[80];
7685
7686 while (*s && itemcnt < STL_MAX_ITEM)
7687 {
7688 /* Check for valid keys after % sequences */
7689 while (*s && *s != '%')
7690 s++;
7691 if (!*s)
7692 break;
7693 s++;
7694 if (*s != '%' && *s != ')')
7695 ++itemcnt;
7696 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7697 {
7698 s++;
7699 continue;
7700 }
7701 if (*s == ')')
7702 {
7703 s++;
7704 if (--groupdepth < 0)
7705 break;
7706 continue;
7707 }
7708 if (*s == '-')
7709 s++;
7710 while (VIM_ISDIGIT(*s))
7711 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007712 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 continue;
7714 if (*s == '.')
7715 {
7716 s++;
7717 while (*s && VIM_ISDIGIT(*s))
7718 s++;
7719 }
7720 if (*s == '(')
7721 {
7722 groupdepth++;
7723 continue;
7724 }
7725 if (vim_strchr(STL_ALL, *s) == NULL)
7726 {
7727 return illegal_char(errbuf, *s);
7728 }
7729 if (*s == '{')
7730 {
7731 s++;
7732 while (*s != '}' && *s)
7733 s++;
7734 if (*s != '}')
7735 return (char_u *)N_("E540: Unclosed expression sequence");
7736 }
7737 }
7738 if (itemcnt >= STL_MAX_ITEM)
7739 return (char_u *)N_("E541: too many items");
7740 if (groupdepth != 0)
7741 return (char_u *)N_("E542: unbalanced groups");
7742 return NULL;
7743}
7744#endif
7745
7746#ifdef FEAT_CLIPBOARD
7747/*
7748 * Extract the items in the 'clipboard' option and set global values.
7749 */
7750 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007751check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007752{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007753 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007754 int new_autoselect_star = FALSE;
7755 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007756 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007757 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007758 regprog_T *new_exclude_prog = NULL;
7759 char_u *errmsg = NULL;
7760 char_u *p;
7761
7762 for (p = p_cb; *p != NUL; )
7763 {
7764 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7765 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007766 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007767 p += 7;
7768 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007769 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007770 && (p[11] == ',' || p[11] == NUL))
7771 {
7772 new_unnamed |= CLIP_UNNAMED_PLUS;
7773 p += 11;
7774 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007775 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007776 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007777 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007778 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007779 p += 10;
7780 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007781 else if (STRNCMP(p, "autoselectplus", 14) == 0
7782 && (p[14] == ',' || p[14] == NUL))
7783 {
7784 new_autoselect_plus = TRUE;
7785 p += 14;
7786 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007787 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007788 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007789 {
7790 new_autoselectml = TRUE;
7791 p += 12;
7792 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007793 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7794 {
7795 new_html = TRUE;
7796 p += 4;
7797 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7799 {
7800 p += 8;
7801 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7802 if (new_exclude_prog == NULL)
7803 errmsg = e_invarg;
7804 break;
7805 }
7806 else
7807 {
7808 errmsg = e_invarg;
7809 break;
7810 }
7811 if (*p == ',')
7812 ++p;
7813 }
7814 if (errmsg == NULL)
7815 {
7816 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007817 clip_autoselect_star = new_autoselect_star;
7818 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007820 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007821 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007822 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007823#ifdef FEAT_GUI_GTK
7824 if (gui.in_use)
7825 {
7826 gui_gtk_set_selection_targets();
7827 gui_gtk_set_dnd_targets();
7828 }
7829#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007830 }
7831 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007832 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007833
7834 return errmsg;
7835}
7836#endif
7837
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007838#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007839 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007840did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007841{
7842 char_u *errmsg = NULL;
7843 win_T *wp;
7844 int l;
7845
7846 if (is_spellfile)
7847 {
7848 l = (int)STRLEN(curwin->w_s->b_p_spf);
7849 if (l > 0 && (l < 4
7850 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7851 errmsg = e_invarg;
7852 }
7853
7854 if (errmsg == NULL)
7855 {
7856 FOR_ALL_WINDOWS(wp)
7857 if (wp->w_buffer == curbuf && wp->w_p_spell)
7858 {
7859 errmsg = did_set_spelllang(wp);
7860# ifdef FEAT_WINDOWS
7861 break;
7862# endif
7863 }
7864 }
7865 return errmsg;
7866}
7867
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007868/*
7869 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7870 * Return error message when failed, NULL when OK.
7871 */
7872 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007873compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007874{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007875 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007876 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007877
Bram Moolenaar860cae12010-06-05 23:22:07 +02007878 if (*synblock->b_p_spc == NUL)
7879 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007880 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007881 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007882 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007883 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007884 if (re != NULL)
7885 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007886 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007887 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007888 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007889 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007890 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007891 return e_invarg;
7892 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007893 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007894 }
7895
Bram Moolenaar473de612013-06-08 18:19:48 +02007896 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007897 return NULL;
7898}
7899#endif
7900
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007901#if defined(FEAT_EVAL) || defined(PROTO)
7902/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007903 * Set the scriptID for an option, taking care of setting the buffer- or
7904 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007905 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007906 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007907set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007908{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007909 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7910 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007911
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007912 /* Remember where the option was set. For local options need to do that
7913 * in the buffer or window structure. */
7914 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007915 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007916 if (both || (opt_flags & OPT_LOCAL))
7917 {
7918 if (indir & PV_BUF)
7919 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7920 else if (indir & PV_WIN)
7921 curwin->w_p_scriptID[indir & PV_MASK] = id;
7922 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007923}
7924#endif
7925
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926/*
7927 * Set the value of a boolean option, and take care of side effects.
7928 * Returns NULL for success, or an error message for an error.
7929 */
7930 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007931set_bool_option(
7932 int opt_idx, /* index in options[] table */
7933 char_u *varp, /* pointer to the option variable */
7934 int value, /* new value */
7935 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936{
7937 int old_value = *(int *)varp;
7938
Bram Moolenaar071d4272004-06-13 20:20:40 +00007939 /* Disallow changing some options from secure mode */
7940 if ((secure
7941#ifdef HAVE_SANDBOX
7942 || sandbox != 0
7943#endif
7944 ) && (options[opt_idx].flags & P_SECURE))
7945 return e_secure;
7946
7947 *(int *)varp = value; /* set the new value */
7948#ifdef FEAT_EVAL
7949 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007950 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007951#endif
7952
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007953#ifdef FEAT_GUI
7954 need_mouse_correct = TRUE;
7955#endif
7956
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957 /* May set global value for local option. */
7958 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7959 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7960
7961 /*
7962 * Handle side effects of changing a bool option.
7963 */
7964
7965 /* 'compatible' */
7966 if ((int *)varp == &p_cp)
7967 {
7968 compatible_set();
7969 }
7970
Bram Moolenaar920694c2016-08-21 17:45:02 +02007971#ifdef FEAT_LANGMAP
7972 if ((int *)varp == &p_lrm)
7973 /* 'langremap' -> !'langnoremap' */
7974 p_lnr = !p_lrm;
7975 else if ((int *)varp == &p_lnr)
7976 /* 'langnoremap' -> !'langremap' */
7977 p_lrm = !p_lnr;
7978#endif
7979
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007980#ifdef FEAT_PERSISTENT_UNDO
7981 /* 'undofile' */
7982 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7983 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007984 /* Only take action when the option was set. When reset we do not
7985 * delete the undo file, the option may be set again without making
7986 * any changes in between. */
7987 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007988 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007989 char_u hash[UNDO_HASH_SIZE];
7990 buf_T *save_curbuf = curbuf;
7991
Bram Moolenaar29323592016-07-24 22:04:11 +02007992 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007993 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007994 /* When 'undofile' is set globally: for every buffer, otherwise
7995 * only for the current buffer: Try to read in the undofile,
7996 * if one exists, the buffer wasn't changed and the buffer was
7997 * loaded */
7998 if ((curbuf == save_curbuf
7999 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8000 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8001 {
8002 u_compute_hash(hash);
8003 u_read_undo(NULL, hash, curbuf->b_fname);
8004 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008005 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008006 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008007 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008008 }
8009#endif
8010
Bram Moolenaar071d4272004-06-13 20:20:40 +00008011 else if ((int *)varp == &curbuf->b_p_ro)
8012 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008013 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8015 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008016
8017 /* when 'readonly' is set may give W10 again */
8018 if (curbuf->b_p_ro)
8019 curbuf->b_did_warn = FALSE;
8020
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008022 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008023#endif
8024 }
8025
Bram Moolenaar9c449722010-07-20 18:44:27 +02008026#ifdef FEAT_GUI
8027 else if ((int *)varp == &p_mh)
8028 {
8029 if (!p_mh)
8030 gui_mch_mousehide(FALSE);
8031 }
8032#endif
8033
Bram Moolenaara539df02010-08-01 14:35:05 +02008034#ifdef FEAT_TITLE
8035 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008036 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008037 {
8038 redraw_titles();
8039 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008040 /* when 'endofline' is changed, redraw the window title */
8041 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008042 {
8043 redraw_titles();
8044 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008045 /* when 'fixeol' is changed, redraw the window title */
8046 else if ((int *)varp == &curbuf->b_p_fixeol)
8047 {
8048 redraw_titles();
8049 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008050# ifdef FEAT_MBYTE
8051 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008052 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008053 {
8054 redraw_titles();
8055 }
8056# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008057#endif
8058
8059 /* when 'bin' is set also set some other options */
8060 else if ((int *)varp == &curbuf->b_p_bin)
8061 {
8062 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8063#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008064 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008065#endif
8066 }
8067
8068#ifdef FEAT_AUTOCMD
8069 /* when 'buflisted' changes, trigger autocommands */
8070 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8071 {
8072 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8073 NULL, NULL, TRUE, curbuf);
8074 }
8075#endif
8076
8077 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8078 else if ((int *)varp == &curbuf->b_p_swf)
8079 {
8080 if (curbuf->b_p_swf && p_uc)
8081 ml_open_file(curbuf); /* create the swap file */
8082 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008083 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8084 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 mf_close_file(curbuf, TRUE); /* remove the swap file */
8086 }
8087
8088 /* when 'terse' is set change 'shortmess' */
8089 else if ((int *)varp == &p_terse)
8090 {
8091 char_u *p;
8092
8093 p = vim_strchr(p_shm, SHM_SEARCH);
8094
8095 /* insert 's' in p_shm */
8096 if (p_terse && p == NULL)
8097 {
8098 STRCPY(IObuff, p_shm);
8099 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008100 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008101 }
8102 /* remove 's' from p_shm */
8103 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008104 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008105 }
8106
8107 /* when 'paste' is set or reset also change other options */
8108 else if ((int *)varp == &p_paste)
8109 {
8110 paste_option_changed();
8111 }
8112
8113 /* when 'insertmode' is set from an autocommand need to do work here */
8114 else if ((int *)varp == &p_im)
8115 {
8116 if (p_im)
8117 {
8118 if ((State & INSERT) == 0)
8119 need_start_insertmode = TRUE;
8120 stop_insert_mode = FALSE;
8121 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008122 /* only reset if it was set previously */
8123 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 {
8125 need_start_insertmode = FALSE;
8126 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008127 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128 clear_cmdline = TRUE; /* remove "(insert)" */
8129 restart_edit = 0;
8130 }
8131 }
8132
8133 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8134 else if ((int *)varp == &p_ic && p_hls)
8135 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008136 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137 }
8138
8139#ifdef FEAT_SEARCH_EXTRA
8140 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8141 else if ((int *)varp == &p_hls)
8142 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008143 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144 }
8145#endif
8146
8147#ifdef FEAT_SCROLLBIND
8148 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8149 * at the end of normal_cmd() */
8150 else if ((int *)varp == &curwin->w_p_scb)
8151 {
8152 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008153 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008154 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008155 curwin->w_scbind_pos = curwin->w_topline;
8156 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 }
8158#endif
8159
8160#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8161 /* There can be only one window with 'previewwindow' set. */
8162 else if ((int *)varp == &curwin->w_p_pvw)
8163 {
8164 if (curwin->w_p_pvw)
8165 {
8166 win_T *win;
8167
Bram Moolenaar29323592016-07-24 22:04:11 +02008168 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 if (win->w_p_pvw && win != curwin)
8170 {
8171 curwin->w_p_pvw = FALSE;
8172 return (char_u *)N_("E590: A preview window already exists");
8173 }
8174 }
8175 }
8176#endif
8177
8178 /* when 'textmode' is set or reset also change 'fileformat' */
8179 else if ((int *)varp == &curbuf->b_p_tx)
8180 {
8181 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8182 }
8183
8184 /* when 'textauto' is set or reset also change 'fileformats' */
8185 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008186 set_string_option_direct((char_u *)"ffs", -1,
8187 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008188 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008189
8190 /*
8191 * When 'lisp' option changes include/exclude '-' in
8192 * keyword characters.
8193 */
8194#ifdef FEAT_LISP
8195 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8196 {
8197 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8198 }
8199#endif
8200
8201#ifdef FEAT_TITLE
8202 /* when 'title' changed, may need to change the title; same for 'icon' */
8203 else if ((int *)varp == &p_title)
8204 {
8205 did_set_title(FALSE);
8206 }
8207
8208 else if ((int *)varp == &p_icon)
8209 {
8210 did_set_title(TRUE);
8211 }
8212#endif
8213
8214 else if ((int *)varp == &curbuf->b_changed)
8215 {
8216 if (!value)
8217 save_file_ff(curbuf); /* Buffer is unchanged */
8218#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008219 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008220#endif
8221#ifdef FEAT_AUTOCMD
8222 modified_was_set = value;
8223#endif
8224 }
8225
8226#ifdef BACKSLASH_IN_FILENAME
8227 else if ((int *)varp == &p_ssl)
8228 {
8229 if (p_ssl)
8230 {
8231 psepc = '/';
8232 psepcN = '\\';
8233 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008234 }
8235 else
8236 {
8237 psepc = '\\';
8238 psepcN = '/';
8239 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008240 }
8241
8242 /* need to adjust the file name arguments and buffer names. */
8243 buflist_slash_adjust();
8244 alist_slash_adjust();
8245# ifdef FEAT_EVAL
8246 scriptnames_slash_adjust();
8247# endif
8248 }
8249#endif
8250
8251 /* If 'wrap' is set, set w_leftcol to zero. */
8252 else if ((int *)varp == &curwin->w_p_wrap)
8253 {
8254 if (curwin->w_p_wrap)
8255 curwin->w_leftcol = 0;
8256 }
8257
8258#ifdef FEAT_WINDOWS
8259 else if ((int *)varp == &p_ea)
8260 {
8261 if (p_ea && !old_value)
8262 win_equal(curwin, FALSE, 0);
8263 }
8264#endif
8265
8266 else if ((int *)varp == &p_wiv)
8267 {
8268 /*
8269 * When 'weirdinvert' changed, set/reset 't_xs'.
8270 * Then set 'weirdinvert' according to value of 't_xs'.
8271 */
8272 if (p_wiv && !old_value)
8273 T_XS = (char_u *)"y";
8274 else if (!p_wiv && old_value)
8275 T_XS = empty_option;
8276 p_wiv = (*T_XS != NUL);
8277 }
8278
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008279#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008280 else if ((int *)varp == &p_beval)
8281 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008282 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008283 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008284 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008285 gui_mch_disable_beval_area(balloonEval);
8286 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008287#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008288
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008289#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 else if ((int *)varp == &p_acd)
8291 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008292 /* Change directories when the 'acd' option is set now. */
8293 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008294 }
8295#endif
8296
8297#ifdef FEAT_DIFF
8298 /* 'diff' */
8299 else if ((int *)varp == &curwin->w_p_diff)
8300 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008301 /* May add or remove the buffer from the list of diff buffers. */
8302 diff_buf_adjust(curwin);
8303# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008304 if (foldmethodIsDiff(curwin))
8305 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008306# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008307 }
8308#endif
8309
8310#ifdef USE_IM_CONTROL
8311 /* 'imdisable' */
8312 else if ((int *)varp == &p_imdisable)
8313 {
8314 /* Only de-activate it here, it will be enabled when changing mode. */
8315 if (p_imdisable)
8316 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008317 else if (State & INSERT)
8318 /* When the option is set from an autocommand, it may need to take
8319 * effect right away. */
8320 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008321 }
8322#endif
8323
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008324#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008325 /* 'spell' */
8326 else if ((int *)varp == &curwin->w_p_spell)
8327 {
8328 if (curwin->w_p_spell)
8329 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008330 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008331 if (errmsg != NULL)
8332 EMSG(_(errmsg));
8333 }
8334 }
8335#endif
8336
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337#ifdef FEAT_FKMAP
8338 else if ((int *)varp == &p_altkeymap)
8339 {
8340 if (old_value != p_altkeymap)
8341 {
8342 if (!p_altkeymap)
8343 {
8344 p_hkmap = p_fkmap;
8345 p_fkmap = 0;
8346 }
8347 else
8348 {
8349 p_fkmap = p_hkmap;
8350 p_hkmap = 0;
8351 }
8352 (void)init_chartab();
8353 }
8354 }
8355
8356 /*
8357 * In case some second language keymapping options have changed, check
8358 * and correct the setting in a consistent way.
8359 */
8360
8361 /*
8362 * If hkmap or fkmap are set, reset Arabic keymapping.
8363 */
8364 if ((p_hkmap || p_fkmap) && p_altkeymap)
8365 {
8366 p_altkeymap = p_fkmap;
8367# ifdef FEAT_ARABIC
8368 curwin->w_p_arab = FALSE;
8369# endif
8370 (void)init_chartab();
8371 }
8372
8373 /*
8374 * If hkmap set, reset Farsi keymapping.
8375 */
8376 if (p_hkmap && p_altkeymap)
8377 {
8378 p_altkeymap = 0;
8379 p_fkmap = 0;
8380# ifdef FEAT_ARABIC
8381 curwin->w_p_arab = FALSE;
8382# endif
8383 (void)init_chartab();
8384 }
8385
8386 /*
8387 * If fkmap set, reset Hebrew keymapping.
8388 */
8389 if (p_fkmap && !p_altkeymap)
8390 {
8391 p_altkeymap = 1;
8392 p_hkmap = 0;
8393# ifdef FEAT_ARABIC
8394 curwin->w_p_arab = FALSE;
8395# endif
8396 (void)init_chartab();
8397 }
8398#endif
8399
8400#ifdef FEAT_ARABIC
8401 if ((int *)varp == &curwin->w_p_arab)
8402 {
8403 if (curwin->w_p_arab)
8404 {
8405 /*
8406 * 'arabic' is set, handle various sub-settings.
8407 */
8408 if (!p_tbidi)
8409 {
8410 /* set rightleft mode */
8411 if (!curwin->w_p_rl)
8412 {
8413 curwin->w_p_rl = TRUE;
8414 changed_window_setting();
8415 }
8416
8417 /* Enable Arabic shaping (major part of what Arabic requires) */
8418 if (!p_arshape)
8419 {
8420 p_arshape = TRUE;
8421 redraw_later_clear();
8422 }
8423 }
8424
8425 /* Arabic requires a utf-8 encoding, inform the user if its not
8426 * set. */
8427 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008428 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008429 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8430
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008431 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008432 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8433#ifdef FEAT_EVAL
8434 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8435#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008436 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437
8438# ifdef FEAT_MBYTE
8439 /* set 'delcombine' */
8440 p_deco = TRUE;
8441# endif
8442
8443# ifdef FEAT_KEYMAP
8444 /* Force-set the necessary keymap for arabic */
8445 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8446 OPT_LOCAL);
8447# endif
8448# ifdef FEAT_FKMAP
8449 p_altkeymap = 0;
8450 p_hkmap = 0;
8451 p_fkmap = 0;
8452 (void)init_chartab();
8453# endif
8454 }
8455 else
8456 {
8457 /*
8458 * 'arabic' is reset, handle various sub-settings.
8459 */
8460 if (!p_tbidi)
8461 {
8462 /* reset rightleft mode */
8463 if (curwin->w_p_rl)
8464 {
8465 curwin->w_p_rl = FALSE;
8466 changed_window_setting();
8467 }
8468
8469 /* 'arabicshape' isn't reset, it is a global option and
8470 * another window may still need it "on". */
8471 }
8472
8473 /* 'delcombine' isn't reset, it is a global option and another
8474 * window may still want it "on". */
8475
8476# ifdef FEAT_KEYMAP
8477 /* Revert to the default keymap */
8478 curbuf->b_p_iminsert = B_IMODE_NONE;
8479 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8480# endif
8481 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008482 }
8483
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008484#endif
8485
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008486#ifdef FEAT_TERMGUICOLORS
8487 /* 'termguicolors' */
8488 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008489 {
8490# ifdef FEAT_GUI
8491 if (!gui.in_use && !gui.starting)
8492# endif
8493 highlight_gui_started();
8494 }
8495#endif
8496
Bram Moolenaar071d4272004-06-13 20:20:40 +00008497 /*
8498 * End of handling side effects for bool options.
8499 */
8500
Bram Moolenaar53744302015-07-17 17:38:22 +02008501 /* after handling side effects, call autocommand */
8502
Bram Moolenaar071d4272004-06-13 20:20:40 +00008503 options[opt_idx].flags |= P_WAS_SET;
8504
Bram Moolenaar53744302015-07-17 17:38:22 +02008505#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8506 if (!starting)
8507 {
8508 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008509 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8510 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8511 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008512 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8513 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8514 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8515 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8516 reset_v_option_vars();
8517 }
8518#endif
8519
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008521 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008522 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008523 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008524 check_redraw(options[opt_idx].flags);
8525
8526 return NULL;
8527}
8528
8529/*
8530 * Set the value of a number option, and take care of side effects.
8531 * Returns NULL for success, or an error message for an error.
8532 */
8533 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008534set_num_option(
8535 int opt_idx, /* index in options[] table */
8536 char_u *varp, /* pointer to the option variable */
8537 long value, /* new value */
8538 char_u *errbuf, /* buffer for error messages */
8539 size_t errbuflen, /* length of "errbuf" */
8540 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008541 OPT_MODELINE */
8542{
8543 char_u *errmsg = NULL;
8544 long old_value = *(long *)varp;
8545 long old_Rows = Rows; /* remember old Rows */
8546 long old_Columns = Columns; /* remember old Columns */
8547 long *pp = (long *)varp;
8548
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008549 /* Disallow changing some options from secure mode. */
8550 if ((secure
8551#ifdef HAVE_SANDBOX
8552 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008553#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008554 ) && (options[opt_idx].flags & P_SECURE))
8555 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008556
8557 *pp = value;
8558#ifdef FEAT_EVAL
8559 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008560 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008562#ifdef FEAT_GUI
8563 need_mouse_correct = TRUE;
8564#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008565
Bram Moolenaar14f24742012-08-08 18:01:05 +02008566 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567 {
8568 errmsg = e_positive;
8569 curbuf->b_p_sw = curbuf->b_p_ts;
8570 }
8571
8572 /*
8573 * Number options that need some action when changed
8574 */
8575#ifdef FEAT_WINDOWS
8576 if (pp == &p_wh || pp == &p_hh)
8577 {
8578 if (p_wh < 1)
8579 {
8580 errmsg = e_positive;
8581 p_wh = 1;
8582 }
8583 if (p_wmh > p_wh)
8584 {
8585 errmsg = e_winheight;
8586 p_wh = p_wmh;
8587 }
8588 if (p_hh < 0)
8589 {
8590 errmsg = e_positive;
8591 p_hh = 0;
8592 }
8593
8594 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008595 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596 {
8597 if (pp == &p_wh && curwin->w_height < p_wh)
8598 win_setheight((int)p_wh);
8599 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8600 win_setheight((int)p_hh);
8601 }
8602 }
8603
8604 /* 'winminheight' */
8605 else if (pp == &p_wmh)
8606 {
8607 if (p_wmh < 0)
8608 {
8609 errmsg = e_positive;
8610 p_wmh = 0;
8611 }
8612 if (p_wmh > p_wh)
8613 {
8614 errmsg = e_winheight;
8615 p_wmh = p_wh;
8616 }
8617 win_setminheight();
8618 }
8619
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008620# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008621 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622 {
8623 if (p_wiw < 1)
8624 {
8625 errmsg = e_positive;
8626 p_wiw = 1;
8627 }
8628 if (p_wmw > p_wiw)
8629 {
8630 errmsg = e_winwidth;
8631 p_wiw = p_wmw;
8632 }
8633
8634 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008635 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636 win_setwidth((int)p_wiw);
8637 }
8638
8639 /* 'winminwidth' */
8640 else if (pp == &p_wmw)
8641 {
8642 if (p_wmw < 0)
8643 {
8644 errmsg = e_positive;
8645 p_wmw = 0;
8646 }
8647 if (p_wmw > p_wiw)
8648 {
8649 errmsg = e_winwidth;
8650 p_wmw = p_wiw;
8651 }
8652 win_setminheight();
8653 }
8654# endif
8655
8656#endif
8657
8658#ifdef FEAT_WINDOWS
8659 /* (re)set last window status line */
8660 else if (pp == &p_ls)
8661 {
8662 last_status(FALSE);
8663 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008664
8665 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008666 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008667 {
8668 shell_new_rows(); /* recompute window positions and heights */
8669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008670#endif
8671
8672#ifdef FEAT_GUI
8673 else if (pp == &p_linespace)
8674 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008675 /* Recompute gui.char_height and resize the Vim window to keep the
8676 * same number of lines. */
8677 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008678 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008679 }
8680#endif
8681
8682#ifdef FEAT_FOLDING
8683 /* 'foldlevel' */
8684 else if (pp == &curwin->w_p_fdl)
8685 {
8686 if (curwin->w_p_fdl < 0)
8687 curwin->w_p_fdl = 0;
8688 newFoldLevel();
8689 }
8690
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008691 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008692 else if (pp == &curwin->w_p_fml)
8693 {
8694 foldUpdateAll(curwin);
8695 }
8696
8697 /* 'foldnestmax' */
8698 else if (pp == &curwin->w_p_fdn)
8699 {
8700 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8701 foldUpdateAll(curwin);
8702 }
8703
8704 /* 'foldcolumn' */
8705 else if (pp == &curwin->w_p_fdc)
8706 {
8707 if (curwin->w_p_fdc < 0)
8708 {
8709 errmsg = e_positive;
8710 curwin->w_p_fdc = 0;
8711 }
8712 else if (curwin->w_p_fdc > 12)
8713 {
8714 errmsg = e_invarg;
8715 curwin->w_p_fdc = 12;
8716 }
8717 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008718#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008719
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008720#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721 /* 'shiftwidth' or 'tabstop' */
8722 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8723 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008724# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008725 if (foldmethodIsIndent(curwin))
8726 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008727# endif
8728# ifdef FEAT_CINDENT
8729 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8730 * parse 'cinoptions'. */
8731 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8732 parse_cino(curbuf);
8733# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008734 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008735#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008736
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008737#ifdef FEAT_MBYTE
8738 /* 'maxcombine' */
8739 else if (pp == &p_mco)
8740 {
8741 if (p_mco > MAX_MCO)
8742 p_mco = MAX_MCO;
8743 else if (p_mco < 0)
8744 p_mco = 0;
8745 screenclear(); /* will re-allocate the screen */
8746 }
8747#endif
8748
Bram Moolenaar071d4272004-06-13 20:20:40 +00008749 else if (pp == &curbuf->b_p_iminsert)
8750 {
8751 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8752 {
8753 errmsg = e_invarg;
8754 curbuf->b_p_iminsert = B_IMODE_NONE;
8755 }
8756 p_iminsert = curbuf->b_p_iminsert;
8757 if (termcap_active) /* don't do this in the alternate screen */
8758 showmode();
8759#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8760 /* Show/unshow value of 'keymap' in status lines. */
8761 status_redraw_curbuf();
8762#endif
8763 }
8764
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008765 else if (pp == &p_window)
8766 {
8767 if (p_window < 1)
8768 p_window = 1;
8769 else if (p_window >= Rows)
8770 p_window = Rows - 1;
8771 }
8772
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773 else if (pp == &curbuf->b_p_imsearch)
8774 {
8775 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8776 {
8777 errmsg = e_invarg;
8778 curbuf->b_p_imsearch = B_IMODE_NONE;
8779 }
8780 p_imsearch = curbuf->b_p_imsearch;
8781 }
8782
8783#ifdef FEAT_TITLE
8784 /* if 'titlelen' has changed, redraw the title */
8785 else if (pp == &p_titlelen)
8786 {
8787 if (p_titlelen < 0)
8788 {
8789 errmsg = e_positive;
8790 p_titlelen = 85;
8791 }
8792 if (starting != NO_SCREEN && old_value != p_titlelen)
8793 need_maketitle = TRUE;
8794 }
8795#endif
8796
8797 /* if p_ch changed value, change the command line height */
8798 else if (pp == &p_ch)
8799 {
8800 if (p_ch < 1)
8801 {
8802 errmsg = e_positive;
8803 p_ch = 1;
8804 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008805 if (p_ch > Rows - min_rows() + 1)
8806 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807
8808 /* Only compute the new window layout when startup has been
8809 * completed. Otherwise the frame sizes may be wrong. */
8810 if (p_ch != old_value && full_screen
8811#ifdef FEAT_GUI
8812 && !gui.starting
8813#endif
8814 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008815 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008816 }
8817
8818 /* when 'updatecount' changes from zero to non-zero, open swap files */
8819 else if (pp == &p_uc)
8820 {
8821 if (p_uc < 0)
8822 {
8823 errmsg = e_positive;
8824 p_uc = 100;
8825 }
8826 if (p_uc && !old_value)
8827 ml_open_files();
8828 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008829#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008830 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008831 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008832 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008833 {
8834 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008835 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008836 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008837 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008838 {
8839 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008840 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008841 }
8842 }
8843#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008844#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008845 else if (pp == &p_mzq)
8846 mzvim_reset_timer();
8847#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008849#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8850 /* 'pyxversion' */
8851 else if (pp == &p_pyx)
8852 {
8853 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8854 errmsg = e_invarg;
8855 }
8856#endif
8857
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858 /* sync undo before 'undolevels' changes */
8859 else if (pp == &p_ul)
8860 {
8861 /* use the old value, otherwise u_sync() may not work properly */
8862 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008863 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864 p_ul = value;
8865 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008866 else if (pp == &curbuf->b_p_ul)
8867 {
8868 /* use the old value, otherwise u_sync() may not work properly */
8869 curbuf->b_p_ul = old_value;
8870 u_sync(TRUE);
8871 curbuf->b_p_ul = value;
8872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008873
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008874#ifdef FEAT_LINEBREAK
8875 /* 'numberwidth' must be positive */
8876 else if (pp == &curwin->w_p_nuw)
8877 {
8878 if (curwin->w_p_nuw < 1)
8879 {
8880 errmsg = e_positive;
8881 curwin->w_p_nuw = 1;
8882 }
8883 if (curwin->w_p_nuw > 10)
8884 {
8885 errmsg = e_invarg;
8886 curwin->w_p_nuw = 10;
8887 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008888 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008889 }
8890#endif
8891
Bram Moolenaar1a384422010-07-14 19:53:30 +02008892 else if (pp == &curbuf->b_p_tw)
8893 {
8894 if (curbuf->b_p_tw < 0)
8895 {
8896 errmsg = e_positive;
8897 curbuf->b_p_tw = 0;
8898 }
8899#ifdef FEAT_SYN_HL
8900# ifdef FEAT_WINDOWS
8901 {
8902 win_T *wp;
8903 tabpage_T *tp;
8904
8905 FOR_ALL_TAB_WINDOWS(tp, wp)
8906 check_colorcolumn(wp);
8907 }
8908# else
8909 check_colorcolumn(curwin);
8910# endif
8911#endif
8912 }
8913
Bram Moolenaar071d4272004-06-13 20:20:40 +00008914 /*
8915 * Check the bounds for numeric options here
8916 */
8917 if (Rows < min_rows() && full_screen)
8918 {
8919 if (errbuf != NULL)
8920 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008921 vim_snprintf((char *)errbuf, errbuflen,
8922 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923 errmsg = errbuf;
8924 }
8925 Rows = min_rows();
8926 }
8927 if (Columns < MIN_COLUMNS && full_screen)
8928 {
8929 if (errbuf != NULL)
8930 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008931 vim_snprintf((char *)errbuf, errbuflen,
8932 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008933 errmsg = errbuf;
8934 }
8935 Columns = MIN_COLUMNS;
8936 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008937 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008938
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 /*
8940 * If the screen (shell) height has been changed, assume it is the
8941 * physical screenheight.
8942 */
8943 if (old_Rows != Rows || old_Columns != Columns)
8944 {
8945 /* Changing the screen size is not allowed while updating the screen. */
8946 if (updating_screen)
8947 *pp = old_value;
8948 else if (full_screen
8949#ifdef FEAT_GUI
8950 && !gui.starting
8951#endif
8952 )
8953 set_shellsize((int)Columns, (int)Rows, TRUE);
8954 else
8955 {
8956 /* Postpone the resizing; check the size and cmdline position for
8957 * messages. */
8958 check_shellsize();
8959 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8960 cmdline_row = Rows - p_ch;
8961 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008962 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008963 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008964 }
8965
Bram Moolenaar071d4272004-06-13 20:20:40 +00008966 if (curbuf->b_p_ts <= 0)
8967 {
8968 errmsg = e_positive;
8969 curbuf->b_p_ts = 8;
8970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008971 if (p_tm < 0)
8972 {
8973 errmsg = e_positive;
8974 p_tm = 0;
8975 }
8976 if ((curwin->w_p_scr <= 0
8977 || (curwin->w_p_scr > curwin->w_height
8978 && curwin->w_height > 0))
8979 && full_screen)
8980 {
8981 if (pp == &(curwin->w_p_scr))
8982 {
8983 if (curwin->w_p_scr != 0)
8984 errmsg = e_scroll;
8985 win_comp_scroll(curwin);
8986 }
8987 /* If 'scroll' became invalid because of a side effect silently adjust
8988 * it. */
8989 else if (curwin->w_p_scr <= 0)
8990 curwin->w_p_scr = 1;
8991 else /* curwin->w_p_scr > curwin->w_height */
8992 curwin->w_p_scr = curwin->w_height;
8993 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008994 if (p_hi < 0)
8995 {
8996 errmsg = e_positive;
8997 p_hi = 0;
8998 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008999 else if (p_hi > 10000)
9000 {
9001 errmsg = e_invarg;
9002 p_hi = 10000;
9003 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009004 if (p_re < 0 || p_re > 2)
9005 {
9006 errmsg = e_invarg;
9007 p_re = 0;
9008 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009009 if (p_report < 0)
9010 {
9011 errmsg = e_positive;
9012 p_report = 1;
9013 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009014 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009015 {
9016 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9017 p_sj = Rows / 2;
9018 else
9019 {
9020 errmsg = e_scroll;
9021 p_sj = 1;
9022 }
9023 }
9024 if (p_so < 0 && full_screen)
9025 {
9026 errmsg = e_scroll;
9027 p_so = 0;
9028 }
9029 if (p_siso < 0 && full_screen)
9030 {
9031 errmsg = e_positive;
9032 p_siso = 0;
9033 }
9034#ifdef FEAT_CMDWIN
9035 if (p_cwh < 1)
9036 {
9037 errmsg = e_positive;
9038 p_cwh = 1;
9039 }
9040#endif
9041 if (p_ut < 0)
9042 {
9043 errmsg = e_positive;
9044 p_ut = 2000;
9045 }
9046 if (p_ss < 0)
9047 {
9048 errmsg = e_positive;
9049 p_ss = 0;
9050 }
9051
9052 /* May set global value for local option. */
9053 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9054 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9055
9056 options[opt_idx].flags |= P_WAS_SET;
9057
Bram Moolenaar53744302015-07-17 17:38:22 +02009058#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9059 if (!starting && errmsg == NULL)
9060 {
9061 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009062 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9063 vim_snprintf((char *)buf_new, 10, "%ld", value);
9064 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009065 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9066 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9067 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9068 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9069 reset_v_option_vars();
9070 }
9071#endif
9072
Bram Moolenaar071d4272004-06-13 20:20:40 +00009073 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009074 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009075 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009076 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009077 check_redraw(options[opt_idx].flags);
9078
9079 return errmsg;
9080}
9081
9082/*
9083 * Called after an option changed: check if something needs to be redrawn.
9084 */
9085 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009086check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087{
9088 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009089 int doclear = (flags & P_RCLR) == P_RCLR;
9090 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009091
9092#ifdef FEAT_WINDOWS
9093 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9094 status_redraw_all();
9095#endif
9096
9097 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9098 changed_window_setting();
9099 if (flags & P_RBUF)
9100 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009101 if (flags & P_RWINONLY)
9102 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009103 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009104 redraw_all_later(CLEAR);
9105 else if (all)
9106 redraw_all_later(NOT_VALID);
9107}
9108
9109/*
9110 * Find index for option 'arg'.
9111 * Return -1 if not found.
9112 */
9113 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009114findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009115{
9116 int opt_idx;
9117 char *s, *p;
9118 static short quick_tab[27] = {0, 0}; /* quick access table */
9119 int is_term_opt;
9120
9121 /*
9122 * For first call: Initialize the quick-access table.
9123 * It contains the index for the first option that starts with a certain
9124 * letter. There are 26 letters, plus the first "t_" option.
9125 */
9126 if (quick_tab[1] == 0)
9127 {
9128 p = options[0].fullname;
9129 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9130 {
9131 if (s[0] != p[0])
9132 {
9133 if (s[0] == 't' && s[1] == '_')
9134 quick_tab[26] = opt_idx;
9135 else
9136 quick_tab[CharOrdLow(s[0])] = opt_idx;
9137 }
9138 p = s;
9139 }
9140 }
9141
9142 /*
9143 * Check for name starting with an illegal character.
9144 */
9145#ifdef EBCDIC
9146 if (!islower(arg[0]))
9147#else
9148 if (arg[0] < 'a' || arg[0] > 'z')
9149#endif
9150 return -1;
9151
9152 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9153 if (is_term_opt)
9154 opt_idx = quick_tab[26];
9155 else
9156 opt_idx = quick_tab[CharOrdLow(arg[0])];
9157 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9158 {
9159 if (STRCMP(arg, s) == 0) /* match full name */
9160 break;
9161 }
9162 if (s == NULL && !is_term_opt)
9163 {
9164 opt_idx = quick_tab[CharOrdLow(arg[0])];
9165 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9166 {
9167 s = options[opt_idx].shortname;
9168 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9169 break;
9170 s = NULL;
9171 }
9172 }
9173 if (s == NULL)
9174 opt_idx = -1;
9175 return opt_idx;
9176}
9177
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009178#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179/*
9180 * Get the value for an option.
9181 *
9182 * Returns:
9183 * Number or Toggle option: 1, *numval gets value.
9184 * String option: 0, *stringval gets allocated string.
9185 * Hidden Number or Toggle option: -1.
9186 * hidden String option: -2.
9187 * unknown option: -3.
9188 */
9189 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009190get_option_value(
9191 char_u *name,
9192 long *numval,
9193 char_u **stringval, /* NULL when only checking existence */
9194 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009195{
9196 int opt_idx;
9197 char_u *varp;
9198
9199 opt_idx = findoption(name);
9200 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009201 {
9202 int key;
9203
9204 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9205 && (key = find_key_option(name)) != 0)
9206 {
9207 char_u key_name[2];
9208 char_u *p;
9209
9210 if (key < 0)
9211 {
9212 key_name[0] = KEY2TERMCAP0(key);
9213 key_name[1] = KEY2TERMCAP1(key);
9214 }
9215 else
9216 {
9217 key_name[0] = KS_KEY;
9218 key_name[1] = (key & 0xff);
9219 }
9220 p = find_termcode(key_name);
9221 if (p != NULL)
9222 {
9223 if (stringval != NULL)
9224 *stringval = vim_strsave(p);
9225 return 0;
9226 }
9227 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009228 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009229 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009230
9231 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9232
9233 if (options[opt_idx].flags & P_STRING)
9234 {
9235 if (varp == NULL) /* hidden option */
9236 return -2;
9237 if (stringval != NULL)
9238 {
9239#ifdef FEAT_CRYPT
9240 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009241 if ((char_u **)varp == &curbuf->b_p_key
9242 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243 *stringval = vim_strsave((char_u *)"*****");
9244 else
9245#endif
9246 *stringval = vim_strsave(*(char_u **)(varp));
9247 }
9248 return 0;
9249 }
9250
9251 if (varp == NULL) /* hidden option */
9252 return -1;
9253 if (options[opt_idx].flags & P_NUM)
9254 *numval = *(long *)varp;
9255 else
9256 {
9257 /* Special case: 'modified' is b_changed, but we also want to consider
9258 * it set when 'ff' or 'fenc' changed. */
9259 if ((int *)varp == &curbuf->b_changed)
9260 *numval = curbufIsChanged();
9261 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009262 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009263 }
9264 return 1;
9265}
9266#endif
9267
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009268#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009269/*
9270 * Returns the option attributes and its value. Unlike the above function it
9271 * will return either global value or local value of the option depending on
9272 * what was requested, but it will never return global value if it was
9273 * requested to return local one and vice versa. Neither it will return
9274 * buffer-local value if it was requested to return window-local one.
9275 *
9276 * Pretends that option is absent if it is not present in the requested scope
9277 * (i.e. has no global, window-local or buffer-local value depending on
9278 * opt_type). Uses
9279 *
9280 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009281 * 0 hidden or unknown option, also option that does not have requested
9282 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009283 * see SOPT_* in vim.h for other flags
9284 *
9285 * Possible opt_type values: see SREQ_* in vim.h
9286 */
9287 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009288get_option_value_strict(
9289 char_u *name,
9290 long *numval,
9291 char_u **stringval, /* NULL when only obtaining attributes */
9292 int opt_type,
9293 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009294{
9295 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009296 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009297 struct vimoption *p;
9298 int r = 0;
9299
9300 opt_idx = findoption(name);
9301 if (opt_idx < 0)
9302 return 0;
9303
9304 p = &(options[opt_idx]);
9305
9306 /* Hidden option */
9307 if (p->var == NULL)
9308 return 0;
9309
9310 if (p->flags & P_BOOL)
9311 r |= SOPT_BOOL;
9312 else if (p->flags & P_NUM)
9313 r |= SOPT_NUM;
9314 else if (p->flags & P_STRING)
9315 r |= SOPT_STRING;
9316
9317 if (p->indir == PV_NONE)
9318 {
9319 if (opt_type == SREQ_GLOBAL)
9320 r |= SOPT_GLOBAL;
9321 else
9322 return 0; /* Did not request global-only option */
9323 }
9324 else
9325 {
9326 if (p->indir & PV_BOTH)
9327 r |= SOPT_GLOBAL;
9328 else if (opt_type == SREQ_GLOBAL)
9329 return 0; /* Requested global option */
9330
9331 if (p->indir & PV_WIN)
9332 {
9333 if (opt_type == SREQ_BUF)
9334 return 0; /* Did not request window-local option */
9335 else
9336 r |= SOPT_WIN;
9337 }
9338 else if (p->indir & PV_BUF)
9339 {
9340 if (opt_type == SREQ_WIN)
9341 return 0; /* Did not request buffer-local option */
9342 else
9343 r |= SOPT_BUF;
9344 }
9345 }
9346
9347 if (stringval == NULL)
9348 return r;
9349
9350 if (opt_type == SREQ_GLOBAL)
9351 varp = p->var;
9352 else
9353 {
9354 if (opt_type == SREQ_BUF)
9355 {
9356 /* Special case: 'modified' is b_changed, but we also want to
9357 * consider it set when 'ff' or 'fenc' changed. */
9358 if (p->indir == PV_MOD)
9359 {
9360 *numval = bufIsChanged((buf_T *) from);
9361 varp = NULL;
9362 }
9363#ifdef FEAT_CRYPT
9364 else if (p->indir == PV_KEY)
9365 {
9366 /* never return the value of the crypt key */
9367 *stringval = NULL;
9368 varp = NULL;
9369 }
9370#endif
9371 else
9372 {
9373 aco_save_T aco;
9374 aucmd_prepbuf(&aco, (buf_T *) from);
9375 varp = get_varp(p);
9376 aucmd_restbuf(&aco);
9377 }
9378 }
9379 else if (opt_type == SREQ_WIN)
9380 {
9381 win_T *save_curwin;
9382 save_curwin = curwin;
9383 curwin = (win_T *) from;
9384 curbuf = curwin->w_buffer;
9385 varp = get_varp(p);
9386 curwin = save_curwin;
9387 curbuf = curwin->w_buffer;
9388 }
9389 if (varp == p->var)
9390 return (r | SOPT_UNSET);
9391 }
9392
9393 if (varp != NULL)
9394 {
9395 if (p->flags & P_STRING)
9396 *stringval = vim_strsave(*(char_u **)(varp));
9397 else if (p->flags & P_NUM)
9398 *numval = *(long *) varp;
9399 else
9400 *numval = *(int *)varp;
9401 }
9402
9403 return r;
9404}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009405
9406/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009407 * Iterate over options. First argument is a pointer to a pointer to a
9408 * structure inside options[] array, second is option type like in the above
9409 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009410 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009411 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009412 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009413 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009414 * first argument to NULL.
9415 *
9416 * Returns full option name for current option on each call.
9417 */
9418 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009419option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009420{
9421 struct vimoption *ret = NULL;
9422 do
9423 {
9424 if (*option == NULL)
9425 *option = (void *) options;
9426 else if (((struct vimoption *) (*option))->fullname == NULL)
9427 {
9428 *option = NULL;
9429 return NULL;
9430 }
9431 else
9432 *option = (void *) (((struct vimoption *) (*option)) + 1);
9433
9434 ret = ((struct vimoption *) (*option));
9435
9436 /* Hidden option */
9437 if (ret->var == NULL)
9438 {
9439 ret = NULL;
9440 continue;
9441 }
9442
9443 switch (opt_type)
9444 {
9445 case SREQ_GLOBAL:
9446 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9447 ret = NULL;
9448 break;
9449 case SREQ_BUF:
9450 if (!(ret->indir & PV_BUF))
9451 ret = NULL;
9452 break;
9453 case SREQ_WIN:
9454 if (!(ret->indir & PV_WIN))
9455 ret = NULL;
9456 break;
9457 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009458 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009459 return NULL;
9460 }
9461 }
9462 while (ret == NULL);
9463
9464 return (char_u *)ret->fullname;
9465}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009466#endif
9467
Bram Moolenaar071d4272004-06-13 20:20:40 +00009468/*
9469 * Set the value of option "name".
9470 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009471 *
9472 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009473 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009474 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009475set_option_value(
9476 char_u *name,
9477 long number,
9478 char_u *string,
9479 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009480{
9481 int opt_idx;
9482 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009483 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009484
9485 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009486 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009487 {
9488 int key;
9489
9490 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9491 && (key = find_key_option(name)) != 0)
9492 {
9493 char_u key_name[2];
9494
9495 if (key < 0)
9496 {
9497 key_name[0] = KEY2TERMCAP0(key);
9498 key_name[1] = KEY2TERMCAP1(key);
9499 }
9500 else
9501 {
9502 key_name[0] = KS_KEY;
9503 key_name[1] = (key & 0xff);
9504 }
9505 add_termcode(key_name, string, FALSE);
9506 if (full_screen)
9507 ttest(FALSE);
9508 redraw_all_later(CLEAR);
9509 return NULL;
9510 }
9511
Bram Moolenaar071d4272004-06-13 20:20:40 +00009512 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009513 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009514 else
9515 {
9516 flags = options[opt_idx].flags;
9517#ifdef HAVE_SANDBOX
9518 /* Disallow changing some options in the sandbox */
9519 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009520 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009521 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009522 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009523 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009524#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009525 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009526 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009527 else
9528 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009529 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009530 if (varp != NULL) /* hidden option is not changed */
9531 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009532 if (number == 0 && string != NULL)
9533 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009534 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009535
9536 /* Either we are given a string or we are setting option
9537 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009538 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009539 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009540 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009541 {
9542 /* There's another character after zeros or the string
9543 * is empty. In both cases, we are trying to set a
9544 * num option using a string. */
9545 EMSG3(_("E521: Number required: &%s = '%s'"),
9546 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009547 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009548
9549 }
9550 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009552 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009553 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009554 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009555 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009556 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009557 }
9558 }
9559 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009560 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009561}
9562
9563/*
9564 * Get the terminal code for a terminal option.
9565 * Returns NULL when not found.
9566 */
9567 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009568get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009569{
9570 int opt_idx;
9571 char_u *varp;
9572
9573 if (tname[0] != 't' || tname[1] != '_' ||
9574 tname[2] == NUL || tname[3] == NUL)
9575 return NULL;
9576 if ((opt_idx = findoption(tname)) >= 0)
9577 {
9578 varp = get_varp(&(options[opt_idx]));
9579 if (varp != NULL)
9580 varp = *(char_u **)(varp);
9581 return varp;
9582 }
9583 return find_termcode(tname + 2);
9584}
9585
9586 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009587get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009588{
9589 int i;
9590
9591 i = findoption((char_u *)"hl");
9592 if (i >= 0)
9593 return options[i].def_val[VI_DEFAULT];
9594 return (char_u *)NULL;
9595}
9596
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009597#if defined(FEAT_MBYTE) || defined(PROTO)
9598 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009599get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009600{
9601 int i;
9602
9603 i = findoption((char_u *)"enc");
9604 if (i >= 0)
9605 return options[i].def_val[VI_DEFAULT];
9606 return (char_u *)NULL;
9607}
9608#endif
9609
Bram Moolenaar071d4272004-06-13 20:20:40 +00009610/*
9611 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9612 */
9613 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009614find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009615{
9616 int key;
9617 int modifiers;
9618
9619 /*
9620 * Don't use get_special_key_code() for t_xx, we don't want it to call
9621 * add_termcap_entry().
9622 */
9623 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9624 key = TERMCAP2KEY(arg[2], arg[3]);
9625 else
9626 {
9627 --arg; /* put arg at the '<' */
9628 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009629 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009630 if (modifiers) /* can't handle modifiers here */
9631 key = 0;
9632 }
9633 return key;
9634}
9635
9636/*
9637 * if 'all' == 0: show changed options
9638 * if 'all' == 1: show all normal options
9639 * if 'all' == 2: show all terminal options
9640 */
9641 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009642showoptions(
9643 int all,
9644 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009645{
9646 struct vimoption *p;
9647 int col;
9648 int isterm;
9649 char_u *varp;
9650 struct vimoption **items;
9651 int item_count;
9652 int run;
9653 int row, rows;
9654 int cols;
9655 int i;
9656 int len;
9657
9658#define INC 20
9659#define GAP 3
9660
9661 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9662 PARAM_COUNT));
9663 if (items == NULL)
9664 return;
9665
9666 /* Highlight title */
9667 if (all == 2)
9668 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9669 else if (opt_flags & OPT_GLOBAL)
9670 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9671 else if (opt_flags & OPT_LOCAL)
9672 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9673 else
9674 MSG_PUTS_TITLE(_("\n--- Options ---"));
9675
9676 /*
9677 * do the loop two times:
9678 * 1. display the short items
9679 * 2. display the long items (only strings and numbers)
9680 */
9681 for (run = 1; run <= 2 && !got_int; ++run)
9682 {
9683 /*
9684 * collect the items in items[]
9685 */
9686 item_count = 0;
9687 for (p = &options[0]; p->fullname != NULL; p++)
9688 {
9689 varp = NULL;
9690 isterm = istermoption(p);
9691 if (opt_flags != 0)
9692 {
9693 if (p->indir != PV_NONE && !isterm)
9694 varp = get_varp_scope(p, opt_flags);
9695 }
9696 else
9697 varp = get_varp(p);
9698 if (varp != NULL
9699 && ((all == 2 && isterm)
9700 || (all == 1 && !isterm)
9701 || (all == 0 && !optval_default(p, varp))))
9702 {
9703 if (p->flags & P_BOOL)
9704 len = 1; /* a toggle option fits always */
9705 else
9706 {
9707 option_value2string(p, opt_flags);
9708 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9709 }
9710 if ((len <= INC - GAP && run == 1) ||
9711 (len > INC - GAP && run == 2))
9712 items[item_count++] = p;
9713 }
9714 }
9715
9716 /*
9717 * display the items
9718 */
9719 if (run == 1)
9720 {
9721 cols = (Columns + GAP - 3) / INC;
9722 if (cols == 0)
9723 cols = 1;
9724 rows = (item_count + cols - 1) / cols;
9725 }
9726 else /* run == 2 */
9727 rows = item_count;
9728 for (row = 0; row < rows && !got_int; ++row)
9729 {
9730 msg_putchar('\n'); /* go to next line */
9731 if (got_int) /* 'q' typed in more */
9732 break;
9733 col = 0;
9734 for (i = row; i < item_count; i += rows)
9735 {
9736 msg_col = col; /* make columns */
9737 showoneopt(items[i], opt_flags);
9738 col += INC;
9739 }
9740 out_flush();
9741 ui_breakcheck();
9742 }
9743 }
9744 vim_free(items);
9745}
9746
9747/*
9748 * Return TRUE if option "p" has its default value.
9749 */
9750 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009751optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009752{
9753 int dvi;
9754
9755 if (varp == NULL)
9756 return TRUE; /* hidden option is always at default */
9757 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9758 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009759 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009760 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009761 /* the cast to long is required for Manx C, long_i is
9762 * needed for MSVC */
9763 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009764 /* P_STRING */
9765 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9766}
9767
9768/*
9769 * showoneopt: show the value of one option
9770 * must not be called with a hidden option!
9771 */
9772 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009773showoneopt(
9774 struct vimoption *p,
9775 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009776{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009777 char_u *varp;
9778 int save_silent = silent_mode;
9779
9780 silent_mode = FALSE;
9781 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009782
9783 varp = get_varp_scope(p, opt_flags);
9784
9785 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9786 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9787 ? !curbufIsChanged() : !*(int *)varp))
9788 MSG_PUTS("no");
9789 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9790 MSG_PUTS("--");
9791 else
9792 MSG_PUTS(" ");
9793 MSG_PUTS(p->fullname);
9794 if (!(p->flags & P_BOOL))
9795 {
9796 msg_putchar('=');
9797 /* put value string in NameBuff */
9798 option_value2string(p, opt_flags);
9799 msg_outtrans(NameBuff);
9800 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009801
9802 silent_mode = save_silent;
9803 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009804}
9805
9806/*
9807 * Write modified options as ":set" commands to a file.
9808 *
9809 * There are three values for "opt_flags":
9810 * OPT_GLOBAL: Write global option values and fresh values of
9811 * buffer-local options (used for start of a session
9812 * file).
9813 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9814 * curwin (used for a vimrc file).
9815 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9816 * and local values for window-local options of
9817 * curwin. Local values are also written when at the
9818 * default value, because a modeline or autocommand
9819 * may have set them when doing ":edit file" and the
9820 * user has set them back at the default or fresh
9821 * value.
9822 * When "local_only" is TRUE, don't write fresh
9823 * values, only local values (for ":mkview").
9824 * (fresh value = value used for a new buffer or window for a local option).
9825 *
9826 * Return FAIL on error, OK otherwise.
9827 */
9828 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009829makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009830{
9831 struct vimoption *p;
9832 char_u *varp; /* currently used value */
9833 char_u *varp_fresh; /* local value */
9834 char_u *varp_local = NULL; /* fresh value */
9835 char *cmd;
9836 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009837 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009838
9839 /*
9840 * The options that don't have a default (terminal name, columns, lines)
9841 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009842 * Do the loop over "options[]" twice: once for options with the
9843 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009844 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009845 for (pri = 1; pri >= 0; --pri)
9846 {
9847 for (p = &options[0]; !istermoption(p); p++)
9848 if (!(p->flags & P_NO_MKRC)
9849 && !istermoption(p)
9850 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009851 {
9852 /* skip global option when only doing locals */
9853 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9854 continue;
9855
9856 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9857 * file, they are always buffer-specific. */
9858 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9859 continue;
9860
9861 /* Global values are only written when not at the default value. */
9862 varp = get_varp_scope(p, opt_flags);
9863 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9864 continue;
9865
9866 round = 2;
9867 if (p->indir != PV_NONE)
9868 {
9869 if (p->var == VAR_WIN)
9870 {
9871 /* skip window-local option when only doing globals */
9872 if (!(opt_flags & OPT_LOCAL))
9873 continue;
9874 /* When fresh value of window-local option is not at the
9875 * default, need to write it too. */
9876 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9877 {
9878 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9879 if (!optval_default(p, varp_fresh))
9880 {
9881 round = 1;
9882 varp_local = varp;
9883 varp = varp_fresh;
9884 }
9885 }
9886 }
9887 }
9888
9889 /* Round 1: fresh value for window-local options.
9890 * Round 2: other values */
9891 for ( ; round <= 2; varp = varp_local, ++round)
9892 {
9893 if (round == 1 || (opt_flags & OPT_GLOBAL))
9894 cmd = "set";
9895 else
9896 cmd = "setlocal";
9897
9898 if (p->flags & P_BOOL)
9899 {
9900 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9901 return FAIL;
9902 }
9903 else if (p->flags & P_NUM)
9904 {
9905 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9906 return FAIL;
9907 }
9908 else /* P_STRING */
9909 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009910#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9911 int do_endif = FALSE;
9912
Bram Moolenaar071d4272004-06-13 20:20:40 +00009913 /* Don't set 'syntax' and 'filetype' again if the value is
9914 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009915 if (
9916# if defined(FEAT_SYN_HL)
9917 p->indir == PV_SYN
9918# if defined(FEAT_AUTOCMD)
9919 ||
9920# endif
9921# endif
9922# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009923 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009924# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009925 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009926 {
9927 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9928 *(char_u **)(varp)) < 0
9929 || put_eol(fd) < 0)
9930 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009931 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009932 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009934 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9935 (p->flags & P_EXPAND) != 0) == FAIL)
9936 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009937#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9938 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009939 {
9940 if (put_line(fd, "endif") == FAIL)
9941 return FAIL;
9942 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009943#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009944 }
9945 }
9946 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009947 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009948 return OK;
9949}
9950
9951#if defined(FEAT_FOLDING) || defined(PROTO)
9952/*
9953 * Generate set commands for the local fold options only. Used when
9954 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9955 */
9956 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009957makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958{
9959 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9960# ifdef FEAT_EVAL
9961 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9962 == FAIL
9963# endif
9964 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9965 == FAIL
9966 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9967 == FAIL
9968 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9969 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9970 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9971 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9972 )
9973 return FAIL;
9974
9975 return OK;
9976}
9977#endif
9978
9979 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009980put_setstring(
9981 FILE *fd,
9982 char *cmd,
9983 char *name,
9984 char_u **valuep,
9985 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009986{
9987 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009988 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989
9990 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9991 return FAIL;
9992 if (*valuep != NULL)
9993 {
9994 /* Output 'pastetoggle' as key names. For other
9995 * options some characters have to be escaped with
9996 * CTRL-V or backslash */
9997 if (valuep == &p_pt)
9998 {
9999 s = *valuep;
10000 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010001 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010002 return FAIL;
10003 }
10004 else if (expand)
10005 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010006 buf = alloc(MAXPATHL);
10007 if (buf == NULL)
10008 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010009 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10010 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010011 {
10012 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010013 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010014 }
10015 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016 }
10017 else if (put_escstr(fd, *valuep, 2) == FAIL)
10018 return FAIL;
10019 }
10020 if (put_eol(fd) < 0)
10021 return FAIL;
10022 return OK;
10023}
10024
10025 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010026put_setnum(
10027 FILE *fd,
10028 char *cmd,
10029 char *name,
10030 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031{
10032 long wc;
10033
10034 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10035 return FAIL;
10036 if (wc_use_keyname((char_u *)valuep, &wc))
10037 {
10038 /* print 'wildchar' and 'wildcharm' as a key name */
10039 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10040 return FAIL;
10041 }
10042 else if (fprintf(fd, "%ld", *valuep) < 0)
10043 return FAIL;
10044 if (put_eol(fd) < 0)
10045 return FAIL;
10046 return OK;
10047}
10048
10049 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010050put_setbool(
10051 FILE *fd,
10052 char *cmd,
10053 char *name,
10054 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010055{
Bram Moolenaar893de922007-10-02 18:40:57 +000010056 if (value < 0) /* global/local option using global value */
10057 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010058 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10059 || put_eol(fd) < 0)
10060 return FAIL;
10061 return OK;
10062}
10063
10064/*
10065 * Clear all the terminal options.
10066 * If the option has been allocated, free the memory.
10067 * Terminal options are never hidden or indirect.
10068 */
10069 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010070clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010071{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010072 /*
10073 * Reset a few things before clearing the old options. This may cause
10074 * outputting a few things that the terminal doesn't understand, but the
10075 * screen will be cleared later, so this is OK.
10076 */
10077#ifdef FEAT_MOUSE_TTY
10078 mch_setmouse(FALSE); /* switch mouse off */
10079#endif
10080#ifdef FEAT_TITLE
10081 mch_restore_title(3); /* restore window titles */
10082#endif
10083#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10084 /* When starting the GUI close the display opened for the clipboard.
10085 * After restoring the title, because that will need the display. */
10086 if (gui.starting)
10087 clear_xterm_clip();
10088#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010089 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010090
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010091 free_termoptions();
10092}
10093
10094 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010095free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010096{
10097 struct vimoption *p;
10098
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099 for (p = &options[0]; p->fullname != NULL; p++)
10100 if (istermoption(p))
10101 {
10102 if (p->flags & P_ALLOCED)
10103 free_string_option(*(char_u **)(p->var));
10104 if (p->flags & P_DEF_ALLOCED)
10105 free_string_option(p->def_val[VI_DEFAULT]);
10106 *(char_u **)(p->var) = empty_option;
10107 p->def_val[VI_DEFAULT] = empty_option;
10108 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10109 }
10110 clear_termcodes();
10111}
10112
10113/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010114 * Free the string for one term option, if it was allocated.
10115 * Set the string to empty_option and clear allocated flag.
10116 * "var" points to the option value.
10117 */
10118 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010119free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010120{
10121 struct vimoption *p;
10122
10123 for (p = &options[0]; p->fullname != NULL; p++)
10124 if (p->var == var)
10125 {
10126 if (p->flags & P_ALLOCED)
10127 free_string_option(*(char_u **)(p->var));
10128 *(char_u **)(p->var) = empty_option;
10129 p->flags &= ~P_ALLOCED;
10130 break;
10131 }
10132}
10133
10134/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010135 * Set the terminal option defaults to the current value.
10136 * Used after setting the terminal name.
10137 */
10138 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010139set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140{
10141 struct vimoption *p;
10142
10143 for (p = &options[0]; p->fullname != NULL; p++)
10144 {
10145 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10146 {
10147 if (p->flags & P_DEF_ALLOCED)
10148 {
10149 free_string_option(p->def_val[VI_DEFAULT]);
10150 p->flags &= ~P_DEF_ALLOCED;
10151 }
10152 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10153 if (p->flags & P_ALLOCED)
10154 {
10155 p->flags |= P_DEF_ALLOCED;
10156 p->flags &= ~P_ALLOCED; /* don't free the value now */
10157 }
10158 }
10159 }
10160}
10161
10162/*
10163 * return TRUE if 'p' starts with 't_'
10164 */
10165 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010166istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167{
10168 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10169}
10170
10171/*
10172 * Compute columns for ruler and shown command. 'sc_col' is also used to
10173 * decide what the maximum length of a message on the status line can be.
10174 * If there is a status line for the last window, 'sc_col' is independent
10175 * of 'ru_col'.
10176 */
10177
10178#define COL_RULER 17 /* columns needed by standard ruler */
10179
10180 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010181comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182{
10183#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010184 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185
10186 sc_col = 0;
10187 ru_col = 0;
10188 if (p_ru)
10189 {
10190#ifdef FEAT_STL_OPT
10191 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10192#else
10193 ru_col = COL_RULER + 1;
10194#endif
10195 /* no last status line, adjust sc_col */
10196 if (!last_has_status)
10197 sc_col = ru_col;
10198 }
10199 if (p_sc)
10200 {
10201 sc_col += SHOWCMD_COLS;
10202 if (!p_ru || last_has_status) /* no need for separating space */
10203 ++sc_col;
10204 }
10205 sc_col = Columns - sc_col;
10206 ru_col = Columns - ru_col;
10207 if (sc_col <= 0) /* screen too narrow, will become a mess */
10208 sc_col = 1;
10209 if (ru_col <= 0)
10210 ru_col = 1;
10211#else
10212 sc_col = Columns;
10213 ru_col = Columns;
10214#endif
10215}
10216
10217/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010218 * Unset local option value, similar to ":set opt<".
10219 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010220 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010221unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010222{
10223 struct vimoption *p;
10224 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010225 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010226
10227 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010228 if (opt_idx < 0)
10229 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010230 p = &(options[opt_idx]);
10231
10232 switch ((int)p->indir)
10233 {
10234 /* global option with local value: use local value if it's been set */
10235 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010236 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010237 break;
10238 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010239 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010240 break;
10241 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010242 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010243 break;
10244 case PV_AR:
10245 buf->b_p_ar = -1;
10246 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010247 case PV_BKC:
10248 clear_string_option(&buf->b_p_bkc);
10249 buf->b_bkc_flags = 0;
10250 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010251 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010252 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010253 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010254 case PV_TC:
10255 clear_string_option(&buf->b_p_tc);
10256 buf->b_tc_flags = 0;
10257 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010258#ifdef FEAT_FIND_ID
10259 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010260 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010261 break;
10262 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010263 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010264 break;
10265#endif
10266#ifdef FEAT_INS_EXPAND
10267 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010268 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010269 break;
10270 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010271 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010272 break;
10273#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010274 case PV_FP:
10275 clear_string_option(&buf->b_p_fp);
10276 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010277#ifdef FEAT_QUICKFIX
10278 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010279 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010280 break;
10281 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010282 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010283 break;
10284 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010285 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010286 break;
10287#endif
10288#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10289 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010290 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010291 break;
10292#endif
10293#if defined(FEAT_CRYPT)
10294 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010295 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010296 break;
10297#endif
10298#ifdef FEAT_STL_OPT
10299 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010300 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010301 break;
10302#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010303 case PV_UL:
10304 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10305 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010306#ifdef FEAT_LISP
10307 case PV_LW:
10308 clear_string_option(&buf->b_p_lw);
10309 break;
10310#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010311 }
10312}
10313
10314/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 * Get pointer to option variable, depending on local or global scope.
10316 */
10317 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010318get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319{
10320 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10321 {
10322 if (p->var == VAR_WIN)
10323 return (char_u *)GLOBAL_WO(get_varp(p));
10324 return p->var;
10325 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010326 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010327 {
10328 switch ((int)p->indir)
10329 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010330 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010332 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10333 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10334 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010335#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010336 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10337 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10338 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010339 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010340 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010341 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010343 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10344 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345#endif
10346#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010347 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10348 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010349#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010350#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10351 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10352#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010353#if defined(FEAT_CRYPT)
10354 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10355#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010356#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010357 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010358#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010359 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010360#ifdef FEAT_LISP
10361 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10362#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010363 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010364 }
10365 return NULL; /* "cannot happen" */
10366 }
10367 return get_varp(p);
10368}
10369
10370/*
10371 * Get pointer to option variable.
10372 */
10373 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010374get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375{
10376 /* hidden option, always return NULL */
10377 if (p->var == NULL)
10378 return NULL;
10379
10380 switch ((int)p->indir)
10381 {
10382 case PV_NONE: return p->var;
10383
10384 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010385 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010386 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010387 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010389 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010390 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010391 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010392 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010393 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010394 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010395 case PV_TC: return *curbuf->b_p_tc != NUL
10396 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010397 case PV_BKC: return *curbuf->b_p_bkc != NUL
10398 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010400 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010402 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10404#endif
10405#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010406 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010407 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010408 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010409 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10410#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010411 case PV_FP: return *curbuf->b_p_fp != NUL
10412 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010414 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010416 case PV_GP: return *curbuf->b_p_gp != NUL
10417 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10418 case PV_MP: return *curbuf->b_p_mp != NUL
10419 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010421#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10422 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10423 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10424#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010425#if defined(FEAT_CRYPT)
10426 case PV_CM: return *curbuf->b_p_cm != NUL
10427 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10428#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010429#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010430 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010431 ? (char_u *)&(curwin->w_p_stl) : p->var;
10432#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010433 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10434 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010435#ifdef FEAT_LISP
10436 case PV_LW: return *curbuf->b_p_lw != NUL
10437 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439
10440#ifdef FEAT_ARABIC
10441 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10442#endif
10443 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010444#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010445 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10446#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010447#ifdef FEAT_SYN_HL
10448 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10449 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010450 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010451#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452#ifdef FEAT_DIFF
10453 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10454#endif
10455#ifdef FEAT_FOLDING
10456 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10457 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10458 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10459 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10460 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10461 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10462 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10463# ifdef FEAT_EVAL
10464 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10465 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10466# endif
10467 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10468#endif
10469 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010470 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010471#ifdef FEAT_LINEBREAK
10472 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10473#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010474#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010476 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10477#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010478#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10479 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10480#endif
10481#ifdef FEAT_RIGHTLEFT
10482 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10483 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10484#endif
10485 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10486 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10487#ifdef FEAT_LINEBREAK
10488 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010489 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10490 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491#endif
10492#ifdef FEAT_SCROLLBIND
10493 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10494#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010495#ifdef FEAT_CURSORBIND
10496 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10497#endif
10498#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010499 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10500 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010501#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502
10503 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10504 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10505#ifdef FEAT_MBYTE
10506 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10507#endif
10508#if defined(FEAT_QUICKFIX)
10509 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10510 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10511#endif
10512 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10513 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10514#ifdef FEAT_CINDENT
10515 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10516 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10517 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10518#endif
10519#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10520 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10521#endif
10522#ifdef FEAT_COMMENTS
10523 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10524#endif
10525#ifdef FEAT_FOLDING
10526 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10527#endif
10528#ifdef FEAT_INS_EXPAND
10529 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10530#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010531#ifdef FEAT_COMPL_FUNC
10532 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010533 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010534#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010535 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010536 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010537 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10538#ifdef FEAT_MBYTE
10539 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10540#endif
10541 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10542#ifdef FEAT_AUTOCMD
10543 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10544#endif
10545 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010546 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10548 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10549 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10550 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10551#ifdef FEAT_FIND_ID
10552# ifdef FEAT_EVAL
10553 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10554# endif
10555#endif
10556#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10557 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10558 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10559#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010560#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010561 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563#ifdef FEAT_CRYPT
10564 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10565#endif
10566#ifdef FEAT_LISP
10567 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10568#endif
10569 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10570 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10571 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10572 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10573 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010574 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010575#ifdef FEAT_TEXTOBJ
10576 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010578 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10579#ifdef FEAT_SMARTINDENT
10580 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10581#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10584#ifdef FEAT_SEARCHPATH
10585 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10586#endif
10587 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10588#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010589 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010590 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10591#endif
10592#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010593 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10594 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10595 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010596#endif
10597 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10598 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10599 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10600 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010601#ifdef FEAT_PERSISTENT_UNDO
10602 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10603#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010604 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10605#ifdef FEAT_KEYMAP
10606 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10607#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010608#ifdef FEAT_SIGNS
10609 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10610#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010611 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010612 }
10613 /* always return a valid pointer to avoid a crash! */
10614 return (char_u *)&(curbuf->b_p_wm);
10615}
10616
10617/*
10618 * Get the value of 'equalprg', either the buffer-local one or the global one.
10619 */
10620 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010621get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010622{
10623 if (*curbuf->b_p_ep == NUL)
10624 return p_ep;
10625 return curbuf->b_p_ep;
10626}
10627
10628#if defined(FEAT_WINDOWS) || defined(PROTO)
10629/*
10630 * Copy options from one window to another.
10631 * Used when splitting a window.
10632 */
10633 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010634win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010635{
10636 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10637 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10638# ifdef FEAT_RIGHTLEFT
10639# ifdef FEAT_FKMAP
10640 /* Is this right? */
10641 wp_to->w_farsi = wp_from->w_farsi;
10642# endif
10643# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010644#if defined(FEAT_LINEBREAK)
10645 briopt_check(wp_to);
10646#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010647}
10648#endif
10649
10650/*
10651 * Copy the options from one winopt_T to another.
10652 * Doesn't free the old option values in "to", use clear_winopt() for that.
10653 * The 'scroll' option is not copied, because it depends on the window height.
10654 * The 'previewwindow' option is reset, there can be only one preview window.
10655 */
10656 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010657copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010658{
10659#ifdef FEAT_ARABIC
10660 to->wo_arab = from->wo_arab;
10661#endif
10662 to->wo_list = from->wo_list;
10663 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010664 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010665#ifdef FEAT_LINEBREAK
10666 to->wo_nuw = from->wo_nuw;
10667#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010668#ifdef FEAT_RIGHTLEFT
10669 to->wo_rl = from->wo_rl;
10670 to->wo_rlc = vim_strsave(from->wo_rlc);
10671#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010672#ifdef FEAT_STL_OPT
10673 to->wo_stl = vim_strsave(from->wo_stl);
10674#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010675 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010676#ifdef FEAT_DIFF
10677 to->wo_wrap_save = from->wo_wrap_save;
10678#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679#ifdef FEAT_LINEBREAK
10680 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010681 to->wo_bri = from->wo_bri;
10682 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010683#endif
10684#ifdef FEAT_SCROLLBIND
10685 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010686 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010687#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010688#ifdef FEAT_CURSORBIND
10689 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010690 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010691#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010692#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010693 to->wo_spell = from->wo_spell;
10694#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010695#ifdef FEAT_SYN_HL
10696 to->wo_cuc = from->wo_cuc;
10697 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010698 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010699#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010700#ifdef FEAT_DIFF
10701 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010702 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010703#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010704#ifdef FEAT_CONCEAL
10705 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010706 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010707#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010708#ifdef FEAT_FOLDING
10709 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010710 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010712 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713 to->wo_fdi = vim_strsave(from->wo_fdi);
10714 to->wo_fml = from->wo_fml;
10715 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010716 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010717 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010718 to->wo_fdm_save = from->wo_diff_saved
10719 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720 to->wo_fdn = from->wo_fdn;
10721# ifdef FEAT_EVAL
10722 to->wo_fde = vim_strsave(from->wo_fde);
10723 to->wo_fdt = vim_strsave(from->wo_fdt);
10724# endif
10725 to->wo_fmr = vim_strsave(from->wo_fmr);
10726#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010727#ifdef FEAT_SIGNS
10728 to->wo_scl = vim_strsave(from->wo_scl);
10729#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 check_winopt(to); /* don't want NULL pointers */
10731}
10732
10733/*
10734 * Check string options in a window for a NULL value.
10735 */
10736 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010737check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738{
10739 check_winopt(&win->w_onebuf_opt);
10740 check_winopt(&win->w_allbuf_opt);
10741}
10742
10743/*
10744 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10745 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010746 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010747check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748{
10749#ifdef FEAT_FOLDING
10750 check_string_option(&wop->wo_fdi);
10751 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010752 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010753# ifdef FEAT_EVAL
10754 check_string_option(&wop->wo_fde);
10755 check_string_option(&wop->wo_fdt);
10756# endif
10757 check_string_option(&wop->wo_fmr);
10758#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010759#ifdef FEAT_SIGNS
10760 check_string_option(&wop->wo_scl);
10761#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762#ifdef FEAT_RIGHTLEFT
10763 check_string_option(&wop->wo_rlc);
10764#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010765#ifdef FEAT_STL_OPT
10766 check_string_option(&wop->wo_stl);
10767#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010768#ifdef FEAT_SYN_HL
10769 check_string_option(&wop->wo_cc);
10770#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010771#ifdef FEAT_CONCEAL
10772 check_string_option(&wop->wo_cocu);
10773#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010774#ifdef FEAT_LINEBREAK
10775 check_string_option(&wop->wo_briopt);
10776#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777}
10778
10779/*
10780 * Free the allocated memory inside a winopt_T.
10781 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010782 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010783clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010784{
10785#ifdef FEAT_FOLDING
10786 clear_string_option(&wop->wo_fdi);
10787 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010788 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010789# ifdef FEAT_EVAL
10790 clear_string_option(&wop->wo_fde);
10791 clear_string_option(&wop->wo_fdt);
10792# endif
10793 clear_string_option(&wop->wo_fmr);
10794#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010795#ifdef FEAT_SIGNS
10796 clear_string_option(&wop->wo_scl);
10797#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010798#ifdef FEAT_LINEBREAK
10799 clear_string_option(&wop->wo_briopt);
10800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801#ifdef FEAT_RIGHTLEFT
10802 clear_string_option(&wop->wo_rlc);
10803#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010804#ifdef FEAT_STL_OPT
10805 clear_string_option(&wop->wo_stl);
10806#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010807#ifdef FEAT_SYN_HL
10808 clear_string_option(&wop->wo_cc);
10809#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010810#ifdef FEAT_CONCEAL
10811 clear_string_option(&wop->wo_cocu);
10812#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813}
10814
10815/*
10816 * Copy global option values to local options for one buffer.
10817 * Used when creating a new buffer and sometimes when entering a buffer.
10818 * flags:
10819 * BCO_ENTER We will enter the buf buffer.
10820 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10821 * appropriate.
10822 * BCO_NOHELP Don't copy the values to a help buffer.
10823 */
10824 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010825buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010826{
10827 int should_copy = TRUE;
10828 char_u *save_p_isk = NULL; /* init for GCC */
10829 int dont_do_help;
10830 int did_isk = FALSE;
10831
10832 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833 * Skip this when the option defaults have not been set yet. Happens when
10834 * main() allocates the first buffer.
10835 */
10836 if (p_cpo != NULL)
10837 {
10838 /*
10839 * Always copy when entering and 'cpo' contains 'S'.
10840 * Don't copy when already initialized.
10841 * Don't copy when 'cpo' contains 's' and not entering.
10842 * 'S' BCO_ENTER initialized 's' should_copy
10843 * yes yes X X TRUE
10844 * yes no yes X FALSE
10845 * no X yes X FALSE
10846 * X no no yes FALSE
10847 * X no no no TRUE
10848 * no yes no X TRUE
10849 */
10850 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10851 && (buf->b_p_initialized
10852 || (!(flags & BCO_ENTER)
10853 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10854 should_copy = FALSE;
10855
10856 if (should_copy || (flags & BCO_ALWAYS))
10857 {
10858 /* Don't copy the options specific to a help buffer when
10859 * BCO_NOHELP is given or the options were initialized already
10860 * (jumping back to a help file with CTRL-T or CTRL-O) */
10861 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10862 || buf->b_p_initialized;
10863 if (dont_do_help) /* don't free b_p_isk */
10864 {
10865 save_p_isk = buf->b_p_isk;
10866 buf->b_p_isk = NULL;
10867 }
10868 /*
10869 * Always free the allocated strings.
10870 * If not already initialized, set 'readonly' and copy 'fileformat'.
10871 */
10872 if (!buf->b_p_initialized)
10873 {
10874 free_buf_options(buf, TRUE);
10875 buf->b_p_ro = FALSE; /* don't copy readonly */
10876 buf->b_p_tx = p_tx;
10877#ifdef FEAT_MBYTE
10878 buf->b_p_fenc = vim_strsave(p_fenc);
10879#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020010880 switch (*p_ffs)
10881 {
10882 case 'm':
10883 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
10884 case 'd':
10885 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
10886 case 'u':
10887 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
10888 default:
10889 buf->b_p_ff = vim_strsave(p_ff);
10890 }
10891 if (buf->b_p_ff != NULL)
10892 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010893#if defined(FEAT_QUICKFIX)
10894 buf->b_p_bh = empty_option;
10895 buf->b_p_bt = empty_option;
10896#endif
10897 }
10898 else
10899 free_buf_options(buf, FALSE);
10900
10901 buf->b_p_ai = p_ai;
10902 buf->b_p_ai_nopaste = p_ai_nopaste;
10903 buf->b_p_sw = p_sw;
10904 buf->b_p_tw = p_tw;
10905 buf->b_p_tw_nopaste = p_tw_nopaste;
10906 buf->b_p_tw_nobin = p_tw_nobin;
10907 buf->b_p_wm = p_wm;
10908 buf->b_p_wm_nopaste = p_wm_nopaste;
10909 buf->b_p_wm_nobin = p_wm_nobin;
10910 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010911#ifdef FEAT_MBYTE
10912 buf->b_p_bomb = p_bomb;
10913#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010914 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010915 buf->b_p_et = p_et;
10916 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010917 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918 buf->b_p_ml = p_ml;
10919 buf->b_p_ml_nobin = p_ml_nobin;
10920 buf->b_p_inf = p_inf;
10921 buf->b_p_swf = p_swf;
10922#ifdef FEAT_INS_EXPAND
10923 buf->b_p_cpt = vim_strsave(p_cpt);
10924#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010925#ifdef FEAT_COMPL_FUNC
10926 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010927 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010928#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929 buf->b_p_sts = p_sts;
10930 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010931 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010932#ifdef FEAT_COMMENTS
10933 buf->b_p_com = vim_strsave(p_com);
10934#endif
10935#ifdef FEAT_FOLDING
10936 buf->b_p_cms = vim_strsave(p_cms);
10937#endif
10938 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010939 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940 buf->b_p_nf = vim_strsave(p_nf);
10941 buf->b_p_mps = vim_strsave(p_mps);
10942#ifdef FEAT_SMARTINDENT
10943 buf->b_p_si = p_si;
10944#endif
10945 buf->b_p_ci = p_ci;
10946#ifdef FEAT_CINDENT
10947 buf->b_p_cin = p_cin;
10948 buf->b_p_cink = vim_strsave(p_cink);
10949 buf->b_p_cino = vim_strsave(p_cino);
10950#endif
10951#ifdef FEAT_AUTOCMD
10952 /* Don't copy 'filetype', it must be detected */
10953 buf->b_p_ft = empty_option;
10954#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010955 buf->b_p_pi = p_pi;
10956#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10957 buf->b_p_cinw = vim_strsave(p_cinw);
10958#endif
10959#ifdef FEAT_LISP
10960 buf->b_p_lisp = p_lisp;
10961#endif
10962#ifdef FEAT_SYN_HL
10963 /* Don't copy 'syntax', it must be set */
10964 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010965 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010966 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010967#endif
10968#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010969 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010970 (void)compile_cap_prog(&buf->b_s);
10971 buf->b_s.b_p_spf = vim_strsave(p_spf);
10972 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010973#endif
10974#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10975 buf->b_p_inde = vim_strsave(p_inde);
10976 buf->b_p_indk = vim_strsave(p_indk);
10977#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010978 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010979#if defined(FEAT_EVAL)
10980 buf->b_p_fex = vim_strsave(p_fex);
10981#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982#ifdef FEAT_CRYPT
10983 buf->b_p_key = vim_strsave(p_key);
10984#endif
10985#ifdef FEAT_SEARCHPATH
10986 buf->b_p_sua = vim_strsave(p_sua);
10987#endif
10988#ifdef FEAT_KEYMAP
10989 buf->b_p_keymap = vim_strsave(p_keymap);
10990 buf->b_kmap_state |= KEYMAP_INIT;
10991#endif
10992 /* This isn't really an option, but copying the langmap and IME
10993 * state from the current buffer is better than resetting it. */
10994 buf->b_p_iminsert = p_iminsert;
10995 buf->b_p_imsearch = p_imsearch;
10996
10997 /* options that are normally global but also have a local value
10998 * are not copied, start using the global value */
10999 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011000 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011001 buf->b_p_bkc = empty_option;
11002 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011003#ifdef FEAT_QUICKFIX
11004 buf->b_p_gp = empty_option;
11005 buf->b_p_mp = empty_option;
11006 buf->b_p_efm = empty_option;
11007#endif
11008 buf->b_p_ep = empty_option;
11009 buf->b_p_kp = empty_option;
11010 buf->b_p_path = empty_option;
11011 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011012 buf->b_p_tc = empty_option;
11013 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011014#ifdef FEAT_FIND_ID
11015 buf->b_p_def = empty_option;
11016 buf->b_p_inc = empty_option;
11017# ifdef FEAT_EVAL
11018 buf->b_p_inex = vim_strsave(p_inex);
11019# endif
11020#endif
11021#ifdef FEAT_INS_EXPAND
11022 buf->b_p_dict = empty_option;
11023 buf->b_p_tsr = empty_option;
11024#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011025#ifdef FEAT_TEXTOBJ
11026 buf->b_p_qe = vim_strsave(p_qe);
11027#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011028#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11029 buf->b_p_bexpr = empty_option;
11030#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011031#if defined(FEAT_CRYPT)
11032 buf->b_p_cm = empty_option;
11033#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011034#ifdef FEAT_PERSISTENT_UNDO
11035 buf->b_p_udf = p_udf;
11036#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011037#ifdef FEAT_LISP
11038 buf->b_p_lw = empty_option;
11039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011040
11041 /*
11042 * Don't copy the options set by ex_help(), use the saved values,
11043 * when going from a help buffer to a non-help buffer.
11044 * Don't touch these at all when BCO_NOHELP is used and going from
11045 * or to a help buffer.
11046 */
11047 if (dont_do_help)
11048 buf->b_p_isk = save_p_isk;
11049 else
11050 {
11051 buf->b_p_isk = vim_strsave(p_isk);
11052 did_isk = TRUE;
11053 buf->b_p_ts = p_ts;
11054 buf->b_help = FALSE;
11055#ifdef FEAT_QUICKFIX
11056 if (buf->b_p_bt[0] == 'h')
11057 clear_string_option(&buf->b_p_bt);
11058#endif
11059 buf->b_p_ma = p_ma;
11060 }
11061 }
11062
11063 /*
11064 * When the options should be copied (ignoring BCO_ALWAYS), set the
11065 * flag that indicates that the options have been initialized.
11066 */
11067 if (should_copy)
11068 buf->b_p_initialized = TRUE;
11069 }
11070
11071 check_buf_options(buf); /* make sure we don't have NULLs */
11072 if (did_isk)
11073 (void)buf_init_chartab(buf, FALSE);
11074}
11075
11076/*
11077 * Reset the 'modifiable' option and its default value.
11078 */
11079 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011080reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011081{
11082 int opt_idx;
11083
11084 curbuf->b_p_ma = FALSE;
11085 p_ma = FALSE;
11086 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011087 if (opt_idx >= 0)
11088 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089}
11090
11091/*
11092 * Set the global value for 'iminsert' to the local value.
11093 */
11094 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011095set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096{
11097 p_iminsert = curbuf->b_p_iminsert;
11098}
11099
11100/*
11101 * Set the global value for 'imsearch' to the local value.
11102 */
11103 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011104set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011105{
11106 p_imsearch = curbuf->b_p_imsearch;
11107}
11108
11109#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11110static int expand_option_idx = -1;
11111static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11112static int expand_option_flags = 0;
11113
11114 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011115set_context_in_set_cmd(
11116 expand_T *xp,
11117 char_u *arg,
11118 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011119{
11120 int nextchar;
11121 long_u flags = 0; /* init for GCC */
11122 int opt_idx = 0; /* init for GCC */
11123 char_u *p;
11124 char_u *s;
11125 int is_term_option = FALSE;
11126 int key;
11127
11128 expand_option_flags = opt_flags;
11129
11130 xp->xp_context = EXPAND_SETTINGS;
11131 if (*arg == NUL)
11132 {
11133 xp->xp_pattern = arg;
11134 return;
11135 }
11136 p = arg + STRLEN(arg) - 1;
11137 if (*p == ' ' && *(p - 1) != '\\')
11138 {
11139 xp->xp_pattern = p + 1;
11140 return;
11141 }
11142 while (p > arg)
11143 {
11144 s = p;
11145 /* count number of backslashes before ' ' or ',' */
11146 if (*p == ' ' || *p == ',')
11147 {
11148 while (s > arg && *(s - 1) == '\\')
11149 --s;
11150 }
11151 /* break at a space with an even number of backslashes */
11152 if (*p == ' ' && ((p - s) & 1) == 0)
11153 {
11154 ++p;
11155 break;
11156 }
11157 --p;
11158 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011159 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011160 {
11161 xp->xp_context = EXPAND_BOOL_SETTINGS;
11162 p += 2;
11163 }
11164 if (STRNCMP(p, "inv", 3) == 0)
11165 {
11166 xp->xp_context = EXPAND_BOOL_SETTINGS;
11167 p += 3;
11168 }
11169 xp->xp_pattern = arg = p;
11170 if (*arg == '<')
11171 {
11172 while (*p != '>')
11173 if (*p++ == NUL) /* expand terminal option name */
11174 return;
11175 key = get_special_key_code(arg + 1);
11176 if (key == 0) /* unknown name */
11177 {
11178 xp->xp_context = EXPAND_NOTHING;
11179 return;
11180 }
11181 nextchar = *++p;
11182 is_term_option = TRUE;
11183 expand_option_name[2] = KEY2TERMCAP0(key);
11184 expand_option_name[3] = KEY2TERMCAP1(key);
11185 }
11186 else
11187 {
11188 if (p[0] == 't' && p[1] == '_')
11189 {
11190 p += 2;
11191 if (*p != NUL)
11192 ++p;
11193 if (*p == NUL)
11194 return; /* expand option name */
11195 nextchar = *++p;
11196 is_term_option = TRUE;
11197 expand_option_name[2] = p[-2];
11198 expand_option_name[3] = p[-1];
11199 }
11200 else
11201 {
11202 /* Allow * wildcard */
11203 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11204 p++;
11205 if (*p == NUL)
11206 return;
11207 nextchar = *p;
11208 *p = NUL;
11209 opt_idx = findoption(arg);
11210 *p = nextchar;
11211 if (opt_idx == -1 || options[opt_idx].var == NULL)
11212 {
11213 xp->xp_context = EXPAND_NOTHING;
11214 return;
11215 }
11216 flags = options[opt_idx].flags;
11217 if (flags & P_BOOL)
11218 {
11219 xp->xp_context = EXPAND_NOTHING;
11220 return;
11221 }
11222 }
11223 }
11224 /* handle "-=" and "+=" */
11225 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11226 {
11227 ++p;
11228 nextchar = '=';
11229 }
11230 if ((nextchar != '=' && nextchar != ':')
11231 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11232 {
11233 xp->xp_context = EXPAND_UNSUCCESSFUL;
11234 return;
11235 }
11236 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11237 {
11238 xp->xp_context = EXPAND_OLD_SETTING;
11239 if (is_term_option)
11240 expand_option_idx = -1;
11241 else
11242 expand_option_idx = opt_idx;
11243 xp->xp_pattern = p + 1;
11244 return;
11245 }
11246 xp->xp_context = EXPAND_NOTHING;
11247 if (is_term_option || (flags & P_NUM))
11248 return;
11249
11250 xp->xp_pattern = p + 1;
11251
11252 if (flags & P_EXPAND)
11253 {
11254 p = options[opt_idx].var;
11255 if (p == (char_u *)&p_bdir
11256 || p == (char_u *)&p_dir
11257 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011258 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011259 || p == (char_u *)&p_rtp
11260#ifdef FEAT_SEARCHPATH
11261 || p == (char_u *)&p_cdpath
11262#endif
11263#ifdef FEAT_SESSION
11264 || p == (char_u *)&p_vdir
11265#endif
11266 )
11267 {
11268 xp->xp_context = EXPAND_DIRECTORIES;
11269 if (p == (char_u *)&p_path
11270#ifdef FEAT_SEARCHPATH
11271 || p == (char_u *)&p_cdpath
11272#endif
11273 )
11274 xp->xp_backslash = XP_BS_THREE;
11275 else
11276 xp->xp_backslash = XP_BS_ONE;
11277 }
11278 else
11279 {
11280 xp->xp_context = EXPAND_FILES;
11281 /* for 'tags' need three backslashes for a space */
11282 if (p == (char_u *)&p_tags)
11283 xp->xp_backslash = XP_BS_THREE;
11284 else
11285 xp->xp_backslash = XP_BS_ONE;
11286 }
11287 }
11288
11289 /* For an option that is a list of file names, find the start of the
11290 * last file name. */
11291 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11292 {
11293 /* count number of backslashes before ' ' or ',' */
11294 if (*p == ' ' || *p == ',')
11295 {
11296 s = p;
11297 while (s > xp->xp_pattern && *(s - 1) == '\\')
11298 --s;
11299 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11300 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11301 {
11302 xp->xp_pattern = p + 1;
11303 break;
11304 }
11305 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011306
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011307#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011308 /* for 'spellsuggest' start at "file:" */
11309 if (options[opt_idx].var == (char_u *)&p_sps
11310 && STRNCMP(p, "file:", 5) == 0)
11311 {
11312 xp->xp_pattern = p + 5;
11313 break;
11314 }
11315#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316 }
11317
11318 return;
11319}
11320
11321 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011322ExpandSettings(
11323 expand_T *xp,
11324 regmatch_T *regmatch,
11325 int *num_file,
11326 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011327{
11328 int num_normal = 0; /* Nr of matching non-term-code settings */
11329 int num_term = 0; /* Nr of matching terminal code settings */
11330 int opt_idx;
11331 int match;
11332 int count = 0;
11333 char_u *str;
11334 int loop;
11335 int is_term_opt;
11336 char_u name_buf[MAX_KEY_NAME_LEN];
11337 static char *(names[]) = {"all", "termcap"};
11338 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11339
11340 /* do this loop twice:
11341 * loop == 0: count the number of matching options
11342 * loop == 1: copy the matching options into allocated memory
11343 */
11344 for (loop = 0; loop <= 1; ++loop)
11345 {
11346 regmatch->rm_ic = ic;
11347 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11348 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011349 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11350 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011351 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11352 {
11353 if (loop == 0)
11354 num_normal++;
11355 else
11356 (*file)[count++] = vim_strsave((char_u *)names[match]);
11357 }
11358 }
11359 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11360 opt_idx++)
11361 {
11362 if (options[opt_idx].var == NULL)
11363 continue;
11364 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11365 && !(options[opt_idx].flags & P_BOOL))
11366 continue;
11367 is_term_opt = istermoption(&options[opt_idx]);
11368 if (is_term_opt && num_normal > 0)
11369 continue;
11370 match = FALSE;
11371 if (vim_regexec(regmatch, str, (colnr_T)0)
11372 || (options[opt_idx].shortname != NULL
11373 && vim_regexec(regmatch,
11374 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11375 match = TRUE;
11376 else if (is_term_opt)
11377 {
11378 name_buf[0] = '<';
11379 name_buf[1] = 't';
11380 name_buf[2] = '_';
11381 name_buf[3] = str[2];
11382 name_buf[4] = str[3];
11383 name_buf[5] = '>';
11384 name_buf[6] = NUL;
11385 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11386 {
11387 match = TRUE;
11388 str = name_buf;
11389 }
11390 }
11391 if (match)
11392 {
11393 if (loop == 0)
11394 {
11395 if (is_term_opt)
11396 num_term++;
11397 else
11398 num_normal++;
11399 }
11400 else
11401 (*file)[count++] = vim_strsave(str);
11402 }
11403 }
11404 /*
11405 * Check terminal key codes, these are not in the option table
11406 */
11407 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11408 {
11409 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11410 {
11411 if (!isprint(str[0]) || !isprint(str[1]))
11412 continue;
11413
11414 name_buf[0] = 't';
11415 name_buf[1] = '_';
11416 name_buf[2] = str[0];
11417 name_buf[3] = str[1];
11418 name_buf[4] = NUL;
11419
11420 match = FALSE;
11421 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11422 match = TRUE;
11423 else
11424 {
11425 name_buf[0] = '<';
11426 name_buf[1] = 't';
11427 name_buf[2] = '_';
11428 name_buf[3] = str[0];
11429 name_buf[4] = str[1];
11430 name_buf[5] = '>';
11431 name_buf[6] = NUL;
11432
11433 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11434 match = TRUE;
11435 }
11436 if (match)
11437 {
11438 if (loop == 0)
11439 num_term++;
11440 else
11441 (*file)[count++] = vim_strsave(name_buf);
11442 }
11443 }
11444
11445 /*
11446 * Check special key names.
11447 */
11448 regmatch->rm_ic = TRUE; /* ignore case here */
11449 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11450 {
11451 name_buf[0] = '<';
11452 STRCPY(name_buf + 1, str);
11453 STRCAT(name_buf, ">");
11454
11455 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11456 {
11457 if (loop == 0)
11458 num_term++;
11459 else
11460 (*file)[count++] = vim_strsave(name_buf);
11461 }
11462 }
11463 }
11464 if (loop == 0)
11465 {
11466 if (num_normal > 0)
11467 *num_file = num_normal;
11468 else if (num_term > 0)
11469 *num_file = num_term;
11470 else
11471 return OK;
11472 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11473 if (*file == NULL)
11474 {
11475 *file = (char_u **)"";
11476 return FAIL;
11477 }
11478 }
11479 }
11480 return OK;
11481}
11482
11483 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011484ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011485{
11486 char_u *var = NULL; /* init for GCC */
11487 char_u *buf;
11488
11489 *num_file = 0;
11490 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11491 if (*file == NULL)
11492 return FAIL;
11493
11494 /*
11495 * For a terminal key code expand_option_idx is < 0.
11496 */
11497 if (expand_option_idx < 0)
11498 {
11499 var = find_termcode(expand_option_name + 2);
11500 if (var == NULL)
11501 expand_option_idx = findoption(expand_option_name);
11502 }
11503
11504 if (expand_option_idx >= 0)
11505 {
11506 /* put string of option value in NameBuff */
11507 option_value2string(&options[expand_option_idx], expand_option_flags);
11508 var = NameBuff;
11509 }
11510 else if (var == NULL)
11511 var = (char_u *)"";
11512
11513 /* A backslash is required before some characters. This is the reverse of
11514 * what happens in do_set(). */
11515 buf = vim_strsave_escaped(var, escape_chars);
11516
11517 if (buf == NULL)
11518 {
11519 vim_free(*file);
11520 *file = NULL;
11521 return FAIL;
11522 }
11523
11524#ifdef BACKSLASH_IN_FILENAME
11525 /* For MS-Windows et al. we don't double backslashes at the start and
11526 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011527 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528 if (var[0] == '\\' && var[1] == '\\'
11529 && expand_option_idx >= 0
11530 && (options[expand_option_idx].flags & P_EXPAND)
11531 && vim_isfilec(var[2])
11532 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011533 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534#endif
11535
11536 *file[0] = buf;
11537 *num_file = 1;
11538 return OK;
11539}
11540#endif
11541
11542/*
11543 * Get the value for the numeric or string option *opp in a nice format into
11544 * NameBuff[]. Must not be called with a hidden option!
11545 */
11546 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011547option_value2string(
11548 struct vimoption *opp,
11549 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011550{
11551 char_u *varp;
11552
11553 varp = get_varp_scope(opp, opt_flags);
11554
11555 if (opp->flags & P_NUM)
11556 {
11557 long wc = 0;
11558
11559 if (wc_use_keyname(varp, &wc))
11560 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11561 else if (wc != 0)
11562 STRCPY(NameBuff, transchar((int)wc));
11563 else
11564 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11565 }
11566 else /* P_STRING */
11567 {
11568 varp = *(char_u **)(varp);
11569 if (varp == NULL) /* just in case */
11570 NameBuff[0] = NUL;
11571#ifdef FEAT_CRYPT
11572 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011573 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011574 STRCPY(NameBuff, "*****");
11575#endif
11576 else if (opp->flags & P_EXPAND)
11577 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11578 /* Translate 'pastetoggle' into special key names */
11579 else if ((char_u **)opp->var == &p_pt)
11580 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11581 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011582 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011583 }
11584}
11585
11586/*
11587 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11588 * printed as a keyname.
11589 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11590 */
11591 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011592wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011593{
11594 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11595 {
11596 *wcp = *(long *)varp;
11597 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11598 return TRUE;
11599 }
11600 return FALSE;
11601}
11602
Bram Moolenaar01615492015-02-03 13:00:38 +010011603#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011604/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011605 * Any character has an equivalent 'langmap' character. This is used for
11606 * keyboards that have a special language mode that sends characters above
11607 * 128 (although other characters can be translated too). The "to" field is a
11608 * Vim command character. This avoids having to switch the keyboard back to
11609 * ASCII mode when leaving Insert mode.
11610 *
11611 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11612 * commands.
11613 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11614 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11615 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011616 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011617# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011618/*
11619 * With multi-byte support use growarray for 'langmap' chars >= 256
11620 */
11621typedef struct
11622{
11623 int from;
11624 int to;
11625} langmap_entry_T;
11626
11627static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011628static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011629
11630/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011631 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11632 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011634 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011635langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011636{
11637 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011638 int a = 0;
11639 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011640
11641 /* Do a binary search for an existing entry. */
11642 while (a != b)
11643 {
11644 int i = (a + b) / 2;
11645 int d = entries[i].from - from;
11646
11647 if (d == 0)
11648 {
11649 entries[i].to = to;
11650 return;
11651 }
11652 if (d < 0)
11653 a = i + 1;
11654 else
11655 b = i;
11656 }
11657
11658 if (ga_grow(&langmap_mapga, 1) != OK)
11659 return; /* out of memory */
11660
11661 /* insert new entry at position "a" */
11662 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11663 mch_memmove(entries + 1, entries,
11664 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11665 ++langmap_mapga.ga_len;
11666 entries[0].from = from;
11667 entries[0].to = to;
11668}
11669
11670/*
11671 * Apply 'langmap' to multi-byte character "c" and return the result.
11672 */
11673 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011674langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011675{
11676 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11677 int a = 0;
11678 int b = langmap_mapga.ga_len;
11679
11680 while (a != b)
11681 {
11682 int i = (a + b) / 2;
11683 int d = entries[i].from - c;
11684
11685 if (d == 0)
11686 return entries[i].to; /* found matching entry */
11687 if (d < 0)
11688 a = i + 1;
11689 else
11690 b = i;
11691 }
11692 return c; /* no entry found, return "c" unmodified */
11693}
11694# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011695
11696 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011697langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011698{
11699 int i;
11700
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011701 for (i = 0; i < 256; i++)
11702 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11703# ifdef FEAT_MBYTE
11704 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11705# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011706}
11707
11708/*
11709 * Called when langmap option is set; the language map can be
11710 * changed at any time!
11711 */
11712 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011713langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714{
11715 char_u *p;
11716 char_u *p2;
11717 int from, to;
11718
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011719#ifdef FEAT_MBYTE
11720 ga_clear(&langmap_mapga); /* clear the previous map first */
11721#endif
11722 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011723
11724 for (p = p_langmap; p[0] != NUL; )
11725 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011726 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11727 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011728 {
11729 if (p2[0] == '\\' && p2[1] != NUL)
11730 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731 }
11732 if (p2[0] == ';')
11733 ++p2; /* abcd;ABCD form, p2 points to A */
11734 else
11735 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11736 while (p[0])
11737 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011738 if (p[0] == ',')
11739 {
11740 ++p;
11741 break;
11742 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011743 if (p[0] == '\\' && p[1] != NUL)
11744 ++p;
11745#ifdef FEAT_MBYTE
11746 from = (*mb_ptr2char)(p);
11747#else
11748 from = p[0];
11749#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011750 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011751 if (p2 == NULL)
11752 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011753 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011754 if (p[0] != ',')
11755 {
11756 if (p[0] == '\\')
11757 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011758#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011759 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011760#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011761 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011762#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011763 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011764 }
11765 else
11766 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011767 if (p2[0] != ',')
11768 {
11769 if (p2[0] == '\\')
11770 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011771#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011772 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011773#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011774 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011775#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011776 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011777 }
11778 if (to == NUL)
11779 {
11780 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11781 transchar(from));
11782 return;
11783 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011784
11785#ifdef FEAT_MBYTE
11786 if (from >= 256)
11787 langmap_set_entry(from, to);
11788 else
11789#endif
11790 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011791
11792 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011793 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011794 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011795 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011796 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011797 if (*p == ';')
11798 {
11799 p = p2;
11800 if (p[0] != NUL)
11801 {
11802 if (p[0] != ',')
11803 {
11804 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11805 return;
11806 }
11807 ++p;
11808 }
11809 break;
11810 }
11811 }
11812 }
11813 }
11814}
11815#endif
11816
11817/*
11818 * Return TRUE if format option 'x' is in effect.
11819 * Take care of no formatting when 'paste' is set.
11820 */
11821 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011822has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823{
11824 if (p_paste)
11825 return FALSE;
11826 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11827}
11828
11829/*
11830 * Return TRUE if "x" is present in 'shortmess' option, or
11831 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11832 */
11833 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011834shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011835{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011836 return p_shm != NULL &&
11837 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011838 || (vim_strchr(p_shm, 'a') != NULL
11839 && vim_strchr((char_u *)SHM_A, x) != NULL));
11840}
11841
11842/*
11843 * paste_option_changed() - Called after p_paste was set or reset.
11844 */
11845 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011846paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011847{
11848 static int old_p_paste = FALSE;
11849 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011850 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011851#ifdef FEAT_CMDL_INFO
11852 static int save_ru = 0;
11853#endif
11854#ifdef FEAT_RIGHTLEFT
11855 static int save_ri = 0;
11856 static int save_hkmap = 0;
11857#endif
11858 buf_T *buf;
11859
11860 if (p_paste)
11861 {
11862 /*
11863 * Paste switched from off to on.
11864 * Save the current values, so they can be restored later.
11865 */
11866 if (!old_p_paste)
11867 {
11868 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011869 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011870 {
11871 buf->b_p_tw_nopaste = buf->b_p_tw;
11872 buf->b_p_wm_nopaste = buf->b_p_wm;
11873 buf->b_p_sts_nopaste = buf->b_p_sts;
11874 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011875 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011876 }
11877
11878 /* save global options */
11879 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011880 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011881#ifdef FEAT_CMDL_INFO
11882 save_ru = p_ru;
11883#endif
11884#ifdef FEAT_RIGHTLEFT
11885 save_ri = p_ri;
11886 save_hkmap = p_hkmap;
11887#endif
11888 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011889 p_ai_nopaste = p_ai;
11890 p_et_nopaste = p_et;
11891 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011892 p_tw_nopaste = p_tw;
11893 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011894 }
11895
11896 /*
11897 * Always set the option values, also when 'paste' is set when it is
11898 * already on.
11899 */
11900 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011901 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011902 {
11903 buf->b_p_tw = 0; /* textwidth is 0 */
11904 buf->b_p_wm = 0; /* wrapmargin is 0 */
11905 buf->b_p_sts = 0; /* softtabstop is 0 */
11906 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011907 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011908 }
11909
11910 /* set global options */
11911 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011912 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011913#ifdef FEAT_CMDL_INFO
11914# ifdef FEAT_WINDOWS
11915 if (p_ru)
11916 status_redraw_all(); /* redraw to remove the ruler */
11917# endif
11918 p_ru = 0; /* no ruler */
11919#endif
11920#ifdef FEAT_RIGHTLEFT
11921 p_ri = 0; /* no reverse insert */
11922 p_hkmap = 0; /* no Hebrew keyboard */
11923#endif
11924 /* set global values for local buffer options */
11925 p_tw = 0;
11926 p_wm = 0;
11927 p_sts = 0;
11928 p_ai = 0;
11929 }
11930
11931 /*
11932 * Paste switched from on to off: Restore saved values.
11933 */
11934 else if (old_p_paste)
11935 {
11936 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011937 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011938 {
11939 buf->b_p_tw = buf->b_p_tw_nopaste;
11940 buf->b_p_wm = buf->b_p_wm_nopaste;
11941 buf->b_p_sts = buf->b_p_sts_nopaste;
11942 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011943 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011944 }
11945
11946 /* restore global options */
11947 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011948 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011949#ifdef FEAT_CMDL_INFO
11950# ifdef FEAT_WINDOWS
11951 if (p_ru != save_ru)
11952 status_redraw_all(); /* redraw to draw the ruler */
11953# endif
11954 p_ru = save_ru;
11955#endif
11956#ifdef FEAT_RIGHTLEFT
11957 p_ri = save_ri;
11958 p_hkmap = save_hkmap;
11959#endif
11960 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011961 p_ai = p_ai_nopaste;
11962 p_et = p_et_nopaste;
11963 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011964 p_tw = p_tw_nopaste;
11965 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011966 }
11967
11968 old_p_paste = p_paste;
11969}
11970
11971/*
11972 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11973 *
11974 * Reset 'compatible' and set the values for options that didn't get set yet
11975 * to the Vim defaults.
11976 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011977 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011978 */
11979 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011980vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011981{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011982 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011983 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011984 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985
11986 if (!option_was_set((char_u *)"cp"))
11987 {
11988 p_cp = FALSE;
11989 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11990 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11991 set_option_default(opt_idx, OPT_FREE, FALSE);
11992 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011993 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011994 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011995
11996 if (fname != NULL)
11997 {
11998 p = vim_getenv(envname, &dofree);
11999 if (p == NULL)
12000 {
12001 /* Set $MYVIMRC to the first vimrc file found. */
12002 p = FullName_save(fname, FALSE);
12003 if (p != NULL)
12004 {
12005 vim_setenv(envname, p);
12006 vim_free(p);
12007 }
12008 }
12009 else if (dofree)
12010 vim_free(p);
12011 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012}
12013
12014/*
12015 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12016 */
12017 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012018change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012019{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012020 int opt_idx;
12021
Bram Moolenaar071d4272004-06-13 20:20:40 +000012022 if (p_cp != on)
12023 {
12024 p_cp = on;
12025 compatible_set();
12026 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012027 opt_idx = findoption((char_u *)"cp");
12028 if (opt_idx >= 0)
12029 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012030}
12031
12032/*
12033 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012034 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012035 */
12036 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012037option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012038{
12039 int idx;
12040
12041 idx = findoption(name);
12042 if (idx < 0) /* unknown option */
12043 return FALSE;
12044 if (options[idx].flags & P_WAS_SET)
12045 return TRUE;
12046 return FALSE;
12047}
12048
12049/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012050 * Reset the flag indicating option "name" was set.
12051 */
12052 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012053reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012054{
12055 int idx = findoption(name);
12056
12057 if (idx >= 0)
12058 options[idx].flags &= ~P_WAS_SET;
12059}
12060
12061/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012062 * compatible_set() - Called when 'compatible' has been set or unset.
12063 *
12064 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12065 * flag) to a Vi compatible value.
12066 * When 'compatible' is unset: Set all options that have a different default
12067 * for Vim (without the P_VI_DEF flag) to that default.
12068 */
12069 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012070compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012071{
12072 int opt_idx;
12073
12074 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12075 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12076 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12077 set_option_default(opt_idx, OPT_FREE, p_cp);
12078 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012079 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012080}
12081
12082#ifdef FEAT_LINEBREAK
12083
12084# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12085 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012086 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087# endif
12088
12089/*
12090 * fill_breakat_flags() -- called when 'breakat' changes value.
12091 */
12092 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012093fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012094{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012095 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012096 int i;
12097
12098 for (i = 0; i < 256; i++)
12099 breakat_flags[i] = FALSE;
12100
12101 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012102 for (p = p_breakat; *p; p++)
12103 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012104}
12105
12106# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012107 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012108# endif
12109
12110#endif
12111
12112/*
12113 * Check an option that can be a range of string values.
12114 *
12115 * Return OK for correct value, FAIL otherwise.
12116 * Empty is always OK.
12117 */
12118 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012119check_opt_strings(
12120 char_u *val,
12121 char **values,
12122 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012123{
12124 return opt_strings_flags(val, values, NULL, list);
12125}
12126
12127/*
12128 * Handle an option that can be a range of string values.
12129 * Set a flag in "*flagp" for each string present.
12130 *
12131 * Return OK for correct value, FAIL otherwise.
12132 * Empty is always OK.
12133 */
12134 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012135opt_strings_flags(
12136 char_u *val, /* new value */
12137 char **values, /* array of valid string values */
12138 unsigned *flagp,
12139 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012140{
12141 int i;
12142 int len;
12143 unsigned new_flags = 0;
12144
12145 while (*val)
12146 {
12147 for (i = 0; ; ++i)
12148 {
12149 if (values[i] == NULL) /* val not found in values[] */
12150 return FAIL;
12151
12152 len = (int)STRLEN(values[i]);
12153 if (STRNCMP(values[i], val, len) == 0
12154 && ((list && val[len] == ',') || val[len] == NUL))
12155 {
12156 val += len + (val[len] == ',');
12157 new_flags |= (1 << i);
12158 break; /* check next item in val list */
12159 }
12160 }
12161 }
12162 if (flagp != NULL)
12163 *flagp = new_flags;
12164
12165 return OK;
12166}
12167
12168/*
12169 * Read the 'wildmode' option, fill wim_flags[].
12170 */
12171 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012172check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173{
12174 char_u new_wim_flags[4];
12175 char_u *p;
12176 int i;
12177 int idx = 0;
12178
12179 for (i = 0; i < 4; ++i)
12180 new_wim_flags[i] = 0;
12181
12182 for (p = p_wim; *p; ++p)
12183 {
12184 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12185 ;
12186 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12187 return FAIL;
12188 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12189 new_wim_flags[idx] |= WIM_LONGEST;
12190 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12191 new_wim_flags[idx] |= WIM_FULL;
12192 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12193 new_wim_flags[idx] |= WIM_LIST;
12194 else
12195 return FAIL;
12196 p += i;
12197 if (*p == NUL)
12198 break;
12199 if (*p == ',')
12200 {
12201 if (idx == 3)
12202 return FAIL;
12203 ++idx;
12204 }
12205 }
12206
12207 /* fill remaining entries with last flag */
12208 while (idx < 3)
12209 {
12210 new_wim_flags[idx + 1] = new_wim_flags[idx];
12211 ++idx;
12212 }
12213
12214 /* only when there are no errors, wim_flags[] is changed */
12215 for (i = 0; i < 4; ++i)
12216 wim_flags[i] = new_wim_flags[i];
12217 return OK;
12218}
12219
12220/*
12221 * Check if backspacing over something is allowed.
12222 */
12223 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012224can_bs(
12225 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012226{
12227 switch (*p_bs)
12228 {
12229 case '2': return TRUE;
12230 case '1': return (what != BS_START);
12231 case '0': return FALSE;
12232 }
12233 return vim_strchr(p_bs, what) != NULL;
12234}
12235
12236/*
12237 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12238 * the file must be considered changed when the value is different.
12239 */
12240 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012241save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242{
12243 buf->b_start_ffc = *buf->b_p_ff;
12244 buf->b_start_eol = buf->b_p_eol;
12245#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012246 buf->b_start_bomb = buf->b_p_bomb;
12247
Bram Moolenaar071d4272004-06-13 20:20:40 +000012248 /* Only use free/alloc when necessary, they take time. */
12249 if (buf->b_start_fenc == NULL
12250 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12251 {
12252 vim_free(buf->b_start_fenc);
12253 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12254 }
12255#endif
12256}
12257
12258/*
12259 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12260 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012261 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12262 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012263 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012264 * When "ignore_empty" is true don't consider a new, empty buffer to be
12265 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012266 */
12267 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012268file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012269{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012270 /* In a buffer that was never loaded the options are not valid. */
12271 if (buf->b_flags & BF_NEVERLOADED)
12272 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012273 if (ignore_empty
12274 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012275 && buf->b_ml.ml_line_count == 1
12276 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12277 return FALSE;
12278 if (buf->b_start_ffc != *buf->b_p_ff)
12279 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012280 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012281 return TRUE;
12282#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012283 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12284 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012285 if (buf->b_start_fenc == NULL)
12286 return (*buf->b_p_fenc != NUL);
12287 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12288#else
12289 return FALSE;
12290#endif
12291}
12292
12293/*
12294 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12295 */
12296 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012297check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012298{
12299 return check_opt_strings(p, p_ff_values, FALSE);
12300}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012301
12302/*
12303 * Return the effective shiftwidth value for current buffer, using the
12304 * 'tabstop' value when 'shiftwidth' is zero.
12305 */
12306 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012307get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012308{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012309 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012310}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012311
12312/*
12313 * Return the effective softtabstop value for the current buffer, using the
12314 * 'tabstop' value when 'softtabstop' is negative.
12315 */
12316 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012317get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012318{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012319 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012320}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012321
12322/*
12323 * Check matchpairs option for "*initc".
12324 * If there is a match set "*initc" to the matching character and "*findc" to
12325 * the opposite character. Set "*backwards" to the direction.
12326 * When "switchit" is TRUE swap the direction.
12327 */
12328 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012329find_mps_values(
12330 int *initc,
12331 int *findc,
12332 int *backwards,
12333 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012334{
12335 char_u *ptr;
12336
12337 ptr = curbuf->b_p_mps;
12338 while (*ptr != NUL)
12339 {
12340#ifdef FEAT_MBYTE
12341 if (has_mbyte)
12342 {
12343 char_u *prev;
12344
12345 if (mb_ptr2char(ptr) == *initc)
12346 {
12347 if (switchit)
12348 {
12349 *findc = *initc;
12350 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12351 *backwards = TRUE;
12352 }
12353 else
12354 {
12355 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12356 *backwards = FALSE;
12357 }
12358 return;
12359 }
12360 prev = ptr;
12361 ptr += mb_ptr2len(ptr) + 1;
12362 if (mb_ptr2char(ptr) == *initc)
12363 {
12364 if (switchit)
12365 {
12366 *findc = *initc;
12367 *initc = mb_ptr2char(prev);
12368 *backwards = FALSE;
12369 }
12370 else
12371 {
12372 *findc = mb_ptr2char(prev);
12373 *backwards = TRUE;
12374 }
12375 return;
12376 }
12377 ptr += mb_ptr2len(ptr);
12378 }
12379 else
12380#endif
12381 {
12382 if (*ptr == *initc)
12383 {
12384 if (switchit)
12385 {
12386 *backwards = TRUE;
12387 *findc = *initc;
12388 *initc = ptr[2];
12389 }
12390 else
12391 {
12392 *backwards = FALSE;
12393 *findc = ptr[2];
12394 }
12395 return;
12396 }
12397 ptr += 2;
12398 if (*ptr == *initc)
12399 {
12400 if (switchit)
12401 {
12402 *backwards = FALSE;
12403 *findc = *initc;
12404 *initc = ptr[-2];
12405 }
12406 else
12407 {
12408 *backwards = TRUE;
12409 *findc = ptr[-2];
12410 }
12411 return;
12412 }
12413 ++ptr;
12414 }
12415 if (*ptr == ',')
12416 ++ptr;
12417 }
12418}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012419
12420#if defined(FEAT_LINEBREAK) || defined(PROTO)
12421/*
12422 * This is called when 'breakindentopt' is changed and when a window is
12423 * initialized.
12424 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012425 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012426briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012427{
12428 char_u *p;
12429 int bri_shift = 0;
12430 long bri_min = 20;
12431 int bri_sbr = FALSE;
12432
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012433 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012434 while (*p != NUL)
12435 {
12436 if (STRNCMP(p, "shift:", 6) == 0
12437 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12438 {
12439 p += 6;
12440 bri_shift = getdigits(&p);
12441 }
12442 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12443 {
12444 p += 4;
12445 bri_min = getdigits(&p);
12446 }
12447 else if (STRNCMP(p, "sbr", 3) == 0)
12448 {
12449 p += 3;
12450 bri_sbr = TRUE;
12451 }
12452 if (*p != ',' && *p != NUL)
12453 return FAIL;
12454 if (*p == ',')
12455 ++p;
12456 }
12457
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012458 wp->w_p_brishift = bri_shift;
12459 wp->w_p_brimin = bri_min;
12460 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012461
12462 return OK;
12463}
12464#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012465
12466/*
12467 * Get the local or global value of 'backupcopy'.
12468 */
12469 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012470get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012471{
12472 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12473}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012474
12475#if defined(FEAT_SIGNS) || defined(PROTO)
12476/*
12477 * Return TRUE when window "wp" has a column to draw signs in.
12478 */
12479 int
12480signcolumn_on(win_T *wp)
12481{
12482 if (*wp->w_p_scl == 'n')
12483 return FALSE;
12484 if (*wp->w_p_scl == 'y')
12485 return TRUE;
12486 return (wp->w_buffer->b_signlist != NULL
12487# ifdef FEAT_NETBEANS_INTG
12488 || wp->w_buffer->b_has_sign_column
12489# endif
12490 );
12491}
12492#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012493
12494#if defined(FEAT_EVAL) || defined(PROTO)
12495/*
12496 * Get window or buffer local options.
12497 */
12498 dict_T *
12499get_winbuf_options(int bufopt)
12500{
12501 dict_T *d;
12502 int opt_idx;
12503
12504 d = dict_alloc();
12505 if (d == NULL)
12506 return NULL;
12507
12508 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12509 {
12510 struct vimoption *opt = &options[opt_idx];
12511
12512 if ((bufopt && (opt->indir & PV_BUF))
12513 || (!bufopt && (opt->indir & PV_WIN)))
12514 {
12515 char_u *varp = get_varp(opt);
12516
12517 if (varp != NULL)
12518 {
12519 if (opt->flags & P_STRING)
12520 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012521 else if (opt->flags & P_NUM)
12522 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012523 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012524 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012525 }
12526 }
12527 }
12528
12529 return d;
12530}
12531#endif