blob: eb20b4120e1d1a17937c33678e4a8020afeb5630 [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 Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# 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 Moolenaarfc3abf42019-01-24 15:54:21 +010069#define PV_BOMB OPT_BUF(BV_BOMB)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000070#define PV_CI OPT_BUF(BV_CI)
71#ifdef FEAT_CINDENT
72# define PV_CIN OPT_BUF(BV_CIN)
73# define PV_CINK OPT_BUF(BV_CINK)
74# define PV_CINO OPT_BUF(BV_CINO)
75#endif
76#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
77# define PV_CINW OPT_BUF(BV_CINW)
78#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020079#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000080#ifdef FEAT_FOLDING
81# define PV_CMS OPT_BUF(BV_CMS)
82#endif
83#ifdef FEAT_COMMENTS
84# define PV_COM OPT_BUF(BV_COM)
85#endif
86#ifdef FEAT_INS_EXPAND
87# define PV_CPT OPT_BUF(BV_CPT)
88# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
89# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
90#endif
91#ifdef FEAT_COMPL_FUNC
92# define PV_CFU OPT_BUF(BV_CFU)
93#endif
94#ifdef FEAT_FIND_ID
95# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
96# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
97#endif
98#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +020099#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100102#define PV_FENC OPT_BUF(BV_FENC)
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000103#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
104# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
105#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100106#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000107#ifdef FEAT_EVAL
108# define PV_FEX OPT_BUF(BV_FEX)
109#endif
110#define PV_FF OPT_BUF(BV_FF)
111#define PV_FLP OPT_BUF(BV_FLP)
112#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100113#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000114#define PV_IMI OPT_BUF(BV_IMI)
115#define PV_IMS OPT_BUF(BV_IMS)
116#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
117# define PV_INDE OPT_BUF(BV_INDE)
118# define PV_INDK OPT_BUF(BV_INDK)
119#endif
120#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
121# define PV_INEX OPT_BUF(BV_INEX)
122#endif
123#define PV_INF OPT_BUF(BV_INF)
124#define PV_ISK OPT_BUF(BV_ISK)
125#ifdef FEAT_CRYPT
126# define PV_KEY OPT_BUF(BV_KEY)
127#endif
128#ifdef FEAT_KEYMAP
129# define PV_KMAP OPT_BUF(BV_KMAP)
130#endif
131#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
132#ifdef FEAT_LISP
133# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100134# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000135#endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100136#define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000137#define PV_MA OPT_BUF(BV_MA)
138#define PV_ML OPT_BUF(BV_ML)
139#define PV_MOD OPT_BUF(BV_MOD)
140#define PV_MPS OPT_BUF(BV_MPS)
141#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000142#ifdef FEAT_COMPL_FUNC
143# define PV_OFU OPT_BUF(BV_OFU)
144#endif
145#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
146#define PV_PI OPT_BUF(BV_PI)
147#ifdef FEAT_TEXTOBJ
148# define PV_QE OPT_BUF(BV_QE)
149#endif
150#define PV_RO OPT_BUF(BV_RO)
151#ifdef FEAT_SMARTINDENT
152# define PV_SI OPT_BUF(BV_SI)
153#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100154#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000155#ifdef FEAT_SYN_HL
156# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000157# define PV_SYN OPT_BUF(BV_SYN)
158#endif
159#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000160# define PV_SPC OPT_BUF(BV_SPC)
161# define PV_SPF OPT_BUF(BV_SPF)
162# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#endif
164#define PV_STS OPT_BUF(BV_STS)
165#ifdef FEAT_SEARCHPATH
166# define PV_SUA OPT_BUF(BV_SUA)
167#endif
168#define PV_SW OPT_BUF(BV_SW)
169#define PV_SWF OPT_BUF(BV_SWF)
170#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100171#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000172#define PV_TS OPT_BUF(BV_TS)
173#define PV_TW OPT_BUF(BV_TW)
174#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200175#ifdef FEAT_PERSISTENT_UNDO
176# define PV_UDF OPT_BUF(BV_UDF)
177#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000178#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200179#ifdef FEAT_VARTABS
180# define PV_VSTS OPT_BUF(BV_VSTS)
181# define PV_VTS OPT_BUF(BV_VTS)
182#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000183
184/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000185 * Definition of the PV_ values for window-local options.
186 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000187 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000188#define PV_LIST OPT_WIN(WV_LIST)
189#ifdef FEAT_ARABIC
190# define PV_ARAB OPT_WIN(WV_ARAB)
191#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200192#ifdef FEAT_LINEBREAK
193# define PV_BRI OPT_WIN(WV_BRI)
194# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
195#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000196#ifdef FEAT_DIFF
197# define PV_DIFF OPT_WIN(WV_DIFF)
198#endif
199#ifdef FEAT_FOLDING
200# define PV_FDC OPT_WIN(WV_FDC)
201# define PV_FEN OPT_WIN(WV_FEN)
202# define PV_FDI OPT_WIN(WV_FDI)
203# define PV_FDL OPT_WIN(WV_FDL)
204# define PV_FDM OPT_WIN(WV_FDM)
205# define PV_FML OPT_WIN(WV_FML)
206# define PV_FDN OPT_WIN(WV_FDN)
207# ifdef FEAT_EVAL
208# define PV_FDE OPT_WIN(WV_FDE)
209# define PV_FDT OPT_WIN(WV_FDT)
210# endif
211# define PV_FMR OPT_WIN(WV_FMR)
212#endif
213#ifdef FEAT_LINEBREAK
214# define PV_LBR OPT_WIN(WV_LBR)
215#endif
216#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200217#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000218#ifdef FEAT_LINEBREAK
219# define PV_NUW OPT_WIN(WV_NUW)
220#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200221#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222# define PV_PVW OPT_WIN(WV_PVW)
223#endif
224#ifdef FEAT_RIGHTLEFT
225# define PV_RL OPT_WIN(WV_RL)
226# define PV_RLC OPT_WIN(WV_RLC)
227#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100228#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000229#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000230#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000231# define PV_SPELL OPT_WIN(WV_SPELL)
232#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000233#ifdef FEAT_SYN_HL
234# define PV_CUC OPT_WIN(WV_CUC)
235# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200236# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000237#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000238#ifdef FEAT_STL_OPT
239# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
240#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100241#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000242# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000243# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100245#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200246#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200247# define PV_COCU OPT_WIN(WV_COCU)
248# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200249#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200250#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200251# define PV_TWK OPT_WIN(WV_TWK)
252# define PV_TWS OPT_WIN(WV_TWS)
253# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200254#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200255#ifdef FEAT_SIGNS
256# define PV_SCL OPT_WIN(WV_SCL)
257#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000258
259/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000260typedef enum
261{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000262 PV_NONE = 0,
263 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000264} idopt_T;
265
266/*
267 * Options local to a window have a value local to a buffer and global to all
268 * buffers. Indicate this by setting "var" to VAR_WIN.
269 */
270#define VAR_WIN ((char_u *)-1)
271
272/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000273 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000274 * Only to be used in option.c!
275 */
276static int p_ai;
277static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000278static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279static char_u *p_bh;
280static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000281static int p_bl;
282static int p_ci;
283#ifdef FEAT_CINDENT
284static int p_cin;
285static char_u *p_cink;
286static char_u *p_cino;
287#endif
288#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
289static char_u *p_cinw;
290#endif
291#ifdef FEAT_COMMENTS
292static char_u *p_com;
293#endif
294#ifdef FEAT_FOLDING
295static char_u *p_cms;
296#endif
297#ifdef FEAT_INS_EXPAND
298static char_u *p_cpt;
299#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000300#ifdef FEAT_COMPL_FUNC
301static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000302static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000304static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200305static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000306static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000307static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000308static char_u *p_ff;
309static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000310static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static long p_iminsert;
313static long p_imsearch;
314#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
315static char_u *p_inex;
316#endif
317#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
318static char_u *p_inde;
319static char_u *p_indk;
320#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000321#if defined(FEAT_EVAL)
322static char_u *p_fex;
323#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000324static int p_inf;
325static char_u *p_isk;
326#ifdef FEAT_CRYPT
327static char_u *p_key;
328#endif
329#ifdef FEAT_LISP
330static int p_lisp;
331#endif
332static int p_ml;
333static int p_ma;
334static int p_mod;
335static char_u *p_mps;
336static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000338#ifdef FEAT_TEXTOBJ
339static char_u *p_qe;
340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000341static int p_ro;
342#ifdef FEAT_SMARTINDENT
343static int p_si;
344#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000345static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static long p_sts;
347#if defined(FEAT_SEARCHPATH)
348static char_u *p_sua;
349#endif
350static long p_sw;
351static int p_swf;
352#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000353static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000355#endif
356#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000357static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000358static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000359static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360#endif
361static long p_ts;
362static long p_tw;
363static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200364#ifdef FEAT_PERSISTENT_UNDO
365static int p_udf;
366#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200368#ifdef FEAT_VARTABS
369static char_u *p_vsts;
370static char_u *p_vts;
371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000372#ifdef FEAT_KEYMAP
373static char_u *p_keymap;
374#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200375#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200376static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200377#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378
379/* Saved values for when 'bin' is set. */
380static int p_et_nobin;
381static int p_ml_nobin;
382static long p_tw_nobin;
383static long p_wm_nobin;
384
385/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200386static int p_ai_nopaste;
387static int p_et_nopaste;
388static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000389static long p_tw_nopaste;
390static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200391#ifdef FEAT_VARTABS
392static char_u *p_vsts_nopaste;
393#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000394
395struct vimoption
396{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200397 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)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000406#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200407 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaarded5f1b2018-11-10 17:33:29 +0100408# define SCTX_INIT , {0, 0, 0}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000409#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200410# define SCTX_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 Moolenaar05fbfdc2017-08-14 22:35:08 +0200473# 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,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000474
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100475/* Default python version for pyx* commands */
476#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
477# define DEFAULT_PYTHON_VER 0
478#elif defined(FEAT_PYTHON3)
479# define DEFAULT_PYTHON_VER 3
480#elif defined(FEAT_PYTHON)
481# define DEFAULT_PYTHON_VER 2
482#else
483# define DEFAULT_PYTHON_VER 0
484#endif
485
Bram Moolenaar071d4272004-06-13 20:20:40 +0000486/*
487 * options[] is initialized here.
488 * The order of the options MUST be alphabetic for ":set all" and findoption().
489 * All option names MUST start with a lowercase letter (for findoption()).
490 * Exception: "t_" options are at the end.
491 * The options with a NULL variable are 'hidden': a set command for them is
492 * ignored and they are not printed.
493 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100494static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000495{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200496 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497#ifdef FEAT_RIGHTLEFT
498 (char_u *)&p_aleph, PV_NONE,
499#else
500 (char_u *)NULL, PV_NONE,
501#endif
502 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100503#if (defined(WIN3264)) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000504 (char_u *)128L,
505#else
506 (char_u *)224L,
507#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200508 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200510#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000511 (char_u *)&p_antialias, PV_NONE,
512 {(char_u *)FALSE, (char_u *)FALSE}
513#else
514 (char_u *)NULL, PV_NONE,
515 {(char_u *)FALSE, (char_u *)FALSE}
516#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200517 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200518 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519#ifdef FEAT_ARABIC
520 (char_u *)VAR_WIN, PV_ARAB,
521#else
522 (char_u *)NULL, PV_NONE,
523#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200524 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000525 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
526#ifdef FEAT_ARABIC
527 (char_u *)&p_arshape, PV_NONE,
528#else
529 (char_u *)NULL, PV_NONE,
530#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200531 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
533#ifdef FEAT_RIGHTLEFT
534 (char_u *)&p_ari, PV_NONE,
535#else
536 (char_u *)NULL, PV_NONE,
537#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200538 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000539 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
540#ifdef FEAT_FKMAP
541 (char_u *)&p_altkeymap, PV_NONE,
542#else
543 (char_u *)NULL, PV_NONE,
544#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200545 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000546 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000547 (char_u *)&p_ambw, PV_NONE,
548 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200549 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100551#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100553 {(char_u *)FALSE, (char_u *)0L}
554#else
555 (char_u *)NULL, PV_NONE,
556 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200558 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autoindent", "ai", P_BOOL|P_VI_DEF,
560 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200561 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000562 {"autoprint", "ap", P_BOOL|P_VI_DEF,
563 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200564 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000566 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200567 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autowrite", "aw", P_BOOL|P_VI_DEF,
569 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200570 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autowriteall","awa", P_BOOL|P_VI_DEF,
572 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200573 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
575 (char_u *)&p_bg, PV_NONE,
576 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100577#if (defined(WIN3264)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 (char_u *)"dark",
579#else
580 (char_u *)"light",
581#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200582 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200583 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200585 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
587 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200588 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200589 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200590 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591#ifdef UNIX
592 {(char_u *)"yes", (char_u *)"auto"}
593#else
594 {(char_u *)"auto", (char_u *)"auto"}
595#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200596 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
598 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200600 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000601 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602 (char_u *)&p_bex, PV_NONE,
603 {
604#ifdef VMS
605 (char_u *)"_",
606#else
607 (char_u *)"~",
608#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200609 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200610 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611#ifdef FEAT_WILDIGN
612 (char_u *)&p_bsk, PV_NONE,
613 {(char_u *)"", (char_u *)0L}
614#else
615 (char_u *)NULL, PV_NONE,
616 {(char_u *)0L, (char_u *)0L}
617#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200618 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100620#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000621 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100622 {(char_u *)600L, (char_u *)0L}
623#else
624 (char_u *)NULL, PV_NONE,
625 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200627 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100629#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 (char_u *)&p_beval, PV_NONE,
631 {(char_u *)FALSE, (char_u *)0L}
632#else
633 (char_u *)NULL, PV_NONE,
634 {(char_u *)0L, (char_u *)0L}
635#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200636 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100637 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100638#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100639 (char_u *)&p_bevalterm, PV_NONE,
640 {(char_u *)FALSE, (char_u *)0L}
641#else
642 (char_u *)NULL, PV_NONE,
643 {(char_u *)0L, (char_u *)0L}
644#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200645 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100646 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
647#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
648 (char_u *)&p_bexpr, PV_BEXPR,
649 {(char_u *)"", (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200654 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000655 {"beautify", "bf", P_BOOL|P_VI_DEF,
656 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200657 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200658 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
659 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200660 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
662 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200663 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000665 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200666 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200669 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
671#ifdef FEAT_LINEBREAK
672 (char_u *)&p_breakat, PV_NONE,
673 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
674#else
675 (char_u *)NULL, PV_NONE,
676 {(char_u *)0L, (char_u *)0L}
677#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200678 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200679 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
680#ifdef FEAT_LINEBREAK
681 (char_u *)VAR_WIN, PV_BRI,
682 {(char_u *)FALSE, (char_u *)0L}
683#else
684 (char_u *)NULL, PV_NONE,
685 {(char_u *)0L, (char_u *)0L}
686#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200687 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200688 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
689 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200690#ifdef FEAT_LINEBREAK
691 (char_u *)VAR_WIN, PV_BRIOPT,
692 {(char_u *)"", (char_u *)NULL}
693#else
694 (char_u *)NULL, PV_NONE,
695 {(char_u *)"", (char_u *)NULL}
696#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200697 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000698 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
699#ifdef FEAT_BROWSE
700 (char_u *)&p_bsdir, PV_NONE,
701 {(char_u *)"last", (char_u *)0L}
702#else
703 (char_u *)NULL, PV_NONE,
704 {(char_u *)0L, (char_u *)0L}
705#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200706 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000708 (char_u *)&p_bh, PV_BH,
709 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200710 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000711 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
712 (char_u *)&p_bl, PV_BL,
713 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200714 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 (char_u *)&p_bt, PV_BT,
717 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200718 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200719 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 (char_u *)&p_cmp, PV_NONE,
721 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200722 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
724#ifdef FEAT_SEARCHPATH
725 (char_u *)&p_cdpath, PV_NONE,
726 {(char_u *)",,", (char_u *)0L}
727#else
728 (char_u *)NULL, PV_NONE,
729 {(char_u *)0L, (char_u *)0L}
730#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200731 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732 {"cedit", NULL, P_STRING,
733#ifdef FEAT_CMDWIN
734 (char_u *)&p_cedit, PV_NONE,
735 {(char_u *)"", (char_u *)CTRL_F_STR}
736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200740 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100742#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000743 (char_u *)&p_ccv, PV_NONE,
744 {(char_u *)"", (char_u *)0L}
745#else
746 (char_u *)NULL, PV_NONE,
747 {(char_u *)0L, (char_u *)0L}
748#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200749 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
751#ifdef FEAT_CINDENT
752 (char_u *)&p_cin, PV_CIN,
753#else
754 (char_u *)NULL, PV_NONE,
755#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200756 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200757 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758#ifdef FEAT_CINDENT
759 (char_u *)&p_cink, PV_CINK,
760 {(char_u *)"0{,0},0),:,0#,!^F,o,O,e", (char_u *)0L}
761#else
762 (char_u *)NULL, PV_NONE,
763 {(char_u *)0L, (char_u *)0L}
764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200765 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200766 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767#ifdef FEAT_CINDENT
768 (char_u *)&p_cino, PV_CINO,
769#else
770 (char_u *)NULL, PV_NONE,
771#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200772 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200773 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
775 (char_u *)&p_cinw, PV_CINW,
776 {(char_u *)"if,else,while,do,for,switch",
777 (char_u *)0L}
778#else
779 (char_u *)NULL, PV_NONE,
780 {(char_u *)0L, (char_u *)0L}
781#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200782 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200783 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000784#ifdef FEAT_CLIPBOARD
785 (char_u *)&p_cb, PV_NONE,
786# ifdef FEAT_XCLIPBOARD
787 {(char_u *)"autoselect,exclude:cons\\|linux",
788 (char_u *)0L}
789# else
790 {(char_u *)"", (char_u *)0L}
791# endif
792#else
793 (char_u *)NULL, PV_NONE,
794 {(char_u *)"", (char_u *)0L}
795#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200796 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000797 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
798 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200799 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000800 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
801#ifdef FEAT_CMDWIN
802 (char_u *)&p_cwh, PV_NONE,
803#else
804 (char_u *)NULL, PV_NONE,
805#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200806 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200807 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200808#ifdef FEAT_SYN_HL
809 (char_u *)VAR_WIN, PV_CC,
810#else
811 (char_u *)NULL, PV_NONE,
812#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200813 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000814 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
815 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200816 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200817 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
818 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000819#ifdef FEAT_COMMENTS
820 (char_u *)&p_com, PV_COM,
821 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
822 (char_u *)0L}
823#else
824 (char_u *)NULL, PV_NONE,
825 {(char_u *)0L, (char_u *)0L}
826#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200827 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200828 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000829#ifdef FEAT_FOLDING
830 (char_u *)&p_cms, PV_CMS,
831 {(char_u *)"/*%s*/", (char_u *)0L}
832#else
833 (char_u *)NULL, PV_NONE,
834 {(char_u *)0L, (char_u *)0L}
835#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200836 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000837 /* P_PRI_MKRC isn't needed here, optval_default()
838 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000839 {"compatible", "cp", P_BOOL|P_RALL,
840 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200841 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200842 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000843#ifdef FEAT_INS_EXPAND
844 (char_u *)&p_cpt, PV_CPT,
845 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
846#else
847 (char_u *)NULL, PV_NONE,
848 {(char_u *)0L, (char_u *)0L}
849#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200850 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200851 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200852#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200853 (char_u *)VAR_WIN, PV_COCU,
854 {(char_u *)"", (char_u *)NULL}
855#else
856 (char_u *)NULL, PV_NONE,
857 {(char_u *)NULL, (char_u *)0L}
858#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200859 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200860 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
861#ifdef FEAT_CONCEAL
862 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200863#else
864 (char_u *)NULL, PV_NONE,
865#endif
866 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200867 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000868 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
869#ifdef FEAT_COMPL_FUNC
870 (char_u *)&p_cfu, PV_CFU,
871 {(char_u *)"", (char_u *)0L}
872#else
873 (char_u *)NULL, PV_NONE,
874 {(char_u *)0L, (char_u *)0L}
875#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200876 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200877 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000878#ifdef FEAT_INS_EXPAND
879 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000880 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000881#else
882 (char_u *)NULL, PV_NONE,
883 {(char_u *)0L, (char_u *)0L}
884#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200885 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000886 {"confirm", "cf", P_BOOL|P_VI_DEF,
887#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
888 (char_u *)&p_confirm, PV_NONE,
889#else
890 (char_u *)NULL, PV_NONE,
891#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200892 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200895 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000896 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
897 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200898 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000899 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
900 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000901 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200902 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200903 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200904#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200905 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100906 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200907#else
908 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200909 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200910#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200911 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
913#ifdef FEAT_CSCOPE
914 (char_u *)&p_cspc, PV_NONE,
915#else
916 (char_u *)NULL, PV_NONE,
917#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200918 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
920#ifdef FEAT_CSCOPE
921 (char_u *)&p_csprg, PV_NONE,
922 {(char_u *)"cscope", (char_u *)0L}
923#else
924 (char_u *)NULL, PV_NONE,
925 {(char_u *)0L, (char_u *)0L}
926#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200927 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200928 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
930 (char_u *)&p_csqf, PV_NONE,
931 {(char_u *)"", (char_u *)0L}
932#else
933 (char_u *)NULL, PV_NONE,
934 {(char_u *)0L, (char_u *)0L}
935#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200936 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200937 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
938#ifdef FEAT_CSCOPE
939 (char_u *)&p_csre, PV_NONE,
940#else
941 (char_u *)NULL, PV_NONE,
942#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200943 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
945#ifdef FEAT_CSCOPE
946 (char_u *)&p_cst, PV_NONE,
947#else
948 (char_u *)NULL, PV_NONE,
949#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200950 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000951 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
952#ifdef FEAT_CSCOPE
953 (char_u *)&p_csto, PV_NONE,
954#else
955 (char_u *)NULL, PV_NONE,
956#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200957 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000958 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
959#ifdef FEAT_CSCOPE
960 (char_u *)&p_csverbose, PV_NONE,
961#else
962 (char_u *)NULL, PV_NONE,
963#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200964 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200965 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200966 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200967 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100968 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000969#ifdef FEAT_SYN_HL
970 (char_u *)VAR_WIN, PV_CUC,
971#else
972 (char_u *)NULL, PV_NONE,
973#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200974 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100975 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000976#ifdef FEAT_SYN_HL
977 (char_u *)VAR_WIN, PV_CUL,
978#else
979 (char_u *)NULL, PV_NONE,
980#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200981 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000982 {"debug", NULL, P_STRING|P_VI_DEF,
983 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200984 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200985 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000986#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000987 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000988 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000989#else
990 (char_u *)NULL, PV_NONE,
991 {(char_u *)NULL, (char_u *)0L}
992#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200993 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200996 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +0100997 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000999 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001000#else
1001 (char_u *)NULL, PV_NONE,
1002#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001003 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1005#ifdef FEAT_DIFF
1006 (char_u *)VAR_WIN, PV_DIFF,
1007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001010 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001011 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1013 (char_u *)&p_dex, PV_NONE,
1014 {(char_u *)"", (char_u *)0L}
1015#else
1016 (char_u *)NULL, PV_NONE,
1017 {(char_u *)0L, (char_u *)0L}
1018#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001019 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001020 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1021 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022#ifdef FEAT_DIFF
1023 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001024 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)"", (char_u *)NULL}
1028#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001029 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1031#ifdef FEAT_DIGRAPHS
1032 (char_u *)&p_dg, PV_NONE,
1033#else
1034 (char_u *)NULL, PV_NONE,
1035#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001036 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001037 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1038 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001040 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001041 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001042 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001043 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 (char_u *)&p_ead, PV_NONE,
1046 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001047 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1049 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001050 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001051 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001052 (char_u *)&p_emoji, PV_NONE,
1053 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001054 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001055 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 (char_u *)&p_enc, PV_NONE,
1057 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001058 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001059 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1060 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001061 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1063 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001064 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001066 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001067 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1069 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001070 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1072#ifdef FEAT_QUICKFIX
1073 (char_u *)&p_ef, PV_NONE,
1074 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1075#else
1076 (char_u *)NULL, PV_NONE,
1077 {(char_u *)NULL, (char_u *)0L}
1078#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001079 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001080 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001082 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001083 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001084#else
1085 (char_u *)NULL, PV_NONE,
1086 {(char_u *)NULL, (char_u *)0L}
1087#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001088 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {"esckeys", "ek", P_BOOL|P_VIM,
1090 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001091 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001092 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001094 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001095 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1096 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001097 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1099 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001100 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001101 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1102 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 (char_u *)&p_fenc, PV_FENC,
1104 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001105 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001106 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 (char_u *)&p_fencs, PV_NONE,
1108 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001109 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001110 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1111 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001113 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001114 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001116 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001117 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001118 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1119 (char_u *)&p_fic, PV_NONE,
1120 {
1121#ifdef CASE_INSENSITIVE_FILENAME
1122 (char_u *)TRUE,
1123#else
1124 (char_u *)FALSE,
1125#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001126 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001127 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128 (char_u *)&p_ft, PV_FT,
1129 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001130 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001131 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132 (char_u *)&p_fcs, PV_NONE,
1133 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001134 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001135 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1136 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001137 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001138 {"fkmap", "fk", P_BOOL|P_VI_DEF,
1139#ifdef FEAT_FKMAP
1140 (char_u *)&p_fkmap, PV_NONE,
1141#else
1142 (char_u *)NULL, PV_NONE,
1143#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001144 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 {"flash", "fl", P_BOOL|P_VI_DEF,
1146 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001147 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001148 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001149#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001151 {(char_u *)"", (char_u *)0L}
1152#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153 (char_u *)NULL, PV_NONE,
1154 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001155#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001156 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001157 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1158#ifdef FEAT_FOLDING
1159 (char_u *)VAR_WIN, PV_FDC,
1160 {(char_u *)FALSE, (char_u *)0L}
1161#else
1162 (char_u *)NULL, PV_NONE,
1163 {(char_u *)NULL, (char_u *)0L}
1164#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001165 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001166 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1167#ifdef FEAT_FOLDING
1168 (char_u *)VAR_WIN, PV_FEN,
1169 {(char_u *)TRUE, (char_u *)0L}
1170#else
1171 (char_u *)NULL, PV_NONE,
1172 {(char_u *)NULL, (char_u *)0L}
1173#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001174 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001175 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1176#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1177 (char_u *)VAR_WIN, PV_FDE,
1178 {(char_u *)"0", (char_u *)NULL}
1179#else
1180 (char_u *)NULL, PV_NONE,
1181 {(char_u *)NULL, (char_u *)0L}
1182#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001183 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001184 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001185#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001186 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001187 {(char_u *)"#", (char_u *)NULL}
1188#else
1189 (char_u *)NULL, PV_NONE,
1190 {(char_u *)NULL, (char_u *)0L}
1191#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001192 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001193 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001194#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001195 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001196 {(char_u *)0L, (char_u *)0L}
1197#else
1198 (char_u *)NULL, PV_NONE,
1199 {(char_u *)NULL, (char_u *)0L}
1200#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001201 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001202 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001203#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001205 {(char_u *)-1L, (char_u *)0L}
1206#else
1207 (char_u *)NULL, PV_NONE,
1208 {(char_u *)NULL, (char_u *)0L}
1209#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001210 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001211 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001212 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001213#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001215 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001216#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 (char_u *)NULL, PV_NONE,
1218 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001220 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1222#ifdef FEAT_FOLDING
1223 (char_u *)VAR_WIN, PV_FDM,
1224 {(char_u *)"manual", (char_u *)NULL}
1225#else
1226 (char_u *)NULL, PV_NONE,
1227 {(char_u *)NULL, (char_u *)0L}
1228#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001229 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001230 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1231#ifdef FEAT_FOLDING
1232 (char_u *)VAR_WIN, PV_FML,
1233 {(char_u *)1L, (char_u *)0L}
1234#else
1235 (char_u *)NULL, PV_NONE,
1236 {(char_u *)NULL, (char_u *)0L}
1237#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001238 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001239 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1240#ifdef FEAT_FOLDING
1241 (char_u *)VAR_WIN, PV_FDN,
1242 {(char_u *)20L, (char_u *)0L}
1243#else
1244 (char_u *)NULL, PV_NONE,
1245 {(char_u *)NULL, (char_u *)0L}
1246#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001247 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001248 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1249#ifdef FEAT_FOLDING
1250 (char_u *)&p_fdo, PV_NONE,
1251 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1252 (char_u *)0L}
1253#else
1254 (char_u *)NULL, PV_NONE,
1255 {(char_u *)NULL, (char_u *)0L}
1256#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001257 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001258 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1259#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1260 (char_u *)VAR_WIN, PV_FDT,
1261 {(char_u *)"foldtext()", (char_u *)NULL}
1262#else
1263 (char_u *)NULL, PV_NONE,
1264 {(char_u *)NULL, (char_u *)0L}
1265#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001266 SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001267 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001268#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001269 (char_u *)&p_fex, PV_FEX,
1270 {(char_u *)"", (char_u *)0L}
1271#else
1272 (char_u *)NULL, PV_NONE,
1273 {(char_u *)0L, (char_u *)0L}
1274#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001275 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001276 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1277 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001278 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001279 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001280 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1281 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001282 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001283 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001284 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001285 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001286 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001287 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1288#ifdef HAVE_FSYNC
1289 (char_u *)&p_fs, PV_NONE,
1290 {(char_u *)TRUE, (char_u *)0L}
1291#else
1292 (char_u *)NULL, PV_NONE,
1293 {(char_u *)FALSE, (char_u *)0L}
1294#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001295 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001296 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1297 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001298 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 {"graphic", "gr", P_BOOL|P_VI_DEF,
1300 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001301 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001302 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303#ifdef FEAT_QUICKFIX
1304 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001305 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306#else
1307 (char_u *)NULL, PV_NONE,
1308 {(char_u *)NULL, (char_u *)0L}
1309#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001310 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1312#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001313 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 {
1315# ifdef WIN3264
1316 /* may be changed to "grep -n" in os_win32.c */
1317 (char_u *)"findstr /n",
1318# else
1319# ifdef UNIX
1320 /* Add an extra file name so that grep will always
1321 * insert a file name in the match line. */
1322 (char_u *)"grep -n $* /dev/null",
1323# else
1324# ifdef VMS
1325 (char_u *)"SEARCH/NUMBERS ",
1326# else
1327 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001328# endif
1329# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332#else
1333 (char_u *)NULL, PV_NONE,
1334 {(char_u *)NULL, (char_u *)0L}
1335#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001336 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001337 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338#ifdef CURSOR_SHAPE
1339 (char_u *)&p_guicursor, PV_NONE,
1340 {
1341# ifdef FEAT_GUI
1342 (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 +01001343# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1345# endif
1346 (char_u *)0L}
1347#else
1348 (char_u *)NULL, PV_NONE,
1349 {(char_u *)NULL, (char_u *)0L}
1350#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001351 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001352 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001353#ifdef FEAT_GUI
1354 (char_u *)&p_guifont, PV_NONE,
1355 {(char_u *)"", (char_u *)0L}
1356#else
1357 (char_u *)NULL, PV_NONE,
1358 {(char_u *)NULL, (char_u *)0L}
1359#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001360 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001361 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001362#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1363 (char_u *)&p_guifontset, PV_NONE,
1364 {(char_u *)"", (char_u *)0L}
1365#else
1366 (char_u *)NULL, PV_NONE,
1367 {(char_u *)NULL, (char_u *)0L}
1368#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001369 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001370 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001371#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001372 (char_u *)&p_guifontwide, PV_NONE,
1373 {(char_u *)"", (char_u *)0L}
1374#else
1375 (char_u *)NULL, PV_NONE,
1376 {(char_u *)NULL, (char_u *)0L}
1377#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001378 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001379 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001380#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001381 (char_u *)&p_ghr, PV_NONE,
1382#else
1383 (char_u *)NULL, PV_NONE,
1384#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001385 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001387#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001388 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001389# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001390 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001391# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001392 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393# endif
1394#else
1395 (char_u *)NULL, PV_NONE,
1396 {(char_u *)NULL, (char_u *)0L}
1397#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001398 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399 {"guipty", NULL, P_BOOL|P_VI_DEF,
1400#if defined(FEAT_GUI)
1401 (char_u *)&p_guipty, PV_NONE,
1402#else
1403 (char_u *)NULL, PV_NONE,
1404#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001405 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001406 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001407#if defined(FEAT_GUI_TABLINE)
1408 (char_u *)&p_gtl, PV_NONE,
1409 {(char_u *)"", (char_u *)0L}
1410#else
1411 (char_u *)NULL, PV_NONE,
1412 {(char_u *)NULL, (char_u *)0L}
1413#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001414 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001415 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001416#if defined(FEAT_GUI_TABLINE)
1417 (char_u *)&p_gtt, PV_NONE,
1418 {(char_u *)"", (char_u *)0L}
1419#else
1420 (char_u *)NULL, PV_NONE,
1421 {(char_u *)NULL, (char_u *)0L}
1422#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001423 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001424 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1425 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001426 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1428 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001429 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001430 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001433 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001434 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435#ifdef FEAT_MULTI_LANG
1436 (char_u *)&p_hlg, PV_NONE,
1437 {(char_u *)"", (char_u *)0L}
1438#else
1439 (char_u *)NULL, PV_NONE,
1440 {(char_u *)0L, (char_u *)0L}
1441#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001442 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001443 {"hidden", "hid", P_BOOL|P_VI_DEF,
1444 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001445 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001446 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001448 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001449 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 {"history", "hi", P_NUM|P_VIM,
1451 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001452 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1454#ifdef FEAT_RIGHTLEFT
1455 (char_u *)&p_hkmap, PV_NONE,
1456#else
1457 (char_u *)NULL, PV_NONE,
1458#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001459 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001460 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1461#ifdef FEAT_RIGHTLEFT
1462 (char_u *)&p_hkmapp, PV_NONE,
1463#else
1464 (char_u *)NULL, PV_NONE,
1465#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001466 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1468 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001469 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470 {"icon", NULL, P_BOOL|P_VI_DEF,
1471#ifdef FEAT_TITLE
1472 (char_u *)&p_icon, PV_NONE,
1473#else
1474 (char_u *)NULL, PV_NONE,
1475#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001476 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001477 {"iconstring", NULL, P_STRING|P_VI_DEF,
1478#ifdef FEAT_TITLE
1479 (char_u *)&p_iconstring, PV_NONE,
1480#else
1481 (char_u *)NULL, PV_NONE,
1482#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001483 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1485 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001486 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001487 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001488#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001489 (char_u *)&p_imaf, PV_NONE,
1490 {(char_u *)"", (char_u *)NULL}
1491# else
1492 (char_u *)NULL, PV_NONE,
1493 {(char_u *)NULL, (char_u *)0L}
1494# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001495 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001496 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001497#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 (char_u *)&p_imak, PV_NONE,
1499#else
1500 (char_u *)NULL, PV_NONE,
1501#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001502 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001505 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001506 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508#ifdef __sgi
1509 {(char_u *)TRUE, (char_u *)0L}
1510#else
1511 {(char_u *)FALSE, (char_u *)0L}
1512#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001513 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514 {"iminsert", "imi", P_NUM|P_VI_DEF,
1515 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001516 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001517 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518 {"imsearch", "ims", P_NUM|P_VI_DEF,
1519 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001520 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001521 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001522 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001523#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001524 (char_u *)&p_imsf, PV_NONE,
1525 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001526#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001527 (char_u *)NULL, PV_NONE,
1528 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001529#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001530 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001531 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1532#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1533 (char_u *)&p_imst, PV_NONE,
1534 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1535#else
1536 (char_u *)NULL, PV_NONE,
1537 {(char_u *)0L, (char_u *)0L}
1538#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001539 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001540 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1541#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001542 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1544#else
1545 (char_u *)NULL, PV_NONE,
1546 {(char_u *)0L, (char_u *)0L}
1547#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001548 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1550#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1551 (char_u *)&p_inex, PV_INEX,
1552 {(char_u *)"", (char_u *)0L}
1553#else
1554 (char_u *)NULL, PV_NONE,
1555 {(char_u *)0L, (char_u *)0L}
1556#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001557 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001558 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1559 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001560 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1562#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1563 (char_u *)&p_inde, PV_INDE,
1564 {(char_u *)"", (char_u *)0L}
1565#else
1566 (char_u *)NULL, PV_NONE,
1567 {(char_u *)0L, (char_u *)0L}
1568#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001569 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001570 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001571#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1572 (char_u *)&p_indk, PV_INDK,
1573 {(char_u *)"0{,0},:,0#,!^F,o,O,e", (char_u *)0L}
1574#else
1575 (char_u *)NULL, PV_NONE,
1576 {(char_u *)0L, (char_u *)0L}
1577#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001578 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579 {"infercase", "inf", P_BOOL|P_VI_DEF,
1580 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001581 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001582 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1583 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001584 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1586 (char_u *)&p_isf, PV_NONE,
1587 {
1588#ifdef BACKSLASH_IN_FILENAME
1589 /* Excluded are: & and ^ are special in cmd.exe
1590 * ( and ) are used in text separating fnames */
1591 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1592#else
1593# ifdef AMIGA
1594 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1595# else
1596# ifdef VMS
1597 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1598# else /* UNIX et al. */
1599# ifdef EBCDIC
1600 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1601# else
1602 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1603# endif
1604# endif
1605# endif
1606#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001607 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001608 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1609 (char_u *)&p_isi, PV_NONE,
1610 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001611#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001612 (char_u *)"@,48-57,_,128-167,224-235",
1613#else
1614# ifdef EBCDIC
1615 /* TODO: EBCDIC Check this! @ == isalpha()*/
1616 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1617 "112-120,128,140-142,156,158,172,"
1618 "174,186,191,203-207,219-225,235-239,"
1619 "251-254",
1620# else
1621 (char_u *)"@,48-57,_,192-255",
1622# endif
1623#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001624 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001625 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1626 (char_u *)&p_isk, PV_ISK,
1627 {
1628#ifdef EBCDIC
1629 (char_u *)"@,240-249,_",
1630 /* TODO: EBCDIC Check this! @ == isalpha()*/
1631 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1632 "112-120,128,140-142,156,158,172,"
1633 "174,186,191,203-207,219-225,235-239,"
1634 "251-254",
1635#else
1636 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001637# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001638 (char_u *)"@,48-57,_,128-167,224-235"
1639# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001640 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641# endif
1642#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001643 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1645 (char_u *)&p_isp, PV_NONE,
1646 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001647#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648 (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 Moolenaarf29c1c62018-09-10 21:05:02 +02001657 (char_u *)0L} SCTX_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 Moolenaarf29c1c62018-09-10 21:05:02 +02001660 {(char_u *)TRUE, (char_u *)0L} SCTX_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 Moolenaarf29c1c62018-09-10 21:05:02 +02001669 SCTX_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 Moolenaarf29c1c62018-09-10 21:05:02 +02001678 SCTX_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 Moolenaarf29c1c62018-09-10 21:05:02 +02001681 {(char_u *)"", (char_u *)0L} SCTX_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 Moolenaarf29c1c62018-09-10 21:05:02 +02001698 (char_u *)0L} SCTX_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,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001702 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703#else
1704 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001705 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001707 SCTX_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 Moolenaarf29c1c62018-09-10 21:05:02 +02001714 {(char_u *)"", (char_u *)0L} SCTX_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
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001721 {(char_u *)FALSE, (char_u *)0L} SCTX_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 Moolenaarf29c1c62018-09-10 21:05:02 +02001728 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001729 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001730 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001731 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1733 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001734 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1736#ifdef FEAT_LINEBREAK
1737 (char_u *)VAR_WIN, PV_LBR,
1738#else
1739 (char_u *)NULL, PV_NONE,
1740#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001741 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001742 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1743 (char_u *)&Rows, PV_NONE,
1744 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001745#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 (char_u *)25L,
1747#else
1748 (char_u *)24L,
1749#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001750 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1752#ifdef FEAT_GUI
1753 (char_u *)&p_linespace, PV_NONE,
1754#else
1755 (char_u *)NULL, PV_NONE,
1756#endif
1757#ifdef FEAT_GUI_W32
1758 {(char_u *)1L, (char_u *)0L}
1759#else
1760 {(char_u *)0L, (char_u *)0L}
1761#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001762 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 {"lisp", NULL, P_BOOL|P_VI_DEF,
1764#ifdef FEAT_LISP
1765 (char_u *)&p_lisp, PV_LISP,
1766#else
1767 (char_u *)NULL, PV_NONE,
1768#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001769 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001770 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001771#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001772 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1774#else
1775 (char_u *)NULL, PV_NONE,
1776 {(char_u *)"", (char_u *)0L}
1777#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001778 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1780 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001781 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001782 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001784 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1786 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001787 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001788 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001789#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001790 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001791 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001792#else
1793 (char_u *)NULL, PV_NONE,
1794 {(char_u *)"", (char_u *)0L}
1795#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001796 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001797 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001798#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001799 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001800 {(char_u *)TRUE, (char_u *)0L}
1801#else
1802 (char_u *)NULL, PV_NONE,
1803 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001804#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001805 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001806 {"magic", NULL, P_BOOL|P_VI_DEF,
1807 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001808 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001809 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810#ifdef FEAT_QUICKFIX
1811 (char_u *)&p_mef, PV_NONE,
1812 {(char_u *)"", (char_u *)0L}
1813#else
1814 (char_u *)NULL, PV_NONE,
1815 {(char_u *)NULL, (char_u *)0L}
1816#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001817 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001818 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001819 (char_u *)&p_menc, PV_MENC,
1820 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001821 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001822 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1823#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001824 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825# ifdef VMS
1826 {(char_u *)"MMS", (char_u *)0L}
1827# else
1828 {(char_u *)"make", (char_u *)0L}
1829# endif
1830#else
1831 (char_u *)NULL, PV_NONE,
1832 {(char_u *)NULL, (char_u *)0L}
1833#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001834 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001835 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001837 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001838 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 {"matchtime", "mat", P_NUM|P_VI_DEF,
1840 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001841 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001842 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001843 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001844 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1846#ifdef FEAT_EVAL
1847 (char_u *)&p_mfd, PV_NONE,
1848#else
1849 (char_u *)NULL, PV_NONE,
1850#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001851 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001852 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1853 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001854 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 {"maxmem", "mm", P_NUM|P_VI_DEF,
1856 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001857 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001858 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001859 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1860 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001861 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001862 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1863 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001864 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001865 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 {"menuitems", "mis", P_NUM|P_VI_DEF,
1867#ifdef FEAT_MENU
1868 (char_u *)&p_mis, PV_NONE,
1869#else
1870 (char_u *)NULL, PV_NONE,
1871#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001872 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001873 {"mesg", NULL, P_BOOL|P_VI_DEF,
1874 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001875 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001876 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001877#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001878 (char_u *)&p_msm, PV_NONE,
1879 {(char_u *)"460000,2000,500", (char_u *)0L}
1880#else
1881 (char_u *)NULL, PV_NONE,
1882 {(char_u *)0L, (char_u *)0L}
1883#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001884 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001885 {"modeline", "ml", P_BOOL|P_VIM,
1886 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001887 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"modelines", "mls", P_NUM|P_VI_DEF,
1889 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001890 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1892 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001893 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1895 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001896 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"more", NULL, P_BOOL|P_VIM,
1898 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001899 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1901 (char_u *)&p_mouse, PV_NONE,
1902 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001903#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001904 (char_u *)"a",
1905#else
1906 (char_u *)"",
1907#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001908 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1910#ifdef FEAT_GUI
1911 (char_u *)&p_mousef, PV_NONE,
1912#else
1913 (char_u *)NULL, PV_NONE,
1914#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001915 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1917#ifdef FEAT_GUI
1918 (char_u *)&p_mh, PV_NONE,
1919#else
1920 (char_u *)NULL, PV_NONE,
1921#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001922 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1924 (char_u *)&p_mousem, PV_NONE,
1925 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001926#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927 (char_u *)"popup",
1928#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001929# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001930 (char_u *)"popup_setpos",
1931# else
1932 (char_u *)"extend",
1933# endif
1934#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001935 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001936 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937#ifdef FEAT_MOUSESHAPE
1938 (char_u *)&p_mouseshape, PV_NONE,
1939 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1940#else
1941 (char_u *)NULL, PV_NONE,
1942 {(char_u *)NULL, (char_u *)0L}
1943#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001944 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1946 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001947 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001948 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1949#if defined(DYNAMIC_MZSCHEME)
1950 (char_u *)&p_mzschemedll, PV_NONE,
1951 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1952#else
1953 (char_u *)NULL, PV_NONE,
1954 {(char_u *)"", (char_u *)0L}
1955#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001956 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001957 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1958#if defined(DYNAMIC_MZSCHEME)
1959 (char_u *)&p_mzschemegcdll, PV_NONE,
1960 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1961#else
1962 (char_u *)NULL, PV_NONE,
1963 {(char_u *)"", (char_u *)0L}
1964#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001965 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001966 {"mzquantum", "mzq", P_NUM,
1967#ifdef FEAT_MZSCHEME
1968 (char_u *)&p_mzq, PV_NONE,
1969#else
1970 (char_u *)NULL, PV_NONE,
1971#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001972 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001973 {"novice", NULL, P_BOOL|P_VI_DEF,
1974 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001975 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001976 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001977 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001978 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001979 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1981 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001982 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001983 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1984#ifdef FEAT_LINEBREAK
1985 (char_u *)VAR_WIN, PV_NUW,
1986#else
1987 (char_u *)NULL, PV_NONE,
1988#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001989 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001990 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001991#ifdef FEAT_COMPL_FUNC
1992 (char_u *)&p_ofu, PV_OFU,
1993 {(char_u *)"", (char_u *)0L}
1994#else
1995 (char_u *)NULL, PV_NONE,
1996 {(char_u *)0L, (char_u *)0L}
1997#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001998 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001999 {"open", NULL, P_BOOL|P_VI_DEF,
2000 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002001 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002002 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002003#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002004 (char_u *)&p_odev, PV_NONE,
2005#else
2006 (char_u *)NULL, PV_NONE,
2007#endif
2008 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002009 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002010 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2011 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002012 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002013 {"optimize", "opt", P_BOOL|P_VI_DEF,
2014 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002015 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002017 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002018 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002019 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2020 |P_SECURE,
2021 (char_u *)&p_pp, PV_NONE,
2022 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002023 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 {"paragraphs", "para", P_STRING|P_VI_DEF,
2025 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002026 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002027 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002028 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002029 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002030 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2032 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002033 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2035#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2036 (char_u *)&p_pex, PV_NONE,
2037 {(char_u *)"", (char_u *)0L}
2038#else
2039 (char_u *)NULL, PV_NONE,
2040 {(char_u *)0L, (char_u *)0L}
2041#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002042 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002043 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002044 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002045 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002047 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002048 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002049#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002050 (char_u *)".,,",
2051#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002054 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002055 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002056#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002057 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002058 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002059#else
2060 (char_u *)NULL, PV_NONE,
2061 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002062#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002063 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002064 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2065 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002066 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002067 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002068#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002069 (char_u *)&p_pvh, PV_NONE,
2070#else
2071 (char_u *)NULL, PV_NONE,
2072#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002073 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002074 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002075#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076 (char_u *)VAR_WIN, PV_PVW,
2077#else
2078 (char_u *)NULL, PV_NONE,
2079#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002080 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002081 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002082#ifdef FEAT_PRINTER
2083 (char_u *)&p_pdev, PV_NONE,
2084 {(char_u *)"", (char_u *)0L}
2085#else
2086 (char_u *)NULL, PV_NONE,
2087 {(char_u *)NULL, (char_u *)0L}
2088#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002089 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002090 {"printencoding", "penc", P_STRING|P_VI_DEF,
2091#ifdef FEAT_POSTSCRIPT
2092 (char_u *)&p_penc, PV_NONE,
2093 {(char_u *)"", (char_u *)0L}
2094#else
2095 (char_u *)NULL, PV_NONE,
2096 {(char_u *)NULL, (char_u *)0L}
2097#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002098 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002099 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100#ifdef FEAT_POSTSCRIPT
2101 (char_u *)&p_pexpr, PV_NONE,
2102 {(char_u *)"", (char_u *)0L}
2103#else
2104 (char_u *)NULL, PV_NONE,
2105 {(char_u *)NULL, (char_u *)0L}
2106#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002107 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"printfont", "pfn", P_STRING|P_VI_DEF,
2109#ifdef FEAT_PRINTER
2110 (char_u *)&p_pfn, PV_NONE,
2111 {
2112# ifdef MSWIN
2113 (char_u *)"Courier_New:h10",
2114# else
2115 (char_u *)"courier",
2116# endif
2117 (char_u *)0L}
2118#else
2119 (char_u *)NULL, PV_NONE,
2120 {(char_u *)NULL, (char_u *)0L}
2121#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002122 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002123 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2124#ifdef FEAT_PRINTER
2125 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002126 /* untranslated to avoid problems when 'encoding'
2127 * is changed */
2128 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002129#else
2130 (char_u *)NULL, PV_NONE,
2131 {(char_u *)NULL, (char_u *)0L}
2132#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002133 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002134 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002135#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002136 (char_u *)&p_pmcs, PV_NONE,
2137 {(char_u *)"", (char_u *)0L}
2138#else
2139 (char_u *)NULL, PV_NONE,
2140 {(char_u *)NULL, (char_u *)0L}
2141#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002142 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002143 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002144#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002145 (char_u *)&p_pmfn, PV_NONE,
2146 {(char_u *)"", (char_u *)0L}
2147#else
2148 (char_u *)NULL, PV_NONE,
2149 {(char_u *)NULL, (char_u *)0L}
2150#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002151 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002152 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002153#ifdef FEAT_PRINTER
2154 (char_u *)&p_popt, PV_NONE,
2155 {(char_u *)"", (char_u *)0L}
2156#else
2157 (char_u *)NULL, PV_NONE,
2158 {(char_u *)NULL, (char_u *)0L}
2159#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002160 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002161 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002162 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002163 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002164 {"pumheight", "ph", P_NUM|P_VI_DEF,
2165#ifdef FEAT_INS_EXPAND
2166 (char_u *)&p_ph, PV_NONE,
2167#else
2168 (char_u *)NULL, PV_NONE,
2169#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002170 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002171 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2172#ifdef FEAT_INS_EXPAND
2173 (char_u *)&p_pw, PV_NONE,
2174#else
2175 (char_u *)NULL, PV_NONE,
2176#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002177 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002178 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002179#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002180 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002181 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002182#else
2183 (char_u *)NULL, PV_NONE,
2184 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002185#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002186 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002187 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2188#if defined(FEAT_PYTHON3)
2189 (char_u *)&p_py3home, PV_NONE,
2190 {(char_u *)"", (char_u *)0L}
2191#else
2192 (char_u *)NULL, PV_NONE,
2193 {(char_u *)NULL, (char_u *)0L}
2194#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002195 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002196 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002197#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002198 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002199 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002203#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002204 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002205 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2206#if defined(FEAT_PYTHON)
2207 (char_u *)&p_pyhome, PV_NONE,
2208 {(char_u *)"", (char_u *)0L}
2209#else
2210 (char_u *)NULL, PV_NONE,
2211 {(char_u *)NULL, (char_u *)0L}
2212#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002213 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002214 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2215#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2216 (char_u *)&p_pyx, PV_NONE,
2217#else
2218 (char_u *)NULL, PV_NONE,
2219#endif
2220 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002221 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002222 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2223#ifdef FEAT_TEXTOBJ
2224 (char_u *)&p_qe, PV_QE,
2225 {(char_u *)"\\", (char_u *)0L}
2226#else
2227 (char_u *)NULL, PV_NONE,
2228 {(char_u *)NULL, (char_u *)0L}
2229#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002230 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002231 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2232 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002233 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"redraw", NULL, P_BOOL|P_VI_DEF,
2235 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002236 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002237 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2238#ifdef FEAT_RELTIME
2239 (char_u *)&p_rdt, PV_NONE,
2240#else
2241 (char_u *)NULL, PV_NONE,
2242#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002243 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002244 {"regexpengine", "re", P_NUM|P_VI_DEF,
2245 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002246 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002247 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2248 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002249 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002250 {"remap", NULL, P_BOOL|P_VI_DEF,
2251 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002252 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002253 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002254#ifdef FEAT_RENDER_OPTIONS
2255 (char_u *)&p_rop, PV_NONE,
2256 {(char_u *)"", (char_u *)0L}
2257#else
2258 (char_u *)NULL, PV_NONE,
2259 {(char_u *)NULL, (char_u *)0L}
2260#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002261 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002262 {"report", NULL, P_NUM|P_VI_DEF,
2263 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002264 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
2266#ifdef WIN3264
2267 (char_u *)&p_rs, PV_NONE,
2268#else
2269 (char_u *)NULL, PV_NONE,
2270#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002271 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2273#ifdef FEAT_RIGHTLEFT
2274 (char_u *)&p_ri, PV_NONE,
2275#else
2276 (char_u *)NULL, PV_NONE,
2277#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002278 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2280#ifdef FEAT_RIGHTLEFT
2281 (char_u *)VAR_WIN, PV_RL,
2282#else
2283 (char_u *)NULL, PV_NONE,
2284#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002285 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002286 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2287#ifdef FEAT_RIGHTLEFT
2288 (char_u *)VAR_WIN, PV_RLC,
2289 {(char_u *)"search", (char_u *)NULL}
2290#else
2291 (char_u *)NULL, PV_NONE,
2292 {(char_u *)NULL, (char_u *)0L}
2293#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002294 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002295 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002296#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002297 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002298 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002299#else
2300 (char_u *)NULL, PV_NONE,
2301 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002302#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002303 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2305#ifdef FEAT_CMDL_INFO
2306 (char_u *)&p_ru, PV_NONE,
2307#else
2308 (char_u *)NULL, PV_NONE,
2309#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002310 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2312#ifdef FEAT_STL_OPT
2313 (char_u *)&p_ruf, PV_NONE,
2314#else
2315 (char_u *)NULL, PV_NONE,
2316#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002317 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002318 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2319 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002320 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002321 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002322 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2324 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002325 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002328 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2330 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002331 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
2333 (char_u *)&p_so, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002334 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002335 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 (char_u *)&p_sbo, PV_NONE,
2337 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002338 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 {"sections", "sect", P_STRING|P_VI_DEF,
2340 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002341 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002342 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2344 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002345 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002349 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002350 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002351 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002352 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002353 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354#ifdef FEAT_SESSION
2355 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002356 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 (char_u *)0L}
2358#else
2359 (char_u *)NULL, PV_NONE,
2360 {(char_u *)0L, (char_u *)0L}
2361#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002362 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2364 (char_u *)&p_sh, PV_NONE,
2365 {
2366#ifdef VMS
2367 (char_u *)"-",
2368#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002369# if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002371# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373# endif
2374#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002375 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2377 (char_u *)&p_shcf, PV_NONE,
2378 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002379#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 (char_u *)"/c",
2381#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002384 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2386#ifdef FEAT_QUICKFIX
2387 (char_u *)&p_sp, PV_NONE,
2388 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002389#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391#else
2392 (char_u *)">",
2393#endif
2394 (char_u *)0L}
2395#else
2396 (char_u *)NULL, PV_NONE,
2397 {(char_u *)0L, (char_u *)0L}
2398#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002399 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2401 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002402 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2404 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002405 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2407#ifdef BACKSLASH_IN_FILENAME
2408 (char_u *)&p_ssl, PV_NONE,
2409#else
2410 (char_u *)NULL, PV_NONE,
2411#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002412 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002413 {"shelltemp", "stmp", P_BOOL,
2414 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002415 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"shelltype", "st", P_NUM|P_VI_DEF,
2417#ifdef AMIGA
2418 (char_u *)&p_st, PV_NONE,
2419#else
2420 (char_u *)NULL, PV_NONE,
2421#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002422 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2424 (char_u *)&p_sxq, PV_NONE,
2425 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002426#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002427 (char_u *)"\"",
2428#else
2429 (char_u *)"",
2430#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002431 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002432 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2433 (char_u *)&p_sxe, PV_NONE,
2434 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002435#if defined(WIN3264)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002436 (char_u *)"\"&|<>()@^",
2437#else
2438 (char_u *)"",
2439#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002440 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2442 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002443 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2445 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002446 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2448 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002449 {(char_u *)"", (char_u *)"filnxtToO"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002450 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002452 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002453 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2455#ifdef FEAT_LINEBREAK
2456 (char_u *)&p_sbr, PV_NONE,
2457#else
2458 (char_u *)NULL, PV_NONE,
2459#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002460 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"showcmd", "sc", P_BOOL|P_VIM,
2462#ifdef FEAT_CMDL_INFO
2463 (char_u *)&p_sc, PV_NONE,
2464#else
2465 (char_u *)NULL, PV_NONE,
2466#endif
2467 {(char_u *)FALSE,
2468#ifdef UNIX
2469 (char_u *)FALSE
2470#else
2471 (char_u *)TRUE
2472#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002473 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002474 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2475 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002476 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2478 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002479 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"showmode", "smd", P_BOOL|P_VIM,
2481 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002482 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002483 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002484 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002485 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002486 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2487 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002488 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2490 (char_u *)&p_siso, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002491 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002492 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2493#ifdef FEAT_SIGNS
2494 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002495 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002496#else
2497 (char_u *)NULL, PV_NONE,
2498 {(char_u *)NULL, (char_u *)0L}
2499#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002500 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002501 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2502 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002503 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2505 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002506 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2508#ifdef FEAT_SMARTINDENT
2509 (char_u *)&p_si, PV_SI,
2510#else
2511 (char_u *)NULL, PV_NONE,
2512#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002513 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2515 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002516 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2518 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002519 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2521 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002522 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002523 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002524#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002525 (char_u *)VAR_WIN, PV_SPELL,
2526#else
2527 (char_u *)NULL, PV_NONE,
2528#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002529 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002530 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002531#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002532 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002533 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002534#else
2535 (char_u *)NULL, PV_NONE,
2536 {(char_u *)0L, (char_u *)0L}
2537#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002538 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002539 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2540 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002541#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002542 (char_u *)&p_spf, PV_SPF,
2543 {(char_u *)"", (char_u *)0L}
2544#else
2545 (char_u *)NULL, PV_NONE,
2546 {(char_u *)0L, (char_u *)0L}
2547#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002548 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002549 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2550 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002551#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002552 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002553 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002554#else
2555 (char_u *)NULL, PV_NONE,
2556 {(char_u *)0L, (char_u *)0L}
2557#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002558 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002559 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002560#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002561 (char_u *)&p_sps, PV_NONE,
2562 {(char_u *)"best", (char_u *)0L}
2563#else
2564 (char_u *)NULL, PV_NONE,
2565 {(char_u *)0L, (char_u *)0L}
2566#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002567 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002568 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002569 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002570 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002573 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2575 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002576 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2578#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002579 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580#else
2581 (char_u *)NULL, PV_NONE,
2582#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002583 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002584 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 (char_u *)&p_su, PV_NONE,
2586 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002587 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002588 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002589#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 (char_u *)&p_sua, PV_SUA,
2591 {(char_u *)"", (char_u *)0L}
2592#else
2593 (char_u *)NULL, PV_NONE,
2594 {(char_u *)0L, (char_u *)0L}
2595#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002596 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2598 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002599 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {"swapsync", "sws", P_STRING|P_VI_DEF,
2601 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002602 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002603 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002605 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002606 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2607#ifdef FEAT_SYN_HL
2608 (char_u *)&p_smc, PV_SMC,
2609 {(char_u *)3000L, (char_u *)0L}
2610#else
2611 (char_u *)NULL, PV_NONE,
2612 {(char_u *)0L, (char_u *)0L}
2613#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002614 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002615 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002616#ifdef FEAT_SYN_HL
2617 (char_u *)&p_syn, PV_SYN,
2618 {(char_u *)"", (char_u *)0L}
2619#else
2620 (char_u *)NULL, PV_NONE,
2621 {(char_u *)0L, (char_u *)0L}
2622#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002623 SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002624 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2625#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002626 (char_u *)&p_tal, PV_NONE,
2627#else
2628 (char_u *)NULL, PV_NONE,
2629#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002630 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002631 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002632 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002633 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2635 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002636 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2638 (char_u *)&p_tbs, PV_NONE,
2639#ifdef VMS /* binary searching doesn't appear to work on VMS */
2640 {(char_u *)0L, (char_u *)0L}
2641#else
2642 {(char_u *)TRUE, (char_u *)0L}
2643#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002644 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002645 {"tagcase", "tc", P_STRING|P_VIM,
2646 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002647 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002648 {"taglength", "tl", P_NUM|P_VI_DEF,
2649 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002650 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"tagrelative", "tr", P_BOOL|P_VIM,
2652 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002653 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002654 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002655 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002656 {
2657#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2658 (char_u *)"./tags,./TAGS,tags,TAGS",
2659#else
2660 (char_u *)"./tags,tags",
2661#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002662 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2664 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002665 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002666 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002667#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002668 (char_u *)&p_tcldll, PV_NONE,
2669 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002670#else
2671 (char_u *)NULL, PV_NONE,
2672 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002673#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002674 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2676 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002677 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2679#ifdef FEAT_ARABIC
2680 (char_u *)&p_tbidi, PV_NONE,
2681#else
2682 (char_u *)NULL, PV_NONE,
2683#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002684 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002685 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002686 (char_u *)&p_tenc, PV_NONE,
2687 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002688 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002689 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2690#ifdef FEAT_TERMGUICOLORS
2691 (char_u *)&p_tgc, PV_NONE,
2692 {(char_u *)FALSE, (char_u *)FALSE}
2693#else
2694 (char_u*)NULL, PV_NONE,
2695 {(char_u *)FALSE, (char_u *)FALSE}
2696#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002697 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002698 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2699#ifdef FEAT_TERMINAL
2700 (char_u *)VAR_WIN, PV_TWK,
2701 {(char_u *)"", (char_u *)NULL}
2702#else
2703 (char_u *)NULL, PV_NONE,
2704 {(char_u *)NULL, (char_u *)0L}
2705#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002706 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002707 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2708#ifdef FEAT_TERMINAL
2709 (char_u *)&p_twsl, PV_TWSL,
2710 {(char_u *)10000L, (char_u *)10000L}
2711#else
2712 (char_u *)NULL, PV_NONE,
2713 {(char_u *)NULL, (char_u *)0L}
2714#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002715 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002716 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2717#ifdef FEAT_TERMINAL
2718 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002719 {(char_u *)"", (char_u *)NULL}
2720#else
2721 (char_u *)NULL, PV_NONE,
2722 {(char_u *)NULL, (char_u *)0L}
2723#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002724 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002725 {"terse", NULL, P_BOOL|P_VI_DEF,
2726 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002727 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002728 {"textauto", "ta", P_BOOL|P_VIM,
2729 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002730 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002731 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002732 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2733 (char_u *)&p_tx, PV_TX,
2734 {
2735#ifdef USE_CRNL
2736 (char_u *)TRUE,
2737#else
2738 (char_u *)FALSE,
2739#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002740 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002741 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002742 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002743 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002744 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002745#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002746 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002747#else
2748 (char_u *)NULL, PV_NONE,
2749#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002750 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002751 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2752 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002753 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002754 {"timeout", "to", P_BOOL|P_VI_DEF,
2755 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002756 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2758 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002759 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"title", NULL, P_BOOL|P_VI_DEF,
2761#ifdef FEAT_TITLE
2762 (char_u *)&p_title, PV_NONE,
2763#else
2764 (char_u *)NULL, PV_NONE,
2765#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002766 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"titlelen", NULL, P_NUM|P_VI_DEF,
2768#ifdef FEAT_TITLE
2769 (char_u *)&p_titlelen, PV_NONE,
2770#else
2771 (char_u *)NULL, PV_NONE,
2772#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002773 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002774 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775#ifdef FEAT_TITLE
2776 (char_u *)&p_titleold, PV_NONE,
2777 {(char_u *)N_("Thanks for flying Vim"),
2778 (char_u *)0L}
2779#else
2780 (char_u *)NULL, PV_NONE,
2781 {(char_u *)0L, (char_u *)0L}
2782#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002783 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"titlestring", NULL, P_STRING|P_VI_DEF,
2785#ifdef FEAT_TITLE
2786 (char_u *)&p_titlestring, PV_NONE,
2787#else
2788 (char_u *)NULL, PV_NONE,
2789#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002790 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002791 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002792#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002793 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002794 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002795#else
2796 (char_u *)NULL, PV_NONE,
2797 {(char_u *)0L, (char_u *)0L}
2798#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002799 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002801#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002803 {(char_u *)"small", (char_u *)0L}
2804#else
2805 (char_u *)NULL, PV_NONE,
2806 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002808 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2810 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002811 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002812 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2813 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002814 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002815 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2816 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002817 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2819 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002820 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2822#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2823 (char_u *)&p_ttym, PV_NONE,
2824#else
2825 (char_u *)NULL, PV_NONE,
2826#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002827 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2829 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002830 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2832 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002833 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002834 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2835 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002836#ifdef FEAT_PERSISTENT_UNDO
2837 (char_u *)&p_udir, PV_NONE,
2838 {(char_u *)".", (char_u *)0L}
2839#else
2840 (char_u *)NULL, PV_NONE,
2841 {(char_u *)0L, (char_u *)0L}
2842#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002843 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002844 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2845#ifdef FEAT_PERSISTENT_UNDO
2846 (char_u *)&p_udf, PV_UDF,
2847#else
2848 (char_u *)NULL, PV_NONE,
2849#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002850 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002851 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002852 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002854#if defined(UNIX) || defined(WIN3264) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 (char_u *)1000L,
2856#else
2857 (char_u *)100L,
2858#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002859 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002860 {"undoreload", "ur", P_NUM|P_VI_DEF,
2861 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002862 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"updatecount", "uc", P_NUM|P_VI_DEF,
2864 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002865 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"updatetime", "ut", P_NUM|P_VI_DEF,
2867 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002868 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002869 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2870#ifdef FEAT_VARTABS
2871 (char_u *)&p_vsts, PV_VSTS,
2872 {(char_u *)"", (char_u *)0L}
2873#else
2874 (char_u *)NULL, PV_NONE,
2875 {(char_u *)"", (char_u *)NULL}
2876#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002877 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002878 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2879#ifdef FEAT_VARTABS
2880 (char_u *)&p_vts, PV_VTS,
2881 {(char_u *)"", (char_u *)0L}
2882#else
2883 (char_u *)NULL, PV_NONE,
2884 {(char_u *)"", (char_u *)NULL}
2885#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002886 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"verbose", "vbs", P_NUM|P_VI_DEF,
2888 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002889 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002890 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2891 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002892 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002893 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2894#ifdef FEAT_SESSION
2895 (char_u *)&p_vdir, PV_NONE,
2896 {(char_u *)DFLT_VDIR, (char_u *)0L}
2897#else
2898 (char_u *)NULL, PV_NONE,
2899 {(char_u *)0L, (char_u *)0L}
2900#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002901 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002902 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002903#ifdef FEAT_SESSION
2904 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002905 {(char_u *)"folds,options,cursor,curdir",
2906 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002907#else
2908 (char_u *)NULL, PV_NONE,
2909 {(char_u *)0L, (char_u *)0L}
2910#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002911 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002912 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002913#ifdef FEAT_VIMINFO
2914 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002915#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002916 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917#else
2918# ifdef AMIGA
2919 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002920 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002921# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002922 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002923# endif
2924#endif
2925#else
2926 (char_u *)NULL, PV_NONE,
2927 {(char_u *)0L, (char_u *)0L}
2928#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002929 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002930 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2931 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002932#ifdef FEAT_VIMINFO
2933 (char_u *)&p_viminfofile, PV_NONE,
2934 {(char_u *)"", (char_u *)0L}
2935#else
2936 (char_u *)NULL, PV_NONE,
2937 {(char_u *)0L, (char_u *)0L}
2938#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002939 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002940 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2941 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942#ifdef FEAT_VIRTUALEDIT
2943 (char_u *)&p_ve, PV_NONE,
2944 {(char_u *)"", (char_u *)""}
2945#else
2946 (char_u *)NULL, PV_NONE,
2947 {(char_u *)0L, (char_u *)0L}
2948#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002949 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002950 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2951 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002952 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953 {"w300", NULL, P_NUM|P_VI_DEF,
2954 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002955 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956 {"w1200", NULL, P_NUM|P_VI_DEF,
2957 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002958 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002959 {"w9600", NULL, P_NUM|P_VI_DEF,
2960 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002961 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002962 {"warn", NULL, P_BOOL|P_VI_DEF,
2963 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002964 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002965 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2966 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002967 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002968 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002970 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 {"wildchar", "wc", P_NUM|P_VIM,
2972 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002973 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002974 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002975 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002977 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002978 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979#ifdef FEAT_WILDIGN
2980 (char_u *)&p_wig, PV_NONE,
2981#else
2982 (char_u *)NULL, PV_NONE,
2983#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002984 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002985 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2986 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002987 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2989#ifdef FEAT_WILDMENU
2990 (char_u *)&p_wmnu, PV_NONE,
2991#else
2992 (char_u *)NULL, PV_NONE,
2993#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002994 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002995 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002997 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002998 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2999#ifdef FEAT_CMDL_COMPL
3000 (char_u *)&p_wop, PV_NONE,
3001 {(char_u *)"", (char_u *)0L}
3002#else
3003 (char_u *)NULL, PV_NONE,
3004 {(char_u *)NULL, (char_u *)0L}
3005#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003006 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3008#ifdef FEAT_WAK
3009 (char_u *)&p_wak, PV_NONE,
3010 {(char_u *)"menu", (char_u *)0L}
3011#else
3012 (char_u *)NULL, PV_NONE,
3013 {(char_u *)NULL, (char_u *)0L}
3014#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003015 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003017 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003018 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003019 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003020 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003021 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003022 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003024 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003025 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003026 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003027 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003028 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003030 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003031 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003033 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003034 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003035#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003036 (char_u *)&p_winptydll, PV_NONE, {
3037# ifdef _WIN64
3038 (char_u *)"winpty64.dll",
3039# else
3040 (char_u *)"winpty32.dll",
3041# endif
3042 (char_u *)0L}
3043#else
3044 (char_u *)NULL, PV_NONE,
3045 {(char_u *)0L, (char_u *)0L}
3046#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003047 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003050 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3052 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003053 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3055 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003056 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3058 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003059 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003060 {"write", NULL, P_BOOL|P_VI_DEF,
3061 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003062 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 {"writeany", "wa", P_BOOL|P_VI_DEF,
3064 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003065 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3067 (char_u *)&p_wb, PV_NONE,
3068 {
3069#ifdef FEAT_WRITEBACKUP
3070 (char_u *)TRUE,
3071#else
3072 (char_u *)FALSE,
3073#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003074 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 {"writedelay", "wd", P_NUM|P_VI_DEF,
3076 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003077 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078
3079/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003080#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003082 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083
3084 p_term("t_AB", T_CAB)
3085 p_term("t_AF", T_CAF)
3086 p_term("t_AL", T_CAL)
3087 p_term("t_al", T_AL)
3088 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003089 p_term("t_BE", T_BE)
3090 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 p_term("t_cd", T_CD)
3092 p_term("t_ce", T_CE)
3093 p_term("t_cl", T_CL)
3094 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003095 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 p_term("t_Co", T_CCO)
3097 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003098 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 p_term("t_da", T_DA)
3102 p_term("t_db", T_DB)
3103 p_term("t_DL", T_CDL)
3104 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003105 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003106 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003108 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 p_term("t_IE", T_CIE)
3110 p_term("t_IS", T_CIS)
3111 p_term("t_ke", T_KE)
3112 p_term("t_ks", T_KS)
3113 p_term("t_le", T_LE)
3114 p_term("t_mb", T_MB)
3115 p_term("t_md", T_MD)
3116 p_term("t_me", T_ME)
3117 p_term("t_mr", T_MR)
3118 p_term("t_ms", T_MS)
3119 p_term("t_nd", T_ND)
3120 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003121 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003122 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003123 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003124 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003125 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003126 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003127 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003128 p_term("t_RV", T_CRV)
3129 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003130 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003132 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003133 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003134 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003135 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003137 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003138 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003139 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003140 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_te", T_TE)
3142 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003143 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003144 p_term("t_ts", T_TS)
3145 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 p_term("t_ue", T_UE)
3147 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003148 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_vb", T_VB)
3150 p_term("t_ve", T_VE)
3151 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003152 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003153 p_term("t_vs", T_VS)
3154 p_term("t_WP", T_CWP)
3155 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003156 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_xs", T_XS)
3158 p_term("t_ZH", T_CZH)
3159 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003160 p_term("t_8f", T_8F)
3161 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162
3163/* terminal key codes are not in here */
3164
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003165 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003166 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167};
3168
3169#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3170
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003173static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003174static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003175#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003176static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003177#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003178#ifdef FEAT_CMDL_COMPL
3179static char *(p_wop_values[]) = {"tagfile", NULL};
3180#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003181#ifdef FEAT_WAK
3182static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3183#endif
3184static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3186static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188#ifdef FEAT_BROWSE
3189static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3190#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003192static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003194static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003195static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3197#ifdef FEAT_FOLDING
3198static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003199# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003201# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003202 NULL};
3203static char *(p_fcl_values[]) = {"all", NULL};
3204#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003205#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003206static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003207#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003208#ifdef FEAT_SIGNS
3209static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003212static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003213static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003214static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003215static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003216static char_u *option_expand(int opt_idx, char_u *val);
3217static void didset_options(void);
3218static void didset_options2(void);
3219static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003220#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003221static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003222#else
3223# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3224#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003225static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003226static char *did_set_string_option(int opt_idx, char_u **varp, int new_value_alloced, char_u *oldval, char *errbuf, int opt_flags, int *value_checked);
3227static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003228#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003229static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003231#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003232static char *did_set_spell_option(int is_spellfile);
3233static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003234#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003235#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003236static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003237#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003238static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3239static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003240static void check_redraw(long_u flags);
3241static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003242static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003243static void showoptions(int all, int opt_flags);
3244static int optval_default(struct vimoption *, char_u *varp);
3245static void showoneopt(struct vimoption *, int opt_flags);
3246static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, int expand);
3247static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3248static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3249static int istermoption(struct vimoption *);
3250static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3251static char_u *get_varp(struct vimoption *);
3252static void option_value2string(struct vimoption *, int opt_flags);
3253static void check_winopt(winopt_T *wop);
3254static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003255#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003256static void langmap_init(void);
3257static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003259static void paste_option_changed(void);
3260static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003262static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003264static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3265static int check_opt_strings(char_u *val, char **values, int);
3266static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003267#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003269#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003270
3271/*
3272 * Initialize the options, first part.
3273 *
3274 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003275 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276 */
3277 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003278set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279{
3280 char_u *p;
3281 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003282 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003283
3284#ifdef FEAT_LANGMAP
3285 langmap_init();
3286#endif
3287
3288 /* Be Vi compatible by default */
3289 p_cp = TRUE;
3290
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003291 /* Use POSIX compatibility when $VIM_POSIX is set. */
3292 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003293 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003294 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003295 set_string_default("shm", (char_u *)"A");
3296 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003297
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298 /*
3299 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003300 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003301 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003302 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003303#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003304 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003306 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307# endif
3308#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003309 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003310 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003311
3312#ifdef FEAT_WILDIGN
3313 /*
3314 * Set the default for 'backupskip' to include environment variables for
3315 * temp files.
3316 */
3317 {
3318# ifdef UNIX
3319 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3320# else
3321 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3322# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003323 int len;
3324 garray_T ga;
3325 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326
3327 ga_init2(&ga, 1, 100);
3328 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3329 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003330 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331# ifdef UNIX
3332 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003333# ifdef MACOS_X
3334 p = (char_u *)"/private/tmp";
3335# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003337# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338 else
3339# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003340 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003341 if (p != NULL && *p != NUL)
3342 {
3343 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003344 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345 if (ga_grow(&ga, len) == OK)
3346 {
3347 if (ga.ga_len > 0)
3348 STRCAT(ga.ga_data, ",");
3349 STRCAT(ga.ga_data, p);
3350 add_pathsep(ga.ga_data);
3351 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352 ga.ga_len += len;
3353 }
3354 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003355 if (mustfree)
3356 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 }
3358 if (ga.ga_data != NULL)
3359 {
3360 set_string_default("bsk", ga.ga_data);
3361 vim_free(ga.ga_data);
3362 }
3363 }
3364#endif
3365
3366 /*
3367 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3368 */
3369 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003370 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003372#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3373 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3374#endif
3375 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003377 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003378 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003379#else
3380# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003381 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003382 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003383# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003384 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003385# endif
3386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003388 opt_idx = findoption((char_u *)"maxmem");
3389 if (opt_idx >= 0)
3390 {
3391#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003392 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3393 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003394#endif
3395 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3396 }
3397 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398 }
3399
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400#ifdef FEAT_SEARCHPATH
3401 {
3402 char_u *cdpath;
3403 char_u *buf;
3404 int i;
3405 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003406 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407
3408 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003409 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003410 if (cdpath != NULL)
3411 {
3412 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3413 if (buf != NULL)
3414 {
3415 buf[0] = ','; /* start with ",", current dir first */
3416 j = 1;
3417 for (i = 0; cdpath[i] != NUL; ++i)
3418 {
3419 if (vim_ispathlistsep(cdpath[i]))
3420 buf[j++] = ',';
3421 else
3422 {
3423 if (cdpath[i] == ' ' || cdpath[i] == ',')
3424 buf[j++] = '\\';
3425 buf[j++] = cdpath[i];
3426 }
3427 }
3428 buf[j] = NUL;
3429 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003430 if (opt_idx >= 0)
3431 {
3432 options[opt_idx].def_val[VI_DEFAULT] = buf;
3433 options[opt_idx].flags |= P_DEF_ALLOCED;
3434 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003435 else
3436 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003438 if (mustfree)
3439 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 }
3441 }
3442#endif
3443
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003444#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445 /* Set print encoding on platforms that don't default to latin1 */
3446 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003447# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 (char_u *)"cp1252"
3449# else
3450# ifdef VMS
3451 (char_u *)"dec-mcs"
3452# else
3453# ifdef EBCDIC
3454 (char_u *)"ebcdic-uk"
3455# else
3456# ifdef MAC
3457 (char_u *)"mac-roman"
3458# else /* HPUX */
3459 (char_u *)"hp-roman8"
3460# endif
3461# endif
3462# endif
3463# endif
3464 );
3465#endif
3466
3467#ifdef FEAT_POSTSCRIPT
3468 /* 'printexpr' must be allocated to be able to evaluate it. */
3469 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003470# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003471 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472# else
3473# ifdef VMS
3474 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3475
3476# else
3477 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3478# endif
3479# endif
3480 );
3481#endif
3482
3483 /*
3484 * Set all the options (except the terminal options) to their default
3485 * value. Also set the global value for local options.
3486 */
3487 set_options_default(0);
3488
Bram Moolenaar07268702018-03-01 21:57:32 +01003489#ifdef CLEAN_RUNTIMEPATH
3490 if (clean_arg)
3491 {
3492 opt_idx = findoption((char_u *)"runtimepath");
3493 if (opt_idx >= 0)
3494 {
3495 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3496 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3497 }
3498 opt_idx = findoption((char_u *)"packpath");
3499 if (opt_idx >= 0)
3500 {
3501 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3502 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3503 }
3504 }
3505#endif
3506
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507#ifdef FEAT_GUI
3508 if (found_reverse_arg)
3509 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3510#endif
3511
3512 curbuf->b_p_initialized = TRUE;
3513 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003514 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003515 check_buf_options(curbuf);
3516 check_win_options(curwin);
3517 check_options();
3518
3519 /* Must be before option_expand(), because that one needs vim_isIDc() */
3520 didset_options();
3521
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003522#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003523 /* Use the current chartab for the generic chartab. This is not in
3524 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003525 init_spell_chartab();
3526#endif
3527
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 /*
3529 * Expand environment variables and things like "~" for the defaults.
3530 * If option_expand() returns non-NULL the variable is expanded. This can
3531 * only happen for non-indirect options.
3532 * Also set the default to the expanded value, so ":set" does not list
3533 * them.
3534 * Don't set the P_ALLOCED flag, because we don't want to free the
3535 * default.
3536 */
3537 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3538 {
3539 if ((options[opt_idx].flags & P_GETTEXT)
3540 && options[opt_idx].var != NULL)
3541 p = (char_u *)_(*(char **)options[opt_idx].var);
3542 else
3543 p = option_expand(opt_idx, NULL);
3544 if (p != NULL && (p = vim_strsave(p)) != NULL)
3545 {
3546 *(char_u **)options[opt_idx].var = p;
3547 /* VIMEXP
3548 * Defaults for all expanded options are currently the same for Vi
3549 * and Vim. When this changes, add some code here! Also need to
3550 * split P_DEF_ALLOCED in two.
3551 */
3552 if (options[opt_idx].flags & P_DEF_ALLOCED)
3553 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3554 options[opt_idx].def_val[VI_DEFAULT] = p;
3555 options[opt_idx].flags |= P_DEF_ALLOCED;
3556 }
3557 }
3558
Bram Moolenaar071d4272004-06-13 20:20:40 +00003559 save_file_ff(curbuf); /* Buffer is unchanged */
3560
Bram Moolenaar071d4272004-06-13 20:20:40 +00003561#if defined(FEAT_ARABIC)
3562 /* Detect use of mlterm.
3563 * Mlterm is a terminal emulator akin to xterm that has some special
3564 * abilities (bidi namely).
3565 * NOTE: mlterm's author is being asked to 'set' a variable
3566 * instead of an environment variable due to inheritance.
3567 */
3568 if (mch_getenv((char_u *)"MLTERM") != NULL)
3569 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3570#endif
3571
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003572 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003573
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574# if defined(WIN3264) && defined(FEAT_GETTEXT)
3575 /*
3576 * If $LANG isn't set, try to get a good value for it. This makes the
3577 * right language be used automatically. Don't do this for English.
3578 */
3579 if (mch_getenv((char_u *)"LANG") == NULL)
3580 {
3581 char buf[20];
3582
3583 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3584 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3585 * only the first two. */
3586 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3587 (LPTSTR)buf, 20);
3588 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3589 {
3590 /* There are a few exceptions (probably more) */
3591 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3592 STRCPY(buf, "zh_TW");
3593 else if (STRNICMP(buf, "chs", 3) == 0
3594 || STRNICMP(buf, "zhc", 3) == 0)
3595 STRCPY(buf, "zh_CN");
3596 else if (STRNICMP(buf, "jp", 2) == 0)
3597 STRCPY(buf, "ja");
3598 else
3599 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003600 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003601 }
3602 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003603# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003604# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003605 /* Moved to os_mac_conv.c to avoid dependency problems. */
3606 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003607# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608# endif
3609
3610 /* enc_locale() will try to find the encoding of the current locale. */
3611 p = enc_locale();
3612 if (p != NULL)
3613 {
3614 char_u *save_enc;
3615
3616 /* Try setting 'encoding' and check if the value is valid.
3617 * If not, go back to the default "latin1". */
3618 save_enc = p_enc;
3619 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003620 if (STRCMP(p_enc, "gb18030") == 0)
3621 {
3622 /* We don't support "gb18030", but "cp936" is a good substitute
3623 * for practical purposes, thus use that. It's not an alias to
3624 * still support conversion between gb18030 and utf-8. */
3625 p_enc = vim_strsave((char_u *)"cp936");
3626 vim_free(p);
3627 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003628 if (mb_init() == NULL)
3629 {
3630 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003631 if (opt_idx >= 0)
3632 {
3633 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3634 options[opt_idx].flags |= P_DEF_ALLOCED;
3635 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636
Bram Moolenaard0573012017-10-28 21:11:06 +02003637#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003638 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003639 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003640 /* Adjust the default for 'isprint' and 'iskeyword' to match
3641 * latin1. Also set the defaults for when 'nocompatible' is
3642 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003643 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003644 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003645 set_string_option_direct((char_u *)"isk", -1,
3646 ISK_LATIN1, OPT_FREE, SID_NONE);
3647 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003648 if (opt_idx >= 0)
3649 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003650 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003651 if (opt_idx >= 0)
3652 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003653 (void)init_chartab();
3654 }
3655#endif
3656
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003657#if defined(WIN3264) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658 /* Win32 console: When GetACP() returns a different value from
3659 * GetConsoleCP() set 'termencoding'. */
3660 if (GetACP() != GetConsoleCP())
3661 {
3662 char buf[50];
3663
3664 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3665 p_tenc = vim_strsave((char_u *)buf);
3666 if (p_tenc != NULL)
3667 {
3668 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003669 if (opt_idx >= 0)
3670 {
3671 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3672 options[opt_idx].flags |= P_DEF_ALLOCED;
3673 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003674 convert_setup(&input_conv, p_tenc, p_enc);
3675 convert_setup(&output_conv, p_enc, p_tenc);
3676 }
3677 else
3678 p_tenc = empty_option;
3679 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003680#endif
3681#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003682 /* $HOME may have characters in active code page. */
3683 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003684#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003685 }
3686 else
3687 {
3688 vim_free(p_enc);
3689 p_enc = save_enc;
3690 }
3691 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003692
3693#ifdef FEAT_MULTI_LANG
3694 /* Set the default for 'helplang'. */
3695 set_helplang_default(get_mess_lang());
3696#endif
3697}
3698
3699/*
3700 * Set an option to its default value.
3701 * This does not take care of side effects!
3702 */
3703 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003704set_option_default(
3705 int opt_idx,
3706 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3707 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708{
3709 char_u *varp; /* pointer to variable for current option */
3710 int dvi; /* index in def_val[] */
3711 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003712 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3714
3715 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3716 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003717 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 {
3719 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3720 if (flags & P_STRING)
3721 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003722 /* Use set_string_option_direct() for local options to handle
3723 * freeing and allocating the value. */
3724 if (options[opt_idx].indir != PV_NONE)
3725 set_string_option_direct(NULL, opt_idx,
3726 options[opt_idx].def_val[dvi], opt_flags, 0);
3727 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003729 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3730 free_string_option(*(char_u **)(varp));
3731 *(char_u **)varp = options[opt_idx].def_val[dvi];
3732 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 }
3734 }
3735 else if (flags & P_NUM)
3736 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003737 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738 win_comp_scroll(curwin);
3739 else
3740 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003741 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742 /* May also set global value for local option. */
3743 if (both)
3744 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3745 *(long *)varp;
3746 }
3747 }
3748 else /* P_BOOL */
3749 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003750 /* the cast to long is required for Manx C, long_i is needed for
3751 * MSVC */
3752 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003753#ifdef UNIX
3754 /* 'modeline' defaults to off for root */
3755 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3756 *(int *)varp = FALSE;
3757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758 /* May also set global value for local option. */
3759 if (both)
3760 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3761 *(int *)varp;
3762 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003763
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003764 /* The default value is not insecure. */
3765 flagsp = insecure_flag(opt_idx, opt_flags);
3766 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003767 }
3768
3769#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003770 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771#endif
3772}
3773
3774/*
3775 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003776 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 */
3778 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003779set_options_default(
3780 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781{
3782 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003784 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785
3786 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003787 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003788 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003789 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003790# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003791 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003792 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003793# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003794 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003795 set_option_default(i, opt_flags, p_cp);
3796
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003798 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003800#ifdef FEAT_CINDENT
3801 parse_cino(curbuf);
3802#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003803}
3804
3805/*
3806 * Set the Vi-default value of a string option.
3807 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003808 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003810 static void
3811set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812{
3813 char_u *p;
3814 int opt_idx;
3815
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003816 if (escape && vim_strchr(val, ' ') != NULL)
3817 p = vim_strsave_escaped(val, (char_u *)" ");
3818 else
3819 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820 if (p != NULL) /* we don't want a NULL */
3821 {
3822 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003823 if (opt_idx >= 0)
3824 {
3825 if (options[opt_idx].flags & P_DEF_ALLOCED)
3826 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3827 options[opt_idx].def_val[VI_DEFAULT] = p;
3828 options[opt_idx].flags |= P_DEF_ALLOCED;
3829 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003830 }
3831}
3832
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003833 void
3834set_string_default(char *name, char_u *val)
3835{
3836 set_string_default_esc(name, val, FALSE);
3837}
3838
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839/*
3840 * Set the Vi-default value of a number option.
3841 * Used for 'lines' and 'columns'.
3842 */
3843 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003844set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003845{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003846 int opt_idx;
3847
3848 opt_idx = findoption((char_u *)name);
3849 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003850 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851}
3852
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003853#if defined(EXITFREE) || defined(PROTO)
3854/*
3855 * Free all options.
3856 */
3857 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003858free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003859{
3860 int i;
3861
3862 for (i = 0; !istermoption(&options[i]); i++)
3863 {
3864 if (options[i].indir == PV_NONE)
3865 {
3866 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003867 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003868 free_string_option(*(char_u **)options[i].var);
3869 if (options[i].flags & P_DEF_ALLOCED)
3870 free_string_option(options[i].def_val[VI_DEFAULT]);
3871 }
3872 else if (options[i].var != VAR_WIN
3873 && (options[i].flags & P_STRING))
3874 /* buffer-local option: free global value */
3875 free_string_option(*(char_u **)options[i].var);
3876 }
3877}
3878#endif
3879
3880
Bram Moolenaar071d4272004-06-13 20:20:40 +00003881/*
3882 * Initialize the options, part two: After getting Rows and Columns and
3883 * setting 'term'.
3884 */
3885 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003886set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003887{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003888 int idx;
3889
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003891 * 'scroll' defaults to half the window height. The stored default is zero,
3892 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003893 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003894 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003895 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003896 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897 comp_col();
3898
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003899 /*
3900 * 'window' is only for backwards compatibility with Vi.
3901 * Default is Rows - 1.
3902 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003903 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003904 p_window = Rows - 1;
3905 set_number_default("window", Rows - 1);
3906
Bram Moolenaarf740b292006-02-16 22:11:02 +00003907 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003908#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003909 /*
3910 * If 'background' wasn't set by the user, try guessing the value,
3911 * depending on the terminal name. Only need to check for terminals
3912 * with a dark background, that can handle color.
3913 */
3914 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003915 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3916 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003918 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003919 /* don't mark it as set, when starting the GUI it may be
3920 * changed again */
3921 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 }
3923#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003924
3925#ifdef CURSOR_SHAPE
3926 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3927#endif
3928#ifdef FEAT_MOUSESHAPE
3929 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3930#endif
3931#ifdef FEAT_PRINTER
3932 (void)parse_printoptions(); /* parse 'printoptions' default value */
3933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003934}
3935
3936/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003937 * Return "dark" or "light" depending on the kind of terminal.
3938 * This is just guessing! Recognized are:
3939 * "linux" Linux console
3940 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003941 * "cygwin.*" Cygwin shell
3942 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003943 * We also check the COLORFGBG environment variable, which is set by
3944 * rxvt and derivatives. This variable contains either two or three
3945 * values separated by semicolons; we want the last value in either
3946 * case. If this value is 0-6 or 8, our background is dark.
3947 */
3948 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003949term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003950{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003951#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003952 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003953 return (char_u *)"dark";
3954#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003955 char_u *p;
3956
Bram Moolenaarf740b292006-02-16 22:11:02 +00003957 if (STRCMP(T_NAME, "linux") == 0
3958 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003959 || STRNCMP(T_NAME, "cygwin", 6) == 0
3960 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003961 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3962 && (p = vim_strrchr(p, ';')) != NULL
3963 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3964 && p[2] == NUL))
3965 return (char_u *)"dark";
3966 return (char_u *)"light";
3967#endif
3968}
3969
3970/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003971 * Initialize the options, part three: After reading the .vimrc
3972 */
3973 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003974set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003976#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003977/*
3978 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3979 * This is done after other initializations, where 'shell' might have been
3980 * set, but only if they have not been set before.
3981 */
3982 char_u *p;
3983 int idx_srr;
3984 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003985# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986 int idx_sp;
3987 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003988# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003989
3990 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003991 if (idx_srr < 0)
3992 do_srr = FALSE;
3993 else
3994 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003995# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003996 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003997 if (idx_sp < 0)
3998 do_sp = FALSE;
3999 else
4000 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004001# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004002 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 if (p != NULL)
4004 {
4005 /*
4006 * Default for p_sp is "| tee", for p_srr is ">".
4007 * For known shells it is changed here to include stderr.
4008 */
4009 if ( fnamecmp(p, "csh") == 0
4010 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004011# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004012 || fnamecmp(p, "csh.exe") == 0
4013 || fnamecmp(p, "tcsh.exe") == 0
4014# endif
4015 )
4016 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004017# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018 if (do_sp)
4019 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004020# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004022# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004024# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004025 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4026 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004027# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028 if (do_srr)
4029 {
4030 p_srr = (char_u *)">&";
4031 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4032 }
4033 }
4034 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004035 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004036 if ( fnamecmp(p, "sh") == 0
4037 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004038 || fnamecmp(p, "mksh") == 0
4039 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004041 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004043 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004044# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045 || fnamecmp(p, "cmd") == 0
4046 || fnamecmp(p, "sh.exe") == 0
4047 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004048 || fnamecmp(p, "mksh.exe") == 0
4049 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004051 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 || fnamecmp(p, "bash.exe") == 0
4053 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004054# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004055 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004057# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 if (do_sp)
4059 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004062# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004064# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4066 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004067# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 if (do_srr)
4069 {
4070 p_srr = (char_u *)">%s 2>&1";
4071 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4072 }
4073 }
4074 vim_free(p);
4075 }
4076#endif
4077
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004078#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004080 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4081 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 * This is done after other initializations, where 'shell' might have been
4083 * set, but only if they have not been set before. Default for p_shcf is
4084 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004085 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004087 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 {
4089 int idx3;
4090
4091 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004092 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 {
4094 p_shcf = (char_u *)"-c";
4095 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4096 }
4097
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 /* Somehow Win32 requires the quotes around the redirection too */
4099 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004100 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 {
4102 p_sxq = (char_u *)"\"";
4103 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4104 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004106 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4107 {
4108 int idx3;
4109
4110 /*
4111 * cmd.exe on Windows will strip the first and last double quote given
4112 * on the command line, e.g. most of the time things like:
4113 * cmd /c "my path/to/echo" "my args to echo"
4114 * become:
4115 * my path/to/echo" "my args to echo
4116 * when executed.
4117 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004118 * To avoid this, set shellxquote to surround the command in
4119 * parenthesis. This appears to make most commands work, without
4120 * breaking commands that worked previously, such as
4121 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004122 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004123 idx3 = findoption((char_u *)"sxq");
4124 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4125 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004126 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004127 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4128 }
4129
Bram Moolenaara64ba222012-02-12 23:23:31 +01004130 idx3 = findoption((char_u *)"shcf");
4131 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4132 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004133 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004134 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4135 }
4136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137#endif
4138
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004139 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004140 {
4141 int idx_ffs = findoption((char_u *)"ffs");
4142
4143 /* Apply the first entry of 'fileformats' to the initial buffer. */
4144 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4145 set_fileformat(default_fileformat(), OPT_LOCAL);
4146 }
4147
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148#ifdef FEAT_TITLE
4149 set_title_defaults();
4150#endif
4151}
4152
4153#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4154/*
4155 * When 'helplang' is still at its default value, set it to "lang".
4156 * Only the first two characters of "lang" are used.
4157 */
4158 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004159set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160{
4161 int idx;
4162
4163 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4164 return;
4165 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004166 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004167 {
4168 if (options[idx].flags & P_ALLOCED)
4169 free_string_option(p_hlg);
4170 p_hlg = vim_strsave(lang);
4171 if (p_hlg == NULL)
4172 p_hlg = empty_option;
4173 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004174 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004175 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004176 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4177 {
4178 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4179 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4180 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004181 // any C like setting, such as C.UTF-8, becomes "en"
4182 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4183 {
4184 p_hlg[0] = 'e';
4185 p_hlg[1] = 'n';
4186 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004189 options[idx].flags |= P_ALLOCED;
4190 }
4191}
4192#endif
4193
4194#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004195 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004196gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004197{
4198 if (gui_get_lightness(gui.back_pixel) < 127)
4199 return (char_u *)"dark";
4200 return (char_u *)"light";
4201}
4202
4203/*
4204 * Option initializations that can only be done after opening the GUI window.
4205 */
4206 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004207init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004208{
4209 /* Set the 'background' option according to the lightness of the
4210 * background color, unless the user has set it already. */
4211 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4212 {
4213 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4214 highlight_changed();
4215 }
4216}
4217#endif
4218
4219#ifdef FEAT_TITLE
4220/*
4221 * 'title' and 'icon' only default to true if they have not been set or reset
4222 * in .vimrc and we can read the old value.
4223 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4224 * they can be reset. This reduces startup time when using X on a remote
4225 * machine.
4226 */
4227 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004228set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229{
4230 int idx1;
4231 long val;
4232
4233 /*
4234 * If GUI is (going to be) used, we can always set the window title and
4235 * icon name. Saves a bit of time, because the X11 display server does
4236 * not need to be contacted.
4237 */
4238 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004239 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240 {
4241#ifdef FEAT_GUI
4242 if (gui.starting || gui.in_use)
4243 val = TRUE;
4244 else
4245#endif
4246 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004247 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004248 p_title = val;
4249 }
4250 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004251 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004252 {
4253#ifdef FEAT_GUI
4254 if (gui.starting || gui.in_use)
4255 val = TRUE;
4256 else
4257#endif
4258 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004259 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260 p_icon = val;
4261 }
4262}
4263#endif
4264
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004265#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004266 static void
4267trigger_optionsset_string(
4268 int opt_idx,
4269 int opt_flags,
4270 char_u *oldval,
4271 char_u *newval)
4272{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004273 // Don't do this recursively.
4274 if (oldval != NULL && newval != NULL
4275 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004276 {
4277 char_u buf_type[7];
4278
4279 sprintf((char *)buf_type, "%s",
4280 (opt_flags & OPT_LOCAL) ? "local" : "global");
4281 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4282 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4283 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4284 apply_autocmds(EVENT_OPTIONSET,
4285 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4286 reset_v_option_vars();
4287 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004288}
4289#endif
4290
Bram Moolenaar071d4272004-06-13 20:20:40 +00004291/*
4292 * Parse 'arg' for option settings.
4293 *
4294 * 'arg' may be IObuff, but only when no errors can be present and option
4295 * does not need to be expanded with option_expand().
4296 * "opt_flags":
4297 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004298 * OPT_GLOBAL for ":setglobal"
4299 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004300 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004301 * OPT_WINONLY to only set window-local options
4302 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004303 *
4304 * returns FAIL if an error is detected, OK otherwise
4305 */
4306 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004307do_set(
4308 char_u *arg, /* option string (may be written to!) */
4309 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004310{
4311 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004312 char *errmsg;
4313 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314 char_u *startarg;
4315 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4316 int nextchar; /* next non-white char after option name */
4317 int afterchar; /* character just after option name */
4318 int len;
4319 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004320 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004321 int key;
4322 long_u flags; /* flags for current option */
4323 char_u *varp = NULL; /* pointer to variable for current option */
4324 int did_show = FALSE; /* already showed one value */
4325 int adding; /* "opt+=arg" */
4326 int prepending; /* "opt^=arg" */
4327 int removing; /* "opt-=arg" */
4328 int cp_val = 0;
4329 char_u key_name[2];
4330
4331 if (*arg == NUL)
4332 {
4333 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004334 did_show = TRUE;
4335 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004336 }
4337
4338 while (*arg != NUL) /* loop to process all options */
4339 {
4340 errmsg = NULL;
4341 startarg = arg; /* remember for error message */
4342
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004343 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4344 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004345 {
4346 /*
4347 * ":set all" show all options.
4348 * ":set all&" set all options to their default value.
4349 */
4350 arg += 3;
4351 if (*arg == '&')
4352 {
4353 ++arg;
4354 /* Only for :set command set global value of local options. */
4355 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004356 didset_options();
4357 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004358 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359 }
4360 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004361 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004362 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004363 did_show = TRUE;
4364 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004365 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004366 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004367 {
4368 showoptions(2, opt_flags);
4369 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004370 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004371 arg += 7;
4372 }
4373 else
4374 {
4375 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004376 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377 {
4378 prefix = 0;
4379 arg += 2;
4380 }
4381 else if (STRNCMP(arg, "inv", 3) == 0)
4382 {
4383 prefix = 2;
4384 arg += 3;
4385 }
4386
4387 /* find end of name */
4388 key = 0;
4389 if (*arg == '<')
4390 {
4391 nextchar = 0;
4392 opt_idx = -1;
4393 /* look out for <t_>;> */
4394 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4395 len = 5;
4396 else
4397 {
4398 len = 1;
4399 while (arg[len] != NUL && arg[len] != '>')
4400 ++len;
4401 }
4402 if (arg[len] != '>')
4403 {
4404 errmsg = e_invarg;
4405 goto skip;
4406 }
4407 arg[len] = NUL; /* put NUL after name */
4408 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4409 opt_idx = findoption(arg + 1);
4410 arg[len++] = '>'; /* restore '>' */
4411 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004412 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004413 }
4414 else
4415 {
4416 len = 0;
4417 /*
4418 * The two characters after "t_" may not be alphanumeric.
4419 */
4420 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4421 len = 4;
4422 else
4423 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4424 ++len;
4425 nextchar = arg[len];
4426 arg[len] = NUL; /* put NUL after name */
4427 opt_idx = findoption(arg);
4428 arg[len] = nextchar; /* restore nextchar */
4429 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004430 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004431 }
4432
4433 /* remember character after option name */
4434 afterchar = arg[len];
4435
4436 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004437 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004438 ++len;
4439
4440 adding = FALSE;
4441 prepending = FALSE;
4442 removing = FALSE;
4443 if (arg[len] != NUL && arg[len + 1] == '=')
4444 {
4445 if (arg[len] == '+')
4446 {
4447 adding = TRUE; /* "+=" */
4448 ++len;
4449 }
4450 else if (arg[len] == '^')
4451 {
4452 prepending = TRUE; /* "^=" */
4453 ++len;
4454 }
4455 else if (arg[len] == '-')
4456 {
4457 removing = TRUE; /* "-=" */
4458 ++len;
4459 }
4460 }
4461 nextchar = arg[len];
4462
4463 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4464 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004465 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004466 goto skip;
4467 }
4468
4469 if (opt_idx >= 0)
4470 {
4471 if (options[opt_idx].var == NULL) /* hidden option: skip */
4472 {
4473 /* Only give an error message when requesting the value of
4474 * a hidden option, ignore setting it. */
4475 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4476 && (!(options[opt_idx].flags & P_BOOL)
4477 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004478 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004479 goto skip;
4480 }
4481
4482 flags = options[opt_idx].flags;
4483 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4484 }
4485 else
4486 {
4487 flags = P_STRING;
4488 if (key < 0)
4489 {
4490 key_name[0] = KEY2TERMCAP0(key);
4491 key_name[1] = KEY2TERMCAP1(key);
4492 }
4493 else
4494 {
4495 key_name[0] = KS_KEY;
4496 key_name[1] = (key & 0xff);
4497 }
4498 }
4499
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004500 /* Skip all options that are not window-local (used when showing
4501 * an already loaded buffer in a window). */
4502 if ((opt_flags & OPT_WINONLY)
4503 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4504 goto skip;
4505
Bram Moolenaara3227e22006-03-08 21:32:40 +00004506 /* Skip all options that are window-local (used for :vimgrep). */
4507 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4508 && options[opt_idx].var == VAR_WIN)
4509 goto skip;
4510
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004511 /* Disallow changing some options from modelines. */
4512 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004513 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004514 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004515 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004516 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004517 goto skip;
4518 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004519#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004520 /* In diff mode some options are overruled. This avoids that
4521 * 'foldmethod' becomes "marker" instead of "diff" and that
4522 * "wrap" gets set. */
4523 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004524 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004525 && (
4526#ifdef FEAT_FOLDING
4527 options[opt_idx].indir == PV_FDM ||
4528#endif
4529 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004530 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004531#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004532 }
4533
4534#ifdef HAVE_SANDBOX
4535 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004536 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004537 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004538 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004539 goto skip;
4540 }
4541#endif
4542
4543 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4544 {
4545 arg += len;
4546 cp_val = p_cp;
4547 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4548 {
4549 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4550 {
4551 cp_val = FALSE;
4552 arg += 3;
4553 }
4554 else /* "opt&vi": set to Vi default */
4555 {
4556 cp_val = TRUE;
4557 arg += 2;
4558 }
4559 }
4560 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004561 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004562 {
4563 errmsg = e_trailing;
4564 goto skip;
4565 }
4566 }
4567
4568 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004569 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4570 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004571 */
4572 if (nextchar == '?'
4573 || (prefix == 1
4574 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4575 && !(flags & P_BOOL)))
4576 {
4577 /*
4578 * print value
4579 */
4580 if (did_show)
4581 msg_putchar('\n'); /* cursor below last one */
4582 else
4583 {
4584 gotocmdline(TRUE); /* cursor at status line */
4585 did_show = TRUE; /* remember that we did a line */
4586 }
4587 if (opt_idx >= 0)
4588 {
4589 showoneopt(&options[opt_idx], opt_flags);
4590#ifdef FEAT_EVAL
4591 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004592 {
4593 /* Mention where the option was last set. */
4594 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004595 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004596 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004597 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004598 (int)options[opt_idx].indir & PV_MASK]);
4599 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004600 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004601 (int)options[opt_idx].indir & PV_MASK]);
4602 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004603#endif
4604 }
4605 else
4606 {
4607 char_u *p;
4608
4609 p = find_termcode(key_name);
4610 if (p == NULL)
4611 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004612 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613 goto skip;
4614 }
4615 else
4616 (void)show_one_termcode(key_name, p, TRUE);
4617 }
4618 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004619 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004620 errmsg = e_trailing;
4621 }
4622 else
4623 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004624 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004625 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004626
Bram Moolenaar071d4272004-06-13 20:20:40 +00004627 if (flags & P_BOOL) /* boolean */
4628 {
4629 if (nextchar == '=' || nextchar == ':')
4630 {
4631 errmsg = e_invarg;
4632 goto skip;
4633 }
4634
4635 /*
4636 * ":set opt!": invert
4637 * ":set opt&": reset to default value
4638 * ":set opt<": reset to global value
4639 */
4640 if (nextchar == '!')
4641 value = *(int *)(varp) ^ 1;
4642 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004643 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004644 ((flags & P_VI_DEF) || cp_val)
4645 ? VI_DEFAULT : VIM_DEFAULT];
4646 else if (nextchar == '<')
4647 {
4648 /* For 'autoread' -1 means to use global value. */
4649 if ((int *)varp == &curbuf->b_p_ar
4650 && opt_flags == OPT_LOCAL)
4651 value = -1;
4652 else
4653 value = *(int *)get_varp_scope(&(options[opt_idx]),
4654 OPT_GLOBAL);
4655 }
4656 else
4657 {
4658 /*
4659 * ":set invopt": invert
4660 * ":set opt" or ":set noopt": set or reset
4661 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004662 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004663 {
4664 errmsg = e_trailing;
4665 goto skip;
4666 }
4667 if (prefix == 2) /* inv */
4668 value = *(int *)(varp) ^ 1;
4669 else
4670 value = prefix;
4671 }
4672
4673 errmsg = set_bool_option(opt_idx, varp, (int)value,
4674 opt_flags);
4675 }
4676 else /* numeric or string */
4677 {
4678 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4679 || prefix != 1)
4680 {
4681 errmsg = e_invarg;
4682 goto skip;
4683 }
4684
4685 if (flags & P_NUM) /* numeric */
4686 {
4687 /*
4688 * Different ways to set a number option:
4689 * & set to default value
4690 * < set to global value
4691 * <xx> accept special key codes for 'wildchar'
4692 * c accept any non-digit for 'wildchar'
4693 * [-]0-9 set number
4694 * other error
4695 */
4696 ++arg;
4697 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004698 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004699 ((flags & P_VI_DEF) || cp_val)
4700 ? VI_DEFAULT : VIM_DEFAULT];
4701 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004702 {
4703 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4704 * use the global value. */
4705 if ((long *)varp == &curbuf->b_p_ul
4706 && opt_flags == OPT_LOCAL)
4707 value = NO_LOCAL_UNDOLEVEL;
4708 else
4709 value = *(long *)get_varp_scope(
4710 &(options[opt_idx]), OPT_GLOBAL);
4711 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004712 else if (((long *)varp == &p_wc
4713 || (long *)varp == &p_wcm)
4714 && (*arg == '<'
4715 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004716 || (*arg != NUL
4717 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004718 && !VIM_ISDIGIT(*arg))))
4719 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004720 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004721 if (value == 0 && (long *)varp != &p_wcm)
4722 {
4723 errmsg = e_invarg;
4724 goto skip;
4725 }
4726 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004727 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4728 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004729 /* Allow negative (for 'undolevels'), octal and
4730 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004731 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4732 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004733 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004734 {
4735 errmsg = e_invarg;
4736 goto skip;
4737 }
4738 }
4739 else
4740 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004741 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004742 goto skip;
4743 }
4744
4745 if (adding)
4746 value = *(long *)varp + value;
4747 if (prepending)
4748 value = *(long *)varp * value;
4749 if (removing)
4750 value = *(long *)varp - value;
4751 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004752 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004753 }
4754 else if (opt_idx >= 0) /* string */
4755 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004756 char_u *save_arg = NULL;
4757 char_u *s = NULL;
4758 char_u *oldval = NULL; /* previous value if *varp */
4759 char_u *newval;
4760 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004761#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004762 char_u *saved_origval = NULL;
4763 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004764#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004765 unsigned newlen;
4766 int comma;
4767 int bs;
4768 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769 was allocated */
4770
4771 /* When using ":set opt=val" for a global option
4772 * with a local value the local value will be
4773 * reset, use the global value here. */
4774 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004775 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004776 varp = options[opt_idx].var;
4777
4778 /* The old value is kept until we are sure that the
4779 * new value is valid. */
4780 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004781
4782 /* When setting the local value of a global
4783 * option, the old value may be the global value. */
4784 if (((int)options[opt_idx].indir & PV_BOTH)
4785 && (opt_flags & OPT_LOCAL))
4786 origval = *(char_u **)get_varp(
4787 &options[opt_idx]);
4788 else
4789 origval = oldval;
4790
Bram Moolenaar071d4272004-06-13 20:20:40 +00004791 if (nextchar == '&') /* set to default val */
4792 {
4793 newval = options[opt_idx].def_val[
4794 ((flags & P_VI_DEF) || cp_val)
4795 ? VI_DEFAULT : VIM_DEFAULT];
4796 if ((char_u **)varp == &p_bg)
4797 {
4798 /* guess the value of 'background' */
4799#ifdef FEAT_GUI
4800 if (gui.in_use)
4801 newval = gui_bg_default();
4802 else
4803#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004804 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004805 }
4806
4807 /* expand environment variables and ~ (since the
4808 * default value was already expanded, only
4809 * required when an environment variable was set
4810 * later */
4811 if (newval == NULL)
4812 newval = empty_option;
4813 else
4814 {
4815 s = option_expand(opt_idx, newval);
4816 if (s == NULL)
4817 s = newval;
4818 newval = vim_strsave(s);
4819 }
4820 new_value_alloced = TRUE;
4821 }
4822 else if (nextchar == '<') /* set to global val */
4823 {
4824 newval = vim_strsave(*(char_u **)get_varp_scope(
4825 &(options[opt_idx]), OPT_GLOBAL));
4826 new_value_alloced = TRUE;
4827 }
4828 else
4829 {
4830 ++arg; /* jump to after the '=' or ':' */
4831
4832 /*
4833 * Set 'keywordprg' to ":help" if an empty
4834 * value was passed to :set by the user.
4835 * Misuse errbuf[] for the resulting string.
4836 */
4837 if (varp == (char_u *)&p_kp
4838 && (*arg == NUL || *arg == ' '))
4839 {
4840 STRCPY(errbuf, ":help");
4841 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004842 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004843 }
4844 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004845 * Convert 'backspace' number to string, for
4846 * adding, prepending and removing string.
4847 */
4848 else if (varp == (char_u *)&p_bs
4849 && VIM_ISDIGIT(**(char_u **)varp))
4850 {
4851 i = getdigits((char_u **)varp);
4852 switch (i)
4853 {
4854 case 0:
4855 *(char_u **)varp = empty_option;
4856 break;
4857 case 1:
4858 *(char_u **)varp = vim_strsave(
4859 (char_u *)"indent,eol");
4860 break;
4861 case 2:
4862 *(char_u **)varp = vim_strsave(
4863 (char_u *)"indent,eol,start");
4864 break;
4865 }
4866 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004867 if (origval == oldval)
4868 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004869 oldval = *(char_u **)varp;
4870 }
4871 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004872 * Convert 'whichwrap' number to string, for
4873 * backwards compatibility with Vim 3.0.
4874 * Misuse errbuf[] for the resulting string.
4875 */
4876 else if (varp == (char_u *)&p_ww
4877 && VIM_ISDIGIT(*arg))
4878 {
4879 *errbuf = NUL;
4880 i = getdigits(&arg);
4881 if (i & 1)
4882 STRCAT(errbuf, "b,");
4883 if (i & 2)
4884 STRCAT(errbuf, "s,");
4885 if (i & 4)
4886 STRCAT(errbuf, "h,l,");
4887 if (i & 8)
4888 STRCAT(errbuf, "<,>,");
4889 if (i & 16)
4890 STRCAT(errbuf, "[,],");
4891 if (*errbuf != NUL) /* remove trailing , */
4892 errbuf[STRLEN(errbuf) - 1] = NUL;
4893 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004894 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004895 }
4896 /*
4897 * Remove '>' before 'dir' and 'bdir', for
4898 * backwards compatibility with version 3.0
4899 */
4900 else if ( *arg == '>'
4901 && (varp == (char_u *)&p_dir
4902 || varp == (char_u *)&p_bdir))
4903 {
4904 ++arg;
4905 }
4906
Bram Moolenaar071d4272004-06-13 20:20:40 +00004907 /*
4908 * Copy the new string into allocated memory.
4909 * Can't use set_string_option_direct(), because
4910 * we need to remove the backslashes.
4911 */
4912 /* get a bit too much */
4913 newlen = (unsigned)STRLEN(arg) + 1;
4914 if (adding || prepending || removing)
4915 newlen += (unsigned)STRLEN(origval) + 1;
4916 newval = alloc(newlen);
4917 if (newval == NULL) /* out of mem, don't change */
4918 break;
4919 s = newval;
4920
4921 /*
4922 * Copy the string, skip over escaped chars.
4923 * For MS-DOS and WIN32 backslashes before normal
4924 * file name characters are not removed, and keep
4925 * backslash at start, for "\\machine\path", but
4926 * do remove it for "\\\\machine\\path".
4927 * The reverse is found in ExpandOldSetting().
4928 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004929 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004930 {
4931 if (*arg == '\\' && arg[1] != NUL
4932#ifdef BACKSLASH_IN_FILENAME
4933 && !((flags & P_EXPAND)
4934 && vim_isfilec(arg[1])
4935 && (arg[1] != '\\'
4936 || (s == newval
4937 && arg[2] != '\\')))
4938#endif
4939 )
4940 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004941 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004942 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004943 {
4944 /* copy multibyte char */
4945 mch_memmove(s, arg, (size_t)i);
4946 arg += i;
4947 s += i;
4948 }
4949 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004950 *s++ = *arg++;
4951 }
4952 *s = NUL;
4953
4954 /*
4955 * Expand environment variables and ~.
4956 * Don't do it when adding without inserting a
4957 * comma.
4958 */
4959 if (!(adding || prepending || removing)
4960 || (flags & P_COMMA))
4961 {
4962 s = option_expand(opt_idx, newval);
4963 if (s != NULL)
4964 {
4965 vim_free(newval);
4966 newlen = (unsigned)STRLEN(s) + 1;
4967 if (adding || prepending || removing)
4968 newlen += (unsigned)STRLEN(origval) + 1;
4969 newval = alloc(newlen);
4970 if (newval == NULL)
4971 break;
4972 STRCPY(newval, s);
4973 }
4974 }
4975
4976 /* locate newval[] in origval[] when removing it
4977 * and when adding to avoid duplicates */
4978 i = 0; /* init for GCC */
4979 if (removing || (flags & P_NODUP))
4980 {
4981 i = (int)STRLEN(newval);
4982 bs = 0;
4983 for (s = origval; *s; ++s)
4984 {
4985 if ((!(flags & P_COMMA)
4986 || s == origval
4987 || (s[-1] == ',' && !(bs & 1)))
4988 && STRNCMP(s, newval, i) == 0
4989 && (!(flags & P_COMMA)
4990 || s[i] == ','
4991 || s[i] == NUL))
4992 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004993 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004994 * even number of backslashes or a single
4995 * backslash preceded by a comma before it
4996 * is recognized as a separator */
4997 if ((s > origval + 1
4998 && s[-1] == '\\'
4999 && s[-2] != ',')
5000 || (s == origval + 1
5001 && s[-1] == '\\'))
5002
Bram Moolenaar071d4272004-06-13 20:20:40 +00005003 ++bs;
5004 else
5005 bs = 0;
5006 }
5007
5008 /* do not add if already there */
5009 if ((adding || prepending) && *s)
5010 {
5011 prepending = FALSE;
5012 adding = FALSE;
5013 STRCPY(newval, origval);
5014 }
5015 }
5016
5017 /* concatenate the two strings; add a ',' if
5018 * needed */
5019 if (adding || prepending)
5020 {
5021 comma = ((flags & P_COMMA) && *origval != NUL
5022 && *newval != NUL);
5023 if (adding)
5024 {
5025 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005026 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005027 if (comma && i > 1
5028 && (flags & P_ONECOMMA) == P_ONECOMMA
5029 && origval[i - 1] == ','
5030 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005031 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005032 mch_memmove(newval + i + comma, newval,
5033 STRLEN(newval) + 1);
5034 mch_memmove(newval, origval, (size_t)i);
5035 }
5036 else
5037 {
5038 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005039 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005040 }
5041 if (comma)
5042 newval[i] = ',';
5043 }
5044
5045 /* Remove newval[] from origval[]. (Note: "i" has
5046 * been set above and is used here). */
5047 if (removing)
5048 {
5049 STRCPY(newval, origval);
5050 if (*s)
5051 {
5052 /* may need to remove a comma */
5053 if (flags & P_COMMA)
5054 {
5055 if (s == origval)
5056 {
5057 /* include comma after string */
5058 if (s[i] == ',')
5059 ++i;
5060 }
5061 else
5062 {
5063 /* include comma before string */
5064 --s;
5065 ++i;
5066 }
5067 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005068 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005069 }
5070 }
5071
5072 if (flags & P_FLAGLIST)
5073 {
5074 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005075 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005076 {
5077 /* if options have P_FLAGLIST and
5078 * P_ONECOMMA such as 'whichwrap' */
5079 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005080 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005081 if (*s != ',' && *(s + 1) == ','
5082 && vim_strchr(s + 2, *s) != NULL)
5083 {
5084 /* Remove the duplicated value and
5085 * the next comma. */
5086 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005087 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005088 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005089 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005090 else
5091 {
5092 if ((!(flags & P_COMMA) || *s != ',')
5093 && vim_strchr(s + 1, *s) != NULL)
5094 {
5095 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005096 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005097 }
5098 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005099 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005100 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005101 }
5102
5103 if (save_arg != NULL) /* number for 'whichwrap' */
5104 arg = save_arg;
5105 new_value_alloced = TRUE;
5106 }
5107
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005108 /*
5109 * Set the new value.
5110 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 *(char_u **)(varp) = newval;
5112
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005113#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005114 if (!starting
5115# ifdef FEAT_CRYPT
5116 && options[opt_idx].indir != PV_KEY
5117# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005118 && origval != NULL && newval != NULL)
5119 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005120 /* origval may be freed by
5121 * did_set_string_option(), make a copy. */
5122 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005123 /* newval (and varp) may become invalid if the
5124 * buffer is closed by autocommands. */
5125 saved_newval = vim_strsave(newval);
5126 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005127#endif
5128
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005129 {
5130 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005131 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005132
5133 // When an option is set in the sandbox, from a
5134 // modeline or in secure mode, then deal with side
5135 // effects in secure mode. Also when the value was
5136 // set with the P_INSECURE flag and is not
5137 // completely replaced.
5138 if (secure
5139#ifdef HAVE_SANDBOX
5140 || sandbox != 0
5141#endif
5142 || (opt_flags & OPT_MODELINE)
5143 || (!value_is_replaced && (*p & P_INSECURE)))
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005144 ++secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005145
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005146 // Handle side effects, and set the global value
5147 // for ":set" on local options. Note: when setting
5148 // 'syntax' or 'filetype' autocommands may be
5149 // triggered that can cause havoc.
5150 errmsg = did_set_string_option(
5151 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005152 new_value_alloced, oldval, errbuf,
5153 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005154
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005155 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005156 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005157
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005158#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005159 if (errmsg == NULL)
5160 trigger_optionsset_string(opt_idx, opt_flags,
5161 saved_origval, saved_newval);
5162 vim_free(saved_origval);
5163 vim_free(saved_newval);
5164#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005165 /* If error detected, print the error message. */
5166 if (errmsg != NULL)
5167 goto skip;
5168 }
5169 else /* key code option */
5170 {
5171 char_u *p;
5172
5173 if (nextchar == '&')
5174 {
5175 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005176 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005177 }
5178 else
5179 {
5180 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005181 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005182 if (*p == '\\' && p[1] != NUL)
5183 ++p;
5184 nextchar = *p;
5185 *p = NUL;
5186 add_termcode(key_name, arg, FALSE);
5187 *p = nextchar;
5188 }
5189 if (full_screen)
5190 ttest(FALSE);
5191 redraw_all_later(CLEAR);
5192 }
5193 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005194
Bram Moolenaar071d4272004-06-13 20:20:40 +00005195 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005196 did_set_option(
5197 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005198 }
5199
5200skip:
5201 /*
5202 * Advance to next argument.
5203 * - skip until a blank found, taking care of backslashes
5204 * - skip blanks
5205 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5206 */
5207 for (i = 0; i < 2 ; ++i)
5208 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005209 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005210 if (*arg++ == '\\' && *arg != NUL)
5211 ++arg;
5212 arg = skipwhite(arg);
5213 if (*arg != '=')
5214 break;
5215 }
5216 }
5217
5218 if (errmsg != NULL)
5219 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005220 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005221 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005222 if (i + (arg - startarg) < IOSIZE)
5223 {
5224 /* append the argument with the error */
5225 STRCAT(IObuff, ": ");
5226 mch_memmove(IObuff + i, startarg, (arg - startarg));
5227 IObuff[i + (arg - startarg)] = NUL;
5228 }
5229 /* make sure all characters are printable */
5230 trans_characters(IObuff, IOSIZE);
5231
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005232 ++no_wait_return; // wait_return done later
5233 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234 --no_wait_return;
5235
5236 return FAIL;
5237 }
5238
5239 arg = skipwhite(arg);
5240 }
5241
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005242theend:
5243 if (silent_mode && did_show)
5244 {
5245 /* After displaying option values in silent mode. */
5246 silent_mode = FALSE;
5247 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5248 msg_putchar('\n');
5249 cursor_on(); /* msg_start() switches it off */
5250 out_flush();
5251 silent_mode = TRUE;
5252 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5253 }
5254
Bram Moolenaar071d4272004-06-13 20:20:40 +00005255 return OK;
5256}
5257
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005258/*
5259 * Call this when an option has been given a new value through a user command.
5260 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5261 */
5262 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005263did_set_option(
5264 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005265 int opt_flags, // possibly with OPT_MODELINE
5266 int new_value, // value was replaced completely
5267 int value_checked) // value was checked to be safe, no need to set the
5268 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005269{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005270 long_u *p;
5271
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005272 options[opt_idx].flags |= P_WAS_SET;
5273
5274 /* When an option is set in the sandbox, from a modeline or in secure mode
5275 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005276 * flag. */
5277 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005278 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005279#ifdef HAVE_SANDBOX
5280 || sandbox != 0
5281#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005282 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005283 *p = *p | P_INSECURE;
5284 else if (new_value)
5285 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005286}
5287
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005288 static char *
5289illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290{
5291 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005292 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005293 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005294 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005295 return errbuf;
5296}
5297
5298/*
5299 * Convert a key name or string into a key value.
5300 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005301 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005302 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005303 int
5304string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005305{
5306 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005307 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308 if (*arg == '^')
5309 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005310 if (multi_byte)
5311 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005312 return *arg;
5313}
5314
5315#ifdef FEAT_CMDWIN
5316/*
5317 * Check value of 'cedit' and set cedit_key.
5318 * Returns NULL if value is OK, error message otherwise.
5319 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005320 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005321check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322{
5323 int n;
5324
5325 if (*p_cedit == NUL)
5326 cedit_key = -1;
5327 else
5328 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005329 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005330 if (vim_isprintc(n))
5331 return e_invarg;
5332 cedit_key = n;
5333 }
5334 return NULL;
5335}
5336#endif
5337
5338#ifdef FEAT_TITLE
5339/*
5340 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5341 * maketitle() to create and display it.
5342 * When switching the title or icon off, call mch_restore_title() to get
5343 * the old value back.
5344 */
5345 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005346did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005347{
5348 if (starting != NO_SCREEN
5349#ifdef FEAT_GUI
5350 && !gui.starting
5351#endif
5352 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354}
5355#endif
5356
5357/*
5358 * set_options_bin - called when 'bin' changes value.
5359 */
5360 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005361set_options_bin(
5362 int oldval,
5363 int newval,
5364 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365{
5366 /*
5367 * The option values that are changed when 'bin' changes are
5368 * copied when 'bin is set and restored when 'bin' is reset.
5369 */
5370 if (newval)
5371 {
5372 if (!oldval) /* switched on */
5373 {
5374 if (!(opt_flags & OPT_GLOBAL))
5375 {
5376 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5377 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5378 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5379 curbuf->b_p_et_nobin = curbuf->b_p_et;
5380 }
5381 if (!(opt_flags & OPT_LOCAL))
5382 {
5383 p_tw_nobin = p_tw;
5384 p_wm_nobin = p_wm;
5385 p_ml_nobin = p_ml;
5386 p_et_nobin = p_et;
5387 }
5388 }
5389
5390 if (!(opt_flags & OPT_GLOBAL))
5391 {
5392 curbuf->b_p_tw = 0; /* no automatic line wrap */
5393 curbuf->b_p_wm = 0; /* no automatic line wrap */
5394 curbuf->b_p_ml = 0; /* no modelines */
5395 curbuf->b_p_et = 0; /* no expandtab */
5396 }
5397 if (!(opt_flags & OPT_LOCAL))
5398 {
5399 p_tw = 0;
5400 p_wm = 0;
5401 p_ml = FALSE;
5402 p_et = FALSE;
5403 p_bin = TRUE; /* needed when called for the "-b" argument */
5404 }
5405 }
5406 else if (oldval) /* switched off */
5407 {
5408 if (!(opt_flags & OPT_GLOBAL))
5409 {
5410 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5411 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5412 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5413 curbuf->b_p_et = curbuf->b_p_et_nobin;
5414 }
5415 if (!(opt_flags & OPT_LOCAL))
5416 {
5417 p_tw = p_tw_nobin;
5418 p_wm = p_wm_nobin;
5419 p_ml = p_ml_nobin;
5420 p_et = p_et_nobin;
5421 }
5422 }
5423}
5424
5425#ifdef FEAT_VIMINFO
5426/*
5427 * Find the parameter represented by the given character (eg ', :, ", or /),
5428 * and return its associated value in the 'viminfo' string.
5429 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005430 * If the parameter is not specified in the string or there is no following
5431 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432 */
5433 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005434get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005435{
5436 char_u *p;
5437
5438 p = find_viminfo_parameter(type);
5439 if (p != NULL && VIM_ISDIGIT(*p))
5440 return atoi((char *)p);
5441 return -1;
5442}
5443
5444/*
5445 * Find the parameter represented by the given character (eg ''', ':', '"', or
5446 * '/') in the 'viminfo' option and return a pointer to the string after it.
5447 * Return NULL if the parameter is not specified in the string.
5448 */
5449 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005450find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005451{
5452 char_u *p;
5453
5454 for (p = p_viminfo; *p; ++p)
5455 {
5456 if (*p == type)
5457 return p + 1;
5458 if (*p == 'n') /* 'n' is always the last one */
5459 break;
5460 p = vim_strchr(p, ','); /* skip until next ',' */
5461 if (p == NULL) /* hit the end without finding parameter */
5462 break;
5463 }
5464 return NULL;
5465}
5466#endif
5467
5468/*
5469 * Expand environment variables for some string options.
5470 * These string options cannot be indirect!
5471 * If "val" is NULL expand the current value of the option.
5472 * Return pointer to NameBuff, or NULL when not expanded.
5473 */
5474 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005475option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005476{
5477 /* if option doesn't need expansion nothing to do */
5478 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5479 return NULL;
5480
5481 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5482 * expand_env() would truncate the string. */
5483 if (val != NULL && STRLEN(val) > MAXPATHL)
5484 return NULL;
5485
5486 if (val == NULL)
5487 val = *(char_u **)options[opt_idx].var;
5488
5489 /*
5490 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5491 * Escape spaces when expanding 'tags', they are used to separate file
5492 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005493 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494 */
5495 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005496 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005497#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005498 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5499#endif
5500 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005501 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5502 return NULL;
5503
5504 return NameBuff;
5505}
5506
5507/*
5508 * After setting various option values: recompute variables that depend on
5509 * option values.
5510 */
5511 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005512didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005513{
5514 /* initialize the table for 'iskeyword' et.al. */
5515 (void)init_chartab();
5516
5517 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5518 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005519 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005520#ifdef FEAT_SESSION
5521 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5522 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5523#endif
5524#ifdef FEAT_FOLDING
5525 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5526#endif
5527 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005528 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005529#ifdef FEAT_VIRTUALEDIT
5530 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
5531#endif
5532#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5533 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5534#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005535#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005536 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005537 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005538 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005539 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005540#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005541#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5542 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5543#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005544#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5546#endif
5547#ifdef FEAT_CMDWIN
5548 /* set cedit_key */
5549 (void)check_cedit();
5550#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005551#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005552 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005553#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005554#ifdef FEAT_LINEBREAK
5555 /* initialize the table for 'breakat'. */
5556 fill_breakat_flags();
5557#endif
5558
5559}
5560
5561/*
5562 * More side effects of setting options.
5563 */
5564 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005565didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005566{
5567 /* Initialize the highlight_attr[] table. */
5568 (void)highlight_changed();
5569
5570 /* Parse default for 'wildmode' */
5571 check_opt_wim();
5572
5573 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005574 /* Parse default for 'fillchars'. */
5575 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005576
5577#ifdef FEAT_CLIPBOARD
5578 /* Parse default for 'clipboard' */
5579 (void)check_clipboard_option();
5580#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005581#ifdef FEAT_VARTABS
5582 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5583 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5584#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585}
5586
5587/*
5588 * Check for string options that are NULL (normally only termcap options).
5589 */
5590 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005591check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005592{
5593 int opt_idx;
5594
5595 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5596 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5597 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5598}
5599
5600/*
5601 * Check string options in a buffer for NULL value.
5602 */
5603 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005604check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005605{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005606 check_string_option(&buf->b_p_bh);
5607 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005608 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005609 check_string_option(&buf->b_p_ff);
5610#ifdef FEAT_FIND_ID
5611 check_string_option(&buf->b_p_def);
5612 check_string_option(&buf->b_p_inc);
5613# ifdef FEAT_EVAL
5614 check_string_option(&buf->b_p_inex);
5615# endif
5616#endif
5617#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5618 check_string_option(&buf->b_p_inde);
5619 check_string_option(&buf->b_p_indk);
5620#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005621#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5622 check_string_option(&buf->b_p_bexpr);
5623#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005624#if defined(FEAT_CRYPT)
5625 check_string_option(&buf->b_p_cm);
5626#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005627 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005628#if defined(FEAT_EVAL)
5629 check_string_option(&buf->b_p_fex);
5630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631#ifdef FEAT_CRYPT
5632 check_string_option(&buf->b_p_key);
5633#endif
5634 check_string_option(&buf->b_p_kp);
5635 check_string_option(&buf->b_p_mps);
5636 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005637 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638 check_string_option(&buf->b_p_isk);
5639#ifdef FEAT_COMMENTS
5640 check_string_option(&buf->b_p_com);
5641#endif
5642#ifdef FEAT_FOLDING
5643 check_string_option(&buf->b_p_cms);
5644#endif
5645 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005646#ifdef FEAT_TEXTOBJ
5647 check_string_option(&buf->b_p_qe);
5648#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649#ifdef FEAT_SYN_HL
5650 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005651 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005652#endif
5653#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005654 check_string_option(&buf->b_s.b_p_spc);
5655 check_string_option(&buf->b_s.b_p_spf);
5656 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005657#endif
5658#ifdef FEAT_SEARCHPATH
5659 check_string_option(&buf->b_p_sua);
5660#endif
5661#ifdef FEAT_CINDENT
5662 check_string_option(&buf->b_p_cink);
5663 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005664 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005665#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005666 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005667#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5668 check_string_option(&buf->b_p_cinw);
5669#endif
5670#ifdef FEAT_INS_EXPAND
5671 check_string_option(&buf->b_p_cpt);
5672#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005673#ifdef FEAT_COMPL_FUNC
5674 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005675 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005677#ifdef FEAT_KEYMAP
5678 check_string_option(&buf->b_p_keymap);
5679#endif
5680#ifdef FEAT_QUICKFIX
5681 check_string_option(&buf->b_p_gp);
5682 check_string_option(&buf->b_p_mp);
5683 check_string_option(&buf->b_p_efm);
5684#endif
5685 check_string_option(&buf->b_p_ep);
5686 check_string_option(&buf->b_p_path);
5687 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005688 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689#ifdef FEAT_INS_EXPAND
5690 check_string_option(&buf->b_p_dict);
5691 check_string_option(&buf->b_p_tsr);
5692#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005693#ifdef FEAT_LISP
5694 check_string_option(&buf->b_p_lw);
5695#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005696 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005697 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005698#ifdef FEAT_VARTABS
5699 check_string_option(&buf->b_p_vsts);
5700 check_string_option(&buf->b_p_vts);
5701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702}
5703
5704/*
5705 * Free the string allocated for an option.
5706 * Checks for the string being empty_option. This may happen if we're out of
5707 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5708 * check_options().
5709 * Does NOT check for P_ALLOCED flag!
5710 */
5711 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005712free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713{
5714 if (p != empty_option)
5715 vim_free(p);
5716}
5717
5718 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005719clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005720{
5721 if (*pp != empty_option)
5722 vim_free(*pp);
5723 *pp = empty_option;
5724}
5725
5726 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005727check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728{
5729 if (*pp == NULL)
5730 *pp = empty_option;
5731}
5732
5733/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005734 * Return the option index found by a pointer into term_strings[].
5735 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005737 int
5738get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005739{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005740 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005741
5742 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5743 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005744 return opt_idx;
5745 return -1; // cannot happen: didn't find it!
5746}
5747
5748/*
5749 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5750 * Return the option index or -1 if not found.
5751 */
5752 int
5753set_term_option_alloced(char_u **p)
5754{
5755 int opt_idx = get_term_opt_idx(p);
5756
5757 if (opt_idx >= 0)
5758 options[opt_idx].flags |= P_ALLOCED;
5759 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005760}
5761
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005762#if defined(FEAT_EVAL) || defined(PROTO)
5763/*
5764 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5765 * Return FALSE when it wasn't.
5766 * Return -1 for an unknown option.
5767 */
5768 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005769was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005770{
5771 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005772 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005773
5774 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005775 {
5776 flagp = insecure_flag(idx, opt_flags);
5777 return (*flagp & P_INSECURE) != 0;
5778 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005779 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005780 return -1;
5781}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005782
5783/*
5784 * Get a pointer to the flags used for the P_INSECURE flag of option
5785 * "opt_idx". For some local options a local flags field is used.
5786 */
5787 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005788insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005789{
5790 if (opt_flags & OPT_LOCAL)
5791 switch ((int)options[opt_idx].indir)
5792 {
5793#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005794 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005795#endif
5796#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005797# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005798 case PV_FDE: return &curwin->w_p_fde_flags;
5799 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005800# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005801# ifdef FEAT_BEVAL
5802 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5803# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005804# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005805 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005806# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005807 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005808# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005809 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005810# endif
5811#endif
5812 }
5813
5814 /* Nothing special, return global flags field. */
5815 return &options[opt_idx].flags;
5816}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005817#endif
5818
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005819#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005820/*
5821 * Redraw the window title and/or tab page text later.
5822 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005823static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005824{
5825 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005826 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005827}
5828#endif
5829
Bram Moolenaar071d4272004-06-13 20:20:40 +00005830/*
5831 * Set a string option to a new value (without checking the effect).
5832 * The string is copied into allocated memory.
5833 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005834 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5835 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5836 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837 */
5838 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005839set_string_option_direct(
5840 char_u *name,
5841 int opt_idx,
5842 char_u *val,
5843 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5844 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845{
5846 char_u *s;
5847 char_u **varp;
5848 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005849 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005850
Bram Moolenaar89d40322006-08-29 15:30:07 +00005851 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005852 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005853 idx = findoption(name);
5854 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005855 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005856 semsg(_(e_intern2), "set_string_option_direct()");
5857 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005859 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005860 }
5861
Bram Moolenaar89d40322006-08-29 15:30:07 +00005862 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005863 return;
5864
5865 s = vim_strsave(val);
5866 if (s != NULL)
5867 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005868 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005869 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005870 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005871 free_string_option(*varp);
5872 *varp = s;
5873
5874 /* For buffer/window local option may also set the global value. */
5875 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005876 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005877
Bram Moolenaar89d40322006-08-29 15:30:07 +00005878 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005879
5880 /* When setting both values of a global option with a local value,
5881 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005882 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883 {
5884 free_string_option(*varp);
5885 *varp = empty_option;
5886 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005887# ifdef FEAT_EVAL
5888 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005889 {
5890 sctx_T script_ctx;
5891
5892 if (set_sid == 0)
5893 script_ctx = current_sctx;
5894 else
5895 {
5896 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005897 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005898 script_ctx.sc_lnum = 0;
5899 }
5900 set_option_sctx_idx(idx, opt_flags, script_ctx);
5901 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005902# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005903 }
5904}
5905
5906/*
5907 * Set global value for string option when it's a local option.
5908 */
5909 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005910set_string_option_global(
5911 int opt_idx, /* option index */
5912 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913{
5914 char_u **p, *s;
5915
5916 /* the global value is always allocated */
5917 if (options[opt_idx].var == VAR_WIN)
5918 p = (char_u **)GLOBAL_WO(varp);
5919 else
5920 p = (char_u **)options[opt_idx].var;
5921 if (options[opt_idx].indir != PV_NONE
5922 && p != varp
5923 && (s = vim_strsave(*varp)) != NULL)
5924 {
5925 free_string_option(*p);
5926 *p = s;
5927 }
5928}
5929
5930/*
5931 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005932 *
5933 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005934 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005935 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005936set_string_option(
5937 int opt_idx,
5938 char_u *value,
5939 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005940{
5941 char_u *s;
5942 char_u **varp;
5943 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005944#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005945 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005946 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005947#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005948 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005949 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950
5951 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005952 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005953
5954 s = vim_strsave(value);
5955 if (s != NULL)
5956 {
5957 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5958 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005959 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005960 ? OPT_GLOBAL : OPT_LOCAL)
5961 : opt_flags);
5962 oldval = *varp;
5963 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005964
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005965#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005966 if (!starting
5967# ifdef FEAT_CRYPT
5968 && options[opt_idx].indir != PV_KEY
5969# endif
5970 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005971 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005972 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005973 saved_newval = vim_strsave(s);
5974 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005975#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005976 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005977 opt_flags, &value_checked)) == NULL)
5978 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02005979
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005980#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005981 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005982 if (r == NULL)
5983 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005984 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005985 vim_free(saved_oldval);
5986 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005988 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005989 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005990}
5991
5992/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005993 * Return TRUE if "val" is a valid 'filetype' name.
5994 * Also used for 'syntax' and 'keymap'.
5995 */
5996 static int
5997valid_filetype(char_u *val)
5998{
5999 char_u *s;
6000
6001 for (s = val; *s != NUL; ++s)
6002 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
6003 return FALSE;
6004 return TRUE;
6005}
6006
6007/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006008 * Handle string options that need some action to perform when changed.
6009 * Returns NULL for success, or an error message for an error.
6010 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006011 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006012did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006013 int opt_idx, // index in options[] table
6014 char_u **varp, // pointer to the option variable
6015 int new_value_alloced, // new value was allocated
6016 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006017 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006018 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6019 int *value_checked) // value was checked to be save, no
6020 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006021{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006022 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006023 char_u *s, *p;
6024 int did_chartab = FALSE;
6025 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006026 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006027#ifdef FEAT_GUI
6028 /* set when changing an option that only requires a redraw in the GUI */
6029 int redraw_gui_only = FALSE;
6030#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006031 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006032#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6033 int did_swaptcap = FALSE;
6034#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006035
6036 /* Get the global option to compare with, otherwise we would have to check
6037 * two values for all local options. */
6038 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6039
6040 /* Disallow changing some options from secure mode */
6041 if ((secure
6042#ifdef HAVE_SANDBOX
6043 || sandbox != 0
6044#endif
6045 ) && (options[opt_idx].flags & P_SECURE))
6046 {
6047 errmsg = e_secure;
6048 }
6049
Bram Moolenaar916a8182018-11-25 02:18:29 +01006050 // Check for a "normal" directory or file name in some options. Disallow a
6051 // path separator (slash and/or backslash), wildcards and characters that
6052 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006053 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006054 && vim_strpbrk(*varp, (char_u *)(secure
6055 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006056 || ((options[opt_idx].flags & P_NDNAME)
6057 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006058 {
6059 errmsg = e_invarg;
6060 }
6061
Bram Moolenaar071d4272004-06-13 20:20:40 +00006062 /* 'term' */
6063 else if (varp == &T_NAME)
6064 {
6065 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006066 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006067#ifdef FEAT_GUI
6068 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006069 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006070 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006071 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006072#endif
6073 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006074 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006075 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006076 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006077 /* Screen colors may have changed. */
6078 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006079
6080 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6081 * P_ALLOCED flag on 'term'. */
6082 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006083 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006084 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006085 }
6086
6087 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006088 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006089 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006090 char_u *bkc = p_bkc;
6091 unsigned int *flags = &bkc_flags;
6092
6093 if (opt_flags & OPT_LOCAL)
6094 {
6095 bkc = curbuf->b_p_bkc;
6096 flags = &curbuf->b_bkc_flags;
6097 }
6098
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006099 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6100 /* make the local value empty: use the global value */
6101 *flags = 0;
6102 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006103 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006104 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6105 errmsg = e_invarg;
6106 if ((((int)*flags & BKC_AUTO) != 0)
6107 + (((int)*flags & BKC_YES) != 0)
6108 + (((int)*flags & BKC_NO) != 0) != 1)
6109 {
6110 /* Must have exactly one of "auto", "yes" and "no". */
6111 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6112 errmsg = e_invarg;
6113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006114 }
6115 }
6116
6117 /* 'backupext' and 'patchmode' */
6118 else if (varp == &p_bex || varp == &p_pm)
6119 {
6120 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6121 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006122 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006124#ifdef FEAT_LINEBREAK
6125 /* 'breakindentopt' */
6126 else if (varp == &curwin->w_p_briopt)
6127 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006128 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006129 errmsg = e_invarg;
6130 }
6131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132
6133 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006134 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006135 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006136 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 */
6138 else if ( varp == &p_isi
6139 || varp == &(curbuf->b_p_isk)
6140 || varp == &p_isp
6141 || varp == &p_isf)
6142 {
6143 if (init_chartab() == FAIL)
6144 {
6145 did_chartab = TRUE; /* need to restore it below */
6146 errmsg = e_invarg; /* error in value */
6147 }
6148 }
6149
6150 /* 'helpfile' */
6151 else if (varp == &p_hf)
6152 {
6153 /* May compute new values for $VIM and $VIMRUNTIME */
6154 if (didset_vim)
6155 {
6156 vim_setenv((char_u *)"VIM", (char_u *)"");
6157 didset_vim = FALSE;
6158 }
6159 if (didset_vimruntime)
6160 {
6161 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6162 didset_vimruntime = FALSE;
6163 }
6164 }
6165
Bram Moolenaar1a384422010-07-14 19:53:30 +02006166#ifdef FEAT_SYN_HL
6167 /* 'colorcolumn' */
6168 else if (varp == &curwin->w_p_cc)
6169 errmsg = check_colorcolumn(curwin);
6170#endif
6171
Bram Moolenaar071d4272004-06-13 20:20:40 +00006172#ifdef FEAT_MULTI_LANG
6173 /* 'helplang' */
6174 else if (varp == &p_hlg)
6175 {
6176 /* Check for "", "ab", "ab,cd", etc. */
6177 for (s = p_hlg; *s != NUL; s += 3)
6178 {
6179 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6180 {
6181 errmsg = e_invarg;
6182 break;
6183 }
6184 if (s[2] == NUL)
6185 break;
6186 }
6187 }
6188#endif
6189
6190 /* 'highlight' */
6191 else if (varp == &p_hl)
6192 {
6193 if (highlight_changed() == FAIL)
6194 errmsg = e_invarg; /* invalid flags */
6195 }
6196
6197 /* 'nrformats' */
6198 else if (gvarp == &p_nf)
6199 {
6200 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6201 errmsg = e_invarg;
6202 }
6203
6204#ifdef FEAT_SESSION
6205 /* 'sessionoptions' */
6206 else if (varp == &p_ssop)
6207 {
6208 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6209 errmsg = e_invarg;
6210 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6211 {
6212 /* Don't allow both "sesdir" and "curdir". */
6213 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6214 errmsg = e_invarg;
6215 }
6216 }
6217 /* 'viewoptions' */
6218 else if (varp == &p_vop)
6219 {
6220 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6221 errmsg = e_invarg;
6222 }
6223#endif
6224
6225 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006226 else if (varp == &p_sbo)
6227 {
6228 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6229 errmsg = e_invarg;
6230 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006231
6232 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006233 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006234 {
6235 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6236 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006237 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006238 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006239 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006240 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006242
6243 /* 'background' */
6244 else if (varp == &p_bg)
6245 {
6246 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6247 {
6248#ifdef FEAT_EVAL
6249 int dark = (*p_bg == 'd');
6250#endif
6251
6252 init_highlight(FALSE, FALSE);
6253
6254#ifdef FEAT_EVAL
6255 if (dark != (*p_bg == 'd')
6256 && get_var_value((char_u *)"g:colors_name") != NULL)
6257 {
6258 /* The color scheme must have set 'background' back to another
6259 * value, that's not what we want here. Disable the color
6260 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006261 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006262 free_string_option(p_bg);
6263 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6264 check_string_option(&p_bg);
6265 init_highlight(FALSE, FALSE);
6266 }
6267#endif
6268 }
6269 else
6270 errmsg = e_invarg;
6271 }
6272
6273 /* 'wildmode' */
6274 else if (varp == &p_wim)
6275 {
6276 if (check_opt_wim() == FAIL)
6277 errmsg = e_invarg;
6278 }
6279
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006280#ifdef FEAT_CMDL_COMPL
6281 /* 'wildoptions' */
6282 else if (varp == &p_wop)
6283 {
6284 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6285 errmsg = e_invarg;
6286 }
6287#endif
6288
Bram Moolenaar071d4272004-06-13 20:20:40 +00006289#ifdef FEAT_WAK
6290 /* 'winaltkeys' */
6291 else if (varp == &p_wak)
6292 {
6293 if (*p_wak == NUL
6294 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6295 errmsg = e_invarg;
6296# ifdef FEAT_MENU
6297# ifdef FEAT_GUI_MOTIF
6298 else if (gui.in_use)
6299 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6300# else
6301# ifdef FEAT_GUI_GTK
6302 else if (gui.in_use)
6303 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6304# endif
6305# endif
6306# endif
6307 }
6308#endif
6309
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310 /* 'eventignore' */
6311 else if (varp == &p_ei)
6312 {
6313 if (check_ei() == FAIL)
6314 errmsg = e_invarg;
6315 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006317 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6318 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6319 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006320 {
6321 if (gvarp == &p_fenc)
6322 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006323 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006324 errmsg = e_modifiable;
6325 else if (vim_strchr(*varp, ',') != NULL)
6326 /* No comma allowed in 'fileencoding'; catches confusing it
6327 * with 'fileencodings'. */
6328 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006329 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006330 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006331#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006332 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006333 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006334#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006335 /* Add 'fileencoding' to the swap file. */
6336 ml_setflags(curbuf);
6337 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006338 }
6339 if (errmsg == NULL)
6340 {
6341 /* canonize the value, so that STRCMP() can be used on it */
6342 p = enc_canonize(*varp);
6343 if (p != NULL)
6344 {
6345 vim_free(*varp);
6346 *varp = p;
6347 }
6348 if (varp == &p_enc)
6349 {
6350 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006351#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006352 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354 }
6355 }
6356
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006357#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006358 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6359 {
6360 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6361 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006362 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006363 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006364#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006365
6366 if (errmsg == NULL)
6367 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006368#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006369 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6370 * (with another encoding). */
6371 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6372 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006374
6375 /* When 'termencoding' is not empty and 'encoding' changes or when
6376 * 'termencoding' changes, need to setup for keyboard input and
6377 * display output conversion. */
6378 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6379 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006380 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6381 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6382 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006383 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006384 p_tenc, p_enc);
6385 errmsg = e_invarg;
6386 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006387 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006388
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006389#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006390 /* $HOME may have characters in active code page. */
6391 if (varp == &p_enc)
6392 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006393#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006394 }
6395 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396
6397#if defined(FEAT_POSTSCRIPT)
6398 else if (varp == &p_penc)
6399 {
6400 /* Canonize printencoding if VIM standard one */
6401 p = enc_canonize(p_penc);
6402 if (p != NULL)
6403 {
6404 vim_free(p_penc);
6405 p_penc = p;
6406 }
6407 else
6408 {
6409 /* Ensure lower case and '-' for '_' */
6410 for (s = p_penc; *s != NUL; s++)
6411 {
6412 if (*s == '_')
6413 *s = '-';
6414 else
6415 *s = TOLOWER_ASC(*s);
6416 }
6417 }
6418 }
6419#endif
6420
Bram Moolenaar9372a112005-12-06 19:59:18 +00006421#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006422 else if (varp == &p_imak)
6423 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006424 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006425 errmsg = e_invarg;
6426 }
6427#endif
6428
6429#ifdef FEAT_KEYMAP
6430 else if (varp == &curbuf->b_p_keymap)
6431 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006432 if (!valid_filetype(*varp))
6433 errmsg = e_invarg;
6434 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006435 {
6436 int secure_save = secure;
6437
6438 // Reset the secure flag, since the value of 'keymap' has
6439 // been checked to be safe.
6440 secure = 0;
6441
6442 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006443 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006444
Bram Moolenaar916a8182018-11-25 02:18:29 +01006445 secure = secure_save;
6446
6447 // Since we check the value, there is no need to set P_INSECURE,
6448 // even when the value comes from a modeline.
6449 *value_checked = TRUE;
6450 }
6451
Bram Moolenaarfab06232009-03-04 03:13:35 +00006452 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006453 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006454 if (*curbuf->b_p_keymap != NUL)
6455 {
6456 /* Installed a new keymap, switch on using it. */
6457 curbuf->b_p_iminsert = B_IMODE_LMAP;
6458 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6459 curbuf->b_p_imsearch = B_IMODE_LMAP;
6460 }
6461 else
6462 {
6463 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6464 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6465 curbuf->b_p_iminsert = B_IMODE_NONE;
6466 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6467 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6468 }
6469 if ((opt_flags & OPT_LOCAL) == 0)
6470 {
6471 set_iminsert_global();
6472 set_imsearch_global();
6473 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006474 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006475 }
6476 }
6477#endif
6478
6479 /* 'fileformat' */
6480 else if (gvarp == &p_ff)
6481 {
6482 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6483 errmsg = e_modifiable;
6484 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6485 errmsg = e_invarg;
6486 else
6487 {
6488 /* may also change 'textmode' */
6489 if (get_fileformat(curbuf) == EOL_DOS)
6490 curbuf->b_p_tx = TRUE;
6491 else
6492 curbuf->b_p_tx = FALSE;
6493#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006494 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006495#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006496 /* update flag in swap file */
6497 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006498 /* Redraw needed when switching to/from "mac": a CR in the text
6499 * will be displayed differently. */
6500 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6501 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006502 }
6503 }
6504
6505 /* 'fileformats' */
6506 else if (varp == &p_ffs)
6507 {
6508 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6509 errmsg = e_invarg;
6510 else
6511 {
6512 /* also change 'textauto' */
6513 if (*p_ffs == NUL)
6514 p_ta = FALSE;
6515 else
6516 p_ta = TRUE;
6517 }
6518 }
6519
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006520#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521 /* 'cryptkey' */
6522 else if (gvarp == &p_key)
6523 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006524# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006525 /* Make sure the ":set" command doesn't show the new value in the
6526 * history. */
6527 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006528# endif
6529 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6530 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006531 ml_set_crypt_key(curbuf, oldval,
6532 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006533 }
6534
6535 else if (gvarp == &p_cm)
6536 {
6537 if (opt_flags & OPT_LOCAL)
6538 p = curbuf->b_p_cm;
6539 else
6540 p = p_cm;
6541 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6542 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006543 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006544 errmsg = e_invarg;
6545 else
6546 {
6547 /* When setting the global value to empty, make it "zip". */
6548 if (*p_cm == NUL)
6549 {
6550 if (new_value_alloced)
6551 free_string_option(p_cm);
6552 p_cm = vim_strsave((char_u *)"zip");
6553 new_value_alloced = TRUE;
6554 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006555 /* When using ":set cm=name" the local value is going to be empty.
6556 * Do that here, otherwise the crypt functions will still use the
6557 * local value. */
6558 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6559 {
6560 free_string_option(curbuf->b_p_cm);
6561 curbuf->b_p_cm = empty_option;
6562 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006563
6564 /* Need to update the swapfile when the effective method changed.
6565 * Set "s" to the effective old value, "p" to the effective new
6566 * method and compare. */
6567 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6568 s = p_cm; /* was previously using the global value */
6569 else
6570 s = oldval;
6571 if (*curbuf->b_p_cm == NUL)
6572 p = p_cm; /* is now using the global value */
6573 else
6574 p = curbuf->b_p_cm;
6575 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006576 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006577
6578 /* If the global value changes need to update the swapfile for all
6579 * buffers using that value. */
6580 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6581 {
6582 buf_T *buf;
6583
Bram Moolenaar29323592016-07-24 22:04:11 +02006584 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006585 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006586 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006587 }
6588 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006589 }
6590#endif
6591
6592 /* 'matchpairs' */
6593 else if (gvarp == &p_mps)
6594 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006595 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006596 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006597 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006598 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006599 int x2 = -1;
6600 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006601
6602 if (*p != NUL)
6603 p += mb_ptr2len(p);
6604 if (*p != NUL)
6605 x2 = *p++;
6606 if (*p != NUL)
6607 {
6608 x3 = mb_ptr2char(p);
6609 p += mb_ptr2len(p);
6610 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006611 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006612 {
6613 errmsg = e_invarg;
6614 break;
6615 }
6616 if (*p == NUL)
6617 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006618 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006619 }
6620 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006621 {
6622 /* Check for "x:y,x:y" */
6623 for (p = *varp; *p != NUL; p += 4)
6624 {
6625 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6626 {
6627 errmsg = e_invarg;
6628 break;
6629 }
6630 if (p[3] == NUL)
6631 break;
6632 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006633 }
6634 }
6635
6636#ifdef FEAT_COMMENTS
6637 /* 'comments' */
6638 else if (gvarp == &p_com)
6639 {
6640 for (s = *varp; *s; )
6641 {
6642 while (*s && *s != ':')
6643 {
6644 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6645 && !VIM_ISDIGIT(*s) && *s != '-')
6646 {
6647 errmsg = illegal_char(errbuf, *s);
6648 break;
6649 }
6650 ++s;
6651 }
6652 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006653 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006655 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006656 if (errmsg != NULL)
6657 break;
6658 while (*s && *s != ',')
6659 {
6660 if (*s == '\\' && s[1] != NUL)
6661 ++s;
6662 ++s;
6663 }
6664 s = skip_to_option_part(s);
6665 }
6666 }
6667#endif
6668
6669 /* 'listchars' */
6670 else if (varp == &p_lcs)
6671 {
6672 errmsg = set_chars_option(varp);
6673 }
6674
Bram Moolenaar071d4272004-06-13 20:20:40 +00006675 /* 'fillchars' */
6676 else if (varp == &p_fcs)
6677 {
6678 errmsg = set_chars_option(varp);
6679 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006680
6681#ifdef FEAT_CMDWIN
6682 /* 'cedit' */
6683 else if (varp == &p_cedit)
6684 {
6685 errmsg = check_cedit();
6686 }
6687#endif
6688
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006689 /* 'verbosefile' */
6690 else if (varp == &p_vfile)
6691 {
6692 verbose_stop();
6693 if (*p_vfile != NUL && verbose_open() == FAIL)
6694 errmsg = e_invarg;
6695 }
6696
Bram Moolenaar071d4272004-06-13 20:20:40 +00006697#ifdef FEAT_VIMINFO
6698 /* 'viminfo' */
6699 else if (varp == &p_viminfo)
6700 {
6701 for (s = p_viminfo; *s;)
6702 {
6703 /* Check it's a valid character */
6704 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6705 {
6706 errmsg = illegal_char(errbuf, *s);
6707 break;
6708 }
6709 if (*s == 'n') /* name is always last one */
6710 {
6711 break;
6712 }
6713 else if (*s == 'r') /* skip until next ',' */
6714 {
6715 while (*++s && *s != ',')
6716 ;
6717 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006718 else if (*s == '%')
6719 {
6720 /* optional number */
6721 while (vim_isdigit(*++s))
6722 ;
6723 }
6724 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006725 ++s; /* no extra chars */
6726 else /* must have a number */
6727 {
6728 while (vim_isdigit(*++s))
6729 ;
6730
6731 if (!VIM_ISDIGIT(*(s - 1)))
6732 {
6733 if (errbuf != NULL)
6734 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006735 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006736 transchar_byte(*(s - 1)));
6737 errmsg = errbuf;
6738 }
6739 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006740 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006741 break;
6742 }
6743 }
6744 if (*s == ',')
6745 ++s;
6746 else if (*s)
6747 {
6748 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006749 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006750 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006751 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006752 break;
6753 }
6754 }
6755 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006756 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 }
6758#endif /* FEAT_VIMINFO */
6759
6760 /* terminal options */
6761 else if (istermoption(&options[opt_idx]) && full_screen)
6762 {
6763 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6764 if (varp == &T_CCO)
6765 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006766 int colors = atoi((char *)T_CCO);
6767
6768 /* Only reinitialize colors if t_Co value has really changed to
6769 * avoid expensive reload of colorscheme if t_Co is set to the
6770 * same value multiple times. */
6771 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006772 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006773 t_colors = colors;
6774 if (t_colors <= 1)
6775 {
6776 if (new_value_alloced)
6777 vim_free(T_CCO);
6778 T_CCO = empty_option;
6779 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006780#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6781 if (is_term_win32())
6782 {
6783 swap_tcap();
6784 did_swaptcap = TRUE;
6785 }
6786#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006787 /* We now have a different color setup, initialize it again. */
6788 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006789 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 }
6791 ttest(FALSE);
6792 if (varp == &T_ME)
6793 {
6794 out_str(T_ME);
6795 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006796#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006797 /* Since t_me has been set, this probably means that the user
6798 * wants to use this as default colors. Need to reset default
6799 * background/foreground colors. */
6800 mch_set_normal_colors();
6801#endif
6802 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006803 if (varp == &T_BE && termcap_active)
6804 {
6805 if (*T_BE == NUL)
6806 /* When clearing t_BE we assume the user no longer wants
6807 * bracketed paste, thus disable it by writing t_BD. */
6808 out_str(T_BD);
6809 else
6810 out_str(T_BE);
6811 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006812 }
6813
6814#ifdef FEAT_LINEBREAK
6815 /* 'showbreak' */
6816 else if (varp == &p_sbr)
6817 {
6818 for (s = p_sbr; *s; )
6819 {
6820 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006821 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006822 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006823 }
6824 }
6825#endif
6826
6827#ifdef FEAT_GUI
6828 /* 'guifont' */
6829 else if (varp == &p_guifont)
6830 {
6831 if (gui.in_use)
6832 {
6833 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006834# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 /*
6836 * Put up a font dialog and let the user select a new value.
6837 * If this is cancelled go back to the old value but don't
6838 * give an error message.
6839 */
6840 if (STRCMP(p, "*") == 0)
6841 {
6842 p = gui_mch_font_dialog(oldval);
6843
6844 if (new_value_alloced)
6845 free_string_option(p_guifont);
6846
6847 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6848 new_value_alloced = TRUE;
6849 }
6850# endif
6851 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6852 {
6853# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6854 if (STRCMP(p_guifont, "*") == 0)
6855 {
6856 /* Dialog was cancelled: Keep the old value without giving
6857 * an error message. */
6858 if (new_value_alloced)
6859 free_string_option(p_guifont);
6860 p_guifont = vim_strsave(oldval);
6861 new_value_alloced = TRUE;
6862 }
6863 else
6864# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006865 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006866 }
6867 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006868 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006869 }
6870# ifdef FEAT_XFONTSET
6871 else if (varp == &p_guifontset)
6872 {
6873 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006874 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006875 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006876 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006877 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006878 }
6879# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880 else if (varp == &p_guifontwide)
6881 {
6882 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006883 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006884 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006885 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006886 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006887 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006888#endif
6889
6890#ifdef CURSOR_SHAPE
6891 /* 'guicursor' */
6892 else if (varp == &p_guicursor)
6893 errmsg = parse_shape_opt(SHAPE_CURSOR);
6894#endif
6895
6896#ifdef FEAT_MOUSESHAPE
6897 /* 'mouseshape' */
6898 else if (varp == &p_mouseshape)
6899 {
6900 errmsg = parse_shape_opt(SHAPE_MOUSE);
6901 update_mouseshape(-1);
6902 }
6903#endif
6904
6905#ifdef FEAT_PRINTER
6906 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006907 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006908# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006909 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006910 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006911# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006912#endif
6913
6914#ifdef FEAT_LANGMAP
6915 /* 'langmap' */
6916 else if (varp == &p_langmap)
6917 langmap_set();
6918#endif
6919
6920#ifdef FEAT_LINEBREAK
6921 /* 'breakat' */
6922 else if (varp == &p_breakat)
6923 fill_breakat_flags();
6924#endif
6925
6926#ifdef FEAT_TITLE
6927 /* 'titlestring' and 'iconstring' */
6928 else if (varp == &p_titlestring || varp == &p_iconstring)
6929 {
6930# ifdef FEAT_STL_OPT
6931 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6932
6933 /* NULL => statusline syntax */
6934 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6935 stl_syntax |= flagval;
6936 else
6937 stl_syntax &= ~flagval;
6938# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006939 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006940 }
6941#endif
6942
6943#ifdef FEAT_GUI
6944 /* 'guioptions' */
6945 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006946 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006948 redraw_gui_only = TRUE;
6949 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006950#endif
6951
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006952#if defined(FEAT_GUI_TABLINE)
6953 /* 'guitablabel' */
6954 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006955 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006956 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006957 redraw_gui_only = TRUE;
6958 }
6959 /* 'guitabtooltip' */
6960 else if (varp == &p_gtt)
6961 {
6962 redraw_gui_only = TRUE;
6963 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006964#endif
6965
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6967 /* 'ttymouse' */
6968 else if (varp == &p_ttym)
6969 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006970 /* Switch the mouse off before changing the escape sequences used for
6971 * that. */
6972 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006973 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6974 errmsg = e_invarg;
6975 else
6976 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006977 if (termcap_active)
6978 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 }
6980#endif
6981
Bram Moolenaar071d4272004-06-13 20:20:40 +00006982 /* 'selection' */
6983 else if (varp == &p_sel)
6984 {
6985 if (*p_sel == NUL
6986 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6987 errmsg = e_invarg;
6988 }
6989
6990 /* 'selectmode' */
6991 else if (varp == &p_slm)
6992 {
6993 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6994 errmsg = e_invarg;
6995 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006996
6997#ifdef FEAT_BROWSE
6998 /* 'browsedir' */
6999 else if (varp == &p_bsdir)
7000 {
7001 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7002 && !mch_isdir(p_bsdir))
7003 errmsg = e_invarg;
7004 }
7005#endif
7006
Bram Moolenaar071d4272004-06-13 20:20:40 +00007007 /* 'keymodel' */
7008 else if (varp == &p_km)
7009 {
7010 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7011 errmsg = e_invarg;
7012 else
7013 {
7014 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7015 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7016 }
7017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018
7019 /* 'mousemodel' */
7020 else if (varp == &p_mousem)
7021 {
7022 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7023 errmsg = e_invarg;
7024#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7025 else if (*p_mousem != *oldval)
7026 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7027 * to create or delete the popup menus. */
7028 gui_motif_update_mousemodel(root_menu);
7029#endif
7030 }
7031
7032 /* 'switchbuf' */
7033 else if (varp == &p_swb)
7034 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007035 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036 errmsg = e_invarg;
7037 }
7038
7039 /* 'debug' */
7040 else if (varp == &p_debug)
7041 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007042 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043 errmsg = e_invarg;
7044 }
7045
7046 /* 'display' */
7047 else if (varp == &p_dy)
7048 {
7049 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7050 errmsg = e_invarg;
7051 else
7052 (void)init_chartab();
7053
7054 }
7055
Bram Moolenaar071d4272004-06-13 20:20:40 +00007056 /* 'eadirection' */
7057 else if (varp == &p_ead)
7058 {
7059 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7060 errmsg = e_invarg;
7061 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007062
7063#ifdef FEAT_CLIPBOARD
7064 /* 'clipboard' */
7065 else if (varp == &p_cb)
7066 errmsg = check_clipboard_option();
7067#endif
7068
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007069#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007070 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7071 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007072 else if (varp == &(curwin->w_s->b_p_spl)
7073 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007074 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007075 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007076 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007077 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007078 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007079 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007080 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007081 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007082 /* 'spellsuggest' */
7083 else if (varp == &p_sps)
7084 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007085 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007086 errmsg = e_invarg;
7087 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007088 /* 'mkspellmem' */
7089 else if (varp == &p_msm)
7090 {
7091 if (spell_check_msm() != OK)
7092 errmsg = e_invarg;
7093 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007094#endif
7095
Bram Moolenaar071d4272004-06-13 20:20:40 +00007096 /* When 'bufhidden' is set, check for valid value. */
7097 else if (gvarp == &p_bh)
7098 {
7099 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7100 errmsg = e_invarg;
7101 }
7102
7103 /* When 'buftype' is set, check for valid value. */
7104 else if (gvarp == &p_bt)
7105 {
7106 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7107 errmsg = e_invarg;
7108 else
7109 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110 if (curwin->w_status_height)
7111 {
7112 curwin->w_redr_status = TRUE;
7113 redraw_later(VALID);
7114 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007115 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007116#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007117 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007118#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 }
7120 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121
7122#ifdef FEAT_STL_OPT
7123 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007124 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125 {
7126 int wid;
7127
7128 if (varp == &p_ruf) /* reset ru_wid first */
7129 ru_wid = 0;
7130 s = *varp;
7131 if (varp == &p_ruf && *s == '%')
7132 {
7133 /* set ru_wid if 'ruf' starts with "%99(" */
7134 if (*++s == '-') /* ignore a '-' */
7135 s++;
7136 wid = getdigits(&s);
7137 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7138 ru_wid = wid;
7139 else
7140 errmsg = check_stl_option(p_ruf);
7141 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007142 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007143 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007145 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007146 comp_col();
7147 }
7148#endif
7149
7150#ifdef FEAT_INS_EXPAND
7151 /* check if it is a valid value for 'complete' -- Acevedo */
7152 else if (gvarp == &p_cpt)
7153 {
7154 for (s = *varp; *s;)
7155 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007156 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007157 s++;
7158 if (!*s)
7159 break;
7160 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7161 {
7162 errmsg = illegal_char(errbuf, *s);
7163 break;
7164 }
7165 if (*++s != NUL && *s != ',' && *s != ' ')
7166 {
7167 if (s[-1] == 'k' || s[-1] == 's')
7168 {
7169 /* skip optional filename after 'k' and 's' */
7170 while (*s && *s != ',' && *s != ' ')
7171 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007172 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007173 ++s;
7174 ++s;
7175 }
7176 }
7177 else
7178 {
7179 if (errbuf != NULL)
7180 {
7181 sprintf((char *)errbuf,
7182 _("E535: Illegal character after <%c>"),
7183 *--s);
7184 errmsg = errbuf;
7185 }
7186 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007187 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007188 break;
7189 }
7190 }
7191 }
7192 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007193
7194 /* 'completeopt' */
7195 else if (varp == &p_cot)
7196 {
7197 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7198 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007199 else
7200 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007201 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007202#endif /* FEAT_INS_EXPAND */
7203
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007204#ifdef FEAT_SIGNS
7205 /* 'signcolumn' */
7206 else if (varp == &curwin->w_p_scl)
7207 {
7208 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7209 errmsg = e_invarg;
7210 }
7211#endif
7212
Bram Moolenaar071d4272004-06-13 20:20:40 +00007213
7214#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007215 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007216 else if (varp == &p_toolbar)
7217 {
7218 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7219 &toolbar_flags, TRUE) != OK)
7220 errmsg = e_invarg;
7221 else
7222 {
7223 out_flush();
7224 gui_mch_show_toolbar((toolbar_flags &
7225 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7226 }
7227 }
7228#endif
7229
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007230#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007231 /* 'toolbariconsize': GTK+ 2 only */
7232 else if (varp == &p_tbis)
7233 {
7234 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7235 errmsg = e_invarg;
7236 else
7237 {
7238 out_flush();
7239 gui_mch_show_toolbar((toolbar_flags &
7240 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7241 }
7242 }
7243#endif
7244
7245 /* 'pastetoggle': translate key codes like in a mapping */
7246 else if (varp == &p_pt)
7247 {
7248 if (*p_pt)
7249 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007250 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251 if (p != NULL)
7252 {
7253 if (new_value_alloced)
7254 free_string_option(p_pt);
7255 p_pt = p;
7256 new_value_alloced = TRUE;
7257 }
7258 }
7259 }
7260
7261 /* 'backspace' */
7262 else if (varp == &p_bs)
7263 {
7264 if (VIM_ISDIGIT(*p_bs))
7265 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007266 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007267 errmsg = e_invarg;
7268 }
7269 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7270 errmsg = e_invarg;
7271 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007272 else if (varp == &p_bo)
7273 {
7274 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7275 errmsg = e_invarg;
7276 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007277
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007278 /* 'tagcase' */
7279 else if (gvarp == &p_tc)
7280 {
7281 unsigned int *flags;
7282
7283 if (opt_flags & OPT_LOCAL)
7284 {
7285 p = curbuf->b_p_tc;
7286 flags = &curbuf->b_tc_flags;
7287 }
7288 else
7289 {
7290 p = p_tc;
7291 flags = &tc_flags;
7292 }
7293
7294 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7295 /* make the local value empty: use the global value */
7296 *flags = 0;
7297 else if (*p == NUL
7298 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7299 errmsg = e_invarg;
7300 }
7301
Bram Moolenaar071d4272004-06-13 20:20:40 +00007302 /* 'casemap' */
7303 else if (varp == &p_cmp)
7304 {
7305 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7306 errmsg = e_invarg;
7307 }
7308
7309#ifdef FEAT_DIFF
7310 /* 'diffopt' */
7311 else if (varp == &p_dip)
7312 {
7313 if (diffopt_changed() == FAIL)
7314 errmsg = e_invarg;
7315 }
7316#endif
7317
7318#ifdef FEAT_FOLDING
7319 /* 'foldmethod' */
7320 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7321 {
7322 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7323 || *curwin->w_p_fdm == NUL)
7324 errmsg = e_invarg;
7325 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007326 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007327 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007328 if (foldmethodIsDiff(curwin))
7329 newFoldLevel();
7330 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007331 }
7332# ifdef FEAT_EVAL
7333 /* 'foldexpr' */
7334 else if (varp == &curwin->w_p_fde)
7335 {
7336 if (foldmethodIsExpr(curwin))
7337 foldUpdateAll(curwin);
7338 }
7339# endif
7340 /* 'foldmarker' */
7341 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7342 {
7343 p = vim_strchr(*varp, ',');
7344 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007345 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007346 else if (p == *varp || p[1] == NUL)
7347 errmsg = e_invarg;
7348 else if (foldmethodIsMarker(curwin))
7349 foldUpdateAll(curwin);
7350 }
7351 /* 'commentstring' */
7352 else if (gvarp == &p_cms)
7353 {
7354 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007355 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007356 }
7357 /* 'foldopen' */
7358 else if (varp == &p_fdo)
7359 {
7360 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7361 errmsg = e_invarg;
7362 }
7363 /* 'foldclose' */
7364 else if (varp == &p_fcl)
7365 {
7366 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7367 errmsg = e_invarg;
7368 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007369 /* 'foldignore' */
7370 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7371 {
7372 if (foldmethodIsIndent(curwin))
7373 foldUpdateAll(curwin);
7374 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007375#endif
7376
7377#ifdef FEAT_VIRTUALEDIT
7378 /* 'virtualedit' */
7379 else if (varp == &p_ve)
7380 {
7381 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7382 errmsg = e_invarg;
7383 else if (STRCMP(p_ve, oldval) != 0)
7384 {
7385 /* Recompute cursor position in case the new 've' setting
7386 * changes something. */
7387 validate_virtcol();
7388 coladvance(curwin->w_virtcol);
7389 }
7390 }
7391#endif
7392
7393#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7394 else if (varp == &p_csqf)
7395 {
7396 if (p_csqf != NULL)
7397 {
7398 p = p_csqf;
7399 while (*p != NUL)
7400 {
7401 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7402 || p[1] == NUL
7403 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7404 || (p[2] != NUL && p[2] != ','))
7405 {
7406 errmsg = e_invarg;
7407 break;
7408 }
7409 else if (p[2] == NUL)
7410 break;
7411 else
7412 p += 3;
7413 }
7414 }
7415 }
7416#endif
7417
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007418#ifdef FEAT_CINDENT
7419 /* 'cinoptions' */
7420 else if (gvarp == &p_cino)
7421 {
7422 /* TODO: recognize errors */
7423 parse_cino(curbuf);
7424 }
7425#endif
7426
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007427#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007428 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007429 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007430 {
7431 if (!gui_mch_set_rendering_options(p_rop))
7432 errmsg = e_invarg;
7433 }
7434#endif
7435
Bram Moolenaard0b51382016-11-04 15:23:45 +01007436 else if (gvarp == &p_ft)
7437 {
7438 if (!valid_filetype(*varp))
7439 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007440 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007441 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007442 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007443
7444 // Since we check the value, there is no need to set P_INSECURE,
7445 // even when the value comes from a modeline.
7446 *value_checked = TRUE;
7447 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007448 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007449
7450#ifdef FEAT_SYN_HL
7451 else if (gvarp == &p_syn)
7452 {
7453 if (!valid_filetype(*varp))
7454 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007455 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007456 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007457 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007458
7459 // Since we check the value, there is no need to set P_INSECURE,
7460 // even when the value comes from a modeline.
7461 *value_checked = TRUE;
7462 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007463 }
7464#endif
7465
Bram Moolenaar825680f2017-07-22 17:04:02 +02007466#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007467 /* 'termwinkey' */
7468 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007469 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007470 if (*curwin->w_p_twk != NUL
7471 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007472 errmsg = e_invarg;
7473 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007474 /* 'termwinsize' */
7475 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007476 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007477 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007478 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007479 p = skipdigits(curwin->w_p_tws);
7480 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007481 || (*p != 'x' && *p != '*')
7482 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007483 errmsg = e_invarg;
7484 }
7485 }
7486#endif
7487
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007488#ifdef FEAT_VARTABS
7489 /* 'varsofttabstop' */
7490 else if (varp == &(curbuf->b_p_vsts))
7491 {
7492 char_u *cp;
7493
7494 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7495 {
7496 if (curbuf->b_p_vsts_array)
7497 {
7498 vim_free(curbuf->b_p_vsts_array);
7499 curbuf->b_p_vsts_array = 0;
7500 }
7501 }
7502 else
7503 {
7504 for (cp = *varp; *cp; ++cp)
7505 {
7506 if (vim_isdigit(*cp))
7507 continue;
7508 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7509 continue;
7510 errmsg = e_invarg;
7511 break;
7512 }
7513 if (errmsg == NULL)
7514 {
7515 int *oldarray = curbuf->b_p_vsts_array;
7516 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7517 {
7518 if (oldarray)
7519 vim_free(oldarray);
7520 }
7521 else
7522 errmsg = e_invarg;
7523 }
7524 }
7525 }
7526
7527 /* 'vartabstop' */
7528 else if (varp == &(curbuf->b_p_vts))
7529 {
7530 char_u *cp;
7531
7532 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7533 {
7534 if (curbuf->b_p_vts_array)
7535 {
7536 vim_free(curbuf->b_p_vts_array);
7537 curbuf->b_p_vts_array = NULL;
7538 }
7539 }
7540 else
7541 {
7542 for (cp = *varp; *cp; ++cp)
7543 {
7544 if (vim_isdigit(*cp))
7545 continue;
7546 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7547 continue;
7548 errmsg = e_invarg;
7549 break;
7550 }
7551 if (errmsg == NULL)
7552 {
7553 int *oldarray = curbuf->b_p_vts_array;
7554 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7555 {
7556 if (oldarray)
7557 vim_free(oldarray);
7558#ifdef FEAT_FOLDING
7559 if (foldmethodIsIndent(curwin))
7560 foldUpdateAll(curwin);
7561#endif /* FEAT_FOLDING */
7562 }
7563 else
7564 errmsg = e_invarg;
7565 }
7566 }
7567 }
7568#endif
7569
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570 /* Options that are a list of flags. */
7571 else
7572 {
7573 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007574 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007575 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007576 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007578 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007579 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007580 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007581 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007582#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007583 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007584 p = (char_u *)COCU_ALL;
7585#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007586 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007587 {
7588#ifdef FEAT_MOUSE
7589 p = (char_u *)MOUSE_ALL;
7590#else
7591 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007592 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007593#endif
7594 }
7595#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007596 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007597 p = (char_u *)GO_ALL;
7598#endif
7599 if (p != NULL)
7600 {
7601 for (s = *varp; *s; ++s)
7602 if (vim_strchr(p, *s) == NULL)
7603 {
7604 errmsg = illegal_char(errbuf, *s);
7605 break;
7606 }
7607 }
7608 }
7609
7610 /*
7611 * If error detected, restore the previous value.
7612 */
7613 if (errmsg != NULL)
7614 {
7615 if (new_value_alloced)
7616 free_string_option(*varp);
7617 *varp = oldval;
7618 /*
7619 * When resetting some values, need to act on it.
7620 */
7621 if (did_chartab)
7622 (void)init_chartab();
7623 if (varp == &p_hl)
7624 (void)highlight_changed();
7625 }
7626 else
7627 {
7628#ifdef FEAT_EVAL
7629 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007630 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007631#endif
7632 /*
7633 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007634 * Use "free_oldval", because recursiveness may change the flags under
7635 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007636 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007637 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007638 free_string_option(oldval);
7639 if (new_value_alloced)
7640 options[opt_idx].flags |= P_ALLOCED;
7641 else
7642 options[opt_idx].flags &= ~P_ALLOCED;
7643
7644 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007645 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007646 {
7647 /* global option with local value set to use global value; free
7648 * the local value and make it empty */
7649 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7650 free_string_option(*(char_u **)p);
7651 *(char_u **)p = empty_option;
7652 }
7653
7654 /* May set global value for local option. */
7655 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7656 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007657
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007658 /*
7659 * Trigger the autocommand only after setting the flags.
7660 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007661#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007662 /* When 'syntax' is set, load the syntax of that name */
7663 if (varp == &(curbuf->b_p_syn))
7664 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007665 static int syn_recursive = 0;
7666
7667 ++syn_recursive;
7668 // Only pass TRUE for "force" when the value changed or not used
7669 // recursively, to avoid endless recurrence.
7670 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7671 value_changed || syn_recursive == 1, curbuf);
7672 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007673 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007674#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007675 else if (varp == &(curbuf->b_p_ft))
7676 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007677 /* 'filetype' is set, trigger the FileType autocommand.
7678 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007679 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007680 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007681 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007682 static int ft_recursive = 0;
7683 int secure_save = secure;
7684
7685 // Reset the secure flag, since the value of 'filetype' has
7686 // been checked to be safe.
7687 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007688
7689 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007690 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007691 // Only pass TRUE for "force" when the value changed or not
7692 // used recursively, to avoid endless recurrence.
7693 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7694 value_changed || ft_recursive == 1, curbuf);
7695 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007696 /* Just in case the old "curbuf" is now invalid. */
7697 if (varp != &(curbuf->b_p_ft))
7698 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007699
7700 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007701 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007702 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007703#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007704 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007705 {
7706 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007707 char_u *q = curwin->w_s->b_p_spl;
7708
7709 /* Skip the first name if it is "cjk". */
7710 if (STRNCMP(q, "cjk,", 4) == 0)
7711 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007712
7713 /*
7714 * Source the spell/LANG.vim in 'runtimepath'.
7715 * They could set 'spellcapcheck' depending on the language.
7716 * Use the first name in 'spelllang' up to '_region' or
7717 * '.encoding'.
7718 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007719 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007720 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007721 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007722 if (p > q)
7723 {
7724 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7725 source_runtime(fname, DIP_ALL);
7726 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007727 }
7728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007729 }
7730
7731#ifdef FEAT_MOUSE
7732 if (varp == &p_mouse)
7733 {
7734# ifdef FEAT_MOUSE_TTY
7735 if (*p_mouse == NUL)
7736 mch_setmouse(FALSE); /* switch mouse off */
7737 else
7738# endif
7739 setmouse(); /* in case 'mouse' changed */
7740 }
7741#endif
7742
Bram Moolenaar913077c2012-03-28 19:59:04 +02007743 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007744 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007745 curwin->w_set_curswant = TRUE;
7746
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007747#ifdef FEAT_GUI
7748 /* check redraw when it's not a GUI option or the GUI is active. */
7749 if (!redraw_gui_only || gui.in_use)
7750#endif
7751 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007752
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007753#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7754 if (did_swaptcap)
7755 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007756 set_termname((char_u *)"win32");
7757 init_highlight(TRUE, FALSE);
7758 }
7759#endif
7760
Bram Moolenaar071d4272004-06-13 20:20:40 +00007761 return errmsg;
7762}
7763
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007764#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007765/*
7766 * Simple int comparison function for use with qsort()
7767 */
7768 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007769int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007770{
7771 return *(const int *)a - *(const int *)b;
7772}
7773
7774/*
7775 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7776 * Returns error message, NULL if it's OK.
7777 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007778 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007779check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007780{
7781 char_u *s;
7782 int col;
7783 int count = 0;
7784 int color_cols[256];
7785 int i;
7786 int j = 0;
7787
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007788 if (wp->w_buffer == NULL)
7789 return NULL; /* buffer was closed */
7790
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007791 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007792 {
7793 if (*s == '-' || *s == '+')
7794 {
7795 /* -N and +N: add to 'textwidth' */
7796 col = (*s == '-') ? -1 : 1;
7797 ++s;
7798 if (!VIM_ISDIGIT(*s))
7799 return e_invarg;
7800 col = col * getdigits(&s);
7801 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007802 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007803 col += wp->w_buffer->b_p_tw;
7804 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007805 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007806 }
7807 else if (VIM_ISDIGIT(*s))
7808 col = getdigits(&s);
7809 else
7810 return e_invarg;
7811 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007812skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007813 if (*s == NUL)
7814 break;
7815 if (*s != ',')
7816 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007817 if (*++s == NUL)
7818 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007819 }
7820
7821 vim_free(wp->w_p_cc_cols);
7822 if (count == 0)
7823 wp->w_p_cc_cols = NULL;
7824 else
7825 {
7826 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7827 if (wp->w_p_cc_cols != NULL)
7828 {
7829 /* sort the columns for faster usage on screen redraw inside
7830 * win_line() */
7831 qsort(color_cols, count, sizeof(int), int_cmp);
7832
7833 for (i = 0; i < count; ++i)
7834 /* skip duplicates */
7835 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7836 wp->w_p_cc_cols[j++] = color_cols[i];
7837 wp->w_p_cc_cols[j] = -1; /* end marker */
7838 }
7839 }
7840
7841 return NULL; /* no error */
7842}
7843#endif
7844
Bram Moolenaar071d4272004-06-13 20:20:40 +00007845/*
7846 * Handle setting 'listchars' or 'fillchars'.
7847 * Returns error message, NULL if it's OK.
7848 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007849 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007850set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007851{
7852 int round, i, len, entries;
7853 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007854 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007855 struct charstab
7856 {
7857 int *cp;
7858 char *name;
7859 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007860 static struct charstab filltab[] =
7861 {
7862 {&fill_stl, "stl"},
7863 {&fill_stlnc, "stlnc"},
7864 {&fill_vert, "vert"},
7865 {&fill_fold, "fold"},
7866 {&fill_diff, "diff"},
7867 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868 static struct charstab lcstab[] =
7869 {
7870 {&lcs_eol, "eol"},
7871 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007872 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007874 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007875 {&lcs_tab2, "tab"},
7876 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007877#ifdef FEAT_CONCEAL
7878 {&lcs_conceal, "conceal"},
7879#else
7880 {NULL, "conceal"},
7881#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007882 };
7883 struct charstab *tab;
7884
Bram Moolenaar071d4272004-06-13 20:20:40 +00007885 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886 {
7887 tab = lcstab;
7888 entries = sizeof(lcstab) / sizeof(struct charstab);
7889 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007890 else
7891 {
7892 tab = filltab;
7893 entries = sizeof(filltab) / sizeof(struct charstab);
7894 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007895
7896 /* first round: check for valid value, second round: assign values */
7897 for (round = 0; round <= 1; ++round)
7898 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007899 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900 {
7901 /* After checking that the value is valid: set defaults: space for
7902 * 'fillchars', NUL for 'listchars' */
7903 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007904 if (tab[i].cp != NULL)
7905 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007906
Bram Moolenaar071d4272004-06-13 20:20:40 +00007907 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007908 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007909 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007910 lcs_tab3 = NUL;
7911 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007912 else
7913 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007914 }
7915 p = *varp;
7916 while (*p)
7917 {
7918 for (i = 0; i < entries; ++i)
7919 {
7920 len = (int)STRLEN(tab[i].name);
7921 if (STRNCMP(p, tab[i].name, len) == 0
7922 && p[len] == ':'
7923 && p[len + 1] != NUL)
7924 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007925 c1 = c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007928 if (mb_char2cells(c1) > 1)
7929 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007930 if (tab[i].cp == &lcs_tab2)
7931 {
7932 if (*s == NUL)
7933 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007934 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007935 if (mb_char2cells(c2) > 1)
7936 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007937 if (!(*s == ',' || *s == NUL))
7938 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007939 c3 = mb_ptr2char_adv(&s);
7940 if (mb_char2cells(c3) > 1)
7941 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007942 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007943 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01007944
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945 if (*s == ',' || *s == NUL)
7946 {
7947 if (round)
7948 {
7949 if (tab[i].cp == &lcs_tab2)
7950 {
7951 lcs_tab1 = c1;
7952 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007953 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007955 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 *(tab[i].cp) = c1;
7957
7958 }
7959 p = s;
7960 break;
7961 }
7962 }
7963 }
7964
7965 if (i == entries)
7966 return e_invarg;
7967 if (*p == ',')
7968 ++p;
7969 }
7970 }
7971
7972 return NULL; /* no error */
7973}
7974
7975#ifdef FEAT_STL_OPT
7976/*
7977 * Check validity of options with the 'statusline' format.
7978 * Return error message or NULL.
7979 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007980 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007981check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007982{
7983 int itemcnt = 0;
7984 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007985 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986
7987 while (*s && itemcnt < STL_MAX_ITEM)
7988 {
7989 /* Check for valid keys after % sequences */
7990 while (*s && *s != '%')
7991 s++;
7992 if (!*s)
7993 break;
7994 s++;
7995 if (*s != '%' && *s != ')')
7996 ++itemcnt;
7997 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7998 {
7999 s++;
8000 continue;
8001 }
8002 if (*s == ')')
8003 {
8004 s++;
8005 if (--groupdepth < 0)
8006 break;
8007 continue;
8008 }
8009 if (*s == '-')
8010 s++;
8011 while (VIM_ISDIGIT(*s))
8012 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008013 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008014 continue;
8015 if (*s == '.')
8016 {
8017 s++;
8018 while (*s && VIM_ISDIGIT(*s))
8019 s++;
8020 }
8021 if (*s == '(')
8022 {
8023 groupdepth++;
8024 continue;
8025 }
8026 if (vim_strchr(STL_ALL, *s) == NULL)
8027 {
8028 return illegal_char(errbuf, *s);
8029 }
8030 if (*s == '{')
8031 {
8032 s++;
8033 while (*s != '}' && *s)
8034 s++;
8035 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008036 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 }
8038 }
8039 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008040 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008041 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008042 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008043 return NULL;
8044}
8045#endif
8046
8047#ifdef FEAT_CLIPBOARD
8048/*
8049 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008050 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008051 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008052 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008053check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008054{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008055 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008056 int new_autoselect_star = FALSE;
8057 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008058 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008059 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008060 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008061 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008062 char_u *p;
8063
8064 for (p = p_cb; *p != NUL; )
8065 {
8066 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8067 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008068 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008069 p += 7;
8070 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008071 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008072 && (p[11] == ',' || p[11] == NUL))
8073 {
8074 new_unnamed |= CLIP_UNNAMED_PLUS;
8075 p += 11;
8076 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008077 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008078 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008079 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008080 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008081 p += 10;
8082 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008083 else if (STRNCMP(p, "autoselectplus", 14) == 0
8084 && (p[14] == ',' || p[14] == NUL))
8085 {
8086 new_autoselect_plus = TRUE;
8087 p += 14;
8088 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008089 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008090 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 {
8092 new_autoselectml = TRUE;
8093 p += 12;
8094 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008095 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8096 {
8097 new_html = TRUE;
8098 p += 4;
8099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008100 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8101 {
8102 p += 8;
8103 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8104 if (new_exclude_prog == NULL)
8105 errmsg = e_invarg;
8106 break;
8107 }
8108 else
8109 {
8110 errmsg = e_invarg;
8111 break;
8112 }
8113 if (*p == ',')
8114 ++p;
8115 }
8116 if (errmsg == NULL)
8117 {
8118 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008119 clip_autoselect_star = new_autoselect_star;
8120 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008121 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008122 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008123 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008125#ifdef FEAT_GUI_GTK
8126 if (gui.in_use)
8127 {
8128 gui_gtk_set_selection_targets();
8129 gui_gtk_set_dnd_targets();
8130 }
8131#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132 }
8133 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008134 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135
8136 return errmsg;
8137}
8138#endif
8139
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008140#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008141/*
8142 * Handle side effects of setting 'spell'.
8143 * Return an error message or NULL for success.
8144 */
8145 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008146did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008147{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008148 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008149 win_T *wp;
8150 int l;
8151
8152 if (is_spellfile)
8153 {
8154 l = (int)STRLEN(curwin->w_s->b_p_spf);
8155 if (l > 0 && (l < 4
8156 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8157 errmsg = e_invarg;
8158 }
8159
8160 if (errmsg == NULL)
8161 {
8162 FOR_ALL_WINDOWS(wp)
8163 if (wp->w_buffer == curbuf && wp->w_p_spell)
8164 {
8165 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008166 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008167 }
8168 }
8169 return errmsg;
8170}
8171
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008172/*
8173 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8174 * Return error message when failed, NULL when OK.
8175 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008176 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008177compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008178{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008179 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008180 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008181
Bram Moolenaar860cae12010-06-05 23:22:07 +02008182 if (*synblock->b_p_spc == NUL)
8183 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008184 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008185 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008186 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008187 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008188 if (re != NULL)
8189 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008190 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008191 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008192 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008193 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008194 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008195 return e_invarg;
8196 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008197 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008198 }
8199
Bram Moolenaar473de612013-06-08 18:19:48 +02008200 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008201 return NULL;
8202}
8203#endif
8204
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008205#if defined(FEAT_EVAL) || defined(PROTO)
8206/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008207 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008208 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008209 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008210 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008211set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008212{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008213 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8214 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008215 sctx_T new_script_ctx = script_ctx;
8216
8217 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008218
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008219 /* Remember where the option was set. For local options need to do that
8220 * in the buffer or window structure. */
8221 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008222 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008223 if (both || (opt_flags & OPT_LOCAL))
8224 {
8225 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008226 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008227 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008228 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008229 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008230}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008231
8232/*
8233 * Set the script_ctx for a termcap option.
8234 * "name" must be the two character code, e.g. "RV".
8235 * When "name" is NULL use "opt_idx".
8236 */
8237 void
8238set_term_option_sctx_idx(char *name, int opt_idx)
8239{
8240 char_u buf[5];
8241 int idx;
8242
8243 if (name == NULL)
8244 idx = opt_idx;
8245 else
8246 {
8247 buf[0] = 't';
8248 buf[1] = '_';
8249 buf[2] = name[0];
8250 buf[3] = name[1];
8251 buf[4] = 0;
8252 idx = findoption(buf);
8253 }
8254 if (idx >= 0)
8255 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8256}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008257#endif
8258
Bram Moolenaar071d4272004-06-13 20:20:40 +00008259/*
8260 * Set the value of a boolean option, and take care of side effects.
8261 * Returns NULL for success, or an error message for an error.
8262 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008263 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008264set_bool_option(
8265 int opt_idx, /* index in options[] table */
8266 char_u *varp, /* pointer to the option variable */
8267 int value, /* new value */
8268 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008269{
8270 int old_value = *(int *)varp;
8271
Bram Moolenaar071d4272004-06-13 20:20:40 +00008272 /* Disallow changing some options from secure mode */
8273 if ((secure
8274#ifdef HAVE_SANDBOX
8275 || sandbox != 0
8276#endif
8277 ) && (options[opt_idx].flags & P_SECURE))
8278 return e_secure;
8279
8280 *(int *)varp = value; /* set the new value */
8281#ifdef FEAT_EVAL
8282 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008283 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008284#endif
8285
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008286#ifdef FEAT_GUI
8287 need_mouse_correct = TRUE;
8288#endif
8289
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 /* May set global value for local option. */
8291 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8292 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8293
8294 /*
8295 * Handle side effects of changing a bool option.
8296 */
8297
8298 /* 'compatible' */
8299 if ((int *)varp == &p_cp)
8300 {
8301 compatible_set();
8302 }
8303
Bram Moolenaar920694c2016-08-21 17:45:02 +02008304#ifdef FEAT_LANGMAP
8305 if ((int *)varp == &p_lrm)
8306 /* 'langremap' -> !'langnoremap' */
8307 p_lnr = !p_lrm;
8308 else if ((int *)varp == &p_lnr)
8309 /* 'langnoremap' -> !'langremap' */
8310 p_lrm = !p_lnr;
8311#endif
8312
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008313#ifdef FEAT_SYN_HL
8314 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8315 reset_cursorline();
8316#endif
8317
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008318#ifdef FEAT_PERSISTENT_UNDO
8319 /* 'undofile' */
8320 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8321 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008322 /* Only take action when the option was set. When reset we do not
8323 * delete the undo file, the option may be set again without making
8324 * any changes in between. */
8325 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008326 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008327 char_u hash[UNDO_HASH_SIZE];
8328 buf_T *save_curbuf = curbuf;
8329
Bram Moolenaar29323592016-07-24 22:04:11 +02008330 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008331 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008332 /* When 'undofile' is set globally: for every buffer, otherwise
8333 * only for the current buffer: Try to read in the undofile,
8334 * if one exists, the buffer wasn't changed and the buffer was
8335 * loaded */
8336 if ((curbuf == save_curbuf
8337 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8338 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8339 {
8340 u_compute_hash(hash);
8341 u_read_undo(NULL, hash, curbuf->b_fname);
8342 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008343 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008344 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008345 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008346 }
8347#endif
8348
Bram Moolenaar071d4272004-06-13 20:20:40 +00008349 else if ((int *)varp == &curbuf->b_p_ro)
8350 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008351 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8353 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008354
8355 /* when 'readonly' is set may give W10 again */
8356 if (curbuf->b_p_ro)
8357 curbuf->b_did_warn = FALSE;
8358
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008360 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008361#endif
8362 }
8363
Bram Moolenaar9c449722010-07-20 18:44:27 +02008364#ifdef FEAT_GUI
8365 else if ((int *)varp == &p_mh)
8366 {
8367 if (!p_mh)
8368 gui_mch_mousehide(FALSE);
8369 }
8370#endif
8371
Bram Moolenaara539df02010-08-01 14:35:05 +02008372 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008373 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008374 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008375# ifdef FEAT_TERMINAL
8376 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008377 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8378 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008379 {
8380 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008381 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008382 }
8383# endif
8384# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008385 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008386# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008387 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008388#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389 /* when 'endofline' is changed, redraw the window title */
8390 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008391 {
8392 redraw_titles();
8393 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008394 /* when 'fixeol' is changed, redraw the window title */
8395 else if ((int *)varp == &curbuf->b_p_fixeol)
8396 {
8397 redraw_titles();
8398 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008399 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008400 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008401 {
8402 redraw_titles();
8403 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404#endif
8405
8406 /* when 'bin' is set also set some other options */
8407 else if ((int *)varp == &curbuf->b_p_bin)
8408 {
8409 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8410#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008411 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412#endif
8413 }
8414
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415 /* when 'buflisted' changes, trigger autocommands */
8416 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8417 {
8418 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8419 NULL, NULL, TRUE, curbuf);
8420 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421
8422 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8423 else if ((int *)varp == &curbuf->b_p_swf)
8424 {
8425 if (curbuf->b_p_swf && p_uc)
8426 ml_open_file(curbuf); /* create the swap file */
8427 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008428 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8429 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008430 mf_close_file(curbuf, TRUE); /* remove the swap file */
8431 }
8432
8433 /* when 'terse' is set change 'shortmess' */
8434 else if ((int *)varp == &p_terse)
8435 {
8436 char_u *p;
8437
8438 p = vim_strchr(p_shm, SHM_SEARCH);
8439
8440 /* insert 's' in p_shm */
8441 if (p_terse && p == NULL)
8442 {
8443 STRCPY(IObuff, p_shm);
8444 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008445 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008446 }
8447 /* remove 's' from p_shm */
8448 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008449 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008450 }
8451
8452 /* when 'paste' is set or reset also change other options */
8453 else if ((int *)varp == &p_paste)
8454 {
8455 paste_option_changed();
8456 }
8457
8458 /* when 'insertmode' is set from an autocommand need to do work here */
8459 else if ((int *)varp == &p_im)
8460 {
8461 if (p_im)
8462 {
8463 if ((State & INSERT) == 0)
8464 need_start_insertmode = TRUE;
8465 stop_insert_mode = FALSE;
8466 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008467 /* only reset if it was set previously */
8468 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008469 {
8470 need_start_insertmode = FALSE;
8471 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008472 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 clear_cmdline = TRUE; /* remove "(insert)" */
8474 restart_edit = 0;
8475 }
8476 }
8477
8478 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8479 else if ((int *)varp == &p_ic && p_hls)
8480 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008481 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008482 }
8483
8484#ifdef FEAT_SEARCH_EXTRA
8485 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8486 else if ((int *)varp == &p_hls)
8487 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008488 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489 }
8490#endif
8491
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8493 * at the end of normal_cmd() */
8494 else if ((int *)varp == &curwin->w_p_scb)
8495 {
8496 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008497 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008498 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008499 curwin->w_scbind_pos = curwin->w_topline;
8500 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008501 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008502
Bram Moolenaar4033c552017-09-16 20:54:51 +02008503#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008504 /* There can be only one window with 'previewwindow' set. */
8505 else if ((int *)varp == &curwin->w_p_pvw)
8506 {
8507 if (curwin->w_p_pvw)
8508 {
8509 win_T *win;
8510
Bram Moolenaar29323592016-07-24 22:04:11 +02008511 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512 if (win->w_p_pvw && win != curwin)
8513 {
8514 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008515 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008516 }
8517 }
8518 }
8519#endif
8520
8521 /* when 'textmode' is set or reset also change 'fileformat' */
8522 else if ((int *)varp == &curbuf->b_p_tx)
8523 {
8524 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8525 }
8526
8527 /* when 'textauto' is set or reset also change 'fileformats' */
8528 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529 set_string_option_direct((char_u *)"ffs", -1,
8530 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008531 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008532
8533 /*
8534 * When 'lisp' option changes include/exclude '-' in
8535 * keyword characters.
8536 */
8537#ifdef FEAT_LISP
8538 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8539 {
8540 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8541 }
8542#endif
8543
8544#ifdef FEAT_TITLE
8545 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008546 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008547 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008548 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008549 }
8550#endif
8551
8552 else if ((int *)varp == &curbuf->b_changed)
8553 {
8554 if (!value)
8555 save_file_ff(curbuf); /* Buffer is unchanged */
8556#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008557 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008558#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008559 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560 }
8561
8562#ifdef BACKSLASH_IN_FILENAME
8563 else if ((int *)varp == &p_ssl)
8564 {
8565 if (p_ssl)
8566 {
8567 psepc = '/';
8568 psepcN = '\\';
8569 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008570 }
8571 else
8572 {
8573 psepc = '\\';
8574 psepcN = '/';
8575 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576 }
8577
8578 /* need to adjust the file name arguments and buffer names. */
8579 buflist_slash_adjust();
8580 alist_slash_adjust();
8581# ifdef FEAT_EVAL
8582 scriptnames_slash_adjust();
8583# endif
8584 }
8585#endif
8586
8587 /* If 'wrap' is set, set w_leftcol to zero. */
8588 else if ((int *)varp == &curwin->w_p_wrap)
8589 {
8590 if (curwin->w_p_wrap)
8591 curwin->w_leftcol = 0;
8592 }
8593
Bram Moolenaar071d4272004-06-13 20:20:40 +00008594 else if ((int *)varp == &p_ea)
8595 {
8596 if (p_ea && !old_value)
8597 win_equal(curwin, FALSE, 0);
8598 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008599
8600 else if ((int *)varp == &p_wiv)
8601 {
8602 /*
8603 * When 'weirdinvert' changed, set/reset 't_xs'.
8604 * Then set 'weirdinvert' according to value of 't_xs'.
8605 */
8606 if (p_wiv && !old_value)
8607 T_XS = (char_u *)"y";
8608 else if (!p_wiv && old_value)
8609 T_XS = empty_option;
8610 p_wiv = (*T_XS != NUL);
8611 }
8612
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008613#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008614 else if ((int *)varp == &p_beval)
8615 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008616 if (!balloonEvalForTerm)
8617 {
8618 if (p_beval && !old_value)
8619 gui_mch_enable_beval_area(balloonEval);
8620 else if (!p_beval && old_value)
8621 gui_mch_disable_beval_area(balloonEval);
8622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008623 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008624#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008625#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008626 else if ((int *)varp == &p_bevalterm)
8627 {
8628 mch_bevalterm_changed();
8629 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008630#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008631
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008632#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008633 else if ((int *)varp == &p_acd)
8634 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008635 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008636 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008637 }
8638#endif
8639
8640#ifdef FEAT_DIFF
8641 /* 'diff' */
8642 else if ((int *)varp == &curwin->w_p_diff)
8643 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008644 /* May add or remove the buffer from the list of diff buffers. */
8645 diff_buf_adjust(curwin);
8646# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008647 if (foldmethodIsDiff(curwin))
8648 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008649# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008650 }
8651#endif
8652
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008653#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654 /* 'imdisable' */
8655 else if ((int *)varp == &p_imdisable)
8656 {
8657 /* Only de-activate it here, it will be enabled when changing mode. */
8658 if (p_imdisable)
8659 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008660 else if (State & INSERT)
8661 /* When the option is set from an autocommand, it may need to take
8662 * effect right away. */
8663 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 }
8665#endif
8666
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008667#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008668 /* 'spell' */
8669 else if ((int *)varp == &curwin->w_p_spell)
8670 {
8671 if (curwin->w_p_spell)
8672 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008673 char *errmsg = did_set_spelllang(curwin);
8674
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008675 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008676 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008677 }
8678 }
8679#endif
8680
Bram Moolenaar071d4272004-06-13 20:20:40 +00008681#ifdef FEAT_FKMAP
8682 else if ((int *)varp == &p_altkeymap)
8683 {
8684 if (old_value != p_altkeymap)
8685 {
8686 if (!p_altkeymap)
8687 {
8688 p_hkmap = p_fkmap;
8689 p_fkmap = 0;
8690 }
8691 else
8692 {
8693 p_fkmap = p_hkmap;
8694 p_hkmap = 0;
8695 }
8696 (void)init_chartab();
8697 }
8698 }
8699
8700 /*
8701 * In case some second language keymapping options have changed, check
8702 * and correct the setting in a consistent way.
8703 */
8704
8705 /*
8706 * If hkmap or fkmap are set, reset Arabic keymapping.
8707 */
8708 if ((p_hkmap || p_fkmap) && p_altkeymap)
8709 {
8710 p_altkeymap = p_fkmap;
8711# ifdef FEAT_ARABIC
8712 curwin->w_p_arab = FALSE;
8713# endif
8714 (void)init_chartab();
8715 }
8716
8717 /*
8718 * If hkmap set, reset Farsi keymapping.
8719 */
8720 if (p_hkmap && p_altkeymap)
8721 {
8722 p_altkeymap = 0;
8723 p_fkmap = 0;
8724# ifdef FEAT_ARABIC
8725 curwin->w_p_arab = FALSE;
8726# endif
8727 (void)init_chartab();
8728 }
8729
8730 /*
8731 * If fkmap set, reset Hebrew keymapping.
8732 */
8733 if (p_fkmap && !p_altkeymap)
8734 {
8735 p_altkeymap = 1;
8736 p_hkmap = 0;
8737# ifdef FEAT_ARABIC
8738 curwin->w_p_arab = FALSE;
8739# endif
8740 (void)init_chartab();
8741 }
8742#endif
8743
8744#ifdef FEAT_ARABIC
8745 if ((int *)varp == &curwin->w_p_arab)
8746 {
8747 if (curwin->w_p_arab)
8748 {
8749 /*
8750 * 'arabic' is set, handle various sub-settings.
8751 */
8752 if (!p_tbidi)
8753 {
8754 /* set rightleft mode */
8755 if (!curwin->w_p_rl)
8756 {
8757 curwin->w_p_rl = TRUE;
8758 changed_window_setting();
8759 }
8760
8761 /* Enable Arabic shaping (major part of what Arabic requires) */
8762 if (!p_arshape)
8763 {
8764 p_arshape = TRUE;
8765 redraw_later_clear();
8766 }
8767 }
8768
8769 /* Arabic requires a utf-8 encoding, inform the user if its not
8770 * set. */
8771 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008772 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008773 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8774
Bram Moolenaar8820b482017-03-16 17:23:31 +01008775 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008776 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008777#ifdef FEAT_EVAL
8778 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8779#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781
Bram Moolenaar071d4272004-06-13 20:20:40 +00008782 /* set 'delcombine' */
8783 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008784
8785# ifdef FEAT_KEYMAP
8786 /* Force-set the necessary keymap for arabic */
8787 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8788 OPT_LOCAL);
8789# endif
8790# ifdef FEAT_FKMAP
8791 p_altkeymap = 0;
8792 p_hkmap = 0;
8793 p_fkmap = 0;
8794 (void)init_chartab();
8795# endif
8796 }
8797 else
8798 {
8799 /*
8800 * 'arabic' is reset, handle various sub-settings.
8801 */
8802 if (!p_tbidi)
8803 {
8804 /* reset rightleft mode */
8805 if (curwin->w_p_rl)
8806 {
8807 curwin->w_p_rl = FALSE;
8808 changed_window_setting();
8809 }
8810
8811 /* 'arabicshape' isn't reset, it is a global option and
8812 * another window may still need it "on". */
8813 }
8814
8815 /* 'delcombine' isn't reset, it is a global option and another
8816 * window may still want it "on". */
8817
8818# ifdef FEAT_KEYMAP
8819 /* Revert to the default keymap */
8820 curbuf->b_p_iminsert = B_IMODE_NONE;
8821 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8822# endif
8823 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008824 }
8825
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008826#endif
8827
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008828#ifdef FEAT_TERMGUICOLORS
8829 /* 'termguicolors' */
8830 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008831 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008832# ifdef FEAT_VTP
8833 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8834 if (!has_vtp_working())
8835 {
8836 p_tgc = 0;
8837 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8838 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008839 if (is_term_win32())
8840 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008841# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008842# ifdef FEAT_GUI
8843 if (!gui.in_use && !gui.starting)
8844# endif
8845 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008846# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008847 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008848 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008849 {
8850 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008851 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008852 init_highlight(TRUE, FALSE);
8853 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008854# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008855 }
8856#endif
8857
Bram Moolenaar071d4272004-06-13 20:20:40 +00008858 /*
8859 * End of handling side effects for bool options.
8860 */
8861
Bram Moolenaar53744302015-07-17 17:38:22 +02008862 /* after handling side effects, call autocommand */
8863
Bram Moolenaar071d4272004-06-13 20:20:40 +00008864 options[opt_idx].flags |= P_WAS_SET;
8865
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008866#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008867 // Don't do this while starting up or recursively.
8868 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008869 {
8870 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008871
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008872 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8873 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8874 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008875 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8876 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8877 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8878 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8879 reset_v_option_vars();
8880 }
8881#endif
8882
Bram Moolenaar071d4272004-06-13 20:20:40 +00008883 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008884 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008885 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008886 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008887 check_redraw(options[opt_idx].flags);
8888
8889 return NULL;
8890}
8891
8892/*
8893 * Set the value of a number option, and take care of side effects.
8894 * Returns NULL for success, or an error message for an error.
8895 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008896 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008897set_num_option(
8898 int opt_idx, /* index in options[] table */
8899 char_u *varp, /* pointer to the option variable */
8900 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008901 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008902 size_t errbuflen, /* length of "errbuf" */
8903 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008904 OPT_MODELINE */
8905{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008906 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907 long old_value = *(long *)varp;
8908 long old_Rows = Rows; /* remember old Rows */
8909 long old_Columns = Columns; /* remember old Columns */
8910 long *pp = (long *)varp;
8911
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008912 /* Disallow changing some options from secure mode. */
8913 if ((secure
8914#ifdef HAVE_SANDBOX
8915 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008916#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008917 ) && (options[opt_idx].flags & P_SECURE))
8918 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919
8920 *pp = value;
8921#ifdef FEAT_EVAL
8922 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008923 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008924#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008925#ifdef FEAT_GUI
8926 need_mouse_correct = TRUE;
8927#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928
Bram Moolenaar14f24742012-08-08 18:01:05 +02008929 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008930 {
8931 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008932#ifdef FEAT_VARTABS
8933 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8934 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8935 ? tabstop_first(curbuf->b_p_vts_array)
8936 : curbuf->b_p_ts;
8937#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008938 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008939#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940 }
8941
8942 /*
8943 * Number options that need some action when changed
8944 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945 if (pp == &p_wh || pp == &p_hh)
8946 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008947 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008948 if (p_wh < 1)
8949 {
8950 errmsg = e_positive;
8951 p_wh = 1;
8952 }
8953 if (p_wmh > p_wh)
8954 {
8955 errmsg = e_winheight;
8956 p_wh = p_wmh;
8957 }
8958 if (p_hh < 0)
8959 {
8960 errmsg = e_positive;
8961 p_hh = 0;
8962 }
8963
8964 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008965 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008966 {
8967 if (pp == &p_wh && curwin->w_height < p_wh)
8968 win_setheight((int)p_wh);
8969 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8970 win_setheight((int)p_hh);
8971 }
8972 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973 else if (pp == &p_wmh)
8974 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008975 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976 if (p_wmh < 0)
8977 {
8978 errmsg = e_positive;
8979 p_wmh = 0;
8980 }
8981 if (p_wmh > p_wh)
8982 {
8983 errmsg = e_winheight;
8984 p_wmh = p_wh;
8985 }
8986 win_setminheight();
8987 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008988 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008989 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008990 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008991 if (p_wiw < 1)
8992 {
8993 errmsg = e_positive;
8994 p_wiw = 1;
8995 }
8996 if (p_wmw > p_wiw)
8997 {
8998 errmsg = e_winwidth;
8999 p_wiw = p_wmw;
9000 }
9001
9002 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009003 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009004 win_setwidth((int)p_wiw);
9005 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009006 else if (pp == &p_wmw)
9007 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009008 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009009 if (p_wmw < 0)
9010 {
9011 errmsg = e_positive;
9012 p_wmw = 0;
9013 }
9014 if (p_wmw > p_wiw)
9015 {
9016 errmsg = e_winwidth;
9017 p_wmw = p_wiw;
9018 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009019 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009020 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009021
Bram Moolenaar071d4272004-06-13 20:20:40 +00009022 /* (re)set last window status line */
9023 else if (pp == &p_ls)
9024 {
9025 last_status(FALSE);
9026 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009027
9028 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009029 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009030 {
9031 shell_new_rows(); /* recompute window positions and heights */
9032 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009033
9034#ifdef FEAT_GUI
9035 else if (pp == &p_linespace)
9036 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009037 /* Recompute gui.char_height and resize the Vim window to keep the
9038 * same number of lines. */
9039 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009040 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041 }
9042#endif
9043
9044#ifdef FEAT_FOLDING
9045 /* 'foldlevel' */
9046 else if (pp == &curwin->w_p_fdl)
9047 {
9048 if (curwin->w_p_fdl < 0)
9049 curwin->w_p_fdl = 0;
9050 newFoldLevel();
9051 }
9052
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009053 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009054 else if (pp == &curwin->w_p_fml)
9055 {
9056 foldUpdateAll(curwin);
9057 }
9058
9059 /* 'foldnestmax' */
9060 else if (pp == &curwin->w_p_fdn)
9061 {
9062 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9063 foldUpdateAll(curwin);
9064 }
9065
9066 /* 'foldcolumn' */
9067 else if (pp == &curwin->w_p_fdc)
9068 {
9069 if (curwin->w_p_fdc < 0)
9070 {
9071 errmsg = e_positive;
9072 curwin->w_p_fdc = 0;
9073 }
9074 else if (curwin->w_p_fdc > 12)
9075 {
9076 errmsg = e_invarg;
9077 curwin->w_p_fdc = 12;
9078 }
9079 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009080#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009081
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009082#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009083 /* 'shiftwidth' or 'tabstop' */
9084 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9085 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009086# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087 if (foldmethodIsIndent(curwin))
9088 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009089# endif
9090# ifdef FEAT_CINDENT
9091 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9092 * parse 'cinoptions'. */
9093 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9094 parse_cino(curbuf);
9095# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009096 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009097#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009098
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009099 /* 'maxcombine' */
9100 else if (pp == &p_mco)
9101 {
9102 if (p_mco > MAX_MCO)
9103 p_mco = MAX_MCO;
9104 else if (p_mco < 0)
9105 p_mco = 0;
9106 screenclear(); /* will re-allocate the screen */
9107 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009108
Bram Moolenaar071d4272004-06-13 20:20:40 +00009109 else if (pp == &curbuf->b_p_iminsert)
9110 {
9111 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9112 {
9113 errmsg = e_invarg;
9114 curbuf->b_p_iminsert = B_IMODE_NONE;
9115 }
9116 p_iminsert = curbuf->b_p_iminsert;
9117 if (termcap_active) /* don't do this in the alternate screen */
9118 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009119#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009120 /* Show/unshow value of 'keymap' in status lines. */
9121 status_redraw_curbuf();
9122#endif
9123 }
9124
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009125#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9126 /* 'imstyle' */
9127 else if (pp == &p_imst)
9128 {
9129 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9130 errmsg = e_invarg;
9131 }
9132#endif
9133
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009134 else if (pp == &p_window)
9135 {
9136 if (p_window < 1)
9137 p_window = 1;
9138 else if (p_window >= Rows)
9139 p_window = Rows - 1;
9140 }
9141
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 else if (pp == &curbuf->b_p_imsearch)
9143 {
9144 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9145 {
9146 errmsg = e_invarg;
9147 curbuf->b_p_imsearch = B_IMODE_NONE;
9148 }
9149 p_imsearch = curbuf->b_p_imsearch;
9150 }
9151
9152#ifdef FEAT_TITLE
9153 /* if 'titlelen' has changed, redraw the title */
9154 else if (pp == &p_titlelen)
9155 {
9156 if (p_titlelen < 0)
9157 {
9158 errmsg = e_positive;
9159 p_titlelen = 85;
9160 }
9161 if (starting != NO_SCREEN && old_value != p_titlelen)
9162 need_maketitle = TRUE;
9163 }
9164#endif
9165
9166 /* if p_ch changed value, change the command line height */
9167 else if (pp == &p_ch)
9168 {
9169 if (p_ch < 1)
9170 {
9171 errmsg = e_positive;
9172 p_ch = 1;
9173 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009174 if (p_ch > Rows - min_rows() + 1)
9175 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009176
9177 /* Only compute the new window layout when startup has been
9178 * completed. Otherwise the frame sizes may be wrong. */
9179 if (p_ch != old_value && full_screen
9180#ifdef FEAT_GUI
9181 && !gui.starting
9182#endif
9183 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009184 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009185 }
9186
9187 /* when 'updatecount' changes from zero to non-zero, open swap files */
9188 else if (pp == &p_uc)
9189 {
9190 if (p_uc < 0)
9191 {
9192 errmsg = e_positive;
9193 p_uc = 100;
9194 }
9195 if (p_uc && !old_value)
9196 ml_open_files();
9197 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009198#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009199 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009200 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009201 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009202 {
9203 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009204 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009205 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009206 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009207 {
9208 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009209 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009210 }
9211 }
9212#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009213#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009214 else if (pp == &p_mzq)
9215 mzvim_reset_timer();
9216#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009217
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009218#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9219 /* 'pyxversion' */
9220 else if (pp == &p_pyx)
9221 {
9222 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9223 errmsg = e_invarg;
9224 }
9225#endif
9226
Bram Moolenaar071d4272004-06-13 20:20:40 +00009227 /* sync undo before 'undolevels' changes */
9228 else if (pp == &p_ul)
9229 {
9230 /* use the old value, otherwise u_sync() may not work properly */
9231 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009232 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233 p_ul = value;
9234 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009235 else if (pp == &curbuf->b_p_ul)
9236 {
9237 /* use the old value, otherwise u_sync() may not work properly */
9238 curbuf->b_p_ul = old_value;
9239 u_sync(TRUE);
9240 curbuf->b_p_ul = value;
9241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009242
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009243#ifdef FEAT_LINEBREAK
9244 /* 'numberwidth' must be positive */
9245 else if (pp == &curwin->w_p_nuw)
9246 {
9247 if (curwin->w_p_nuw < 1)
9248 {
9249 errmsg = e_positive;
9250 curwin->w_p_nuw = 1;
9251 }
9252 if (curwin->w_p_nuw > 10)
9253 {
9254 errmsg = e_invarg;
9255 curwin->w_p_nuw = 10;
9256 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009257 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009258 }
9259#endif
9260
Bram Moolenaar1a384422010-07-14 19:53:30 +02009261 else if (pp == &curbuf->b_p_tw)
9262 {
9263 if (curbuf->b_p_tw < 0)
9264 {
9265 errmsg = e_positive;
9266 curbuf->b_p_tw = 0;
9267 }
9268#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009269 {
9270 win_T *wp;
9271 tabpage_T *tp;
9272
9273 FOR_ALL_TAB_WINDOWS(tp, wp)
9274 check_colorcolumn(wp);
9275 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009276#endif
9277 }
9278
Bram Moolenaar071d4272004-06-13 20:20:40 +00009279 /*
9280 * Check the bounds for numeric options here
9281 */
9282 if (Rows < min_rows() && full_screen)
9283 {
9284 if (errbuf != NULL)
9285 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009286 vim_snprintf((char *)errbuf, errbuflen,
9287 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009288 errmsg = errbuf;
9289 }
9290 Rows = min_rows();
9291 }
9292 if (Columns < MIN_COLUMNS && full_screen)
9293 {
9294 if (errbuf != NULL)
9295 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009296 vim_snprintf((char *)errbuf, errbuflen,
9297 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009298 errmsg = errbuf;
9299 }
9300 Columns = MIN_COLUMNS;
9301 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009302 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009303
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304 /*
9305 * If the screen (shell) height has been changed, assume it is the
9306 * physical screenheight.
9307 */
9308 if (old_Rows != Rows || old_Columns != Columns)
9309 {
9310 /* Changing the screen size is not allowed while updating the screen. */
9311 if (updating_screen)
9312 *pp = old_value;
9313 else if (full_screen
9314#ifdef FEAT_GUI
9315 && !gui.starting
9316#endif
9317 )
9318 set_shellsize((int)Columns, (int)Rows, TRUE);
9319 else
9320 {
9321 /* Postpone the resizing; check the size and cmdline position for
9322 * messages. */
9323 check_shellsize();
9324 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9325 cmdline_row = Rows - p_ch;
9326 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009327 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009328 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009329 }
9330
Bram Moolenaar071d4272004-06-13 20:20:40 +00009331 if (curbuf->b_p_ts <= 0)
9332 {
9333 errmsg = e_positive;
9334 curbuf->b_p_ts = 8;
9335 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336 if (p_tm < 0)
9337 {
9338 errmsg = e_positive;
9339 p_tm = 0;
9340 }
9341 if ((curwin->w_p_scr <= 0
9342 || (curwin->w_p_scr > curwin->w_height
9343 && curwin->w_height > 0))
9344 && full_screen)
9345 {
9346 if (pp == &(curwin->w_p_scr))
9347 {
9348 if (curwin->w_p_scr != 0)
9349 errmsg = e_scroll;
9350 win_comp_scroll(curwin);
9351 }
9352 /* If 'scroll' became invalid because of a side effect silently adjust
9353 * it. */
9354 else if (curwin->w_p_scr <= 0)
9355 curwin->w_p_scr = 1;
9356 else /* curwin->w_p_scr > curwin->w_height */
9357 curwin->w_p_scr = curwin->w_height;
9358 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009359 if (p_hi < 0)
9360 {
9361 errmsg = e_positive;
9362 p_hi = 0;
9363 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009364 else if (p_hi > 10000)
9365 {
9366 errmsg = e_invarg;
9367 p_hi = 10000;
9368 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009369 if (p_re < 0 || p_re > 2)
9370 {
9371 errmsg = e_invarg;
9372 p_re = 0;
9373 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009374 if (p_report < 0)
9375 {
9376 errmsg = e_positive;
9377 p_report = 1;
9378 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009379 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009380 {
9381 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9382 p_sj = Rows / 2;
9383 else
9384 {
9385 errmsg = e_scroll;
9386 p_sj = 1;
9387 }
9388 }
9389 if (p_so < 0 && full_screen)
9390 {
9391 errmsg = e_scroll;
9392 p_so = 0;
9393 }
9394 if (p_siso < 0 && full_screen)
9395 {
9396 errmsg = e_positive;
9397 p_siso = 0;
9398 }
9399#ifdef FEAT_CMDWIN
9400 if (p_cwh < 1)
9401 {
9402 errmsg = e_positive;
9403 p_cwh = 1;
9404 }
9405#endif
9406 if (p_ut < 0)
9407 {
9408 errmsg = e_positive;
9409 p_ut = 2000;
9410 }
9411 if (p_ss < 0)
9412 {
9413 errmsg = e_positive;
9414 p_ss = 0;
9415 }
9416
9417 /* May set global value for local option. */
9418 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9419 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9420
9421 options[opt_idx].flags |= P_WAS_SET;
9422
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009423#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009424 // Don't do this while starting up, failure or recursively.
9425 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009426 {
9427 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009428 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9429 vim_snprintf((char *)buf_new, 10, "%ld", value);
9430 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009431 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9432 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9433 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9434 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9435 reset_v_option_vars();
9436 }
9437#endif
9438
Bram Moolenaar071d4272004-06-13 20:20:40 +00009439 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009440 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009441 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009442 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443 check_redraw(options[opt_idx].flags);
9444
9445 return errmsg;
9446}
9447
9448/*
9449 * Called after an option changed: check if something needs to be redrawn.
9450 */
9451 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009452check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009453{
9454 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009455 int doclear = (flags & P_RCLR) == P_RCLR;
9456 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009457
Bram Moolenaar071d4272004-06-13 20:20:40 +00009458 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9459 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009460
9461 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9462 changed_window_setting();
9463 if (flags & P_RBUF)
9464 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009465 if (flags & P_RWINONLY)
9466 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009467 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009468 redraw_all_later(CLEAR);
9469 else if (all)
9470 redraw_all_later(NOT_VALID);
9471}
9472
9473/*
9474 * Find index for option 'arg'.
9475 * Return -1 if not found.
9476 */
9477 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009478findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009479{
9480 int opt_idx;
9481 char *s, *p;
9482 static short quick_tab[27] = {0, 0}; /* quick access table */
9483 int is_term_opt;
9484
9485 /*
9486 * For first call: Initialize the quick-access table.
9487 * It contains the index for the first option that starts with a certain
9488 * letter. There are 26 letters, plus the first "t_" option.
9489 */
9490 if (quick_tab[1] == 0)
9491 {
9492 p = options[0].fullname;
9493 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9494 {
9495 if (s[0] != p[0])
9496 {
9497 if (s[0] == 't' && s[1] == '_')
9498 quick_tab[26] = opt_idx;
9499 else
9500 quick_tab[CharOrdLow(s[0])] = opt_idx;
9501 }
9502 p = s;
9503 }
9504 }
9505
9506 /*
9507 * Check for name starting with an illegal character.
9508 */
9509#ifdef EBCDIC
9510 if (!islower(arg[0]))
9511#else
9512 if (arg[0] < 'a' || arg[0] > 'z')
9513#endif
9514 return -1;
9515
9516 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9517 if (is_term_opt)
9518 opt_idx = quick_tab[26];
9519 else
9520 opt_idx = quick_tab[CharOrdLow(arg[0])];
9521 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9522 {
9523 if (STRCMP(arg, s) == 0) /* match full name */
9524 break;
9525 }
9526 if (s == NULL && !is_term_opt)
9527 {
9528 opt_idx = quick_tab[CharOrdLow(arg[0])];
9529 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9530 {
9531 s = options[opt_idx].shortname;
9532 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9533 break;
9534 s = NULL;
9535 }
9536 }
9537 if (s == NULL)
9538 opt_idx = -1;
9539 return opt_idx;
9540}
9541
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009542#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009543/*
9544 * Get the value for an option.
9545 *
9546 * Returns:
9547 * Number or Toggle option: 1, *numval gets value.
9548 * String option: 0, *stringval gets allocated string.
9549 * Hidden Number or Toggle option: -1.
9550 * hidden String option: -2.
9551 * unknown option: -3.
9552 */
9553 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009554get_option_value(
9555 char_u *name,
9556 long *numval,
9557 char_u **stringval, /* NULL when only checking existence */
9558 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009559{
9560 int opt_idx;
9561 char_u *varp;
9562
9563 opt_idx = findoption(name);
9564 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009565 {
9566 int key;
9567
9568 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009569 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009570 {
9571 char_u key_name[2];
9572 char_u *p;
9573
9574 if (key < 0)
9575 {
9576 key_name[0] = KEY2TERMCAP0(key);
9577 key_name[1] = KEY2TERMCAP1(key);
9578 }
9579 else
9580 {
9581 key_name[0] = KS_KEY;
9582 key_name[1] = (key & 0xff);
9583 }
9584 p = find_termcode(key_name);
9585 if (p != NULL)
9586 {
9587 if (stringval != NULL)
9588 *stringval = vim_strsave(p);
9589 return 0;
9590 }
9591 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009592 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009593 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009594
9595 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9596
9597 if (options[opt_idx].flags & P_STRING)
9598 {
9599 if (varp == NULL) /* hidden option */
9600 return -2;
9601 if (stringval != NULL)
9602 {
9603#ifdef FEAT_CRYPT
9604 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009605 if ((char_u **)varp == &curbuf->b_p_key
9606 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009607 *stringval = vim_strsave((char_u *)"*****");
9608 else
9609#endif
9610 *stringval = vim_strsave(*(char_u **)(varp));
9611 }
9612 return 0;
9613 }
9614
9615 if (varp == NULL) /* hidden option */
9616 return -1;
9617 if (options[opt_idx].flags & P_NUM)
9618 *numval = *(long *)varp;
9619 else
9620 {
9621 /* Special case: 'modified' is b_changed, but we also want to consider
9622 * it set when 'ff' or 'fenc' changed. */
9623 if ((int *)varp == &curbuf->b_changed)
9624 *numval = curbufIsChanged();
9625 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009626 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009627 }
9628 return 1;
9629}
9630#endif
9631
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009632#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009633/*
9634 * Returns the option attributes and its value. Unlike the above function it
9635 * will return either global value or local value of the option depending on
9636 * what was requested, but it will never return global value if it was
9637 * requested to return local one and vice versa. Neither it will return
9638 * buffer-local value if it was requested to return window-local one.
9639 *
9640 * Pretends that option is absent if it is not present in the requested scope
9641 * (i.e. has no global, window-local or buffer-local value depending on
9642 * opt_type). Uses
9643 *
9644 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009645 * 0 hidden or unknown option, also option that does not have requested
9646 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009647 * see SOPT_* in vim.h for other flags
9648 *
9649 * Possible opt_type values: see SREQ_* in vim.h
9650 */
9651 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009652get_option_value_strict(
9653 char_u *name,
9654 long *numval,
9655 char_u **stringval, /* NULL when only obtaining attributes */
9656 int opt_type,
9657 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009658{
9659 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009660 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009661 struct vimoption *p;
9662 int r = 0;
9663
9664 opt_idx = findoption(name);
9665 if (opt_idx < 0)
9666 return 0;
9667
9668 p = &(options[opt_idx]);
9669
9670 /* Hidden option */
9671 if (p->var == NULL)
9672 return 0;
9673
9674 if (p->flags & P_BOOL)
9675 r |= SOPT_BOOL;
9676 else if (p->flags & P_NUM)
9677 r |= SOPT_NUM;
9678 else if (p->flags & P_STRING)
9679 r |= SOPT_STRING;
9680
9681 if (p->indir == PV_NONE)
9682 {
9683 if (opt_type == SREQ_GLOBAL)
9684 r |= SOPT_GLOBAL;
9685 else
9686 return 0; /* Did not request global-only option */
9687 }
9688 else
9689 {
9690 if (p->indir & PV_BOTH)
9691 r |= SOPT_GLOBAL;
9692 else if (opt_type == SREQ_GLOBAL)
9693 return 0; /* Requested global option */
9694
9695 if (p->indir & PV_WIN)
9696 {
9697 if (opt_type == SREQ_BUF)
9698 return 0; /* Did not request window-local option */
9699 else
9700 r |= SOPT_WIN;
9701 }
9702 else if (p->indir & PV_BUF)
9703 {
9704 if (opt_type == SREQ_WIN)
9705 return 0; /* Did not request buffer-local option */
9706 else
9707 r |= SOPT_BUF;
9708 }
9709 }
9710
9711 if (stringval == NULL)
9712 return r;
9713
9714 if (opt_type == SREQ_GLOBAL)
9715 varp = p->var;
9716 else
9717 {
9718 if (opt_type == SREQ_BUF)
9719 {
9720 /* Special case: 'modified' is b_changed, but we also want to
9721 * consider it set when 'ff' or 'fenc' changed. */
9722 if (p->indir == PV_MOD)
9723 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009724 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009725 varp = NULL;
9726 }
9727#ifdef FEAT_CRYPT
9728 else if (p->indir == PV_KEY)
9729 {
9730 /* never return the value of the crypt key */
9731 *stringval = NULL;
9732 varp = NULL;
9733 }
9734#endif
9735 else
9736 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009737 buf_T *save_curbuf = curbuf;
9738
9739 // only getting a pointer, no need to use aucmd_prepbuf()
9740 curbuf = (buf_T *)from;
9741 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009742 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009743 curbuf = save_curbuf;
9744 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009745 }
9746 }
9747 else if (opt_type == SREQ_WIN)
9748 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009749 win_T *save_curwin = curwin;
9750
9751 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009752 curbuf = curwin->w_buffer;
9753 varp = get_varp(p);
9754 curwin = save_curwin;
9755 curbuf = curwin->w_buffer;
9756 }
9757 if (varp == p->var)
9758 return (r | SOPT_UNSET);
9759 }
9760
9761 if (varp != NULL)
9762 {
9763 if (p->flags & P_STRING)
9764 *stringval = vim_strsave(*(char_u **)(varp));
9765 else if (p->flags & P_NUM)
9766 *numval = *(long *) varp;
9767 else
9768 *numval = *(int *)varp;
9769 }
9770
9771 return r;
9772}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009773
9774/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009775 * Iterate over options. First argument is a pointer to a pointer to a
9776 * structure inside options[] array, second is option type like in the above
9777 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009778 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009779 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009780 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009781 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009782 * first argument to NULL.
9783 *
9784 * Returns full option name for current option on each call.
9785 */
9786 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009787option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009788{
9789 struct vimoption *ret = NULL;
9790 do
9791 {
9792 if (*option == NULL)
9793 *option = (void *) options;
9794 else if (((struct vimoption *) (*option))->fullname == NULL)
9795 {
9796 *option = NULL;
9797 return NULL;
9798 }
9799 else
9800 *option = (void *) (((struct vimoption *) (*option)) + 1);
9801
9802 ret = ((struct vimoption *) (*option));
9803
9804 /* Hidden option */
9805 if (ret->var == NULL)
9806 {
9807 ret = NULL;
9808 continue;
9809 }
9810
9811 switch (opt_type)
9812 {
9813 case SREQ_GLOBAL:
9814 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9815 ret = NULL;
9816 break;
9817 case SREQ_BUF:
9818 if (!(ret->indir & PV_BUF))
9819 ret = NULL;
9820 break;
9821 case SREQ_WIN:
9822 if (!(ret->indir & PV_WIN))
9823 ret = NULL;
9824 break;
9825 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009826 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009827 return NULL;
9828 }
9829 }
9830 while (ret == NULL);
9831
9832 return (char_u *)ret->fullname;
9833}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009834#endif
9835
Bram Moolenaar071d4272004-06-13 20:20:40 +00009836/*
9837 * Set the value of option "name".
9838 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009839 *
9840 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009841 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009842 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009843set_option_value(
9844 char_u *name,
9845 long number,
9846 char_u *string,
9847 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009848{
9849 int opt_idx;
9850 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009851 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009852
9853 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009854 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009855 {
9856 int key;
9857
9858 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009859 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009860 {
9861 char_u key_name[2];
9862
9863 if (key < 0)
9864 {
9865 key_name[0] = KEY2TERMCAP0(key);
9866 key_name[1] = KEY2TERMCAP1(key);
9867 }
9868 else
9869 {
9870 key_name[0] = KS_KEY;
9871 key_name[1] = (key & 0xff);
9872 }
9873 add_termcode(key_name, string, FALSE);
9874 if (full_screen)
9875 ttest(FALSE);
9876 redraw_all_later(CLEAR);
9877 return NULL;
9878 }
9879
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009880 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009881 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009882 else
9883 {
9884 flags = options[opt_idx].flags;
9885#ifdef HAVE_SANDBOX
9886 /* Disallow changing some options in the sandbox */
9887 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009888 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009889 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009890 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009891 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009892#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009893 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009894 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009895 else
9896 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009897 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009898 if (varp != NULL) /* hidden option is not changed */
9899 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009900 if (number == 0 && string != NULL)
9901 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009902 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009903
9904 /* Either we are given a string or we are setting option
9905 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009906 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009907 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009908 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009909 {
9910 /* There's another character after zeros or the string
9911 * is empty. In both cases, we are trying to set a
9912 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009913 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009914 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009915 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009916
9917 }
9918 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009919 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009920 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009921 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009922 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009923 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009924 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009925 }
9926 }
9927 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009928 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009929}
9930
9931/*
9932 * Get the terminal code for a terminal option.
9933 * Returns NULL when not found.
9934 */
9935 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009936get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009937{
9938 int opt_idx;
9939 char_u *varp;
9940
9941 if (tname[0] != 't' || tname[1] != '_' ||
9942 tname[2] == NUL || tname[3] == NUL)
9943 return NULL;
9944 if ((opt_idx = findoption(tname)) >= 0)
9945 {
9946 varp = get_varp(&(options[opt_idx]));
9947 if (varp != NULL)
9948 varp = *(char_u **)(varp);
9949 return varp;
9950 }
9951 return find_termcode(tname + 2);
9952}
9953
9954 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009955get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009956{
9957 int i;
9958
9959 i = findoption((char_u *)"hl");
9960 if (i >= 0)
9961 return options[i].def_val[VI_DEFAULT];
9962 return (char_u *)NULL;
9963}
9964
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009965 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009966get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009967{
9968 int i;
9969
9970 i = findoption((char_u *)"enc");
9971 if (i >= 0)
9972 return options[i].def_val[VI_DEFAULT];
9973 return (char_u *)NULL;
9974}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009975
Bram Moolenaar071d4272004-06-13 20:20:40 +00009976/*
9977 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009978 * When "has_lt" is true there is a '<' before "*arg_arg".
9979 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009980 */
9981 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009982find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009983{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009984 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009985 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009986 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009987
9988 /*
9989 * Don't use get_special_key_code() for t_xx, we don't want it to call
9990 * add_termcap_entry().
9991 */
9992 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9993 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009994 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009995 {
9996 --arg; /* put arg at the '<' */
9997 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009998 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009999 if (modifiers) /* can't handle modifiers here */
10000 key = 0;
10001 }
10002 return key;
10003}
10004
10005/*
10006 * if 'all' == 0: show changed options
10007 * if 'all' == 1: show all normal options
10008 * if 'all' == 2: show all terminal options
10009 */
10010 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010011showoptions(
10012 int all,
10013 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014{
10015 struct vimoption *p;
10016 int col;
10017 int isterm;
10018 char_u *varp;
10019 struct vimoption **items;
10020 int item_count;
10021 int run;
10022 int row, rows;
10023 int cols;
10024 int i;
10025 int len;
10026
10027#define INC 20
10028#define GAP 3
10029
10030 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10031 PARAM_COUNT));
10032 if (items == NULL)
10033 return;
10034
10035 /* Highlight title */
10036 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010037 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010038 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010039 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010041 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010042 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010043 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010044
10045 /*
10046 * do the loop two times:
10047 * 1. display the short items
10048 * 2. display the long items (only strings and numbers)
10049 */
10050 for (run = 1; run <= 2 && !got_int; ++run)
10051 {
10052 /*
10053 * collect the items in items[]
10054 */
10055 item_count = 0;
10056 for (p = &options[0]; p->fullname != NULL; p++)
10057 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010058 // apply :filter /pat/
10059 if (message_filtered((char_u *) p->fullname))
10060 continue;
10061
Bram Moolenaar071d4272004-06-13 20:20:40 +000010062 varp = NULL;
10063 isterm = istermoption(p);
10064 if (opt_flags != 0)
10065 {
10066 if (p->indir != PV_NONE && !isterm)
10067 varp = get_varp_scope(p, opt_flags);
10068 }
10069 else
10070 varp = get_varp(p);
10071 if (varp != NULL
10072 && ((all == 2 && isterm)
10073 || (all == 1 && !isterm)
10074 || (all == 0 && !optval_default(p, varp))))
10075 {
10076 if (p->flags & P_BOOL)
10077 len = 1; /* a toggle option fits always */
10078 else
10079 {
10080 option_value2string(p, opt_flags);
10081 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10082 }
10083 if ((len <= INC - GAP && run == 1) ||
10084 (len > INC - GAP && run == 2))
10085 items[item_count++] = p;
10086 }
10087 }
10088
10089 /*
10090 * display the items
10091 */
10092 if (run == 1)
10093 {
10094 cols = (Columns + GAP - 3) / INC;
10095 if (cols == 0)
10096 cols = 1;
10097 rows = (item_count + cols - 1) / cols;
10098 }
10099 else /* run == 2 */
10100 rows = item_count;
10101 for (row = 0; row < rows && !got_int; ++row)
10102 {
10103 msg_putchar('\n'); /* go to next line */
10104 if (got_int) /* 'q' typed in more */
10105 break;
10106 col = 0;
10107 for (i = row; i < item_count; i += rows)
10108 {
10109 msg_col = col; /* make columns */
10110 showoneopt(items[i], opt_flags);
10111 col += INC;
10112 }
10113 out_flush();
10114 ui_breakcheck();
10115 }
10116 }
10117 vim_free(items);
10118}
10119
10120/*
10121 * Return TRUE if option "p" has its default value.
10122 */
10123 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010124optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010125{
10126 int dvi;
10127
10128 if (varp == NULL)
10129 return TRUE; /* hidden option is always at default */
10130 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10131 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010132 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010134 /* the cast to long is required for Manx C, long_i is
10135 * needed for MSVC */
10136 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010137 /* P_STRING */
10138 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10139}
10140
10141/*
10142 * showoneopt: show the value of one option
10143 * must not be called with a hidden option!
10144 */
10145 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010146showoneopt(
10147 struct vimoption *p,
10148 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010149{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010150 char_u *varp;
10151 int save_silent = silent_mode;
10152
10153 silent_mode = FALSE;
10154 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010155
10156 varp = get_varp_scope(p, opt_flags);
10157
10158 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10159 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10160 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010161 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010162 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010163 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010164 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010165 msg_puts(" ");
10166 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010167 if (!(p->flags & P_BOOL))
10168 {
10169 msg_putchar('=');
10170 /* put value string in NameBuff */
10171 option_value2string(p, opt_flags);
10172 msg_outtrans(NameBuff);
10173 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010174
10175 silent_mode = save_silent;
10176 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010177}
10178
10179/*
10180 * Write modified options as ":set" commands to a file.
10181 *
10182 * There are three values for "opt_flags":
10183 * OPT_GLOBAL: Write global option values and fresh values of
10184 * buffer-local options (used for start of a session
10185 * file).
10186 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10187 * curwin (used for a vimrc file).
10188 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10189 * and local values for window-local options of
10190 * curwin. Local values are also written when at the
10191 * default value, because a modeline or autocommand
10192 * may have set them when doing ":edit file" and the
10193 * user has set them back at the default or fresh
10194 * value.
10195 * When "local_only" is TRUE, don't write fresh
10196 * values, only local values (for ":mkview").
10197 * (fresh value = value used for a new buffer or window for a local option).
10198 *
10199 * Return FAIL on error, OK otherwise.
10200 */
10201 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010202makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203{
10204 struct vimoption *p;
10205 char_u *varp; /* currently used value */
10206 char_u *varp_fresh; /* local value */
10207 char_u *varp_local = NULL; /* fresh value */
10208 char *cmd;
10209 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010210 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211
10212 /*
10213 * The options that don't have a default (terminal name, columns, lines)
10214 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010215 * Do the loop over "options[]" twice: once for options with the
10216 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010217 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010218 for (pri = 1; pri >= 0; --pri)
10219 {
10220 for (p = &options[0]; !istermoption(p); p++)
10221 if (!(p->flags & P_NO_MKRC)
10222 && !istermoption(p)
10223 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010224 {
10225 /* skip global option when only doing locals */
10226 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10227 continue;
10228
10229 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10230 * file, they are always buffer-specific. */
10231 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10232 continue;
10233
10234 /* Global values are only written when not at the default value. */
10235 varp = get_varp_scope(p, opt_flags);
10236 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10237 continue;
10238
10239 round = 2;
10240 if (p->indir != PV_NONE)
10241 {
10242 if (p->var == VAR_WIN)
10243 {
10244 /* skip window-local option when only doing globals */
10245 if (!(opt_flags & OPT_LOCAL))
10246 continue;
10247 /* When fresh value of window-local option is not at the
10248 * default, need to write it too. */
10249 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10250 {
10251 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10252 if (!optval_default(p, varp_fresh))
10253 {
10254 round = 1;
10255 varp_local = varp;
10256 varp = varp_fresh;
10257 }
10258 }
10259 }
10260 }
10261
10262 /* Round 1: fresh value for window-local options.
10263 * Round 2: other values */
10264 for ( ; round <= 2; varp = varp_local, ++round)
10265 {
10266 if (round == 1 || (opt_flags & OPT_GLOBAL))
10267 cmd = "set";
10268 else
10269 cmd = "setlocal";
10270
10271 if (p->flags & P_BOOL)
10272 {
10273 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10274 return FAIL;
10275 }
10276 else if (p->flags & P_NUM)
10277 {
10278 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10279 return FAIL;
10280 }
10281 else /* P_STRING */
10282 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010283 int do_endif = FALSE;
10284
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285 /* Don't set 'syntax' and 'filetype' again if the value is
10286 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010287 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010288#if defined(FEAT_SYN_HL)
10289 p->indir == PV_SYN ||
10290#endif
10291 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292 {
10293 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10294 *(char_u **)(varp)) < 0
10295 || put_eol(fd) < 0)
10296 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010297 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010298 }
10299 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
10300 (p->flags & P_EXPAND) != 0) == FAIL)
10301 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010302 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303 {
10304 if (put_line(fd, "endif") == FAIL)
10305 return FAIL;
10306 }
10307 }
10308 }
10309 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010310 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311 return OK;
10312}
10313
10314#if defined(FEAT_FOLDING) || defined(PROTO)
10315/*
10316 * Generate set commands for the local fold options only. Used when
10317 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10318 */
10319 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010320makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321{
10322 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, FALSE) == FAIL
10323# ifdef FEAT_EVAL
10324 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, FALSE)
10325 == FAIL
10326# endif
10327 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, FALSE)
10328 == FAIL
10329 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, FALSE)
10330 == FAIL
10331 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10332 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10333 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10334 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10335 )
10336 return FAIL;
10337
10338 return OK;
10339}
10340#endif
10341
10342 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010343put_setstring(
10344 FILE *fd,
10345 char *cmd,
10346 char *name,
10347 char_u **valuep,
10348 int expand)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010349{
10350 char_u *s;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010351 char_u *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352
10353 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10354 return FAIL;
10355 if (*valuep != NULL)
10356 {
10357 /* Output 'pastetoggle' as key names. For other
10358 * options some characters have to be escaped with
10359 * CTRL-V or backslash */
10360 if (valuep == &p_pt)
10361 {
10362 s = *valuep;
10363 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010364 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365 return FAIL;
10366 }
10367 else if (expand)
10368 {
Bram Moolenaarf8441472011-04-28 17:24:58 +020010369 buf = alloc(MAXPATHL);
10370 if (buf == NULL)
10371 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010372 home_replace(NULL, *valuep, buf, MAXPATHL, FALSE);
10373 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010374 {
10375 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010376 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010377 }
10378 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010379 }
10380 else if (put_escstr(fd, *valuep, 2) == FAIL)
10381 return FAIL;
10382 }
10383 if (put_eol(fd) < 0)
10384 return FAIL;
10385 return OK;
10386}
10387
10388 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010389put_setnum(
10390 FILE *fd,
10391 char *cmd,
10392 char *name,
10393 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010394{
10395 long wc;
10396
10397 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10398 return FAIL;
10399 if (wc_use_keyname((char_u *)valuep, &wc))
10400 {
10401 /* print 'wildchar' and 'wildcharm' as a key name */
10402 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10403 return FAIL;
10404 }
10405 else if (fprintf(fd, "%ld", *valuep) < 0)
10406 return FAIL;
10407 if (put_eol(fd) < 0)
10408 return FAIL;
10409 return OK;
10410}
10411
10412 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010413put_setbool(
10414 FILE *fd,
10415 char *cmd,
10416 char *name,
10417 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010418{
Bram Moolenaar893de922007-10-02 18:40:57 +000010419 if (value < 0) /* global/local option using global value */
10420 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010421 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10422 || put_eol(fd) < 0)
10423 return FAIL;
10424 return OK;
10425}
10426
10427/*
10428 * Clear all the terminal options.
10429 * If the option has been allocated, free the memory.
10430 * Terminal options are never hidden or indirect.
10431 */
10432 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010433clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435 /*
10436 * Reset a few things before clearing the old options. This may cause
10437 * outputting a few things that the terminal doesn't understand, but the
10438 * screen will be cleared later, so this is OK.
10439 */
10440#ifdef FEAT_MOUSE_TTY
10441 mch_setmouse(FALSE); /* switch mouse off */
10442#endif
10443#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010444 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010445#endif
10446#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10447 /* When starting the GUI close the display opened for the clipboard.
10448 * After restoring the title, because that will need the display. */
10449 if (gui.starting)
10450 clear_xterm_clip();
10451#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010452 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010453
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010454 free_termoptions();
10455}
10456
10457 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010458free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010459{
10460 struct vimoption *p;
10461
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010462 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010463 if (istermoption(p))
10464 {
10465 if (p->flags & P_ALLOCED)
10466 free_string_option(*(char_u **)(p->var));
10467 if (p->flags & P_DEF_ALLOCED)
10468 free_string_option(p->def_val[VI_DEFAULT]);
10469 *(char_u **)(p->var) = empty_option;
10470 p->def_val[VI_DEFAULT] = empty_option;
10471 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010472#ifdef FEAT_EVAL
10473 // remember where the option was cleared
10474 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10475#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476 }
10477 clear_termcodes();
10478}
10479
10480/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010481 * Free the string for one term option, if it was allocated.
10482 * Set the string to empty_option and clear allocated flag.
10483 * "var" points to the option value.
10484 */
10485 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010486free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010487{
10488 struct vimoption *p;
10489
10490 for (p = &options[0]; p->fullname != NULL; p++)
10491 if (p->var == var)
10492 {
10493 if (p->flags & P_ALLOCED)
10494 free_string_option(*(char_u **)(p->var));
10495 *(char_u **)(p->var) = empty_option;
10496 p->flags &= ~P_ALLOCED;
10497 break;
10498 }
10499}
10500
10501/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502 * Set the terminal option defaults to the current value.
10503 * Used after setting the terminal name.
10504 */
10505 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010506set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507{
10508 struct vimoption *p;
10509
10510 for (p = &options[0]; p->fullname != NULL; p++)
10511 {
10512 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10513 {
10514 if (p->flags & P_DEF_ALLOCED)
10515 {
10516 free_string_option(p->def_val[VI_DEFAULT]);
10517 p->flags &= ~P_DEF_ALLOCED;
10518 }
10519 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10520 if (p->flags & P_ALLOCED)
10521 {
10522 p->flags |= P_DEF_ALLOCED;
10523 p->flags &= ~P_ALLOCED; /* don't free the value now */
10524 }
10525 }
10526 }
10527}
10528
10529/*
10530 * return TRUE if 'p' starts with 't_'
10531 */
10532 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010533istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010534{
10535 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10536}
10537
10538/*
10539 * Compute columns for ruler and shown command. 'sc_col' is also used to
10540 * decide what the maximum length of a message on the status line can be.
10541 * If there is a status line for the last window, 'sc_col' is independent
10542 * of 'ru_col'.
10543 */
10544
10545#define COL_RULER 17 /* columns needed by standard ruler */
10546
10547 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010548comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010550#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010551 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010552
10553 sc_col = 0;
10554 ru_col = 0;
10555 if (p_ru)
10556 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010557# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010558 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010559# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010561# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562 /* no last status line, adjust sc_col */
10563 if (!last_has_status)
10564 sc_col = ru_col;
10565 }
10566 if (p_sc)
10567 {
10568 sc_col += SHOWCMD_COLS;
10569 if (!p_ru || last_has_status) /* no need for separating space */
10570 ++sc_col;
10571 }
10572 sc_col = Columns - sc_col;
10573 ru_col = Columns - ru_col;
10574 if (sc_col <= 0) /* screen too narrow, will become a mess */
10575 sc_col = 1;
10576 if (ru_col <= 0)
10577 ru_col = 1;
10578#else
10579 sc_col = Columns;
10580 ru_col = Columns;
10581#endif
10582}
10583
Bram Moolenaar113e1072019-01-20 15:30:40 +010010584#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010586 * Unset local option value, similar to ":set opt<".
10587 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010588 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010589unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010590{
10591 struct vimoption *p;
10592 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010593 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010594
10595 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010596 if (opt_idx < 0)
10597 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010598 p = &(options[opt_idx]);
10599
10600 switch ((int)p->indir)
10601 {
10602 /* global option with local value: use local value if it's been set */
10603 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010604 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010605 break;
10606 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010607 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010608 break;
10609 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010610 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010611 break;
10612 case PV_AR:
10613 buf->b_p_ar = -1;
10614 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010615 case PV_BKC:
10616 clear_string_option(&buf->b_p_bkc);
10617 buf->b_bkc_flags = 0;
10618 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010619 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010620 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010621 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010622 case PV_TC:
10623 clear_string_option(&buf->b_p_tc);
10624 buf->b_tc_flags = 0;
10625 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010626#ifdef FEAT_FIND_ID
10627 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010628 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010629 break;
10630 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010631 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010632 break;
10633#endif
10634#ifdef FEAT_INS_EXPAND
10635 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010636 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010637 break;
10638 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010639 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010640 break;
10641#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010642 case PV_FP:
10643 clear_string_option(&buf->b_p_fp);
10644 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010645#ifdef FEAT_QUICKFIX
10646 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010647 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010648 break;
10649 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010650 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010651 break;
10652 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010653 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010654 break;
10655#endif
10656#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10657 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010658 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010659 break;
10660#endif
10661#if defined(FEAT_CRYPT)
10662 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010663 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010664 break;
10665#endif
10666#ifdef FEAT_STL_OPT
10667 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010668 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010669 break;
10670#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010671 case PV_UL:
10672 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10673 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010674#ifdef FEAT_LISP
10675 case PV_LW:
10676 clear_string_option(&buf->b_p_lw);
10677 break;
10678#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010679 case PV_MENC:
10680 clear_string_option(&buf->b_p_menc);
10681 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010682 }
10683}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010684#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010685
10686/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010687 * Get pointer to option variable, depending on local or global scope.
10688 */
10689 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010690get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691{
10692 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10693 {
10694 if (p->var == VAR_WIN)
10695 return (char_u *)GLOBAL_WO(get_varp(p));
10696 return p->var;
10697 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010698 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 {
10700 switch ((int)p->indir)
10701 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010702 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010703#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010704 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10705 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10706 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010707#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010708 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10709 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10710 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010711 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010712 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010713 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010714#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010715 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10716 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010717#endif
10718#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010719 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10720 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010721#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010722#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10723 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10724#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010725#if defined(FEAT_CRYPT)
10726 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10727#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010728#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010729 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010730#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010731 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010732#ifdef FEAT_LISP
10733 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10734#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010735 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010736 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 }
10738 return NULL; /* "cannot happen" */
10739 }
10740 return get_varp(p);
10741}
10742
10743/*
10744 * Get pointer to option variable.
10745 */
10746 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010747get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748{
10749 /* hidden option, always return NULL */
10750 if (p->var == NULL)
10751 return NULL;
10752
10753 switch ((int)p->indir)
10754 {
10755 case PV_NONE: return p->var;
10756
10757 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010758 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010760 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010762 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010764 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010765 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010766 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010768 case PV_TC: return *curbuf->b_p_tc != NUL
10769 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010770 case PV_BKC: return *curbuf->b_p_bkc != NUL
10771 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010772#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010773 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010774 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010775 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010776 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10777#endif
10778#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010779 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010781 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010782 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10783#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010784 case PV_FP: return *curbuf->b_p_fp != NUL
10785 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010787 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010789 case PV_GP: return *curbuf->b_p_gp != NUL
10790 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10791 case PV_MP: return *curbuf->b_p_mp != NUL
10792 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010793#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010794#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10795 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10796 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10797#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010798#if defined(FEAT_CRYPT)
10799 case PV_CM: return *curbuf->b_p_cm != NUL
10800 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10801#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010802#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010803 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010804 ? (char_u *)&(curwin->w_p_stl) : p->var;
10805#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010806 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10807 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010808#ifdef FEAT_LISP
10809 case PV_LW: return *curbuf->b_p_lw != NUL
10810 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10811#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010812 case PV_MENC: return *curbuf->b_p_menc != NUL
10813 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010814
10815#ifdef FEAT_ARABIC
10816 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10817#endif
10818 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010819#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010820 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10821#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010822#ifdef FEAT_SYN_HL
10823 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10824 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010825 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010826#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010827#ifdef FEAT_DIFF
10828 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10829#endif
10830#ifdef FEAT_FOLDING
10831 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10832 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10833 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10834 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10835 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10836 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10837 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10838# ifdef FEAT_EVAL
10839 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10840 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10841# endif
10842 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10843#endif
10844 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010845 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010846#ifdef FEAT_LINEBREAK
10847 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10848#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010850 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010851#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10853#endif
10854#ifdef FEAT_RIGHTLEFT
10855 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10856 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10857#endif
10858 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10859 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10860#ifdef FEAT_LINEBREAK
10861 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010862 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10863 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010866 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010867#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010868 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10869 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10870#endif
10871#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010872 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10873 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10874 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010875#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876
10877 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10878 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10881 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10883 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10884#ifdef FEAT_CINDENT
10885 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10886 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10887 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10888#endif
10889#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10890 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10891#endif
10892#ifdef FEAT_COMMENTS
10893 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10894#endif
10895#ifdef FEAT_FOLDING
10896 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10897#endif
10898#ifdef FEAT_INS_EXPAND
10899 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10900#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010901#ifdef FEAT_COMPL_FUNC
10902 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010903 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010904#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010905 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010906 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010908 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010910 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010911 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010912 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10914 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10915 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10916 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10917#ifdef FEAT_FIND_ID
10918# ifdef FEAT_EVAL
10919 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10920# endif
10921#endif
10922#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10923 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10924 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10925#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010926#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010927 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10928#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010929#ifdef FEAT_CRYPT
10930 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10931#endif
10932#ifdef FEAT_LISP
10933 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10934#endif
10935 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10936 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10937 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10938 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10939 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010941#ifdef FEAT_TEXTOBJ
10942 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10943#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10945#ifdef FEAT_SMARTINDENT
10946 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10947#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010948 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10950#ifdef FEAT_SEARCHPATH
10951 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10952#endif
10953 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10954#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010955 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010956 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10957#endif
10958#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010959 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10960 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10961 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010962#endif
10963 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10964 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10965 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10966 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010967#ifdef FEAT_PERSISTENT_UNDO
10968 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10969#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010970 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10971#ifdef FEAT_KEYMAP
10972 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10973#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010974#ifdef FEAT_SIGNS
10975 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10976#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020010977#ifdef FEAT_VARTABS
10978 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
10979 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
10980#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010981 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982 }
10983 /* always return a valid pointer to avoid a crash! */
10984 return (char_u *)&(curbuf->b_p_wm);
10985}
10986
10987/*
10988 * Get the value of 'equalprg', either the buffer-local one or the global one.
10989 */
10990 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010991get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010992{
10993 if (*curbuf->b_p_ep == NUL)
10994 return p_ep;
10995 return curbuf->b_p_ep;
10996}
10997
Bram Moolenaar071d4272004-06-13 20:20:40 +000010998/*
10999 * Copy options from one window to another.
11000 * Used when splitting a window.
11001 */
11002 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011003win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011004{
11005 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11006 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
11007# ifdef FEAT_RIGHTLEFT
11008# ifdef FEAT_FKMAP
11009 /* Is this right? */
11010 wp_to->w_farsi = wp_from->w_farsi;
11011# endif
11012# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011013#if defined(FEAT_LINEBREAK)
11014 briopt_check(wp_to);
11015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011016}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011017
11018/*
11019 * Copy the options from one winopt_T to another.
11020 * Doesn't free the old option values in "to", use clear_winopt() for that.
11021 * The 'scroll' option is not copied, because it depends on the window height.
11022 * The 'previewwindow' option is reset, there can be only one preview window.
11023 */
11024 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011025copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011026{
11027#ifdef FEAT_ARABIC
11028 to->wo_arab = from->wo_arab;
11029#endif
11030 to->wo_list = from->wo_list;
11031 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011032 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011033#ifdef FEAT_LINEBREAK
11034 to->wo_nuw = from->wo_nuw;
11035#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011036#ifdef FEAT_RIGHTLEFT
11037 to->wo_rl = from->wo_rl;
11038 to->wo_rlc = vim_strsave(from->wo_rlc);
11039#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011040#ifdef FEAT_STL_OPT
11041 to->wo_stl = vim_strsave(from->wo_stl);
11042#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011043 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011044#ifdef FEAT_DIFF
11045 to->wo_wrap_save = from->wo_wrap_save;
11046#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011047#ifdef FEAT_LINEBREAK
11048 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011049 to->wo_bri = from->wo_bri;
11050 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011052 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011053 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011054 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011055 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011056#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011057 to->wo_spell = from->wo_spell;
11058#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011059#ifdef FEAT_SYN_HL
11060 to->wo_cuc = from->wo_cuc;
11061 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011062 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011063#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011064#ifdef FEAT_DIFF
11065 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011066 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011067#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011068#ifdef FEAT_CONCEAL
11069 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011070 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011071#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011072#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011073 to->wo_twk = vim_strsave(from->wo_twk);
11074 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011075#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076#ifdef FEAT_FOLDING
11077 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011078 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011080 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011081 to->wo_fdi = vim_strsave(from->wo_fdi);
11082 to->wo_fml = from->wo_fml;
11083 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011084 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011086 to->wo_fdm_save = from->wo_diff_saved
11087 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011088 to->wo_fdn = from->wo_fdn;
11089# ifdef FEAT_EVAL
11090 to->wo_fde = vim_strsave(from->wo_fde);
11091 to->wo_fdt = vim_strsave(from->wo_fdt);
11092# endif
11093 to->wo_fmr = vim_strsave(from->wo_fmr);
11094#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011095#ifdef FEAT_SIGNS
11096 to->wo_scl = vim_strsave(from->wo_scl);
11097#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098 check_winopt(to); /* don't want NULL pointers */
11099}
11100
11101/*
11102 * Check string options in a window for a NULL value.
11103 */
11104 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011105check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011106{
11107 check_winopt(&win->w_onebuf_opt);
11108 check_winopt(&win->w_allbuf_opt);
11109}
11110
11111/*
11112 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11113 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011114 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011115check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011116{
11117#ifdef FEAT_FOLDING
11118 check_string_option(&wop->wo_fdi);
11119 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011120 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011121# ifdef FEAT_EVAL
11122 check_string_option(&wop->wo_fde);
11123 check_string_option(&wop->wo_fdt);
11124# endif
11125 check_string_option(&wop->wo_fmr);
11126#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011127#ifdef FEAT_SIGNS
11128 check_string_option(&wop->wo_scl);
11129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011130#ifdef FEAT_RIGHTLEFT
11131 check_string_option(&wop->wo_rlc);
11132#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011133#ifdef FEAT_STL_OPT
11134 check_string_option(&wop->wo_stl);
11135#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011136#ifdef FEAT_SYN_HL
11137 check_string_option(&wop->wo_cc);
11138#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011139#ifdef FEAT_CONCEAL
11140 check_string_option(&wop->wo_cocu);
11141#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011142#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011143 check_string_option(&wop->wo_twk);
11144 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011145#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011146#ifdef FEAT_LINEBREAK
11147 check_string_option(&wop->wo_briopt);
11148#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011149}
11150
11151/*
11152 * Free the allocated memory inside a winopt_T.
11153 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011155clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156{
11157#ifdef FEAT_FOLDING
11158 clear_string_option(&wop->wo_fdi);
11159 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011160 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011161# ifdef FEAT_EVAL
11162 clear_string_option(&wop->wo_fde);
11163 clear_string_option(&wop->wo_fdt);
11164# endif
11165 clear_string_option(&wop->wo_fmr);
11166#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011167#ifdef FEAT_SIGNS
11168 clear_string_option(&wop->wo_scl);
11169#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011170#ifdef FEAT_LINEBREAK
11171 clear_string_option(&wop->wo_briopt);
11172#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173#ifdef FEAT_RIGHTLEFT
11174 clear_string_option(&wop->wo_rlc);
11175#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011176#ifdef FEAT_STL_OPT
11177 clear_string_option(&wop->wo_stl);
11178#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011179#ifdef FEAT_SYN_HL
11180 clear_string_option(&wop->wo_cc);
11181#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011182#ifdef FEAT_CONCEAL
11183 clear_string_option(&wop->wo_cocu);
11184#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011185#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011186 clear_string_option(&wop->wo_twk);
11187 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011189}
11190
11191/*
11192 * Copy global option values to local options for one buffer.
11193 * Used when creating a new buffer and sometimes when entering a buffer.
11194 * flags:
11195 * BCO_ENTER We will enter the buf buffer.
11196 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11197 * appropriate.
11198 * BCO_NOHELP Don't copy the values to a help buffer.
11199 */
11200 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011201buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202{
11203 int should_copy = TRUE;
11204 char_u *save_p_isk = NULL; /* init for GCC */
11205 int dont_do_help;
11206 int did_isk = FALSE;
11207
11208 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011209 * Skip this when the option defaults have not been set yet. Happens when
11210 * main() allocates the first buffer.
11211 */
11212 if (p_cpo != NULL)
11213 {
11214 /*
11215 * Always copy when entering and 'cpo' contains 'S'.
11216 * Don't copy when already initialized.
11217 * Don't copy when 'cpo' contains 's' and not entering.
11218 * 'S' BCO_ENTER initialized 's' should_copy
11219 * yes yes X X TRUE
11220 * yes no yes X FALSE
11221 * no X yes X FALSE
11222 * X no no yes FALSE
11223 * X no no no TRUE
11224 * no yes no X TRUE
11225 */
11226 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11227 && (buf->b_p_initialized
11228 || (!(flags & BCO_ENTER)
11229 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11230 should_copy = FALSE;
11231
11232 if (should_copy || (flags & BCO_ALWAYS))
11233 {
11234 /* Don't copy the options specific to a help buffer when
11235 * BCO_NOHELP is given or the options were initialized already
11236 * (jumping back to a help file with CTRL-T or CTRL-O) */
11237 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11238 || buf->b_p_initialized;
11239 if (dont_do_help) /* don't free b_p_isk */
11240 {
11241 save_p_isk = buf->b_p_isk;
11242 buf->b_p_isk = NULL;
11243 }
11244 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011245 * Always free the allocated strings. If not already initialized,
11246 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247 */
11248 if (!buf->b_p_initialized)
11249 {
11250 free_buf_options(buf, TRUE);
11251 buf->b_p_ro = FALSE; /* don't copy readonly */
11252 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011253 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011254 switch (*p_ffs)
11255 {
11256 case 'm':
11257 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11258 case 'd':
11259 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11260 case 'u':
11261 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11262 default:
11263 buf->b_p_ff = vim_strsave(p_ff);
11264 }
11265 if (buf->b_p_ff != NULL)
11266 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267 buf->b_p_bh = empty_option;
11268 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011269 }
11270 else
11271 free_buf_options(buf, FALSE);
11272
11273 buf->b_p_ai = p_ai;
11274 buf->b_p_ai_nopaste = p_ai_nopaste;
11275 buf->b_p_sw = p_sw;
11276 buf->b_p_tw = p_tw;
11277 buf->b_p_tw_nopaste = p_tw_nopaste;
11278 buf->b_p_tw_nobin = p_tw_nobin;
11279 buf->b_p_wm = p_wm;
11280 buf->b_p_wm_nopaste = p_wm_nopaste;
11281 buf->b_p_wm_nobin = p_wm_nobin;
11282 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011283 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011284 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011285 buf->b_p_et = p_et;
11286 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011287 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011288 buf->b_p_ml = p_ml;
11289 buf->b_p_ml_nobin = p_ml_nobin;
11290 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011291 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011292#ifdef FEAT_INS_EXPAND
11293 buf->b_p_cpt = vim_strsave(p_cpt);
11294#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011295#ifdef FEAT_COMPL_FUNC
11296 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011297 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011298#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011299 buf->b_p_sts = p_sts;
11300 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011301#ifdef FEAT_VARTABS
11302 buf->b_p_vsts = vim_strsave(p_vsts);
11303 if (p_vsts && p_vsts != empty_option)
11304 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11305 else
11306 buf->b_p_vsts_array = 0;
11307 buf->b_p_vsts_nopaste = p_vsts_nopaste
11308 ? vim_strsave(p_vsts_nopaste) : NULL;
11309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011311#ifdef FEAT_COMMENTS
11312 buf->b_p_com = vim_strsave(p_com);
11313#endif
11314#ifdef FEAT_FOLDING
11315 buf->b_p_cms = vim_strsave(p_cms);
11316#endif
11317 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011318 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319 buf->b_p_nf = vim_strsave(p_nf);
11320 buf->b_p_mps = vim_strsave(p_mps);
11321#ifdef FEAT_SMARTINDENT
11322 buf->b_p_si = p_si;
11323#endif
11324 buf->b_p_ci = p_ci;
11325#ifdef FEAT_CINDENT
11326 buf->b_p_cin = p_cin;
11327 buf->b_p_cink = vim_strsave(p_cink);
11328 buf->b_p_cino = vim_strsave(p_cino);
11329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330 /* Don't copy 'filetype', it must be detected */
11331 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332 buf->b_p_pi = p_pi;
11333#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11334 buf->b_p_cinw = vim_strsave(p_cinw);
11335#endif
11336#ifdef FEAT_LISP
11337 buf->b_p_lisp = p_lisp;
11338#endif
11339#ifdef FEAT_SYN_HL
11340 /* Don't copy 'syntax', it must be set */
11341 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011342 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011343 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011344#endif
11345#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011346 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011347 (void)compile_cap_prog(&buf->b_s);
11348 buf->b_s.b_p_spf = vim_strsave(p_spf);
11349 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350#endif
11351#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11352 buf->b_p_inde = vim_strsave(p_inde);
11353 buf->b_p_indk = vim_strsave(p_indk);
11354#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011355 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011356#if defined(FEAT_EVAL)
11357 buf->b_p_fex = vim_strsave(p_fex);
11358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011359#ifdef FEAT_CRYPT
11360 buf->b_p_key = vim_strsave(p_key);
11361#endif
11362#ifdef FEAT_SEARCHPATH
11363 buf->b_p_sua = vim_strsave(p_sua);
11364#endif
11365#ifdef FEAT_KEYMAP
11366 buf->b_p_keymap = vim_strsave(p_keymap);
11367 buf->b_kmap_state |= KEYMAP_INIT;
11368#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011369#ifdef FEAT_TERMINAL
11370 buf->b_p_twsl = p_twsl;
11371#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011372 /* This isn't really an option, but copying the langmap and IME
11373 * state from the current buffer is better than resetting it. */
11374 buf->b_p_iminsert = p_iminsert;
11375 buf->b_p_imsearch = p_imsearch;
11376
11377 /* options that are normally global but also have a local value
11378 * are not copied, start using the global value */
11379 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011380 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011381 buf->b_p_bkc = empty_option;
11382 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383#ifdef FEAT_QUICKFIX
11384 buf->b_p_gp = empty_option;
11385 buf->b_p_mp = empty_option;
11386 buf->b_p_efm = empty_option;
11387#endif
11388 buf->b_p_ep = empty_option;
11389 buf->b_p_kp = empty_option;
11390 buf->b_p_path = empty_option;
11391 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011392 buf->b_p_tc = empty_option;
11393 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011394#ifdef FEAT_FIND_ID
11395 buf->b_p_def = empty_option;
11396 buf->b_p_inc = empty_option;
11397# ifdef FEAT_EVAL
11398 buf->b_p_inex = vim_strsave(p_inex);
11399# endif
11400#endif
11401#ifdef FEAT_INS_EXPAND
11402 buf->b_p_dict = empty_option;
11403 buf->b_p_tsr = empty_option;
11404#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011405#ifdef FEAT_TEXTOBJ
11406 buf->b_p_qe = vim_strsave(p_qe);
11407#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011408#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11409 buf->b_p_bexpr = empty_option;
11410#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011411#if defined(FEAT_CRYPT)
11412 buf->b_p_cm = empty_option;
11413#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011414#ifdef FEAT_PERSISTENT_UNDO
11415 buf->b_p_udf = p_udf;
11416#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011417#ifdef FEAT_LISP
11418 buf->b_p_lw = empty_option;
11419#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011420 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011421
11422 /*
11423 * Don't copy the options set by ex_help(), use the saved values,
11424 * when going from a help buffer to a non-help buffer.
11425 * Don't touch these at all when BCO_NOHELP is used and going from
11426 * or to a help buffer.
11427 */
11428 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011429 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011430 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011431#ifdef FEAT_VARTABS
11432 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11433 tabstop_set(p_vts, &buf->b_p_vts_array);
11434 else
11435 buf->b_p_vts_array = NULL;
11436#endif
11437 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011438 else
11439 {
11440 buf->b_p_isk = vim_strsave(p_isk);
11441 did_isk = TRUE;
11442 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011443#ifdef FEAT_VARTABS
11444 buf->b_p_vts = vim_strsave(p_vts);
11445 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11446 tabstop_set(p_vts, &buf->b_p_vts_array);
11447 else
11448 buf->b_p_vts_array = NULL;
11449#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011450 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011451 if (buf->b_p_bt[0] == 'h')
11452 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011453 buf->b_p_ma = p_ma;
11454 }
11455 }
11456
11457 /*
11458 * When the options should be copied (ignoring BCO_ALWAYS), set the
11459 * flag that indicates that the options have been initialized.
11460 */
11461 if (should_copy)
11462 buf->b_p_initialized = TRUE;
11463 }
11464
11465 check_buf_options(buf); /* make sure we don't have NULLs */
11466 if (did_isk)
11467 (void)buf_init_chartab(buf, FALSE);
11468}
11469
11470/*
11471 * Reset the 'modifiable' option and its default value.
11472 */
11473 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011474reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011475{
11476 int opt_idx;
11477
11478 curbuf->b_p_ma = FALSE;
11479 p_ma = FALSE;
11480 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011481 if (opt_idx >= 0)
11482 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011483}
11484
11485/*
11486 * Set the global value for 'iminsert' to the local value.
11487 */
11488 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011489set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011490{
11491 p_iminsert = curbuf->b_p_iminsert;
11492}
11493
11494/*
11495 * Set the global value for 'imsearch' to the local value.
11496 */
11497 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011498set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499{
11500 p_imsearch = curbuf->b_p_imsearch;
11501}
11502
11503#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11504static int expand_option_idx = -1;
11505static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11506static int expand_option_flags = 0;
11507
11508 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011509set_context_in_set_cmd(
11510 expand_T *xp,
11511 char_u *arg,
11512 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011513{
11514 int nextchar;
11515 long_u flags = 0; /* init for GCC */
11516 int opt_idx = 0; /* init for GCC */
11517 char_u *p;
11518 char_u *s;
11519 int is_term_option = FALSE;
11520 int key;
11521
11522 expand_option_flags = opt_flags;
11523
11524 xp->xp_context = EXPAND_SETTINGS;
11525 if (*arg == NUL)
11526 {
11527 xp->xp_pattern = arg;
11528 return;
11529 }
11530 p = arg + STRLEN(arg) - 1;
11531 if (*p == ' ' && *(p - 1) != '\\')
11532 {
11533 xp->xp_pattern = p + 1;
11534 return;
11535 }
11536 while (p > arg)
11537 {
11538 s = p;
11539 /* count number of backslashes before ' ' or ',' */
11540 if (*p == ' ' || *p == ',')
11541 {
11542 while (s > arg && *(s - 1) == '\\')
11543 --s;
11544 }
11545 /* break at a space with an even number of backslashes */
11546 if (*p == ' ' && ((p - s) & 1) == 0)
11547 {
11548 ++p;
11549 break;
11550 }
11551 --p;
11552 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011553 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011554 {
11555 xp->xp_context = EXPAND_BOOL_SETTINGS;
11556 p += 2;
11557 }
11558 if (STRNCMP(p, "inv", 3) == 0)
11559 {
11560 xp->xp_context = EXPAND_BOOL_SETTINGS;
11561 p += 3;
11562 }
11563 xp->xp_pattern = arg = p;
11564 if (*arg == '<')
11565 {
11566 while (*p != '>')
11567 if (*p++ == NUL) /* expand terminal option name */
11568 return;
11569 key = get_special_key_code(arg + 1);
11570 if (key == 0) /* unknown name */
11571 {
11572 xp->xp_context = EXPAND_NOTHING;
11573 return;
11574 }
11575 nextchar = *++p;
11576 is_term_option = TRUE;
11577 expand_option_name[2] = KEY2TERMCAP0(key);
11578 expand_option_name[3] = KEY2TERMCAP1(key);
11579 }
11580 else
11581 {
11582 if (p[0] == 't' && p[1] == '_')
11583 {
11584 p += 2;
11585 if (*p != NUL)
11586 ++p;
11587 if (*p == NUL)
11588 return; /* expand option name */
11589 nextchar = *++p;
11590 is_term_option = TRUE;
11591 expand_option_name[2] = p[-2];
11592 expand_option_name[3] = p[-1];
11593 }
11594 else
11595 {
11596 /* Allow * wildcard */
11597 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11598 p++;
11599 if (*p == NUL)
11600 return;
11601 nextchar = *p;
11602 *p = NUL;
11603 opt_idx = findoption(arg);
11604 *p = nextchar;
11605 if (opt_idx == -1 || options[opt_idx].var == NULL)
11606 {
11607 xp->xp_context = EXPAND_NOTHING;
11608 return;
11609 }
11610 flags = options[opt_idx].flags;
11611 if (flags & P_BOOL)
11612 {
11613 xp->xp_context = EXPAND_NOTHING;
11614 return;
11615 }
11616 }
11617 }
11618 /* handle "-=" and "+=" */
11619 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11620 {
11621 ++p;
11622 nextchar = '=';
11623 }
11624 if ((nextchar != '=' && nextchar != ':')
11625 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11626 {
11627 xp->xp_context = EXPAND_UNSUCCESSFUL;
11628 return;
11629 }
11630 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11631 {
11632 xp->xp_context = EXPAND_OLD_SETTING;
11633 if (is_term_option)
11634 expand_option_idx = -1;
11635 else
11636 expand_option_idx = opt_idx;
11637 xp->xp_pattern = p + 1;
11638 return;
11639 }
11640 xp->xp_context = EXPAND_NOTHING;
11641 if (is_term_option || (flags & P_NUM))
11642 return;
11643
11644 xp->xp_pattern = p + 1;
11645
11646 if (flags & P_EXPAND)
11647 {
11648 p = options[opt_idx].var;
11649 if (p == (char_u *)&p_bdir
11650 || p == (char_u *)&p_dir
11651 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011652 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011653 || p == (char_u *)&p_rtp
11654#ifdef FEAT_SEARCHPATH
11655 || p == (char_u *)&p_cdpath
11656#endif
11657#ifdef FEAT_SESSION
11658 || p == (char_u *)&p_vdir
11659#endif
11660 )
11661 {
11662 xp->xp_context = EXPAND_DIRECTORIES;
11663 if (p == (char_u *)&p_path
11664#ifdef FEAT_SEARCHPATH
11665 || p == (char_u *)&p_cdpath
11666#endif
11667 )
11668 xp->xp_backslash = XP_BS_THREE;
11669 else
11670 xp->xp_backslash = XP_BS_ONE;
11671 }
11672 else
11673 {
11674 xp->xp_context = EXPAND_FILES;
11675 /* for 'tags' need three backslashes for a space */
11676 if (p == (char_u *)&p_tags)
11677 xp->xp_backslash = XP_BS_THREE;
11678 else
11679 xp->xp_backslash = XP_BS_ONE;
11680 }
11681 }
11682
11683 /* For an option that is a list of file names, find the start of the
11684 * last file name. */
11685 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11686 {
11687 /* count number of backslashes before ' ' or ',' */
11688 if (*p == ' ' || *p == ',')
11689 {
11690 s = p;
11691 while (s > xp->xp_pattern && *(s - 1) == '\\')
11692 --s;
11693 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11694 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11695 {
11696 xp->xp_pattern = p + 1;
11697 break;
11698 }
11699 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011700
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011701#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011702 /* for 'spellsuggest' start at "file:" */
11703 if (options[opt_idx].var == (char_u *)&p_sps
11704 && STRNCMP(p, "file:", 5) == 0)
11705 {
11706 xp->xp_pattern = p + 5;
11707 break;
11708 }
11709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011710 }
11711
11712 return;
11713}
11714
11715 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011716ExpandSettings(
11717 expand_T *xp,
11718 regmatch_T *regmatch,
11719 int *num_file,
11720 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011721{
11722 int num_normal = 0; /* Nr of matching non-term-code settings */
11723 int num_term = 0; /* Nr of matching terminal code settings */
11724 int opt_idx;
11725 int match;
11726 int count = 0;
11727 char_u *str;
11728 int loop;
11729 int is_term_opt;
11730 char_u name_buf[MAX_KEY_NAME_LEN];
11731 static char *(names[]) = {"all", "termcap"};
11732 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11733
11734 /* do this loop twice:
11735 * loop == 0: count the number of matching options
11736 * loop == 1: copy the matching options into allocated memory
11737 */
11738 for (loop = 0; loop <= 1; ++loop)
11739 {
11740 regmatch->rm_ic = ic;
11741 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11742 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011743 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11744 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011745 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11746 {
11747 if (loop == 0)
11748 num_normal++;
11749 else
11750 (*file)[count++] = vim_strsave((char_u *)names[match]);
11751 }
11752 }
11753 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11754 opt_idx++)
11755 {
11756 if (options[opt_idx].var == NULL)
11757 continue;
11758 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11759 && !(options[opt_idx].flags & P_BOOL))
11760 continue;
11761 is_term_opt = istermoption(&options[opt_idx]);
11762 if (is_term_opt && num_normal > 0)
11763 continue;
11764 match = FALSE;
11765 if (vim_regexec(regmatch, str, (colnr_T)0)
11766 || (options[opt_idx].shortname != NULL
11767 && vim_regexec(regmatch,
11768 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11769 match = TRUE;
11770 else if (is_term_opt)
11771 {
11772 name_buf[0] = '<';
11773 name_buf[1] = 't';
11774 name_buf[2] = '_';
11775 name_buf[3] = str[2];
11776 name_buf[4] = str[3];
11777 name_buf[5] = '>';
11778 name_buf[6] = NUL;
11779 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11780 {
11781 match = TRUE;
11782 str = name_buf;
11783 }
11784 }
11785 if (match)
11786 {
11787 if (loop == 0)
11788 {
11789 if (is_term_opt)
11790 num_term++;
11791 else
11792 num_normal++;
11793 }
11794 else
11795 (*file)[count++] = vim_strsave(str);
11796 }
11797 }
11798 /*
11799 * Check terminal key codes, these are not in the option table
11800 */
11801 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11802 {
11803 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11804 {
11805 if (!isprint(str[0]) || !isprint(str[1]))
11806 continue;
11807
11808 name_buf[0] = 't';
11809 name_buf[1] = '_';
11810 name_buf[2] = str[0];
11811 name_buf[3] = str[1];
11812 name_buf[4] = NUL;
11813
11814 match = FALSE;
11815 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11816 match = TRUE;
11817 else
11818 {
11819 name_buf[0] = '<';
11820 name_buf[1] = 't';
11821 name_buf[2] = '_';
11822 name_buf[3] = str[0];
11823 name_buf[4] = str[1];
11824 name_buf[5] = '>';
11825 name_buf[6] = NUL;
11826
11827 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11828 match = TRUE;
11829 }
11830 if (match)
11831 {
11832 if (loop == 0)
11833 num_term++;
11834 else
11835 (*file)[count++] = vim_strsave(name_buf);
11836 }
11837 }
11838
11839 /*
11840 * Check special key names.
11841 */
11842 regmatch->rm_ic = TRUE; /* ignore case here */
11843 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11844 {
11845 name_buf[0] = '<';
11846 STRCPY(name_buf + 1, str);
11847 STRCAT(name_buf, ">");
11848
11849 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11850 {
11851 if (loop == 0)
11852 num_term++;
11853 else
11854 (*file)[count++] = vim_strsave(name_buf);
11855 }
11856 }
11857 }
11858 if (loop == 0)
11859 {
11860 if (num_normal > 0)
11861 *num_file = num_normal;
11862 else if (num_term > 0)
11863 *num_file = num_term;
11864 else
11865 return OK;
11866 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11867 if (*file == NULL)
11868 {
11869 *file = (char_u **)"";
11870 return FAIL;
11871 }
11872 }
11873 }
11874 return OK;
11875}
11876
11877 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011878ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011879{
11880 char_u *var = NULL; /* init for GCC */
11881 char_u *buf;
11882
11883 *num_file = 0;
11884 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11885 if (*file == NULL)
11886 return FAIL;
11887
11888 /*
11889 * For a terminal key code expand_option_idx is < 0.
11890 */
11891 if (expand_option_idx < 0)
11892 {
11893 var = find_termcode(expand_option_name + 2);
11894 if (var == NULL)
11895 expand_option_idx = findoption(expand_option_name);
11896 }
11897
11898 if (expand_option_idx >= 0)
11899 {
11900 /* put string of option value in NameBuff */
11901 option_value2string(&options[expand_option_idx], expand_option_flags);
11902 var = NameBuff;
11903 }
11904 else if (var == NULL)
11905 var = (char_u *)"";
11906
11907 /* A backslash is required before some characters. This is the reverse of
11908 * what happens in do_set(). */
11909 buf = vim_strsave_escaped(var, escape_chars);
11910
11911 if (buf == NULL)
11912 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011913 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011914 return FAIL;
11915 }
11916
11917#ifdef BACKSLASH_IN_FILENAME
11918 /* For MS-Windows et al. we don't double backslashes at the start and
11919 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011920 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011921 if (var[0] == '\\' && var[1] == '\\'
11922 && expand_option_idx >= 0
11923 && (options[expand_option_idx].flags & P_EXPAND)
11924 && vim_isfilec(var[2])
11925 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011926 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011927#endif
11928
11929 *file[0] = buf;
11930 *num_file = 1;
11931 return OK;
11932}
11933#endif
11934
11935/*
11936 * Get the value for the numeric or string option *opp in a nice format into
11937 * NameBuff[]. Must not be called with a hidden option!
11938 */
11939 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011940option_value2string(
11941 struct vimoption *opp,
11942 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011943{
11944 char_u *varp;
11945
11946 varp = get_varp_scope(opp, opt_flags);
11947
11948 if (opp->flags & P_NUM)
11949 {
11950 long wc = 0;
11951
11952 if (wc_use_keyname(varp, &wc))
11953 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11954 else if (wc != 0)
11955 STRCPY(NameBuff, transchar((int)wc));
11956 else
11957 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11958 }
11959 else /* P_STRING */
11960 {
11961 varp = *(char_u **)(varp);
11962 if (varp == NULL) /* just in case */
11963 NameBuff[0] = NUL;
11964#ifdef FEAT_CRYPT
11965 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011966 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011967 STRCPY(NameBuff, "*****");
11968#endif
11969 else if (opp->flags & P_EXPAND)
11970 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11971 /* Translate 'pastetoggle' into special key names */
11972 else if ((char_u **)opp->var == &p_pt)
11973 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11974 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011975 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011976 }
11977}
11978
11979/*
11980 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11981 * printed as a keyname.
11982 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11983 */
11984 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011985wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011986{
11987 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11988 {
11989 *wcp = *(long *)varp;
11990 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11991 return TRUE;
11992 }
11993 return FALSE;
11994}
11995
Bram Moolenaar01615492015-02-03 13:00:38 +010011996#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011997/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000011998 * Any character has an equivalent 'langmap' character. This is used for
11999 * keyboards that have a special language mode that sends characters above
12000 * 128 (although other characters can be translated too). The "to" field is a
12001 * Vim command character. This avoids having to switch the keyboard back to
12002 * ASCII mode when leaving Insert mode.
12003 *
12004 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12005 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012006 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12007 * same as langmap_mapchar[] for characters >= 256.
12008 *
12009 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012010 */
12011typedef struct
12012{
12013 int from;
12014 int to;
12015} langmap_entry_T;
12016
12017static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012018
12019/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012020 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12021 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012022 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012023 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012024langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012025{
12026 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012027 int a = 0;
12028 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012029
12030 /* Do a binary search for an existing entry. */
12031 while (a != b)
12032 {
12033 int i = (a + b) / 2;
12034 int d = entries[i].from - from;
12035
12036 if (d == 0)
12037 {
12038 entries[i].to = to;
12039 return;
12040 }
12041 if (d < 0)
12042 a = i + 1;
12043 else
12044 b = i;
12045 }
12046
12047 if (ga_grow(&langmap_mapga, 1) != OK)
12048 return; /* out of memory */
12049
12050 /* insert new entry at position "a" */
12051 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12052 mch_memmove(entries + 1, entries,
12053 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12054 ++langmap_mapga.ga_len;
12055 entries[0].from = from;
12056 entries[0].to = to;
12057}
12058
12059/*
12060 * Apply 'langmap' to multi-byte character "c" and return the result.
12061 */
12062 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012063langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012064{
12065 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12066 int a = 0;
12067 int b = langmap_mapga.ga_len;
12068
12069 while (a != b)
12070 {
12071 int i = (a + b) / 2;
12072 int d = entries[i].from - c;
12073
12074 if (d == 0)
12075 return entries[i].to; /* found matching entry */
12076 if (d < 0)
12077 a = i + 1;
12078 else
12079 b = i;
12080 }
12081 return c; /* no entry found, return "c" unmodified */
12082}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012083
12084 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012085langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012086{
12087 int i;
12088
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012089 for (i = 0; i < 256; i++)
12090 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012091 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012092}
12093
12094/*
12095 * Called when langmap option is set; the language map can be
12096 * changed at any time!
12097 */
12098 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012099langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100{
12101 char_u *p;
12102 char_u *p2;
12103 int from, to;
12104
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012105 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012106 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012107
12108 for (p = p_langmap; p[0] != NUL; )
12109 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012110 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012111 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012112 {
12113 if (p2[0] == '\\' && p2[1] != NUL)
12114 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012115 }
12116 if (p2[0] == ';')
12117 ++p2; /* abcd;ABCD form, p2 points to A */
12118 else
12119 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12120 while (p[0])
12121 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012122 if (p[0] == ',')
12123 {
12124 ++p;
12125 break;
12126 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012127 if (p[0] == '\\' && p[1] != NUL)
12128 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012129 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012130 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012131 if (p2 == NULL)
12132 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012133 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012134 if (p[0] != ',')
12135 {
12136 if (p[0] == '\\')
12137 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012138 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012139 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012140 }
12141 else
12142 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012143 if (p2[0] != ',')
12144 {
12145 if (p2[0] == '\\')
12146 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012147 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 }
12150 if (to == NUL)
12151 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012152 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012153 transchar(from));
12154 return;
12155 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012156
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012157 if (from >= 256)
12158 langmap_set_entry(from, to);
12159 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012160 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161
12162 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012163 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012164 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012166 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167 if (*p == ';')
12168 {
12169 p = p2;
12170 if (p[0] != NUL)
12171 {
12172 if (p[0] != ',')
12173 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012174 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175 return;
12176 }
12177 ++p;
12178 }
12179 break;
12180 }
12181 }
12182 }
12183 }
12184}
12185#endif
12186
12187/*
12188 * Return TRUE if format option 'x' is in effect.
12189 * Take care of no formatting when 'paste' is set.
12190 */
12191 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012192has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193{
12194 if (p_paste)
12195 return FALSE;
12196 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12197}
12198
12199/*
12200 * Return TRUE if "x" is present in 'shortmess' option, or
12201 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12202 */
12203 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012204shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012205{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012206 return p_shm != NULL &&
12207 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012208 || (vim_strchr(p_shm, 'a') != NULL
12209 && vim_strchr((char_u *)SHM_A, x) != NULL));
12210}
12211
12212/*
12213 * paste_option_changed() - Called after p_paste was set or reset.
12214 */
12215 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012216paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012217{
12218 static int old_p_paste = FALSE;
12219 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012220 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221#ifdef FEAT_CMDL_INFO
12222 static int save_ru = 0;
12223#endif
12224#ifdef FEAT_RIGHTLEFT
12225 static int save_ri = 0;
12226 static int save_hkmap = 0;
12227#endif
12228 buf_T *buf;
12229
12230 if (p_paste)
12231 {
12232 /*
12233 * Paste switched from off to on.
12234 * Save the current values, so they can be restored later.
12235 */
12236 if (!old_p_paste)
12237 {
12238 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012239 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012240 {
12241 buf->b_p_tw_nopaste = buf->b_p_tw;
12242 buf->b_p_wm_nopaste = buf->b_p_wm;
12243 buf->b_p_sts_nopaste = buf->b_p_sts;
12244 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012245 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012246#ifdef FEAT_VARTABS
12247 if (buf->b_p_vsts_nopaste)
12248 vim_free(buf->b_p_vsts_nopaste);
12249 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12250 ? vim_strsave(buf->b_p_vsts) : NULL;
12251#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012252 }
12253
12254 /* save global options */
12255 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012256 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257#ifdef FEAT_CMDL_INFO
12258 save_ru = p_ru;
12259#endif
12260#ifdef FEAT_RIGHTLEFT
12261 save_ri = p_ri;
12262 save_hkmap = p_hkmap;
12263#endif
12264 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012265 p_ai_nopaste = p_ai;
12266 p_et_nopaste = p_et;
12267 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012268 p_tw_nopaste = p_tw;
12269 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012270#ifdef FEAT_VARTABS
12271 if (p_vsts_nopaste)
12272 vim_free(p_vsts_nopaste);
12273 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012275 }
12276
12277 /*
12278 * Always set the option values, also when 'paste' is set when it is
12279 * already on.
12280 */
12281 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012282 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012283 {
12284 buf->b_p_tw = 0; /* textwidth is 0 */
12285 buf->b_p_wm = 0; /* wrapmargin is 0 */
12286 buf->b_p_sts = 0; /* softtabstop is 0 */
12287 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012288 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012289#ifdef FEAT_VARTABS
12290 if (buf->b_p_vsts)
12291 free_string_option(buf->b_p_vsts);
12292 buf->b_p_vsts = empty_option;
12293 if (buf->b_p_vsts_array)
12294 vim_free(buf->b_p_vsts_array);
12295 buf->b_p_vsts_array = 0;
12296#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012297 }
12298
12299 /* set global options */
12300 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012301 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012302#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012303 if (p_ru)
12304 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012305 p_ru = 0; /* no ruler */
12306#endif
12307#ifdef FEAT_RIGHTLEFT
12308 p_ri = 0; /* no reverse insert */
12309 p_hkmap = 0; /* no Hebrew keyboard */
12310#endif
12311 /* set global values for local buffer options */
12312 p_tw = 0;
12313 p_wm = 0;
12314 p_sts = 0;
12315 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012316#ifdef FEAT_VARTABS
12317 if (p_vsts)
12318 free_string_option(p_vsts);
12319 p_vsts = empty_option;
12320#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012321 }
12322
12323 /*
12324 * Paste switched from on to off: Restore saved values.
12325 */
12326 else if (old_p_paste)
12327 {
12328 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012329 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012330 {
12331 buf->b_p_tw = buf->b_p_tw_nopaste;
12332 buf->b_p_wm = buf->b_p_wm_nopaste;
12333 buf->b_p_sts = buf->b_p_sts_nopaste;
12334 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012335 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012336#ifdef FEAT_VARTABS
12337 if (buf->b_p_vsts)
12338 free_string_option(buf->b_p_vsts);
12339 buf->b_p_vsts = buf->b_p_vsts_nopaste
12340 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12341 if (buf->b_p_vsts_array)
12342 vim_free(buf->b_p_vsts_array);
12343 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12344 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12345 else
12346 buf->b_p_vsts_array = 0;
12347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012348 }
12349
12350 /* restore global options */
12351 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012352 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012353#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012354 if (p_ru != save_ru)
12355 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012356 p_ru = save_ru;
12357#endif
12358#ifdef FEAT_RIGHTLEFT
12359 p_ri = save_ri;
12360 p_hkmap = save_hkmap;
12361#endif
12362 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012363 p_ai = p_ai_nopaste;
12364 p_et = p_et_nopaste;
12365 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012366 p_tw = p_tw_nopaste;
12367 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012368#ifdef FEAT_VARTABS
12369 if (p_vsts)
12370 free_string_option(p_vsts);
12371 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012373 }
12374
12375 old_p_paste = p_paste;
12376}
12377
12378/*
12379 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12380 *
12381 * Reset 'compatible' and set the values for options that didn't get set yet
12382 * to the Vim defaults.
12383 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012384 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012385 */
12386 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012387vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012388{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012389 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012390 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012391 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012392
12393 if (!option_was_set((char_u *)"cp"))
12394 {
12395 p_cp = FALSE;
12396 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12397 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12398 set_option_default(opt_idx, OPT_FREE, FALSE);
12399 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012400 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012401 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012402
12403 if (fname != NULL)
12404 {
12405 p = vim_getenv(envname, &dofree);
12406 if (p == NULL)
12407 {
12408 /* Set $MYVIMRC to the first vimrc file found. */
12409 p = FullName_save(fname, FALSE);
12410 if (p != NULL)
12411 {
12412 vim_setenv(envname, p);
12413 vim_free(p);
12414 }
12415 }
12416 else if (dofree)
12417 vim_free(p);
12418 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012419}
12420
12421/*
12422 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12423 */
12424 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012425change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012426{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012427 int opt_idx;
12428
Bram Moolenaar071d4272004-06-13 20:20:40 +000012429 if (p_cp != on)
12430 {
12431 p_cp = on;
12432 compatible_set();
12433 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012434 opt_idx = findoption((char_u *)"cp");
12435 if (opt_idx >= 0)
12436 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012437}
12438
12439/*
12440 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012441 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012442 */
12443 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012444option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445{
12446 int idx;
12447
12448 idx = findoption(name);
12449 if (idx < 0) /* unknown option */
12450 return FALSE;
12451 if (options[idx].flags & P_WAS_SET)
12452 return TRUE;
12453 return FALSE;
12454}
12455
12456/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012457 * Reset the flag indicating option "name" was set.
12458 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012459 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012460reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012461{
12462 int idx = findoption(name);
12463
12464 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012465 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012466 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012467 return OK;
12468 }
12469 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012470}
12471
12472/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012473 * compatible_set() - Called when 'compatible' has been set or unset.
12474 *
12475 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12476 * flag) to a Vi compatible value.
12477 * When 'compatible' is unset: Set all options that have a different default
12478 * for Vim (without the P_VI_DEF flag) to that default.
12479 */
12480 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012481compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012482{
12483 int opt_idx;
12484
12485 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12486 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12487 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12488 set_option_default(opt_idx, OPT_FREE, p_cp);
12489 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012490 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012491}
12492
12493#ifdef FEAT_LINEBREAK
12494
12495# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12496 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012497 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012498# endif
12499
12500/*
12501 * fill_breakat_flags() -- called when 'breakat' changes value.
12502 */
12503 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012504fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012505{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012506 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507 int i;
12508
12509 for (i = 0; i < 256; i++)
12510 breakat_flags[i] = FALSE;
12511
12512 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012513 for (p = p_breakat; *p; p++)
12514 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012515}
12516
12517# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012518 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012519# endif
12520
12521#endif
12522
12523/*
12524 * Check an option that can be a range of string values.
12525 *
12526 * Return OK for correct value, FAIL otherwise.
12527 * Empty is always OK.
12528 */
12529 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012530check_opt_strings(
12531 char_u *val,
12532 char **values,
12533 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012534{
12535 return opt_strings_flags(val, values, NULL, list);
12536}
12537
12538/*
12539 * Handle an option that can be a range of string values.
12540 * Set a flag in "*flagp" for each string present.
12541 *
12542 * Return OK for correct value, FAIL otherwise.
12543 * Empty is always OK.
12544 */
12545 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012546opt_strings_flags(
12547 char_u *val, /* new value */
12548 char **values, /* array of valid string values */
12549 unsigned *flagp,
12550 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012551{
12552 int i;
12553 int len;
12554 unsigned new_flags = 0;
12555
12556 while (*val)
12557 {
12558 for (i = 0; ; ++i)
12559 {
12560 if (values[i] == NULL) /* val not found in values[] */
12561 return FAIL;
12562
12563 len = (int)STRLEN(values[i]);
12564 if (STRNCMP(values[i], val, len) == 0
12565 && ((list && val[len] == ',') || val[len] == NUL))
12566 {
12567 val += len + (val[len] == ',');
12568 new_flags |= (1 << i);
12569 break; /* check next item in val list */
12570 }
12571 }
12572 }
12573 if (flagp != NULL)
12574 *flagp = new_flags;
12575
12576 return OK;
12577}
12578
12579/*
12580 * Read the 'wildmode' option, fill wim_flags[].
12581 */
12582 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012583check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012584{
12585 char_u new_wim_flags[4];
12586 char_u *p;
12587 int i;
12588 int idx = 0;
12589
12590 for (i = 0; i < 4; ++i)
12591 new_wim_flags[i] = 0;
12592
12593 for (p = p_wim; *p; ++p)
12594 {
12595 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12596 ;
12597 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12598 return FAIL;
12599 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12600 new_wim_flags[idx] |= WIM_LONGEST;
12601 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12602 new_wim_flags[idx] |= WIM_FULL;
12603 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12604 new_wim_flags[idx] |= WIM_LIST;
12605 else
12606 return FAIL;
12607 p += i;
12608 if (*p == NUL)
12609 break;
12610 if (*p == ',')
12611 {
12612 if (idx == 3)
12613 return FAIL;
12614 ++idx;
12615 }
12616 }
12617
12618 /* fill remaining entries with last flag */
12619 while (idx < 3)
12620 {
12621 new_wim_flags[idx + 1] = new_wim_flags[idx];
12622 ++idx;
12623 }
12624
12625 /* only when there are no errors, wim_flags[] is changed */
12626 for (i = 0; i < 4; ++i)
12627 wim_flags[i] = new_wim_flags[i];
12628 return OK;
12629}
12630
12631/*
12632 * Check if backspacing over something is allowed.
12633 */
12634 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012635can_bs(
12636 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012637{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012638#ifdef FEAT_JOB_CHANNEL
12639 if (what == BS_START && bt_prompt(curbuf))
12640 return FALSE;
12641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012642 switch (*p_bs)
12643 {
12644 case '2': return TRUE;
12645 case '1': return (what != BS_START);
12646 case '0': return FALSE;
12647 }
12648 return vim_strchr(p_bs, what) != NULL;
12649}
12650
12651/*
12652 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12653 * the file must be considered changed when the value is different.
12654 */
12655 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012656save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012657{
12658 buf->b_start_ffc = *buf->b_p_ff;
12659 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012660 buf->b_start_bomb = buf->b_p_bomb;
12661
Bram Moolenaar071d4272004-06-13 20:20:40 +000012662 /* Only use free/alloc when necessary, they take time. */
12663 if (buf->b_start_fenc == NULL
12664 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12665 {
12666 vim_free(buf->b_start_fenc);
12667 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12668 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012669}
12670
12671/*
12672 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12673 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012674 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12675 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012676 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012677 * When "ignore_empty" is true don't consider a new, empty buffer to be
12678 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012679 */
12680 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012681file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012682{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012683 /* In a buffer that was never loaded the options are not valid. */
12684 if (buf->b_flags & BF_NEVERLOADED)
12685 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012686 if (ignore_empty
12687 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012688 && buf->b_ml.ml_line_count == 1
12689 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12690 return FALSE;
12691 if (buf->b_start_ffc != *buf->b_p_ff)
12692 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012693 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012694 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012695 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12696 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012697 if (buf->b_start_fenc == NULL)
12698 return (*buf->b_p_fenc != NUL);
12699 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012700}
12701
12702/*
12703 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12704 */
12705 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012706check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012707{
12708 return check_opt_strings(p, p_ff_values, FALSE);
12709}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012710
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012711#ifdef FEAT_VARTABS
12712
12713/*
12714 * Set the integer values corresponding to the string setting of 'vartabstop'.
12715 */
12716 int
12717tabstop_set(char_u *var, int **array)
12718{
12719 int valcount = 1;
12720 int t;
12721 char_u *cp;
12722
Bram Moolenaar64f41072018-10-15 22:51:50 +020012723 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012724 {
12725 *array = NULL;
12726 return TRUE;
12727 }
12728
Bram Moolenaar64f41072018-10-15 22:51:50 +020012729 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012730 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012731 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012732 {
12733 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012734
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012735 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12736 {
12737 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012738 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012739 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012740 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012741 return FALSE;
12742 }
12743 }
12744
12745 if (VIM_ISDIGIT(*cp))
12746 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012747 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012748 {
12749 ++valcount;
12750 continue;
12751 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012752 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012753 return FALSE;
12754 }
12755
Bram Moolenaar64f41072018-10-15 22:51:50 +020012756 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012757 (*array)[0] = valcount;
12758
12759 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012760 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012761 {
12762 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012763 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012764 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012765 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012766 ++cp;
12767 }
12768
12769 return TRUE;
12770}
12771
12772/*
12773 * Calculate the number of screen spaces a tab will occupy.
12774 * If "vts" is set then the tab widths are taken from that array,
12775 * otherwise the value of ts is used.
12776 */
12777 int
12778tabstop_padding(colnr_T col, int ts_arg, int *vts)
12779{
12780 int ts = ts_arg == 0 ? 8 : ts_arg;
12781 int tabcount;
12782 colnr_T tabcol = 0;
12783 int t;
12784 int padding = 0;
12785
12786 if (vts == NULL || vts[0] == 0)
12787 return ts - (col % ts);
12788
12789 tabcount = vts[0];
12790
12791 for (t = 1; t <= tabcount; ++t)
12792 {
12793 tabcol += vts[t];
12794 if (tabcol > col)
12795 {
12796 padding = (int)(tabcol - col);
12797 break;
12798 }
12799 }
12800 if (t > tabcount)
12801 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12802
12803 return padding;
12804}
12805
12806/*
12807 * Find the size of the tab that covers a particular column.
12808 */
12809 int
12810tabstop_at(colnr_T col, int ts, int *vts)
12811{
12812 int tabcount;
12813 colnr_T tabcol = 0;
12814 int t;
12815 int tab_size = 0;
12816
12817 if (vts == 0 || vts[0] == 0)
12818 return ts;
12819
12820 tabcount = vts[0];
12821 for (t = 1; t <= tabcount; ++t)
12822 {
12823 tabcol += vts[t];
12824 if (tabcol > col)
12825 {
12826 tab_size = vts[t];
12827 break;
12828 }
12829 }
12830 if (t > tabcount)
12831 tab_size = vts[tabcount];
12832
12833 return tab_size;
12834}
12835
12836/*
12837 * Find the column on which a tab starts.
12838 */
12839 colnr_T
12840tabstop_start(colnr_T col, int ts, int *vts)
12841{
12842 int tabcount;
12843 colnr_T tabcol = 0;
12844 int t;
12845 int excess;
12846
Bram Moolenaar0119a592018-06-24 23:53:28 +020012847 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012848 return (col / ts) * ts;
12849
12850 tabcount = vts[0];
12851 for (t = 1; t <= tabcount; ++t)
12852 {
12853 tabcol += vts[t];
12854 if (tabcol > col)
12855 return tabcol - vts[t];
12856 }
12857
12858 excess = tabcol % vts[tabcount];
12859 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12860}
12861
12862/*
12863 * Find the number of tabs and spaces necessary to get from one column
12864 * to another.
12865 */
12866 void
12867tabstop_fromto(
12868 colnr_T start_col,
12869 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012870 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012871 int *vts,
12872 int *ntabs,
12873 int *nspcs)
12874{
12875 int spaces = end_col - start_col;
12876 colnr_T tabcol = 0;
12877 int padding = 0;
12878 int tabcount;
12879 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012880 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012881
Bram Moolenaar0119a592018-06-24 23:53:28 +020012882 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012883 {
12884 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012885 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012886
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012887 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012888 if (spaces >= initspc)
12889 {
12890 spaces -= initspc;
12891 tabs++;
12892 }
12893 tabs += spaces / ts;
12894 spaces -= (spaces / ts) * ts;
12895
12896 *ntabs = tabs;
12897 *nspcs = spaces;
12898 return;
12899 }
12900
12901 /* Find the padding needed to reach the next tabstop. */
12902 tabcount = vts[0];
12903 for (t = 1; t <= tabcount; ++t)
12904 {
12905 tabcol += vts[t];
12906 if (tabcol > start_col)
12907 {
12908 padding = (int)(tabcol - start_col);
12909 break;
12910 }
12911 }
12912 if (t > tabcount)
12913 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12914
12915 /* If the space needed is less than the padding no tabs can be used. */
12916 if (spaces < padding)
12917 {
12918 *ntabs = 0;
12919 *nspcs = spaces;
12920 return;
12921 }
12922
12923 *ntabs = 1;
12924 spaces -= padding;
12925
12926 /* At least one tab has been used. See if any more will fit. */
12927 while (spaces != 0 && ++t <= tabcount)
12928 {
12929 padding = vts[t];
12930 if (spaces < padding)
12931 {
12932 *nspcs = spaces;
12933 return;
12934 }
12935 ++*ntabs;
12936 spaces -= padding;
12937 }
12938
12939 *ntabs += spaces / vts[tabcount];
12940 *nspcs = spaces % vts[tabcount];
12941}
12942
12943/*
12944 * See if two tabstop arrays contain the same values.
12945 */
12946 int
12947tabstop_eq(int *ts1, int *ts2)
12948{
12949 int t;
12950
12951 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
12952 return FALSE;
12953 if (ts1 == ts2)
12954 return TRUE;
12955 if (ts1[0] != ts2[0])
12956 return FALSE;
12957
12958 for (t = 1; t <= ts1[0]; ++t)
12959 if (ts1[t] != ts2[t])
12960 return FALSE;
12961
12962 return TRUE;
12963}
12964
Bram Moolenaar113e1072019-01-20 15:30:40 +010012965#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012966/*
12967 * Copy a tabstop array, allocating space for the new array.
12968 */
12969 int *
12970tabstop_copy(int *oldts)
12971{
12972 int *newts;
12973 int t;
12974
12975 if (oldts == 0)
12976 return 0;
12977
12978 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
12979 for (t = 0; t <= oldts[0]; ++t)
12980 newts[t] = oldts[t];
12981
12982 return newts;
12983}
Bram Moolenaar113e1072019-01-20 15:30:40 +010012984#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012985
12986/*
12987 * Return a count of the number of tabstops.
12988 */
12989 int
12990tabstop_count(int *ts)
12991{
12992 return ts != NULL ? ts[0] : 0;
12993}
12994
12995/*
12996 * Return the first tabstop, or 8 if there are no tabstops defined.
12997 */
12998 int
12999tabstop_first(int *ts)
13000{
13001 return ts != NULL ? ts[1] : 8;
13002}
13003
13004#endif
13005
Bram Moolenaar14f24742012-08-08 18:01:05 +020013006/*
13007 * Return the effective shiftwidth value for current buffer, using the
13008 * 'tabstop' value when 'shiftwidth' is zero.
13009 */
13010 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013011get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013012{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013013 return get_sw_value_col(buf, 0);
13014}
13015
13016/*
13017 * Idem, using the first non-black in the current line.
13018 */
13019 long
13020get_sw_value_indent(buf_T *buf)
13021{
13022 pos_T pos = curwin->w_cursor;
13023
13024 pos.col = getwhitecols_curline();
13025 return get_sw_value_pos(buf, &pos);
13026}
13027
13028/*
13029 * Idem, using "pos".
13030 */
13031 long
13032get_sw_value_pos(buf_T *buf, pos_T *pos)
13033{
13034 pos_T save_cursor = curwin->w_cursor;
13035 long sw_value;
13036
13037 curwin->w_cursor = *pos;
13038 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13039 curwin->w_cursor = save_cursor;
13040 return sw_value;
13041}
13042
13043/*
13044 * Idem, using virtual column "col".
13045 */
13046 long
13047get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13048{
13049 return buf->b_p_sw ? buf->b_p_sw :
13050 #ifdef FEAT_VARTABS
13051 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13052 #else
13053 buf->b_p_ts;
13054 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013055}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013056
13057/*
13058 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013059 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013060 */
13061 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013062get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013063{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013064 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013065}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013066
13067/*
13068 * Check matchpairs option for "*initc".
13069 * If there is a match set "*initc" to the matching character and "*findc" to
13070 * the opposite character. Set "*backwards" to the direction.
13071 * When "switchit" is TRUE swap the direction.
13072 */
13073 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013074find_mps_values(
13075 int *initc,
13076 int *findc,
13077 int *backwards,
13078 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013079{
13080 char_u *ptr;
13081
13082 ptr = curbuf->b_p_mps;
13083 while (*ptr != NUL)
13084 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013085 if (has_mbyte)
13086 {
13087 char_u *prev;
13088
13089 if (mb_ptr2char(ptr) == *initc)
13090 {
13091 if (switchit)
13092 {
13093 *findc = *initc;
13094 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13095 *backwards = TRUE;
13096 }
13097 else
13098 {
13099 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13100 *backwards = FALSE;
13101 }
13102 return;
13103 }
13104 prev = ptr;
13105 ptr += mb_ptr2len(ptr) + 1;
13106 if (mb_ptr2char(ptr) == *initc)
13107 {
13108 if (switchit)
13109 {
13110 *findc = *initc;
13111 *initc = mb_ptr2char(prev);
13112 *backwards = FALSE;
13113 }
13114 else
13115 {
13116 *findc = mb_ptr2char(prev);
13117 *backwards = TRUE;
13118 }
13119 return;
13120 }
13121 ptr += mb_ptr2len(ptr);
13122 }
13123 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013124 {
13125 if (*ptr == *initc)
13126 {
13127 if (switchit)
13128 {
13129 *backwards = TRUE;
13130 *findc = *initc;
13131 *initc = ptr[2];
13132 }
13133 else
13134 {
13135 *backwards = FALSE;
13136 *findc = ptr[2];
13137 }
13138 return;
13139 }
13140 ptr += 2;
13141 if (*ptr == *initc)
13142 {
13143 if (switchit)
13144 {
13145 *backwards = FALSE;
13146 *findc = *initc;
13147 *initc = ptr[-2];
13148 }
13149 else
13150 {
13151 *backwards = TRUE;
13152 *findc = ptr[-2];
13153 }
13154 return;
13155 }
13156 ++ptr;
13157 }
13158 if (*ptr == ',')
13159 ++ptr;
13160 }
13161}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013162
13163#if defined(FEAT_LINEBREAK) || defined(PROTO)
13164/*
13165 * This is called when 'breakindentopt' is changed and when a window is
13166 * initialized.
13167 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013168 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013169briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013170{
13171 char_u *p;
13172 int bri_shift = 0;
13173 long bri_min = 20;
13174 int bri_sbr = FALSE;
13175
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013176 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013177 while (*p != NUL)
13178 {
13179 if (STRNCMP(p, "shift:", 6) == 0
13180 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13181 {
13182 p += 6;
13183 bri_shift = getdigits(&p);
13184 }
13185 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13186 {
13187 p += 4;
13188 bri_min = getdigits(&p);
13189 }
13190 else if (STRNCMP(p, "sbr", 3) == 0)
13191 {
13192 p += 3;
13193 bri_sbr = TRUE;
13194 }
13195 if (*p != ',' && *p != NUL)
13196 return FAIL;
13197 if (*p == ',')
13198 ++p;
13199 }
13200
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013201 wp->w_p_brishift = bri_shift;
13202 wp->w_p_brimin = bri_min;
13203 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013204
13205 return OK;
13206}
13207#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013208
13209/*
13210 * Get the local or global value of 'backupcopy'.
13211 */
13212 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013213get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013214{
13215 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13216}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013217
13218#if defined(FEAT_SIGNS) || defined(PROTO)
13219/*
13220 * Return TRUE when window "wp" has a column to draw signs in.
13221 */
13222 int
13223signcolumn_on(win_T *wp)
13224{
13225 if (*wp->w_p_scl == 'n')
13226 return FALSE;
13227 if (*wp->w_p_scl == 'y')
13228 return TRUE;
13229 return (wp->w_buffer->b_signlist != NULL
13230# ifdef FEAT_NETBEANS_INTG
13231 || wp->w_buffer->b_has_sign_column
13232# endif
13233 );
13234}
13235#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013236
13237#if defined(FEAT_EVAL) || defined(PROTO)
13238/*
13239 * Get window or buffer local options.
13240 */
13241 dict_T *
13242get_winbuf_options(int bufopt)
13243{
13244 dict_T *d;
13245 int opt_idx;
13246
13247 d = dict_alloc();
13248 if (d == NULL)
13249 return NULL;
13250
13251 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13252 {
13253 struct vimoption *opt = &options[opt_idx];
13254
13255 if ((bufopt && (opt->indir & PV_BUF))
13256 || (!bufopt && (opt->indir & PV_WIN)))
13257 {
13258 char_u *varp = get_varp(opt);
13259
13260 if (varp != NULL)
13261 {
13262 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013263 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013264 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013265 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013266 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013267 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013268 }
13269 }
13270 }
13271
13272 return d;
13273}
13274#endif