blob: 1237d048bac1c55352e0a55f846f1ae02a8e3364 [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. */
4957 for (s = newval; *s; ++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);
4969 s -= 2;
4970 }
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);
4978 --s;
4979 }
4980 }
4981 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004982 }
4983
4984 if (save_arg != NULL) /* number for 'whichwrap' */
4985 arg = save_arg;
4986 new_value_alloced = TRUE;
4987 }
4988
4989 /* Set the new value. */
4990 *(char_u **)(varp) = newval;
4991
Bram Moolenaar53744302015-07-17 17:38:22 +02004992#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02004993 if (!starting
4994# ifdef FEAT_CRYPT
4995 && options[opt_idx].indir != PV_KEY
4996# endif
Bram Moolenaar53744302015-07-17 17:38:22 +02004997 && origval != NULL)
4998 /* origval may be freed by
4999 * did_set_string_option(), make a copy. */
5000 saved_origval = vim_strsave(origval);
5001#endif
5002
Bram Moolenaar071d4272004-06-13 20:20:40 +00005003 /* Handle side effects, and set the global value for
5004 * ":set" on local options. */
5005 errmsg = did_set_string_option(opt_idx, (char_u **)varp,
5006 new_value_alloced, oldval, errbuf, opt_flags);
5007
5008 /* If error detected, print the error message. */
5009 if (errmsg != NULL)
Bram Moolenaara9884962015-12-13 15:08:56 +01005010 {
5011#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5012 vim_free(saved_origval);
5013#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005014 goto skip;
Bram Moolenaara9884962015-12-13 15:08:56 +01005015 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005016#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5017 if (saved_origval != NULL)
5018 {
5019 char_u buf_type[7];
5020
5021 sprintf((char *)buf_type, "%s",
5022 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005023 set_vim_var_string(VV_OPTION_NEW,
5024 *(char_u **)varp, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005025 set_vim_var_string(VV_OPTION_OLD, saved_origval, -1);
5026 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5027 apply_autocmds(EVENT_OPTIONSET,
5028 (char_u *)options[opt_idx].fullname,
5029 NULL, FALSE, NULL);
5030 reset_v_option_vars();
5031 vim_free(saved_origval);
5032 }
5033#endif
5034
Bram Moolenaar071d4272004-06-13 20:20:40 +00005035 }
5036 else /* key code option */
5037 {
5038 char_u *p;
5039
5040 if (nextchar == '&')
5041 {
5042 if (add_termcap_entry(key_name, TRUE) == FAIL)
5043 errmsg = (char_u *)N_("E522: Not found in termcap");
5044 }
5045 else
5046 {
5047 ++arg; /* jump to after the '=' or ':' */
5048 for (p = arg; *p && !vim_iswhite(*p); ++p)
5049 if (*p == '\\' && p[1] != NUL)
5050 ++p;
5051 nextchar = *p;
5052 *p = NUL;
5053 add_termcode(key_name, arg, FALSE);
5054 *p = nextchar;
5055 }
5056 if (full_screen)
5057 ttest(FALSE);
5058 redraw_all_later(CLEAR);
5059 }
5060 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005061
Bram Moolenaar071d4272004-06-13 20:20:40 +00005062 if (opt_idx >= 0)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005063 did_set_option(opt_idx, opt_flags,
5064 !prepending && !adding && !removing);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005065 }
5066
5067skip:
5068 /*
5069 * Advance to next argument.
5070 * - skip until a blank found, taking care of backslashes
5071 * - skip blanks
5072 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5073 */
5074 for (i = 0; i < 2 ; ++i)
5075 {
5076 while (*arg != NUL && !vim_iswhite(*arg))
5077 if (*arg++ == '\\' && *arg != NUL)
5078 ++arg;
5079 arg = skipwhite(arg);
5080 if (*arg != '=')
5081 break;
5082 }
5083 }
5084
5085 if (errmsg != NULL)
5086 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005087 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005088 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005089 if (i + (arg - startarg) < IOSIZE)
5090 {
5091 /* append the argument with the error */
5092 STRCAT(IObuff, ": ");
5093 mch_memmove(IObuff + i, startarg, (arg - startarg));
5094 IObuff[i + (arg - startarg)] = NUL;
5095 }
5096 /* make sure all characters are printable */
5097 trans_characters(IObuff, IOSIZE);
5098
5099 ++no_wait_return; /* wait_return done later */
5100 emsg(IObuff); /* show error highlighted */
5101 --no_wait_return;
5102
5103 return FAIL;
5104 }
5105
5106 arg = skipwhite(arg);
5107 }
5108
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005109theend:
5110 if (silent_mode && did_show)
5111 {
5112 /* After displaying option values in silent mode. */
5113 silent_mode = FALSE;
5114 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5115 msg_putchar('\n');
5116 cursor_on(); /* msg_start() switches it off */
5117 out_flush();
5118 silent_mode = TRUE;
5119 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5120 }
5121
Bram Moolenaar071d4272004-06-13 20:20:40 +00005122 return OK;
5123}
5124
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005125/*
5126 * Call this when an option has been given a new value through a user command.
5127 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5128 */
5129 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005130did_set_option(
5131 int opt_idx,
5132 int opt_flags, /* possibly with OPT_MODELINE */
5133 int new_value) /* value was replaced completely */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005134{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005135 long_u *p;
5136
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005137 options[opt_idx].flags |= P_WAS_SET;
5138
5139 /* When an option is set in the sandbox, from a modeline or in secure mode
5140 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005141 * flag. */
5142 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005143 if (secure
5144#ifdef HAVE_SANDBOX
5145 || sandbox != 0
5146#endif
5147 || (opt_flags & OPT_MODELINE))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005148 *p = *p | P_INSECURE;
5149 else if (new_value)
5150 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005151}
5152
Bram Moolenaar071d4272004-06-13 20:20:40 +00005153 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005154illegal_char(char_u *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005155{
5156 if (errbuf == NULL)
5157 return (char_u *)"";
5158 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005159 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005160 return errbuf;
5161}
5162
5163/*
5164 * Convert a key name or string into a key value.
5165 * Used for 'wildchar' and 'cedit' options.
5166 */
5167 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005168string_to_key(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005169{
5170 if (*arg == '<')
5171 return find_key_option(arg + 1);
5172 if (*arg == '^')
5173 return Ctrl_chr(arg[1]);
5174 return *arg;
5175}
5176
5177#ifdef FEAT_CMDWIN
5178/*
5179 * Check value of 'cedit' and set cedit_key.
5180 * Returns NULL if value is OK, error message otherwise.
5181 */
5182 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005183check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005184{
5185 int n;
5186
5187 if (*p_cedit == NUL)
5188 cedit_key = -1;
5189 else
5190 {
5191 n = string_to_key(p_cedit);
5192 if (vim_isprintc(n))
5193 return e_invarg;
5194 cedit_key = n;
5195 }
5196 return NULL;
5197}
5198#endif
5199
5200#ifdef FEAT_TITLE
5201/*
5202 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5203 * maketitle() to create and display it.
5204 * When switching the title or icon off, call mch_restore_title() to get
5205 * the old value back.
5206 */
5207 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005208did_set_title(
5209 int icon) /* Did set icon instead of title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005210{
5211 if (starting != NO_SCREEN
5212#ifdef FEAT_GUI
5213 && !gui.starting
5214#endif
5215 )
5216 {
5217 maketitle();
5218 if (icon)
5219 {
5220 if (!p_icon)
5221 mch_restore_title(2);
5222 }
5223 else
5224 {
5225 if (!p_title)
5226 mch_restore_title(1);
5227 }
5228 }
5229}
5230#endif
5231
5232/*
5233 * set_options_bin - called when 'bin' changes value.
5234 */
5235 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005236set_options_bin(
5237 int oldval,
5238 int newval,
5239 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005240{
5241 /*
5242 * The option values that are changed when 'bin' changes are
5243 * copied when 'bin is set and restored when 'bin' is reset.
5244 */
5245 if (newval)
5246 {
5247 if (!oldval) /* switched on */
5248 {
5249 if (!(opt_flags & OPT_GLOBAL))
5250 {
5251 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5252 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5253 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5254 curbuf->b_p_et_nobin = curbuf->b_p_et;
5255 }
5256 if (!(opt_flags & OPT_LOCAL))
5257 {
5258 p_tw_nobin = p_tw;
5259 p_wm_nobin = p_wm;
5260 p_ml_nobin = p_ml;
5261 p_et_nobin = p_et;
5262 }
5263 }
5264
5265 if (!(opt_flags & OPT_GLOBAL))
5266 {
5267 curbuf->b_p_tw = 0; /* no automatic line wrap */
5268 curbuf->b_p_wm = 0; /* no automatic line wrap */
5269 curbuf->b_p_ml = 0; /* no modelines */
5270 curbuf->b_p_et = 0; /* no expandtab */
5271 }
5272 if (!(opt_flags & OPT_LOCAL))
5273 {
5274 p_tw = 0;
5275 p_wm = 0;
5276 p_ml = FALSE;
5277 p_et = FALSE;
5278 p_bin = TRUE; /* needed when called for the "-b" argument */
5279 }
5280 }
5281 else if (oldval) /* switched off */
5282 {
5283 if (!(opt_flags & OPT_GLOBAL))
5284 {
5285 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5286 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5287 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5288 curbuf->b_p_et = curbuf->b_p_et_nobin;
5289 }
5290 if (!(opt_flags & OPT_LOCAL))
5291 {
5292 p_tw = p_tw_nobin;
5293 p_wm = p_wm_nobin;
5294 p_ml = p_ml_nobin;
5295 p_et = p_et_nobin;
5296 }
5297 }
5298}
5299
5300#ifdef FEAT_VIMINFO
5301/*
5302 * Find the parameter represented by the given character (eg ', :, ", or /),
5303 * and return its associated value in the 'viminfo' string.
5304 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005305 * If the parameter is not specified in the string or there is no following
5306 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307 */
5308 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005309get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005310{
5311 char_u *p;
5312
5313 p = find_viminfo_parameter(type);
5314 if (p != NULL && VIM_ISDIGIT(*p))
5315 return atoi((char *)p);
5316 return -1;
5317}
5318
5319/*
5320 * Find the parameter represented by the given character (eg ''', ':', '"', or
5321 * '/') in the 'viminfo' option and return a pointer to the string after it.
5322 * Return NULL if the parameter is not specified in the string.
5323 */
5324 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005325find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326{
5327 char_u *p;
5328
5329 for (p = p_viminfo; *p; ++p)
5330 {
5331 if (*p == type)
5332 return p + 1;
5333 if (*p == 'n') /* 'n' is always the last one */
5334 break;
5335 p = vim_strchr(p, ','); /* skip until next ',' */
5336 if (p == NULL) /* hit the end without finding parameter */
5337 break;
5338 }
5339 return NULL;
5340}
5341#endif
5342
5343/*
5344 * Expand environment variables for some string options.
5345 * These string options cannot be indirect!
5346 * If "val" is NULL expand the current value of the option.
5347 * Return pointer to NameBuff, or NULL when not expanded.
5348 */
5349 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005350option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005351{
5352 /* if option doesn't need expansion nothing to do */
5353 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5354 return NULL;
5355
5356 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5357 * expand_env() would truncate the string. */
5358 if (val != NULL && STRLEN(val) > MAXPATHL)
5359 return NULL;
5360
5361 if (val == NULL)
5362 val = *(char_u **)options[opt_idx].var;
5363
5364 /*
5365 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5366 * Escape spaces when expanding 'tags', they are used to separate file
5367 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005368 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005369 */
5370 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005371 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005372#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005373 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5374#endif
5375 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5377 return NULL;
5378
5379 return NameBuff;
5380}
5381
5382/*
5383 * After setting various option values: recompute variables that depend on
5384 * option values.
5385 */
5386 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005387didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005388{
5389 /* initialize the table for 'iskeyword' et.al. */
5390 (void)init_chartab();
5391
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005392#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00005393 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00005394#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005396 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397#ifdef FEAT_SESSION
5398 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5399 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5400#endif
5401#ifdef FEAT_FOLDING
5402 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5403#endif
5404 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005405 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005406#ifdef FEAT_VIRTUALEDIT
5407 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5408#endif
5409#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5410 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5411#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005412#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005413 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005414 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005415 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005416 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005417#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005418#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5419 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5420#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005421#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005422 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5423#endif
5424#ifdef FEAT_CMDWIN
5425 /* set cedit_key */
5426 (void)check_cedit();
5427#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005428#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005429 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005430#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005431#ifdef FEAT_LINEBREAK
5432 /* initialize the table for 'breakat'. */
5433 fill_breakat_flags();
5434#endif
5435
5436}
5437
5438/*
5439 * More side effects of setting options.
5440 */
5441 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005442didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005443{
5444 /* Initialize the highlight_attr[] table. */
5445 (void)highlight_changed();
5446
5447 /* Parse default for 'wildmode' */
5448 check_opt_wim();
5449
5450 (void)set_chars_option(&p_lcs);
5451#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
5452 /* Parse default for 'fillchars'. */
5453 (void)set_chars_option(&p_fcs);
5454#endif
5455
5456#ifdef FEAT_CLIPBOARD
5457 /* Parse default for 'clipboard' */
5458 (void)check_clipboard_option();
5459#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460}
5461
5462/*
5463 * Check for string options that are NULL (normally only termcap options).
5464 */
5465 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005466check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467{
5468 int opt_idx;
5469
5470 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5471 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5472 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5473}
5474
5475/*
5476 * Check string options in a buffer for NULL value.
5477 */
5478 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005479check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005480{
5481#if defined(FEAT_QUICKFIX)
5482 check_string_option(&buf->b_p_bh);
5483 check_string_option(&buf->b_p_bt);
5484#endif
5485#ifdef FEAT_MBYTE
5486 check_string_option(&buf->b_p_fenc);
5487#endif
5488 check_string_option(&buf->b_p_ff);
5489#ifdef FEAT_FIND_ID
5490 check_string_option(&buf->b_p_def);
5491 check_string_option(&buf->b_p_inc);
5492# ifdef FEAT_EVAL
5493 check_string_option(&buf->b_p_inex);
5494# endif
5495#endif
5496#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5497 check_string_option(&buf->b_p_inde);
5498 check_string_option(&buf->b_p_indk);
5499#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005500#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5501 check_string_option(&buf->b_p_bexpr);
5502#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005503#if defined(FEAT_CRYPT)
5504 check_string_option(&buf->b_p_cm);
5505#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005506 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005507#if defined(FEAT_EVAL)
5508 check_string_option(&buf->b_p_fex);
5509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005510#ifdef FEAT_CRYPT
5511 check_string_option(&buf->b_p_key);
5512#endif
5513 check_string_option(&buf->b_p_kp);
5514 check_string_option(&buf->b_p_mps);
5515 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005516 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517 check_string_option(&buf->b_p_isk);
5518#ifdef FEAT_COMMENTS
5519 check_string_option(&buf->b_p_com);
5520#endif
5521#ifdef FEAT_FOLDING
5522 check_string_option(&buf->b_p_cms);
5523#endif
5524 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005525#ifdef FEAT_TEXTOBJ
5526 check_string_option(&buf->b_p_qe);
5527#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005528#ifdef FEAT_SYN_HL
5529 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005530 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005531#endif
5532#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005533 check_string_option(&buf->b_s.b_p_spc);
5534 check_string_option(&buf->b_s.b_p_spf);
5535 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005536#endif
5537#ifdef FEAT_SEARCHPATH
5538 check_string_option(&buf->b_p_sua);
5539#endif
5540#ifdef FEAT_CINDENT
5541 check_string_option(&buf->b_p_cink);
5542 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005543 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005544#endif
5545#ifdef FEAT_AUTOCMD
5546 check_string_option(&buf->b_p_ft);
5547#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005548#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5549 check_string_option(&buf->b_p_cinw);
5550#endif
5551#ifdef FEAT_INS_EXPAND
5552 check_string_option(&buf->b_p_cpt);
5553#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005554#ifdef FEAT_COMPL_FUNC
5555 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005556 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005557#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005558#ifdef FEAT_KEYMAP
5559 check_string_option(&buf->b_p_keymap);
5560#endif
5561#ifdef FEAT_QUICKFIX
5562 check_string_option(&buf->b_p_gp);
5563 check_string_option(&buf->b_p_mp);
5564 check_string_option(&buf->b_p_efm);
5565#endif
5566 check_string_option(&buf->b_p_ep);
5567 check_string_option(&buf->b_p_path);
5568 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005569 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005570#ifdef FEAT_INS_EXPAND
5571 check_string_option(&buf->b_p_dict);
5572 check_string_option(&buf->b_p_tsr);
5573#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005574#ifdef FEAT_LISP
5575 check_string_option(&buf->b_p_lw);
5576#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005577 check_string_option(&buf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578}
5579
5580/*
5581 * Free the string allocated for an option.
5582 * Checks for the string being empty_option. This may happen if we're out of
5583 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5584 * check_options().
5585 * Does NOT check for P_ALLOCED flag!
5586 */
5587 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005588free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589{
5590 if (p != empty_option)
5591 vim_free(p);
5592}
5593
5594 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005595clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005596{
5597 if (*pp != empty_option)
5598 vim_free(*pp);
5599 *pp = empty_option;
5600}
5601
5602 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005603check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005604{
5605 if (*pp == NULL)
5606 *pp = empty_option;
5607}
5608
5609/*
5610 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5611 */
5612 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005613set_term_option_alloced(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005614{
5615 int opt_idx;
5616
5617 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5618 if (options[opt_idx].var == (char_u *)p)
5619 {
5620 options[opt_idx].flags |= P_ALLOCED;
5621 return;
5622 }
5623 return; /* cannot happen: didn't find it! */
5624}
5625
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005626#if defined(FEAT_EVAL) || defined(PROTO)
5627/*
5628 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5629 * Return FALSE when it wasn't.
5630 * Return -1 for an unknown option.
5631 */
5632 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005633was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005634{
5635 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005636 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005637
5638 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005639 {
5640 flagp = insecure_flag(idx, opt_flags);
5641 return (*flagp & P_INSECURE) != 0;
5642 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005643 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005644 return -1;
5645}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005646
5647/*
5648 * Get a pointer to the flags used for the P_INSECURE flag of option
5649 * "opt_idx". For some local options a local flags field is used.
5650 */
5651 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005652insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005653{
5654 if (opt_flags & OPT_LOCAL)
5655 switch ((int)options[opt_idx].indir)
5656 {
5657#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005658 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005659#endif
5660#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005661# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005662 case PV_FDE: return &curwin->w_p_fde_flags;
5663 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005664# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005665# ifdef FEAT_BEVAL
5666 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5667# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005668# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005669 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005670# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005671 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005672# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005673 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005674# endif
5675#endif
5676 }
5677
5678 /* Nothing special, return global flags field. */
5679 return &options[opt_idx].flags;
5680}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005681#endif
5682
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005683#ifdef FEAT_TITLE
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01005684static void redraw_titles(void);
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005685
5686/*
5687 * Redraw the window title and/or tab page text later.
5688 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005689static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005690{
5691 need_maketitle = TRUE;
5692# ifdef FEAT_WINDOWS
5693 redraw_tabline = TRUE;
5694# endif
5695}
5696#endif
5697
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698/*
5699 * Set a string option to a new value (without checking the effect).
5700 * The string is copied into allocated memory.
5701 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005702 * When "set_sid" is zero set the scriptID to current_SID. When "set_sid" is
Bram Moolenaard55de222007-05-06 13:38:48 +00005703 * SID_NONE don't set the scriptID. Otherwise set the scriptID to "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704 */
5705 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005706set_string_option_direct(
5707 char_u *name,
5708 int opt_idx,
5709 char_u *val,
5710 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5711 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712{
5713 char_u *s;
5714 char_u **varp;
5715 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005716 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005717
Bram Moolenaar89d40322006-08-29 15:30:07 +00005718 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005720 idx = findoption(name);
5721 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005722 {
5723 EMSG2(_(e_intern2), "set_string_option_direct()");
Bram Moolenaar95f09602016-11-10 20:01:45 +01005724 IEMSG2(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005725 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005727 }
5728
Bram Moolenaar89d40322006-08-29 15:30:07 +00005729 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005730 return;
5731
5732 s = vim_strsave(val);
5733 if (s != NULL)
5734 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005735 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005737 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005738 free_string_option(*varp);
5739 *varp = s;
5740
5741 /* For buffer/window local option may also set the global value. */
5742 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005743 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005744
Bram Moolenaar89d40322006-08-29 15:30:07 +00005745 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746
5747 /* When setting both values of a global option with a local value,
5748 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005749 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005750 {
5751 free_string_option(*varp);
5752 *varp = empty_option;
5753 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005754# ifdef FEAT_EVAL
5755 if (set_sid != SID_NONE)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005756 set_option_scriptID_idx(idx, opt_flags,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005757 set_sid == 0 ? current_SID : set_sid);
5758# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759 }
5760}
5761
5762/*
5763 * Set global value for string option when it's a local option.
5764 */
5765 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005766set_string_option_global(
5767 int opt_idx, /* option index */
5768 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769{
5770 char_u **p, *s;
5771
5772 /* the global value is always allocated */
5773 if (options[opt_idx].var == VAR_WIN)
5774 p = (char_u **)GLOBAL_WO(varp);
5775 else
5776 p = (char_u **)options[opt_idx].var;
5777 if (options[opt_idx].indir != PV_NONE
5778 && p != varp
5779 && (s = vim_strsave(*varp)) != NULL)
5780 {
5781 free_string_option(*p);
5782 *p = s;
5783 }
5784}
5785
5786/*
5787 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005788 *
5789 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005790 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005791 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005792set_string_option(
5793 int opt_idx,
5794 char_u *value,
5795 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005796{
5797 char_u *s;
5798 char_u **varp;
5799 char_u *oldval;
Bram Moolenaar53744302015-07-17 17:38:22 +02005800#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5801 char_u *saved_oldval = NULL;
5802#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005803 char_u *r = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005804
5805 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005806 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005807
5808 s = vim_strsave(value);
5809 if (s != NULL)
5810 {
5811 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5812 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005813 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005814 ? OPT_GLOBAL : OPT_LOCAL)
5815 : opt_flags);
5816 oldval = *varp;
5817 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005818
5819#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005820 if (!starting
5821# ifdef FEAT_CRYPT
5822 && options[opt_idx].indir != PV_KEY
5823# endif
5824 )
Bram Moolenaar53744302015-07-17 17:38:22 +02005825 saved_oldval = vim_strsave(oldval);
5826#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005827 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
5828 opt_flags)) == NULL)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005829 did_set_option(opt_idx, opt_flags, TRUE);
Bram Moolenaar53744302015-07-17 17:38:22 +02005830
5831 /* call autocomamnd after handling side effects */
5832#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
5833 if (saved_oldval != NULL)
5834 {
5835 char_u buf_type[7];
5836 sprintf((char *)buf_type, "%s",
5837 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar9cac4242015-07-19 14:42:23 +02005838 set_vim_var_string(VV_OPTION_NEW, *varp, -1);
5839 set_vim_var_string(VV_OPTION_OLD, saved_oldval, -1);
Bram Moolenaar53744302015-07-17 17:38:22 +02005840 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
5841 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
5842 reset_v_option_vars();
5843 vim_free(saved_oldval);
5844 }
5845#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005846 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005847 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005848}
5849
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005850#if defined(FEAT_KEYMAP) || defined(FEAT_AUTOCMD) || defined(FEAT_SYN_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005851/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005852 * Return TRUE if "val" is a valid 'filetype' name.
5853 * Also used for 'syntax' and 'keymap'.
5854 */
5855 static int
5856valid_filetype(char_u *val)
5857{
5858 char_u *s;
5859
5860 for (s = val; *s != NUL; ++s)
5861 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5862 return FALSE;
5863 return TRUE;
5864}
Bram Moolenaar40d3f132016-11-05 20:13:35 +01005865#endif
Bram Moolenaard0b51382016-11-04 15:23:45 +01005866
5867/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005868 * Handle string options that need some action to perform when changed.
5869 * Returns NULL for success, or an error message for an error.
5870 */
5871 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005872did_set_string_option(
5873 int opt_idx, /* index in options[] table */
5874 char_u **varp, /* pointer to the option variable */
5875 int new_value_alloced, /* new value was allocated */
5876 char_u *oldval, /* previous value of the option */
5877 char_u *errbuf, /* buffer for errors, or NULL */
5878 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879{
5880 char_u *errmsg = NULL;
5881 char_u *s, *p;
5882 int did_chartab = FALSE;
5883 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005884 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00005885#ifdef FEAT_GUI
5886 /* set when changing an option that only requires a redraw in the GUI */
5887 int redraw_gui_only = FALSE;
5888#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889
5890 /* Get the global option to compare with, otherwise we would have to check
5891 * two values for all local options. */
5892 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
5893
5894 /* Disallow changing some options from secure mode */
5895 if ((secure
5896#ifdef HAVE_SANDBOX
5897 || sandbox != 0
5898#endif
5899 ) && (options[opt_idx].flags & P_SECURE))
5900 {
5901 errmsg = e_secure;
5902 }
5903
Bram Moolenaar7554da42016-11-25 22:04:13 +01005904 /* Check for a "normal" directory or file name in some options. Disallow a
5905 * path separator (slash and/or backslash), wildcards and characters that
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005906 * are often illegal in a file name. Be more permissive if "secure" is off.
5907 */
Bram Moolenaar7554da42016-11-25 22:04:13 +01005908 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01005909 && vim_strpbrk(*varp, (char_u *)(secure
5910 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01005911 || ((options[opt_idx].flags & P_NDNAME)
5912 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00005913 {
5914 errmsg = e_invarg;
5915 }
5916
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917 /* 'term' */
5918 else if (varp == &T_NAME)
5919 {
5920 if (T_NAME[0] == NUL)
5921 errmsg = (char_u *)N_("E529: Cannot set 'term' to empty string");
5922#ifdef FEAT_GUI
5923 if (gui.in_use)
5924 errmsg = (char_u *)N_("E530: Cannot change term in GUI");
5925 else if (term_is_gui(T_NAME))
5926 errmsg = (char_u *)N_("E531: Use \":gui\" to start the GUI");
5927#endif
5928 else if (set_termname(T_NAME) == FAIL)
5929 errmsg = (char_u *)N_("E522: Not found in termcap");
5930 else
5931 /* Screen colors may have changed. */
5932 redraw_later_clear();
5933 }
5934
5935 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005936 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005938 char_u *bkc = p_bkc;
5939 unsigned int *flags = &bkc_flags;
5940
5941 if (opt_flags & OPT_LOCAL)
5942 {
5943 bkc = curbuf->b_p_bkc;
5944 flags = &curbuf->b_bkc_flags;
5945 }
5946
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005947 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
5948 /* make the local value empty: use the global value */
5949 *flags = 0;
5950 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005951 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02005952 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
5953 errmsg = e_invarg;
5954 if ((((int)*flags & BKC_AUTO) != 0)
5955 + (((int)*flags & BKC_YES) != 0)
5956 + (((int)*flags & BKC_NO) != 0) != 1)
5957 {
5958 /* Must have exactly one of "auto", "yes" and "no". */
5959 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
5960 errmsg = e_invarg;
5961 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005962 }
5963 }
5964
5965 /* 'backupext' and 'patchmode' */
5966 else if (varp == &p_bex || varp == &p_pm)
5967 {
5968 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
5969 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
5970 errmsg = (char_u *)N_("E589: 'backupext' and 'patchmode' are equal");
5971 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02005972#ifdef FEAT_LINEBREAK
5973 /* 'breakindentopt' */
5974 else if (varp == &curwin->w_p_briopt)
5975 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005976 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02005977 errmsg = e_invarg;
5978 }
5979#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005980
5981 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005982 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00005983 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01005984 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00005985 */
5986 else if ( varp == &p_isi
5987 || varp == &(curbuf->b_p_isk)
5988 || varp == &p_isp
5989 || varp == &p_isf)
5990 {
5991 if (init_chartab() == FAIL)
5992 {
5993 did_chartab = TRUE; /* need to restore it below */
5994 errmsg = e_invarg; /* error in value */
5995 }
5996 }
5997
5998 /* 'helpfile' */
5999 else if (varp == &p_hf)
6000 {
6001 /* May compute new values for $VIM and $VIMRUNTIME */
6002 if (didset_vim)
6003 {
6004 vim_setenv((char_u *)"VIM", (char_u *)"");
6005 didset_vim = FALSE;
6006 }
6007 if (didset_vimruntime)
6008 {
6009 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6010 didset_vimruntime = FALSE;
6011 }
6012 }
6013
Bram Moolenaar1a384422010-07-14 19:53:30 +02006014#ifdef FEAT_SYN_HL
6015 /* 'colorcolumn' */
6016 else if (varp == &curwin->w_p_cc)
6017 errmsg = check_colorcolumn(curwin);
6018#endif
6019
Bram Moolenaar071d4272004-06-13 20:20:40 +00006020#ifdef FEAT_MULTI_LANG
6021 /* 'helplang' */
6022 else if (varp == &p_hlg)
6023 {
6024 /* Check for "", "ab", "ab,cd", etc. */
6025 for (s = p_hlg; *s != NUL; s += 3)
6026 {
6027 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6028 {
6029 errmsg = e_invarg;
6030 break;
6031 }
6032 if (s[2] == NUL)
6033 break;
6034 }
6035 }
6036#endif
6037
6038 /* 'highlight' */
6039 else if (varp == &p_hl)
6040 {
6041 if (highlight_changed() == FAIL)
6042 errmsg = e_invarg; /* invalid flags */
6043 }
6044
6045 /* 'nrformats' */
6046 else if (gvarp == &p_nf)
6047 {
6048 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6049 errmsg = e_invarg;
6050 }
6051
6052#ifdef FEAT_SESSION
6053 /* 'sessionoptions' */
6054 else if (varp == &p_ssop)
6055 {
6056 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6057 errmsg = e_invarg;
6058 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6059 {
6060 /* Don't allow both "sesdir" and "curdir". */
6061 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6062 errmsg = e_invarg;
6063 }
6064 }
6065 /* 'viewoptions' */
6066 else if (varp == &p_vop)
6067 {
6068 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6069 errmsg = e_invarg;
6070 }
6071#endif
6072
6073 /* 'scrollopt' */
6074#ifdef FEAT_SCROLLBIND
6075 else if (varp == &p_sbo)
6076 {
6077 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6078 errmsg = e_invarg;
6079 }
6080#endif
6081
6082 /* 'ambiwidth' */
6083#ifdef FEAT_MBYTE
Bram Moolenaar3848e002016-03-19 18:42:29 +01006084 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006085 {
6086 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6087 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006088 else if (set_chars_option(&p_lcs) != NULL)
6089 errmsg = (char_u *)_("E834: Conflicts with value of 'listchars'");
6090# if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6091 else if (set_chars_option(&p_fcs) != NULL)
6092 errmsg = (char_u *)_("E835: Conflicts with value of 'fillchars'");
6093# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006094 }
6095#endif
6096
6097 /* 'background' */
6098 else if (varp == &p_bg)
6099 {
6100 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6101 {
6102#ifdef FEAT_EVAL
6103 int dark = (*p_bg == 'd');
6104#endif
6105
6106 init_highlight(FALSE, FALSE);
6107
6108#ifdef FEAT_EVAL
6109 if (dark != (*p_bg == 'd')
6110 && get_var_value((char_u *)"g:colors_name") != NULL)
6111 {
6112 /* The color scheme must have set 'background' back to another
6113 * value, that's not what we want here. Disable the color
6114 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006115 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 free_string_option(p_bg);
6117 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6118 check_string_option(&p_bg);
6119 init_highlight(FALSE, FALSE);
6120 }
6121#endif
6122 }
6123 else
6124 errmsg = e_invarg;
6125 }
6126
6127 /* 'wildmode' */
6128 else if (varp == &p_wim)
6129 {
6130 if (check_opt_wim() == FAIL)
6131 errmsg = e_invarg;
6132 }
6133
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006134#ifdef FEAT_CMDL_COMPL
6135 /* 'wildoptions' */
6136 else if (varp == &p_wop)
6137 {
6138 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6139 errmsg = e_invarg;
6140 }
6141#endif
6142
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143#ifdef FEAT_WAK
6144 /* 'winaltkeys' */
6145 else if (varp == &p_wak)
6146 {
6147 if (*p_wak == NUL
6148 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6149 errmsg = e_invarg;
6150# ifdef FEAT_MENU
6151# ifdef FEAT_GUI_MOTIF
6152 else if (gui.in_use)
6153 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6154# else
6155# ifdef FEAT_GUI_GTK
6156 else if (gui.in_use)
6157 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6158# endif
6159# endif
6160# endif
6161 }
6162#endif
6163
6164#ifdef FEAT_AUTOCMD
6165 /* 'eventignore' */
6166 else if (varp == &p_ei)
6167 {
6168 if (check_ei() == FAIL)
6169 errmsg = e_invarg;
6170 }
6171#endif
6172
6173#ifdef FEAT_MBYTE
6174 /* 'encoding' and 'fileencoding' */
6175 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc)
6176 {
6177 if (gvarp == &p_fenc)
6178 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006179 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006180 errmsg = e_modifiable;
6181 else if (vim_strchr(*varp, ',') != NULL)
6182 /* No comma allowed in 'fileencoding'; catches confusing it
6183 * with 'fileencodings'. */
6184 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006185 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006186 {
6187# ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006189 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006190# endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006191 /* Add 'fileencoding' to the swap file. */
6192 ml_setflags(curbuf);
6193 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006194 }
6195 if (errmsg == NULL)
6196 {
6197 /* canonize the value, so that STRCMP() can be used on it */
6198 p = enc_canonize(*varp);
6199 if (p != NULL)
6200 {
6201 vim_free(*varp);
6202 *varp = p;
6203 }
6204 if (varp == &p_enc)
6205 {
6206 errmsg = mb_init();
6207# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006208 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006209# endif
6210 }
6211 }
6212
Bram Moolenaar182c5be2010-06-25 05:37:59 +02006213# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006214 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6215 {
6216 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6217 if (STRCMP(p_tenc, "utf-8") != 0)
6218 errmsg = (char_u *)N_("E617: Cannot be changed in the GTK+ 2 GUI");
6219 }
6220# endif
6221
6222 if (errmsg == NULL)
6223 {
6224# ifdef FEAT_KEYMAP
6225 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6226 * (with another encoding). */
6227 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6228 (void)keymap_init();
6229# endif
6230
6231 /* When 'termencoding' is not empty and 'encoding' changes or when
6232 * 'termencoding' changes, need to setup for keyboard input and
6233 * display output conversion. */
6234 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6235 {
6236 convert_setup(&input_conv, p_tenc, p_enc);
6237 convert_setup(&output_conv, p_enc, p_tenc);
6238 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006239
6240# if defined(WIN3264) && defined(FEAT_MBYTE)
6241 /* $HOME may have characters in active code page. */
6242 if (varp == &p_enc)
6243 init_homedir();
6244# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006245 }
6246 }
6247#endif
6248
6249#if defined(FEAT_POSTSCRIPT)
6250 else if (varp == &p_penc)
6251 {
6252 /* Canonize printencoding if VIM standard one */
6253 p = enc_canonize(p_penc);
6254 if (p != NULL)
6255 {
6256 vim_free(p_penc);
6257 p_penc = p;
6258 }
6259 else
6260 {
6261 /* Ensure lower case and '-' for '_' */
6262 for (s = p_penc; *s != NUL; s++)
6263 {
6264 if (*s == '_')
6265 *s = '-';
6266 else
6267 *s = TOLOWER_ASC(*s);
6268 }
6269 }
6270 }
6271#endif
6272
Bram Moolenaar9372a112005-12-06 19:59:18 +00006273#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006274 else if (varp == &p_imak)
6275 {
6276 if (gui.in_use && !im_xim_isvalid_imactivate())
6277 errmsg = e_invarg;
6278 }
6279#endif
6280
6281#ifdef FEAT_KEYMAP
6282 else if (varp == &curbuf->b_p_keymap)
6283 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006284 if (!valid_filetype(*varp))
6285 errmsg = e_invarg;
6286 else
6287 /* load or unload key mapping tables */
6288 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289
Bram Moolenaarfab06232009-03-04 03:13:35 +00006290 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006291 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006292 if (*curbuf->b_p_keymap != NUL)
6293 {
6294 /* Installed a new keymap, switch on using it. */
6295 curbuf->b_p_iminsert = B_IMODE_LMAP;
6296 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6297 curbuf->b_p_imsearch = B_IMODE_LMAP;
6298 }
6299 else
6300 {
6301 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6302 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6303 curbuf->b_p_iminsert = B_IMODE_NONE;
6304 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6305 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6306 }
6307 if ((opt_flags & OPT_LOCAL) == 0)
6308 {
6309 set_iminsert_global();
6310 set_imsearch_global();
6311 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006312# ifdef FEAT_WINDOWS
6313 status_redraw_curbuf();
6314# endif
6315 }
6316 }
6317#endif
6318
6319 /* 'fileformat' */
6320 else if (gvarp == &p_ff)
6321 {
6322 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6323 errmsg = e_modifiable;
6324 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6325 errmsg = e_invarg;
6326 else
6327 {
6328 /* may also change 'textmode' */
6329 if (get_fileformat(curbuf) == EOL_DOS)
6330 curbuf->b_p_tx = TRUE;
6331 else
6332 curbuf->b_p_tx = FALSE;
6333#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006334 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006335#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006336 /* update flag in swap file */
6337 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006338 /* Redraw needed when switching to/from "mac": a CR in the text
6339 * will be displayed differently. */
6340 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6341 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006342 }
6343 }
6344
6345 /* 'fileformats' */
6346 else if (varp == &p_ffs)
6347 {
6348 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6349 errmsg = e_invarg;
6350 else
6351 {
6352 /* also change 'textauto' */
6353 if (*p_ffs == NUL)
6354 p_ta = FALSE;
6355 else
6356 p_ta = TRUE;
6357 }
6358 }
6359
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006360#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006361 /* 'cryptkey' */
6362 else if (gvarp == &p_key)
6363 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006364# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006365 /* Make sure the ":set" command doesn't show the new value in the
6366 * history. */
6367 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006368# endif
6369 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6370 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006371 ml_set_crypt_key(curbuf, oldval,
6372 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006373 }
6374
6375 else if (gvarp == &p_cm)
6376 {
6377 if (opt_flags & OPT_LOCAL)
6378 p = curbuf->b_p_cm;
6379 else
6380 p = p_cm;
6381 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6382 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006383 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006384 errmsg = e_invarg;
6385 else
6386 {
6387 /* When setting the global value to empty, make it "zip". */
6388 if (*p_cm == NUL)
6389 {
6390 if (new_value_alloced)
6391 free_string_option(p_cm);
6392 p_cm = vim_strsave((char_u *)"zip");
6393 new_value_alloced = TRUE;
6394 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006395 /* When using ":set cm=name" the local value is going to be empty.
6396 * Do that here, otherwise the crypt functions will still use the
6397 * local value. */
6398 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6399 {
6400 free_string_option(curbuf->b_p_cm);
6401 curbuf->b_p_cm = empty_option;
6402 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006403
6404 /* Need to update the swapfile when the effective method changed.
6405 * Set "s" to the effective old value, "p" to the effective new
6406 * method and compare. */
6407 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6408 s = p_cm; /* was previously using the global value */
6409 else
6410 s = oldval;
6411 if (*curbuf->b_p_cm == NUL)
6412 p = p_cm; /* is now using the global value */
6413 else
6414 p = curbuf->b_p_cm;
6415 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006416 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006417
6418 /* If the global value changes need to update the swapfile for all
6419 * buffers using that value. */
6420 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6421 {
6422 buf_T *buf;
6423
Bram Moolenaar29323592016-07-24 22:04:11 +02006424 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006425 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006426 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006427 }
6428 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006429 }
6430#endif
6431
6432 /* 'matchpairs' */
6433 else if (gvarp == &p_mps)
6434 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006435#ifdef FEAT_MBYTE
6436 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006437 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006438 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006440 int x2 = -1;
6441 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006442
6443 if (*p != NUL)
6444 p += mb_ptr2len(p);
6445 if (*p != NUL)
6446 x2 = *p++;
6447 if (*p != NUL)
6448 {
6449 x3 = mb_ptr2char(p);
6450 p += mb_ptr2len(p);
6451 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006452 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006453 {
6454 errmsg = e_invarg;
6455 break;
6456 }
6457 if (*p == NUL)
6458 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006459 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006460 }
6461 else
6462#endif
6463 {
6464 /* Check for "x:y,x:y" */
6465 for (p = *varp; *p != NUL; p += 4)
6466 {
6467 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6468 {
6469 errmsg = e_invarg;
6470 break;
6471 }
6472 if (p[3] == NUL)
6473 break;
6474 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006475 }
6476 }
6477
6478#ifdef FEAT_COMMENTS
6479 /* 'comments' */
6480 else if (gvarp == &p_com)
6481 {
6482 for (s = *varp; *s; )
6483 {
6484 while (*s && *s != ':')
6485 {
6486 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6487 && !VIM_ISDIGIT(*s) && *s != '-')
6488 {
6489 errmsg = illegal_char(errbuf, *s);
6490 break;
6491 }
6492 ++s;
6493 }
6494 if (*s++ == NUL)
6495 errmsg = (char_u *)N_("E524: Missing colon");
6496 else if (*s == ',' || *s == NUL)
6497 errmsg = (char_u *)N_("E525: Zero length string");
6498 if (errmsg != NULL)
6499 break;
6500 while (*s && *s != ',')
6501 {
6502 if (*s == '\\' && s[1] != NUL)
6503 ++s;
6504 ++s;
6505 }
6506 s = skip_to_option_part(s);
6507 }
6508 }
6509#endif
6510
6511 /* 'listchars' */
6512 else if (varp == &p_lcs)
6513 {
6514 errmsg = set_chars_option(varp);
6515 }
6516
6517#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
6518 /* 'fillchars' */
6519 else if (varp == &p_fcs)
6520 {
6521 errmsg = set_chars_option(varp);
6522 }
6523#endif
6524
6525#ifdef FEAT_CMDWIN
6526 /* 'cedit' */
6527 else if (varp == &p_cedit)
6528 {
6529 errmsg = check_cedit();
6530 }
6531#endif
6532
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006533 /* 'verbosefile' */
6534 else if (varp == &p_vfile)
6535 {
6536 verbose_stop();
6537 if (*p_vfile != NUL && verbose_open() == FAIL)
6538 errmsg = e_invarg;
6539 }
6540
Bram Moolenaar071d4272004-06-13 20:20:40 +00006541#ifdef FEAT_VIMINFO
6542 /* 'viminfo' */
6543 else if (varp == &p_viminfo)
6544 {
6545 for (s = p_viminfo; *s;)
6546 {
6547 /* Check it's a valid character */
6548 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6549 {
6550 errmsg = illegal_char(errbuf, *s);
6551 break;
6552 }
6553 if (*s == 'n') /* name is always last one */
6554 {
6555 break;
6556 }
6557 else if (*s == 'r') /* skip until next ',' */
6558 {
6559 while (*++s && *s != ',')
6560 ;
6561 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006562 else if (*s == '%')
6563 {
6564 /* optional number */
6565 while (vim_isdigit(*++s))
6566 ;
6567 }
6568 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006569 ++s; /* no extra chars */
6570 else /* must have a number */
6571 {
6572 while (vim_isdigit(*++s))
6573 ;
6574
6575 if (!VIM_ISDIGIT(*(s - 1)))
6576 {
6577 if (errbuf != NULL)
6578 {
Bram Moolenaar8f999f12005-01-25 22:12:55 +00006579 sprintf((char *)errbuf,
6580 _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 transchar_byte(*(s - 1)));
6582 errmsg = errbuf;
6583 }
6584 else
6585 errmsg = (char_u *)"";
6586 break;
6587 }
6588 }
6589 if (*s == ',')
6590 ++s;
6591 else if (*s)
6592 {
6593 if (errbuf != NULL)
6594 errmsg = (char_u *)N_("E527: Missing comma");
6595 else
6596 errmsg = (char_u *)"";
6597 break;
6598 }
6599 }
6600 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
6601 errmsg = (char_u *)N_("E528: Must specify a ' value");
6602 }
6603#endif /* FEAT_VIMINFO */
6604
6605 /* terminal options */
6606 else if (istermoption(&options[opt_idx]) && full_screen)
6607 {
6608 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6609 if (varp == &T_CCO)
6610 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006611 int colors = atoi((char *)T_CCO);
6612
6613 /* Only reinitialize colors if t_Co value has really changed to
6614 * avoid expensive reload of colorscheme if t_Co is set to the
6615 * same value multiple times. */
6616 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006617 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006618 t_colors = colors;
6619 if (t_colors <= 1)
6620 {
6621 if (new_value_alloced)
6622 vim_free(T_CCO);
6623 T_CCO = empty_option;
6624 }
6625 /* We now have a different color setup, initialize it again. */
6626 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006627 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006628 }
6629 ttest(FALSE);
6630 if (varp == &T_ME)
6631 {
6632 out_str(T_ME);
6633 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006634#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 /* Since t_me has been set, this probably means that the user
6636 * wants to use this as default colors. Need to reset default
6637 * background/foreground colors. */
6638 mch_set_normal_colors();
6639#endif
6640 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006641 if (varp == &T_BE && termcap_active)
6642 {
6643 if (*T_BE == NUL)
6644 /* When clearing t_BE we assume the user no longer wants
6645 * bracketed paste, thus disable it by writing t_BD. */
6646 out_str(T_BD);
6647 else
6648 out_str(T_BE);
6649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006650 }
6651
6652#ifdef FEAT_LINEBREAK
6653 /* 'showbreak' */
6654 else if (varp == &p_sbr)
6655 {
6656 for (s = p_sbr; *s; )
6657 {
6658 if (ptr2cells(s) != 1)
6659 errmsg = (char_u *)N_("E595: contains unprintable or wide character");
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006660 mb_ptr_adv(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006661 }
6662 }
6663#endif
6664
6665#ifdef FEAT_GUI
6666 /* 'guifont' */
6667 else if (varp == &p_guifont)
6668 {
6669 if (gui.in_use)
6670 {
6671 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006672# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006673 /*
6674 * Put up a font dialog and let the user select a new value.
6675 * If this is cancelled go back to the old value but don't
6676 * give an error message.
6677 */
6678 if (STRCMP(p, "*") == 0)
6679 {
6680 p = gui_mch_font_dialog(oldval);
6681
6682 if (new_value_alloced)
6683 free_string_option(p_guifont);
6684
6685 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6686 new_value_alloced = TRUE;
6687 }
6688# endif
6689 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6690 {
6691# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6692 if (STRCMP(p_guifont, "*") == 0)
6693 {
6694 /* Dialog was cancelled: Keep the old value without giving
6695 * an error message. */
6696 if (new_value_alloced)
6697 free_string_option(p_guifont);
6698 p_guifont = vim_strsave(oldval);
6699 new_value_alloced = TRUE;
6700 }
6701 else
6702# endif
6703 errmsg = (char_u *)N_("E596: Invalid font(s)");
6704 }
6705 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006706 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006707 }
6708# ifdef FEAT_XFONTSET
6709 else if (varp == &p_guifontset)
6710 {
6711 if (STRCMP(p_guifontset, "*") == 0)
6712 errmsg = (char_u *)N_("E597: can't select fontset");
6713 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
6714 errmsg = (char_u *)N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006715 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006716 }
6717# endif
6718# ifdef FEAT_MBYTE
6719 else if (varp == &p_guifontwide)
6720 {
6721 if (STRCMP(p_guifontwide, "*") == 0)
6722 errmsg = (char_u *)N_("E533: can't select wide font");
6723 else if (gui_get_wide_font() == FAIL)
6724 errmsg = (char_u *)N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006725 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006726 }
6727# endif
6728#endif
6729
6730#ifdef CURSOR_SHAPE
6731 /* 'guicursor' */
6732 else if (varp == &p_guicursor)
6733 errmsg = parse_shape_opt(SHAPE_CURSOR);
6734#endif
6735
6736#ifdef FEAT_MOUSESHAPE
6737 /* 'mouseshape' */
6738 else if (varp == &p_mouseshape)
6739 {
6740 errmsg = parse_shape_opt(SHAPE_MOUSE);
6741 update_mouseshape(-1);
6742 }
6743#endif
6744
6745#ifdef FEAT_PRINTER
6746 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006747 errmsg = parse_printoptions();
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00006748# if defined(FEAT_MBYTE) && defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006749 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006750 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006751# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006752#endif
6753
6754#ifdef FEAT_LANGMAP
6755 /* 'langmap' */
6756 else if (varp == &p_langmap)
6757 langmap_set();
6758#endif
6759
6760#ifdef FEAT_LINEBREAK
6761 /* 'breakat' */
6762 else if (varp == &p_breakat)
6763 fill_breakat_flags();
6764#endif
6765
6766#ifdef FEAT_TITLE
6767 /* 'titlestring' and 'iconstring' */
6768 else if (varp == &p_titlestring || varp == &p_iconstring)
6769 {
6770# ifdef FEAT_STL_OPT
6771 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6772
6773 /* NULL => statusline syntax */
6774 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6775 stl_syntax |= flagval;
6776 else
6777 stl_syntax &= ~flagval;
6778# endif
6779 did_set_title(varp == &p_iconstring);
6780
6781 }
6782#endif
6783
6784#ifdef FEAT_GUI
6785 /* 'guioptions' */
6786 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006787 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006788 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006789 redraw_gui_only = TRUE;
6790 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006791#endif
6792
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006793#if defined(FEAT_GUI_TABLINE)
6794 /* 'guitablabel' */
6795 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006796 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006797 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006798 redraw_gui_only = TRUE;
6799 }
6800 /* 'guitabtooltip' */
6801 else if (varp == &p_gtt)
6802 {
6803 redraw_gui_only = TRUE;
6804 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006805#endif
6806
Bram Moolenaar071d4272004-06-13 20:20:40 +00006807#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6808 /* 'ttymouse' */
6809 else if (varp == &p_ttym)
6810 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006811 /* Switch the mouse off before changing the escape sequences used for
6812 * that. */
6813 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006814 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6815 errmsg = e_invarg;
6816 else
6817 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006818 if (termcap_active)
6819 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006820 }
6821#endif
6822
Bram Moolenaar071d4272004-06-13 20:20:40 +00006823 /* 'selection' */
6824 else if (varp == &p_sel)
6825 {
6826 if (*p_sel == NUL
6827 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6828 errmsg = e_invarg;
6829 }
6830
6831 /* 'selectmode' */
6832 else if (varp == &p_slm)
6833 {
6834 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6835 errmsg = e_invarg;
6836 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006837
6838#ifdef FEAT_BROWSE
6839 /* 'browsedir' */
6840 else if (varp == &p_bsdir)
6841 {
6842 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6843 && !mch_isdir(p_bsdir))
6844 errmsg = e_invarg;
6845 }
6846#endif
6847
Bram Moolenaar071d4272004-06-13 20:20:40 +00006848 /* 'keymodel' */
6849 else if (varp == &p_km)
6850 {
6851 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
6852 errmsg = e_invarg;
6853 else
6854 {
6855 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
6856 km_startsel = (vim_strchr(p_km, 'a') != NULL);
6857 }
6858 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006859
6860 /* 'mousemodel' */
6861 else if (varp == &p_mousem)
6862 {
6863 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
6864 errmsg = e_invarg;
6865#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
6866 else if (*p_mousem != *oldval)
6867 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
6868 * to create or delete the popup menus. */
6869 gui_motif_update_mousemodel(root_menu);
6870#endif
6871 }
6872
6873 /* 'switchbuf' */
6874 else if (varp == &p_swb)
6875 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00006876 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006877 errmsg = e_invarg;
6878 }
6879
6880 /* 'debug' */
6881 else if (varp == &p_debug)
6882 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00006883 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 errmsg = e_invarg;
6885 }
6886
6887 /* 'display' */
6888 else if (varp == &p_dy)
6889 {
6890 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
6891 errmsg = e_invarg;
6892 else
6893 (void)init_chartab();
6894
6895 }
6896
Bram Moolenaar44a2f922016-03-19 22:11:51 +01006897#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898 /* 'eadirection' */
6899 else if (varp == &p_ead)
6900 {
6901 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
6902 errmsg = e_invarg;
6903 }
6904#endif
6905
6906#ifdef FEAT_CLIPBOARD
6907 /* 'clipboard' */
6908 else if (varp == &p_cb)
6909 errmsg = check_clipboard_option();
6910#endif
6911
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00006912#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00006913 /* When 'spelllang' or 'spellfile' is set and there is a window for this
6914 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01006915 else if (varp == &(curwin->w_s->b_p_spl)
6916 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00006917 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02006918 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00006919 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006920 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02006921 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006922 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02006923 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00006924 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006925 /* 'spellsuggest' */
6926 else if (varp == &p_sps)
6927 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00006928 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00006929 errmsg = e_invarg;
6930 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00006931 /* 'mkspellmem' */
6932 else if (varp == &p_msm)
6933 {
6934 if (spell_check_msm() != OK)
6935 errmsg = e_invarg;
6936 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00006937#endif
6938
Bram Moolenaar071d4272004-06-13 20:20:40 +00006939#ifdef FEAT_QUICKFIX
6940 /* When 'bufhidden' is set, check for valid value. */
6941 else if (gvarp == &p_bh)
6942 {
6943 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
6944 errmsg = e_invarg;
6945 }
6946
6947 /* When 'buftype' is set, check for valid value. */
6948 else if (gvarp == &p_bt)
6949 {
6950 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
6951 errmsg = e_invarg;
6952 else
6953 {
6954# ifdef FEAT_WINDOWS
6955 if (curwin->w_status_height)
6956 {
6957 curwin->w_redr_status = TRUE;
6958 redraw_later(VALID);
6959 }
6960# endif
6961 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar5075aad2010-01-27 15:58:13 +01006962# ifdef FEAT_TITLE
6963 redraw_titles();
6964# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965 }
6966 }
6967#endif
6968
6969#ifdef FEAT_STL_OPT
6970 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006971 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972 {
6973 int wid;
6974
6975 if (varp == &p_ruf) /* reset ru_wid first */
6976 ru_wid = 0;
6977 s = *varp;
6978 if (varp == &p_ruf && *s == '%')
6979 {
6980 /* set ru_wid if 'ruf' starts with "%99(" */
6981 if (*++s == '-') /* ignore a '-' */
6982 s++;
6983 wid = getdigits(&s);
6984 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
6985 ru_wid = wid;
6986 else
6987 errmsg = check_stl_option(p_ruf);
6988 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00006989 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00006990 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006991 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006992 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993 comp_col();
6994 }
6995#endif
6996
6997#ifdef FEAT_INS_EXPAND
6998 /* check if it is a valid value for 'complete' -- Acevedo */
6999 else if (gvarp == &p_cpt)
7000 {
7001 for (s = *varp; *s;)
7002 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007003 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007004 s++;
7005 if (!*s)
7006 break;
7007 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7008 {
7009 errmsg = illegal_char(errbuf, *s);
7010 break;
7011 }
7012 if (*++s != NUL && *s != ',' && *s != ' ')
7013 {
7014 if (s[-1] == 'k' || s[-1] == 's')
7015 {
7016 /* skip optional filename after 'k' and 's' */
7017 while (*s && *s != ',' && *s != ' ')
7018 {
7019 if (*s == '\\')
7020 ++s;
7021 ++s;
7022 }
7023 }
7024 else
7025 {
7026 if (errbuf != NULL)
7027 {
7028 sprintf((char *)errbuf,
7029 _("E535: Illegal character after <%c>"),
7030 *--s);
7031 errmsg = errbuf;
7032 }
7033 else
7034 errmsg = (char_u *)"";
7035 break;
7036 }
7037 }
7038 }
7039 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007040
7041 /* 'completeopt' */
7042 else if (varp == &p_cot)
7043 {
7044 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7045 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007046 else
7047 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007048 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049#endif /* FEAT_INS_EXPAND */
7050
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007051#ifdef FEAT_SIGNS
7052 /* 'signcolumn' */
7053 else if (varp == &curwin->w_p_scl)
7054 {
7055 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7056 errmsg = e_invarg;
7057 }
7058#endif
7059
Bram Moolenaar071d4272004-06-13 20:20:40 +00007060
7061#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007062 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063 else if (varp == &p_toolbar)
7064 {
7065 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7066 &toolbar_flags, TRUE) != OK)
7067 errmsg = e_invarg;
7068 else
7069 {
7070 out_flush();
7071 gui_mch_show_toolbar((toolbar_flags &
7072 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7073 }
7074 }
7075#endif
7076
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007077#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 /* 'toolbariconsize': GTK+ 2 only */
7079 else if (varp == &p_tbis)
7080 {
7081 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7082 errmsg = e_invarg;
7083 else
7084 {
7085 out_flush();
7086 gui_mch_show_toolbar((toolbar_flags &
7087 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7088 }
7089 }
7090#endif
7091
7092 /* 'pastetoggle': translate key codes like in a mapping */
7093 else if (varp == &p_pt)
7094 {
7095 if (*p_pt)
7096 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007097 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007098 if (p != NULL)
7099 {
7100 if (new_value_alloced)
7101 free_string_option(p_pt);
7102 p_pt = p;
7103 new_value_alloced = TRUE;
7104 }
7105 }
7106 }
7107
7108 /* 'backspace' */
7109 else if (varp == &p_bs)
7110 {
7111 if (VIM_ISDIGIT(*p_bs))
7112 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007113 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007114 errmsg = e_invarg;
7115 }
7116 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7117 errmsg = e_invarg;
7118 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007119 else if (varp == &p_bo)
7120 {
7121 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7122 errmsg = e_invarg;
7123 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007124
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007125 /* 'tagcase' */
7126 else if (gvarp == &p_tc)
7127 {
7128 unsigned int *flags;
7129
7130 if (opt_flags & OPT_LOCAL)
7131 {
7132 p = curbuf->b_p_tc;
7133 flags = &curbuf->b_tc_flags;
7134 }
7135 else
7136 {
7137 p = p_tc;
7138 flags = &tc_flags;
7139 }
7140
7141 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7142 /* make the local value empty: use the global value */
7143 *flags = 0;
7144 else if (*p == NUL
7145 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7146 errmsg = e_invarg;
7147 }
7148
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007149#ifdef FEAT_MBYTE
Bram Moolenaar071d4272004-06-13 20:20:40 +00007150 /* 'casemap' */
7151 else if (varp == &p_cmp)
7152 {
7153 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7154 errmsg = e_invarg;
7155 }
Bram Moolenaarfa1d1402006-03-25 21:59:56 +00007156#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157
7158#ifdef FEAT_DIFF
7159 /* 'diffopt' */
7160 else if (varp == &p_dip)
7161 {
7162 if (diffopt_changed() == FAIL)
7163 errmsg = e_invarg;
7164 }
7165#endif
7166
7167#ifdef FEAT_FOLDING
7168 /* 'foldmethod' */
7169 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7170 {
7171 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7172 || *curwin->w_p_fdm == NUL)
7173 errmsg = e_invarg;
7174 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007175 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007176 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007177 if (foldmethodIsDiff(curwin))
7178 newFoldLevel();
7179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007180 }
7181# ifdef FEAT_EVAL
7182 /* 'foldexpr' */
7183 else if (varp == &curwin->w_p_fde)
7184 {
7185 if (foldmethodIsExpr(curwin))
7186 foldUpdateAll(curwin);
7187 }
7188# endif
7189 /* 'foldmarker' */
7190 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7191 {
7192 p = vim_strchr(*varp, ',');
7193 if (p == NULL)
7194 errmsg = (char_u *)N_("E536: comma required");
7195 else if (p == *varp || p[1] == NUL)
7196 errmsg = e_invarg;
7197 else if (foldmethodIsMarker(curwin))
7198 foldUpdateAll(curwin);
7199 }
7200 /* 'commentstring' */
7201 else if (gvarp == &p_cms)
7202 {
7203 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
7204 errmsg = (char_u *)N_("E537: 'commentstring' must be empty or contain %s");
7205 }
7206 /* 'foldopen' */
7207 else if (varp == &p_fdo)
7208 {
7209 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7210 errmsg = e_invarg;
7211 }
7212 /* 'foldclose' */
7213 else if (varp == &p_fcl)
7214 {
7215 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7216 errmsg = e_invarg;
7217 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007218 /* 'foldignore' */
7219 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7220 {
7221 if (foldmethodIsIndent(curwin))
7222 foldUpdateAll(curwin);
7223 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224#endif
7225
7226#ifdef FEAT_VIRTUALEDIT
7227 /* 'virtualedit' */
7228 else if (varp == &p_ve)
7229 {
7230 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7231 errmsg = e_invarg;
7232 else if (STRCMP(p_ve, oldval) != 0)
7233 {
7234 /* Recompute cursor position in case the new 've' setting
7235 * changes something. */
7236 validate_virtcol();
7237 coladvance(curwin->w_virtcol);
7238 }
7239 }
7240#endif
7241
7242#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7243 else if (varp == &p_csqf)
7244 {
7245 if (p_csqf != NULL)
7246 {
7247 p = p_csqf;
7248 while (*p != NUL)
7249 {
7250 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7251 || p[1] == NUL
7252 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7253 || (p[2] != NUL && p[2] != ','))
7254 {
7255 errmsg = e_invarg;
7256 break;
7257 }
7258 else if (p[2] == NUL)
7259 break;
7260 else
7261 p += 3;
7262 }
7263 }
7264 }
7265#endif
7266
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007267#ifdef FEAT_CINDENT
7268 /* 'cinoptions' */
7269 else if (gvarp == &p_cino)
7270 {
7271 /* TODO: recognize errors */
7272 parse_cino(curbuf);
7273 }
7274#endif
7275
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007276#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007277 /* 'renderoptions' */
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007278 else if (varp == &p_rop && gui.in_use)
7279 {
7280 if (!gui_mch_set_rendering_options(p_rop))
7281 errmsg = e_invarg;
7282 }
7283#endif
7284
Bram Moolenaard0b51382016-11-04 15:23:45 +01007285#ifdef FEAT_AUTOCMD
7286 else if (gvarp == &p_ft)
7287 {
7288 if (!valid_filetype(*varp))
7289 errmsg = e_invarg;
7290 }
7291#endif
7292
7293#ifdef FEAT_SYN_HL
7294 else if (gvarp == &p_syn)
7295 {
7296 if (!valid_filetype(*varp))
7297 errmsg = e_invarg;
7298 }
7299#endif
7300
Bram Moolenaar071d4272004-06-13 20:20:40 +00007301 /* Options that are a list of flags. */
7302 else
7303 {
7304 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007305 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007306 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007307 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007308 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007309 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007311 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007312 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007313#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007314 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007315 p = (char_u *)COCU_ALL;
7316#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007317 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007318 {
7319#ifdef FEAT_MOUSE
7320 p = (char_u *)MOUSE_ALL;
7321#else
7322 if (*p_mouse != NUL)
7323 errmsg = (char_u *)N_("E538: No mouse support");
7324#endif
7325 }
7326#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007327 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007328 p = (char_u *)GO_ALL;
7329#endif
7330 if (p != NULL)
7331 {
7332 for (s = *varp; *s; ++s)
7333 if (vim_strchr(p, *s) == NULL)
7334 {
7335 errmsg = illegal_char(errbuf, *s);
7336 break;
7337 }
7338 }
7339 }
7340
7341 /*
7342 * If error detected, restore the previous value.
7343 */
7344 if (errmsg != NULL)
7345 {
7346 if (new_value_alloced)
7347 free_string_option(*varp);
7348 *varp = oldval;
7349 /*
7350 * When resetting some values, need to act on it.
7351 */
7352 if (did_chartab)
7353 (void)init_chartab();
7354 if (varp == &p_hl)
7355 (void)highlight_changed();
7356 }
7357 else
7358 {
7359#ifdef FEAT_EVAL
7360 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007361 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007362#endif
7363 /*
7364 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007365 * Use "free_oldval", because recursiveness may change the flags under
7366 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007367 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007368 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007369 free_string_option(oldval);
7370 if (new_value_alloced)
7371 options[opt_idx].flags |= P_ALLOCED;
7372 else
7373 options[opt_idx].flags &= ~P_ALLOCED;
7374
7375 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007376 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007377 {
7378 /* global option with local value set to use global value; free
7379 * the local value and make it empty */
7380 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7381 free_string_option(*(char_u **)p);
7382 *(char_u **)p = empty_option;
7383 }
7384
7385 /* May set global value for local option. */
7386 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7387 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007388
7389#ifdef FEAT_AUTOCMD
7390 /*
7391 * Trigger the autocommand only after setting the flags.
7392 */
7393# ifdef FEAT_SYN_HL
7394 /* When 'syntax' is set, load the syntax of that name */
7395 if (varp == &(curbuf->b_p_syn))
7396 {
7397 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7398 curbuf->b_fname, TRUE, curbuf);
7399 }
7400# endif
7401 else if (varp == &(curbuf->b_p_ft))
7402 {
7403 /* 'filetype' is set, trigger the FileType autocommand */
7404 did_filetype = TRUE;
7405 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7406 curbuf->b_fname, TRUE, curbuf);
7407 }
7408#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007409#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007410 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007411 {
7412 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007413 char_u *q = curwin->w_s->b_p_spl;
7414
7415 /* Skip the first name if it is "cjk". */
7416 if (STRNCMP(q, "cjk,", 4) == 0)
7417 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007418
7419 /*
7420 * Source the spell/LANG.vim in 'runtimepath'.
7421 * They could set 'spellcapcheck' depending on the language.
7422 * Use the first name in 'spelllang' up to '_region' or
7423 * '.encoding'.
7424 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007425 for (p = q; *p != NUL; ++p)
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007426 if (vim_strchr((char_u *)"_.,", *p) != NULL)
7427 break;
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007428 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
Bram Moolenaar7f8989d2016-03-12 22:11:39 +01007429 source_runtime(fname, DIP_ALL);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007430 }
7431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007432 }
7433
7434#ifdef FEAT_MOUSE
7435 if (varp == &p_mouse)
7436 {
7437# ifdef FEAT_MOUSE_TTY
7438 if (*p_mouse == NUL)
7439 mch_setmouse(FALSE); /* switch mouse off */
7440 else
7441# endif
7442 setmouse(); /* in case 'mouse' changed */
7443 }
7444#endif
7445
Bram Moolenaar913077c2012-03-28 19:59:04 +02007446 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007447 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007448 curwin->w_set_curswant = TRUE;
7449
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007450#ifdef FEAT_GUI
7451 /* check redraw when it's not a GUI option or the GUI is active. */
7452 if (!redraw_gui_only || gui.in_use)
7453#endif
7454 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007455
7456 return errmsg;
7457}
7458
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007459#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007460/*
7461 * Simple int comparison function for use with qsort()
7462 */
7463 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007464int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007465{
7466 return *(const int *)a - *(const int *)b;
7467}
7468
7469/*
7470 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7471 * Returns error message, NULL if it's OK.
7472 */
7473 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007474check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007475{
7476 char_u *s;
7477 int col;
7478 int count = 0;
7479 int color_cols[256];
7480 int i;
7481 int j = 0;
7482
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007483 if (wp->w_buffer == NULL)
7484 return NULL; /* buffer was closed */
7485
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007486 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007487 {
7488 if (*s == '-' || *s == '+')
7489 {
7490 /* -N and +N: add to 'textwidth' */
7491 col = (*s == '-') ? -1 : 1;
7492 ++s;
7493 if (!VIM_ISDIGIT(*s))
7494 return e_invarg;
7495 col = col * getdigits(&s);
7496 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007497 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007498 col += wp->w_buffer->b_p_tw;
7499 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007500 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007501 }
7502 else if (VIM_ISDIGIT(*s))
7503 col = getdigits(&s);
7504 else
7505 return e_invarg;
7506 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007507skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007508 if (*s == NUL)
7509 break;
7510 if (*s != ',')
7511 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007512 if (*++s == NUL)
7513 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007514 }
7515
7516 vim_free(wp->w_p_cc_cols);
7517 if (count == 0)
7518 wp->w_p_cc_cols = NULL;
7519 else
7520 {
7521 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7522 if (wp->w_p_cc_cols != NULL)
7523 {
7524 /* sort the columns for faster usage on screen redraw inside
7525 * win_line() */
7526 qsort(color_cols, count, sizeof(int), int_cmp);
7527
7528 for (i = 0; i < count; ++i)
7529 /* skip duplicates */
7530 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7531 wp->w_p_cc_cols[j++] = color_cols[i];
7532 wp->w_p_cc_cols[j] = -1; /* end marker */
7533 }
7534 }
7535
7536 return NULL; /* no error */
7537}
7538#endif
7539
Bram Moolenaar071d4272004-06-13 20:20:40 +00007540/*
7541 * Handle setting 'listchars' or 'fillchars'.
7542 * Returns error message, NULL if it's OK.
7543 */
7544 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007545set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546{
7547 int round, i, len, entries;
7548 char_u *p, *s;
7549 int c1, c2 = 0;
7550 struct charstab
7551 {
7552 int *cp;
7553 char *name;
7554 };
7555#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7556 static struct charstab filltab[] =
7557 {
7558 {&fill_stl, "stl"},
7559 {&fill_stlnc, "stlnc"},
7560 {&fill_vert, "vert"},
7561 {&fill_fold, "fold"},
7562 {&fill_diff, "diff"},
7563 };
7564#endif
7565 static struct charstab lcstab[] =
7566 {
7567 {&lcs_eol, "eol"},
7568 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007569 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007571 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007572 {&lcs_tab2, "tab"},
7573 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007574#ifdef FEAT_CONCEAL
7575 {&lcs_conceal, "conceal"},
7576#else
7577 {NULL, "conceal"},
7578#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007579 };
7580 struct charstab *tab;
7581
7582#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7583 if (varp == &p_lcs)
7584#endif
7585 {
7586 tab = lcstab;
7587 entries = sizeof(lcstab) / sizeof(struct charstab);
7588 }
7589#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7590 else
7591 {
7592 tab = filltab;
7593 entries = sizeof(filltab) / sizeof(struct charstab);
7594 }
7595#endif
7596
7597 /* first round: check for valid value, second round: assign values */
7598 for (round = 0; round <= 1; ++round)
7599 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007600 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007601 {
7602 /* After checking that the value is valid: set defaults: space for
7603 * 'fillchars', NUL for 'listchars' */
7604 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007605 if (tab[i].cp != NULL)
7606 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar071d4272004-06-13 20:20:40 +00007607 if (varp == &p_lcs)
7608 lcs_tab1 = NUL;
7609#if defined(FEAT_WINDOWS) || defined(FEAT_FOLDING)
7610 else
7611 fill_diff = '-';
7612#endif
7613 }
7614 p = *varp;
7615 while (*p)
7616 {
7617 for (i = 0; i < entries; ++i)
7618 {
7619 len = (int)STRLEN(tab[i].name);
7620 if (STRNCMP(p, tab[i].name, len) == 0
7621 && p[len] == ':'
7622 && p[len + 1] != NUL)
7623 {
7624 s = p + len + 1;
7625#ifdef FEAT_MBYTE
7626 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007627 if (mb_char2cells(c1) > 1)
7628 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007629#else
7630 c1 = *s++;
7631#endif
7632 if (tab[i].cp == &lcs_tab2)
7633 {
7634 if (*s == NUL)
7635 continue;
7636#ifdef FEAT_MBYTE
7637 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007638 if (mb_char2cells(c2) > 1)
7639 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007640#else
7641 c2 = *s++;
7642#endif
7643 }
7644 if (*s == ',' || *s == NUL)
7645 {
7646 if (round)
7647 {
7648 if (tab[i].cp == &lcs_tab2)
7649 {
7650 lcs_tab1 = c1;
7651 lcs_tab2 = c2;
7652 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007653 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007654 *(tab[i].cp) = c1;
7655
7656 }
7657 p = s;
7658 break;
7659 }
7660 }
7661 }
7662
7663 if (i == entries)
7664 return e_invarg;
7665 if (*p == ',')
7666 ++p;
7667 }
7668 }
7669
7670 return NULL; /* no error */
7671}
7672
7673#ifdef FEAT_STL_OPT
7674/*
7675 * Check validity of options with the 'statusline' format.
7676 * Return error message or NULL.
7677 */
7678 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007679check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007680{
7681 int itemcnt = 0;
7682 int groupdepth = 0;
7683 static char_u errbuf[80];
7684
7685 while (*s && itemcnt < STL_MAX_ITEM)
7686 {
7687 /* Check for valid keys after % sequences */
7688 while (*s && *s != '%')
7689 s++;
7690 if (!*s)
7691 break;
7692 s++;
7693 if (*s != '%' && *s != ')')
7694 ++itemcnt;
7695 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7696 {
7697 s++;
7698 continue;
7699 }
7700 if (*s == ')')
7701 {
7702 s++;
7703 if (--groupdepth < 0)
7704 break;
7705 continue;
7706 }
7707 if (*s == '-')
7708 s++;
7709 while (VIM_ISDIGIT(*s))
7710 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00007711 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007712 continue;
7713 if (*s == '.')
7714 {
7715 s++;
7716 while (*s && VIM_ISDIGIT(*s))
7717 s++;
7718 }
7719 if (*s == '(')
7720 {
7721 groupdepth++;
7722 continue;
7723 }
7724 if (vim_strchr(STL_ALL, *s) == NULL)
7725 {
7726 return illegal_char(errbuf, *s);
7727 }
7728 if (*s == '{')
7729 {
7730 s++;
7731 while (*s != '}' && *s)
7732 s++;
7733 if (*s != '}')
7734 return (char_u *)N_("E540: Unclosed expression sequence");
7735 }
7736 }
7737 if (itemcnt >= STL_MAX_ITEM)
7738 return (char_u *)N_("E541: too many items");
7739 if (groupdepth != 0)
7740 return (char_u *)N_("E542: unbalanced groups");
7741 return NULL;
7742}
7743#endif
7744
7745#ifdef FEAT_CLIPBOARD
7746/*
7747 * Extract the items in the 'clipboard' option and set global values.
7748 */
7749 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007750check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007751{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007752 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007753 int new_autoselect_star = FALSE;
7754 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007755 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007756 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007757 regprog_T *new_exclude_prog = NULL;
7758 char_u *errmsg = NULL;
7759 char_u *p;
7760
7761 for (p = p_cb; *p != NUL; )
7762 {
7763 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
7764 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007765 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007766 p += 7;
7767 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007768 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01007769 && (p[11] == ',' || p[11] == NUL))
7770 {
7771 new_unnamed |= CLIP_UNNAMED_PLUS;
7772 p += 11;
7773 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007774 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007775 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007776 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02007777 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778 p += 10;
7779 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02007780 else if (STRNCMP(p, "autoselectplus", 14) == 0
7781 && (p[14] == ',' || p[14] == NUL))
7782 {
7783 new_autoselect_plus = TRUE;
7784 p += 14;
7785 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007786 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02007787 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007788 {
7789 new_autoselectml = TRUE;
7790 p += 12;
7791 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007792 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
7793 {
7794 new_html = TRUE;
7795 p += 4;
7796 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007797 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
7798 {
7799 p += 8;
7800 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
7801 if (new_exclude_prog == NULL)
7802 errmsg = e_invarg;
7803 break;
7804 }
7805 else
7806 {
7807 errmsg = e_invarg;
7808 break;
7809 }
7810 if (*p == ',')
7811 ++p;
7812 }
7813 if (errmsg == NULL)
7814 {
7815 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02007816 clip_autoselect_star = new_autoselect_star;
7817 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00007819 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02007820 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007821 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02007822#ifdef FEAT_GUI_GTK
7823 if (gui.in_use)
7824 {
7825 gui_gtk_set_selection_targets();
7826 gui_gtk_set_dnd_targets();
7827 }
7828#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007829 }
7830 else
Bram Moolenaar473de612013-06-08 18:19:48 +02007831 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007832
7833 return errmsg;
7834}
7835#endif
7836
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007837#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007838 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007839did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007840{
7841 char_u *errmsg = NULL;
7842 win_T *wp;
7843 int l;
7844
7845 if (is_spellfile)
7846 {
7847 l = (int)STRLEN(curwin->w_s->b_p_spf);
7848 if (l > 0 && (l < 4
7849 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
7850 errmsg = e_invarg;
7851 }
7852
7853 if (errmsg == NULL)
7854 {
7855 FOR_ALL_WINDOWS(wp)
7856 if (wp->w_buffer == curbuf && wp->w_p_spell)
7857 {
7858 errmsg = did_set_spelllang(wp);
7859# ifdef FEAT_WINDOWS
7860 break;
7861# endif
7862 }
7863 }
7864 return errmsg;
7865}
7866
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007867/*
7868 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
7869 * Return error message when failed, NULL when OK.
7870 */
7871 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007872compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007873{
Bram Moolenaar860cae12010-06-05 23:22:07 +02007874 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007875 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007876
Bram Moolenaar860cae12010-06-05 23:22:07 +02007877 if (*synblock->b_p_spc == NUL)
7878 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007879 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007880 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007881 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007882 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007883 if (re != NULL)
7884 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007885 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02007886 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02007887 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007888 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007889 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007890 return e_invarg;
7891 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00007892 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007893 }
7894
Bram Moolenaar473de612013-06-08 18:19:48 +02007895 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007896 return NULL;
7897}
7898#endif
7899
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007900#if defined(FEAT_EVAL) || defined(PROTO)
7901/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007902 * Set the scriptID for an option, taking care of setting the buffer- or
7903 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007904 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007905 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01007906set_option_scriptID_idx(int opt_idx, int opt_flags, int id)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007907{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007908 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
7909 int indir = (int)options[opt_idx].indir;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007910
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007911 /* Remember where the option was set. For local options need to do that
7912 * in the buffer or window structure. */
7913 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007914 options[opt_idx].scriptID = id;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007915 if (both || (opt_flags & OPT_LOCAL))
7916 {
7917 if (indir & PV_BUF)
7918 curbuf->b_p_scriptID[indir & PV_MASK] = id;
7919 else if (indir & PV_WIN)
7920 curwin->w_p_scriptID[indir & PV_MASK] = id;
7921 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00007922}
7923#endif
7924
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925/*
7926 * Set the value of a boolean option, and take care of side effects.
7927 * Returns NULL for success, or an error message for an error.
7928 */
7929 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007930set_bool_option(
7931 int opt_idx, /* index in options[] table */
7932 char_u *varp, /* pointer to the option variable */
7933 int value, /* new value */
7934 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935{
7936 int old_value = *(int *)varp;
7937
Bram Moolenaar071d4272004-06-13 20:20:40 +00007938 /* Disallow changing some options from secure mode */
7939 if ((secure
7940#ifdef HAVE_SANDBOX
7941 || sandbox != 0
7942#endif
7943 ) && (options[opt_idx].flags & P_SECURE))
7944 return e_secure;
7945
7946 *(int *)varp = value; /* set the new value */
7947#ifdef FEAT_EVAL
7948 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00007949 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007950#endif
7951
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00007952#ifdef FEAT_GUI
7953 need_mouse_correct = TRUE;
7954#endif
7955
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 /* May set global value for local option. */
7957 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
7958 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
7959
7960 /*
7961 * Handle side effects of changing a bool option.
7962 */
7963
7964 /* 'compatible' */
7965 if ((int *)varp == &p_cp)
7966 {
7967 compatible_set();
7968 }
7969
Bram Moolenaar920694c2016-08-21 17:45:02 +02007970#ifdef FEAT_LANGMAP
7971 if ((int *)varp == &p_lrm)
7972 /* 'langremap' -> !'langnoremap' */
7973 p_lnr = !p_lrm;
7974 else if ((int *)varp == &p_lnr)
7975 /* 'langnoremap' -> !'langremap' */
7976 p_lrm = !p_lnr;
7977#endif
7978
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007979#ifdef FEAT_PERSISTENT_UNDO
7980 /* 'undofile' */
7981 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
7982 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007983 /* Only take action when the option was set. When reset we do not
7984 * delete the undo file, the option may be set again without making
7985 * any changes in between. */
7986 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007987 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007988 char_u hash[UNDO_HASH_SIZE];
7989 buf_T *save_curbuf = curbuf;
7990
Bram Moolenaar29323592016-07-24 22:04:11 +02007991 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01007992 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02007993 /* When 'undofile' is set globally: for every buffer, otherwise
7994 * only for the current buffer: Try to read in the undofile,
7995 * if one exists, the buffer wasn't changed and the buffer was
7996 * loaded */
7997 if ((curbuf == save_curbuf
7998 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
7999 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8000 {
8001 u_compute_hash(hash);
8002 u_read_undo(NULL, hash, curbuf->b_fname);
8003 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008004 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008005 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008006 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008007 }
8008#endif
8009
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 else if ((int *)varp == &curbuf->b_p_ro)
8011 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008012 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008013 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8014 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008015
8016 /* when 'readonly' is set may give W10 again */
8017 if (curbuf->b_p_ro)
8018 curbuf->b_did_warn = FALSE;
8019
Bram Moolenaar071d4272004-06-13 20:20:40 +00008020#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008021 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008022#endif
8023 }
8024
Bram Moolenaar9c449722010-07-20 18:44:27 +02008025#ifdef FEAT_GUI
8026 else if ((int *)varp == &p_mh)
8027 {
8028 if (!p_mh)
8029 gui_mch_mousehide(FALSE);
8030 }
8031#endif
8032
Bram Moolenaara539df02010-08-01 14:35:05 +02008033#ifdef FEAT_TITLE
8034 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008036 {
8037 redraw_titles();
8038 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008039 /* when 'endofline' is changed, redraw the window title */
8040 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008041 {
8042 redraw_titles();
8043 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008044 /* when 'fixeol' is changed, redraw the window title */
8045 else if ((int *)varp == &curbuf->b_p_fixeol)
8046 {
8047 redraw_titles();
8048 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008049# ifdef FEAT_MBYTE
8050 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008051 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008052 {
8053 redraw_titles();
8054 }
8055# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056#endif
8057
8058 /* when 'bin' is set also set some other options */
8059 else if ((int *)varp == &curbuf->b_p_bin)
8060 {
8061 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8062#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008063 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008064#endif
8065 }
8066
8067#ifdef FEAT_AUTOCMD
8068 /* when 'buflisted' changes, trigger autocommands */
8069 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8070 {
8071 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8072 NULL, NULL, TRUE, curbuf);
8073 }
8074#endif
8075
8076 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8077 else if ((int *)varp == &curbuf->b_p_swf)
8078 {
8079 if (curbuf->b_p_swf && p_uc)
8080 ml_open_file(curbuf); /* create the swap file */
8081 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008082 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8083 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008084 mf_close_file(curbuf, TRUE); /* remove the swap file */
8085 }
8086
8087 /* when 'terse' is set change 'shortmess' */
8088 else if ((int *)varp == &p_terse)
8089 {
8090 char_u *p;
8091
8092 p = vim_strchr(p_shm, SHM_SEARCH);
8093
8094 /* insert 's' in p_shm */
8095 if (p_terse && p == NULL)
8096 {
8097 STRCPY(IObuff, p_shm);
8098 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008099 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008100 }
8101 /* remove 's' from p_shm */
8102 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008103 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 }
8105
8106 /* when 'paste' is set or reset also change other options */
8107 else if ((int *)varp == &p_paste)
8108 {
8109 paste_option_changed();
8110 }
8111
8112 /* when 'insertmode' is set from an autocommand need to do work here */
8113 else if ((int *)varp == &p_im)
8114 {
8115 if (p_im)
8116 {
8117 if ((State & INSERT) == 0)
8118 need_start_insertmode = TRUE;
8119 stop_insert_mode = FALSE;
8120 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008121 /* only reset if it was set previously */
8122 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123 {
8124 need_start_insertmode = FALSE;
8125 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008126 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008127 clear_cmdline = TRUE; /* remove "(insert)" */
8128 restart_edit = 0;
8129 }
8130 }
8131
8132 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8133 else if ((int *)varp == &p_ic && p_hls)
8134 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008135 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136 }
8137
8138#ifdef FEAT_SEARCH_EXTRA
8139 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8140 else if ((int *)varp == &p_hls)
8141 {
Bram Moolenaar8050efa2013-11-08 04:30:20 +01008142 SET_NO_HLSEARCH(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 }
8144#endif
8145
8146#ifdef FEAT_SCROLLBIND
8147 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8148 * at the end of normal_cmd() */
8149 else if ((int *)varp == &curwin->w_p_scb)
8150 {
8151 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008152 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008154 curwin->w_scbind_pos = curwin->w_topline;
8155 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156 }
8157#endif
8158
8159#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
8160 /* There can be only one window with 'previewwindow' set. */
8161 else if ((int *)varp == &curwin->w_p_pvw)
8162 {
8163 if (curwin->w_p_pvw)
8164 {
8165 win_T *win;
8166
Bram Moolenaar29323592016-07-24 22:04:11 +02008167 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008168 if (win->w_p_pvw && win != curwin)
8169 {
8170 curwin->w_p_pvw = FALSE;
8171 return (char_u *)N_("E590: A preview window already exists");
8172 }
8173 }
8174 }
8175#endif
8176
8177 /* when 'textmode' is set or reset also change 'fileformat' */
8178 else if ((int *)varp == &curbuf->b_p_tx)
8179 {
8180 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8181 }
8182
8183 /* when 'textauto' is set or reset also change 'fileformats' */
8184 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008185 set_string_option_direct((char_u *)"ffs", -1,
8186 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008187 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188
8189 /*
8190 * When 'lisp' option changes include/exclude '-' in
8191 * keyword characters.
8192 */
8193#ifdef FEAT_LISP
8194 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8195 {
8196 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8197 }
8198#endif
8199
8200#ifdef FEAT_TITLE
8201 /* when 'title' changed, may need to change the title; same for 'icon' */
8202 else if ((int *)varp == &p_title)
8203 {
8204 did_set_title(FALSE);
8205 }
8206
8207 else if ((int *)varp == &p_icon)
8208 {
8209 did_set_title(TRUE);
8210 }
8211#endif
8212
8213 else if ((int *)varp == &curbuf->b_changed)
8214 {
8215 if (!value)
8216 save_file_ff(curbuf); /* Buffer is unchanged */
8217#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008218 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219#endif
8220#ifdef FEAT_AUTOCMD
8221 modified_was_set = value;
8222#endif
8223 }
8224
8225#ifdef BACKSLASH_IN_FILENAME
8226 else if ((int *)varp == &p_ssl)
8227 {
8228 if (p_ssl)
8229 {
8230 psepc = '/';
8231 psepcN = '\\';
8232 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008233 }
8234 else
8235 {
8236 psepc = '\\';
8237 psepcN = '/';
8238 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239 }
8240
8241 /* need to adjust the file name arguments and buffer names. */
8242 buflist_slash_adjust();
8243 alist_slash_adjust();
8244# ifdef FEAT_EVAL
8245 scriptnames_slash_adjust();
8246# endif
8247 }
8248#endif
8249
8250 /* If 'wrap' is set, set w_leftcol to zero. */
8251 else if ((int *)varp == &curwin->w_p_wrap)
8252 {
8253 if (curwin->w_p_wrap)
8254 curwin->w_leftcol = 0;
8255 }
8256
8257#ifdef FEAT_WINDOWS
8258 else if ((int *)varp == &p_ea)
8259 {
8260 if (p_ea && !old_value)
8261 win_equal(curwin, FALSE, 0);
8262 }
8263#endif
8264
8265 else if ((int *)varp == &p_wiv)
8266 {
8267 /*
8268 * When 'weirdinvert' changed, set/reset 't_xs'.
8269 * Then set 'weirdinvert' according to value of 't_xs'.
8270 */
8271 if (p_wiv && !old_value)
8272 T_XS = (char_u *)"y";
8273 else if (!p_wiv && old_value)
8274 T_XS = empty_option;
8275 p_wiv = (*T_XS != NUL);
8276 }
8277
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00008278#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +00008279 else if ((int *)varp == &p_beval)
8280 {
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008281 if (p_beval && !old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008282 gui_mch_enable_beval_area(balloonEval);
Bram Moolenaar49e4ec62011-11-30 11:31:30 +01008283 else if (!p_beval && old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284 gui_mch_disable_beval_area(balloonEval);
8285 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008287
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008288#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008289 else if ((int *)varp == &p_acd)
8290 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008291 /* Change directories when the 'acd' option is set now. */
8292 DO_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008293 }
8294#endif
8295
8296#ifdef FEAT_DIFF
8297 /* 'diff' */
8298 else if ((int *)varp == &curwin->w_p_diff)
8299 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008300 /* May add or remove the buffer from the list of diff buffers. */
8301 diff_buf_adjust(curwin);
8302# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008303 if (foldmethodIsDiff(curwin))
8304 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008305# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 }
8307#endif
8308
8309#ifdef USE_IM_CONTROL
8310 /* 'imdisable' */
8311 else if ((int *)varp == &p_imdisable)
8312 {
8313 /* Only de-activate it here, it will be enabled when changing mode. */
8314 if (p_imdisable)
8315 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008316 else if (State & INSERT)
8317 /* When the option is set from an autocommand, it may need to take
8318 * effect right away. */
8319 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 }
8321#endif
8322
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008323#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008324 /* 'spell' */
8325 else if ((int *)varp == &curwin->w_p_spell)
8326 {
8327 if (curwin->w_p_spell)
8328 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008329 char_u *errmsg = did_set_spelllang(curwin);
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008330 if (errmsg != NULL)
8331 EMSG(_(errmsg));
8332 }
8333 }
8334#endif
8335
Bram Moolenaar071d4272004-06-13 20:20:40 +00008336#ifdef FEAT_FKMAP
8337 else if ((int *)varp == &p_altkeymap)
8338 {
8339 if (old_value != p_altkeymap)
8340 {
8341 if (!p_altkeymap)
8342 {
8343 p_hkmap = p_fkmap;
8344 p_fkmap = 0;
8345 }
8346 else
8347 {
8348 p_fkmap = p_hkmap;
8349 p_hkmap = 0;
8350 }
8351 (void)init_chartab();
8352 }
8353 }
8354
8355 /*
8356 * In case some second language keymapping options have changed, check
8357 * and correct the setting in a consistent way.
8358 */
8359
8360 /*
8361 * If hkmap or fkmap are set, reset Arabic keymapping.
8362 */
8363 if ((p_hkmap || p_fkmap) && p_altkeymap)
8364 {
8365 p_altkeymap = p_fkmap;
8366# ifdef FEAT_ARABIC
8367 curwin->w_p_arab = FALSE;
8368# endif
8369 (void)init_chartab();
8370 }
8371
8372 /*
8373 * If hkmap set, reset Farsi keymapping.
8374 */
8375 if (p_hkmap && p_altkeymap)
8376 {
8377 p_altkeymap = 0;
8378 p_fkmap = 0;
8379# ifdef FEAT_ARABIC
8380 curwin->w_p_arab = FALSE;
8381# endif
8382 (void)init_chartab();
8383 }
8384
8385 /*
8386 * If fkmap set, reset Hebrew keymapping.
8387 */
8388 if (p_fkmap && !p_altkeymap)
8389 {
8390 p_altkeymap = 1;
8391 p_hkmap = 0;
8392# ifdef FEAT_ARABIC
8393 curwin->w_p_arab = FALSE;
8394# endif
8395 (void)init_chartab();
8396 }
8397#endif
8398
8399#ifdef FEAT_ARABIC
8400 if ((int *)varp == &curwin->w_p_arab)
8401 {
8402 if (curwin->w_p_arab)
8403 {
8404 /*
8405 * 'arabic' is set, handle various sub-settings.
8406 */
8407 if (!p_tbidi)
8408 {
8409 /* set rightleft mode */
8410 if (!curwin->w_p_rl)
8411 {
8412 curwin->w_p_rl = TRUE;
8413 changed_window_setting();
8414 }
8415
8416 /* Enable Arabic shaping (major part of what Arabic requires) */
8417 if (!p_arshape)
8418 {
8419 p_arshape = TRUE;
8420 redraw_later_clear();
8421 }
8422 }
8423
8424 /* Arabic requires a utf-8 encoding, inform the user if its not
8425 * set. */
8426 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008427 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008428 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8429
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008430 msg_source(hl_attr(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008431 MSG_ATTR(_(w_arabic), hl_attr(HLF_W));
8432#ifdef FEAT_EVAL
8433 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8434#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008435 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008436
8437# ifdef FEAT_MBYTE
8438 /* set 'delcombine' */
8439 p_deco = TRUE;
8440# endif
8441
8442# ifdef FEAT_KEYMAP
8443 /* Force-set the necessary keymap for arabic */
8444 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8445 OPT_LOCAL);
8446# endif
8447# ifdef FEAT_FKMAP
8448 p_altkeymap = 0;
8449 p_hkmap = 0;
8450 p_fkmap = 0;
8451 (void)init_chartab();
8452# endif
8453 }
8454 else
8455 {
8456 /*
8457 * 'arabic' is reset, handle various sub-settings.
8458 */
8459 if (!p_tbidi)
8460 {
8461 /* reset rightleft mode */
8462 if (curwin->w_p_rl)
8463 {
8464 curwin->w_p_rl = FALSE;
8465 changed_window_setting();
8466 }
8467
8468 /* 'arabicshape' isn't reset, it is a global option and
8469 * another window may still need it "on". */
8470 }
8471
8472 /* 'delcombine' isn't reset, it is a global option and another
8473 * window may still want it "on". */
8474
8475# ifdef FEAT_KEYMAP
8476 /* Revert to the default keymap */
8477 curbuf->b_p_iminsert = B_IMODE_NONE;
8478 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8479# endif
8480 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008481 }
8482
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008483#endif
8484
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008485#ifdef FEAT_TERMGUICOLORS
8486 /* 'termguicolors' */
8487 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008488 {
8489# ifdef FEAT_GUI
8490 if (!gui.in_use && !gui.starting)
8491# endif
8492 highlight_gui_started();
8493 }
8494#endif
8495
Bram Moolenaar071d4272004-06-13 20:20:40 +00008496 /*
8497 * End of handling side effects for bool options.
8498 */
8499
Bram Moolenaar53744302015-07-17 17:38:22 +02008500 /* after handling side effects, call autocommand */
8501
Bram Moolenaar071d4272004-06-13 20:20:40 +00008502 options[opt_idx].flags |= P_WAS_SET;
8503
Bram Moolenaar53744302015-07-17 17:38:22 +02008504#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
8505 if (!starting)
8506 {
8507 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008508 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8509 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8510 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008511 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8512 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8513 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8514 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8515 reset_v_option_vars();
8516 }
8517#endif
8518
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008520 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008521 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008522 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008523 check_redraw(options[opt_idx].flags);
8524
8525 return NULL;
8526}
8527
8528/*
8529 * Set the value of a number option, and take care of side effects.
8530 * Returns NULL for success, or an error message for an error.
8531 */
8532 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008533set_num_option(
8534 int opt_idx, /* index in options[] table */
8535 char_u *varp, /* pointer to the option variable */
8536 long value, /* new value */
8537 char_u *errbuf, /* buffer for error messages */
8538 size_t errbuflen, /* length of "errbuf" */
8539 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540 OPT_MODELINE */
8541{
8542 char_u *errmsg = NULL;
8543 long old_value = *(long *)varp;
8544 long old_Rows = Rows; /* remember old Rows */
8545 long old_Columns = Columns; /* remember old Columns */
8546 long *pp = (long *)varp;
8547
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008548 /* Disallow changing some options from secure mode. */
8549 if ((secure
8550#ifdef HAVE_SANDBOX
8551 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008552#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008553 ) && (options[opt_idx].flags & P_SECURE))
8554 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008555
8556 *pp = value;
8557#ifdef FEAT_EVAL
8558 /* Remember where the option was set. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008559 set_option_scriptID_idx(opt_idx, opt_flags, current_SID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008561#ifdef FEAT_GUI
8562 need_mouse_correct = TRUE;
8563#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008564
Bram Moolenaar14f24742012-08-08 18:01:05 +02008565 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008566 {
8567 errmsg = e_positive;
8568 curbuf->b_p_sw = curbuf->b_p_ts;
8569 }
8570
8571 /*
8572 * Number options that need some action when changed
8573 */
8574#ifdef FEAT_WINDOWS
8575 if (pp == &p_wh || pp == &p_hh)
8576 {
8577 if (p_wh < 1)
8578 {
8579 errmsg = e_positive;
8580 p_wh = 1;
8581 }
8582 if (p_wmh > p_wh)
8583 {
8584 errmsg = e_winheight;
8585 p_wh = p_wmh;
8586 }
8587 if (p_hh < 0)
8588 {
8589 errmsg = e_positive;
8590 p_hh = 0;
8591 }
8592
8593 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008594 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008595 {
8596 if (pp == &p_wh && curwin->w_height < p_wh)
8597 win_setheight((int)p_wh);
8598 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8599 win_setheight((int)p_hh);
8600 }
8601 }
8602
8603 /* 'winminheight' */
8604 else if (pp == &p_wmh)
8605 {
8606 if (p_wmh < 0)
8607 {
8608 errmsg = e_positive;
8609 p_wmh = 0;
8610 }
8611 if (p_wmh > p_wh)
8612 {
8613 errmsg = e_winheight;
8614 p_wmh = p_wh;
8615 }
8616 win_setminheight();
8617 }
8618
Bram Moolenaar44a2f922016-03-19 22:11:51 +01008619# ifdef FEAT_WINDOWS
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008620 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008621 {
8622 if (p_wiw < 1)
8623 {
8624 errmsg = e_positive;
8625 p_wiw = 1;
8626 }
8627 if (p_wmw > p_wiw)
8628 {
8629 errmsg = e_winwidth;
8630 p_wiw = p_wmw;
8631 }
8632
8633 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008634 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635 win_setwidth((int)p_wiw);
8636 }
8637
8638 /* 'winminwidth' */
8639 else if (pp == &p_wmw)
8640 {
8641 if (p_wmw < 0)
8642 {
8643 errmsg = e_positive;
8644 p_wmw = 0;
8645 }
8646 if (p_wmw > p_wiw)
8647 {
8648 errmsg = e_winwidth;
8649 p_wmw = p_wiw;
8650 }
8651 win_setminheight();
8652 }
8653# endif
8654
8655#endif
8656
8657#ifdef FEAT_WINDOWS
8658 /* (re)set last window status line */
8659 else if (pp == &p_ls)
8660 {
8661 last_status(FALSE);
8662 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008663
8664 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008665 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008666 {
8667 shell_new_rows(); /* recompute window positions and heights */
8668 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008669#endif
8670
8671#ifdef FEAT_GUI
8672 else if (pp == &p_linespace)
8673 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008674 /* Recompute gui.char_height and resize the Vim window to keep the
8675 * same number of lines. */
8676 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008677 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008678 }
8679#endif
8680
8681#ifdef FEAT_FOLDING
8682 /* 'foldlevel' */
8683 else if (pp == &curwin->w_p_fdl)
8684 {
8685 if (curwin->w_p_fdl < 0)
8686 curwin->w_p_fdl = 0;
8687 newFoldLevel();
8688 }
8689
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008690 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008691 else if (pp == &curwin->w_p_fml)
8692 {
8693 foldUpdateAll(curwin);
8694 }
8695
8696 /* 'foldnestmax' */
8697 else if (pp == &curwin->w_p_fdn)
8698 {
8699 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8700 foldUpdateAll(curwin);
8701 }
8702
8703 /* 'foldcolumn' */
8704 else if (pp == &curwin->w_p_fdc)
8705 {
8706 if (curwin->w_p_fdc < 0)
8707 {
8708 errmsg = e_positive;
8709 curwin->w_p_fdc = 0;
8710 }
8711 else if (curwin->w_p_fdc > 12)
8712 {
8713 errmsg = e_invarg;
8714 curwin->w_p_fdc = 12;
8715 }
8716 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008717#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008719#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 /* 'shiftwidth' or 'tabstop' */
8721 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
8722 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008723# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008724 if (foldmethodIsIndent(curwin))
8725 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008726# endif
8727# ifdef FEAT_CINDENT
8728 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
8729 * parse 'cinoptions'. */
8730 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
8731 parse_cino(curbuf);
8732# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008733 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01008734#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008735
Bram Moolenaar362e1a32006-03-06 23:29:24 +00008736#ifdef FEAT_MBYTE
8737 /* 'maxcombine' */
8738 else if (pp == &p_mco)
8739 {
8740 if (p_mco > MAX_MCO)
8741 p_mco = MAX_MCO;
8742 else if (p_mco < 0)
8743 p_mco = 0;
8744 screenclear(); /* will re-allocate the screen */
8745 }
8746#endif
8747
Bram Moolenaar071d4272004-06-13 20:20:40 +00008748 else if (pp == &curbuf->b_p_iminsert)
8749 {
8750 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
8751 {
8752 errmsg = e_invarg;
8753 curbuf->b_p_iminsert = B_IMODE_NONE;
8754 }
8755 p_iminsert = curbuf->b_p_iminsert;
8756 if (termcap_active) /* don't do this in the alternate screen */
8757 showmode();
8758#if defined(FEAT_WINDOWS) && defined(FEAT_KEYMAP)
8759 /* Show/unshow value of 'keymap' in status lines. */
8760 status_redraw_curbuf();
8761#endif
8762 }
8763
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008764 else if (pp == &p_window)
8765 {
8766 if (p_window < 1)
8767 p_window = 1;
8768 else if (p_window >= Rows)
8769 p_window = Rows - 1;
8770 }
8771
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 else if (pp == &curbuf->b_p_imsearch)
8773 {
8774 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
8775 {
8776 errmsg = e_invarg;
8777 curbuf->b_p_imsearch = B_IMODE_NONE;
8778 }
8779 p_imsearch = curbuf->b_p_imsearch;
8780 }
8781
8782#ifdef FEAT_TITLE
8783 /* if 'titlelen' has changed, redraw the title */
8784 else if (pp == &p_titlelen)
8785 {
8786 if (p_titlelen < 0)
8787 {
8788 errmsg = e_positive;
8789 p_titlelen = 85;
8790 }
8791 if (starting != NO_SCREEN && old_value != p_titlelen)
8792 need_maketitle = TRUE;
8793 }
8794#endif
8795
8796 /* if p_ch changed value, change the command line height */
8797 else if (pp == &p_ch)
8798 {
8799 if (p_ch < 1)
8800 {
8801 errmsg = e_positive;
8802 p_ch = 1;
8803 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00008804 if (p_ch > Rows - min_rows() + 1)
8805 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806
8807 /* Only compute the new window layout when startup has been
8808 * completed. Otherwise the frame sizes may be wrong. */
8809 if (p_ch != old_value && full_screen
8810#ifdef FEAT_GUI
8811 && !gui.starting
8812#endif
8813 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00008814 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008815 }
8816
8817 /* when 'updatecount' changes from zero to non-zero, open swap files */
8818 else if (pp == &p_uc)
8819 {
8820 if (p_uc < 0)
8821 {
8822 errmsg = e_positive;
8823 p_uc = 100;
8824 }
8825 if (p_uc && !old_value)
8826 ml_open_files();
8827 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008828#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008829 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008830 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008831 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008832 {
8833 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008834 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008835 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008836 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008837 {
8838 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02008839 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02008840 }
8841 }
8842#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008843#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00008844 else if (pp == &p_mzq)
8845 mzvim_reset_timer();
8846#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008847
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01008848#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
8849 /* 'pyxversion' */
8850 else if (pp == &p_pyx)
8851 {
8852 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
8853 errmsg = e_invarg;
8854 }
8855#endif
8856
Bram Moolenaar071d4272004-06-13 20:20:40 +00008857 /* sync undo before 'undolevels' changes */
8858 else if (pp == &p_ul)
8859 {
8860 /* use the old value, otherwise u_sync() may not work properly */
8861 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00008862 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008863 p_ul = value;
8864 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01008865 else if (pp == &curbuf->b_p_ul)
8866 {
8867 /* use the old value, otherwise u_sync() may not work properly */
8868 curbuf->b_p_ul = old_value;
8869 u_sync(TRUE);
8870 curbuf->b_p_ul = value;
8871 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008873#ifdef FEAT_LINEBREAK
8874 /* 'numberwidth' must be positive */
8875 else if (pp == &curwin->w_p_nuw)
8876 {
8877 if (curwin->w_p_nuw < 1)
8878 {
8879 errmsg = e_positive;
8880 curwin->w_p_nuw = 1;
8881 }
8882 if (curwin->w_p_nuw > 10)
8883 {
8884 errmsg = e_invarg;
8885 curwin->w_p_nuw = 10;
8886 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02008887 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008888 }
8889#endif
8890
Bram Moolenaar1a384422010-07-14 19:53:30 +02008891 else if (pp == &curbuf->b_p_tw)
8892 {
8893 if (curbuf->b_p_tw < 0)
8894 {
8895 errmsg = e_positive;
8896 curbuf->b_p_tw = 0;
8897 }
8898#ifdef FEAT_SYN_HL
8899# ifdef FEAT_WINDOWS
8900 {
8901 win_T *wp;
8902 tabpage_T *tp;
8903
8904 FOR_ALL_TAB_WINDOWS(tp, wp)
8905 check_colorcolumn(wp);
8906 }
8907# else
8908 check_colorcolumn(curwin);
8909# endif
8910#endif
8911 }
8912
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 /*
8914 * Check the bounds for numeric options here
8915 */
8916 if (Rows < min_rows() && full_screen)
8917 {
8918 if (errbuf != NULL)
8919 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008920 vim_snprintf((char *)errbuf, errbuflen,
8921 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00008922 errmsg = errbuf;
8923 }
8924 Rows = min_rows();
8925 }
8926 if (Columns < MIN_COLUMNS && full_screen)
8927 {
8928 if (errbuf != NULL)
8929 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00008930 vim_snprintf((char *)errbuf, errbuflen,
8931 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 errmsg = errbuf;
8933 }
8934 Columns = MIN_COLUMNS;
8935 }
Bram Moolenaare057d402013-06-30 17:51:51 +02008936 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937
Bram Moolenaar071d4272004-06-13 20:20:40 +00008938 /*
8939 * If the screen (shell) height has been changed, assume it is the
8940 * physical screenheight.
8941 */
8942 if (old_Rows != Rows || old_Columns != Columns)
8943 {
8944 /* Changing the screen size is not allowed while updating the screen. */
8945 if (updating_screen)
8946 *pp = old_value;
8947 else if (full_screen
8948#ifdef FEAT_GUI
8949 && !gui.starting
8950#endif
8951 )
8952 set_shellsize((int)Columns, (int)Rows, TRUE);
8953 else
8954 {
8955 /* Postpone the resizing; check the size and cmdline position for
8956 * messages. */
8957 check_shellsize();
8958 if (cmdline_row > Rows - p_ch && Rows > p_ch)
8959 cmdline_row = Rows - p_ch;
8960 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00008961 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00008962 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008963 }
8964
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965 if (curbuf->b_p_ts <= 0)
8966 {
8967 errmsg = e_positive;
8968 curbuf->b_p_ts = 8;
8969 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970 if (p_tm < 0)
8971 {
8972 errmsg = e_positive;
8973 p_tm = 0;
8974 }
8975 if ((curwin->w_p_scr <= 0
8976 || (curwin->w_p_scr > curwin->w_height
8977 && curwin->w_height > 0))
8978 && full_screen)
8979 {
8980 if (pp == &(curwin->w_p_scr))
8981 {
8982 if (curwin->w_p_scr != 0)
8983 errmsg = e_scroll;
8984 win_comp_scroll(curwin);
8985 }
8986 /* If 'scroll' became invalid because of a side effect silently adjust
8987 * it. */
8988 else if (curwin->w_p_scr <= 0)
8989 curwin->w_p_scr = 1;
8990 else /* curwin->w_p_scr > curwin->w_height */
8991 curwin->w_p_scr = curwin->w_height;
8992 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00008993 if (p_hi < 0)
8994 {
8995 errmsg = e_positive;
8996 p_hi = 0;
8997 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02008998 else if (p_hi > 10000)
8999 {
9000 errmsg = e_invarg;
9001 p_hi = 10000;
9002 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009003 if (p_re < 0 || p_re > 2)
9004 {
9005 errmsg = e_invarg;
9006 p_re = 0;
9007 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009008 if (p_report < 0)
9009 {
9010 errmsg = e_positive;
9011 p_report = 1;
9012 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009013 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009014 {
9015 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9016 p_sj = Rows / 2;
9017 else
9018 {
9019 errmsg = e_scroll;
9020 p_sj = 1;
9021 }
9022 }
9023 if (p_so < 0 && full_screen)
9024 {
9025 errmsg = e_scroll;
9026 p_so = 0;
9027 }
9028 if (p_siso < 0 && full_screen)
9029 {
9030 errmsg = e_positive;
9031 p_siso = 0;
9032 }
9033#ifdef FEAT_CMDWIN
9034 if (p_cwh < 1)
9035 {
9036 errmsg = e_positive;
9037 p_cwh = 1;
9038 }
9039#endif
9040 if (p_ut < 0)
9041 {
9042 errmsg = e_positive;
9043 p_ut = 2000;
9044 }
9045 if (p_ss < 0)
9046 {
9047 errmsg = e_positive;
9048 p_ss = 0;
9049 }
9050
9051 /* May set global value for local option. */
9052 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9053 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9054
9055 options[opt_idx].flags |= P_WAS_SET;
9056
Bram Moolenaar53744302015-07-17 17:38:22 +02009057#if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL)
9058 if (!starting && errmsg == NULL)
9059 {
9060 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009061 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9062 vim_snprintf((char *)buf_new, 10, "%ld", value);
9063 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009064 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9065 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9066 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9067 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9068 reset_v_option_vars();
9069 }
9070#endif
9071
Bram Moolenaar071d4272004-06-13 20:20:40 +00009072 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009073 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009074 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009075 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009076 check_redraw(options[opt_idx].flags);
9077
9078 return errmsg;
9079}
9080
9081/*
9082 * Called after an option changed: check if something needs to be redrawn.
9083 */
9084 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009085check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009086{
9087 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009088 int doclear = (flags & P_RCLR) == P_RCLR;
9089 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009090
9091#ifdef FEAT_WINDOWS
9092 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9093 status_redraw_all();
9094#endif
9095
9096 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9097 changed_window_setting();
9098 if (flags & P_RBUF)
9099 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009100 if (flags & P_RWINONLY)
9101 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009102 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 redraw_all_later(CLEAR);
9104 else if (all)
9105 redraw_all_later(NOT_VALID);
9106}
9107
9108/*
9109 * Find index for option 'arg'.
9110 * Return -1 if not found.
9111 */
9112 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009113findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009114{
9115 int opt_idx;
9116 char *s, *p;
9117 static short quick_tab[27] = {0, 0}; /* quick access table */
9118 int is_term_opt;
9119
9120 /*
9121 * For first call: Initialize the quick-access table.
9122 * It contains the index for the first option that starts with a certain
9123 * letter. There are 26 letters, plus the first "t_" option.
9124 */
9125 if (quick_tab[1] == 0)
9126 {
9127 p = options[0].fullname;
9128 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9129 {
9130 if (s[0] != p[0])
9131 {
9132 if (s[0] == 't' && s[1] == '_')
9133 quick_tab[26] = opt_idx;
9134 else
9135 quick_tab[CharOrdLow(s[0])] = opt_idx;
9136 }
9137 p = s;
9138 }
9139 }
9140
9141 /*
9142 * Check for name starting with an illegal character.
9143 */
9144#ifdef EBCDIC
9145 if (!islower(arg[0]))
9146#else
9147 if (arg[0] < 'a' || arg[0] > 'z')
9148#endif
9149 return -1;
9150
9151 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9152 if (is_term_opt)
9153 opt_idx = quick_tab[26];
9154 else
9155 opt_idx = quick_tab[CharOrdLow(arg[0])];
9156 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9157 {
9158 if (STRCMP(arg, s) == 0) /* match full name */
9159 break;
9160 }
9161 if (s == NULL && !is_term_opt)
9162 {
9163 opt_idx = quick_tab[CharOrdLow(arg[0])];
9164 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9165 {
9166 s = options[opt_idx].shortname;
9167 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9168 break;
9169 s = NULL;
9170 }
9171 }
9172 if (s == NULL)
9173 opt_idx = -1;
9174 return opt_idx;
9175}
9176
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009177#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009178/*
9179 * Get the value for an option.
9180 *
9181 * Returns:
9182 * Number or Toggle option: 1, *numval gets value.
9183 * String option: 0, *stringval gets allocated string.
9184 * Hidden Number or Toggle option: -1.
9185 * hidden String option: -2.
9186 * unknown option: -3.
9187 */
9188 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009189get_option_value(
9190 char_u *name,
9191 long *numval,
9192 char_u **stringval, /* NULL when only checking existence */
9193 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009194{
9195 int opt_idx;
9196 char_u *varp;
9197
9198 opt_idx = findoption(name);
9199 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009200 {
9201 int key;
9202
9203 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9204 && (key = find_key_option(name)) != 0)
9205 {
9206 char_u key_name[2];
9207 char_u *p;
9208
9209 if (key < 0)
9210 {
9211 key_name[0] = KEY2TERMCAP0(key);
9212 key_name[1] = KEY2TERMCAP1(key);
9213 }
9214 else
9215 {
9216 key_name[0] = KS_KEY;
9217 key_name[1] = (key & 0xff);
9218 }
9219 p = find_termcode(key_name);
9220 if (p != NULL)
9221 {
9222 if (stringval != NULL)
9223 *stringval = vim_strsave(p);
9224 return 0;
9225 }
9226 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009227 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009228 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009229
9230 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9231
9232 if (options[opt_idx].flags & P_STRING)
9233 {
9234 if (varp == NULL) /* hidden option */
9235 return -2;
9236 if (stringval != NULL)
9237 {
9238#ifdef FEAT_CRYPT
9239 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009240 if ((char_u **)varp == &curbuf->b_p_key
9241 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009242 *stringval = vim_strsave((char_u *)"*****");
9243 else
9244#endif
9245 *stringval = vim_strsave(*(char_u **)(varp));
9246 }
9247 return 0;
9248 }
9249
9250 if (varp == NULL) /* hidden option */
9251 return -1;
9252 if (options[opt_idx].flags & P_NUM)
9253 *numval = *(long *)varp;
9254 else
9255 {
9256 /* Special case: 'modified' is b_changed, but we also want to consider
9257 * it set when 'ff' or 'fenc' changed. */
9258 if ((int *)varp == &curbuf->b_changed)
9259 *numval = curbufIsChanged();
9260 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009261 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009262 }
9263 return 1;
9264}
9265#endif
9266
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009267#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009268/*
9269 * Returns the option attributes and its value. Unlike the above function it
9270 * will return either global value or local value of the option depending on
9271 * what was requested, but it will never return global value if it was
9272 * requested to return local one and vice versa. Neither it will return
9273 * buffer-local value if it was requested to return window-local one.
9274 *
9275 * Pretends that option is absent if it is not present in the requested scope
9276 * (i.e. has no global, window-local or buffer-local value depending on
9277 * opt_type). Uses
9278 *
9279 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009280 * 0 hidden or unknown option, also option that does not have requested
9281 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009282 * see SOPT_* in vim.h for other flags
9283 *
9284 * Possible opt_type values: see SREQ_* in vim.h
9285 */
9286 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009287get_option_value_strict(
9288 char_u *name,
9289 long *numval,
9290 char_u **stringval, /* NULL when only obtaining attributes */
9291 int opt_type,
9292 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009293{
9294 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009295 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009296 struct vimoption *p;
9297 int r = 0;
9298
9299 opt_idx = findoption(name);
9300 if (opt_idx < 0)
9301 return 0;
9302
9303 p = &(options[opt_idx]);
9304
9305 /* Hidden option */
9306 if (p->var == NULL)
9307 return 0;
9308
9309 if (p->flags & P_BOOL)
9310 r |= SOPT_BOOL;
9311 else if (p->flags & P_NUM)
9312 r |= SOPT_NUM;
9313 else if (p->flags & P_STRING)
9314 r |= SOPT_STRING;
9315
9316 if (p->indir == PV_NONE)
9317 {
9318 if (opt_type == SREQ_GLOBAL)
9319 r |= SOPT_GLOBAL;
9320 else
9321 return 0; /* Did not request global-only option */
9322 }
9323 else
9324 {
9325 if (p->indir & PV_BOTH)
9326 r |= SOPT_GLOBAL;
9327 else if (opt_type == SREQ_GLOBAL)
9328 return 0; /* Requested global option */
9329
9330 if (p->indir & PV_WIN)
9331 {
9332 if (opt_type == SREQ_BUF)
9333 return 0; /* Did not request window-local option */
9334 else
9335 r |= SOPT_WIN;
9336 }
9337 else if (p->indir & PV_BUF)
9338 {
9339 if (opt_type == SREQ_WIN)
9340 return 0; /* Did not request buffer-local option */
9341 else
9342 r |= SOPT_BUF;
9343 }
9344 }
9345
9346 if (stringval == NULL)
9347 return r;
9348
9349 if (opt_type == SREQ_GLOBAL)
9350 varp = p->var;
9351 else
9352 {
9353 if (opt_type == SREQ_BUF)
9354 {
9355 /* Special case: 'modified' is b_changed, but we also want to
9356 * consider it set when 'ff' or 'fenc' changed. */
9357 if (p->indir == PV_MOD)
9358 {
9359 *numval = bufIsChanged((buf_T *) from);
9360 varp = NULL;
9361 }
9362#ifdef FEAT_CRYPT
9363 else if (p->indir == PV_KEY)
9364 {
9365 /* never return the value of the crypt key */
9366 *stringval = NULL;
9367 varp = NULL;
9368 }
9369#endif
9370 else
9371 {
9372 aco_save_T aco;
9373 aucmd_prepbuf(&aco, (buf_T *) from);
9374 varp = get_varp(p);
9375 aucmd_restbuf(&aco);
9376 }
9377 }
9378 else if (opt_type == SREQ_WIN)
9379 {
9380 win_T *save_curwin;
9381 save_curwin = curwin;
9382 curwin = (win_T *) from;
9383 curbuf = curwin->w_buffer;
9384 varp = get_varp(p);
9385 curwin = save_curwin;
9386 curbuf = curwin->w_buffer;
9387 }
9388 if (varp == p->var)
9389 return (r | SOPT_UNSET);
9390 }
9391
9392 if (varp != NULL)
9393 {
9394 if (p->flags & P_STRING)
9395 *stringval = vim_strsave(*(char_u **)(varp));
9396 else if (p->flags & P_NUM)
9397 *numval = *(long *) varp;
9398 else
9399 *numval = *(int *)varp;
9400 }
9401
9402 return r;
9403}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009404
9405/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009406 * Iterate over options. First argument is a pointer to a pointer to a
9407 * structure inside options[] array, second is option type like in the above
9408 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009409 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009410 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009411 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009412 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009413 * first argument to NULL.
9414 *
9415 * Returns full option name for current option on each call.
9416 */
9417 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009418option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009419{
9420 struct vimoption *ret = NULL;
9421 do
9422 {
9423 if (*option == NULL)
9424 *option = (void *) options;
9425 else if (((struct vimoption *) (*option))->fullname == NULL)
9426 {
9427 *option = NULL;
9428 return NULL;
9429 }
9430 else
9431 *option = (void *) (((struct vimoption *) (*option)) + 1);
9432
9433 ret = ((struct vimoption *) (*option));
9434
9435 /* Hidden option */
9436 if (ret->var == NULL)
9437 {
9438 ret = NULL;
9439 continue;
9440 }
9441
9442 switch (opt_type)
9443 {
9444 case SREQ_GLOBAL:
9445 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9446 ret = NULL;
9447 break;
9448 case SREQ_BUF:
9449 if (!(ret->indir & PV_BUF))
9450 ret = NULL;
9451 break;
9452 case SREQ_WIN:
9453 if (!(ret->indir & PV_WIN))
9454 ret = NULL;
9455 break;
9456 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009457 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009458 return NULL;
9459 }
9460 }
9461 while (ret == NULL);
9462
9463 return (char_u *)ret->fullname;
9464}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009465#endif
9466
Bram Moolenaar071d4272004-06-13 20:20:40 +00009467/*
9468 * Set the value of option "name".
9469 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009470 *
9471 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009472 */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009473 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009474set_option_value(
9475 char_u *name,
9476 long number,
9477 char_u *string,
9478 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009479{
9480 int opt_idx;
9481 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009482 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009483
9484 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009485 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009486 {
9487 int key;
9488
9489 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
9490 && (key = find_key_option(name)) != 0)
9491 {
9492 char_u key_name[2];
9493
9494 if (key < 0)
9495 {
9496 key_name[0] = KEY2TERMCAP0(key);
9497 key_name[1] = KEY2TERMCAP1(key);
9498 }
9499 else
9500 {
9501 key_name[0] = KS_KEY;
9502 key_name[1] = (key & 0xff);
9503 }
9504 add_termcode(key_name, string, FALSE);
9505 if (full_screen)
9506 ttest(FALSE);
9507 redraw_all_later(CLEAR);
9508 return NULL;
9509 }
9510
Bram Moolenaar071d4272004-06-13 20:20:40 +00009511 EMSG2(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009512 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009513 else
9514 {
9515 flags = options[opt_idx].flags;
9516#ifdef HAVE_SANDBOX
9517 /* Disallow changing some options in the sandbox */
9518 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009519 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00009520 EMSG(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009521 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009522 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009523#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009524 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009525 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009526 else
9527 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009528 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009529 if (varp != NULL) /* hidden option is not changed */
9530 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009531 if (number == 0 && string != NULL)
9532 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009533 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009534
9535 /* Either we are given a string or we are setting option
9536 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009537 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009538 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009539 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009540 {
9541 /* There's another character after zeros or the string
9542 * is empty. In both cases, we are trying to set a
9543 * num option using a string. */
9544 EMSG3(_("E521: Number required: &%s = '%s'"),
9545 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009546 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009547
9548 }
9549 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009550 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009551 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009552 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009553 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009554 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009555 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009556 }
9557 }
9558 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009559 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009560}
9561
9562/*
9563 * Get the terminal code for a terminal option.
9564 * Returns NULL when not found.
9565 */
9566 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009567get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009568{
9569 int opt_idx;
9570 char_u *varp;
9571
9572 if (tname[0] != 't' || tname[1] != '_' ||
9573 tname[2] == NUL || tname[3] == NUL)
9574 return NULL;
9575 if ((opt_idx = findoption(tname)) >= 0)
9576 {
9577 varp = get_varp(&(options[opt_idx]));
9578 if (varp != NULL)
9579 varp = *(char_u **)(varp);
9580 return varp;
9581 }
9582 return find_termcode(tname + 2);
9583}
9584
9585 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009586get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009587{
9588 int i;
9589
9590 i = findoption((char_u *)"hl");
9591 if (i >= 0)
9592 return options[i].def_val[VI_DEFAULT];
9593 return (char_u *)NULL;
9594}
9595
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009596#if defined(FEAT_MBYTE) || defined(PROTO)
9597 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009598get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009599{
9600 int i;
9601
9602 i = findoption((char_u *)"enc");
9603 if (i >= 0)
9604 return options[i].def_val[VI_DEFAULT];
9605 return (char_u *)NULL;
9606}
9607#endif
9608
Bram Moolenaar071d4272004-06-13 20:20:40 +00009609/*
9610 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
9611 */
9612 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009613find_key_option(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009614{
9615 int key;
9616 int modifiers;
9617
9618 /*
9619 * Don't use get_special_key_code() for t_xx, we don't want it to call
9620 * add_termcap_entry().
9621 */
9622 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9623 key = TERMCAP2KEY(arg[2], arg[3]);
9624 else
9625 {
9626 --arg; /* put arg at the '<' */
9627 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009628 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009629 if (modifiers) /* can't handle modifiers here */
9630 key = 0;
9631 }
9632 return key;
9633}
9634
9635/*
9636 * if 'all' == 0: show changed options
9637 * if 'all' == 1: show all normal options
9638 * if 'all' == 2: show all terminal options
9639 */
9640 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009641showoptions(
9642 int all,
9643 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644{
9645 struct vimoption *p;
9646 int col;
9647 int isterm;
9648 char_u *varp;
9649 struct vimoption **items;
9650 int item_count;
9651 int run;
9652 int row, rows;
9653 int cols;
9654 int i;
9655 int len;
9656
9657#define INC 20
9658#define GAP 3
9659
9660 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
9661 PARAM_COUNT));
9662 if (items == NULL)
9663 return;
9664
9665 /* Highlight title */
9666 if (all == 2)
9667 MSG_PUTS_TITLE(_("\n--- Terminal codes ---"));
9668 else if (opt_flags & OPT_GLOBAL)
9669 MSG_PUTS_TITLE(_("\n--- Global option values ---"));
9670 else if (opt_flags & OPT_LOCAL)
9671 MSG_PUTS_TITLE(_("\n--- Local option values ---"));
9672 else
9673 MSG_PUTS_TITLE(_("\n--- Options ---"));
9674
9675 /*
9676 * do the loop two times:
9677 * 1. display the short items
9678 * 2. display the long items (only strings and numbers)
9679 */
9680 for (run = 1; run <= 2 && !got_int; ++run)
9681 {
9682 /*
9683 * collect the items in items[]
9684 */
9685 item_count = 0;
9686 for (p = &options[0]; p->fullname != NULL; p++)
9687 {
9688 varp = NULL;
9689 isterm = istermoption(p);
9690 if (opt_flags != 0)
9691 {
9692 if (p->indir != PV_NONE && !isterm)
9693 varp = get_varp_scope(p, opt_flags);
9694 }
9695 else
9696 varp = get_varp(p);
9697 if (varp != NULL
9698 && ((all == 2 && isterm)
9699 || (all == 1 && !isterm)
9700 || (all == 0 && !optval_default(p, varp))))
9701 {
9702 if (p->flags & P_BOOL)
9703 len = 1; /* a toggle option fits always */
9704 else
9705 {
9706 option_value2string(p, opt_flags);
9707 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
9708 }
9709 if ((len <= INC - GAP && run == 1) ||
9710 (len > INC - GAP && run == 2))
9711 items[item_count++] = p;
9712 }
9713 }
9714
9715 /*
9716 * display the items
9717 */
9718 if (run == 1)
9719 {
9720 cols = (Columns + GAP - 3) / INC;
9721 if (cols == 0)
9722 cols = 1;
9723 rows = (item_count + cols - 1) / cols;
9724 }
9725 else /* run == 2 */
9726 rows = item_count;
9727 for (row = 0; row < rows && !got_int; ++row)
9728 {
9729 msg_putchar('\n'); /* go to next line */
9730 if (got_int) /* 'q' typed in more */
9731 break;
9732 col = 0;
9733 for (i = row; i < item_count; i += rows)
9734 {
9735 msg_col = col; /* make columns */
9736 showoneopt(items[i], opt_flags);
9737 col += INC;
9738 }
9739 out_flush();
9740 ui_breakcheck();
9741 }
9742 }
9743 vim_free(items);
9744}
9745
9746/*
9747 * Return TRUE if option "p" has its default value.
9748 */
9749 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009750optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009751{
9752 int dvi;
9753
9754 if (varp == NULL)
9755 return TRUE; /* hidden option is always at default */
9756 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
9757 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009758 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009759 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00009760 /* the cast to long is required for Manx C, long_i is
9761 * needed for MSVC */
9762 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009763 /* P_STRING */
9764 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
9765}
9766
9767/*
9768 * showoneopt: show the value of one option
9769 * must not be called with a hidden option!
9770 */
9771 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009772showoneopt(
9773 struct vimoption *p,
9774 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009775{
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009776 char_u *varp;
9777 int save_silent = silent_mode;
9778
9779 silent_mode = FALSE;
9780 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009781
9782 varp = get_varp_scope(p, opt_flags);
9783
9784 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
9785 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
9786 ? !curbufIsChanged() : !*(int *)varp))
9787 MSG_PUTS("no");
9788 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
9789 MSG_PUTS("--");
9790 else
9791 MSG_PUTS(" ");
9792 MSG_PUTS(p->fullname);
9793 if (!(p->flags & P_BOOL))
9794 {
9795 msg_putchar('=');
9796 /* put value string in NameBuff */
9797 option_value2string(p, opt_flags);
9798 msg_outtrans(NameBuff);
9799 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00009800
9801 silent_mode = save_silent;
9802 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009803}
9804
9805/*
9806 * Write modified options as ":set" commands to a file.
9807 *
9808 * There are three values for "opt_flags":
9809 * OPT_GLOBAL: Write global option values and fresh values of
9810 * buffer-local options (used for start of a session
9811 * file).
9812 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
9813 * curwin (used for a vimrc file).
9814 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
9815 * and local values for window-local options of
9816 * curwin. Local values are also written when at the
9817 * default value, because a modeline or autocommand
9818 * may have set them when doing ":edit file" and the
9819 * user has set them back at the default or fresh
9820 * value.
9821 * When "local_only" is TRUE, don't write fresh
9822 * values, only local values (for ":mkview").
9823 * (fresh value = value used for a new buffer or window for a local option).
9824 *
9825 * Return FAIL on error, OK otherwise.
9826 */
9827 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009828makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009829{
9830 struct vimoption *p;
9831 char_u *varp; /* currently used value */
9832 char_u *varp_fresh; /* local value */
9833 char_u *varp_local = NULL; /* fresh value */
9834 char *cmd;
9835 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009836 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009837
9838 /*
9839 * The options that don't have a default (terminal name, columns, lines)
9840 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009841 * Do the loop over "options[]" twice: once for options with the
9842 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009843 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009844 for (pri = 1; pri >= 0; --pri)
9845 {
9846 for (p = &options[0]; !istermoption(p); p++)
9847 if (!(p->flags & P_NO_MKRC)
9848 && !istermoption(p)
9849 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00009850 {
9851 /* skip global option when only doing locals */
9852 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
9853 continue;
9854
9855 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
9856 * file, they are always buffer-specific. */
9857 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
9858 continue;
9859
9860 /* Global values are only written when not at the default value. */
9861 varp = get_varp_scope(p, opt_flags);
9862 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
9863 continue;
9864
9865 round = 2;
9866 if (p->indir != PV_NONE)
9867 {
9868 if (p->var == VAR_WIN)
9869 {
9870 /* skip window-local option when only doing globals */
9871 if (!(opt_flags & OPT_LOCAL))
9872 continue;
9873 /* When fresh value of window-local option is not at the
9874 * default, need to write it too. */
9875 if (!(opt_flags & OPT_GLOBAL) && !local_only)
9876 {
9877 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
9878 if (!optval_default(p, varp_fresh))
9879 {
9880 round = 1;
9881 varp_local = varp;
9882 varp = varp_fresh;
9883 }
9884 }
9885 }
9886 }
9887
9888 /* Round 1: fresh value for window-local options.
9889 * Round 2: other values */
9890 for ( ; round <= 2; varp = varp_local, ++round)
9891 {
9892 if (round == 1 || (opt_flags & OPT_GLOBAL))
9893 cmd = "set";
9894 else
9895 cmd = "setlocal";
9896
9897 if (p->flags & P_BOOL)
9898 {
9899 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
9900 return FAIL;
9901 }
9902 else if (p->flags & P_NUM)
9903 {
9904 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
9905 return FAIL;
9906 }
9907 else /* P_STRING */
9908 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009909#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9910 int do_endif = FALSE;
9911
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912 /* Don't set 'syntax' and 'filetype' again if the value is
9913 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009914 if (
9915# if defined(FEAT_SYN_HL)
9916 p->indir == PV_SYN
9917# if defined(FEAT_AUTOCMD)
9918 ||
9919# endif
9920# endif
9921# if defined(FEAT_AUTOCMD)
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009922 p->indir == PV_FT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009923# endif
Bram Moolenaar15bfa092008-07-24 16:45:38 +00009924 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00009925 {
9926 if (fprintf(fd, "if &%s != '%s'", p->fullname,
9927 *(char_u **)(varp)) < 0
9928 || put_eol(fd) < 0)
9929 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009930 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009931 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009932#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009933 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
9934 (p->flags & P_EXPAND) != 0) == FAIL)
9935 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009936#if defined(FEAT_SYN_HL) || defined(FEAT_AUTOCMD)
9937 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009938 {
9939 if (put_line(fd, "endif") == FAIL)
9940 return FAIL;
9941 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00009942#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009943 }
9944 }
9945 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +00009946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009947 return OK;
9948}
9949
9950#if defined(FEAT_FOLDING) || defined(PROTO)
9951/*
9952 * Generate set commands for the local fold options only. Used when
9953 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
9954 */
9955 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009956makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009957{
9958 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
9959# ifdef FEAT_EVAL
9960 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
9961 == FAIL
9962# endif
9963 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
9964 == FAIL
9965 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
9966 == FAIL
9967 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
9968 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
9969 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
9970 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
9971 )
9972 return FAIL;
9973
9974 return OK;
9975}
9976#endif
9977
9978 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009979put_setstring(
9980 FILE *fd,
9981 char *cmd,
9982 char *name,
9983 char_u **valuep,
9984 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985{
9986 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +02009987 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988
9989 if (fprintf(fd, "%s %s=", cmd, name) < 0)
9990 return FAIL;
9991 if (*valuep != NULL)
9992 {
9993 /* Output 'pastetoggle' as key names. For other
9994 * options some characters have to be escaped with
9995 * CTRL-V or backslash */
9996 if (valuep == &p_pt)
9997 {
9998 s = *valuep;
9999 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010000 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010001 return FAIL;
10002 }
10003 else if (expand)
10004 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010005 buf = alloc(MAXPATHL);
10006 if (buf == NULL)
10007 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010008 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10009 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010010 {
10011 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010012 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010013 }
10014 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010015 }
10016 else if (put_escstr(fd, *valuep, 2) == FAIL)
10017 return FAIL;
10018 }
10019 if (put_eol(fd) < 0)
10020 return FAIL;
10021 return OK;
10022}
10023
10024 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010025put_setnum(
10026 FILE *fd,
10027 char *cmd,
10028 char *name,
10029 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010030{
10031 long wc;
10032
10033 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10034 return FAIL;
10035 if (wc_use_keyname((char_u *)valuep, &wc))
10036 {
10037 /* print 'wildchar' and 'wildcharm' as a key name */
10038 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10039 return FAIL;
10040 }
10041 else if (fprintf(fd, "%ld", *valuep) < 0)
10042 return FAIL;
10043 if (put_eol(fd) < 0)
10044 return FAIL;
10045 return OK;
10046}
10047
10048 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010049put_setbool(
10050 FILE *fd,
10051 char *cmd,
10052 char *name,
10053 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010054{
Bram Moolenaar893de922007-10-02 18:40:57 +000010055 if (value < 0) /* global/local option using global value */
10056 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010057 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10058 || put_eol(fd) < 0)
10059 return FAIL;
10060 return OK;
10061}
10062
10063/*
10064 * Clear all the terminal options.
10065 * If the option has been allocated, free the memory.
10066 * Terminal options are never hidden or indirect.
10067 */
10068 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010069clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010071 /*
10072 * Reset a few things before clearing the old options. This may cause
10073 * outputting a few things that the terminal doesn't understand, but the
10074 * screen will be cleared later, so this is OK.
10075 */
10076#ifdef FEAT_MOUSE_TTY
10077 mch_setmouse(FALSE); /* switch mouse off */
10078#endif
10079#ifdef FEAT_TITLE
10080 mch_restore_title(3); /* restore window titles */
10081#endif
10082#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10083 /* When starting the GUI close the display opened for the clipboard.
10084 * After restoring the title, because that will need the display. */
10085 if (gui.starting)
10086 clear_xterm_clip();
10087#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010088 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010089
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010090 free_termoptions();
10091}
10092
10093 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010094free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010095{
10096 struct vimoption *p;
10097
Bram Moolenaar071d4272004-06-13 20:20:40 +000010098 for (p = &options[0]; p->fullname != NULL; p++)
10099 if (istermoption(p))
10100 {
10101 if (p->flags & P_ALLOCED)
10102 free_string_option(*(char_u **)(p->var));
10103 if (p->flags & P_DEF_ALLOCED)
10104 free_string_option(p->def_val[VI_DEFAULT]);
10105 *(char_u **)(p->var) = empty_option;
10106 p->def_val[VI_DEFAULT] = empty_option;
10107 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
10108 }
10109 clear_termcodes();
10110}
10111
10112/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010113 * Free the string for one term option, if it was allocated.
10114 * Set the string to empty_option and clear allocated flag.
10115 * "var" points to the option value.
10116 */
10117 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010118free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010119{
10120 struct vimoption *p;
10121
10122 for (p = &options[0]; p->fullname != NULL; p++)
10123 if (p->var == var)
10124 {
10125 if (p->flags & P_ALLOCED)
10126 free_string_option(*(char_u **)(p->var));
10127 *(char_u **)(p->var) = empty_option;
10128 p->flags &= ~P_ALLOCED;
10129 break;
10130 }
10131}
10132
10133/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010134 * Set the terminal option defaults to the current value.
10135 * Used after setting the terminal name.
10136 */
10137 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010138set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139{
10140 struct vimoption *p;
10141
10142 for (p = &options[0]; p->fullname != NULL; p++)
10143 {
10144 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10145 {
10146 if (p->flags & P_DEF_ALLOCED)
10147 {
10148 free_string_option(p->def_val[VI_DEFAULT]);
10149 p->flags &= ~P_DEF_ALLOCED;
10150 }
10151 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10152 if (p->flags & P_ALLOCED)
10153 {
10154 p->flags |= P_DEF_ALLOCED;
10155 p->flags &= ~P_ALLOCED; /* don't free the value now */
10156 }
10157 }
10158 }
10159}
10160
10161/*
10162 * return TRUE if 'p' starts with 't_'
10163 */
10164 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010165istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166{
10167 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10168}
10169
10170/*
10171 * Compute columns for ruler and shown command. 'sc_col' is also used to
10172 * decide what the maximum length of a message on the status line can be.
10173 * If there is a status line for the last window, 'sc_col' is independent
10174 * of 'ru_col'.
10175 */
10176
10177#define COL_RULER 17 /* columns needed by standard ruler */
10178
10179 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010180comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010181{
10182#if defined(FEAT_CMDL_INFO) && defined(FEAT_WINDOWS)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010183 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184
10185 sc_col = 0;
10186 ru_col = 0;
10187 if (p_ru)
10188 {
10189#ifdef FEAT_STL_OPT
10190 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
10191#else
10192 ru_col = COL_RULER + 1;
10193#endif
10194 /* no last status line, adjust sc_col */
10195 if (!last_has_status)
10196 sc_col = ru_col;
10197 }
10198 if (p_sc)
10199 {
10200 sc_col += SHOWCMD_COLS;
10201 if (!p_ru || last_has_status) /* no need for separating space */
10202 ++sc_col;
10203 }
10204 sc_col = Columns - sc_col;
10205 ru_col = Columns - ru_col;
10206 if (sc_col <= 0) /* screen too narrow, will become a mess */
10207 sc_col = 1;
10208 if (ru_col <= 0)
10209 ru_col = 1;
10210#else
10211 sc_col = Columns;
10212 ru_col = Columns;
10213#endif
10214}
10215
10216/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010217 * Unset local option value, similar to ":set opt<".
10218 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010219 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010220unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010221{
10222 struct vimoption *p;
10223 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010224 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010225
10226 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010227 if (opt_idx < 0)
10228 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010229 p = &(options[opt_idx]);
10230
10231 switch ((int)p->indir)
10232 {
10233 /* global option with local value: use local value if it's been set */
10234 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010235 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010236 break;
10237 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010238 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010239 break;
10240 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010241 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010242 break;
10243 case PV_AR:
10244 buf->b_p_ar = -1;
10245 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010246 case PV_BKC:
10247 clear_string_option(&buf->b_p_bkc);
10248 buf->b_bkc_flags = 0;
10249 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010250 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010251 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010252 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010253 case PV_TC:
10254 clear_string_option(&buf->b_p_tc);
10255 buf->b_tc_flags = 0;
10256 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010257#ifdef FEAT_FIND_ID
10258 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010259 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010260 break;
10261 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010262 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010263 break;
10264#endif
10265#ifdef FEAT_INS_EXPAND
10266 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010267 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010268 break;
10269 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010270 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010271 break;
10272#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010273 case PV_FP:
10274 clear_string_option(&buf->b_p_fp);
10275 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010276#ifdef FEAT_QUICKFIX
10277 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010278 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010279 break;
10280 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010281 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010282 break;
10283 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010284 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010285 break;
10286#endif
10287#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10288 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010289 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010290 break;
10291#endif
10292#if defined(FEAT_CRYPT)
10293 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010294 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010295 break;
10296#endif
10297#ifdef FEAT_STL_OPT
10298 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010299 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010300 break;
10301#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010302 case PV_UL:
10303 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10304 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010305#ifdef FEAT_LISP
10306 case PV_LW:
10307 clear_string_option(&buf->b_p_lw);
10308 break;
10309#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010310 }
10311}
10312
10313/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314 * Get pointer to option variable, depending on local or global scope.
10315 */
10316 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010317get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318{
10319 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10320 {
10321 if (p->var == VAR_WIN)
10322 return (char_u *)GLOBAL_WO(get_varp(p));
10323 return p->var;
10324 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010325 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 {
10327 switch ((int)p->indir)
10328 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010329 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010331 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10332 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10333 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010335 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10336 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10337 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010338 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010339 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010340 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010342 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10343 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010344#endif
10345#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010346 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10347 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010348#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010349#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10350 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10351#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010352#if defined(FEAT_CRYPT)
10353 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10354#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010355#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010356 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010357#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010358 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010359#ifdef FEAT_LISP
10360 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10361#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010362 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363 }
10364 return NULL; /* "cannot happen" */
10365 }
10366 return get_varp(p);
10367}
10368
10369/*
10370 * Get pointer to option variable.
10371 */
10372 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010373get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010374{
10375 /* hidden option, always return NULL */
10376 if (p->var == NULL)
10377 return NULL;
10378
10379 switch ((int)p->indir)
10380 {
10381 case PV_NONE: return p->var;
10382
10383 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010384 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010385 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010386 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010388 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010390 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010391 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010392 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010393 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010394 case PV_TC: return *curbuf->b_p_tc != NUL
10395 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010396 case PV_BKC: return *curbuf->b_p_bkc != NUL
10397 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010398#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010399 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010400 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010401 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010402 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10403#endif
10404#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010405 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010407 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10409#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010410 case PV_FP: return *curbuf->b_p_fp != NUL
10411 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010412#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010413 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010414 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010415 case PV_GP: return *curbuf->b_p_gp != NUL
10416 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10417 case PV_MP: return *curbuf->b_p_mp != NUL
10418 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010419#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010420#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10421 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10422 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10423#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010424#if defined(FEAT_CRYPT)
10425 case PV_CM: return *curbuf->b_p_cm != NUL
10426 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10427#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010428#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010429 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010430 ? (char_u *)&(curwin->w_p_stl) : p->var;
10431#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010432 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10433 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010434#ifdef FEAT_LISP
10435 case PV_LW: return *curbuf->b_p_lw != NUL
10436 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10437#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438
10439#ifdef FEAT_ARABIC
10440 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10441#endif
10442 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010443#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010444 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10445#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010446#ifdef FEAT_SYN_HL
10447 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10448 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010449 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010450#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451#ifdef FEAT_DIFF
10452 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10453#endif
10454#ifdef FEAT_FOLDING
10455 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10456 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10457 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10458 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10459 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10460 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10461 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10462# ifdef FEAT_EVAL
10463 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10464 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10465# endif
10466 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10467#endif
10468 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010469 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010470#ifdef FEAT_LINEBREAK
10471 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10472#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010473#ifdef FEAT_WINDOWS
Bram Moolenaar071d4272004-06-13 20:20:40 +000010474 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010475 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
10476#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010477#if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX)
10478 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10479#endif
10480#ifdef FEAT_RIGHTLEFT
10481 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10482 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10483#endif
10484 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10485 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10486#ifdef FEAT_LINEBREAK
10487 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010488 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10489 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490#endif
10491#ifdef FEAT_SCROLLBIND
10492 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
10493#endif
Bram Moolenaar860cae12010-06-05 23:22:07 +020010494#ifdef FEAT_CURSORBIND
10495 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
10496#endif
10497#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010498 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10499 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010500#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501
10502 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10503 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
10504#ifdef FEAT_MBYTE
10505 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
10506#endif
10507#if defined(FEAT_QUICKFIX)
10508 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10509 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
10510#endif
10511 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10512 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10513#ifdef FEAT_CINDENT
10514 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10515 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10516 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10517#endif
10518#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10519 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10520#endif
10521#ifdef FEAT_COMMENTS
10522 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10523#endif
10524#ifdef FEAT_FOLDING
10525 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10526#endif
10527#ifdef FEAT_INS_EXPAND
10528 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10529#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010530#ifdef FEAT_COMPL_FUNC
10531 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010532 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010535 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010536 case PV_ET: return (char_u *)&(curbuf->b_p_et);
10537#ifdef FEAT_MBYTE
10538 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
10539#endif
10540 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
10541#ifdef FEAT_AUTOCMD
10542 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
10543#endif
10544 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010545 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010546 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10547 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10548 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10549 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10550#ifdef FEAT_FIND_ID
10551# ifdef FEAT_EVAL
10552 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10553# endif
10554#endif
10555#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10556 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10557 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10558#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010559#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010560 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10561#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562#ifdef FEAT_CRYPT
10563 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10564#endif
10565#ifdef FEAT_LISP
10566 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10567#endif
10568 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10569 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10570 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10571 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10572 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010574#ifdef FEAT_TEXTOBJ
10575 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10576#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010577 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10578#ifdef FEAT_SMARTINDENT
10579 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10580#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010581 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10583#ifdef FEAT_SEARCHPATH
10584 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10585#endif
10586 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10587#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010588 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010589 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10590#endif
10591#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010592 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10593 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10594 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010595#endif
10596 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10597 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10598 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10599 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010600#ifdef FEAT_PERSISTENT_UNDO
10601 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10602#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010603 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10604#ifdef FEAT_KEYMAP
10605 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10606#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010607#ifdef FEAT_SIGNS
10608 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10609#endif
Bram Moolenaar95f09602016-11-10 20:01:45 +010010610 default: IEMSG(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611 }
10612 /* always return a valid pointer to avoid a crash! */
10613 return (char_u *)&(curbuf->b_p_wm);
10614}
10615
10616/*
10617 * Get the value of 'equalprg', either the buffer-local one or the global one.
10618 */
10619 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010620get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010621{
10622 if (*curbuf->b_p_ep == NUL)
10623 return p_ep;
10624 return curbuf->b_p_ep;
10625}
10626
10627#if defined(FEAT_WINDOWS) || defined(PROTO)
10628/*
10629 * Copy options from one window to another.
10630 * Used when splitting a window.
10631 */
10632 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010633win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010634{
10635 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10636 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
10637# ifdef FEAT_RIGHTLEFT
10638# ifdef FEAT_FKMAP
10639 /* Is this right? */
10640 wp_to->w_farsi = wp_from->w_farsi;
10641# endif
10642# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010643#if defined(FEAT_LINEBREAK)
10644 briopt_check(wp_to);
10645#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010646}
10647#endif
10648
10649/*
10650 * Copy the options from one winopt_T to another.
10651 * Doesn't free the old option values in "to", use clear_winopt() for that.
10652 * The 'scroll' option is not copied, because it depends on the window height.
10653 * The 'previewwindow' option is reset, there can be only one preview window.
10654 */
10655 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010656copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657{
10658#ifdef FEAT_ARABIC
10659 to->wo_arab = from->wo_arab;
10660#endif
10661 to->wo_list = from->wo_list;
10662 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010663 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010664#ifdef FEAT_LINEBREAK
10665 to->wo_nuw = from->wo_nuw;
10666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010667#ifdef FEAT_RIGHTLEFT
10668 to->wo_rl = from->wo_rl;
10669 to->wo_rlc = vim_strsave(from->wo_rlc);
10670#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010671#ifdef FEAT_STL_OPT
10672 to->wo_stl = vim_strsave(from->wo_stl);
10673#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010674 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010675#ifdef FEAT_DIFF
10676 to->wo_wrap_save = from->wo_wrap_save;
10677#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010678#ifdef FEAT_LINEBREAK
10679 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020010680 to->wo_bri = from->wo_bri;
10681 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010682#endif
10683#ifdef FEAT_SCROLLBIND
10684 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010685 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010686#endif
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010687#ifdef FEAT_CURSORBIND
10688 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010689 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010010690#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010691#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010692 to->wo_spell = from->wo_spell;
10693#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010694#ifdef FEAT_SYN_HL
10695 to->wo_cuc = from->wo_cuc;
10696 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020010697 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010698#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699#ifdef FEAT_DIFF
10700 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010701 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010702#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010703#ifdef FEAT_CONCEAL
10704 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020010705 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707#ifdef FEAT_FOLDING
10708 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010709 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010710 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010711 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010712 to->wo_fdi = vim_strsave(from->wo_fdi);
10713 to->wo_fml = from->wo_fml;
10714 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010715 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010717 to->wo_fdm_save = from->wo_diff_saved
10718 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719 to->wo_fdn = from->wo_fdn;
10720# ifdef FEAT_EVAL
10721 to->wo_fde = vim_strsave(from->wo_fde);
10722 to->wo_fdt = vim_strsave(from->wo_fdt);
10723# endif
10724 to->wo_fmr = vim_strsave(from->wo_fmr);
10725#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010726#ifdef FEAT_SIGNS
10727 to->wo_scl = vim_strsave(from->wo_scl);
10728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010729 check_winopt(to); /* don't want NULL pointers */
10730}
10731
10732/*
10733 * Check string options in a window for a NULL value.
10734 */
10735 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010736check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737{
10738 check_winopt(&win->w_onebuf_opt);
10739 check_winopt(&win->w_allbuf_opt);
10740}
10741
10742/*
10743 * Check for NULL pointers in a winopt_T and replace them with empty_option.
10744 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020010745 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010746check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010747{
10748#ifdef FEAT_FOLDING
10749 check_string_option(&wop->wo_fdi);
10750 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010751 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752# ifdef FEAT_EVAL
10753 check_string_option(&wop->wo_fde);
10754 check_string_option(&wop->wo_fdt);
10755# endif
10756 check_string_option(&wop->wo_fmr);
10757#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010758#ifdef FEAT_SIGNS
10759 check_string_option(&wop->wo_scl);
10760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761#ifdef FEAT_RIGHTLEFT
10762 check_string_option(&wop->wo_rlc);
10763#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010764#ifdef FEAT_STL_OPT
10765 check_string_option(&wop->wo_stl);
10766#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010767#ifdef FEAT_SYN_HL
10768 check_string_option(&wop->wo_cc);
10769#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010770#ifdef FEAT_CONCEAL
10771 check_string_option(&wop->wo_cocu);
10772#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010773#ifdef FEAT_LINEBREAK
10774 check_string_option(&wop->wo_briopt);
10775#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010776}
10777
10778/*
10779 * Free the allocated memory inside a winopt_T.
10780 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010781 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010782clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783{
10784#ifdef FEAT_FOLDING
10785 clear_string_option(&wop->wo_fdi);
10786 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020010787 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788# ifdef FEAT_EVAL
10789 clear_string_option(&wop->wo_fde);
10790 clear_string_option(&wop->wo_fdt);
10791# endif
10792 clear_string_option(&wop->wo_fmr);
10793#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010794#ifdef FEAT_SIGNS
10795 clear_string_option(&wop->wo_scl);
10796#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020010797#ifdef FEAT_LINEBREAK
10798 clear_string_option(&wop->wo_briopt);
10799#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010800#ifdef FEAT_RIGHTLEFT
10801 clear_string_option(&wop->wo_rlc);
10802#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010803#ifdef FEAT_STL_OPT
10804 clear_string_option(&wop->wo_stl);
10805#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020010806#ifdef FEAT_SYN_HL
10807 clear_string_option(&wop->wo_cc);
10808#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020010809#ifdef FEAT_CONCEAL
10810 clear_string_option(&wop->wo_cocu);
10811#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010812}
10813
10814/*
10815 * Copy global option values to local options for one buffer.
10816 * Used when creating a new buffer and sometimes when entering a buffer.
10817 * flags:
10818 * BCO_ENTER We will enter the buf buffer.
10819 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
10820 * appropriate.
10821 * BCO_NOHELP Don't copy the values to a help buffer.
10822 */
10823 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010824buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010825{
10826 int should_copy = TRUE;
10827 char_u *save_p_isk = NULL; /* init for GCC */
10828 int dont_do_help;
10829 int did_isk = FALSE;
10830
10831 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832 * Skip this when the option defaults have not been set yet. Happens when
10833 * main() allocates the first buffer.
10834 */
10835 if (p_cpo != NULL)
10836 {
10837 /*
10838 * Always copy when entering and 'cpo' contains 'S'.
10839 * Don't copy when already initialized.
10840 * Don't copy when 'cpo' contains 's' and not entering.
10841 * 'S' BCO_ENTER initialized 's' should_copy
10842 * yes yes X X TRUE
10843 * yes no yes X FALSE
10844 * no X yes X FALSE
10845 * X no no yes FALSE
10846 * X no no no TRUE
10847 * no yes no X TRUE
10848 */
10849 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
10850 && (buf->b_p_initialized
10851 || (!(flags & BCO_ENTER)
10852 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
10853 should_copy = FALSE;
10854
10855 if (should_copy || (flags & BCO_ALWAYS))
10856 {
10857 /* Don't copy the options specific to a help buffer when
10858 * BCO_NOHELP is given or the options were initialized already
10859 * (jumping back to a help file with CTRL-T or CTRL-O) */
10860 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
10861 || buf->b_p_initialized;
10862 if (dont_do_help) /* don't free b_p_isk */
10863 {
10864 save_p_isk = buf->b_p_isk;
10865 buf->b_p_isk = NULL;
10866 }
10867 /*
10868 * Always free the allocated strings.
10869 * If not already initialized, set 'readonly' and copy 'fileformat'.
10870 */
10871 if (!buf->b_p_initialized)
10872 {
10873 free_buf_options(buf, TRUE);
10874 buf->b_p_ro = FALSE; /* don't copy readonly */
10875 buf->b_p_tx = p_tx;
10876#ifdef FEAT_MBYTE
10877 buf->b_p_fenc = vim_strsave(p_fenc);
10878#endif
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020010879 switch (*p_ffs)
10880 {
10881 case 'm':
10882 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
10883 case 'd':
10884 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
10885 case 'u':
10886 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
10887 default:
10888 buf->b_p_ff = vim_strsave(p_ff);
10889 }
10890 if (buf->b_p_ff != NULL)
10891 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892#if defined(FEAT_QUICKFIX)
10893 buf->b_p_bh = empty_option;
10894 buf->b_p_bt = empty_option;
10895#endif
10896 }
10897 else
10898 free_buf_options(buf, FALSE);
10899
10900 buf->b_p_ai = p_ai;
10901 buf->b_p_ai_nopaste = p_ai_nopaste;
10902 buf->b_p_sw = p_sw;
10903 buf->b_p_tw = p_tw;
10904 buf->b_p_tw_nopaste = p_tw_nopaste;
10905 buf->b_p_tw_nobin = p_tw_nobin;
10906 buf->b_p_wm = p_wm;
10907 buf->b_p_wm_nopaste = p_wm_nopaste;
10908 buf->b_p_wm_nobin = p_wm_nobin;
10909 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000010910#ifdef FEAT_MBYTE
10911 buf->b_p_bomb = p_bomb;
10912#endif
Bram Moolenaarb388be02015-07-22 22:19:38 +020010913 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010914 buf->b_p_et = p_et;
10915 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020010916 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010917 buf->b_p_ml = p_ml;
10918 buf->b_p_ml_nobin = p_ml_nobin;
10919 buf->b_p_inf = p_inf;
10920 buf->b_p_swf = p_swf;
10921#ifdef FEAT_INS_EXPAND
10922 buf->b_p_cpt = vim_strsave(p_cpt);
10923#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010924#ifdef FEAT_COMPL_FUNC
10925 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010926 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010927#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010928 buf->b_p_sts = p_sts;
10929 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010930 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010931#ifdef FEAT_COMMENTS
10932 buf->b_p_com = vim_strsave(p_com);
10933#endif
10934#ifdef FEAT_FOLDING
10935 buf->b_p_cms = vim_strsave(p_cms);
10936#endif
10937 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010938 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939 buf->b_p_nf = vim_strsave(p_nf);
10940 buf->b_p_mps = vim_strsave(p_mps);
10941#ifdef FEAT_SMARTINDENT
10942 buf->b_p_si = p_si;
10943#endif
10944 buf->b_p_ci = p_ci;
10945#ifdef FEAT_CINDENT
10946 buf->b_p_cin = p_cin;
10947 buf->b_p_cink = vim_strsave(p_cink);
10948 buf->b_p_cino = vim_strsave(p_cino);
10949#endif
10950#ifdef FEAT_AUTOCMD
10951 /* Don't copy 'filetype', it must be detected */
10952 buf->b_p_ft = empty_option;
10953#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954 buf->b_p_pi = p_pi;
10955#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10956 buf->b_p_cinw = vim_strsave(p_cinw);
10957#endif
10958#ifdef FEAT_LISP
10959 buf->b_p_lisp = p_lisp;
10960#endif
10961#ifdef FEAT_SYN_HL
10962 /* Don't copy 'syntax', it must be set */
10963 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010964 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010010965 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010966#endif
10967#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020010968 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010969 (void)compile_cap_prog(&buf->b_s);
10970 buf->b_s.b_p_spf = vim_strsave(p_spf);
10971 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010972#endif
10973#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10974 buf->b_p_inde = vim_strsave(p_inde);
10975 buf->b_p_indk = vim_strsave(p_indk);
10976#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010977 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010978#if defined(FEAT_EVAL)
10979 buf->b_p_fex = vim_strsave(p_fex);
10980#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010981#ifdef FEAT_CRYPT
10982 buf->b_p_key = vim_strsave(p_key);
10983#endif
10984#ifdef FEAT_SEARCHPATH
10985 buf->b_p_sua = vim_strsave(p_sua);
10986#endif
10987#ifdef FEAT_KEYMAP
10988 buf->b_p_keymap = vim_strsave(p_keymap);
10989 buf->b_kmap_state |= KEYMAP_INIT;
10990#endif
10991 /* This isn't really an option, but copying the langmap and IME
10992 * state from the current buffer is better than resetting it. */
10993 buf->b_p_iminsert = p_iminsert;
10994 buf->b_p_imsearch = p_imsearch;
10995
10996 /* options that are normally global but also have a local value
10997 * are not copied, start using the global value */
10998 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010999 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011000 buf->b_p_bkc = empty_option;
11001 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011002#ifdef FEAT_QUICKFIX
11003 buf->b_p_gp = empty_option;
11004 buf->b_p_mp = empty_option;
11005 buf->b_p_efm = empty_option;
11006#endif
11007 buf->b_p_ep = empty_option;
11008 buf->b_p_kp = empty_option;
11009 buf->b_p_path = empty_option;
11010 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011011 buf->b_p_tc = empty_option;
11012 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013#ifdef FEAT_FIND_ID
11014 buf->b_p_def = empty_option;
11015 buf->b_p_inc = empty_option;
11016# ifdef FEAT_EVAL
11017 buf->b_p_inex = vim_strsave(p_inex);
11018# endif
11019#endif
11020#ifdef FEAT_INS_EXPAND
11021 buf->b_p_dict = empty_option;
11022 buf->b_p_tsr = empty_option;
11023#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011024#ifdef FEAT_TEXTOBJ
11025 buf->b_p_qe = vim_strsave(p_qe);
11026#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011027#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11028 buf->b_p_bexpr = empty_option;
11029#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011030#if defined(FEAT_CRYPT)
11031 buf->b_p_cm = empty_option;
11032#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011033#ifdef FEAT_PERSISTENT_UNDO
11034 buf->b_p_udf = p_udf;
11035#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011036#ifdef FEAT_LISP
11037 buf->b_p_lw = empty_option;
11038#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011039
11040 /*
11041 * Don't copy the options set by ex_help(), use the saved values,
11042 * when going from a help buffer to a non-help buffer.
11043 * Don't touch these at all when BCO_NOHELP is used and going from
11044 * or to a help buffer.
11045 */
11046 if (dont_do_help)
11047 buf->b_p_isk = save_p_isk;
11048 else
11049 {
11050 buf->b_p_isk = vim_strsave(p_isk);
11051 did_isk = TRUE;
11052 buf->b_p_ts = p_ts;
11053 buf->b_help = FALSE;
11054#ifdef FEAT_QUICKFIX
11055 if (buf->b_p_bt[0] == 'h')
11056 clear_string_option(&buf->b_p_bt);
11057#endif
11058 buf->b_p_ma = p_ma;
11059 }
11060 }
11061
11062 /*
11063 * When the options should be copied (ignoring BCO_ALWAYS), set the
11064 * flag that indicates that the options have been initialized.
11065 */
11066 if (should_copy)
11067 buf->b_p_initialized = TRUE;
11068 }
11069
11070 check_buf_options(buf); /* make sure we don't have NULLs */
11071 if (did_isk)
11072 (void)buf_init_chartab(buf, FALSE);
11073}
11074
11075/*
11076 * Reset the 'modifiable' option and its default value.
11077 */
11078 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011079reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011080{
11081 int opt_idx;
11082
11083 curbuf->b_p_ma = FALSE;
11084 p_ma = FALSE;
11085 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011086 if (opt_idx >= 0)
11087 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011088}
11089
11090/*
11091 * Set the global value for 'iminsert' to the local value.
11092 */
11093 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011094set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095{
11096 p_iminsert = curbuf->b_p_iminsert;
11097}
11098
11099/*
11100 * Set the global value for 'imsearch' to the local value.
11101 */
11102 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011103set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104{
11105 p_imsearch = curbuf->b_p_imsearch;
11106}
11107
11108#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11109static int expand_option_idx = -1;
11110static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11111static int expand_option_flags = 0;
11112
11113 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011114set_context_in_set_cmd(
11115 expand_T *xp,
11116 char_u *arg,
11117 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118{
11119 int nextchar;
11120 long_u flags = 0; /* init for GCC */
11121 int opt_idx = 0; /* init for GCC */
11122 char_u *p;
11123 char_u *s;
11124 int is_term_option = FALSE;
11125 int key;
11126
11127 expand_option_flags = opt_flags;
11128
11129 xp->xp_context = EXPAND_SETTINGS;
11130 if (*arg == NUL)
11131 {
11132 xp->xp_pattern = arg;
11133 return;
11134 }
11135 p = arg + STRLEN(arg) - 1;
11136 if (*p == ' ' && *(p - 1) != '\\')
11137 {
11138 xp->xp_pattern = p + 1;
11139 return;
11140 }
11141 while (p > arg)
11142 {
11143 s = p;
11144 /* count number of backslashes before ' ' or ',' */
11145 if (*p == ' ' || *p == ',')
11146 {
11147 while (s > arg && *(s - 1) == '\\')
11148 --s;
11149 }
11150 /* break at a space with an even number of backslashes */
11151 if (*p == ' ' && ((p - s) & 1) == 0)
11152 {
11153 ++p;
11154 break;
11155 }
11156 --p;
11157 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011158 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011159 {
11160 xp->xp_context = EXPAND_BOOL_SETTINGS;
11161 p += 2;
11162 }
11163 if (STRNCMP(p, "inv", 3) == 0)
11164 {
11165 xp->xp_context = EXPAND_BOOL_SETTINGS;
11166 p += 3;
11167 }
11168 xp->xp_pattern = arg = p;
11169 if (*arg == '<')
11170 {
11171 while (*p != '>')
11172 if (*p++ == NUL) /* expand terminal option name */
11173 return;
11174 key = get_special_key_code(arg + 1);
11175 if (key == 0) /* unknown name */
11176 {
11177 xp->xp_context = EXPAND_NOTHING;
11178 return;
11179 }
11180 nextchar = *++p;
11181 is_term_option = TRUE;
11182 expand_option_name[2] = KEY2TERMCAP0(key);
11183 expand_option_name[3] = KEY2TERMCAP1(key);
11184 }
11185 else
11186 {
11187 if (p[0] == 't' && p[1] == '_')
11188 {
11189 p += 2;
11190 if (*p != NUL)
11191 ++p;
11192 if (*p == NUL)
11193 return; /* expand option name */
11194 nextchar = *++p;
11195 is_term_option = TRUE;
11196 expand_option_name[2] = p[-2];
11197 expand_option_name[3] = p[-1];
11198 }
11199 else
11200 {
11201 /* Allow * wildcard */
11202 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11203 p++;
11204 if (*p == NUL)
11205 return;
11206 nextchar = *p;
11207 *p = NUL;
11208 opt_idx = findoption(arg);
11209 *p = nextchar;
11210 if (opt_idx == -1 || options[opt_idx].var == NULL)
11211 {
11212 xp->xp_context = EXPAND_NOTHING;
11213 return;
11214 }
11215 flags = options[opt_idx].flags;
11216 if (flags & P_BOOL)
11217 {
11218 xp->xp_context = EXPAND_NOTHING;
11219 return;
11220 }
11221 }
11222 }
11223 /* handle "-=" and "+=" */
11224 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11225 {
11226 ++p;
11227 nextchar = '=';
11228 }
11229 if ((nextchar != '=' && nextchar != ':')
11230 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11231 {
11232 xp->xp_context = EXPAND_UNSUCCESSFUL;
11233 return;
11234 }
11235 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11236 {
11237 xp->xp_context = EXPAND_OLD_SETTING;
11238 if (is_term_option)
11239 expand_option_idx = -1;
11240 else
11241 expand_option_idx = opt_idx;
11242 xp->xp_pattern = p + 1;
11243 return;
11244 }
11245 xp->xp_context = EXPAND_NOTHING;
11246 if (is_term_option || (flags & P_NUM))
11247 return;
11248
11249 xp->xp_pattern = p + 1;
11250
11251 if (flags & P_EXPAND)
11252 {
11253 p = options[opt_idx].var;
11254 if (p == (char_u *)&p_bdir
11255 || p == (char_u *)&p_dir
11256 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011257 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011258 || p == (char_u *)&p_rtp
11259#ifdef FEAT_SEARCHPATH
11260 || p == (char_u *)&p_cdpath
11261#endif
11262#ifdef FEAT_SESSION
11263 || p == (char_u *)&p_vdir
11264#endif
11265 )
11266 {
11267 xp->xp_context = EXPAND_DIRECTORIES;
11268 if (p == (char_u *)&p_path
11269#ifdef FEAT_SEARCHPATH
11270 || p == (char_u *)&p_cdpath
11271#endif
11272 )
11273 xp->xp_backslash = XP_BS_THREE;
11274 else
11275 xp->xp_backslash = XP_BS_ONE;
11276 }
11277 else
11278 {
11279 xp->xp_context = EXPAND_FILES;
11280 /* for 'tags' need three backslashes for a space */
11281 if (p == (char_u *)&p_tags)
11282 xp->xp_backslash = XP_BS_THREE;
11283 else
11284 xp->xp_backslash = XP_BS_ONE;
11285 }
11286 }
11287
11288 /* For an option that is a list of file names, find the start of the
11289 * last file name. */
11290 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11291 {
11292 /* count number of backslashes before ' ' or ',' */
11293 if (*p == ' ' || *p == ',')
11294 {
11295 s = p;
11296 while (s > xp->xp_pattern && *(s - 1) == '\\')
11297 --s;
11298 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11299 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11300 {
11301 xp->xp_pattern = p + 1;
11302 break;
11303 }
11304 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011305
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011306#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011307 /* for 'spellsuggest' start at "file:" */
11308 if (options[opt_idx].var == (char_u *)&p_sps
11309 && STRNCMP(p, "file:", 5) == 0)
11310 {
11311 xp->xp_pattern = p + 5;
11312 break;
11313 }
11314#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315 }
11316
11317 return;
11318}
11319
11320 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011321ExpandSettings(
11322 expand_T *xp,
11323 regmatch_T *regmatch,
11324 int *num_file,
11325 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011326{
11327 int num_normal = 0; /* Nr of matching non-term-code settings */
11328 int num_term = 0; /* Nr of matching terminal code settings */
11329 int opt_idx;
11330 int match;
11331 int count = 0;
11332 char_u *str;
11333 int loop;
11334 int is_term_opt;
11335 char_u name_buf[MAX_KEY_NAME_LEN];
11336 static char *(names[]) = {"all", "termcap"};
11337 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11338
11339 /* do this loop twice:
11340 * loop == 0: count the number of matching options
11341 * loop == 1: copy the matching options into allocated memory
11342 */
11343 for (loop = 0; loop <= 1; ++loop)
11344 {
11345 regmatch->rm_ic = ic;
11346 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11347 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011348 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11349 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11351 {
11352 if (loop == 0)
11353 num_normal++;
11354 else
11355 (*file)[count++] = vim_strsave((char_u *)names[match]);
11356 }
11357 }
11358 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11359 opt_idx++)
11360 {
11361 if (options[opt_idx].var == NULL)
11362 continue;
11363 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11364 && !(options[opt_idx].flags & P_BOOL))
11365 continue;
11366 is_term_opt = istermoption(&options[opt_idx]);
11367 if (is_term_opt && num_normal > 0)
11368 continue;
11369 match = FALSE;
11370 if (vim_regexec(regmatch, str, (colnr_T)0)
11371 || (options[opt_idx].shortname != NULL
11372 && vim_regexec(regmatch,
11373 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11374 match = TRUE;
11375 else if (is_term_opt)
11376 {
11377 name_buf[0] = '<';
11378 name_buf[1] = 't';
11379 name_buf[2] = '_';
11380 name_buf[3] = str[2];
11381 name_buf[4] = str[3];
11382 name_buf[5] = '>';
11383 name_buf[6] = NUL;
11384 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11385 {
11386 match = TRUE;
11387 str = name_buf;
11388 }
11389 }
11390 if (match)
11391 {
11392 if (loop == 0)
11393 {
11394 if (is_term_opt)
11395 num_term++;
11396 else
11397 num_normal++;
11398 }
11399 else
11400 (*file)[count++] = vim_strsave(str);
11401 }
11402 }
11403 /*
11404 * Check terminal key codes, these are not in the option table
11405 */
11406 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11407 {
11408 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11409 {
11410 if (!isprint(str[0]) || !isprint(str[1]))
11411 continue;
11412
11413 name_buf[0] = 't';
11414 name_buf[1] = '_';
11415 name_buf[2] = str[0];
11416 name_buf[3] = str[1];
11417 name_buf[4] = NUL;
11418
11419 match = FALSE;
11420 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11421 match = TRUE;
11422 else
11423 {
11424 name_buf[0] = '<';
11425 name_buf[1] = 't';
11426 name_buf[2] = '_';
11427 name_buf[3] = str[0];
11428 name_buf[4] = str[1];
11429 name_buf[5] = '>';
11430 name_buf[6] = NUL;
11431
11432 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11433 match = TRUE;
11434 }
11435 if (match)
11436 {
11437 if (loop == 0)
11438 num_term++;
11439 else
11440 (*file)[count++] = vim_strsave(name_buf);
11441 }
11442 }
11443
11444 /*
11445 * Check special key names.
11446 */
11447 regmatch->rm_ic = TRUE; /* ignore case here */
11448 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11449 {
11450 name_buf[0] = '<';
11451 STRCPY(name_buf + 1, str);
11452 STRCAT(name_buf, ">");
11453
11454 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11455 {
11456 if (loop == 0)
11457 num_term++;
11458 else
11459 (*file)[count++] = vim_strsave(name_buf);
11460 }
11461 }
11462 }
11463 if (loop == 0)
11464 {
11465 if (num_normal > 0)
11466 *num_file = num_normal;
11467 else if (num_term > 0)
11468 *num_file = num_term;
11469 else
11470 return OK;
11471 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11472 if (*file == NULL)
11473 {
11474 *file = (char_u **)"";
11475 return FAIL;
11476 }
11477 }
11478 }
11479 return OK;
11480}
11481
11482 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011483ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484{
11485 char_u *var = NULL; /* init for GCC */
11486 char_u *buf;
11487
11488 *num_file = 0;
11489 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11490 if (*file == NULL)
11491 return FAIL;
11492
11493 /*
11494 * For a terminal key code expand_option_idx is < 0.
11495 */
11496 if (expand_option_idx < 0)
11497 {
11498 var = find_termcode(expand_option_name + 2);
11499 if (var == NULL)
11500 expand_option_idx = findoption(expand_option_name);
11501 }
11502
11503 if (expand_option_idx >= 0)
11504 {
11505 /* put string of option value in NameBuff */
11506 option_value2string(&options[expand_option_idx], expand_option_flags);
11507 var = NameBuff;
11508 }
11509 else if (var == NULL)
11510 var = (char_u *)"";
11511
11512 /* A backslash is required before some characters. This is the reverse of
11513 * what happens in do_set(). */
11514 buf = vim_strsave_escaped(var, escape_chars);
11515
11516 if (buf == NULL)
11517 {
11518 vim_free(*file);
11519 *file = NULL;
11520 return FAIL;
11521 }
11522
11523#ifdef BACKSLASH_IN_FILENAME
11524 /* For MS-Windows et al. we don't double backslashes at the start and
11525 * before a file name character. */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011526 for (var = buf; *var != NUL; mb_ptr_adv(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011527 if (var[0] == '\\' && var[1] == '\\'
11528 && expand_option_idx >= 0
11529 && (options[expand_option_idx].flags & P_EXPAND)
11530 && vim_isfilec(var[2])
11531 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011532 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011533#endif
11534
11535 *file[0] = buf;
11536 *num_file = 1;
11537 return OK;
11538}
11539#endif
11540
11541/*
11542 * Get the value for the numeric or string option *opp in a nice format into
11543 * NameBuff[]. Must not be called with a hidden option!
11544 */
11545 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011546option_value2string(
11547 struct vimoption *opp,
11548 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011549{
11550 char_u *varp;
11551
11552 varp = get_varp_scope(opp, opt_flags);
11553
11554 if (opp->flags & P_NUM)
11555 {
11556 long wc = 0;
11557
11558 if (wc_use_keyname(varp, &wc))
11559 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11560 else if (wc != 0)
11561 STRCPY(NameBuff, transchar((int)wc));
11562 else
11563 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11564 }
11565 else /* P_STRING */
11566 {
11567 varp = *(char_u **)(varp);
11568 if (varp == NULL) /* just in case */
11569 NameBuff[0] = NUL;
11570#ifdef FEAT_CRYPT
11571 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011572 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011573 STRCPY(NameBuff, "*****");
11574#endif
11575 else if (opp->flags & P_EXPAND)
11576 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11577 /* Translate 'pastetoggle' into special key names */
11578 else if ((char_u **)opp->var == &p_pt)
11579 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11580 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011581 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011582 }
11583}
11584
11585/*
11586 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11587 * printed as a keyname.
11588 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11589 */
11590 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011591wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011592{
11593 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11594 {
11595 *wcp = *(long *)varp;
11596 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11597 return TRUE;
11598 }
11599 return FALSE;
11600}
11601
Bram Moolenaar01615492015-02-03 13:00:38 +010011602#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011603/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011604 * Any character has an equivalent 'langmap' character. This is used for
11605 * keyboards that have a special language mode that sends characters above
11606 * 128 (although other characters can be translated too). The "to" field is a
11607 * Vim command character. This avoids having to switch the keyboard back to
11608 * ASCII mode when leaving Insert mode.
11609 *
11610 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
11611 * commands.
11612 * When FEAT_MBYTE is defined langmap_mapga.ga_data is a sorted table of
11613 * langmap_entry_T. This does the same as langmap_mapchar[] for characters >=
11614 * 256.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011615 */
Bram Moolenaar01615492015-02-03 13:00:38 +010011616# if defined(FEAT_MBYTE) || defined(PROTO)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011617/*
11618 * With multi-byte support use growarray for 'langmap' chars >= 256
11619 */
11620typedef struct
11621{
11622 int from;
11623 int to;
11624} langmap_entry_T;
11625
11626static garray_T langmap_mapga;
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +010011627static void langmap_set_entry(int from, int to);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011628
11629/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011630 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
11631 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011632 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011633 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011634langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011635{
11636 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020011637 int a = 0;
11638 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011639
11640 /* Do a binary search for an existing entry. */
11641 while (a != b)
11642 {
11643 int i = (a + b) / 2;
11644 int d = entries[i].from - from;
11645
11646 if (d == 0)
11647 {
11648 entries[i].to = to;
11649 return;
11650 }
11651 if (d < 0)
11652 a = i + 1;
11653 else
11654 b = i;
11655 }
11656
11657 if (ga_grow(&langmap_mapga, 1) != OK)
11658 return; /* out of memory */
11659
11660 /* insert new entry at position "a" */
11661 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
11662 mch_memmove(entries + 1, entries,
11663 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
11664 ++langmap_mapga.ga_len;
11665 entries[0].from = from;
11666 entries[0].to = to;
11667}
11668
11669/*
11670 * Apply 'langmap' to multi-byte character "c" and return the result.
11671 */
11672 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011673langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011674{
11675 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
11676 int a = 0;
11677 int b = langmap_mapga.ga_len;
11678
11679 while (a != b)
11680 {
11681 int i = (a + b) / 2;
11682 int d = entries[i].from - c;
11683
11684 if (d == 0)
11685 return entries[i].to; /* found matching entry */
11686 if (d < 0)
11687 a = i + 1;
11688 else
11689 b = i;
11690 }
11691 return c; /* no entry found, return "c" unmodified */
11692}
11693# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011694
11695 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011696langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011697{
11698 int i;
11699
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011700 for (i = 0; i < 256; i++)
11701 langmap_mapchar[i] = i; /* we init with a one-to-one map */
11702# ifdef FEAT_MBYTE
11703 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
11704# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011705}
11706
11707/*
11708 * Called when langmap option is set; the language map can be
11709 * changed at any time!
11710 */
11711 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011712langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011713{
11714 char_u *p;
11715 char_u *p2;
11716 int from, to;
11717
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011718#ifdef FEAT_MBYTE
11719 ga_clear(&langmap_mapga); /* clear the previous map first */
11720#endif
11721 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011722
11723 for (p = p_langmap; p[0] != NUL; )
11724 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011725 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
11726 mb_ptr_adv(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011727 {
11728 if (p2[0] == '\\' && p2[1] != NUL)
11729 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011730 }
11731 if (p2[0] == ';')
11732 ++p2; /* abcd;ABCD form, p2 points to A */
11733 else
11734 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
11735 while (p[0])
11736 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011737 if (p[0] == ',')
11738 {
11739 ++p;
11740 break;
11741 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011742 if (p[0] == '\\' && p[1] != NUL)
11743 ++p;
11744#ifdef FEAT_MBYTE
11745 from = (*mb_ptr2char)(p);
11746#else
11747 from = p[0];
11748#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011749 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011750 if (p2 == NULL)
11751 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011752 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011753 if (p[0] != ',')
11754 {
11755 if (p[0] == '\\')
11756 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011757#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011758 to = (*mb_ptr2char)(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011759#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011760 to = p[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011762 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011763 }
11764 else
11765 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020011766 if (p2[0] != ',')
11767 {
11768 if (p2[0] == '\\')
11769 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011770#ifdef FEAT_MBYTE
Bram Moolenaar6af05062010-05-14 17:32:58 +020011771 to = (*mb_ptr2char)(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011772#else
Bram Moolenaar6af05062010-05-14 17:32:58 +020011773 to = p2[0];
Bram Moolenaar071d4272004-06-13 20:20:40 +000011774#endif
Bram Moolenaar6af05062010-05-14 17:32:58 +020011775 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776 }
11777 if (to == NUL)
11778 {
11779 EMSG2(_("E357: 'langmap': Matching character missing for %s"),
11780 transchar(from));
11781 return;
11782 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011783
11784#ifdef FEAT_MBYTE
11785 if (from >= 256)
11786 langmap_set_entry(from, to);
11787 else
11788#endif
11789 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011790
11791 /* Advance to next pair */
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011792 mb_ptr_adv(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020011793 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000011795 mb_ptr_adv(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011796 if (*p == ';')
11797 {
11798 p = p2;
11799 if (p[0] != NUL)
11800 {
11801 if (p[0] != ',')
11802 {
11803 EMSG2(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
11804 return;
11805 }
11806 ++p;
11807 }
11808 break;
11809 }
11810 }
11811 }
11812 }
11813}
11814#endif
11815
11816/*
11817 * Return TRUE if format option 'x' is in effect.
11818 * Take care of no formatting when 'paste' is set.
11819 */
11820 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011821has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011822{
11823 if (p_paste)
11824 return FALSE;
11825 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11826}
11827
11828/*
11829 * Return TRUE if "x" is present in 'shortmess' option, or
11830 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11831 */
11832 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011833shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011834{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011835 return p_shm != NULL &&
11836 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011837 || (vim_strchr(p_shm, 'a') != NULL
11838 && vim_strchr((char_u *)SHM_A, x) != NULL));
11839}
11840
11841/*
11842 * paste_option_changed() - Called after p_paste was set or reset.
11843 */
11844 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011845paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011846{
11847 static int old_p_paste = FALSE;
11848 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011849 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011850#ifdef FEAT_CMDL_INFO
11851 static int save_ru = 0;
11852#endif
11853#ifdef FEAT_RIGHTLEFT
11854 static int save_ri = 0;
11855 static int save_hkmap = 0;
11856#endif
11857 buf_T *buf;
11858
11859 if (p_paste)
11860 {
11861 /*
11862 * Paste switched from off to on.
11863 * Save the current values, so they can be restored later.
11864 */
11865 if (!old_p_paste)
11866 {
11867 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011868 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869 {
11870 buf->b_p_tw_nopaste = buf->b_p_tw;
11871 buf->b_p_wm_nopaste = buf->b_p_wm;
11872 buf->b_p_sts_nopaste = buf->b_p_sts;
11873 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011874 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011875 }
11876
11877 /* save global options */
11878 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011879 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011880#ifdef FEAT_CMDL_INFO
11881 save_ru = p_ru;
11882#endif
11883#ifdef FEAT_RIGHTLEFT
11884 save_ri = p_ri;
11885 save_hkmap = p_hkmap;
11886#endif
11887 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011888 p_ai_nopaste = p_ai;
11889 p_et_nopaste = p_et;
11890 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011891 p_tw_nopaste = p_tw;
11892 p_wm_nopaste = p_wm;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011893 }
11894
11895 /*
11896 * Always set the option values, also when 'paste' is set when it is
11897 * already on.
11898 */
11899 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011900 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901 {
11902 buf->b_p_tw = 0; /* textwidth is 0 */
11903 buf->b_p_wm = 0; /* wrapmargin is 0 */
11904 buf->b_p_sts = 0; /* softtabstop is 0 */
11905 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011906 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011907 }
11908
11909 /* set global options */
11910 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011911 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011912#ifdef FEAT_CMDL_INFO
11913# ifdef FEAT_WINDOWS
11914 if (p_ru)
11915 status_redraw_all(); /* redraw to remove the ruler */
11916# endif
11917 p_ru = 0; /* no ruler */
11918#endif
11919#ifdef FEAT_RIGHTLEFT
11920 p_ri = 0; /* no reverse insert */
11921 p_hkmap = 0; /* no Hebrew keyboard */
11922#endif
11923 /* set global values for local buffer options */
11924 p_tw = 0;
11925 p_wm = 0;
11926 p_sts = 0;
11927 p_ai = 0;
11928 }
11929
11930 /*
11931 * Paste switched from on to off: Restore saved values.
11932 */
11933 else if (old_p_paste)
11934 {
11935 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020011936 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011937 {
11938 buf->b_p_tw = buf->b_p_tw_nopaste;
11939 buf->b_p_wm = buf->b_p_wm_nopaste;
11940 buf->b_p_sts = buf->b_p_sts_nopaste;
11941 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011942 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011943 }
11944
11945 /* restore global options */
11946 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011947 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011948#ifdef FEAT_CMDL_INFO
11949# ifdef FEAT_WINDOWS
11950 if (p_ru != save_ru)
11951 status_redraw_all(); /* redraw to draw the ruler */
11952# endif
11953 p_ru = save_ru;
11954#endif
11955#ifdef FEAT_RIGHTLEFT
11956 p_ri = save_ri;
11957 p_hkmap = save_hkmap;
11958#endif
11959 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011960 p_ai = p_ai_nopaste;
11961 p_et = p_et_nopaste;
11962 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963 p_tw = p_tw_nopaste;
11964 p_wm = p_wm_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965 }
11966
11967 old_p_paste = p_paste;
11968}
11969
11970/*
11971 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
11972 *
11973 * Reset 'compatible' and set the values for options that didn't get set yet
11974 * to the Vim defaults.
11975 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011976 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011977 */
11978 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011979vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011980{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011981 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000011982 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011983 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011984
11985 if (!option_was_set((char_u *)"cp"))
11986 {
11987 p_cp = FALSE;
11988 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
11989 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
11990 set_option_default(opt_idx, OPT_FREE, FALSE);
11991 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020011992 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000011994
11995 if (fname != NULL)
11996 {
11997 p = vim_getenv(envname, &dofree);
11998 if (p == NULL)
11999 {
12000 /* Set $MYVIMRC to the first vimrc file found. */
12001 p = FullName_save(fname, FALSE);
12002 if (p != NULL)
12003 {
12004 vim_setenv(envname, p);
12005 vim_free(p);
12006 }
12007 }
12008 else if (dofree)
12009 vim_free(p);
12010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012011}
12012
12013/*
12014 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12015 */
12016 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012017change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012018{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012019 int opt_idx;
12020
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021 if (p_cp != on)
12022 {
12023 p_cp = on;
12024 compatible_set();
12025 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012026 opt_idx = findoption((char_u *)"cp");
12027 if (opt_idx >= 0)
12028 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012029}
12030
12031/*
12032 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012033 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012034 */
12035 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012036option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012037{
12038 int idx;
12039
12040 idx = findoption(name);
12041 if (idx < 0) /* unknown option */
12042 return FALSE;
12043 if (options[idx].flags & P_WAS_SET)
12044 return TRUE;
12045 return FALSE;
12046}
12047
12048/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012049 * Reset the flag indicating option "name" was set.
12050 */
12051 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012052reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012053{
12054 int idx = findoption(name);
12055
12056 if (idx >= 0)
12057 options[idx].flags &= ~P_WAS_SET;
12058}
12059
12060/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061 * compatible_set() - Called when 'compatible' has been set or unset.
12062 *
12063 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12064 * flag) to a Vi compatible value.
12065 * When 'compatible' is unset: Set all options that have a different default
12066 * for Vim (without the P_VI_DEF flag) to that default.
12067 */
12068 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012069compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012070{
12071 int opt_idx;
12072
12073 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12074 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12075 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12076 set_option_default(opt_idx, OPT_FREE, p_cp);
12077 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012078 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012079}
12080
12081#ifdef FEAT_LINEBREAK
12082
12083# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12084 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012085 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086# endif
12087
12088/*
12089 * fill_breakat_flags() -- called when 'breakat' changes value.
12090 */
12091 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012092fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012093{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012094 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012095 int i;
12096
12097 for (i = 0; i < 256; i++)
12098 breakat_flags[i] = FALSE;
12099
12100 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012101 for (p = p_breakat; *p; p++)
12102 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012103}
12104
12105# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012106 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012107# endif
12108
12109#endif
12110
12111/*
12112 * Check an option that can be a range of string values.
12113 *
12114 * Return OK for correct value, FAIL otherwise.
12115 * Empty is always OK.
12116 */
12117 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012118check_opt_strings(
12119 char_u *val,
12120 char **values,
12121 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012122{
12123 return opt_strings_flags(val, values, NULL, list);
12124}
12125
12126/*
12127 * Handle an option that can be a range of string values.
12128 * Set a flag in "*flagp" for each string present.
12129 *
12130 * Return OK for correct value, FAIL otherwise.
12131 * Empty is always OK.
12132 */
12133 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012134opt_strings_flags(
12135 char_u *val, /* new value */
12136 char **values, /* array of valid string values */
12137 unsigned *flagp,
12138 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012139{
12140 int i;
12141 int len;
12142 unsigned new_flags = 0;
12143
12144 while (*val)
12145 {
12146 for (i = 0; ; ++i)
12147 {
12148 if (values[i] == NULL) /* val not found in values[] */
12149 return FAIL;
12150
12151 len = (int)STRLEN(values[i]);
12152 if (STRNCMP(values[i], val, len) == 0
12153 && ((list && val[len] == ',') || val[len] == NUL))
12154 {
12155 val += len + (val[len] == ',');
12156 new_flags |= (1 << i);
12157 break; /* check next item in val list */
12158 }
12159 }
12160 }
12161 if (flagp != NULL)
12162 *flagp = new_flags;
12163
12164 return OK;
12165}
12166
12167/*
12168 * Read the 'wildmode' option, fill wim_flags[].
12169 */
12170 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012171check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012172{
12173 char_u new_wim_flags[4];
12174 char_u *p;
12175 int i;
12176 int idx = 0;
12177
12178 for (i = 0; i < 4; ++i)
12179 new_wim_flags[i] = 0;
12180
12181 for (p = p_wim; *p; ++p)
12182 {
12183 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12184 ;
12185 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12186 return FAIL;
12187 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12188 new_wim_flags[idx] |= WIM_LONGEST;
12189 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12190 new_wim_flags[idx] |= WIM_FULL;
12191 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12192 new_wim_flags[idx] |= WIM_LIST;
12193 else
12194 return FAIL;
12195 p += i;
12196 if (*p == NUL)
12197 break;
12198 if (*p == ',')
12199 {
12200 if (idx == 3)
12201 return FAIL;
12202 ++idx;
12203 }
12204 }
12205
12206 /* fill remaining entries with last flag */
12207 while (idx < 3)
12208 {
12209 new_wim_flags[idx + 1] = new_wim_flags[idx];
12210 ++idx;
12211 }
12212
12213 /* only when there are no errors, wim_flags[] is changed */
12214 for (i = 0; i < 4; ++i)
12215 wim_flags[i] = new_wim_flags[i];
12216 return OK;
12217}
12218
12219/*
12220 * Check if backspacing over something is allowed.
12221 */
12222 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012223can_bs(
12224 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012225{
12226 switch (*p_bs)
12227 {
12228 case '2': return TRUE;
12229 case '1': return (what != BS_START);
12230 case '0': return FALSE;
12231 }
12232 return vim_strchr(p_bs, what) != NULL;
12233}
12234
12235/*
12236 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12237 * the file must be considered changed when the value is different.
12238 */
12239 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012240save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012241{
12242 buf->b_start_ffc = *buf->b_p_ff;
12243 buf->b_start_eol = buf->b_p_eol;
12244#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012245 buf->b_start_bomb = buf->b_p_bomb;
12246
Bram Moolenaar071d4272004-06-13 20:20:40 +000012247 /* Only use free/alloc when necessary, they take time. */
12248 if (buf->b_start_fenc == NULL
12249 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12250 {
12251 vim_free(buf->b_start_fenc);
12252 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12253 }
12254#endif
12255}
12256
12257/*
12258 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12259 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012260 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12261 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012262 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012263 * When "ignore_empty" is true don't consider a new, empty buffer to be
12264 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012265 */
12266 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012267file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012268{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012269 /* In a buffer that was never loaded the options are not valid. */
12270 if (buf->b_flags & BF_NEVERLOADED)
12271 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012272 if (ignore_empty
12273 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012274 && buf->b_ml.ml_line_count == 1
12275 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12276 return FALSE;
12277 if (buf->b_start_ffc != *buf->b_p_ff)
12278 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012279 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012280 return TRUE;
12281#ifdef FEAT_MBYTE
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012282 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12283 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012284 if (buf->b_start_fenc == NULL)
12285 return (*buf->b_p_fenc != NUL);
12286 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
12287#else
12288 return FALSE;
12289#endif
12290}
12291
12292/*
12293 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12294 */
12295 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012296check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012297{
12298 return check_opt_strings(p, p_ff_values, FALSE);
12299}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012300
12301/*
12302 * Return the effective shiftwidth value for current buffer, using the
12303 * 'tabstop' value when 'shiftwidth' is zero.
12304 */
12305 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012306get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020012307{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012308 return buf->b_p_sw ? buf->b_p_sw : buf->b_p_ts;
Bram Moolenaar14f24742012-08-08 18:01:05 +020012309}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012310
12311/*
12312 * Return the effective softtabstop value for the current buffer, using the
12313 * 'tabstop' value when 'softtabstop' is negative.
12314 */
12315 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010012316get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012317{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010012318 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020012319}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012320
12321/*
12322 * Check matchpairs option for "*initc".
12323 * If there is a match set "*initc" to the matching character and "*findc" to
12324 * the opposite character. Set "*backwards" to the direction.
12325 * When "switchit" is TRUE swap the direction.
12326 */
12327 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012328find_mps_values(
12329 int *initc,
12330 int *findc,
12331 int *backwards,
12332 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012333{
12334 char_u *ptr;
12335
12336 ptr = curbuf->b_p_mps;
12337 while (*ptr != NUL)
12338 {
12339#ifdef FEAT_MBYTE
12340 if (has_mbyte)
12341 {
12342 char_u *prev;
12343
12344 if (mb_ptr2char(ptr) == *initc)
12345 {
12346 if (switchit)
12347 {
12348 *findc = *initc;
12349 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12350 *backwards = TRUE;
12351 }
12352 else
12353 {
12354 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12355 *backwards = FALSE;
12356 }
12357 return;
12358 }
12359 prev = ptr;
12360 ptr += mb_ptr2len(ptr) + 1;
12361 if (mb_ptr2char(ptr) == *initc)
12362 {
12363 if (switchit)
12364 {
12365 *findc = *initc;
12366 *initc = mb_ptr2char(prev);
12367 *backwards = FALSE;
12368 }
12369 else
12370 {
12371 *findc = mb_ptr2char(prev);
12372 *backwards = TRUE;
12373 }
12374 return;
12375 }
12376 ptr += mb_ptr2len(ptr);
12377 }
12378 else
12379#endif
12380 {
12381 if (*ptr == *initc)
12382 {
12383 if (switchit)
12384 {
12385 *backwards = TRUE;
12386 *findc = *initc;
12387 *initc = ptr[2];
12388 }
12389 else
12390 {
12391 *backwards = FALSE;
12392 *findc = ptr[2];
12393 }
12394 return;
12395 }
12396 ptr += 2;
12397 if (*ptr == *initc)
12398 {
12399 if (switchit)
12400 {
12401 *backwards = FALSE;
12402 *findc = *initc;
12403 *initc = ptr[-2];
12404 }
12405 else
12406 {
12407 *backwards = TRUE;
12408 *findc = ptr[-2];
12409 }
12410 return;
12411 }
12412 ++ptr;
12413 }
12414 if (*ptr == ',')
12415 ++ptr;
12416 }
12417}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012418
12419#if defined(FEAT_LINEBREAK) || defined(PROTO)
12420/*
12421 * This is called when 'breakindentopt' is changed and when a window is
12422 * initialized.
12423 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012424 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012425briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012426{
12427 char_u *p;
12428 int bri_shift = 0;
12429 long bri_min = 20;
12430 int bri_sbr = FALSE;
12431
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012432 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012433 while (*p != NUL)
12434 {
12435 if (STRNCMP(p, "shift:", 6) == 0
12436 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12437 {
12438 p += 6;
12439 bri_shift = getdigits(&p);
12440 }
12441 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12442 {
12443 p += 4;
12444 bri_min = getdigits(&p);
12445 }
12446 else if (STRNCMP(p, "sbr", 3) == 0)
12447 {
12448 p += 3;
12449 bri_sbr = TRUE;
12450 }
12451 if (*p != ',' && *p != NUL)
12452 return FAIL;
12453 if (*p == ',')
12454 ++p;
12455 }
12456
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012457 wp->w_p_brishift = bri_shift;
12458 wp->w_p_brimin = bri_min;
12459 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012460
12461 return OK;
12462}
12463#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012464
12465/*
12466 * Get the local or global value of 'backupcopy'.
12467 */
12468 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012469get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012470{
12471 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12472}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012473
12474#if defined(FEAT_SIGNS) || defined(PROTO)
12475/*
12476 * Return TRUE when window "wp" has a column to draw signs in.
12477 */
12478 int
12479signcolumn_on(win_T *wp)
12480{
12481 if (*wp->w_p_scl == 'n')
12482 return FALSE;
12483 if (*wp->w_p_scl == 'y')
12484 return TRUE;
12485 return (wp->w_buffer->b_signlist != NULL
12486# ifdef FEAT_NETBEANS_INTG
12487 || wp->w_buffer->b_has_sign_column
12488# endif
12489 );
12490}
12491#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012492
12493#if defined(FEAT_EVAL) || defined(PROTO)
12494/*
12495 * Get window or buffer local options.
12496 */
12497 dict_T *
12498get_winbuf_options(int bufopt)
12499{
12500 dict_T *d;
12501 int opt_idx;
12502
12503 d = dict_alloc();
12504 if (d == NULL)
12505 return NULL;
12506
12507 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12508 {
12509 struct vimoption *opt = &options[opt_idx];
12510
12511 if ((bufopt && (opt->indir & PV_BUF))
12512 || (!bufopt && (opt->indir & PV_WIN)))
12513 {
12514 char_u *varp = get_varp(opt);
12515
12516 if (varp != NULL)
12517 {
12518 if (opt->flags & P_STRING)
12519 dict_add_nr_str(d, opt->fullname, 0L, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012520 else if (opt->flags & P_NUM)
12521 dict_add_nr_str(d, opt->fullname, *(long *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012522 else
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012523 dict_add_nr_str(d, opt->fullname, *(int *)varp, NULL);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012524 }
12525 }
12526 }
12527
12528 return d;
12529}
12530#endif