blob: dda5414e616a9c2cb11e981e37a31fc1c2d04530 [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 (char_u *)&p_ve, PV_NONE,
2943 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002944 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2946 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002947 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948 {"w300", NULL, P_NUM|P_VI_DEF,
2949 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002950 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002951 {"w1200", NULL, P_NUM|P_VI_DEF,
2952 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002953 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002954 {"w9600", NULL, P_NUM|P_VI_DEF,
2955 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002956 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002957 {"warn", NULL, P_BOOL|P_VI_DEF,
2958 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002959 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002960 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2961 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002962 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002963 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002964 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002965 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 {"wildchar", "wc", P_NUM|P_VIM,
2967 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002968 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002969 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002970 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002971 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002972 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002973 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974#ifdef FEAT_WILDIGN
2975 (char_u *)&p_wig, PV_NONE,
2976#else
2977 (char_u *)NULL, PV_NONE,
2978#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002979 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002980 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
2981 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002982 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
2984#ifdef FEAT_WILDMENU
2985 (char_u *)&p_wmnu, PV_NONE,
2986#else
2987 (char_u *)NULL, PV_NONE,
2988#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002989 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002990 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002992 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00002993 {"wildoptions", "wop", P_STRING|P_VI_DEF,
2994#ifdef FEAT_CMDL_COMPL
2995 (char_u *)&p_wop, PV_NONE,
2996 {(char_u *)"", (char_u *)0L}
2997#else
2998 (char_u *)NULL, PV_NONE,
2999 {(char_u *)NULL, (char_u *)0L}
3000#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003001 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003002 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3003#ifdef FEAT_WAK
3004 (char_u *)&p_wak, PV_NONE,
3005 {(char_u *)"menu", (char_u *)0L}
3006#else
3007 (char_u *)NULL, PV_NONE,
3008 {(char_u *)NULL, (char_u *)0L}
3009#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003010 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003011 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003012 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003013 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003014 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003016 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003017 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003019 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003020 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003021 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003022 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003024 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003025 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003028 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003029 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar84ed4ad2017-08-17 11:33:42 +02003030#if defined(WIN3264) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003031 (char_u *)&p_winptydll, PV_NONE, {
3032# ifdef _WIN64
3033 (char_u *)"winpty64.dll",
3034# else
3035 (char_u *)"winpty32.dll",
3036# endif
3037 (char_u *)0L}
3038#else
3039 (char_u *)NULL, PV_NONE,
3040 {(char_u *)0L, (char_u *)0L}
3041#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003042 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003045 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3047 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003048 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3050 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003051 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3053 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003054 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 {"write", NULL, P_BOOL|P_VI_DEF,
3056 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003057 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 {"writeany", "wa", P_BOOL|P_VI_DEF,
3059 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003060 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003061 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3062 (char_u *)&p_wb, PV_NONE,
3063 {
3064#ifdef FEAT_WRITEBACKUP
3065 (char_u *)TRUE,
3066#else
3067 (char_u *)FALSE,
3068#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003069 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 {"writedelay", "wd", P_NUM|P_VI_DEF,
3071 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003072 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073
3074/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003075#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003077 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078
3079 p_term("t_AB", T_CAB)
3080 p_term("t_AF", T_CAF)
3081 p_term("t_AL", T_CAL)
3082 p_term("t_al", T_AL)
3083 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003084 p_term("t_BE", T_BE)
3085 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 p_term("t_cd", T_CD)
3087 p_term("t_ce", T_CE)
3088 p_term("t_cl", T_CL)
3089 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003090 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 p_term("t_Co", T_CCO)
3092 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003093 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096 p_term("t_da", T_DA)
3097 p_term("t_db", T_DB)
3098 p_term("t_DL", T_CDL)
3099 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003100 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003101 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003102 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003103 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104 p_term("t_IE", T_CIE)
3105 p_term("t_IS", T_CIS)
3106 p_term("t_ke", T_KE)
3107 p_term("t_ks", T_KS)
3108 p_term("t_le", T_LE)
3109 p_term("t_mb", T_MB)
3110 p_term("t_md", T_MD)
3111 p_term("t_me", T_ME)
3112 p_term("t_mr", T_MR)
3113 p_term("t_ms", T_MS)
3114 p_term("t_nd", T_ND)
3115 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003116 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003117 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003118 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003120 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003121 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003122 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_RV", T_CRV)
3124 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003125 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003127 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003128 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003129 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003130 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003131 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003132 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003134 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003135 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003136 p_term("t_te", T_TE)
3137 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003138 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003139 p_term("t_ts", T_TS)
3140 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_ue", T_UE)
3142 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003143 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 p_term("t_vb", T_VB)
3145 p_term("t_ve", T_VE)
3146 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003147 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 p_term("t_vs", T_VS)
3149 p_term("t_WP", T_CWP)
3150 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003151 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152 p_term("t_xs", T_XS)
3153 p_term("t_ZH", T_CZH)
3154 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003155 p_term("t_8f", T_8F)
3156 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157
3158/* terminal key codes are not in here */
3159
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003160 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003161 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162};
3163
3164#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3165
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003168static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003170#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003171static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003172#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003173#ifdef FEAT_CMDL_COMPL
3174static char *(p_wop_values[]) = {"tagfile", NULL};
3175#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003176#ifdef FEAT_WAK
3177static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3178#endif
3179static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3181static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183#ifdef FEAT_BROWSE
3184static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3185#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003186static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003187static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003189static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003190static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3192#ifdef FEAT_FOLDING
3193static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003194# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003195 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003196# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197 NULL};
3198static char *(p_fcl_values[]) = {"all", NULL};
3199#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003200#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003201static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003202#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003203#ifdef FEAT_SIGNS
3204static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003207static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003208static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003209static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003210static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003211static char_u *option_expand(int opt_idx, char_u *val);
3212static void didset_options(void);
3213static void didset_options2(void);
3214static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003215#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003216static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003217#else
3218# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3219#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003220static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003221static 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);
3222static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003223#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003224static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003226#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003227static char *did_set_spell_option(int is_spellfile);
3228static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003229#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003230#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003231static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003232#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003233static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3234static 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 +01003235static void check_redraw(long_u flags);
3236static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003237static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003238static void showoptions(int all, int opt_flags);
3239static int optval_default(struct vimoption *, char_u *varp);
3240static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003241static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003242static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3243static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3244static int istermoption(struct vimoption *);
3245static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3246static char_u *get_varp(struct vimoption *);
3247static void option_value2string(struct vimoption *, int opt_flags);
3248static void check_winopt(winopt_T *wop);
3249static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003251static void langmap_init(void);
3252static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003254static void paste_option_changed(void);
3255static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003256#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003257static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003258#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003259static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3260static int check_opt_strings(char_u *val, char **values, int);
3261static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003262#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265
3266/*
3267 * Initialize the options, first part.
3268 *
3269 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003270 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003271 */
3272 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003273set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274{
3275 char_u *p;
3276 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003277 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278
3279#ifdef FEAT_LANGMAP
3280 langmap_init();
3281#endif
3282
3283 /* Be Vi compatible by default */
3284 p_cp = TRUE;
3285
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003286 /* Use POSIX compatibility when $VIM_POSIX is set. */
3287 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003288 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003289 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003290 set_string_default("shm", (char_u *)"A");
3291 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003292
Bram Moolenaar071d4272004-06-13 20:20:40 +00003293 /*
3294 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003295 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003297 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003298#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003299 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300# ifdef WIN3264
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003301 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302# endif
3303#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003304 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003305 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306
3307#ifdef FEAT_WILDIGN
3308 /*
3309 * Set the default for 'backupskip' to include environment variables for
3310 * temp files.
3311 */
3312 {
3313# ifdef UNIX
3314 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3315# else
3316 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3317# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003318 int len;
3319 garray_T ga;
3320 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321
3322 ga_init2(&ga, 1, 100);
3323 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3324 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003325 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326# ifdef UNIX
3327 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003328# ifdef MACOS_X
3329 p = (char_u *)"/private/tmp";
3330# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003331 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003332# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333 else
3334# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003335 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003336 if (p != NULL && *p != NUL)
3337 {
3338 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003339 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003340 if (ga_grow(&ga, len) == OK)
3341 {
3342 if (ga.ga_len > 0)
3343 STRCAT(ga.ga_data, ",");
3344 STRCAT(ga.ga_data, p);
3345 add_pathsep(ga.ga_data);
3346 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347 ga.ga_len += len;
3348 }
3349 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003350 if (mustfree)
3351 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352 }
3353 if (ga.ga_data != NULL)
3354 {
3355 set_string_default("bsk", ga.ga_data);
3356 vim_free(ga.ga_data);
3357 }
3358 }
3359#endif
3360
3361 /*
3362 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3363 */
3364 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003365 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003367#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3368 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3369#endif
3370 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003372 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003373 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374#else
3375# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003376 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003377 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003379 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380# endif
3381#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003382 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003383 opt_idx = findoption((char_u *)"maxmem");
3384 if (opt_idx >= 0)
3385 {
3386#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003387 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3388 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003389#endif
3390 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3391 }
3392 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393 }
3394
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395#ifdef FEAT_SEARCHPATH
3396 {
3397 char_u *cdpath;
3398 char_u *buf;
3399 int i;
3400 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003401 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402
3403 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003404 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405 if (cdpath != NULL)
3406 {
3407 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3408 if (buf != NULL)
3409 {
3410 buf[0] = ','; /* start with ",", current dir first */
3411 j = 1;
3412 for (i = 0; cdpath[i] != NUL; ++i)
3413 {
3414 if (vim_ispathlistsep(cdpath[i]))
3415 buf[j++] = ',';
3416 else
3417 {
3418 if (cdpath[i] == ' ' || cdpath[i] == ',')
3419 buf[j++] = '\\';
3420 buf[j++] = cdpath[i];
3421 }
3422 }
3423 buf[j] = NUL;
3424 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003425 if (opt_idx >= 0)
3426 {
3427 options[opt_idx].def_val[VI_DEFAULT] = buf;
3428 options[opt_idx].flags |= P_DEF_ALLOCED;
3429 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003430 else
3431 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003433 if (mustfree)
3434 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435 }
3436 }
3437#endif
3438
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003439#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003440 /* Set print encoding on platforms that don't default to latin1 */
3441 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003442# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003443 (char_u *)"cp1252"
3444# else
3445# ifdef VMS
3446 (char_u *)"dec-mcs"
3447# else
3448# ifdef EBCDIC
3449 (char_u *)"ebcdic-uk"
3450# else
3451# ifdef MAC
3452 (char_u *)"mac-roman"
3453# else /* HPUX */
3454 (char_u *)"hp-roman8"
3455# endif
3456# endif
3457# endif
3458# endif
3459 );
3460#endif
3461
3462#ifdef FEAT_POSTSCRIPT
3463 /* 'printexpr' must be allocated to be able to evaluate it. */
3464 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003465# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003466 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467# else
3468# ifdef VMS
3469 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3470
3471# else
3472 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3473# endif
3474# endif
3475 );
3476#endif
3477
3478 /*
3479 * Set all the options (except the terminal options) to their default
3480 * value. Also set the global value for local options.
3481 */
3482 set_options_default(0);
3483
Bram Moolenaar07268702018-03-01 21:57:32 +01003484#ifdef CLEAN_RUNTIMEPATH
3485 if (clean_arg)
3486 {
3487 opt_idx = findoption((char_u *)"runtimepath");
3488 if (opt_idx >= 0)
3489 {
3490 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3491 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3492 }
3493 opt_idx = findoption((char_u *)"packpath");
3494 if (opt_idx >= 0)
3495 {
3496 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3497 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3498 }
3499 }
3500#endif
3501
Bram Moolenaar071d4272004-06-13 20:20:40 +00003502#ifdef FEAT_GUI
3503 if (found_reverse_arg)
3504 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3505#endif
3506
3507 curbuf->b_p_initialized = TRUE;
3508 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003509 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003510 check_buf_options(curbuf);
3511 check_win_options(curwin);
3512 check_options();
3513
3514 /* Must be before option_expand(), because that one needs vim_isIDc() */
3515 didset_options();
3516
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003517#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003518 /* Use the current chartab for the generic chartab. This is not in
3519 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003520 init_spell_chartab();
3521#endif
3522
Bram Moolenaar071d4272004-06-13 20:20:40 +00003523 /*
3524 * Expand environment variables and things like "~" for the defaults.
3525 * If option_expand() returns non-NULL the variable is expanded. This can
3526 * only happen for non-indirect options.
3527 * Also set the default to the expanded value, so ":set" does not list
3528 * them.
3529 * Don't set the P_ALLOCED flag, because we don't want to free the
3530 * default.
3531 */
3532 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3533 {
3534 if ((options[opt_idx].flags & P_GETTEXT)
3535 && options[opt_idx].var != NULL)
3536 p = (char_u *)_(*(char **)options[opt_idx].var);
3537 else
3538 p = option_expand(opt_idx, NULL);
3539 if (p != NULL && (p = vim_strsave(p)) != NULL)
3540 {
3541 *(char_u **)options[opt_idx].var = p;
3542 /* VIMEXP
3543 * Defaults for all expanded options are currently the same for Vi
3544 * and Vim. When this changes, add some code here! Also need to
3545 * split P_DEF_ALLOCED in two.
3546 */
3547 if (options[opt_idx].flags & P_DEF_ALLOCED)
3548 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3549 options[opt_idx].def_val[VI_DEFAULT] = p;
3550 options[opt_idx].flags |= P_DEF_ALLOCED;
3551 }
3552 }
3553
Bram Moolenaar071d4272004-06-13 20:20:40 +00003554 save_file_ff(curbuf); /* Buffer is unchanged */
3555
Bram Moolenaar071d4272004-06-13 20:20:40 +00003556#if defined(FEAT_ARABIC)
3557 /* Detect use of mlterm.
3558 * Mlterm is a terminal emulator akin to xterm that has some special
3559 * abilities (bidi namely).
3560 * NOTE: mlterm's author is being asked to 'set' a variable
3561 * instead of an environment variable due to inheritance.
3562 */
3563 if (mch_getenv((char_u *)"MLTERM") != NULL)
3564 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3565#endif
3566
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003567 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003568
Bram Moolenaar071d4272004-06-13 20:20:40 +00003569# if defined(WIN3264) && defined(FEAT_GETTEXT)
3570 /*
3571 * If $LANG isn't set, try to get a good value for it. This makes the
3572 * right language be used automatically. Don't do this for English.
3573 */
3574 if (mch_getenv((char_u *)"LANG") == NULL)
3575 {
3576 char buf[20];
3577
3578 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3579 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3580 * only the first two. */
3581 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3582 (LPTSTR)buf, 20);
3583 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3584 {
3585 /* There are a few exceptions (probably more) */
3586 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3587 STRCPY(buf, "zh_TW");
3588 else if (STRNICMP(buf, "chs", 3) == 0
3589 || STRNICMP(buf, "zhc", 3) == 0)
3590 STRCPY(buf, "zh_CN");
3591 else if (STRNICMP(buf, "jp", 2) == 0)
3592 STRCPY(buf, "ja");
3593 else
3594 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003595 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 }
3597 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003598# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003599# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003600 /* Moved to os_mac_conv.c to avoid dependency problems. */
3601 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003602# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003603# endif
3604
3605 /* enc_locale() will try to find the encoding of the current locale. */
3606 p = enc_locale();
3607 if (p != NULL)
3608 {
3609 char_u *save_enc;
3610
3611 /* Try setting 'encoding' and check if the value is valid.
3612 * If not, go back to the default "latin1". */
3613 save_enc = p_enc;
3614 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003615 if (STRCMP(p_enc, "gb18030") == 0)
3616 {
3617 /* We don't support "gb18030", but "cp936" is a good substitute
3618 * for practical purposes, thus use that. It's not an alias to
3619 * still support conversion between gb18030 and utf-8. */
3620 p_enc = vim_strsave((char_u *)"cp936");
3621 vim_free(p);
3622 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623 if (mb_init() == NULL)
3624 {
3625 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003626 if (opt_idx >= 0)
3627 {
3628 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3629 options[opt_idx].flags |= P_DEF_ALLOCED;
3630 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003631
Bram Moolenaard0573012017-10-28 21:11:06 +02003632#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003633 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003634 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003635 /* Adjust the default for 'isprint' and 'iskeyword' to match
3636 * latin1. Also set the defaults for when 'nocompatible' is
3637 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003638 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003639 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003640 set_string_option_direct((char_u *)"isk", -1,
3641 ISK_LATIN1, OPT_FREE, SID_NONE);
3642 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003643 if (opt_idx >= 0)
3644 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003645 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003646 if (opt_idx >= 0)
3647 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003648 (void)init_chartab();
3649 }
3650#endif
3651
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003652#if defined(WIN3264) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653 /* Win32 console: When GetACP() returns a different value from
3654 * GetConsoleCP() set 'termencoding'. */
3655 if (GetACP() != GetConsoleCP())
3656 {
3657 char buf[50];
3658
3659 sprintf(buf, "cp%ld", (long)GetConsoleCP());
3660 p_tenc = vim_strsave((char_u *)buf);
3661 if (p_tenc != NULL)
3662 {
3663 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003664 if (opt_idx >= 0)
3665 {
3666 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3667 options[opt_idx].flags |= P_DEF_ALLOCED;
3668 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003669 convert_setup(&input_conv, p_tenc, p_enc);
3670 convert_setup(&output_conv, p_enc, p_tenc);
3671 }
3672 else
3673 p_tenc = empty_option;
3674 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003675#endif
3676#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003677 /* $HOME may have characters in active code page. */
3678 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003679#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680 }
3681 else
3682 {
3683 vim_free(p_enc);
3684 p_enc = save_enc;
3685 }
3686 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687
3688#ifdef FEAT_MULTI_LANG
3689 /* Set the default for 'helplang'. */
3690 set_helplang_default(get_mess_lang());
3691#endif
3692}
3693
3694/*
3695 * Set an option to its default value.
3696 * This does not take care of side effects!
3697 */
3698 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003699set_option_default(
3700 int opt_idx,
3701 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3702 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003703{
3704 char_u *varp; /* pointer to variable for current option */
3705 int dvi; /* index in def_val[] */
3706 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003707 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003708 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3709
3710 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3711 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003712 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003713 {
3714 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3715 if (flags & P_STRING)
3716 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003717 /* Use set_string_option_direct() for local options to handle
3718 * freeing and allocating the value. */
3719 if (options[opt_idx].indir != PV_NONE)
3720 set_string_option_direct(NULL, opt_idx,
3721 options[opt_idx].def_val[dvi], opt_flags, 0);
3722 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003724 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3725 free_string_option(*(char_u **)(varp));
3726 *(char_u **)varp = options[opt_idx].def_val[dvi];
3727 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003728 }
3729 }
3730 else if (flags & P_NUM)
3731 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003732 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003733 win_comp_scroll(curwin);
3734 else
3735 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003736 *(long *)varp = (long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 /* May also set global value for local option. */
3738 if (both)
3739 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3740 *(long *)varp;
3741 }
3742 }
3743 else /* P_BOOL */
3744 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003745 /* the cast to long is required for Manx C, long_i is needed for
3746 * MSVC */
3747 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003748#ifdef UNIX
3749 /* 'modeline' defaults to off for root */
3750 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3751 *(int *)varp = FALSE;
3752#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003753 /* May also set global value for local option. */
3754 if (both)
3755 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3756 *(int *)varp;
3757 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003758
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003759 /* The default value is not insecure. */
3760 flagsp = insecure_flag(opt_idx, opt_flags);
3761 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 }
3763
3764#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003765 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766#endif
3767}
3768
3769/*
3770 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003771 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 */
3773 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003774set_options_default(
3775 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776{
3777 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003778 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003779 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780
3781 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003782 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003783 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003784 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003785# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003786 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003787 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003788# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003789 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790 set_option_default(i, opt_flags, p_cp);
3791
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003793 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003795#ifdef FEAT_CINDENT
3796 parse_cino(curbuf);
3797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798}
3799
3800/*
3801 * Set the Vi-default value of a string option.
3802 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003803 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003804 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003805 static void
3806set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807{
3808 char_u *p;
3809 int opt_idx;
3810
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003811 if (escape && vim_strchr(val, ' ') != NULL)
3812 p = vim_strsave_escaped(val, (char_u *)" ");
3813 else
3814 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 if (p != NULL) /* we don't want a NULL */
3816 {
3817 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003818 if (opt_idx >= 0)
3819 {
3820 if (options[opt_idx].flags & P_DEF_ALLOCED)
3821 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3822 options[opt_idx].def_val[VI_DEFAULT] = p;
3823 options[opt_idx].flags |= P_DEF_ALLOCED;
3824 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 }
3826}
3827
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003828 void
3829set_string_default(char *name, char_u *val)
3830{
3831 set_string_default_esc(name, val, FALSE);
3832}
3833
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834/*
3835 * Set the Vi-default value of a number option.
3836 * Used for 'lines' and 'columns'.
3837 */
3838 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003839set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003840{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003841 int opt_idx;
3842
3843 opt_idx = findoption((char_u *)name);
3844 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003845 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846}
3847
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003848#if defined(EXITFREE) || defined(PROTO)
3849/*
3850 * Free all options.
3851 */
3852 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003853free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003854{
3855 int i;
3856
3857 for (i = 0; !istermoption(&options[i]); i++)
3858 {
3859 if (options[i].indir == PV_NONE)
3860 {
3861 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003862 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003863 free_string_option(*(char_u **)options[i].var);
3864 if (options[i].flags & P_DEF_ALLOCED)
3865 free_string_option(options[i].def_val[VI_DEFAULT]);
3866 }
3867 else if (options[i].var != VAR_WIN
3868 && (options[i].flags & P_STRING))
3869 /* buffer-local option: free global value */
3870 free_string_option(*(char_u **)options[i].var);
3871 }
3872}
3873#endif
3874
3875
Bram Moolenaar071d4272004-06-13 20:20:40 +00003876/*
3877 * Initialize the options, part two: After getting Rows and Columns and
3878 * setting 'term'.
3879 */
3880 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003881set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003883 int idx;
3884
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003886 * 'scroll' defaults to half the window height. The stored default is zero,
3887 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003888 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003889 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003890 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003891 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892 comp_col();
3893
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003894 /*
3895 * 'window' is only for backwards compatibility with Vi.
3896 * Default is Rows - 1.
3897 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003898 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003899 p_window = Rows - 1;
3900 set_number_default("window", Rows - 1);
3901
Bram Moolenaarf740b292006-02-16 22:11:02 +00003902 /* For DOS console the default is always black. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003903#if !((defined(WIN3264)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003904 /*
3905 * If 'background' wasn't set by the user, try guessing the value,
3906 * depending on the terminal name. Only need to check for terminals
3907 * with a dark background, that can handle color.
3908 */
3909 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003910 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3911 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003912 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003913 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003914 /* don't mark it as set, when starting the GUI it may be
3915 * changed again */
3916 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003917 }
3918#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003919
3920#ifdef CURSOR_SHAPE
3921 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3922#endif
3923#ifdef FEAT_MOUSESHAPE
3924 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3925#endif
3926#ifdef FEAT_PRINTER
3927 (void)parse_printoptions(); /* parse 'printoptions' default value */
3928#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929}
3930
3931/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003932 * Return "dark" or "light" depending on the kind of terminal.
3933 * This is just guessing! Recognized are:
3934 * "linux" Linux console
3935 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003936 * "cygwin.*" Cygwin shell
3937 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003938 * We also check the COLORFGBG environment variable, which is set by
3939 * rxvt and derivatives. This variable contains either two or three
3940 * values separated by semicolons; we want the last value in either
3941 * case. If this value is 0-6 or 8, our background is dark.
3942 */
3943 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003944term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003945{
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003946#if defined(WIN3264)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003947 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003948 return (char_u *)"dark";
3949#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003950 char_u *p;
3951
Bram Moolenaarf740b292006-02-16 22:11:02 +00003952 if (STRCMP(T_NAME, "linux") == 0
3953 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003954 || STRNCMP(T_NAME, "cygwin", 6) == 0
3955 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003956 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3957 && (p = vim_strrchr(p, ';')) != NULL
3958 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3959 && p[2] == NUL))
3960 return (char_u *)"dark";
3961 return (char_u *)"light";
3962#endif
3963}
3964
3965/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 * Initialize the options, part three: After reading the .vimrc
3967 */
3968 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003969set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970{
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003971#if defined(UNIX) || defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972/*
3973 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
3974 * This is done after other initializations, where 'shell' might have been
3975 * set, but only if they have not been set before.
3976 */
3977 char_u *p;
3978 int idx_srr;
3979 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003980# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003981 int idx_sp;
3982 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003983# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984
3985 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003986 if (idx_srr < 0)
3987 do_srr = FALSE;
3988 else
3989 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003990# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003992 if (idx_sp < 0)
3993 do_sp = FALSE;
3994 else
3995 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003996# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02003997 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003998 if (p != NULL)
3999 {
4000 /*
4001 * Default for p_sp is "| tee", for p_srr is ">".
4002 * For known shells it is changed here to include stderr.
4003 */
4004 if ( fnamecmp(p, "csh") == 0
4005 || fnamecmp(p, "tcsh") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004006# if defined(WIN3264) /* also check with .exe extension */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007 || fnamecmp(p, "csh.exe") == 0
4008 || fnamecmp(p, "tcsh.exe") == 0
4009# endif
4010 )
4011 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004012# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004013 if (do_sp)
4014 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004015# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004016 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004017# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004019# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4021 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004022# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023 if (do_srr)
4024 {
4025 p_srr = (char_u *)">&";
4026 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4027 }
4028 }
4029 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004030 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004031 if ( fnamecmp(p, "sh") == 0
4032 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004033 || fnamecmp(p, "mksh") == 0
4034 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004036 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004038 || fnamecmp(p, "fish") == 0
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004039# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 || fnamecmp(p, "cmd") == 0
4041 || fnamecmp(p, "sh.exe") == 0
4042 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004043 || fnamecmp(p, "mksh.exe") == 0
4044 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004045 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004046 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004047 || fnamecmp(p, "bash.exe") == 0
4048 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004049# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004050 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004052# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 if (do_sp)
4054 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004055# ifdef WIN3264
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004057# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004059# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4061 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004062# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 if (do_srr)
4064 {
4065 p_srr = (char_u *)">%s 2>&1";
4066 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4067 }
4068 }
4069 vim_free(p);
4070 }
4071#endif
4072
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004073#if defined(WIN3264)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004075 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4076 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 * This is done after other initializations, where 'shell' might have been
4078 * set, but only if they have not been set before. Default for p_shcf is
4079 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004080 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004082 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 {
4084 int idx3;
4085
4086 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004087 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 {
4089 p_shcf = (char_u *)"-c";
4090 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4091 }
4092
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 /* Somehow Win32 requires the quotes around the redirection too */
4094 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004095 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 {
4097 p_sxq = (char_u *)"\"";
4098 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4099 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004101 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4102 {
4103 int idx3;
4104
4105 /*
4106 * cmd.exe on Windows will strip the first and last double quote given
4107 * on the command line, e.g. most of the time things like:
4108 * cmd /c "my path/to/echo" "my args to echo"
4109 * become:
4110 * my path/to/echo" "my args to echo
4111 * when executed.
4112 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004113 * To avoid this, set shellxquote to surround the command in
4114 * parenthesis. This appears to make most commands work, without
4115 * breaking commands that worked previously, such as
4116 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004117 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004118 idx3 = findoption((char_u *)"sxq");
4119 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4120 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004121 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004122 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4123 }
4124
Bram Moolenaara64ba222012-02-12 23:23:31 +01004125 idx3 = findoption((char_u *)"shcf");
4126 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4127 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004128 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004129 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4130 }
4131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132#endif
4133
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004134 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004135 {
4136 int idx_ffs = findoption((char_u *)"ffs");
4137
4138 /* Apply the first entry of 'fileformats' to the initial buffer. */
4139 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4140 set_fileformat(default_fileformat(), OPT_LOCAL);
4141 }
4142
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143#ifdef FEAT_TITLE
4144 set_title_defaults();
4145#endif
4146}
4147
4148#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4149/*
4150 * When 'helplang' is still at its default value, set it to "lang".
4151 * Only the first two characters of "lang" are used.
4152 */
4153 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004154set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155{
4156 int idx;
4157
4158 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4159 return;
4160 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004161 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162 {
4163 if (options[idx].flags & P_ALLOCED)
4164 free_string_option(p_hlg);
4165 p_hlg = vim_strsave(lang);
4166 if (p_hlg == NULL)
4167 p_hlg = empty_option;
4168 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004169 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004170 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004171 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4172 {
4173 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4174 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4175 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004176 // any C like setting, such as C.UTF-8, becomes "en"
4177 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4178 {
4179 p_hlg[0] = 'e';
4180 p_hlg[1] = 'n';
4181 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004183 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004184 options[idx].flags |= P_ALLOCED;
4185 }
4186}
4187#endif
4188
4189#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004190 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004191gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192{
4193 if (gui_get_lightness(gui.back_pixel) < 127)
4194 return (char_u *)"dark";
4195 return (char_u *)"light";
4196}
4197
4198/*
4199 * Option initializations that can only be done after opening the GUI window.
4200 */
4201 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004202init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004203{
4204 /* Set the 'background' option according to the lightness of the
4205 * background color, unless the user has set it already. */
4206 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4207 {
4208 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4209 highlight_changed();
4210 }
4211}
4212#endif
4213
4214#ifdef FEAT_TITLE
4215/*
4216 * 'title' and 'icon' only default to true if they have not been set or reset
4217 * in .vimrc and we can read the old value.
4218 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4219 * they can be reset. This reduces startup time when using X on a remote
4220 * machine.
4221 */
4222 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004223set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004224{
4225 int idx1;
4226 long val;
4227
4228 /*
4229 * If GUI is (going to be) used, we can always set the window title and
4230 * icon name. Saves a bit of time, because the X11 display server does
4231 * not need to be contacted.
4232 */
4233 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004234 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235 {
4236#ifdef FEAT_GUI
4237 if (gui.starting || gui.in_use)
4238 val = TRUE;
4239 else
4240#endif
4241 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004242 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004243 p_title = val;
4244 }
4245 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004246 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004247 {
4248#ifdef FEAT_GUI
4249 if (gui.starting || gui.in_use)
4250 val = TRUE;
4251 else
4252#endif
4253 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004254 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004255 p_icon = val;
4256 }
4257}
4258#endif
4259
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004260#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004261 static void
4262trigger_optionsset_string(
4263 int opt_idx,
4264 int opt_flags,
4265 char_u *oldval,
4266 char_u *newval)
4267{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004268 // Don't do this recursively.
4269 if (oldval != NULL && newval != NULL
4270 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004271 {
4272 char_u buf_type[7];
4273
4274 sprintf((char *)buf_type, "%s",
4275 (opt_flags & OPT_LOCAL) ? "local" : "global");
4276 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4277 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4278 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4279 apply_autocmds(EVENT_OPTIONSET,
4280 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4281 reset_v_option_vars();
4282 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004283}
4284#endif
4285
Bram Moolenaar071d4272004-06-13 20:20:40 +00004286/*
4287 * Parse 'arg' for option settings.
4288 *
4289 * 'arg' may be IObuff, but only when no errors can be present and option
4290 * does not need to be expanded with option_expand().
4291 * "opt_flags":
4292 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004293 * OPT_GLOBAL for ":setglobal"
4294 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004295 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004296 * OPT_WINONLY to only set window-local options
4297 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004298 *
4299 * returns FAIL if an error is detected, OK otherwise
4300 */
4301 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004302do_set(
4303 char_u *arg, /* option string (may be written to!) */
4304 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004305{
4306 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004307 char *errmsg;
4308 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309 char_u *startarg;
4310 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4311 int nextchar; /* next non-white char after option name */
4312 int afterchar; /* character just after option name */
4313 int len;
4314 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004315 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004316 int key;
4317 long_u flags; /* flags for current option */
4318 char_u *varp = NULL; /* pointer to variable for current option */
4319 int did_show = FALSE; /* already showed one value */
4320 int adding; /* "opt+=arg" */
4321 int prepending; /* "opt^=arg" */
4322 int removing; /* "opt-=arg" */
4323 int cp_val = 0;
4324 char_u key_name[2];
4325
4326 if (*arg == NUL)
4327 {
4328 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004329 did_show = TRUE;
4330 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004331 }
4332
4333 while (*arg != NUL) /* loop to process all options */
4334 {
4335 errmsg = NULL;
4336 startarg = arg; /* remember for error message */
4337
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004338 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4339 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004340 {
4341 /*
4342 * ":set all" show all options.
4343 * ":set all&" set all options to their default value.
4344 */
4345 arg += 3;
4346 if (*arg == '&')
4347 {
4348 ++arg;
4349 /* Only for :set command set global value of local options. */
4350 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004351 didset_options();
4352 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004353 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004354 }
4355 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004356 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004357 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004358 did_show = TRUE;
4359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004360 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004361 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004362 {
4363 showoptions(2, opt_flags);
4364 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004365 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004366 arg += 7;
4367 }
4368 else
4369 {
4370 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004371 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004372 {
4373 prefix = 0;
4374 arg += 2;
4375 }
4376 else if (STRNCMP(arg, "inv", 3) == 0)
4377 {
4378 prefix = 2;
4379 arg += 3;
4380 }
4381
4382 /* find end of name */
4383 key = 0;
4384 if (*arg == '<')
4385 {
4386 nextchar = 0;
4387 opt_idx = -1;
4388 /* look out for <t_>;> */
4389 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4390 len = 5;
4391 else
4392 {
4393 len = 1;
4394 while (arg[len] != NUL && arg[len] != '>')
4395 ++len;
4396 }
4397 if (arg[len] != '>')
4398 {
4399 errmsg = e_invarg;
4400 goto skip;
4401 }
4402 arg[len] = NUL; /* put NUL after name */
4403 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4404 opt_idx = findoption(arg + 1);
4405 arg[len++] = '>'; /* restore '>' */
4406 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004407 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 }
4409 else
4410 {
4411 len = 0;
4412 /*
4413 * The two characters after "t_" may not be alphanumeric.
4414 */
4415 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4416 len = 4;
4417 else
4418 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4419 ++len;
4420 nextchar = arg[len];
4421 arg[len] = NUL; /* put NUL after name */
4422 opt_idx = findoption(arg);
4423 arg[len] = nextchar; /* restore nextchar */
4424 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004425 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004426 }
4427
4428 /* remember character after option name */
4429 afterchar = arg[len];
4430
4431 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004432 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004433 ++len;
4434
4435 adding = FALSE;
4436 prepending = FALSE;
4437 removing = FALSE;
4438 if (arg[len] != NUL && arg[len + 1] == '=')
4439 {
4440 if (arg[len] == '+')
4441 {
4442 adding = TRUE; /* "+=" */
4443 ++len;
4444 }
4445 else if (arg[len] == '^')
4446 {
4447 prepending = TRUE; /* "^=" */
4448 ++len;
4449 }
4450 else if (arg[len] == '-')
4451 {
4452 removing = TRUE; /* "-=" */
4453 ++len;
4454 }
4455 }
4456 nextchar = arg[len];
4457
4458 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4459 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004460 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004461 goto skip;
4462 }
4463
4464 if (opt_idx >= 0)
4465 {
4466 if (options[opt_idx].var == NULL) /* hidden option: skip */
4467 {
4468 /* Only give an error message when requesting the value of
4469 * a hidden option, ignore setting it. */
4470 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4471 && (!(options[opt_idx].flags & P_BOOL)
4472 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004473 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004474 goto skip;
4475 }
4476
4477 flags = options[opt_idx].flags;
4478 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4479 }
4480 else
4481 {
4482 flags = P_STRING;
4483 if (key < 0)
4484 {
4485 key_name[0] = KEY2TERMCAP0(key);
4486 key_name[1] = KEY2TERMCAP1(key);
4487 }
4488 else
4489 {
4490 key_name[0] = KS_KEY;
4491 key_name[1] = (key & 0xff);
4492 }
4493 }
4494
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004495 /* Skip all options that are not window-local (used when showing
4496 * an already loaded buffer in a window). */
4497 if ((opt_flags & OPT_WINONLY)
4498 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4499 goto skip;
4500
Bram Moolenaara3227e22006-03-08 21:32:40 +00004501 /* Skip all options that are window-local (used for :vimgrep). */
4502 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4503 && options[opt_idx].var == VAR_WIN)
4504 goto skip;
4505
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004506 /* Disallow changing some options from modelines. */
4507 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004508 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004509 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004510 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004511 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004512 goto skip;
4513 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004514#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004515 /* In diff mode some options are overruled. This avoids that
4516 * 'foldmethod' becomes "marker" instead of "diff" and that
4517 * "wrap" gets set. */
4518 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004519 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004520 && (
4521#ifdef FEAT_FOLDING
4522 options[opt_idx].indir == PV_FDM ||
4523#endif
4524 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004525 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004526#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004527 }
4528
4529#ifdef HAVE_SANDBOX
4530 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004531 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004532 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004533 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004534 goto skip;
4535 }
4536#endif
4537
4538 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4539 {
4540 arg += len;
4541 cp_val = p_cp;
4542 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4543 {
4544 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4545 {
4546 cp_val = FALSE;
4547 arg += 3;
4548 }
4549 else /* "opt&vi": set to Vi default */
4550 {
4551 cp_val = TRUE;
4552 arg += 2;
4553 }
4554 }
4555 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004556 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004557 {
4558 errmsg = e_trailing;
4559 goto skip;
4560 }
4561 }
4562
4563 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004564 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4565 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004566 */
4567 if (nextchar == '?'
4568 || (prefix == 1
4569 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4570 && !(flags & P_BOOL)))
4571 {
4572 /*
4573 * print value
4574 */
4575 if (did_show)
4576 msg_putchar('\n'); /* cursor below last one */
4577 else
4578 {
4579 gotocmdline(TRUE); /* cursor at status line */
4580 did_show = TRUE; /* remember that we did a line */
4581 }
4582 if (opt_idx >= 0)
4583 {
4584 showoneopt(&options[opt_idx], opt_flags);
4585#ifdef FEAT_EVAL
4586 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004587 {
4588 /* Mention where the option was last set. */
4589 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004590 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004591 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004592 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004593 (int)options[opt_idx].indir & PV_MASK]);
4594 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004595 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004596 (int)options[opt_idx].indir & PV_MASK]);
4597 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004598#endif
4599 }
4600 else
4601 {
4602 char_u *p;
4603
4604 p = find_termcode(key_name);
4605 if (p == NULL)
4606 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004607 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004608 goto skip;
4609 }
4610 else
4611 (void)show_one_termcode(key_name, p, TRUE);
4612 }
4613 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004614 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 errmsg = e_trailing;
4616 }
4617 else
4618 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004619 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004620 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004621
Bram Moolenaar071d4272004-06-13 20:20:40 +00004622 if (flags & P_BOOL) /* boolean */
4623 {
4624 if (nextchar == '=' || nextchar == ':')
4625 {
4626 errmsg = e_invarg;
4627 goto skip;
4628 }
4629
4630 /*
4631 * ":set opt!": invert
4632 * ":set opt&": reset to default value
4633 * ":set opt<": reset to global value
4634 */
4635 if (nextchar == '!')
4636 value = *(int *)(varp) ^ 1;
4637 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004638 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004639 ((flags & P_VI_DEF) || cp_val)
4640 ? VI_DEFAULT : VIM_DEFAULT];
4641 else if (nextchar == '<')
4642 {
4643 /* For 'autoread' -1 means to use global value. */
4644 if ((int *)varp == &curbuf->b_p_ar
4645 && opt_flags == OPT_LOCAL)
4646 value = -1;
4647 else
4648 value = *(int *)get_varp_scope(&(options[opt_idx]),
4649 OPT_GLOBAL);
4650 }
4651 else
4652 {
4653 /*
4654 * ":set invopt": invert
4655 * ":set opt" or ":set noopt": set or reset
4656 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004657 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004658 {
4659 errmsg = e_trailing;
4660 goto skip;
4661 }
4662 if (prefix == 2) /* inv */
4663 value = *(int *)(varp) ^ 1;
4664 else
4665 value = prefix;
4666 }
4667
4668 errmsg = set_bool_option(opt_idx, varp, (int)value,
4669 opt_flags);
4670 }
4671 else /* numeric or string */
4672 {
4673 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4674 || prefix != 1)
4675 {
4676 errmsg = e_invarg;
4677 goto skip;
4678 }
4679
4680 if (flags & P_NUM) /* numeric */
4681 {
4682 /*
4683 * Different ways to set a number option:
4684 * & set to default value
4685 * < set to global value
4686 * <xx> accept special key codes for 'wildchar'
4687 * c accept any non-digit for 'wildchar'
4688 * [-]0-9 set number
4689 * other error
4690 */
4691 ++arg;
4692 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004693 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004694 ((flags & P_VI_DEF) || cp_val)
4695 ? VI_DEFAULT : VIM_DEFAULT];
4696 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004697 {
4698 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4699 * use the global value. */
4700 if ((long *)varp == &curbuf->b_p_ul
4701 && opt_flags == OPT_LOCAL)
4702 value = NO_LOCAL_UNDOLEVEL;
4703 else
4704 value = *(long *)get_varp_scope(
4705 &(options[opt_idx]), OPT_GLOBAL);
4706 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004707 else if (((long *)varp == &p_wc
4708 || (long *)varp == &p_wcm)
4709 && (*arg == '<'
4710 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004711 || (*arg != NUL
4712 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004713 && !VIM_ISDIGIT(*arg))))
4714 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004715 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004716 if (value == 0 && (long *)varp != &p_wcm)
4717 {
4718 errmsg = e_invarg;
4719 goto skip;
4720 }
4721 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004722 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4723 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004724 /* Allow negative (for 'undolevels'), octal and
4725 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004726 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4727 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004728 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004729 {
4730 errmsg = e_invarg;
4731 goto skip;
4732 }
4733 }
4734 else
4735 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004736 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004737 goto skip;
4738 }
4739
4740 if (adding)
4741 value = *(long *)varp + value;
4742 if (prepending)
4743 value = *(long *)varp * value;
4744 if (removing)
4745 value = *(long *)varp - value;
4746 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004747 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004748 }
4749 else if (opt_idx >= 0) /* string */
4750 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004751 char_u *save_arg = NULL;
4752 char_u *s = NULL;
4753 char_u *oldval = NULL; /* previous value if *varp */
4754 char_u *newval;
4755 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004756#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004757 char_u *saved_origval = NULL;
4758 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004759#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004760 unsigned newlen;
4761 int comma;
4762 int bs;
4763 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004764 was allocated */
4765
4766 /* When using ":set opt=val" for a global option
4767 * with a local value the local value will be
4768 * reset, use the global value here. */
4769 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004770 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004771 varp = options[opt_idx].var;
4772
4773 /* The old value is kept until we are sure that the
4774 * new value is valid. */
4775 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004776
4777 /* When setting the local value of a global
4778 * option, the old value may be the global value. */
4779 if (((int)options[opt_idx].indir & PV_BOTH)
4780 && (opt_flags & OPT_LOCAL))
4781 origval = *(char_u **)get_varp(
4782 &options[opt_idx]);
4783 else
4784 origval = oldval;
4785
Bram Moolenaar071d4272004-06-13 20:20:40 +00004786 if (nextchar == '&') /* set to default val */
4787 {
4788 newval = options[opt_idx].def_val[
4789 ((flags & P_VI_DEF) || cp_val)
4790 ? VI_DEFAULT : VIM_DEFAULT];
4791 if ((char_u **)varp == &p_bg)
4792 {
4793 /* guess the value of 'background' */
4794#ifdef FEAT_GUI
4795 if (gui.in_use)
4796 newval = gui_bg_default();
4797 else
4798#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004799 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004800 }
4801
4802 /* expand environment variables and ~ (since the
4803 * default value was already expanded, only
4804 * required when an environment variable was set
4805 * later */
4806 if (newval == NULL)
4807 newval = empty_option;
4808 else
4809 {
4810 s = option_expand(opt_idx, newval);
4811 if (s == NULL)
4812 s = newval;
4813 newval = vim_strsave(s);
4814 }
4815 new_value_alloced = TRUE;
4816 }
4817 else if (nextchar == '<') /* set to global val */
4818 {
4819 newval = vim_strsave(*(char_u **)get_varp_scope(
4820 &(options[opt_idx]), OPT_GLOBAL));
4821 new_value_alloced = TRUE;
4822 }
4823 else
4824 {
4825 ++arg; /* jump to after the '=' or ':' */
4826
4827 /*
4828 * Set 'keywordprg' to ":help" if an empty
4829 * value was passed to :set by the user.
4830 * Misuse errbuf[] for the resulting string.
4831 */
4832 if (varp == (char_u *)&p_kp
4833 && (*arg == NUL || *arg == ' '))
4834 {
4835 STRCPY(errbuf, ":help");
4836 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004837 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004838 }
4839 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004840 * Convert 'backspace' number to string, for
4841 * adding, prepending and removing string.
4842 */
4843 else if (varp == (char_u *)&p_bs
4844 && VIM_ISDIGIT(**(char_u **)varp))
4845 {
4846 i = getdigits((char_u **)varp);
4847 switch (i)
4848 {
4849 case 0:
4850 *(char_u **)varp = empty_option;
4851 break;
4852 case 1:
4853 *(char_u **)varp = vim_strsave(
4854 (char_u *)"indent,eol");
4855 break;
4856 case 2:
4857 *(char_u **)varp = vim_strsave(
4858 (char_u *)"indent,eol,start");
4859 break;
4860 }
4861 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004862 if (origval == oldval)
4863 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004864 oldval = *(char_u **)varp;
4865 }
4866 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004867 * Convert 'whichwrap' number to string, for
4868 * backwards compatibility with Vim 3.0.
4869 * Misuse errbuf[] for the resulting string.
4870 */
4871 else if (varp == (char_u *)&p_ww
4872 && VIM_ISDIGIT(*arg))
4873 {
4874 *errbuf = NUL;
4875 i = getdigits(&arg);
4876 if (i & 1)
4877 STRCAT(errbuf, "b,");
4878 if (i & 2)
4879 STRCAT(errbuf, "s,");
4880 if (i & 4)
4881 STRCAT(errbuf, "h,l,");
4882 if (i & 8)
4883 STRCAT(errbuf, "<,>,");
4884 if (i & 16)
4885 STRCAT(errbuf, "[,],");
4886 if (*errbuf != NUL) /* remove trailing , */
4887 errbuf[STRLEN(errbuf) - 1] = NUL;
4888 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004889 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004890 }
4891 /*
4892 * Remove '>' before 'dir' and 'bdir', for
4893 * backwards compatibility with version 3.0
4894 */
4895 else if ( *arg == '>'
4896 && (varp == (char_u *)&p_dir
4897 || varp == (char_u *)&p_bdir))
4898 {
4899 ++arg;
4900 }
4901
Bram Moolenaar071d4272004-06-13 20:20:40 +00004902 /*
4903 * Copy the new string into allocated memory.
4904 * Can't use set_string_option_direct(), because
4905 * we need to remove the backslashes.
4906 */
4907 /* get a bit too much */
4908 newlen = (unsigned)STRLEN(arg) + 1;
4909 if (adding || prepending || removing)
4910 newlen += (unsigned)STRLEN(origval) + 1;
4911 newval = alloc(newlen);
4912 if (newval == NULL) /* out of mem, don't change */
4913 break;
4914 s = newval;
4915
4916 /*
4917 * Copy the string, skip over escaped chars.
4918 * For MS-DOS and WIN32 backslashes before normal
4919 * file name characters are not removed, and keep
4920 * backslash at start, for "\\machine\path", but
4921 * do remove it for "\\\\machine\\path".
4922 * The reverse is found in ExpandOldSetting().
4923 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004924 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004925 {
4926 if (*arg == '\\' && arg[1] != NUL
4927#ifdef BACKSLASH_IN_FILENAME
4928 && !((flags & P_EXPAND)
4929 && vim_isfilec(arg[1])
4930 && (arg[1] != '\\'
4931 || (s == newval
4932 && arg[2] != '\\')))
4933#endif
4934 )
4935 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004936 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004937 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004938 {
4939 /* copy multibyte char */
4940 mch_memmove(s, arg, (size_t)i);
4941 arg += i;
4942 s += i;
4943 }
4944 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004945 *s++ = *arg++;
4946 }
4947 *s = NUL;
4948
4949 /*
4950 * Expand environment variables and ~.
4951 * Don't do it when adding without inserting a
4952 * comma.
4953 */
4954 if (!(adding || prepending || removing)
4955 || (flags & P_COMMA))
4956 {
4957 s = option_expand(opt_idx, newval);
4958 if (s != NULL)
4959 {
4960 vim_free(newval);
4961 newlen = (unsigned)STRLEN(s) + 1;
4962 if (adding || prepending || removing)
4963 newlen += (unsigned)STRLEN(origval) + 1;
4964 newval = alloc(newlen);
4965 if (newval == NULL)
4966 break;
4967 STRCPY(newval, s);
4968 }
4969 }
4970
4971 /* locate newval[] in origval[] when removing it
4972 * and when adding to avoid duplicates */
4973 i = 0; /* init for GCC */
4974 if (removing || (flags & P_NODUP))
4975 {
4976 i = (int)STRLEN(newval);
4977 bs = 0;
4978 for (s = origval; *s; ++s)
4979 {
4980 if ((!(flags & P_COMMA)
4981 || s == origval
4982 || (s[-1] == ',' && !(bs & 1)))
4983 && STRNCMP(s, newval, i) == 0
4984 && (!(flags & P_COMMA)
4985 || s[i] == ','
4986 || s[i] == NUL))
4987 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01004988 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01004989 * even number of backslashes or a single
4990 * backslash preceded by a comma before it
4991 * is recognized as a separator */
4992 if ((s > origval + 1
4993 && s[-1] == '\\'
4994 && s[-2] != ',')
4995 || (s == origval + 1
4996 && s[-1] == '\\'))
4997
Bram Moolenaar071d4272004-06-13 20:20:40 +00004998 ++bs;
4999 else
5000 bs = 0;
5001 }
5002
5003 /* do not add if already there */
5004 if ((adding || prepending) && *s)
5005 {
5006 prepending = FALSE;
5007 adding = FALSE;
5008 STRCPY(newval, origval);
5009 }
5010 }
5011
5012 /* concatenate the two strings; add a ',' if
5013 * needed */
5014 if (adding || prepending)
5015 {
5016 comma = ((flags & P_COMMA) && *origval != NUL
5017 && *newval != NUL);
5018 if (adding)
5019 {
5020 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005021 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005022 if (comma && i > 1
5023 && (flags & P_ONECOMMA) == P_ONECOMMA
5024 && origval[i - 1] == ','
5025 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005026 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005027 mch_memmove(newval + i + comma, newval,
5028 STRLEN(newval) + 1);
5029 mch_memmove(newval, origval, (size_t)i);
5030 }
5031 else
5032 {
5033 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005034 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005035 }
5036 if (comma)
5037 newval[i] = ',';
5038 }
5039
5040 /* Remove newval[] from origval[]. (Note: "i" has
5041 * been set above and is used here). */
5042 if (removing)
5043 {
5044 STRCPY(newval, origval);
5045 if (*s)
5046 {
5047 /* may need to remove a comma */
5048 if (flags & P_COMMA)
5049 {
5050 if (s == origval)
5051 {
5052 /* include comma after string */
5053 if (s[i] == ',')
5054 ++i;
5055 }
5056 else
5057 {
5058 /* include comma before string */
5059 --s;
5060 ++i;
5061 }
5062 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005063 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005064 }
5065 }
5066
5067 if (flags & P_FLAGLIST)
5068 {
5069 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005070 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005071 {
5072 /* if options have P_FLAGLIST and
5073 * P_ONECOMMA such as 'whichwrap' */
5074 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005075 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005076 if (*s != ',' && *(s + 1) == ','
5077 && vim_strchr(s + 2, *s) != NULL)
5078 {
5079 /* Remove the duplicated value and
5080 * the next comma. */
5081 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005082 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005083 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005084 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005085 else
5086 {
5087 if ((!(flags & P_COMMA) || *s != ',')
5088 && vim_strchr(s + 1, *s) != NULL)
5089 {
5090 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005091 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005092 }
5093 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005094 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005095 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005096 }
5097
5098 if (save_arg != NULL) /* number for 'whichwrap' */
5099 arg = save_arg;
5100 new_value_alloced = TRUE;
5101 }
5102
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005103 /*
5104 * Set the new value.
5105 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005106 *(char_u **)(varp) = newval;
5107
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005108#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005109 if (!starting
5110# ifdef FEAT_CRYPT
5111 && options[opt_idx].indir != PV_KEY
5112# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005113 && origval != NULL && newval != NULL)
5114 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005115 /* origval may be freed by
5116 * did_set_string_option(), make a copy. */
5117 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005118 /* newval (and varp) may become invalid if the
5119 * buffer is closed by autocommands. */
5120 saved_newval = vim_strsave(newval);
5121 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005122#endif
5123
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005124 {
5125 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005126 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005127
5128 // When an option is set in the sandbox, from a
5129 // modeline or in secure mode, then deal with side
5130 // effects in secure mode. Also when the value was
5131 // set with the P_INSECURE flag and is not
5132 // completely replaced.
5133 if (secure
5134#ifdef HAVE_SANDBOX
5135 || sandbox != 0
5136#endif
5137 || (opt_flags & OPT_MODELINE)
5138 || (!value_is_replaced && (*p & P_INSECURE)))
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005139 ++secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005140
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005141 // Handle side effects, and set the global value
5142 // for ":set" on local options. Note: when setting
5143 // 'syntax' or 'filetype' autocommands may be
5144 // triggered that can cause havoc.
5145 errmsg = did_set_string_option(
5146 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005147 new_value_alloced, oldval, errbuf,
5148 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005149
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005150 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005151 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005152
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005153#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005154 if (errmsg == NULL)
5155 trigger_optionsset_string(opt_idx, opt_flags,
5156 saved_origval, saved_newval);
5157 vim_free(saved_origval);
5158 vim_free(saved_newval);
5159#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005160 /* If error detected, print the error message. */
5161 if (errmsg != NULL)
5162 goto skip;
5163 }
5164 else /* key code option */
5165 {
5166 char_u *p;
5167
5168 if (nextchar == '&')
5169 {
5170 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005171 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005172 }
5173 else
5174 {
5175 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005176 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005177 if (*p == '\\' && p[1] != NUL)
5178 ++p;
5179 nextchar = *p;
5180 *p = NUL;
5181 add_termcode(key_name, arg, FALSE);
5182 *p = nextchar;
5183 }
5184 if (full_screen)
5185 ttest(FALSE);
5186 redraw_all_later(CLEAR);
5187 }
5188 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005189
Bram Moolenaar071d4272004-06-13 20:20:40 +00005190 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005191 did_set_option(
5192 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005193 }
5194
5195skip:
5196 /*
5197 * Advance to next argument.
5198 * - skip until a blank found, taking care of backslashes
5199 * - skip blanks
5200 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5201 */
5202 for (i = 0; i < 2 ; ++i)
5203 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005204 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005205 if (*arg++ == '\\' && *arg != NUL)
5206 ++arg;
5207 arg = skipwhite(arg);
5208 if (*arg != '=')
5209 break;
5210 }
5211 }
5212
5213 if (errmsg != NULL)
5214 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005215 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005216 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005217 if (i + (arg - startarg) < IOSIZE)
5218 {
5219 /* append the argument with the error */
5220 STRCAT(IObuff, ": ");
5221 mch_memmove(IObuff + i, startarg, (arg - startarg));
5222 IObuff[i + (arg - startarg)] = NUL;
5223 }
5224 /* make sure all characters are printable */
5225 trans_characters(IObuff, IOSIZE);
5226
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005227 ++no_wait_return; // wait_return done later
5228 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005229 --no_wait_return;
5230
5231 return FAIL;
5232 }
5233
5234 arg = skipwhite(arg);
5235 }
5236
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005237theend:
5238 if (silent_mode && did_show)
5239 {
5240 /* After displaying option values in silent mode. */
5241 silent_mode = FALSE;
5242 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5243 msg_putchar('\n');
5244 cursor_on(); /* msg_start() switches it off */
5245 out_flush();
5246 silent_mode = TRUE;
5247 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5248 }
5249
Bram Moolenaar071d4272004-06-13 20:20:40 +00005250 return OK;
5251}
5252
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005253/*
5254 * Call this when an option has been given a new value through a user command.
5255 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5256 */
5257 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005258did_set_option(
5259 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005260 int opt_flags, // possibly with OPT_MODELINE
5261 int new_value, // value was replaced completely
5262 int value_checked) // value was checked to be safe, no need to set the
5263 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005264{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005265 long_u *p;
5266
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005267 options[opt_idx].flags |= P_WAS_SET;
5268
5269 /* When an option is set in the sandbox, from a modeline or in secure mode
5270 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005271 * flag. */
5272 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005273 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005274#ifdef HAVE_SANDBOX
5275 || sandbox != 0
5276#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005277 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005278 *p = *p | P_INSECURE;
5279 else if (new_value)
5280 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005281}
5282
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005283 static char *
5284illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285{
5286 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005287 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005288 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005289 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005290 return errbuf;
5291}
5292
5293/*
5294 * Convert a key name or string into a key value.
5295 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005296 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005297 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005298 int
5299string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005300{
5301 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005302 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005303 if (*arg == '^')
5304 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005305 if (multi_byte)
5306 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307 return *arg;
5308}
5309
5310#ifdef FEAT_CMDWIN
5311/*
5312 * Check value of 'cedit' and set cedit_key.
5313 * Returns NULL if value is OK, error message otherwise.
5314 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005315 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005316check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317{
5318 int n;
5319
5320 if (*p_cedit == NUL)
5321 cedit_key = -1;
5322 else
5323 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005324 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325 if (vim_isprintc(n))
5326 return e_invarg;
5327 cedit_key = n;
5328 }
5329 return NULL;
5330}
5331#endif
5332
5333#ifdef FEAT_TITLE
5334/*
5335 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5336 * maketitle() to create and display it.
5337 * When switching the title or icon off, call mch_restore_title() to get
5338 * the old value back.
5339 */
5340 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005341did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005342{
5343 if (starting != NO_SCREEN
5344#ifdef FEAT_GUI
5345 && !gui.starting
5346#endif
5347 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349}
5350#endif
5351
5352/*
5353 * set_options_bin - called when 'bin' changes value.
5354 */
5355 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005356set_options_bin(
5357 int oldval,
5358 int newval,
5359 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360{
5361 /*
5362 * The option values that are changed when 'bin' changes are
5363 * copied when 'bin is set and restored when 'bin' is reset.
5364 */
5365 if (newval)
5366 {
5367 if (!oldval) /* switched on */
5368 {
5369 if (!(opt_flags & OPT_GLOBAL))
5370 {
5371 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5372 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5373 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5374 curbuf->b_p_et_nobin = curbuf->b_p_et;
5375 }
5376 if (!(opt_flags & OPT_LOCAL))
5377 {
5378 p_tw_nobin = p_tw;
5379 p_wm_nobin = p_wm;
5380 p_ml_nobin = p_ml;
5381 p_et_nobin = p_et;
5382 }
5383 }
5384
5385 if (!(opt_flags & OPT_GLOBAL))
5386 {
5387 curbuf->b_p_tw = 0; /* no automatic line wrap */
5388 curbuf->b_p_wm = 0; /* no automatic line wrap */
5389 curbuf->b_p_ml = 0; /* no modelines */
5390 curbuf->b_p_et = 0; /* no expandtab */
5391 }
5392 if (!(opt_flags & OPT_LOCAL))
5393 {
5394 p_tw = 0;
5395 p_wm = 0;
5396 p_ml = FALSE;
5397 p_et = FALSE;
5398 p_bin = TRUE; /* needed when called for the "-b" argument */
5399 }
5400 }
5401 else if (oldval) /* switched off */
5402 {
5403 if (!(opt_flags & OPT_GLOBAL))
5404 {
5405 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5406 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5407 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5408 curbuf->b_p_et = curbuf->b_p_et_nobin;
5409 }
5410 if (!(opt_flags & OPT_LOCAL))
5411 {
5412 p_tw = p_tw_nobin;
5413 p_wm = p_wm_nobin;
5414 p_ml = p_ml_nobin;
5415 p_et = p_et_nobin;
5416 }
5417 }
5418}
5419
5420#ifdef FEAT_VIMINFO
5421/*
5422 * Find the parameter represented by the given character (eg ', :, ", or /),
5423 * and return its associated value in the 'viminfo' string.
5424 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005425 * If the parameter is not specified in the string or there is no following
5426 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005427 */
5428 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005429get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005430{
5431 char_u *p;
5432
5433 p = find_viminfo_parameter(type);
5434 if (p != NULL && VIM_ISDIGIT(*p))
5435 return atoi((char *)p);
5436 return -1;
5437}
5438
5439/*
5440 * Find the parameter represented by the given character (eg ''', ':', '"', or
5441 * '/') in the 'viminfo' option and return a pointer to the string after it.
5442 * Return NULL if the parameter is not specified in the string.
5443 */
5444 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005445find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446{
5447 char_u *p;
5448
5449 for (p = p_viminfo; *p; ++p)
5450 {
5451 if (*p == type)
5452 return p + 1;
5453 if (*p == 'n') /* 'n' is always the last one */
5454 break;
5455 p = vim_strchr(p, ','); /* skip until next ',' */
5456 if (p == NULL) /* hit the end without finding parameter */
5457 break;
5458 }
5459 return NULL;
5460}
5461#endif
5462
5463/*
5464 * Expand environment variables for some string options.
5465 * These string options cannot be indirect!
5466 * If "val" is NULL expand the current value of the option.
5467 * Return pointer to NameBuff, or NULL when not expanded.
5468 */
5469 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005470option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005471{
5472 /* if option doesn't need expansion nothing to do */
5473 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5474 return NULL;
5475
5476 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5477 * expand_env() would truncate the string. */
5478 if (val != NULL && STRLEN(val) > MAXPATHL)
5479 return NULL;
5480
5481 if (val == NULL)
5482 val = *(char_u **)options[opt_idx].var;
5483
5484 /*
5485 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5486 * Escape spaces when expanding 'tags', they are used to separate file
5487 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005488 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005489 */
5490 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005491 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005492#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005493 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5494#endif
5495 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5497 return NULL;
5498
5499 return NameBuff;
5500}
5501
5502/*
5503 * After setting various option values: recompute variables that depend on
5504 * option values.
5505 */
5506 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005507didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508{
5509 /* initialize the table for 'iskeyword' et.al. */
5510 (void)init_chartab();
5511
5512 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5513 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005514 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005515#ifdef FEAT_SESSION
5516 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5517 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5518#endif
5519#ifdef FEAT_FOLDING
5520 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5521#endif
5522 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005523 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005524 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005525#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5526 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5527#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005528#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005529 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005530 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005531 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005532 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005534#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
5535 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5536#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005537#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005538 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5539#endif
5540#ifdef FEAT_CMDWIN
5541 /* set cedit_key */
5542 (void)check_cedit();
5543#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005544#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005545 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005546#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005547#ifdef FEAT_LINEBREAK
5548 /* initialize the table for 'breakat'. */
5549 fill_breakat_flags();
5550#endif
5551
5552}
5553
5554/*
5555 * More side effects of setting options.
5556 */
5557 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005558didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005559{
5560 /* Initialize the highlight_attr[] table. */
5561 (void)highlight_changed();
5562
5563 /* Parse default for 'wildmode' */
5564 check_opt_wim();
5565
5566 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005567 /* Parse default for 'fillchars'. */
5568 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005569
5570#ifdef FEAT_CLIPBOARD
5571 /* Parse default for 'clipboard' */
5572 (void)check_clipboard_option();
5573#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005574#ifdef FEAT_VARTABS
5575 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
5576 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5577#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005578}
5579
5580/*
5581 * Check for string options that are NULL (normally only termcap options).
5582 */
5583 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005584check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005585{
5586 int opt_idx;
5587
5588 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5589 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5590 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5591}
5592
5593/*
5594 * Check string options in a buffer for NULL value.
5595 */
5596 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005597check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005599 check_string_option(&buf->b_p_bh);
5600 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005601 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005602 check_string_option(&buf->b_p_ff);
5603#ifdef FEAT_FIND_ID
5604 check_string_option(&buf->b_p_def);
5605 check_string_option(&buf->b_p_inc);
5606# ifdef FEAT_EVAL
5607 check_string_option(&buf->b_p_inex);
5608# endif
5609#endif
5610#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5611 check_string_option(&buf->b_p_inde);
5612 check_string_option(&buf->b_p_indk);
5613#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005614#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5615 check_string_option(&buf->b_p_bexpr);
5616#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005617#if defined(FEAT_CRYPT)
5618 check_string_option(&buf->b_p_cm);
5619#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005620 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005621#if defined(FEAT_EVAL)
5622 check_string_option(&buf->b_p_fex);
5623#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005624#ifdef FEAT_CRYPT
5625 check_string_option(&buf->b_p_key);
5626#endif
5627 check_string_option(&buf->b_p_kp);
5628 check_string_option(&buf->b_p_mps);
5629 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005630 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631 check_string_option(&buf->b_p_isk);
5632#ifdef FEAT_COMMENTS
5633 check_string_option(&buf->b_p_com);
5634#endif
5635#ifdef FEAT_FOLDING
5636 check_string_option(&buf->b_p_cms);
5637#endif
5638 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005639#ifdef FEAT_TEXTOBJ
5640 check_string_option(&buf->b_p_qe);
5641#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005642#ifdef FEAT_SYN_HL
5643 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005644 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005645#endif
5646#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005647 check_string_option(&buf->b_s.b_p_spc);
5648 check_string_option(&buf->b_s.b_p_spf);
5649 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650#endif
5651#ifdef FEAT_SEARCHPATH
5652 check_string_option(&buf->b_p_sua);
5653#endif
5654#ifdef FEAT_CINDENT
5655 check_string_option(&buf->b_p_cink);
5656 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005657 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005658#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005659 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005660#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5661 check_string_option(&buf->b_p_cinw);
5662#endif
5663#ifdef FEAT_INS_EXPAND
5664 check_string_option(&buf->b_p_cpt);
5665#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005666#ifdef FEAT_COMPL_FUNC
5667 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005668 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005669#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670#ifdef FEAT_KEYMAP
5671 check_string_option(&buf->b_p_keymap);
5672#endif
5673#ifdef FEAT_QUICKFIX
5674 check_string_option(&buf->b_p_gp);
5675 check_string_option(&buf->b_p_mp);
5676 check_string_option(&buf->b_p_efm);
5677#endif
5678 check_string_option(&buf->b_p_ep);
5679 check_string_option(&buf->b_p_path);
5680 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005681 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682#ifdef FEAT_INS_EXPAND
5683 check_string_option(&buf->b_p_dict);
5684 check_string_option(&buf->b_p_tsr);
5685#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005686#ifdef FEAT_LISP
5687 check_string_option(&buf->b_p_lw);
5688#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005689 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005690 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005691#ifdef FEAT_VARTABS
5692 check_string_option(&buf->b_p_vsts);
5693 check_string_option(&buf->b_p_vts);
5694#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695}
5696
5697/*
5698 * Free the string allocated for an option.
5699 * Checks for the string being empty_option. This may happen if we're out of
5700 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5701 * check_options().
5702 * Does NOT check for P_ALLOCED flag!
5703 */
5704 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005705free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706{
5707 if (p != empty_option)
5708 vim_free(p);
5709}
5710
5711 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005712clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005713{
5714 if (*pp != empty_option)
5715 vim_free(*pp);
5716 *pp = empty_option;
5717}
5718
5719 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005720check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005721{
5722 if (*pp == NULL)
5723 *pp = empty_option;
5724}
5725
5726/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005727 * Return the option index found by a pointer into term_strings[].
5728 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005729 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005730 int
5731get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005732{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005733 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005734
5735 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5736 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005737 return opt_idx;
5738 return -1; // cannot happen: didn't find it!
5739}
5740
5741/*
5742 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5743 * Return the option index or -1 if not found.
5744 */
5745 int
5746set_term_option_alloced(char_u **p)
5747{
5748 int opt_idx = get_term_opt_idx(p);
5749
5750 if (opt_idx >= 0)
5751 options[opt_idx].flags |= P_ALLOCED;
5752 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753}
5754
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005755#if defined(FEAT_EVAL) || defined(PROTO)
5756/*
5757 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5758 * Return FALSE when it wasn't.
5759 * Return -1 for an unknown option.
5760 */
5761 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005762was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005763{
5764 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005765 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005766
5767 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005768 {
5769 flagp = insecure_flag(idx, opt_flags);
5770 return (*flagp & P_INSECURE) != 0;
5771 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005772 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005773 return -1;
5774}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005775
5776/*
5777 * Get a pointer to the flags used for the P_INSECURE flag of option
5778 * "opt_idx". For some local options a local flags field is used.
5779 */
5780 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005781insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005782{
5783 if (opt_flags & OPT_LOCAL)
5784 switch ((int)options[opt_idx].indir)
5785 {
5786#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005787 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005788#endif
5789#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005790# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005791 case PV_FDE: return &curwin->w_p_fde_flags;
5792 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005793# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005794# ifdef FEAT_BEVAL
5795 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5796# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005797# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005798 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005799# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005800 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005801# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005802 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005803# endif
5804#endif
5805 }
5806
5807 /* Nothing special, return global flags field. */
5808 return &options[opt_idx].flags;
5809}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005810#endif
5811
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005812#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005813/*
5814 * Redraw the window title and/or tab page text later.
5815 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005816static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005817{
5818 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005819 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005820}
5821#endif
5822
Bram Moolenaar071d4272004-06-13 20:20:40 +00005823/*
5824 * Set a string option to a new value (without checking the effect).
5825 * The string is copied into allocated memory.
5826 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005827 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5828 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5829 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005830 */
5831 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005832set_string_option_direct(
5833 char_u *name,
5834 int opt_idx,
5835 char_u *val,
5836 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5837 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005838{
5839 char_u *s;
5840 char_u **varp;
5841 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005842 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005843
Bram Moolenaar89d40322006-08-29 15:30:07 +00005844 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005845 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005846 idx = findoption(name);
5847 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005848 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005849 semsg(_(e_intern2), "set_string_option_direct()");
5850 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005851 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005852 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005853 }
5854
Bram Moolenaar89d40322006-08-29 15:30:07 +00005855 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856 return;
5857
5858 s = vim_strsave(val);
5859 if (s != NULL)
5860 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005861 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005862 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005863 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005864 free_string_option(*varp);
5865 *varp = s;
5866
5867 /* For buffer/window local option may also set the global value. */
5868 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005869 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870
Bram Moolenaar89d40322006-08-29 15:30:07 +00005871 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872
5873 /* When setting both values of a global option with a local value,
5874 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005875 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005876 {
5877 free_string_option(*varp);
5878 *varp = empty_option;
5879 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005880# ifdef FEAT_EVAL
5881 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005882 {
5883 sctx_T script_ctx;
5884
5885 if (set_sid == 0)
5886 script_ctx = current_sctx;
5887 else
5888 {
5889 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005890 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005891 script_ctx.sc_lnum = 0;
5892 }
5893 set_option_sctx_idx(idx, opt_flags, script_ctx);
5894 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005895# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 }
5897}
5898
5899/*
5900 * Set global value for string option when it's a local option.
5901 */
5902 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005903set_string_option_global(
5904 int opt_idx, /* option index */
5905 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906{
5907 char_u **p, *s;
5908
5909 /* the global value is always allocated */
5910 if (options[opt_idx].var == VAR_WIN)
5911 p = (char_u **)GLOBAL_WO(varp);
5912 else
5913 p = (char_u **)options[opt_idx].var;
5914 if (options[opt_idx].indir != PV_NONE
5915 && p != varp
5916 && (s = vim_strsave(*varp)) != NULL)
5917 {
5918 free_string_option(*p);
5919 *p = s;
5920 }
5921}
5922
5923/*
5924 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005925 *
5926 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005928 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005929set_string_option(
5930 int opt_idx,
5931 char_u *value,
5932 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005933{
5934 char_u *s;
5935 char_u **varp;
5936 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005937#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005938 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005939 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005940#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005941 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005942 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005943
5944 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005945 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946
5947 s = vim_strsave(value);
5948 if (s != NULL)
5949 {
5950 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5951 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005952 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005953 ? OPT_GLOBAL : OPT_LOCAL)
5954 : opt_flags);
5955 oldval = *varp;
5956 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005957
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005958#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005959 if (!starting
5960# ifdef FEAT_CRYPT
5961 && options[opt_idx].indir != PV_KEY
5962# endif
5963 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005964 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005965 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005966 saved_newval = vim_strsave(s);
5967 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005968#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005969 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005970 opt_flags, &value_checked)) == NULL)
5971 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02005972
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005973#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005974 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005975 if (r == NULL)
5976 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005977 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005978 vim_free(saved_oldval);
5979 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02005980#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005981 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005982 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005983}
5984
5985/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01005986 * Return TRUE if "val" is a valid 'filetype' name.
5987 * Also used for 'syntax' and 'keymap'.
5988 */
5989 static int
5990valid_filetype(char_u *val)
5991{
5992 char_u *s;
5993
5994 for (s = val; *s != NUL; ++s)
5995 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)".-_", *s) == NULL)
5996 return FALSE;
5997 return TRUE;
5998}
5999
6000/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006001 * Handle string options that need some action to perform when changed.
6002 * Returns NULL for success, or an error message for an error.
6003 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006004 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006005did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006006 int opt_idx, // index in options[] table
6007 char_u **varp, // pointer to the option variable
6008 int new_value_alloced, // new value was allocated
6009 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006010 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006011 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6012 int *value_checked) // value was checked to be save, no
6013 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006015 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006016 char_u *s, *p;
6017 int did_chartab = FALSE;
6018 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006019 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006020#ifdef FEAT_GUI
6021 /* set when changing an option that only requires a redraw in the GUI */
6022 int redraw_gui_only = FALSE;
6023#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006024 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006025#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6026 int did_swaptcap = FALSE;
6027#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006028
6029 /* Get the global option to compare with, otherwise we would have to check
6030 * two values for all local options. */
6031 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6032
6033 /* Disallow changing some options from secure mode */
6034 if ((secure
6035#ifdef HAVE_SANDBOX
6036 || sandbox != 0
6037#endif
6038 ) && (options[opt_idx].flags & P_SECURE))
6039 {
6040 errmsg = e_secure;
6041 }
6042
Bram Moolenaar916a8182018-11-25 02:18:29 +01006043 // Check for a "normal" directory or file name in some options. Disallow a
6044 // path separator (slash and/or backslash), wildcards and characters that
6045 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006046 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006047 && vim_strpbrk(*varp, (char_u *)(secure
6048 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006049 || ((options[opt_idx].flags & P_NDNAME)
6050 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006051 {
6052 errmsg = e_invarg;
6053 }
6054
Bram Moolenaar071d4272004-06-13 20:20:40 +00006055 /* 'term' */
6056 else if (varp == &T_NAME)
6057 {
6058 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006059 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006060#ifdef FEAT_GUI
6061 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006062 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006063 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006064 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006065#endif
6066 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006067 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006068 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006069 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006070 /* Screen colors may have changed. */
6071 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006072
6073 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6074 * P_ALLOCED flag on 'term'. */
6075 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006076 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006077 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006078 }
6079
6080 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006081 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006082 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006083 char_u *bkc = p_bkc;
6084 unsigned int *flags = &bkc_flags;
6085
6086 if (opt_flags & OPT_LOCAL)
6087 {
6088 bkc = curbuf->b_p_bkc;
6089 flags = &curbuf->b_bkc_flags;
6090 }
6091
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006092 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6093 /* make the local value empty: use the global value */
6094 *flags = 0;
6095 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006096 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006097 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6098 errmsg = e_invarg;
6099 if ((((int)*flags & BKC_AUTO) != 0)
6100 + (((int)*flags & BKC_YES) != 0)
6101 + (((int)*flags & BKC_NO) != 0) != 1)
6102 {
6103 /* Must have exactly one of "auto", "yes" and "no". */
6104 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6105 errmsg = e_invarg;
6106 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107 }
6108 }
6109
6110 /* 'backupext' and 'patchmode' */
6111 else if (varp == &p_bex || varp == &p_pm)
6112 {
6113 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6114 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006115 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006117#ifdef FEAT_LINEBREAK
6118 /* 'breakindentopt' */
6119 else if (varp == &curwin->w_p_briopt)
6120 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006121 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006122 errmsg = e_invarg;
6123 }
6124#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006125
6126 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006127 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006128 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006129 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006130 */
6131 else if ( varp == &p_isi
6132 || varp == &(curbuf->b_p_isk)
6133 || varp == &p_isp
6134 || varp == &p_isf)
6135 {
6136 if (init_chartab() == FAIL)
6137 {
6138 did_chartab = TRUE; /* need to restore it below */
6139 errmsg = e_invarg; /* error in value */
6140 }
6141 }
6142
6143 /* 'helpfile' */
6144 else if (varp == &p_hf)
6145 {
6146 /* May compute new values for $VIM and $VIMRUNTIME */
6147 if (didset_vim)
6148 {
6149 vim_setenv((char_u *)"VIM", (char_u *)"");
6150 didset_vim = FALSE;
6151 }
6152 if (didset_vimruntime)
6153 {
6154 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6155 didset_vimruntime = FALSE;
6156 }
6157 }
6158
Bram Moolenaar1a384422010-07-14 19:53:30 +02006159#ifdef FEAT_SYN_HL
6160 /* 'colorcolumn' */
6161 else if (varp == &curwin->w_p_cc)
6162 errmsg = check_colorcolumn(curwin);
6163#endif
6164
Bram Moolenaar071d4272004-06-13 20:20:40 +00006165#ifdef FEAT_MULTI_LANG
6166 /* 'helplang' */
6167 else if (varp == &p_hlg)
6168 {
6169 /* Check for "", "ab", "ab,cd", etc. */
6170 for (s = p_hlg; *s != NUL; s += 3)
6171 {
6172 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6173 {
6174 errmsg = e_invarg;
6175 break;
6176 }
6177 if (s[2] == NUL)
6178 break;
6179 }
6180 }
6181#endif
6182
6183 /* 'highlight' */
6184 else if (varp == &p_hl)
6185 {
6186 if (highlight_changed() == FAIL)
6187 errmsg = e_invarg; /* invalid flags */
6188 }
6189
6190 /* 'nrformats' */
6191 else if (gvarp == &p_nf)
6192 {
6193 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6194 errmsg = e_invarg;
6195 }
6196
6197#ifdef FEAT_SESSION
6198 /* 'sessionoptions' */
6199 else if (varp == &p_ssop)
6200 {
6201 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6202 errmsg = e_invarg;
6203 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6204 {
6205 /* Don't allow both "sesdir" and "curdir". */
6206 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6207 errmsg = e_invarg;
6208 }
6209 }
6210 /* 'viewoptions' */
6211 else if (varp == &p_vop)
6212 {
6213 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6214 errmsg = e_invarg;
6215 }
6216#endif
6217
6218 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006219 else if (varp == &p_sbo)
6220 {
6221 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6222 errmsg = e_invarg;
6223 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006224
6225 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006226 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006227 {
6228 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6229 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006230 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006231 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006232 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006233 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006234 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006235
6236 /* 'background' */
6237 else if (varp == &p_bg)
6238 {
6239 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6240 {
6241#ifdef FEAT_EVAL
6242 int dark = (*p_bg == 'd');
6243#endif
6244
6245 init_highlight(FALSE, FALSE);
6246
6247#ifdef FEAT_EVAL
6248 if (dark != (*p_bg == 'd')
6249 && get_var_value((char_u *)"g:colors_name") != NULL)
6250 {
6251 /* The color scheme must have set 'background' back to another
6252 * value, that's not what we want here. Disable the color
6253 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006254 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006255 free_string_option(p_bg);
6256 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6257 check_string_option(&p_bg);
6258 init_highlight(FALSE, FALSE);
6259 }
6260#endif
6261 }
6262 else
6263 errmsg = e_invarg;
6264 }
6265
6266 /* 'wildmode' */
6267 else if (varp == &p_wim)
6268 {
6269 if (check_opt_wim() == FAIL)
6270 errmsg = e_invarg;
6271 }
6272
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006273#ifdef FEAT_CMDL_COMPL
6274 /* 'wildoptions' */
6275 else if (varp == &p_wop)
6276 {
6277 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6278 errmsg = e_invarg;
6279 }
6280#endif
6281
Bram Moolenaar071d4272004-06-13 20:20:40 +00006282#ifdef FEAT_WAK
6283 /* 'winaltkeys' */
6284 else if (varp == &p_wak)
6285 {
6286 if (*p_wak == NUL
6287 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6288 errmsg = e_invarg;
6289# ifdef FEAT_MENU
6290# ifdef FEAT_GUI_MOTIF
6291 else if (gui.in_use)
6292 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6293# else
6294# ifdef FEAT_GUI_GTK
6295 else if (gui.in_use)
6296 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6297# endif
6298# endif
6299# endif
6300 }
6301#endif
6302
Bram Moolenaar071d4272004-06-13 20:20:40 +00006303 /* 'eventignore' */
6304 else if (varp == &p_ei)
6305 {
6306 if (check_ei() == FAIL)
6307 errmsg = e_invarg;
6308 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006309
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006310 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6311 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6312 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006313 {
6314 if (gvarp == &p_fenc)
6315 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006316 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006317 errmsg = e_modifiable;
6318 else if (vim_strchr(*varp, ',') != NULL)
6319 /* No comma allowed in 'fileencoding'; catches confusing it
6320 * with 'fileencodings'. */
6321 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006322 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006323 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006324#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006325 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006326 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006327#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006328 /* Add 'fileencoding' to the swap file. */
6329 ml_setflags(curbuf);
6330 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331 }
6332 if (errmsg == NULL)
6333 {
6334 /* canonize the value, so that STRCMP() can be used on it */
6335 p = enc_canonize(*varp);
6336 if (p != NULL)
6337 {
6338 vim_free(*varp);
6339 *varp = p;
6340 }
6341 if (varp == &p_enc)
6342 {
6343 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006344#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006345 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006347 }
6348 }
6349
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006350#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006351 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6352 {
6353 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6354 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006355 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006356 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006358
6359 if (errmsg == NULL)
6360 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006361#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006362 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6363 * (with another encoding). */
6364 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6365 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006366#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006367
6368 /* When 'termencoding' is not empty and 'encoding' changes or when
6369 * 'termencoding' changes, need to setup for keyboard input and
6370 * display output conversion. */
6371 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6372 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006373 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6374 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6375 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006376 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006377 p_tenc, p_enc);
6378 errmsg = e_invarg;
6379 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006380 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006381
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006382#if defined(WIN3264)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006383 /* $HOME may have characters in active code page. */
6384 if (varp == &p_enc)
6385 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006387 }
6388 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006389
6390#if defined(FEAT_POSTSCRIPT)
6391 else if (varp == &p_penc)
6392 {
6393 /* Canonize printencoding if VIM standard one */
6394 p = enc_canonize(p_penc);
6395 if (p != NULL)
6396 {
6397 vim_free(p_penc);
6398 p_penc = p;
6399 }
6400 else
6401 {
6402 /* Ensure lower case and '-' for '_' */
6403 for (s = p_penc; *s != NUL; s++)
6404 {
6405 if (*s == '_')
6406 *s = '-';
6407 else
6408 *s = TOLOWER_ASC(*s);
6409 }
6410 }
6411 }
6412#endif
6413
Bram Moolenaar9372a112005-12-06 19:59:18 +00006414#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006415 else if (varp == &p_imak)
6416 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006417 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006418 errmsg = e_invarg;
6419 }
6420#endif
6421
6422#ifdef FEAT_KEYMAP
6423 else if (varp == &curbuf->b_p_keymap)
6424 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006425 if (!valid_filetype(*varp))
6426 errmsg = e_invarg;
6427 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006428 {
6429 int secure_save = secure;
6430
6431 // Reset the secure flag, since the value of 'keymap' has
6432 // been checked to be safe.
6433 secure = 0;
6434
6435 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006436 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006437
Bram Moolenaar916a8182018-11-25 02:18:29 +01006438 secure = secure_save;
6439
6440 // Since we check the value, there is no need to set P_INSECURE,
6441 // even when the value comes from a modeline.
6442 *value_checked = TRUE;
6443 }
6444
Bram Moolenaarfab06232009-03-04 03:13:35 +00006445 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006446 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006447 if (*curbuf->b_p_keymap != NUL)
6448 {
6449 /* Installed a new keymap, switch on using it. */
6450 curbuf->b_p_iminsert = B_IMODE_LMAP;
6451 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6452 curbuf->b_p_imsearch = B_IMODE_LMAP;
6453 }
6454 else
6455 {
6456 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6457 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6458 curbuf->b_p_iminsert = B_IMODE_NONE;
6459 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6460 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6461 }
6462 if ((opt_flags & OPT_LOCAL) == 0)
6463 {
6464 set_iminsert_global();
6465 set_imsearch_global();
6466 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006467 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006468 }
6469 }
6470#endif
6471
6472 /* 'fileformat' */
6473 else if (gvarp == &p_ff)
6474 {
6475 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6476 errmsg = e_modifiable;
6477 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6478 errmsg = e_invarg;
6479 else
6480 {
6481 /* may also change 'textmode' */
6482 if (get_fileformat(curbuf) == EOL_DOS)
6483 curbuf->b_p_tx = TRUE;
6484 else
6485 curbuf->b_p_tx = FALSE;
6486#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006487 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006488#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006489 /* update flag in swap file */
6490 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006491 /* Redraw needed when switching to/from "mac": a CR in the text
6492 * will be displayed differently. */
6493 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6494 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006495 }
6496 }
6497
6498 /* 'fileformats' */
6499 else if (varp == &p_ffs)
6500 {
6501 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6502 errmsg = e_invarg;
6503 else
6504 {
6505 /* also change 'textauto' */
6506 if (*p_ffs == NUL)
6507 p_ta = FALSE;
6508 else
6509 p_ta = TRUE;
6510 }
6511 }
6512
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006513#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006514 /* 'cryptkey' */
6515 else if (gvarp == &p_key)
6516 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006517# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 /* Make sure the ":set" command doesn't show the new value in the
6519 * history. */
6520 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006521# endif
6522 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6523 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006524 ml_set_crypt_key(curbuf, oldval,
6525 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006526 }
6527
6528 else if (gvarp == &p_cm)
6529 {
6530 if (opt_flags & OPT_LOCAL)
6531 p = curbuf->b_p_cm;
6532 else
6533 p = p_cm;
6534 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6535 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006536 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006537 errmsg = e_invarg;
6538 else
6539 {
6540 /* When setting the global value to empty, make it "zip". */
6541 if (*p_cm == NUL)
6542 {
6543 if (new_value_alloced)
6544 free_string_option(p_cm);
6545 p_cm = vim_strsave((char_u *)"zip");
6546 new_value_alloced = TRUE;
6547 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006548 /* When using ":set cm=name" the local value is going to be empty.
6549 * Do that here, otherwise the crypt functions will still use the
6550 * local value. */
6551 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6552 {
6553 free_string_option(curbuf->b_p_cm);
6554 curbuf->b_p_cm = empty_option;
6555 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006556
6557 /* Need to update the swapfile when the effective method changed.
6558 * Set "s" to the effective old value, "p" to the effective new
6559 * method and compare. */
6560 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6561 s = p_cm; /* was previously using the global value */
6562 else
6563 s = oldval;
6564 if (*curbuf->b_p_cm == NUL)
6565 p = p_cm; /* is now using the global value */
6566 else
6567 p = curbuf->b_p_cm;
6568 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006569 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006570
6571 /* If the global value changes need to update the swapfile for all
6572 * buffers using that value. */
6573 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6574 {
6575 buf_T *buf;
6576
Bram Moolenaar29323592016-07-24 22:04:11 +02006577 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006578 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006579 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006580 }
6581 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 }
6583#endif
6584
6585 /* 'matchpairs' */
6586 else if (gvarp == &p_mps)
6587 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006588 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006589 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006590 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006591 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006592 int x2 = -1;
6593 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006594
6595 if (*p != NUL)
6596 p += mb_ptr2len(p);
6597 if (*p != NUL)
6598 x2 = *p++;
6599 if (*p != NUL)
6600 {
6601 x3 = mb_ptr2char(p);
6602 p += mb_ptr2len(p);
6603 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006604 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006605 {
6606 errmsg = e_invarg;
6607 break;
6608 }
6609 if (*p == NUL)
6610 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006611 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006612 }
6613 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006614 {
6615 /* Check for "x:y,x:y" */
6616 for (p = *varp; *p != NUL; p += 4)
6617 {
6618 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6619 {
6620 errmsg = e_invarg;
6621 break;
6622 }
6623 if (p[3] == NUL)
6624 break;
6625 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006626 }
6627 }
6628
6629#ifdef FEAT_COMMENTS
6630 /* 'comments' */
6631 else if (gvarp == &p_com)
6632 {
6633 for (s = *varp; *s; )
6634 {
6635 while (*s && *s != ':')
6636 {
6637 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6638 && !VIM_ISDIGIT(*s) && *s != '-')
6639 {
6640 errmsg = illegal_char(errbuf, *s);
6641 break;
6642 }
6643 ++s;
6644 }
6645 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006646 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006647 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006648 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006649 if (errmsg != NULL)
6650 break;
6651 while (*s && *s != ',')
6652 {
6653 if (*s == '\\' && s[1] != NUL)
6654 ++s;
6655 ++s;
6656 }
6657 s = skip_to_option_part(s);
6658 }
6659 }
6660#endif
6661
6662 /* 'listchars' */
6663 else if (varp == &p_lcs)
6664 {
6665 errmsg = set_chars_option(varp);
6666 }
6667
Bram Moolenaar071d4272004-06-13 20:20:40 +00006668 /* 'fillchars' */
6669 else if (varp == &p_fcs)
6670 {
6671 errmsg = set_chars_option(varp);
6672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006673
6674#ifdef FEAT_CMDWIN
6675 /* 'cedit' */
6676 else if (varp == &p_cedit)
6677 {
6678 errmsg = check_cedit();
6679 }
6680#endif
6681
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006682 /* 'verbosefile' */
6683 else if (varp == &p_vfile)
6684 {
6685 verbose_stop();
6686 if (*p_vfile != NUL && verbose_open() == FAIL)
6687 errmsg = e_invarg;
6688 }
6689
Bram Moolenaar071d4272004-06-13 20:20:40 +00006690#ifdef FEAT_VIMINFO
6691 /* 'viminfo' */
6692 else if (varp == &p_viminfo)
6693 {
6694 for (s = p_viminfo; *s;)
6695 {
6696 /* Check it's a valid character */
6697 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6698 {
6699 errmsg = illegal_char(errbuf, *s);
6700 break;
6701 }
6702 if (*s == 'n') /* name is always last one */
6703 {
6704 break;
6705 }
6706 else if (*s == 'r') /* skip until next ',' */
6707 {
6708 while (*++s && *s != ',')
6709 ;
6710 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006711 else if (*s == '%')
6712 {
6713 /* optional number */
6714 while (vim_isdigit(*++s))
6715 ;
6716 }
6717 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006718 ++s; /* no extra chars */
6719 else /* must have a number */
6720 {
6721 while (vim_isdigit(*++s))
6722 ;
6723
6724 if (!VIM_ISDIGIT(*(s - 1)))
6725 {
6726 if (errbuf != NULL)
6727 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006728 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006729 transchar_byte(*(s - 1)));
6730 errmsg = errbuf;
6731 }
6732 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006733 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006734 break;
6735 }
6736 }
6737 if (*s == ',')
6738 ++s;
6739 else if (*s)
6740 {
6741 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006742 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006743 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006744 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745 break;
6746 }
6747 }
6748 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006749 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006750 }
6751#endif /* FEAT_VIMINFO */
6752
6753 /* terminal options */
6754 else if (istermoption(&options[opt_idx]) && full_screen)
6755 {
6756 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6757 if (varp == &T_CCO)
6758 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006759 int colors = atoi((char *)T_CCO);
6760
6761 /* Only reinitialize colors if t_Co value has really changed to
6762 * avoid expensive reload of colorscheme if t_Co is set to the
6763 * same value multiple times. */
6764 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006765 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006766 t_colors = colors;
6767 if (t_colors <= 1)
6768 {
6769 if (new_value_alloced)
6770 vim_free(T_CCO);
6771 T_CCO = empty_option;
6772 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006773#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6774 if (is_term_win32())
6775 {
6776 swap_tcap();
6777 did_swaptcap = TRUE;
6778 }
6779#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006780 /* We now have a different color setup, initialize it again. */
6781 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006782 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006783 }
6784 ttest(FALSE);
6785 if (varp == &T_ME)
6786 {
6787 out_str(T_ME);
6788 redraw_later(CLEAR);
Bram Moolenaar48e330a2016-02-23 14:53:34 +01006789#if defined(WIN3264) && !defined(FEAT_GUI_W32)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 /* Since t_me has been set, this probably means that the user
6791 * wants to use this as default colors. Need to reset default
6792 * background/foreground colors. */
6793 mch_set_normal_colors();
6794#endif
6795 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006796 if (varp == &T_BE && termcap_active)
6797 {
6798 if (*T_BE == NUL)
6799 /* When clearing t_BE we assume the user no longer wants
6800 * bracketed paste, thus disable it by writing t_BD. */
6801 out_str(T_BD);
6802 else
6803 out_str(T_BE);
6804 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006805 }
6806
6807#ifdef FEAT_LINEBREAK
6808 /* 'showbreak' */
6809 else if (varp == &p_sbr)
6810 {
6811 for (s = p_sbr; *s; )
6812 {
6813 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006814 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006815 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006816 }
6817 }
6818#endif
6819
6820#ifdef FEAT_GUI
6821 /* 'guifont' */
6822 else if (varp == &p_guifont)
6823 {
6824 if (gui.in_use)
6825 {
6826 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006827# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006828 /*
6829 * Put up a font dialog and let the user select a new value.
6830 * If this is cancelled go back to the old value but don't
6831 * give an error message.
6832 */
6833 if (STRCMP(p, "*") == 0)
6834 {
6835 p = gui_mch_font_dialog(oldval);
6836
6837 if (new_value_alloced)
6838 free_string_option(p_guifont);
6839
6840 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6841 new_value_alloced = TRUE;
6842 }
6843# endif
6844 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6845 {
6846# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6847 if (STRCMP(p_guifont, "*") == 0)
6848 {
6849 /* Dialog was cancelled: Keep the old value without giving
6850 * an error message. */
6851 if (new_value_alloced)
6852 free_string_option(p_guifont);
6853 p_guifont = vim_strsave(oldval);
6854 new_value_alloced = TRUE;
6855 }
6856 else
6857# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006858 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006859 }
6860 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006861 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006862 }
6863# ifdef FEAT_XFONTSET
6864 else if (varp == &p_guifontset)
6865 {
6866 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006867 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006868 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006869 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006870 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871 }
6872# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873 else if (varp == &p_guifontwide)
6874 {
6875 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006876 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006877 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006878 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006879 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006881#endif
6882
6883#ifdef CURSOR_SHAPE
6884 /* 'guicursor' */
6885 else if (varp == &p_guicursor)
6886 errmsg = parse_shape_opt(SHAPE_CURSOR);
6887#endif
6888
6889#ifdef FEAT_MOUSESHAPE
6890 /* 'mouseshape' */
6891 else if (varp == &p_mouseshape)
6892 {
6893 errmsg = parse_shape_opt(SHAPE_MOUSE);
6894 update_mouseshape(-1);
6895 }
6896#endif
6897
6898#ifdef FEAT_PRINTER
6899 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006900 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006901# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006902 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006903 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006904# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006905#endif
6906
6907#ifdef FEAT_LANGMAP
6908 /* 'langmap' */
6909 else if (varp == &p_langmap)
6910 langmap_set();
6911#endif
6912
6913#ifdef FEAT_LINEBREAK
6914 /* 'breakat' */
6915 else if (varp == &p_breakat)
6916 fill_breakat_flags();
6917#endif
6918
6919#ifdef FEAT_TITLE
6920 /* 'titlestring' and 'iconstring' */
6921 else if (varp == &p_titlestring || varp == &p_iconstring)
6922 {
6923# ifdef FEAT_STL_OPT
6924 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6925
6926 /* NULL => statusline syntax */
6927 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6928 stl_syntax |= flagval;
6929 else
6930 stl_syntax &= ~flagval;
6931# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02006932 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006933 }
6934#endif
6935
6936#ifdef FEAT_GUI
6937 /* 'guioptions' */
6938 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006939 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006940 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006941 redraw_gui_only = TRUE;
6942 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943#endif
6944
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006945#if defined(FEAT_GUI_TABLINE)
6946 /* 'guitablabel' */
6947 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006948 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00006949 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006950 redraw_gui_only = TRUE;
6951 }
6952 /* 'guitabtooltip' */
6953 else if (varp == &p_gtt)
6954 {
6955 redraw_gui_only = TRUE;
6956 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00006957#endif
6958
Bram Moolenaar071d4272004-06-13 20:20:40 +00006959#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
6960 /* 'ttymouse' */
6961 else if (varp == &p_ttym)
6962 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00006963 /* Switch the mouse off before changing the escape sequences used for
6964 * that. */
6965 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
6967 errmsg = e_invarg;
6968 else
6969 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00006970 if (termcap_active)
6971 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972 }
6973#endif
6974
Bram Moolenaar071d4272004-06-13 20:20:40 +00006975 /* 'selection' */
6976 else if (varp == &p_sel)
6977 {
6978 if (*p_sel == NUL
6979 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
6980 errmsg = e_invarg;
6981 }
6982
6983 /* 'selectmode' */
6984 else if (varp == &p_slm)
6985 {
6986 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
6987 errmsg = e_invarg;
6988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006989
6990#ifdef FEAT_BROWSE
6991 /* 'browsedir' */
6992 else if (varp == &p_bsdir)
6993 {
6994 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
6995 && !mch_isdir(p_bsdir))
6996 errmsg = e_invarg;
6997 }
6998#endif
6999
Bram Moolenaar071d4272004-06-13 20:20:40 +00007000 /* 'keymodel' */
7001 else if (varp == &p_km)
7002 {
7003 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7004 errmsg = e_invarg;
7005 else
7006 {
7007 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7008 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7009 }
7010 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007011
7012 /* 'mousemodel' */
7013 else if (varp == &p_mousem)
7014 {
7015 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7016 errmsg = e_invarg;
7017#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7018 else if (*p_mousem != *oldval)
7019 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7020 * to create or delete the popup menus. */
7021 gui_motif_update_mousemodel(root_menu);
7022#endif
7023 }
7024
7025 /* 'switchbuf' */
7026 else if (varp == &p_swb)
7027 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007028 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029 errmsg = e_invarg;
7030 }
7031
7032 /* 'debug' */
7033 else if (varp == &p_debug)
7034 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007035 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036 errmsg = e_invarg;
7037 }
7038
7039 /* 'display' */
7040 else if (varp == &p_dy)
7041 {
7042 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7043 errmsg = e_invarg;
7044 else
7045 (void)init_chartab();
7046
7047 }
7048
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049 /* 'eadirection' */
7050 else if (varp == &p_ead)
7051 {
7052 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7053 errmsg = e_invarg;
7054 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007055
7056#ifdef FEAT_CLIPBOARD
7057 /* 'clipboard' */
7058 else if (varp == &p_cb)
7059 errmsg = check_clipboard_option();
7060#endif
7061
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007062#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007063 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7064 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007065 else if (varp == &(curwin->w_s->b_p_spl)
7066 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007067 {
Bram Moolenaare68c25c2015-08-25 15:39:55 +02007068 errmsg = did_set_spell_option(varp == &(curwin->w_s->b_p_spf));
Bram Moolenaar217ad922005-03-20 22:37:15 +00007069 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007070 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007071 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007072 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007073 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007074 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007075 /* 'spellsuggest' */
7076 else if (varp == &p_sps)
7077 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007078 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007079 errmsg = e_invarg;
7080 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007081 /* 'mkspellmem' */
7082 else if (varp == &p_msm)
7083 {
7084 if (spell_check_msm() != OK)
7085 errmsg = e_invarg;
7086 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007087#endif
7088
Bram Moolenaar071d4272004-06-13 20:20:40 +00007089 /* When 'bufhidden' is set, check for valid value. */
7090 else if (gvarp == &p_bh)
7091 {
7092 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7093 errmsg = e_invarg;
7094 }
7095
7096 /* When 'buftype' is set, check for valid value. */
7097 else if (gvarp == &p_bt)
7098 {
7099 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7100 errmsg = e_invarg;
7101 else
7102 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007103 if (curwin->w_status_height)
7104 {
7105 curwin->w_redr_status = TRUE;
7106 redraw_later(VALID);
7107 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007108 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007109#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007110 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007112 }
7113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007114
7115#ifdef FEAT_STL_OPT
7116 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007117 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007118 {
7119 int wid;
7120
7121 if (varp == &p_ruf) /* reset ru_wid first */
7122 ru_wid = 0;
7123 s = *varp;
7124 if (varp == &p_ruf && *s == '%')
7125 {
7126 /* set ru_wid if 'ruf' starts with "%99(" */
7127 if (*++s == '-') /* ignore a '-' */
7128 s++;
7129 wid = getdigits(&s);
7130 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7131 ru_wid = wid;
7132 else
7133 errmsg = check_stl_option(p_ruf);
7134 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007135 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007136 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007137 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007138 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007139 comp_col();
7140 }
7141#endif
7142
7143#ifdef FEAT_INS_EXPAND
7144 /* check if it is a valid value for 'complete' -- Acevedo */
7145 else if (gvarp == &p_cpt)
7146 {
7147 for (s = *varp; *s;)
7148 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007149 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007150 s++;
7151 if (!*s)
7152 break;
7153 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7154 {
7155 errmsg = illegal_char(errbuf, *s);
7156 break;
7157 }
7158 if (*++s != NUL && *s != ',' && *s != ' ')
7159 {
7160 if (s[-1] == 'k' || s[-1] == 's')
7161 {
7162 /* skip optional filename after 'k' and 's' */
7163 while (*s && *s != ',' && *s != ' ')
7164 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007165 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007166 ++s;
7167 ++s;
7168 }
7169 }
7170 else
7171 {
7172 if (errbuf != NULL)
7173 {
7174 sprintf((char *)errbuf,
7175 _("E535: Illegal character after <%c>"),
7176 *--s);
7177 errmsg = errbuf;
7178 }
7179 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007180 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007181 break;
7182 }
7183 }
7184 }
7185 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007186
7187 /* 'completeopt' */
7188 else if (varp == &p_cot)
7189 {
7190 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7191 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007192 else
7193 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007194 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007195#endif /* FEAT_INS_EXPAND */
7196
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007197#ifdef FEAT_SIGNS
7198 /* 'signcolumn' */
7199 else if (varp == &curwin->w_p_scl)
7200 {
7201 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7202 errmsg = e_invarg;
7203 }
7204#endif
7205
Bram Moolenaar071d4272004-06-13 20:20:40 +00007206
7207#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_W32)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007208 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007209 else if (varp == &p_toolbar)
7210 {
7211 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7212 &toolbar_flags, TRUE) != OK)
7213 errmsg = e_invarg;
7214 else
7215 {
7216 out_flush();
7217 gui_mch_show_toolbar((toolbar_flags &
7218 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7219 }
7220 }
7221#endif
7222
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007223#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007224 /* 'toolbariconsize': GTK+ 2 only */
7225 else if (varp == &p_tbis)
7226 {
7227 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7228 errmsg = e_invarg;
7229 else
7230 {
7231 out_flush();
7232 gui_mch_show_toolbar((toolbar_flags &
7233 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7234 }
7235 }
7236#endif
7237
7238 /* 'pastetoggle': translate key codes like in a mapping */
7239 else if (varp == &p_pt)
7240 {
7241 if (*p_pt)
7242 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007243 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007244 if (p != NULL)
7245 {
7246 if (new_value_alloced)
7247 free_string_option(p_pt);
7248 p_pt = p;
7249 new_value_alloced = TRUE;
7250 }
7251 }
7252 }
7253
7254 /* 'backspace' */
7255 else if (varp == &p_bs)
7256 {
7257 if (VIM_ISDIGIT(*p_bs))
7258 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007259 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007260 errmsg = e_invarg;
7261 }
7262 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7263 errmsg = e_invarg;
7264 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007265 else if (varp == &p_bo)
7266 {
7267 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7268 errmsg = e_invarg;
7269 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007270
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007271 /* 'tagcase' */
7272 else if (gvarp == &p_tc)
7273 {
7274 unsigned int *flags;
7275
7276 if (opt_flags & OPT_LOCAL)
7277 {
7278 p = curbuf->b_p_tc;
7279 flags = &curbuf->b_tc_flags;
7280 }
7281 else
7282 {
7283 p = p_tc;
7284 flags = &tc_flags;
7285 }
7286
7287 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7288 /* make the local value empty: use the global value */
7289 *flags = 0;
7290 else if (*p == NUL
7291 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7292 errmsg = e_invarg;
7293 }
7294
Bram Moolenaar071d4272004-06-13 20:20:40 +00007295 /* 'casemap' */
7296 else if (varp == &p_cmp)
7297 {
7298 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7299 errmsg = e_invarg;
7300 }
7301
7302#ifdef FEAT_DIFF
7303 /* 'diffopt' */
7304 else if (varp == &p_dip)
7305 {
7306 if (diffopt_changed() == FAIL)
7307 errmsg = e_invarg;
7308 }
7309#endif
7310
7311#ifdef FEAT_FOLDING
7312 /* 'foldmethod' */
7313 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7314 {
7315 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7316 || *curwin->w_p_fdm == NUL)
7317 errmsg = e_invarg;
7318 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007319 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007321 if (foldmethodIsDiff(curwin))
7322 newFoldLevel();
7323 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007324 }
7325# ifdef FEAT_EVAL
7326 /* 'foldexpr' */
7327 else if (varp == &curwin->w_p_fde)
7328 {
7329 if (foldmethodIsExpr(curwin))
7330 foldUpdateAll(curwin);
7331 }
7332# endif
7333 /* 'foldmarker' */
7334 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7335 {
7336 p = vim_strchr(*varp, ',');
7337 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007338 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007339 else if (p == *varp || p[1] == NUL)
7340 errmsg = e_invarg;
7341 else if (foldmethodIsMarker(curwin))
7342 foldUpdateAll(curwin);
7343 }
7344 /* 'commentstring' */
7345 else if (gvarp == &p_cms)
7346 {
7347 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007348 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007349 }
7350 /* 'foldopen' */
7351 else if (varp == &p_fdo)
7352 {
7353 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7354 errmsg = e_invarg;
7355 }
7356 /* 'foldclose' */
7357 else if (varp == &p_fcl)
7358 {
7359 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7360 errmsg = e_invarg;
7361 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007362 /* 'foldignore' */
7363 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7364 {
7365 if (foldmethodIsIndent(curwin))
7366 foldUpdateAll(curwin);
7367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007368#endif
7369
Bram Moolenaar071d4272004-06-13 20:20:40 +00007370 /* 'virtualedit' */
7371 else if (varp == &p_ve)
7372 {
7373 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7374 errmsg = e_invarg;
7375 else if (STRCMP(p_ve, oldval) != 0)
7376 {
7377 /* Recompute cursor position in case the new 've' setting
7378 * changes something. */
7379 validate_virtcol();
7380 coladvance(curwin->w_virtcol);
7381 }
7382 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007383
7384#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7385 else if (varp == &p_csqf)
7386 {
7387 if (p_csqf != NULL)
7388 {
7389 p = p_csqf;
7390 while (*p != NUL)
7391 {
7392 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7393 || p[1] == NUL
7394 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7395 || (p[2] != NUL && p[2] != ','))
7396 {
7397 errmsg = e_invarg;
7398 break;
7399 }
7400 else if (p[2] == NUL)
7401 break;
7402 else
7403 p += 3;
7404 }
7405 }
7406 }
7407#endif
7408
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007409#ifdef FEAT_CINDENT
7410 /* 'cinoptions' */
7411 else if (gvarp == &p_cino)
7412 {
7413 /* TODO: recognize errors */
7414 parse_cino(curbuf);
7415 }
7416#endif
7417
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007418#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007419 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007420 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007421 {
7422 if (!gui_mch_set_rendering_options(p_rop))
7423 errmsg = e_invarg;
7424 }
7425#endif
7426
Bram Moolenaard0b51382016-11-04 15:23:45 +01007427 else if (gvarp == &p_ft)
7428 {
7429 if (!valid_filetype(*varp))
7430 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007431 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007432 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007433 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007434
7435 // Since we check the value, there is no need to set P_INSECURE,
7436 // even when the value comes from a modeline.
7437 *value_checked = TRUE;
7438 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007439 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007440
7441#ifdef FEAT_SYN_HL
7442 else if (gvarp == &p_syn)
7443 {
7444 if (!valid_filetype(*varp))
7445 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007446 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007447 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007448 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007449
7450 // Since we check the value, there is no need to set P_INSECURE,
7451 // even when the value comes from a modeline.
7452 *value_checked = TRUE;
7453 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007454 }
7455#endif
7456
Bram Moolenaar825680f2017-07-22 17:04:02 +02007457#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007458 /* 'termwinkey' */
7459 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007460 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007461 if (*curwin->w_p_twk != NUL
7462 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007463 errmsg = e_invarg;
7464 }
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007465 /* 'termwinsize' */
7466 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007467 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007468 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007469 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007470 p = skipdigits(curwin->w_p_tws);
7471 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007472 || (*p != 'x' && *p != '*')
7473 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007474 errmsg = e_invarg;
7475 }
7476 }
7477#endif
7478
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007479#ifdef FEAT_VARTABS
7480 /* 'varsofttabstop' */
7481 else if (varp == &(curbuf->b_p_vsts))
7482 {
7483 char_u *cp;
7484
7485 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7486 {
7487 if (curbuf->b_p_vsts_array)
7488 {
7489 vim_free(curbuf->b_p_vsts_array);
7490 curbuf->b_p_vsts_array = 0;
7491 }
7492 }
7493 else
7494 {
7495 for (cp = *varp; *cp; ++cp)
7496 {
7497 if (vim_isdigit(*cp))
7498 continue;
7499 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7500 continue;
7501 errmsg = e_invarg;
7502 break;
7503 }
7504 if (errmsg == NULL)
7505 {
7506 int *oldarray = curbuf->b_p_vsts_array;
7507 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7508 {
7509 if (oldarray)
7510 vim_free(oldarray);
7511 }
7512 else
7513 errmsg = e_invarg;
7514 }
7515 }
7516 }
7517
7518 /* 'vartabstop' */
7519 else if (varp == &(curbuf->b_p_vts))
7520 {
7521 char_u *cp;
7522
7523 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7524 {
7525 if (curbuf->b_p_vts_array)
7526 {
7527 vim_free(curbuf->b_p_vts_array);
7528 curbuf->b_p_vts_array = NULL;
7529 }
7530 }
7531 else
7532 {
7533 for (cp = *varp; *cp; ++cp)
7534 {
7535 if (vim_isdigit(*cp))
7536 continue;
7537 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7538 continue;
7539 errmsg = e_invarg;
7540 break;
7541 }
7542 if (errmsg == NULL)
7543 {
7544 int *oldarray = curbuf->b_p_vts_array;
7545 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7546 {
7547 if (oldarray)
7548 vim_free(oldarray);
7549#ifdef FEAT_FOLDING
7550 if (foldmethodIsIndent(curwin))
7551 foldUpdateAll(curwin);
7552#endif /* FEAT_FOLDING */
7553 }
7554 else
7555 errmsg = e_invarg;
7556 }
7557 }
7558 }
7559#endif
7560
Bram Moolenaar071d4272004-06-13 20:20:40 +00007561 /* Options that are a list of flags. */
7562 else
7563 {
7564 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007565 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007566 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007567 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007568 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007569 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007571 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007572 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007573#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007574 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007575 p = (char_u *)COCU_ALL;
7576#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007577 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007578 {
7579#ifdef FEAT_MOUSE
7580 p = (char_u *)MOUSE_ALL;
7581#else
7582 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007583 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007584#endif
7585 }
7586#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007587 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007588 p = (char_u *)GO_ALL;
7589#endif
7590 if (p != NULL)
7591 {
7592 for (s = *varp; *s; ++s)
7593 if (vim_strchr(p, *s) == NULL)
7594 {
7595 errmsg = illegal_char(errbuf, *s);
7596 break;
7597 }
7598 }
7599 }
7600
7601 /*
7602 * If error detected, restore the previous value.
7603 */
7604 if (errmsg != NULL)
7605 {
7606 if (new_value_alloced)
7607 free_string_option(*varp);
7608 *varp = oldval;
7609 /*
7610 * When resetting some values, need to act on it.
7611 */
7612 if (did_chartab)
7613 (void)init_chartab();
7614 if (varp == &p_hl)
7615 (void)highlight_changed();
7616 }
7617 else
7618 {
7619#ifdef FEAT_EVAL
7620 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007621 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007622#endif
7623 /*
7624 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007625 * Use "free_oldval", because recursiveness may change the flags under
7626 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007627 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007628 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007629 free_string_option(oldval);
7630 if (new_value_alloced)
7631 options[opt_idx].flags |= P_ALLOCED;
7632 else
7633 options[opt_idx].flags &= ~P_ALLOCED;
7634
7635 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007636 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007637 {
7638 /* global option with local value set to use global value; free
7639 * the local value and make it empty */
7640 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7641 free_string_option(*(char_u **)p);
7642 *(char_u **)p = empty_option;
7643 }
7644
7645 /* May set global value for local option. */
7646 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7647 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007648
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007649 /*
7650 * Trigger the autocommand only after setting the flags.
7651 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007652#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007653 /* When 'syntax' is set, load the syntax of that name */
7654 if (varp == &(curbuf->b_p_syn))
7655 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007656 static int syn_recursive = 0;
7657
7658 ++syn_recursive;
7659 // Only pass TRUE for "force" when the value changed or not used
7660 // recursively, to avoid endless recurrence.
7661 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7662 value_changed || syn_recursive == 1, curbuf);
7663 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007664 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007665#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007666 else if (varp == &(curbuf->b_p_ft))
7667 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007668 /* 'filetype' is set, trigger the FileType autocommand.
7669 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007670 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007671 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007672 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007673 static int ft_recursive = 0;
7674 int secure_save = secure;
7675
7676 // Reset the secure flag, since the value of 'filetype' has
7677 // been checked to be safe.
7678 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007679
7680 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007681 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007682 // Only pass TRUE for "force" when the value changed or not
7683 // used recursively, to avoid endless recurrence.
7684 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7685 value_changed || ft_recursive == 1, curbuf);
7686 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007687 /* Just in case the old "curbuf" is now invalid. */
7688 if (varp != &(curbuf->b_p_ft))
7689 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007690
7691 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007692 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007693 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007694#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007695 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007696 {
7697 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007698 char_u *q = curwin->w_s->b_p_spl;
7699
7700 /* Skip the first name if it is "cjk". */
7701 if (STRNCMP(q, "cjk,", 4) == 0)
7702 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007703
7704 /*
7705 * Source the spell/LANG.vim in 'runtimepath'.
7706 * They could set 'spellcapcheck' depending on the language.
7707 * Use the first name in 'spelllang' up to '_region' or
7708 * '.encoding'.
7709 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007710 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007711 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007712 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007713 if (p > q)
7714 {
7715 vim_snprintf((char *)fname, 200, "spell/%.*s.vim", (int)(p - q), q);
7716 source_runtime(fname, DIP_ALL);
7717 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007718 }
7719#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007720 }
7721
7722#ifdef FEAT_MOUSE
7723 if (varp == &p_mouse)
7724 {
7725# ifdef FEAT_MOUSE_TTY
7726 if (*p_mouse == NUL)
7727 mch_setmouse(FALSE); /* switch mouse off */
7728 else
7729# endif
7730 setmouse(); /* in case 'mouse' changed */
7731 }
7732#endif
7733
Bram Moolenaar913077c2012-03-28 19:59:04 +02007734 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007735 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007736 curwin->w_set_curswant = TRUE;
7737
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007738#ifdef FEAT_GUI
7739 /* check redraw when it's not a GUI option or the GUI is active. */
7740 if (!redraw_gui_only || gui.in_use)
7741#endif
7742 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007743
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007744#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7745 if (did_swaptcap)
7746 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007747 set_termname((char_u *)"win32");
7748 init_highlight(TRUE, FALSE);
7749 }
7750#endif
7751
Bram Moolenaar071d4272004-06-13 20:20:40 +00007752 return errmsg;
7753}
7754
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007755#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007756/*
7757 * Simple int comparison function for use with qsort()
7758 */
7759 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007760int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007761{
7762 return *(const int *)a - *(const int *)b;
7763}
7764
7765/*
7766 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7767 * Returns error message, NULL if it's OK.
7768 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007769 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007770check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007771{
7772 char_u *s;
7773 int col;
7774 int count = 0;
7775 int color_cols[256];
7776 int i;
7777 int j = 0;
7778
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007779 if (wp->w_buffer == NULL)
7780 return NULL; /* buffer was closed */
7781
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007782 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007783 {
7784 if (*s == '-' || *s == '+')
7785 {
7786 /* -N and +N: add to 'textwidth' */
7787 col = (*s == '-') ? -1 : 1;
7788 ++s;
7789 if (!VIM_ISDIGIT(*s))
7790 return e_invarg;
7791 col = col * getdigits(&s);
7792 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007793 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007794 col += wp->w_buffer->b_p_tw;
7795 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007796 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007797 }
7798 else if (VIM_ISDIGIT(*s))
7799 col = getdigits(&s);
7800 else
7801 return e_invarg;
7802 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007803skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007804 if (*s == NUL)
7805 break;
7806 if (*s != ',')
7807 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007808 if (*++s == NUL)
7809 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007810 }
7811
7812 vim_free(wp->w_p_cc_cols);
7813 if (count == 0)
7814 wp->w_p_cc_cols = NULL;
7815 else
7816 {
7817 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7818 if (wp->w_p_cc_cols != NULL)
7819 {
7820 /* sort the columns for faster usage on screen redraw inside
7821 * win_line() */
7822 qsort(color_cols, count, sizeof(int), int_cmp);
7823
7824 for (i = 0; i < count; ++i)
7825 /* skip duplicates */
7826 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7827 wp->w_p_cc_cols[j++] = color_cols[i];
7828 wp->w_p_cc_cols[j] = -1; /* end marker */
7829 }
7830 }
7831
7832 return NULL; /* no error */
7833}
7834#endif
7835
Bram Moolenaar071d4272004-06-13 20:20:40 +00007836/*
7837 * Handle setting 'listchars' or 'fillchars'.
7838 * Returns error message, NULL if it's OK.
7839 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007840 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007841set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007842{
7843 int round, i, len, entries;
7844 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007845 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007846 struct charstab
7847 {
7848 int *cp;
7849 char *name;
7850 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007851 static struct charstab filltab[] =
7852 {
7853 {&fill_stl, "stl"},
7854 {&fill_stlnc, "stlnc"},
7855 {&fill_vert, "vert"},
7856 {&fill_fold, "fold"},
7857 {&fill_diff, "diff"},
7858 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859 static struct charstab lcstab[] =
7860 {
7861 {&lcs_eol, "eol"},
7862 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007863 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007864 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007865 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007866 {&lcs_tab2, "tab"},
7867 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007868#ifdef FEAT_CONCEAL
7869 {&lcs_conceal, "conceal"},
7870#else
7871 {NULL, "conceal"},
7872#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873 };
7874 struct charstab *tab;
7875
Bram Moolenaar071d4272004-06-13 20:20:40 +00007876 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007877 {
7878 tab = lcstab;
7879 entries = sizeof(lcstab) / sizeof(struct charstab);
7880 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007881 else
7882 {
7883 tab = filltab;
7884 entries = sizeof(filltab) / sizeof(struct charstab);
7885 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007886
7887 /* first round: check for valid value, second round: assign values */
7888 for (round = 0; round <= 1; ++round)
7889 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007890 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007891 {
7892 /* After checking that the value is valid: set defaults: space for
7893 * 'fillchars', NUL for 'listchars' */
7894 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007895 if (tab[i].cp != NULL)
7896 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007897
Bram Moolenaar071d4272004-06-13 20:20:40 +00007898 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007899 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007900 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007901 lcs_tab3 = NUL;
7902 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007903 else
7904 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007905 }
7906 p = *varp;
7907 while (*p)
7908 {
7909 for (i = 0; i < entries; ++i)
7910 {
7911 len = (int)STRLEN(tab[i].name);
7912 if (STRNCMP(p, tab[i].name, len) == 0
7913 && p[len] == ':'
7914 && p[len + 1] != NUL)
7915 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007916 c1 = c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007917 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007919 if (mb_char2cells(c1) > 1)
7920 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921 if (tab[i].cp == &lcs_tab2)
7922 {
7923 if (*s == NUL)
7924 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007925 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00007926 if (mb_char2cells(c2) > 1)
7927 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007928 if (!(*s == ',' || *s == NUL))
7929 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01007930 c3 = mb_ptr2char_adv(&s);
7931 if (mb_char2cells(c3) > 1)
7932 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007933 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007934 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01007935
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 if (*s == ',' || *s == NUL)
7937 {
7938 if (round)
7939 {
7940 if (tab[i].cp == &lcs_tab2)
7941 {
7942 lcs_tab1 = c1;
7943 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007944 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02007946 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007947 *(tab[i].cp) = c1;
7948
7949 }
7950 p = s;
7951 break;
7952 }
7953 }
7954 }
7955
7956 if (i == entries)
7957 return e_invarg;
7958 if (*p == ',')
7959 ++p;
7960 }
7961 }
7962
7963 return NULL; /* no error */
7964}
7965
7966#ifdef FEAT_STL_OPT
7967/*
7968 * Check validity of options with the 'statusline' format.
7969 * Return error message or NULL.
7970 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007971 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007972check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007973{
7974 int itemcnt = 0;
7975 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007976 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007977
7978 while (*s && itemcnt < STL_MAX_ITEM)
7979 {
7980 /* Check for valid keys after % sequences */
7981 while (*s && *s != '%')
7982 s++;
7983 if (!*s)
7984 break;
7985 s++;
7986 if (*s != '%' && *s != ')')
7987 ++itemcnt;
7988 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7989 {
7990 s++;
7991 continue;
7992 }
7993 if (*s == ')')
7994 {
7995 s++;
7996 if (--groupdepth < 0)
7997 break;
7998 continue;
7999 }
8000 if (*s == '-')
8001 s++;
8002 while (VIM_ISDIGIT(*s))
8003 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008004 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008005 continue;
8006 if (*s == '.')
8007 {
8008 s++;
8009 while (*s && VIM_ISDIGIT(*s))
8010 s++;
8011 }
8012 if (*s == '(')
8013 {
8014 groupdepth++;
8015 continue;
8016 }
8017 if (vim_strchr(STL_ALL, *s) == NULL)
8018 {
8019 return illegal_char(errbuf, *s);
8020 }
8021 if (*s == '{')
8022 {
8023 s++;
8024 while (*s != '}' && *s)
8025 s++;
8026 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008027 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008028 }
8029 }
8030 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008031 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008032 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008033 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008034 return NULL;
8035}
8036#endif
8037
8038#ifdef FEAT_CLIPBOARD
8039/*
8040 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008041 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008042 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008043 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008044check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008046 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008047 int new_autoselect_star = FALSE;
8048 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008049 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008050 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008051 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008052 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008053 char_u *p;
8054
8055 for (p = p_cb; *p != NUL; )
8056 {
8057 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8058 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008059 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008060 p += 7;
8061 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008062 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008063 && (p[11] == ',' || p[11] == NUL))
8064 {
8065 new_unnamed |= CLIP_UNNAMED_PLUS;
8066 p += 11;
8067 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008068 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008069 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008070 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008071 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072 p += 10;
8073 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008074 else if (STRNCMP(p, "autoselectplus", 14) == 0
8075 && (p[14] == ',' || p[14] == NUL))
8076 {
8077 new_autoselect_plus = TRUE;
8078 p += 14;
8079 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008080 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008081 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008082 {
8083 new_autoselectml = TRUE;
8084 p += 12;
8085 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008086 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8087 {
8088 new_html = TRUE;
8089 p += 4;
8090 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8092 {
8093 p += 8;
8094 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8095 if (new_exclude_prog == NULL)
8096 errmsg = e_invarg;
8097 break;
8098 }
8099 else
8100 {
8101 errmsg = e_invarg;
8102 break;
8103 }
8104 if (*p == ',')
8105 ++p;
8106 }
8107 if (errmsg == NULL)
8108 {
8109 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008110 clip_autoselect_star = new_autoselect_star;
8111 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008112 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008113 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008114 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008116#ifdef FEAT_GUI_GTK
8117 if (gui.in_use)
8118 {
8119 gui_gtk_set_selection_targets();
8120 gui_gtk_set_dnd_targets();
8121 }
8122#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123 }
8124 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008125 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126
8127 return errmsg;
8128}
8129#endif
8130
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008131#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008132/*
8133 * Handle side effects of setting 'spell'.
8134 * Return an error message or NULL for success.
8135 */
8136 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008137did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008138{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008139 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008140 win_T *wp;
8141 int l;
8142
8143 if (is_spellfile)
8144 {
8145 l = (int)STRLEN(curwin->w_s->b_p_spf);
8146 if (l > 0 && (l < 4
8147 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8148 errmsg = e_invarg;
8149 }
8150
8151 if (errmsg == NULL)
8152 {
8153 FOR_ALL_WINDOWS(wp)
8154 if (wp->w_buffer == curbuf && wp->w_p_spell)
8155 {
8156 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008157 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008158 }
8159 }
8160 return errmsg;
8161}
8162
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008163/*
8164 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8165 * Return error message when failed, NULL when OK.
8166 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008167 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008168compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008169{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008170 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008171 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008172
Bram Moolenaar860cae12010-06-05 23:22:07 +02008173 if (*synblock->b_p_spc == NUL)
8174 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008175 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008176 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008177 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008178 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008179 if (re != NULL)
8180 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008181 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008182 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008183 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008184 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008185 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008186 return e_invarg;
8187 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008188 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008189 }
8190
Bram Moolenaar473de612013-06-08 18:19:48 +02008191 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008192 return NULL;
8193}
8194#endif
8195
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008196#if defined(FEAT_EVAL) || defined(PROTO)
8197/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008198 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008199 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008200 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008201 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008202set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008203{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008204 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8205 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008206 sctx_T new_script_ctx = script_ctx;
8207
8208 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008209
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008210 /* Remember where the option was set. For local options need to do that
8211 * in the buffer or window structure. */
8212 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008213 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008214 if (both || (opt_flags & OPT_LOCAL))
8215 {
8216 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008217 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008218 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008219 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008220 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008221}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008222
8223/*
8224 * Set the script_ctx for a termcap option.
8225 * "name" must be the two character code, e.g. "RV".
8226 * When "name" is NULL use "opt_idx".
8227 */
8228 void
8229set_term_option_sctx_idx(char *name, int opt_idx)
8230{
8231 char_u buf[5];
8232 int idx;
8233
8234 if (name == NULL)
8235 idx = opt_idx;
8236 else
8237 {
8238 buf[0] = 't';
8239 buf[1] = '_';
8240 buf[2] = name[0];
8241 buf[3] = name[1];
8242 buf[4] = 0;
8243 idx = findoption(buf);
8244 }
8245 if (idx >= 0)
8246 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8247}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008248#endif
8249
Bram Moolenaar071d4272004-06-13 20:20:40 +00008250/*
8251 * Set the value of a boolean option, and take care of side effects.
8252 * Returns NULL for success, or an error message for an error.
8253 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008254 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008255set_bool_option(
8256 int opt_idx, /* index in options[] table */
8257 char_u *varp, /* pointer to the option variable */
8258 int value, /* new value */
8259 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008260{
8261 int old_value = *(int *)varp;
8262
Bram Moolenaar071d4272004-06-13 20:20:40 +00008263 /* Disallow changing some options from secure mode */
8264 if ((secure
8265#ifdef HAVE_SANDBOX
8266 || sandbox != 0
8267#endif
8268 ) && (options[opt_idx].flags & P_SECURE))
8269 return e_secure;
8270
8271 *(int *)varp = value; /* set the new value */
8272#ifdef FEAT_EVAL
8273 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008274 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008275#endif
8276
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008277#ifdef FEAT_GUI
8278 need_mouse_correct = TRUE;
8279#endif
8280
Bram Moolenaar071d4272004-06-13 20:20:40 +00008281 /* May set global value for local option. */
8282 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8283 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8284
8285 /*
8286 * Handle side effects of changing a bool option.
8287 */
8288
8289 /* 'compatible' */
8290 if ((int *)varp == &p_cp)
8291 {
8292 compatible_set();
8293 }
8294
Bram Moolenaar920694c2016-08-21 17:45:02 +02008295#ifdef FEAT_LANGMAP
8296 if ((int *)varp == &p_lrm)
8297 /* 'langremap' -> !'langnoremap' */
8298 p_lnr = !p_lrm;
8299 else if ((int *)varp == &p_lnr)
8300 /* 'langnoremap' -> !'langremap' */
8301 p_lrm = !p_lnr;
8302#endif
8303
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008304#ifdef FEAT_SYN_HL
8305 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8306 reset_cursorline();
8307#endif
8308
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008309#ifdef FEAT_PERSISTENT_UNDO
8310 /* 'undofile' */
8311 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8312 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008313 /* Only take action when the option was set. When reset we do not
8314 * delete the undo file, the option may be set again without making
8315 * any changes in between. */
8316 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008317 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008318 char_u hash[UNDO_HASH_SIZE];
8319 buf_T *save_curbuf = curbuf;
8320
Bram Moolenaar29323592016-07-24 22:04:11 +02008321 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008322 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008323 /* When 'undofile' is set globally: for every buffer, otherwise
8324 * only for the current buffer: Try to read in the undofile,
8325 * if one exists, the buffer wasn't changed and the buffer was
8326 * loaded */
8327 if ((curbuf == save_curbuf
8328 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8329 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8330 {
8331 u_compute_hash(hash);
8332 u_read_undo(NULL, hash, curbuf->b_fname);
8333 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008334 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008335 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008336 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008337 }
8338#endif
8339
Bram Moolenaar071d4272004-06-13 20:20:40 +00008340 else if ((int *)varp == &curbuf->b_p_ro)
8341 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008342 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8344 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008345
8346 /* when 'readonly' is set may give W10 again */
8347 if (curbuf->b_p_ro)
8348 curbuf->b_did_warn = FALSE;
8349
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008351 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352#endif
8353 }
8354
Bram Moolenaar9c449722010-07-20 18:44:27 +02008355#ifdef FEAT_GUI
8356 else if ((int *)varp == &p_mh)
8357 {
8358 if (!p_mh)
8359 gui_mch_mousehide(FALSE);
8360 }
8361#endif
8362
Bram Moolenaara539df02010-08-01 14:35:05 +02008363 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008365 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008366# ifdef FEAT_TERMINAL
8367 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008368 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8369 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008370 {
8371 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008372 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008373 }
8374# endif
8375# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008376 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008377# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008378 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008379#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380 /* when 'endofline' is changed, redraw the window title */
8381 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008382 {
8383 redraw_titles();
8384 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008385 /* when 'fixeol' is changed, redraw the window title */
8386 else if ((int *)varp == &curbuf->b_p_fixeol)
8387 {
8388 redraw_titles();
8389 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008390 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008391 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008392 {
8393 redraw_titles();
8394 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008395#endif
8396
8397 /* when 'bin' is set also set some other options */
8398 else if ((int *)varp == &curbuf->b_p_bin)
8399 {
8400 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8401#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008402 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008403#endif
8404 }
8405
Bram Moolenaar071d4272004-06-13 20:20:40 +00008406 /* when 'buflisted' changes, trigger autocommands */
8407 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8408 {
8409 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8410 NULL, NULL, TRUE, curbuf);
8411 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412
8413 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8414 else if ((int *)varp == &curbuf->b_p_swf)
8415 {
8416 if (curbuf->b_p_swf && p_uc)
8417 ml_open_file(curbuf); /* create the swap file */
8418 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008419 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8420 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421 mf_close_file(curbuf, TRUE); /* remove the swap file */
8422 }
8423
8424 /* when 'terse' is set change 'shortmess' */
8425 else if ((int *)varp == &p_terse)
8426 {
8427 char_u *p;
8428
8429 p = vim_strchr(p_shm, SHM_SEARCH);
8430
8431 /* insert 's' in p_shm */
8432 if (p_terse && p == NULL)
8433 {
8434 STRCPY(IObuff, p_shm);
8435 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008436 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 }
8438 /* remove 's' from p_shm */
8439 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008440 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441 }
8442
8443 /* when 'paste' is set or reset also change other options */
8444 else if ((int *)varp == &p_paste)
8445 {
8446 paste_option_changed();
8447 }
8448
8449 /* when 'insertmode' is set from an autocommand need to do work here */
8450 else if ((int *)varp == &p_im)
8451 {
8452 if (p_im)
8453 {
8454 if ((State & INSERT) == 0)
8455 need_start_insertmode = TRUE;
8456 stop_insert_mode = FALSE;
8457 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008458 /* only reset if it was set previously */
8459 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460 {
8461 need_start_insertmode = FALSE;
8462 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008463 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008464 clear_cmdline = TRUE; /* remove "(insert)" */
8465 restart_edit = 0;
8466 }
8467 }
8468
8469 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8470 else if ((int *)varp == &p_ic && p_hls)
8471 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008472 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473 }
8474
8475#ifdef FEAT_SEARCH_EXTRA
8476 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8477 else if ((int *)varp == &p_hls)
8478 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008479 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008480 }
8481#endif
8482
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8484 * at the end of normal_cmd() */
8485 else if ((int *)varp == &curwin->w_p_scb)
8486 {
8487 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008488 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008490 curwin->w_scbind_pos = curwin->w_topline;
8491 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493
Bram Moolenaar4033c552017-09-16 20:54:51 +02008494#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495 /* There can be only one window with 'previewwindow' set. */
8496 else if ((int *)varp == &curwin->w_p_pvw)
8497 {
8498 if (curwin->w_p_pvw)
8499 {
8500 win_T *win;
8501
Bram Moolenaar29323592016-07-24 22:04:11 +02008502 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008503 if (win->w_p_pvw && win != curwin)
8504 {
8505 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008506 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008507 }
8508 }
8509 }
8510#endif
8511
8512 /* when 'textmode' is set or reset also change 'fileformat' */
8513 else if ((int *)varp == &curbuf->b_p_tx)
8514 {
8515 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8516 }
8517
8518 /* when 'textauto' is set or reset also change 'fileformats' */
8519 else if ((int *)varp == &p_ta)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 set_string_option_direct((char_u *)"ffs", -1,
8521 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008522 OPT_FREE | opt_flags, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008523
8524 /*
8525 * When 'lisp' option changes include/exclude '-' in
8526 * keyword characters.
8527 */
8528#ifdef FEAT_LISP
8529 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8530 {
8531 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8532 }
8533#endif
8534
8535#ifdef FEAT_TITLE
8536 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008537 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008539 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540 }
8541#endif
8542
8543 else if ((int *)varp == &curbuf->b_changed)
8544 {
8545 if (!value)
8546 save_file_ff(curbuf); /* Buffer is unchanged */
8547#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008548 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008549#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008550 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551 }
8552
8553#ifdef BACKSLASH_IN_FILENAME
8554 else if ((int *)varp == &p_ssl)
8555 {
8556 if (p_ssl)
8557 {
8558 psepc = '/';
8559 psepcN = '\\';
8560 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561 }
8562 else
8563 {
8564 psepc = '\\';
8565 psepcN = '/';
8566 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008567 }
8568
8569 /* need to adjust the file name arguments and buffer names. */
8570 buflist_slash_adjust();
8571 alist_slash_adjust();
8572# ifdef FEAT_EVAL
8573 scriptnames_slash_adjust();
8574# endif
8575 }
8576#endif
8577
8578 /* If 'wrap' is set, set w_leftcol to zero. */
8579 else if ((int *)varp == &curwin->w_p_wrap)
8580 {
8581 if (curwin->w_p_wrap)
8582 curwin->w_leftcol = 0;
8583 }
8584
Bram Moolenaar071d4272004-06-13 20:20:40 +00008585 else if ((int *)varp == &p_ea)
8586 {
8587 if (p_ea && !old_value)
8588 win_equal(curwin, FALSE, 0);
8589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590
8591 else if ((int *)varp == &p_wiv)
8592 {
8593 /*
8594 * When 'weirdinvert' changed, set/reset 't_xs'.
8595 * Then set 'weirdinvert' according to value of 't_xs'.
8596 */
8597 if (p_wiv && !old_value)
8598 T_XS = (char_u *)"y";
8599 else if (!p_wiv && old_value)
8600 T_XS = empty_option;
8601 p_wiv = (*T_XS != NUL);
8602 }
8603
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008604#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605 else if ((int *)varp == &p_beval)
8606 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008607 if (!balloonEvalForTerm)
8608 {
8609 if (p_beval && !old_value)
8610 gui_mch_enable_beval_area(balloonEval);
8611 else if (!p_beval && old_value)
8612 gui_mch_disable_beval_area(balloonEval);
8613 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008614 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008615#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008616#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008617 else if ((int *)varp == &p_bevalterm)
8618 {
8619 mch_bevalterm_changed();
8620 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008621#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008623#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008624 else if ((int *)varp == &p_acd)
8625 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008626 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008627 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 }
8629#endif
8630
8631#ifdef FEAT_DIFF
8632 /* 'diff' */
8633 else if ((int *)varp == &curwin->w_p_diff)
8634 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008635 /* May add or remove the buffer from the list of diff buffers. */
8636 diff_buf_adjust(curwin);
8637# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638 if (foldmethodIsDiff(curwin))
8639 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008640# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 }
8642#endif
8643
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008644#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008645 /* 'imdisable' */
8646 else if ((int *)varp == &p_imdisable)
8647 {
8648 /* Only de-activate it here, it will be enabled when changing mode. */
8649 if (p_imdisable)
8650 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008651 else if (State & INSERT)
8652 /* When the option is set from an autocommand, it may need to take
8653 * effect right away. */
8654 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008655 }
8656#endif
8657
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008658#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008659 /* 'spell' */
8660 else if ((int *)varp == &curwin->w_p_spell)
8661 {
8662 if (curwin->w_p_spell)
8663 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008664 char *errmsg = did_set_spelllang(curwin);
8665
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008666 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008667 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008668 }
8669 }
8670#endif
8671
Bram Moolenaar071d4272004-06-13 20:20:40 +00008672#ifdef FEAT_FKMAP
8673 else if ((int *)varp == &p_altkeymap)
8674 {
8675 if (old_value != p_altkeymap)
8676 {
8677 if (!p_altkeymap)
8678 {
8679 p_hkmap = p_fkmap;
8680 p_fkmap = 0;
8681 }
8682 else
8683 {
8684 p_fkmap = p_hkmap;
8685 p_hkmap = 0;
8686 }
8687 (void)init_chartab();
8688 }
8689 }
8690
8691 /*
8692 * In case some second language keymapping options have changed, check
8693 * and correct the setting in a consistent way.
8694 */
8695
8696 /*
8697 * If hkmap or fkmap are set, reset Arabic keymapping.
8698 */
8699 if ((p_hkmap || p_fkmap) && p_altkeymap)
8700 {
8701 p_altkeymap = p_fkmap;
8702# ifdef FEAT_ARABIC
8703 curwin->w_p_arab = FALSE;
8704# endif
8705 (void)init_chartab();
8706 }
8707
8708 /*
8709 * If hkmap set, reset Farsi keymapping.
8710 */
8711 if (p_hkmap && p_altkeymap)
8712 {
8713 p_altkeymap = 0;
8714 p_fkmap = 0;
8715# ifdef FEAT_ARABIC
8716 curwin->w_p_arab = FALSE;
8717# endif
8718 (void)init_chartab();
8719 }
8720
8721 /*
8722 * If fkmap set, reset Hebrew keymapping.
8723 */
8724 if (p_fkmap && !p_altkeymap)
8725 {
8726 p_altkeymap = 1;
8727 p_hkmap = 0;
8728# ifdef FEAT_ARABIC
8729 curwin->w_p_arab = FALSE;
8730# endif
8731 (void)init_chartab();
8732 }
8733#endif
8734
8735#ifdef FEAT_ARABIC
8736 if ((int *)varp == &curwin->w_p_arab)
8737 {
8738 if (curwin->w_p_arab)
8739 {
8740 /*
8741 * 'arabic' is set, handle various sub-settings.
8742 */
8743 if (!p_tbidi)
8744 {
8745 /* set rightleft mode */
8746 if (!curwin->w_p_rl)
8747 {
8748 curwin->w_p_rl = TRUE;
8749 changed_window_setting();
8750 }
8751
8752 /* Enable Arabic shaping (major part of what Arabic requires) */
8753 if (!p_arshape)
8754 {
8755 p_arshape = TRUE;
8756 redraw_later_clear();
8757 }
8758 }
8759
8760 /* Arabic requires a utf-8 encoding, inform the user if its not
8761 * set. */
8762 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008763 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008764 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8765
Bram Moolenaar8820b482017-03-16 17:23:31 +01008766 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008767 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008768#ifdef FEAT_EVAL
8769 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8770#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008771 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772
Bram Moolenaar071d4272004-06-13 20:20:40 +00008773 /* set 'delcombine' */
8774 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008775
8776# ifdef FEAT_KEYMAP
8777 /* Force-set the necessary keymap for arabic */
8778 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8779 OPT_LOCAL);
8780# endif
8781# ifdef FEAT_FKMAP
8782 p_altkeymap = 0;
8783 p_hkmap = 0;
8784 p_fkmap = 0;
8785 (void)init_chartab();
8786# endif
8787 }
8788 else
8789 {
8790 /*
8791 * 'arabic' is reset, handle various sub-settings.
8792 */
8793 if (!p_tbidi)
8794 {
8795 /* reset rightleft mode */
8796 if (curwin->w_p_rl)
8797 {
8798 curwin->w_p_rl = FALSE;
8799 changed_window_setting();
8800 }
8801
8802 /* 'arabicshape' isn't reset, it is a global option and
8803 * another window may still need it "on". */
8804 }
8805
8806 /* 'delcombine' isn't reset, it is a global option and another
8807 * window may still want it "on". */
8808
8809# ifdef FEAT_KEYMAP
8810 /* Revert to the default keymap */
8811 curbuf->b_p_iminsert = B_IMODE_NONE;
8812 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8813# endif
8814 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008815 }
8816
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008817#endif
8818
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008819#ifdef FEAT_TERMGUICOLORS
8820 /* 'termguicolors' */
8821 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008822 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008823# ifdef FEAT_VTP
8824 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8825 if (!has_vtp_working())
8826 {
8827 p_tgc = 0;
8828 return (char_u*)N_("E954: 24-bit colors are not supported on this environment");
8829 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008830 if (is_term_win32())
8831 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008832# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008833# ifdef FEAT_GUI
8834 if (!gui.in_use && !gui.starting)
8835# endif
8836 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008837# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008838 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008839 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008840 {
8841 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008842 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008843 init_highlight(TRUE, FALSE);
8844 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008845# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008846 }
8847#endif
8848
Bram Moolenaar071d4272004-06-13 20:20:40 +00008849 /*
8850 * End of handling side effects for bool options.
8851 */
8852
Bram Moolenaar53744302015-07-17 17:38:22 +02008853 /* after handling side effects, call autocommand */
8854
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855 options[opt_idx].flags |= P_WAS_SET;
8856
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008857#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008858 // Don't do this while starting up or recursively.
8859 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008860 {
8861 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008862
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008863 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8864 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8865 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008866 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8867 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8868 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8869 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8870 reset_v_option_vars();
8871 }
8872#endif
8873
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008875 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008876 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008877 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008878 check_redraw(options[opt_idx].flags);
8879
8880 return NULL;
8881}
8882
8883/*
8884 * Set the value of a number option, and take care of side effects.
8885 * Returns NULL for success, or an error message for an error.
8886 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008887 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008888set_num_option(
8889 int opt_idx, /* index in options[] table */
8890 char_u *varp, /* pointer to the option variable */
8891 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008892 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008893 size_t errbuflen, /* length of "errbuf" */
8894 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008895 OPT_MODELINE */
8896{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008897 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 long old_value = *(long *)varp;
8899 long old_Rows = Rows; /* remember old Rows */
8900 long old_Columns = Columns; /* remember old Columns */
8901 long *pp = (long *)varp;
8902
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008903 /* Disallow changing some options from secure mode. */
8904 if ((secure
8905#ifdef HAVE_SANDBOX
8906 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008907#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008908 ) && (options[opt_idx].flags & P_SECURE))
8909 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008910
8911 *pp = value;
8912#ifdef FEAT_EVAL
8913 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008914 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008915#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008916#ifdef FEAT_GUI
8917 need_mouse_correct = TRUE;
8918#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008919
Bram Moolenaar14f24742012-08-08 18:01:05 +02008920 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921 {
8922 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008923#ifdef FEAT_VARTABS
8924 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8925 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8926 ? tabstop_first(curbuf->b_p_vts_array)
8927 : curbuf->b_p_ts;
8928#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008930#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008931 }
8932
8933 /*
8934 * Number options that need some action when changed
8935 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008936 if (pp == &p_wh || pp == &p_hh)
8937 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008938 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008939 if (p_wh < 1)
8940 {
8941 errmsg = e_positive;
8942 p_wh = 1;
8943 }
8944 if (p_wmh > p_wh)
8945 {
8946 errmsg = e_winheight;
8947 p_wh = p_wmh;
8948 }
8949 if (p_hh < 0)
8950 {
8951 errmsg = e_positive;
8952 p_hh = 0;
8953 }
8954
8955 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008956 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008957 {
8958 if (pp == &p_wh && curwin->w_height < p_wh)
8959 win_setheight((int)p_wh);
8960 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8961 win_setheight((int)p_hh);
8962 }
8963 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008964 else if (pp == &p_wmh)
8965 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008966 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008967 if (p_wmh < 0)
8968 {
8969 errmsg = e_positive;
8970 p_wmh = 0;
8971 }
8972 if (p_wmh > p_wh)
8973 {
8974 errmsg = e_winheight;
8975 p_wmh = p_wh;
8976 }
8977 win_setminheight();
8978 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008979 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008981 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008982 if (p_wiw < 1)
8983 {
8984 errmsg = e_positive;
8985 p_wiw = 1;
8986 }
8987 if (p_wmw > p_wiw)
8988 {
8989 errmsg = e_winwidth;
8990 p_wiw = p_wmw;
8991 }
8992
8993 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008994 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008995 win_setwidth((int)p_wiw);
8996 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008997 else if (pp == &p_wmw)
8998 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008999 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009000 if (p_wmw < 0)
9001 {
9002 errmsg = e_positive;
9003 p_wmw = 0;
9004 }
9005 if (p_wmw > p_wiw)
9006 {
9007 errmsg = e_winwidth;
9008 p_wmw = p_wiw;
9009 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009010 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009011 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009012
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013 /* (re)set last window status line */
9014 else if (pp == &p_ls)
9015 {
9016 last_status(FALSE);
9017 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009018
9019 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009020 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009021 {
9022 shell_new_rows(); /* recompute window positions and heights */
9023 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009024
9025#ifdef FEAT_GUI
9026 else if (pp == &p_linespace)
9027 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009028 /* Recompute gui.char_height and resize the Vim window to keep the
9029 * same number of lines. */
9030 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009031 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009032 }
9033#endif
9034
9035#ifdef FEAT_FOLDING
9036 /* 'foldlevel' */
9037 else if (pp == &curwin->w_p_fdl)
9038 {
9039 if (curwin->w_p_fdl < 0)
9040 curwin->w_p_fdl = 0;
9041 newFoldLevel();
9042 }
9043
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009044 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009045 else if (pp == &curwin->w_p_fml)
9046 {
9047 foldUpdateAll(curwin);
9048 }
9049
9050 /* 'foldnestmax' */
9051 else if (pp == &curwin->w_p_fdn)
9052 {
9053 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9054 foldUpdateAll(curwin);
9055 }
9056
9057 /* 'foldcolumn' */
9058 else if (pp == &curwin->w_p_fdc)
9059 {
9060 if (curwin->w_p_fdc < 0)
9061 {
9062 errmsg = e_positive;
9063 curwin->w_p_fdc = 0;
9064 }
9065 else if (curwin->w_p_fdc > 12)
9066 {
9067 errmsg = e_invarg;
9068 curwin->w_p_fdc = 12;
9069 }
9070 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009071#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009072
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009073#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074 /* 'shiftwidth' or 'tabstop' */
9075 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9076 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009077# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009078 if (foldmethodIsIndent(curwin))
9079 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009080# endif
9081# ifdef FEAT_CINDENT
9082 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9083 * parse 'cinoptions'. */
9084 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9085 parse_cino(curbuf);
9086# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009087 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009088#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009089
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009090 /* 'maxcombine' */
9091 else if (pp == &p_mco)
9092 {
9093 if (p_mco > MAX_MCO)
9094 p_mco = MAX_MCO;
9095 else if (p_mco < 0)
9096 p_mco = 0;
9097 screenclear(); /* will re-allocate the screen */
9098 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009099
Bram Moolenaar071d4272004-06-13 20:20:40 +00009100 else if (pp == &curbuf->b_p_iminsert)
9101 {
9102 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9103 {
9104 errmsg = e_invarg;
9105 curbuf->b_p_iminsert = B_IMODE_NONE;
9106 }
9107 p_iminsert = curbuf->b_p_iminsert;
9108 if (termcap_active) /* don't do this in the alternate screen */
9109 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009110#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009111 /* Show/unshow value of 'keymap' in status lines. */
9112 status_redraw_curbuf();
9113#endif
9114 }
9115
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009116#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9117 /* 'imstyle' */
9118 else if (pp == &p_imst)
9119 {
9120 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9121 errmsg = e_invarg;
9122 }
9123#endif
9124
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009125 else if (pp == &p_window)
9126 {
9127 if (p_window < 1)
9128 p_window = 1;
9129 else if (p_window >= Rows)
9130 p_window = Rows - 1;
9131 }
9132
Bram Moolenaar071d4272004-06-13 20:20:40 +00009133 else if (pp == &curbuf->b_p_imsearch)
9134 {
9135 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9136 {
9137 errmsg = e_invarg;
9138 curbuf->b_p_imsearch = B_IMODE_NONE;
9139 }
9140 p_imsearch = curbuf->b_p_imsearch;
9141 }
9142
9143#ifdef FEAT_TITLE
9144 /* if 'titlelen' has changed, redraw the title */
9145 else if (pp == &p_titlelen)
9146 {
9147 if (p_titlelen < 0)
9148 {
9149 errmsg = e_positive;
9150 p_titlelen = 85;
9151 }
9152 if (starting != NO_SCREEN && old_value != p_titlelen)
9153 need_maketitle = TRUE;
9154 }
9155#endif
9156
9157 /* if p_ch changed value, change the command line height */
9158 else if (pp == &p_ch)
9159 {
9160 if (p_ch < 1)
9161 {
9162 errmsg = e_positive;
9163 p_ch = 1;
9164 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009165 if (p_ch > Rows - min_rows() + 1)
9166 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167
9168 /* Only compute the new window layout when startup has been
9169 * completed. Otherwise the frame sizes may be wrong. */
9170 if (p_ch != old_value && full_screen
9171#ifdef FEAT_GUI
9172 && !gui.starting
9173#endif
9174 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009175 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009176 }
9177
9178 /* when 'updatecount' changes from zero to non-zero, open swap files */
9179 else if (pp == &p_uc)
9180 {
9181 if (p_uc < 0)
9182 {
9183 errmsg = e_positive;
9184 p_uc = 100;
9185 }
9186 if (p_uc && !old_value)
9187 ml_open_files();
9188 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009189#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009190 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009191 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009192 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009193 {
9194 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009195 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009196 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009197 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009198 {
9199 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009200 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009201 }
9202 }
9203#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009204#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009205 else if (pp == &p_mzq)
9206 mzvim_reset_timer();
9207#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009208
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009209#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9210 /* 'pyxversion' */
9211 else if (pp == &p_pyx)
9212 {
9213 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9214 errmsg = e_invarg;
9215 }
9216#endif
9217
Bram Moolenaar071d4272004-06-13 20:20:40 +00009218 /* sync undo before 'undolevels' changes */
9219 else if (pp == &p_ul)
9220 {
9221 /* use the old value, otherwise u_sync() may not work properly */
9222 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009223 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009224 p_ul = value;
9225 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009226 else if (pp == &curbuf->b_p_ul)
9227 {
9228 /* use the old value, otherwise u_sync() may not work properly */
9229 curbuf->b_p_ul = old_value;
9230 u_sync(TRUE);
9231 curbuf->b_p_ul = value;
9232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009234#ifdef FEAT_LINEBREAK
9235 /* 'numberwidth' must be positive */
9236 else if (pp == &curwin->w_p_nuw)
9237 {
9238 if (curwin->w_p_nuw < 1)
9239 {
9240 errmsg = e_positive;
9241 curwin->w_p_nuw = 1;
9242 }
9243 if (curwin->w_p_nuw > 10)
9244 {
9245 errmsg = e_invarg;
9246 curwin->w_p_nuw = 10;
9247 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009248 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009249 }
9250#endif
9251
Bram Moolenaar1a384422010-07-14 19:53:30 +02009252 else if (pp == &curbuf->b_p_tw)
9253 {
9254 if (curbuf->b_p_tw < 0)
9255 {
9256 errmsg = e_positive;
9257 curbuf->b_p_tw = 0;
9258 }
9259#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009260 {
9261 win_T *wp;
9262 tabpage_T *tp;
9263
9264 FOR_ALL_TAB_WINDOWS(tp, wp)
9265 check_colorcolumn(wp);
9266 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009267#endif
9268 }
9269
Bram Moolenaar071d4272004-06-13 20:20:40 +00009270 /*
9271 * Check the bounds for numeric options here
9272 */
9273 if (Rows < min_rows() && full_screen)
9274 {
9275 if (errbuf != NULL)
9276 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009277 vim_snprintf((char *)errbuf, errbuflen,
9278 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009279 errmsg = errbuf;
9280 }
9281 Rows = min_rows();
9282 }
9283 if (Columns < MIN_COLUMNS && full_screen)
9284 {
9285 if (errbuf != NULL)
9286 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009287 vim_snprintf((char *)errbuf, errbuflen,
9288 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009289 errmsg = errbuf;
9290 }
9291 Columns = MIN_COLUMNS;
9292 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009293 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009294
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295 /*
9296 * If the screen (shell) height has been changed, assume it is the
9297 * physical screenheight.
9298 */
9299 if (old_Rows != Rows || old_Columns != Columns)
9300 {
9301 /* Changing the screen size is not allowed while updating the screen. */
9302 if (updating_screen)
9303 *pp = old_value;
9304 else if (full_screen
9305#ifdef FEAT_GUI
9306 && !gui.starting
9307#endif
9308 )
9309 set_shellsize((int)Columns, (int)Rows, TRUE);
9310 else
9311 {
9312 /* Postpone the resizing; check the size and cmdline position for
9313 * messages. */
9314 check_shellsize();
9315 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9316 cmdline_row = Rows - p_ch;
9317 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009318 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009319 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009320 }
9321
Bram Moolenaar071d4272004-06-13 20:20:40 +00009322 if (curbuf->b_p_ts <= 0)
9323 {
9324 errmsg = e_positive;
9325 curbuf->b_p_ts = 8;
9326 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327 if (p_tm < 0)
9328 {
9329 errmsg = e_positive;
9330 p_tm = 0;
9331 }
9332 if ((curwin->w_p_scr <= 0
9333 || (curwin->w_p_scr > curwin->w_height
9334 && curwin->w_height > 0))
9335 && full_screen)
9336 {
9337 if (pp == &(curwin->w_p_scr))
9338 {
9339 if (curwin->w_p_scr != 0)
9340 errmsg = e_scroll;
9341 win_comp_scroll(curwin);
9342 }
9343 /* If 'scroll' became invalid because of a side effect silently adjust
9344 * it. */
9345 else if (curwin->w_p_scr <= 0)
9346 curwin->w_p_scr = 1;
9347 else /* curwin->w_p_scr > curwin->w_height */
9348 curwin->w_p_scr = curwin->w_height;
9349 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009350 if (p_hi < 0)
9351 {
9352 errmsg = e_positive;
9353 p_hi = 0;
9354 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009355 else if (p_hi > 10000)
9356 {
9357 errmsg = e_invarg;
9358 p_hi = 10000;
9359 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009360 if (p_re < 0 || p_re > 2)
9361 {
9362 errmsg = e_invarg;
9363 p_re = 0;
9364 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009365 if (p_report < 0)
9366 {
9367 errmsg = e_positive;
9368 p_report = 1;
9369 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009370 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009371 {
9372 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9373 p_sj = Rows / 2;
9374 else
9375 {
9376 errmsg = e_scroll;
9377 p_sj = 1;
9378 }
9379 }
9380 if (p_so < 0 && full_screen)
9381 {
9382 errmsg = e_scroll;
9383 p_so = 0;
9384 }
9385 if (p_siso < 0 && full_screen)
9386 {
9387 errmsg = e_positive;
9388 p_siso = 0;
9389 }
9390#ifdef FEAT_CMDWIN
9391 if (p_cwh < 1)
9392 {
9393 errmsg = e_positive;
9394 p_cwh = 1;
9395 }
9396#endif
9397 if (p_ut < 0)
9398 {
9399 errmsg = e_positive;
9400 p_ut = 2000;
9401 }
9402 if (p_ss < 0)
9403 {
9404 errmsg = e_positive;
9405 p_ss = 0;
9406 }
9407
9408 /* May set global value for local option. */
9409 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9410 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9411
9412 options[opt_idx].flags |= P_WAS_SET;
9413
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009414#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009415 // Don't do this while starting up, failure or recursively.
9416 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009417 {
9418 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009419 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9420 vim_snprintf((char *)buf_new, 10, "%ld", value);
9421 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009422 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9423 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9424 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9425 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9426 reset_v_option_vars();
9427 }
9428#endif
9429
Bram Moolenaar071d4272004-06-13 20:20:40 +00009430 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009431 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009432 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009433 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009434 check_redraw(options[opt_idx].flags);
9435
9436 return errmsg;
9437}
9438
9439/*
9440 * Called after an option changed: check if something needs to be redrawn.
9441 */
9442 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009443check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009444{
9445 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009446 int doclear = (flags & P_RCLR) == P_RCLR;
9447 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009448
Bram Moolenaar071d4272004-06-13 20:20:40 +00009449 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9450 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009451
9452 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9453 changed_window_setting();
9454 if (flags & P_RBUF)
9455 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009456 if (flags & P_RWINONLY)
9457 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009458 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009459 redraw_all_later(CLEAR);
9460 else if (all)
9461 redraw_all_later(NOT_VALID);
9462}
9463
9464/*
9465 * Find index for option 'arg'.
9466 * Return -1 if not found.
9467 */
9468 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009469findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009470{
9471 int opt_idx;
9472 char *s, *p;
9473 static short quick_tab[27] = {0, 0}; /* quick access table */
9474 int is_term_opt;
9475
9476 /*
9477 * For first call: Initialize the quick-access table.
9478 * It contains the index for the first option that starts with a certain
9479 * letter. There are 26 letters, plus the first "t_" option.
9480 */
9481 if (quick_tab[1] == 0)
9482 {
9483 p = options[0].fullname;
9484 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9485 {
9486 if (s[0] != p[0])
9487 {
9488 if (s[0] == 't' && s[1] == '_')
9489 quick_tab[26] = opt_idx;
9490 else
9491 quick_tab[CharOrdLow(s[0])] = opt_idx;
9492 }
9493 p = s;
9494 }
9495 }
9496
9497 /*
9498 * Check for name starting with an illegal character.
9499 */
9500#ifdef EBCDIC
9501 if (!islower(arg[0]))
9502#else
9503 if (arg[0] < 'a' || arg[0] > 'z')
9504#endif
9505 return -1;
9506
9507 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9508 if (is_term_opt)
9509 opt_idx = quick_tab[26];
9510 else
9511 opt_idx = quick_tab[CharOrdLow(arg[0])];
9512 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9513 {
9514 if (STRCMP(arg, s) == 0) /* match full name */
9515 break;
9516 }
9517 if (s == NULL && !is_term_opt)
9518 {
9519 opt_idx = quick_tab[CharOrdLow(arg[0])];
9520 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9521 {
9522 s = options[opt_idx].shortname;
9523 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9524 break;
9525 s = NULL;
9526 }
9527 }
9528 if (s == NULL)
9529 opt_idx = -1;
9530 return opt_idx;
9531}
9532
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009533#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009534/*
9535 * Get the value for an option.
9536 *
9537 * Returns:
9538 * Number or Toggle option: 1, *numval gets value.
9539 * String option: 0, *stringval gets allocated string.
9540 * Hidden Number or Toggle option: -1.
9541 * hidden String option: -2.
9542 * unknown option: -3.
9543 */
9544 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009545get_option_value(
9546 char_u *name,
9547 long *numval,
9548 char_u **stringval, /* NULL when only checking existence */
9549 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009550{
9551 int opt_idx;
9552 char_u *varp;
9553
9554 opt_idx = findoption(name);
9555 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009556 {
9557 int key;
9558
9559 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009560 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009561 {
9562 char_u key_name[2];
9563 char_u *p;
9564
9565 if (key < 0)
9566 {
9567 key_name[0] = KEY2TERMCAP0(key);
9568 key_name[1] = KEY2TERMCAP1(key);
9569 }
9570 else
9571 {
9572 key_name[0] = KS_KEY;
9573 key_name[1] = (key & 0xff);
9574 }
9575 p = find_termcode(key_name);
9576 if (p != NULL)
9577 {
9578 if (stringval != NULL)
9579 *stringval = vim_strsave(p);
9580 return 0;
9581 }
9582 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009583 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009584 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585
9586 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9587
9588 if (options[opt_idx].flags & P_STRING)
9589 {
9590 if (varp == NULL) /* hidden option */
9591 return -2;
9592 if (stringval != NULL)
9593 {
9594#ifdef FEAT_CRYPT
9595 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009596 if ((char_u **)varp == &curbuf->b_p_key
9597 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009598 *stringval = vim_strsave((char_u *)"*****");
9599 else
9600#endif
9601 *stringval = vim_strsave(*(char_u **)(varp));
9602 }
9603 return 0;
9604 }
9605
9606 if (varp == NULL) /* hidden option */
9607 return -1;
9608 if (options[opt_idx].flags & P_NUM)
9609 *numval = *(long *)varp;
9610 else
9611 {
9612 /* Special case: 'modified' is b_changed, but we also want to consider
9613 * it set when 'ff' or 'fenc' changed. */
9614 if ((int *)varp == &curbuf->b_changed)
9615 *numval = curbufIsChanged();
9616 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009617 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009618 }
9619 return 1;
9620}
9621#endif
9622
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009623#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009624/*
9625 * Returns the option attributes and its value. Unlike the above function it
9626 * will return either global value or local value of the option depending on
9627 * what was requested, but it will never return global value if it was
9628 * requested to return local one and vice versa. Neither it will return
9629 * buffer-local value if it was requested to return window-local one.
9630 *
9631 * Pretends that option is absent if it is not present in the requested scope
9632 * (i.e. has no global, window-local or buffer-local value depending on
9633 * opt_type). Uses
9634 *
9635 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009636 * 0 hidden or unknown option, also option that does not have requested
9637 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009638 * see SOPT_* in vim.h for other flags
9639 *
9640 * Possible opt_type values: see SREQ_* in vim.h
9641 */
9642 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009643get_option_value_strict(
9644 char_u *name,
9645 long *numval,
9646 char_u **stringval, /* NULL when only obtaining attributes */
9647 int opt_type,
9648 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009649{
9650 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009651 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009652 struct vimoption *p;
9653 int r = 0;
9654
9655 opt_idx = findoption(name);
9656 if (opt_idx < 0)
9657 return 0;
9658
9659 p = &(options[opt_idx]);
9660
9661 /* Hidden option */
9662 if (p->var == NULL)
9663 return 0;
9664
9665 if (p->flags & P_BOOL)
9666 r |= SOPT_BOOL;
9667 else if (p->flags & P_NUM)
9668 r |= SOPT_NUM;
9669 else if (p->flags & P_STRING)
9670 r |= SOPT_STRING;
9671
9672 if (p->indir == PV_NONE)
9673 {
9674 if (opt_type == SREQ_GLOBAL)
9675 r |= SOPT_GLOBAL;
9676 else
9677 return 0; /* Did not request global-only option */
9678 }
9679 else
9680 {
9681 if (p->indir & PV_BOTH)
9682 r |= SOPT_GLOBAL;
9683 else if (opt_type == SREQ_GLOBAL)
9684 return 0; /* Requested global option */
9685
9686 if (p->indir & PV_WIN)
9687 {
9688 if (opt_type == SREQ_BUF)
9689 return 0; /* Did not request window-local option */
9690 else
9691 r |= SOPT_WIN;
9692 }
9693 else if (p->indir & PV_BUF)
9694 {
9695 if (opt_type == SREQ_WIN)
9696 return 0; /* Did not request buffer-local option */
9697 else
9698 r |= SOPT_BUF;
9699 }
9700 }
9701
9702 if (stringval == NULL)
9703 return r;
9704
9705 if (opt_type == SREQ_GLOBAL)
9706 varp = p->var;
9707 else
9708 {
9709 if (opt_type == SREQ_BUF)
9710 {
9711 /* Special case: 'modified' is b_changed, but we also want to
9712 * consider it set when 'ff' or 'fenc' changed. */
9713 if (p->indir == PV_MOD)
9714 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009715 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009716 varp = NULL;
9717 }
9718#ifdef FEAT_CRYPT
9719 else if (p->indir == PV_KEY)
9720 {
9721 /* never return the value of the crypt key */
9722 *stringval = NULL;
9723 varp = NULL;
9724 }
9725#endif
9726 else
9727 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009728 buf_T *save_curbuf = curbuf;
9729
9730 // only getting a pointer, no need to use aucmd_prepbuf()
9731 curbuf = (buf_T *)from;
9732 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009733 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009734 curbuf = save_curbuf;
9735 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009736 }
9737 }
9738 else if (opt_type == SREQ_WIN)
9739 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009740 win_T *save_curwin = curwin;
9741
9742 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009743 curbuf = curwin->w_buffer;
9744 varp = get_varp(p);
9745 curwin = save_curwin;
9746 curbuf = curwin->w_buffer;
9747 }
9748 if (varp == p->var)
9749 return (r | SOPT_UNSET);
9750 }
9751
9752 if (varp != NULL)
9753 {
9754 if (p->flags & P_STRING)
9755 *stringval = vim_strsave(*(char_u **)(varp));
9756 else if (p->flags & P_NUM)
9757 *numval = *(long *) varp;
9758 else
9759 *numval = *(int *)varp;
9760 }
9761
9762 return r;
9763}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009764
9765/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009766 * Iterate over options. First argument is a pointer to a pointer to a
9767 * structure inside options[] array, second is option type like in the above
9768 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009769 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009770 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009771 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009772 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009773 * first argument to NULL.
9774 *
9775 * Returns full option name for current option on each call.
9776 */
9777 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009778option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009779{
9780 struct vimoption *ret = NULL;
9781 do
9782 {
9783 if (*option == NULL)
9784 *option = (void *) options;
9785 else if (((struct vimoption *) (*option))->fullname == NULL)
9786 {
9787 *option = NULL;
9788 return NULL;
9789 }
9790 else
9791 *option = (void *) (((struct vimoption *) (*option)) + 1);
9792
9793 ret = ((struct vimoption *) (*option));
9794
9795 /* Hidden option */
9796 if (ret->var == NULL)
9797 {
9798 ret = NULL;
9799 continue;
9800 }
9801
9802 switch (opt_type)
9803 {
9804 case SREQ_GLOBAL:
9805 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9806 ret = NULL;
9807 break;
9808 case SREQ_BUF:
9809 if (!(ret->indir & PV_BUF))
9810 ret = NULL;
9811 break;
9812 case SREQ_WIN:
9813 if (!(ret->indir & PV_WIN))
9814 ret = NULL;
9815 break;
9816 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009817 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009818 return NULL;
9819 }
9820 }
9821 while (ret == NULL);
9822
9823 return (char_u *)ret->fullname;
9824}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009825#endif
9826
Bram Moolenaar071d4272004-06-13 20:20:40 +00009827/*
9828 * Set the value of option "name".
9829 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009830 *
9831 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009832 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009833 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009834set_option_value(
9835 char_u *name,
9836 long number,
9837 char_u *string,
9838 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009839{
9840 int opt_idx;
9841 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009842 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009843
9844 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009845 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009846 {
9847 int key;
9848
9849 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009850 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009851 {
9852 char_u key_name[2];
9853
9854 if (key < 0)
9855 {
9856 key_name[0] = KEY2TERMCAP0(key);
9857 key_name[1] = KEY2TERMCAP1(key);
9858 }
9859 else
9860 {
9861 key_name[0] = KS_KEY;
9862 key_name[1] = (key & 0xff);
9863 }
9864 add_termcode(key_name, string, FALSE);
9865 if (full_screen)
9866 ttest(FALSE);
9867 redraw_all_later(CLEAR);
9868 return NULL;
9869 }
9870
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009871 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009873 else
9874 {
9875 flags = options[opt_idx].flags;
9876#ifdef HAVE_SANDBOX
9877 /* Disallow changing some options in the sandbox */
9878 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009879 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009880 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009881 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009882 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009883#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009884 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009885 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009886 else
9887 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009888 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009889 if (varp != NULL) /* hidden option is not changed */
9890 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009891 if (number == 0 && string != NULL)
9892 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009893 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009894
9895 /* Either we are given a string or we are setting option
9896 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009897 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009898 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009899 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009900 {
9901 /* There's another character after zeros or the string
9902 * is empty. In both cases, we are trying to set a
9903 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009904 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009905 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009906 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009907
9908 }
9909 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009910 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009911 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009912 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009913 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009914 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009915 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009916 }
9917 }
9918 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009919 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009920}
9921
9922/*
9923 * Get the terminal code for a terminal option.
9924 * Returns NULL when not found.
9925 */
9926 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009927get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009928{
9929 int opt_idx;
9930 char_u *varp;
9931
9932 if (tname[0] != 't' || tname[1] != '_' ||
9933 tname[2] == NUL || tname[3] == NUL)
9934 return NULL;
9935 if ((opt_idx = findoption(tname)) >= 0)
9936 {
9937 varp = get_varp(&(options[opt_idx]));
9938 if (varp != NULL)
9939 varp = *(char_u **)(varp);
9940 return varp;
9941 }
9942 return find_termcode(tname + 2);
9943}
9944
9945 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009946get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009947{
9948 int i;
9949
9950 i = findoption((char_u *)"hl");
9951 if (i >= 0)
9952 return options[i].def_val[VI_DEFAULT];
9953 return (char_u *)NULL;
9954}
9955
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009956 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009957get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009958{
9959 int i;
9960
9961 i = findoption((char_u *)"enc");
9962 if (i >= 0)
9963 return options[i].def_val[VI_DEFAULT];
9964 return (char_u *)NULL;
9965}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009966
Bram Moolenaar071d4272004-06-13 20:20:40 +00009967/*
9968 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009969 * When "has_lt" is true there is a '<' before "*arg_arg".
9970 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009971 */
9972 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009973find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009975 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009976 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009977 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009978
9979 /*
9980 * Don't use get_special_key_code() for t_xx, we don't want it to call
9981 * add_termcap_entry().
9982 */
9983 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9984 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009985 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009986 {
9987 --arg; /* put arg at the '<' */
9988 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009989 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009990 if (modifiers) /* can't handle modifiers here */
9991 key = 0;
9992 }
9993 return key;
9994}
9995
9996/*
9997 * if 'all' == 0: show changed options
9998 * if 'all' == 1: show all normal options
9999 * if 'all' == 2: show all terminal options
10000 */
10001 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010002showoptions(
10003 int all,
10004 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010005{
10006 struct vimoption *p;
10007 int col;
10008 int isterm;
10009 char_u *varp;
10010 struct vimoption **items;
10011 int item_count;
10012 int run;
10013 int row, rows;
10014 int cols;
10015 int i;
10016 int len;
10017
10018#define INC 20
10019#define GAP 3
10020
10021 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10022 PARAM_COUNT));
10023 if (items == NULL)
10024 return;
10025
10026 /* Highlight title */
10027 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010028 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010029 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010030 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010032 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010033 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010034 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010035
10036 /*
10037 * do the loop two times:
10038 * 1. display the short items
10039 * 2. display the long items (only strings and numbers)
10040 */
10041 for (run = 1; run <= 2 && !got_int; ++run)
10042 {
10043 /*
10044 * collect the items in items[]
10045 */
10046 item_count = 0;
10047 for (p = &options[0]; p->fullname != NULL; p++)
10048 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010049 // apply :filter /pat/
10050 if (message_filtered((char_u *) p->fullname))
10051 continue;
10052
Bram Moolenaar071d4272004-06-13 20:20:40 +000010053 varp = NULL;
10054 isterm = istermoption(p);
10055 if (opt_flags != 0)
10056 {
10057 if (p->indir != PV_NONE && !isterm)
10058 varp = get_varp_scope(p, opt_flags);
10059 }
10060 else
10061 varp = get_varp(p);
10062 if (varp != NULL
10063 && ((all == 2 && isterm)
10064 || (all == 1 && !isterm)
10065 || (all == 0 && !optval_default(p, varp))))
10066 {
10067 if (p->flags & P_BOOL)
10068 len = 1; /* a toggle option fits always */
10069 else
10070 {
10071 option_value2string(p, opt_flags);
10072 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10073 }
10074 if ((len <= INC - GAP && run == 1) ||
10075 (len > INC - GAP && run == 2))
10076 items[item_count++] = p;
10077 }
10078 }
10079
10080 /*
10081 * display the items
10082 */
10083 if (run == 1)
10084 {
10085 cols = (Columns + GAP - 3) / INC;
10086 if (cols == 0)
10087 cols = 1;
10088 rows = (item_count + cols - 1) / cols;
10089 }
10090 else /* run == 2 */
10091 rows = item_count;
10092 for (row = 0; row < rows && !got_int; ++row)
10093 {
10094 msg_putchar('\n'); /* go to next line */
10095 if (got_int) /* 'q' typed in more */
10096 break;
10097 col = 0;
10098 for (i = row; i < item_count; i += rows)
10099 {
10100 msg_col = col; /* make columns */
10101 showoneopt(items[i], opt_flags);
10102 col += INC;
10103 }
10104 out_flush();
10105 ui_breakcheck();
10106 }
10107 }
10108 vim_free(items);
10109}
10110
10111/*
10112 * Return TRUE if option "p" has its default value.
10113 */
10114 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010115optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116{
10117 int dvi;
10118
10119 if (varp == NULL)
10120 return TRUE; /* hidden option is always at default */
10121 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10122 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010123 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010124 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010125 /* the cast to long is required for Manx C, long_i is
10126 * needed for MSVC */
10127 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010128 /* P_STRING */
10129 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10130}
10131
10132/*
10133 * showoneopt: show the value of one option
10134 * must not be called with a hidden option!
10135 */
10136 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010137showoneopt(
10138 struct vimoption *p,
10139 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010140{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010141 char_u *varp;
10142 int save_silent = silent_mode;
10143
10144 silent_mode = FALSE;
10145 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010146
10147 varp = get_varp_scope(p, opt_flags);
10148
10149 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10150 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10151 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010152 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010153 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010154 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010155 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010156 msg_puts(" ");
10157 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010158 if (!(p->flags & P_BOOL))
10159 {
10160 msg_putchar('=');
10161 /* put value string in NameBuff */
10162 option_value2string(p, opt_flags);
10163 msg_outtrans(NameBuff);
10164 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010165
10166 silent_mode = save_silent;
10167 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010168}
10169
10170/*
10171 * Write modified options as ":set" commands to a file.
10172 *
10173 * There are three values for "opt_flags":
10174 * OPT_GLOBAL: Write global option values and fresh values of
10175 * buffer-local options (used for start of a session
10176 * file).
10177 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10178 * curwin (used for a vimrc file).
10179 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10180 * and local values for window-local options of
10181 * curwin. Local values are also written when at the
10182 * default value, because a modeline or autocommand
10183 * may have set them when doing ":edit file" and the
10184 * user has set them back at the default or fresh
10185 * value.
10186 * When "local_only" is TRUE, don't write fresh
10187 * values, only local values (for ":mkview").
10188 * (fresh value = value used for a new buffer or window for a local option).
10189 *
10190 * Return FAIL on error, OK otherwise.
10191 */
10192 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010193makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194{
10195 struct vimoption *p;
10196 char_u *varp; /* currently used value */
10197 char_u *varp_fresh; /* local value */
10198 char_u *varp_local = NULL; /* fresh value */
10199 char *cmd;
10200 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010201 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202
10203 /*
10204 * The options that don't have a default (terminal name, columns, lines)
10205 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010206 * Do the loop over "options[]" twice: once for options with the
10207 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010208 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010209 for (pri = 1; pri >= 0; --pri)
10210 {
10211 for (p = &options[0]; !istermoption(p); p++)
10212 if (!(p->flags & P_NO_MKRC)
10213 && !istermoption(p)
10214 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010215 {
10216 /* skip global option when only doing locals */
10217 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10218 continue;
10219
10220 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10221 * file, they are always buffer-specific. */
10222 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10223 continue;
10224
10225 /* Global values are only written when not at the default value. */
10226 varp = get_varp_scope(p, opt_flags);
10227 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10228 continue;
10229
10230 round = 2;
10231 if (p->indir != PV_NONE)
10232 {
10233 if (p->var == VAR_WIN)
10234 {
10235 /* skip window-local option when only doing globals */
10236 if (!(opt_flags & OPT_LOCAL))
10237 continue;
10238 /* When fresh value of window-local option is not at the
10239 * default, need to write it too. */
10240 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10241 {
10242 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10243 if (!optval_default(p, varp_fresh))
10244 {
10245 round = 1;
10246 varp_local = varp;
10247 varp = varp_fresh;
10248 }
10249 }
10250 }
10251 }
10252
10253 /* Round 1: fresh value for window-local options.
10254 * Round 2: other values */
10255 for ( ; round <= 2; varp = varp_local, ++round)
10256 {
10257 if (round == 1 || (opt_flags & OPT_GLOBAL))
10258 cmd = "set";
10259 else
10260 cmd = "setlocal";
10261
10262 if (p->flags & P_BOOL)
10263 {
10264 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10265 return FAIL;
10266 }
10267 else if (p->flags & P_NUM)
10268 {
10269 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10270 return FAIL;
10271 }
10272 else /* P_STRING */
10273 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010274 int do_endif = FALSE;
10275
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276 /* Don't set 'syntax' and 'filetype' again if the value is
10277 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010278 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010279#if defined(FEAT_SYN_HL)
10280 p->indir == PV_SYN ||
10281#endif
10282 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010283 {
10284 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10285 *(char_u **)(varp)) < 0
10286 || put_eol(fd) < 0)
10287 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010288 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010289 }
10290 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010291 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010292 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010293 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294 {
10295 if (put_line(fd, "endif") == FAIL)
10296 return FAIL;
10297 }
10298 }
10299 }
10300 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010301 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 return OK;
10303}
10304
10305#if defined(FEAT_FOLDING) || defined(PROTO)
10306/*
10307 * Generate set commands for the local fold options only. Used when
10308 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10309 */
10310 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010311makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010312{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010313 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010314# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010315 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010316 == FAIL
10317# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010318 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010320 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321 == FAIL
10322 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10323 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10324 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10325 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10326 )
10327 return FAIL;
10328
10329 return OK;
10330}
10331#endif
10332
10333 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010334put_setstring(
10335 FILE *fd,
10336 char *cmd,
10337 char *name,
10338 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010339 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010340{
10341 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010342 char_u *buf = NULL;
10343 char_u *part = NULL;
10344 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345
10346 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10347 return FAIL;
10348 if (*valuep != NULL)
10349 {
10350 /* Output 'pastetoggle' as key names. For other
10351 * options some characters have to be escaped with
10352 * CTRL-V or backslash */
10353 if (valuep == &p_pt)
10354 {
10355 s = *valuep;
10356 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010357 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010358 return FAIL;
10359 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010360 // expand the option value, replace $HOME by ~
10361 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010362 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010363 int size = (int)STRLEN(*valuep) + 1;
10364
10365 // replace home directory in the whole option value into "buf"
10366 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010367 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010368 goto fail;
10369 home_replace(NULL, *valuep, buf, size, FALSE);
10370
10371 // If the option value is longer than MAXPATHL, we need to append
10372 // earch comma separated part of the option separately, so that it
10373 // can be expanded when read back.
10374 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10375 && vim_strchr(*valuep, ',') != NULL)
10376 {
10377 part = alloc(size);
10378 if (part == NULL)
10379 goto fail;
10380
10381 // write line break to clear the option, e.g. ':set rtp='
10382 if (put_eol(fd) == FAIL)
10383 goto fail;
10384
10385 p = buf;
10386 while (*p != NUL)
10387 {
10388 // for each comma separated option part, append value to
10389 // the option, :set rtp+=value
10390 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10391 goto fail;
10392 (void)copy_option_part(&p, part, size, ",");
10393 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10394 goto fail;
10395 }
10396 vim_free(buf);
10397 vim_free(part);
10398 return OK;
10399 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010400 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010401 {
10402 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010403 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010404 }
10405 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010406 }
10407 else if (put_escstr(fd, *valuep, 2) == FAIL)
10408 return FAIL;
10409 }
10410 if (put_eol(fd) < 0)
10411 return FAIL;
10412 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010413fail:
10414 vim_free(buf);
10415 vim_free(part);
10416 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417}
10418
10419 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010420put_setnum(
10421 FILE *fd,
10422 char *cmd,
10423 char *name,
10424 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010425{
10426 long wc;
10427
10428 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10429 return FAIL;
10430 if (wc_use_keyname((char_u *)valuep, &wc))
10431 {
10432 /* print 'wildchar' and 'wildcharm' as a key name */
10433 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10434 return FAIL;
10435 }
10436 else if (fprintf(fd, "%ld", *valuep) < 0)
10437 return FAIL;
10438 if (put_eol(fd) < 0)
10439 return FAIL;
10440 return OK;
10441}
10442
10443 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010444put_setbool(
10445 FILE *fd,
10446 char *cmd,
10447 char *name,
10448 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010449{
Bram Moolenaar893de922007-10-02 18:40:57 +000010450 if (value < 0) /* global/local option using global value */
10451 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10453 || put_eol(fd) < 0)
10454 return FAIL;
10455 return OK;
10456}
10457
10458/*
10459 * Clear all the terminal options.
10460 * If the option has been allocated, free the memory.
10461 * Terminal options are never hidden or indirect.
10462 */
10463 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010464clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010465{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010466 /*
10467 * Reset a few things before clearing the old options. This may cause
10468 * outputting a few things that the terminal doesn't understand, but the
10469 * screen will be cleared later, so this is OK.
10470 */
10471#ifdef FEAT_MOUSE_TTY
10472 mch_setmouse(FALSE); /* switch mouse off */
10473#endif
10474#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010475 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010476#endif
10477#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10478 /* When starting the GUI close the display opened for the clipboard.
10479 * After restoring the title, because that will need the display. */
10480 if (gui.starting)
10481 clear_xterm_clip();
10482#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010483 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010485 free_termoptions();
10486}
10487
10488 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010489free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010490{
10491 struct vimoption *p;
10492
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010493 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010494 if (istermoption(p))
10495 {
10496 if (p->flags & P_ALLOCED)
10497 free_string_option(*(char_u **)(p->var));
10498 if (p->flags & P_DEF_ALLOCED)
10499 free_string_option(p->def_val[VI_DEFAULT]);
10500 *(char_u **)(p->var) = empty_option;
10501 p->def_val[VI_DEFAULT] = empty_option;
10502 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010503#ifdef FEAT_EVAL
10504 // remember where the option was cleared
10505 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10506#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507 }
10508 clear_termcodes();
10509}
10510
10511/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010512 * Free the string for one term option, if it was allocated.
10513 * Set the string to empty_option and clear allocated flag.
10514 * "var" points to the option value.
10515 */
10516 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010517free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010518{
10519 struct vimoption *p;
10520
10521 for (p = &options[0]; p->fullname != NULL; p++)
10522 if (p->var == var)
10523 {
10524 if (p->flags & P_ALLOCED)
10525 free_string_option(*(char_u **)(p->var));
10526 *(char_u **)(p->var) = empty_option;
10527 p->flags &= ~P_ALLOCED;
10528 break;
10529 }
10530}
10531
10532/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533 * Set the terminal option defaults to the current value.
10534 * Used after setting the terminal name.
10535 */
10536 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010537set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010538{
10539 struct vimoption *p;
10540
10541 for (p = &options[0]; p->fullname != NULL; p++)
10542 {
10543 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10544 {
10545 if (p->flags & P_DEF_ALLOCED)
10546 {
10547 free_string_option(p->def_val[VI_DEFAULT]);
10548 p->flags &= ~P_DEF_ALLOCED;
10549 }
10550 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10551 if (p->flags & P_ALLOCED)
10552 {
10553 p->flags |= P_DEF_ALLOCED;
10554 p->flags &= ~P_ALLOCED; /* don't free the value now */
10555 }
10556 }
10557 }
10558}
10559
10560/*
10561 * return TRUE if 'p' starts with 't_'
10562 */
10563 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010564istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010565{
10566 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10567}
10568
10569/*
10570 * Compute columns for ruler and shown command. 'sc_col' is also used to
10571 * decide what the maximum length of a message on the status line can be.
10572 * If there is a status line for the last window, 'sc_col' is independent
10573 * of 'ru_col'.
10574 */
10575
10576#define COL_RULER 17 /* columns needed by standard ruler */
10577
10578 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010579comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010580{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010581#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010582 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583
10584 sc_col = 0;
10585 ru_col = 0;
10586 if (p_ru)
10587 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010588# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010590# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010592# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593 /* no last status line, adjust sc_col */
10594 if (!last_has_status)
10595 sc_col = ru_col;
10596 }
10597 if (p_sc)
10598 {
10599 sc_col += SHOWCMD_COLS;
10600 if (!p_ru || last_has_status) /* no need for separating space */
10601 ++sc_col;
10602 }
10603 sc_col = Columns - sc_col;
10604 ru_col = Columns - ru_col;
10605 if (sc_col <= 0) /* screen too narrow, will become a mess */
10606 sc_col = 1;
10607 if (ru_col <= 0)
10608 ru_col = 1;
10609#else
10610 sc_col = Columns;
10611 ru_col = Columns;
10612#endif
10613}
10614
Bram Moolenaar113e1072019-01-20 15:30:40 +010010615#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010617 * Unset local option value, similar to ":set opt<".
10618 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010619 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010620unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010621{
10622 struct vimoption *p;
10623 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010624 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010625
10626 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010627 if (opt_idx < 0)
10628 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010629 p = &(options[opt_idx]);
10630
10631 switch ((int)p->indir)
10632 {
10633 /* global option with local value: use local value if it's been set */
10634 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010635 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010636 break;
10637 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010638 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010639 break;
10640 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010641 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010642 break;
10643 case PV_AR:
10644 buf->b_p_ar = -1;
10645 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010646 case PV_BKC:
10647 clear_string_option(&buf->b_p_bkc);
10648 buf->b_bkc_flags = 0;
10649 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010650 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010651 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010652 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010653 case PV_TC:
10654 clear_string_option(&buf->b_p_tc);
10655 buf->b_tc_flags = 0;
10656 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010657#ifdef FEAT_FIND_ID
10658 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010659 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010660 break;
10661 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010662 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010663 break;
10664#endif
10665#ifdef FEAT_INS_EXPAND
10666 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010667 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010668 break;
10669 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010670 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010671 break;
10672#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010673 case PV_FP:
10674 clear_string_option(&buf->b_p_fp);
10675 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010676#ifdef FEAT_QUICKFIX
10677 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010678 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010679 break;
10680 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010681 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010682 break;
10683 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010684 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010685 break;
10686#endif
10687#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10688 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010689 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010690 break;
10691#endif
10692#if defined(FEAT_CRYPT)
10693 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010694 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010695 break;
10696#endif
10697#ifdef FEAT_STL_OPT
10698 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010699 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010700 break;
10701#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010702 case PV_UL:
10703 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10704 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010705#ifdef FEAT_LISP
10706 case PV_LW:
10707 clear_string_option(&buf->b_p_lw);
10708 break;
10709#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010710 case PV_MENC:
10711 clear_string_option(&buf->b_p_menc);
10712 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010713 }
10714}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010715#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010716
10717/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010718 * Get pointer to option variable, depending on local or global scope.
10719 */
10720 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010721get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010722{
10723 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10724 {
10725 if (p->var == VAR_WIN)
10726 return (char_u *)GLOBAL_WO(get_varp(p));
10727 return p->var;
10728 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010729 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 {
10731 switch ((int)p->indir)
10732 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010733 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010734#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010735 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10736 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10737 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010739 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10740 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10741 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010742 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010743 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010744 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010745#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010746 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10747 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748#endif
10749#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010750 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10751 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010753#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10754 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10755#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010756#if defined(FEAT_CRYPT)
10757 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10758#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010759#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010760 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010761#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010762 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010763#ifdef FEAT_LISP
10764 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10765#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010766 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010767 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768 }
10769 return NULL; /* "cannot happen" */
10770 }
10771 return get_varp(p);
10772}
10773
10774/*
10775 * Get pointer to option variable.
10776 */
10777 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010778get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779{
10780 /* hidden option, always return NULL */
10781 if (p->var == NULL)
10782 return NULL;
10783
10784 switch ((int)p->indir)
10785 {
10786 case PV_NONE: return p->var;
10787
10788 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010789 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010790 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010791 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010792 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010793 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010794 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010795 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010796 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010797 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010798 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010799 case PV_TC: return *curbuf->b_p_tc != NUL
10800 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010801 case PV_BKC: return *curbuf->b_p_bkc != NUL
10802 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010803#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010804 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010805 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010806 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010807 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10808#endif
10809#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010810 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010812 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10814#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010815 case PV_FP: return *curbuf->b_p_fp != NUL
10816 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010818 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010820 case PV_GP: return *curbuf->b_p_gp != NUL
10821 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10822 case PV_MP: return *curbuf->b_p_mp != NUL
10823 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010824#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010825#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10826 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10827 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10828#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010829#if defined(FEAT_CRYPT)
10830 case PV_CM: return *curbuf->b_p_cm != NUL
10831 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10832#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010833#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010834 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010835 ? (char_u *)&(curwin->w_p_stl) : p->var;
10836#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010837 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10838 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010839#ifdef FEAT_LISP
10840 case PV_LW: return *curbuf->b_p_lw != NUL
10841 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10842#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010843 case PV_MENC: return *curbuf->b_p_menc != NUL
10844 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845
10846#ifdef FEAT_ARABIC
10847 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10848#endif
10849 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010850#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010851 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10852#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010853#ifdef FEAT_SYN_HL
10854 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10855 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010856 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010857#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858#ifdef FEAT_DIFF
10859 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10860#endif
10861#ifdef FEAT_FOLDING
10862 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10863 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10864 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10865 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10866 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10867 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10868 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10869# ifdef FEAT_EVAL
10870 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10871 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10872# endif
10873 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10874#endif
10875 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010876 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010877#ifdef FEAT_LINEBREAK
10878 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10879#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010880 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010881 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010882#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10884#endif
10885#ifdef FEAT_RIGHTLEFT
10886 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10887 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10888#endif
10889 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10890 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10891#ifdef FEAT_LINEBREAK
10892 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010893 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10894 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010895#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010897 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010898#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010899 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10900 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10901#endif
10902#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010903 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10904 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10905 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010906#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907
10908 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10909 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010910 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010911 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10912 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010913 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10914 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10915#ifdef FEAT_CINDENT
10916 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10917 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10918 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10919#endif
10920#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10921 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10922#endif
10923#ifdef FEAT_COMMENTS
10924 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10925#endif
10926#ifdef FEAT_FOLDING
10927 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10928#endif
10929#ifdef FEAT_INS_EXPAND
10930 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10931#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010932#ifdef FEAT_COMPL_FUNC
10933 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010934 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010935#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010937 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010938 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010942 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010943 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010944 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10945 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10946 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10947 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10948#ifdef FEAT_FIND_ID
10949# ifdef FEAT_EVAL
10950 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10951# endif
10952#endif
10953#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10954 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10955 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10956#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010957#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010958 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10959#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010960#ifdef FEAT_CRYPT
10961 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10962#endif
10963#ifdef FEAT_LISP
10964 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10965#endif
10966 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10967 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10968 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10969 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10970 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010971 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010972#ifdef FEAT_TEXTOBJ
10973 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10974#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010975 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10976#ifdef FEAT_SMARTINDENT
10977 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10978#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010979 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010980 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10981#ifdef FEAT_SEARCHPATH
10982 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10983#endif
10984 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10985#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010986 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010987 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10988#endif
10989#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010990 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10991 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10992 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010993#endif
10994 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10995 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10996 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10997 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010998#ifdef FEAT_PERSISTENT_UNDO
10999 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11000#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011001 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11002#ifdef FEAT_KEYMAP
11003 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11004#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011005#ifdef FEAT_SIGNS
11006 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11007#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011008#ifdef FEAT_VARTABS
11009 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11010 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11011#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011012 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013 }
11014 /* always return a valid pointer to avoid a crash! */
11015 return (char_u *)&(curbuf->b_p_wm);
11016}
11017
11018/*
11019 * Get the value of 'equalprg', either the buffer-local one or the global one.
11020 */
11021 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011022get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011023{
11024 if (*curbuf->b_p_ep == NUL)
11025 return p_ep;
11026 return curbuf->b_p_ep;
11027}
11028
Bram Moolenaar071d4272004-06-13 20:20:40 +000011029/*
11030 * Copy options from one window to another.
11031 * Used when splitting a window.
11032 */
11033 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011034win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035{
11036 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11037 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
11038# ifdef FEAT_RIGHTLEFT
11039# ifdef FEAT_FKMAP
11040 /* Is this right? */
11041 wp_to->w_farsi = wp_from->w_farsi;
11042# endif
11043# endif
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011044#if defined(FEAT_LINEBREAK)
11045 briopt_check(wp_to);
11046#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011047}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011048
11049/*
11050 * Copy the options from one winopt_T to another.
11051 * Doesn't free the old option values in "to", use clear_winopt() for that.
11052 * The 'scroll' option is not copied, because it depends on the window height.
11053 * The 'previewwindow' option is reset, there can be only one preview window.
11054 */
11055 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011056copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011057{
11058#ifdef FEAT_ARABIC
11059 to->wo_arab = from->wo_arab;
11060#endif
11061 to->wo_list = from->wo_list;
11062 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011063 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011064#ifdef FEAT_LINEBREAK
11065 to->wo_nuw = from->wo_nuw;
11066#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011067#ifdef FEAT_RIGHTLEFT
11068 to->wo_rl = from->wo_rl;
11069 to->wo_rlc = vim_strsave(from->wo_rlc);
11070#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011071#ifdef FEAT_STL_OPT
11072 to->wo_stl = vim_strsave(from->wo_stl);
11073#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011075#ifdef FEAT_DIFF
11076 to->wo_wrap_save = from->wo_wrap_save;
11077#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078#ifdef FEAT_LINEBREAK
11079 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011080 to->wo_bri = from->wo_bri;
11081 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011084 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011085 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011086 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011087#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011088 to->wo_spell = from->wo_spell;
11089#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011090#ifdef FEAT_SYN_HL
11091 to->wo_cuc = from->wo_cuc;
11092 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011093 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011094#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011095#ifdef FEAT_DIFF
11096 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011097 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011098#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011099#ifdef FEAT_CONCEAL
11100 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011101 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011102#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011103#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011104 to->wo_twk = vim_strsave(from->wo_twk);
11105 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011106#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011107#ifdef FEAT_FOLDING
11108 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011109 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011110 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011111 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011112 to->wo_fdi = vim_strsave(from->wo_fdi);
11113 to->wo_fml = from->wo_fml;
11114 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011115 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011116 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011117 to->wo_fdm_save = from->wo_diff_saved
11118 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011119 to->wo_fdn = from->wo_fdn;
11120# ifdef FEAT_EVAL
11121 to->wo_fde = vim_strsave(from->wo_fde);
11122 to->wo_fdt = vim_strsave(from->wo_fdt);
11123# endif
11124 to->wo_fmr = vim_strsave(from->wo_fmr);
11125#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011126#ifdef FEAT_SIGNS
11127 to->wo_scl = vim_strsave(from->wo_scl);
11128#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011129 check_winopt(to); /* don't want NULL pointers */
11130}
11131
11132/*
11133 * Check string options in a window for a NULL value.
11134 */
11135 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011136check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011137{
11138 check_winopt(&win->w_onebuf_opt);
11139 check_winopt(&win->w_allbuf_opt);
11140}
11141
11142/*
11143 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11144 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011145 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011146check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147{
11148#ifdef FEAT_FOLDING
11149 check_string_option(&wop->wo_fdi);
11150 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011151 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011152# ifdef FEAT_EVAL
11153 check_string_option(&wop->wo_fde);
11154 check_string_option(&wop->wo_fdt);
11155# endif
11156 check_string_option(&wop->wo_fmr);
11157#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011158#ifdef FEAT_SIGNS
11159 check_string_option(&wop->wo_scl);
11160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011161#ifdef FEAT_RIGHTLEFT
11162 check_string_option(&wop->wo_rlc);
11163#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011164#ifdef FEAT_STL_OPT
11165 check_string_option(&wop->wo_stl);
11166#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011167#ifdef FEAT_SYN_HL
11168 check_string_option(&wop->wo_cc);
11169#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011170#ifdef FEAT_CONCEAL
11171 check_string_option(&wop->wo_cocu);
11172#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011173#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011174 check_string_option(&wop->wo_twk);
11175 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011176#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011177#ifdef FEAT_LINEBREAK
11178 check_string_option(&wop->wo_briopt);
11179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011180}
11181
11182/*
11183 * Free the allocated memory inside a winopt_T.
11184 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011185 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011186clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187{
11188#ifdef FEAT_FOLDING
11189 clear_string_option(&wop->wo_fdi);
11190 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011191 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011192# ifdef FEAT_EVAL
11193 clear_string_option(&wop->wo_fde);
11194 clear_string_option(&wop->wo_fdt);
11195# endif
11196 clear_string_option(&wop->wo_fmr);
11197#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011198#ifdef FEAT_SIGNS
11199 clear_string_option(&wop->wo_scl);
11200#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011201#ifdef FEAT_LINEBREAK
11202 clear_string_option(&wop->wo_briopt);
11203#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011204#ifdef FEAT_RIGHTLEFT
11205 clear_string_option(&wop->wo_rlc);
11206#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011207#ifdef FEAT_STL_OPT
11208 clear_string_option(&wop->wo_stl);
11209#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011210#ifdef FEAT_SYN_HL
11211 clear_string_option(&wop->wo_cc);
11212#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011213#ifdef FEAT_CONCEAL
11214 clear_string_option(&wop->wo_cocu);
11215#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011216#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011217 clear_string_option(&wop->wo_twk);
11218 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011219#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011220}
11221
11222/*
11223 * Copy global option values to local options for one buffer.
11224 * Used when creating a new buffer and sometimes when entering a buffer.
11225 * flags:
11226 * BCO_ENTER We will enter the buf buffer.
11227 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11228 * appropriate.
11229 * BCO_NOHELP Don't copy the values to a help buffer.
11230 */
11231 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011232buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011233{
11234 int should_copy = TRUE;
11235 char_u *save_p_isk = NULL; /* init for GCC */
11236 int dont_do_help;
11237 int did_isk = FALSE;
11238
11239 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011240 * Skip this when the option defaults have not been set yet. Happens when
11241 * main() allocates the first buffer.
11242 */
11243 if (p_cpo != NULL)
11244 {
11245 /*
11246 * Always copy when entering and 'cpo' contains 'S'.
11247 * Don't copy when already initialized.
11248 * Don't copy when 'cpo' contains 's' and not entering.
11249 * 'S' BCO_ENTER initialized 's' should_copy
11250 * yes yes X X TRUE
11251 * yes no yes X FALSE
11252 * no X yes X FALSE
11253 * X no no yes FALSE
11254 * X no no no TRUE
11255 * no yes no X TRUE
11256 */
11257 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11258 && (buf->b_p_initialized
11259 || (!(flags & BCO_ENTER)
11260 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11261 should_copy = FALSE;
11262
11263 if (should_copy || (flags & BCO_ALWAYS))
11264 {
11265 /* Don't copy the options specific to a help buffer when
11266 * BCO_NOHELP is given or the options were initialized already
11267 * (jumping back to a help file with CTRL-T or CTRL-O) */
11268 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11269 || buf->b_p_initialized;
11270 if (dont_do_help) /* don't free b_p_isk */
11271 {
11272 save_p_isk = buf->b_p_isk;
11273 buf->b_p_isk = NULL;
11274 }
11275 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011276 * Always free the allocated strings. If not already initialized,
11277 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278 */
11279 if (!buf->b_p_initialized)
11280 {
11281 free_buf_options(buf, TRUE);
11282 buf->b_p_ro = FALSE; /* don't copy readonly */
11283 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011284 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011285 switch (*p_ffs)
11286 {
11287 case 'm':
11288 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11289 case 'd':
11290 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11291 case 'u':
11292 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11293 default:
11294 buf->b_p_ff = vim_strsave(p_ff);
11295 }
11296 if (buf->b_p_ff != NULL)
11297 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011298 buf->b_p_bh = empty_option;
11299 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011300 }
11301 else
11302 free_buf_options(buf, FALSE);
11303
11304 buf->b_p_ai = p_ai;
11305 buf->b_p_ai_nopaste = p_ai_nopaste;
11306 buf->b_p_sw = p_sw;
11307 buf->b_p_tw = p_tw;
11308 buf->b_p_tw_nopaste = p_tw_nopaste;
11309 buf->b_p_tw_nobin = p_tw_nobin;
11310 buf->b_p_wm = p_wm;
11311 buf->b_p_wm_nopaste = p_wm_nopaste;
11312 buf->b_p_wm_nobin = p_wm_nobin;
11313 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011314 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011315 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316 buf->b_p_et = p_et;
11317 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011318 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319 buf->b_p_ml = p_ml;
11320 buf->b_p_ml_nobin = p_ml_nobin;
11321 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011322 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323#ifdef FEAT_INS_EXPAND
11324 buf->b_p_cpt = vim_strsave(p_cpt);
11325#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011326#ifdef FEAT_COMPL_FUNC
11327 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011328 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011330 buf->b_p_sts = p_sts;
11331 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011332#ifdef FEAT_VARTABS
11333 buf->b_p_vsts = vim_strsave(p_vsts);
11334 if (p_vsts && p_vsts != empty_option)
11335 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11336 else
11337 buf->b_p_vsts_array = 0;
11338 buf->b_p_vsts_nopaste = p_vsts_nopaste
11339 ? vim_strsave(p_vsts_nopaste) : NULL;
11340#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011341 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342#ifdef FEAT_COMMENTS
11343 buf->b_p_com = vim_strsave(p_com);
11344#endif
11345#ifdef FEAT_FOLDING
11346 buf->b_p_cms = vim_strsave(p_cms);
11347#endif
11348 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011349 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350 buf->b_p_nf = vim_strsave(p_nf);
11351 buf->b_p_mps = vim_strsave(p_mps);
11352#ifdef FEAT_SMARTINDENT
11353 buf->b_p_si = p_si;
11354#endif
11355 buf->b_p_ci = p_ci;
11356#ifdef FEAT_CINDENT
11357 buf->b_p_cin = p_cin;
11358 buf->b_p_cink = vim_strsave(p_cink);
11359 buf->b_p_cino = vim_strsave(p_cino);
11360#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011361 /* Don't copy 'filetype', it must be detected */
11362 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011363 buf->b_p_pi = p_pi;
11364#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11365 buf->b_p_cinw = vim_strsave(p_cinw);
11366#endif
11367#ifdef FEAT_LISP
11368 buf->b_p_lisp = p_lisp;
11369#endif
11370#ifdef FEAT_SYN_HL
11371 /* Don't copy 'syntax', it must be set */
11372 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011373 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011374 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011375#endif
11376#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011377 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011378 (void)compile_cap_prog(&buf->b_s);
11379 buf->b_s.b_p_spf = vim_strsave(p_spf);
11380 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011381#endif
11382#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11383 buf->b_p_inde = vim_strsave(p_inde);
11384 buf->b_p_indk = vim_strsave(p_indk);
11385#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011386 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011387#if defined(FEAT_EVAL)
11388 buf->b_p_fex = vim_strsave(p_fex);
11389#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011390#ifdef FEAT_CRYPT
11391 buf->b_p_key = vim_strsave(p_key);
11392#endif
11393#ifdef FEAT_SEARCHPATH
11394 buf->b_p_sua = vim_strsave(p_sua);
11395#endif
11396#ifdef FEAT_KEYMAP
11397 buf->b_p_keymap = vim_strsave(p_keymap);
11398 buf->b_kmap_state |= KEYMAP_INIT;
11399#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011400#ifdef FEAT_TERMINAL
11401 buf->b_p_twsl = p_twsl;
11402#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011403 /* This isn't really an option, but copying the langmap and IME
11404 * state from the current buffer is better than resetting it. */
11405 buf->b_p_iminsert = p_iminsert;
11406 buf->b_p_imsearch = p_imsearch;
11407
11408 /* options that are normally global but also have a local value
11409 * are not copied, start using the global value */
11410 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011411 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011412 buf->b_p_bkc = empty_option;
11413 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011414#ifdef FEAT_QUICKFIX
11415 buf->b_p_gp = empty_option;
11416 buf->b_p_mp = empty_option;
11417 buf->b_p_efm = empty_option;
11418#endif
11419 buf->b_p_ep = empty_option;
11420 buf->b_p_kp = empty_option;
11421 buf->b_p_path = empty_option;
11422 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011423 buf->b_p_tc = empty_option;
11424 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011425#ifdef FEAT_FIND_ID
11426 buf->b_p_def = empty_option;
11427 buf->b_p_inc = empty_option;
11428# ifdef FEAT_EVAL
11429 buf->b_p_inex = vim_strsave(p_inex);
11430# endif
11431#endif
11432#ifdef FEAT_INS_EXPAND
11433 buf->b_p_dict = empty_option;
11434 buf->b_p_tsr = empty_option;
11435#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011436#ifdef FEAT_TEXTOBJ
11437 buf->b_p_qe = vim_strsave(p_qe);
11438#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011439#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11440 buf->b_p_bexpr = empty_option;
11441#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011442#if defined(FEAT_CRYPT)
11443 buf->b_p_cm = empty_option;
11444#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011445#ifdef FEAT_PERSISTENT_UNDO
11446 buf->b_p_udf = p_udf;
11447#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011448#ifdef FEAT_LISP
11449 buf->b_p_lw = empty_option;
11450#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011451 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011452
11453 /*
11454 * Don't copy the options set by ex_help(), use the saved values,
11455 * when going from a help buffer to a non-help buffer.
11456 * Don't touch these at all when BCO_NOHELP is used and going from
11457 * or to a help buffer.
11458 */
11459 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011460 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011461 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011462#ifdef FEAT_VARTABS
11463 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11464 tabstop_set(p_vts, &buf->b_p_vts_array);
11465 else
11466 buf->b_p_vts_array = NULL;
11467#endif
11468 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011469 else
11470 {
11471 buf->b_p_isk = vim_strsave(p_isk);
11472 did_isk = TRUE;
11473 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011474#ifdef FEAT_VARTABS
11475 buf->b_p_vts = vim_strsave(p_vts);
11476 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11477 tabstop_set(p_vts, &buf->b_p_vts_array);
11478 else
11479 buf->b_p_vts_array = NULL;
11480#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011481 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011482 if (buf->b_p_bt[0] == 'h')
11483 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484 buf->b_p_ma = p_ma;
11485 }
11486 }
11487
11488 /*
11489 * When the options should be copied (ignoring BCO_ALWAYS), set the
11490 * flag that indicates that the options have been initialized.
11491 */
11492 if (should_copy)
11493 buf->b_p_initialized = TRUE;
11494 }
11495
11496 check_buf_options(buf); /* make sure we don't have NULLs */
11497 if (did_isk)
11498 (void)buf_init_chartab(buf, FALSE);
11499}
11500
11501/*
11502 * Reset the 'modifiable' option and its default value.
11503 */
11504 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011505reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011506{
11507 int opt_idx;
11508
11509 curbuf->b_p_ma = FALSE;
11510 p_ma = FALSE;
11511 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011512 if (opt_idx >= 0)
11513 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011514}
11515
11516/*
11517 * Set the global value for 'iminsert' to the local value.
11518 */
11519 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011520set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011521{
11522 p_iminsert = curbuf->b_p_iminsert;
11523}
11524
11525/*
11526 * Set the global value for 'imsearch' to the local value.
11527 */
11528 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011529set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011530{
11531 p_imsearch = curbuf->b_p_imsearch;
11532}
11533
11534#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11535static int expand_option_idx = -1;
11536static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11537static int expand_option_flags = 0;
11538
11539 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011540set_context_in_set_cmd(
11541 expand_T *xp,
11542 char_u *arg,
11543 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011544{
11545 int nextchar;
11546 long_u flags = 0; /* init for GCC */
11547 int opt_idx = 0; /* init for GCC */
11548 char_u *p;
11549 char_u *s;
11550 int is_term_option = FALSE;
11551 int key;
11552
11553 expand_option_flags = opt_flags;
11554
11555 xp->xp_context = EXPAND_SETTINGS;
11556 if (*arg == NUL)
11557 {
11558 xp->xp_pattern = arg;
11559 return;
11560 }
11561 p = arg + STRLEN(arg) - 1;
11562 if (*p == ' ' && *(p - 1) != '\\')
11563 {
11564 xp->xp_pattern = p + 1;
11565 return;
11566 }
11567 while (p > arg)
11568 {
11569 s = p;
11570 /* count number of backslashes before ' ' or ',' */
11571 if (*p == ' ' || *p == ',')
11572 {
11573 while (s > arg && *(s - 1) == '\\')
11574 --s;
11575 }
11576 /* break at a space with an even number of backslashes */
11577 if (*p == ' ' && ((p - s) & 1) == 0)
11578 {
11579 ++p;
11580 break;
11581 }
11582 --p;
11583 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011584 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011585 {
11586 xp->xp_context = EXPAND_BOOL_SETTINGS;
11587 p += 2;
11588 }
11589 if (STRNCMP(p, "inv", 3) == 0)
11590 {
11591 xp->xp_context = EXPAND_BOOL_SETTINGS;
11592 p += 3;
11593 }
11594 xp->xp_pattern = arg = p;
11595 if (*arg == '<')
11596 {
11597 while (*p != '>')
11598 if (*p++ == NUL) /* expand terminal option name */
11599 return;
11600 key = get_special_key_code(arg + 1);
11601 if (key == 0) /* unknown name */
11602 {
11603 xp->xp_context = EXPAND_NOTHING;
11604 return;
11605 }
11606 nextchar = *++p;
11607 is_term_option = TRUE;
11608 expand_option_name[2] = KEY2TERMCAP0(key);
11609 expand_option_name[3] = KEY2TERMCAP1(key);
11610 }
11611 else
11612 {
11613 if (p[0] == 't' && p[1] == '_')
11614 {
11615 p += 2;
11616 if (*p != NUL)
11617 ++p;
11618 if (*p == NUL)
11619 return; /* expand option name */
11620 nextchar = *++p;
11621 is_term_option = TRUE;
11622 expand_option_name[2] = p[-2];
11623 expand_option_name[3] = p[-1];
11624 }
11625 else
11626 {
11627 /* Allow * wildcard */
11628 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11629 p++;
11630 if (*p == NUL)
11631 return;
11632 nextchar = *p;
11633 *p = NUL;
11634 opt_idx = findoption(arg);
11635 *p = nextchar;
11636 if (opt_idx == -1 || options[opt_idx].var == NULL)
11637 {
11638 xp->xp_context = EXPAND_NOTHING;
11639 return;
11640 }
11641 flags = options[opt_idx].flags;
11642 if (flags & P_BOOL)
11643 {
11644 xp->xp_context = EXPAND_NOTHING;
11645 return;
11646 }
11647 }
11648 }
11649 /* handle "-=" and "+=" */
11650 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11651 {
11652 ++p;
11653 nextchar = '=';
11654 }
11655 if ((nextchar != '=' && nextchar != ':')
11656 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11657 {
11658 xp->xp_context = EXPAND_UNSUCCESSFUL;
11659 return;
11660 }
11661 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11662 {
11663 xp->xp_context = EXPAND_OLD_SETTING;
11664 if (is_term_option)
11665 expand_option_idx = -1;
11666 else
11667 expand_option_idx = opt_idx;
11668 xp->xp_pattern = p + 1;
11669 return;
11670 }
11671 xp->xp_context = EXPAND_NOTHING;
11672 if (is_term_option || (flags & P_NUM))
11673 return;
11674
11675 xp->xp_pattern = p + 1;
11676
11677 if (flags & P_EXPAND)
11678 {
11679 p = options[opt_idx].var;
11680 if (p == (char_u *)&p_bdir
11681 || p == (char_u *)&p_dir
11682 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011683 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011684 || p == (char_u *)&p_rtp
11685#ifdef FEAT_SEARCHPATH
11686 || p == (char_u *)&p_cdpath
11687#endif
11688#ifdef FEAT_SESSION
11689 || p == (char_u *)&p_vdir
11690#endif
11691 )
11692 {
11693 xp->xp_context = EXPAND_DIRECTORIES;
11694 if (p == (char_u *)&p_path
11695#ifdef FEAT_SEARCHPATH
11696 || p == (char_u *)&p_cdpath
11697#endif
11698 )
11699 xp->xp_backslash = XP_BS_THREE;
11700 else
11701 xp->xp_backslash = XP_BS_ONE;
11702 }
11703 else
11704 {
11705 xp->xp_context = EXPAND_FILES;
11706 /* for 'tags' need three backslashes for a space */
11707 if (p == (char_u *)&p_tags)
11708 xp->xp_backslash = XP_BS_THREE;
11709 else
11710 xp->xp_backslash = XP_BS_ONE;
11711 }
11712 }
11713
11714 /* For an option that is a list of file names, find the start of the
11715 * last file name. */
11716 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11717 {
11718 /* count number of backslashes before ' ' or ',' */
11719 if (*p == ' ' || *p == ',')
11720 {
11721 s = p;
11722 while (s > xp->xp_pattern && *(s - 1) == '\\')
11723 --s;
11724 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11725 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11726 {
11727 xp->xp_pattern = p + 1;
11728 break;
11729 }
11730 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011731
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011732#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011733 /* for 'spellsuggest' start at "file:" */
11734 if (options[opt_idx].var == (char_u *)&p_sps
11735 && STRNCMP(p, "file:", 5) == 0)
11736 {
11737 xp->xp_pattern = p + 5;
11738 break;
11739 }
11740#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741 }
11742
11743 return;
11744}
11745
11746 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011747ExpandSettings(
11748 expand_T *xp,
11749 regmatch_T *regmatch,
11750 int *num_file,
11751 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011752{
11753 int num_normal = 0; /* Nr of matching non-term-code settings */
11754 int num_term = 0; /* Nr of matching terminal code settings */
11755 int opt_idx;
11756 int match;
11757 int count = 0;
11758 char_u *str;
11759 int loop;
11760 int is_term_opt;
11761 char_u name_buf[MAX_KEY_NAME_LEN];
11762 static char *(names[]) = {"all", "termcap"};
11763 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11764
11765 /* do this loop twice:
11766 * loop == 0: count the number of matching options
11767 * loop == 1: copy the matching options into allocated memory
11768 */
11769 for (loop = 0; loop <= 1; ++loop)
11770 {
11771 regmatch->rm_ic = ic;
11772 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11773 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011774 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11775 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11777 {
11778 if (loop == 0)
11779 num_normal++;
11780 else
11781 (*file)[count++] = vim_strsave((char_u *)names[match]);
11782 }
11783 }
11784 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11785 opt_idx++)
11786 {
11787 if (options[opt_idx].var == NULL)
11788 continue;
11789 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11790 && !(options[opt_idx].flags & P_BOOL))
11791 continue;
11792 is_term_opt = istermoption(&options[opt_idx]);
11793 if (is_term_opt && num_normal > 0)
11794 continue;
11795 match = FALSE;
11796 if (vim_regexec(regmatch, str, (colnr_T)0)
11797 || (options[opt_idx].shortname != NULL
11798 && vim_regexec(regmatch,
11799 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11800 match = TRUE;
11801 else if (is_term_opt)
11802 {
11803 name_buf[0] = '<';
11804 name_buf[1] = 't';
11805 name_buf[2] = '_';
11806 name_buf[3] = str[2];
11807 name_buf[4] = str[3];
11808 name_buf[5] = '>';
11809 name_buf[6] = NUL;
11810 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11811 {
11812 match = TRUE;
11813 str = name_buf;
11814 }
11815 }
11816 if (match)
11817 {
11818 if (loop == 0)
11819 {
11820 if (is_term_opt)
11821 num_term++;
11822 else
11823 num_normal++;
11824 }
11825 else
11826 (*file)[count++] = vim_strsave(str);
11827 }
11828 }
11829 /*
11830 * Check terminal key codes, these are not in the option table
11831 */
11832 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11833 {
11834 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11835 {
11836 if (!isprint(str[0]) || !isprint(str[1]))
11837 continue;
11838
11839 name_buf[0] = 't';
11840 name_buf[1] = '_';
11841 name_buf[2] = str[0];
11842 name_buf[3] = str[1];
11843 name_buf[4] = NUL;
11844
11845 match = FALSE;
11846 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11847 match = TRUE;
11848 else
11849 {
11850 name_buf[0] = '<';
11851 name_buf[1] = 't';
11852 name_buf[2] = '_';
11853 name_buf[3] = str[0];
11854 name_buf[4] = str[1];
11855 name_buf[5] = '>';
11856 name_buf[6] = NUL;
11857
11858 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11859 match = TRUE;
11860 }
11861 if (match)
11862 {
11863 if (loop == 0)
11864 num_term++;
11865 else
11866 (*file)[count++] = vim_strsave(name_buf);
11867 }
11868 }
11869
11870 /*
11871 * Check special key names.
11872 */
11873 regmatch->rm_ic = TRUE; /* ignore case here */
11874 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11875 {
11876 name_buf[0] = '<';
11877 STRCPY(name_buf + 1, str);
11878 STRCAT(name_buf, ">");
11879
11880 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11881 {
11882 if (loop == 0)
11883 num_term++;
11884 else
11885 (*file)[count++] = vim_strsave(name_buf);
11886 }
11887 }
11888 }
11889 if (loop == 0)
11890 {
11891 if (num_normal > 0)
11892 *num_file = num_normal;
11893 else if (num_term > 0)
11894 *num_file = num_term;
11895 else
11896 return OK;
11897 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11898 if (*file == NULL)
11899 {
11900 *file = (char_u **)"";
11901 return FAIL;
11902 }
11903 }
11904 }
11905 return OK;
11906}
11907
11908 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011909ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011910{
11911 char_u *var = NULL; /* init for GCC */
11912 char_u *buf;
11913
11914 *num_file = 0;
11915 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11916 if (*file == NULL)
11917 return FAIL;
11918
11919 /*
11920 * For a terminal key code expand_option_idx is < 0.
11921 */
11922 if (expand_option_idx < 0)
11923 {
11924 var = find_termcode(expand_option_name + 2);
11925 if (var == NULL)
11926 expand_option_idx = findoption(expand_option_name);
11927 }
11928
11929 if (expand_option_idx >= 0)
11930 {
11931 /* put string of option value in NameBuff */
11932 option_value2string(&options[expand_option_idx], expand_option_flags);
11933 var = NameBuff;
11934 }
11935 else if (var == NULL)
11936 var = (char_u *)"";
11937
11938 /* A backslash is required before some characters. This is the reverse of
11939 * what happens in do_set(). */
11940 buf = vim_strsave_escaped(var, escape_chars);
11941
11942 if (buf == NULL)
11943 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011944 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011945 return FAIL;
11946 }
11947
11948#ifdef BACKSLASH_IN_FILENAME
11949 /* For MS-Windows et al. we don't double backslashes at the start and
11950 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011951 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011952 if (var[0] == '\\' && var[1] == '\\'
11953 && expand_option_idx >= 0
11954 && (options[expand_option_idx].flags & P_EXPAND)
11955 && vim_isfilec(var[2])
11956 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011957 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011958#endif
11959
11960 *file[0] = buf;
11961 *num_file = 1;
11962 return OK;
11963}
11964#endif
11965
11966/*
11967 * Get the value for the numeric or string option *opp in a nice format into
11968 * NameBuff[]. Must not be called with a hidden option!
11969 */
11970 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011971option_value2string(
11972 struct vimoption *opp,
11973 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011974{
11975 char_u *varp;
11976
11977 varp = get_varp_scope(opp, opt_flags);
11978
11979 if (opp->flags & P_NUM)
11980 {
11981 long wc = 0;
11982
11983 if (wc_use_keyname(varp, &wc))
11984 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11985 else if (wc != 0)
11986 STRCPY(NameBuff, transchar((int)wc));
11987 else
11988 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11989 }
11990 else /* P_STRING */
11991 {
11992 varp = *(char_u **)(varp);
11993 if (varp == NULL) /* just in case */
11994 NameBuff[0] = NUL;
11995#ifdef FEAT_CRYPT
11996 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011997 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011998 STRCPY(NameBuff, "*****");
11999#endif
12000 else if (opp->flags & P_EXPAND)
12001 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12002 /* Translate 'pastetoggle' into special key names */
12003 else if ((char_u **)opp->var == &p_pt)
12004 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12005 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012006 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012007 }
12008}
12009
12010/*
12011 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12012 * printed as a keyname.
12013 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12014 */
12015 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012016wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012017{
12018 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12019 {
12020 *wcp = *(long *)varp;
12021 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12022 return TRUE;
12023 }
12024 return FALSE;
12025}
12026
Bram Moolenaar01615492015-02-03 13:00:38 +010012027#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012028/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012029 * Any character has an equivalent 'langmap' character. This is used for
12030 * keyboards that have a special language mode that sends characters above
12031 * 128 (although other characters can be translated too). The "to" field is a
12032 * Vim command character. This avoids having to switch the keyboard back to
12033 * ASCII mode when leaving Insert mode.
12034 *
12035 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12036 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012037 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12038 * same as langmap_mapchar[] for characters >= 256.
12039 *
12040 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012041 */
12042typedef struct
12043{
12044 int from;
12045 int to;
12046} langmap_entry_T;
12047
12048static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012049
12050/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012051 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12052 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012053 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012054 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012055langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012056{
12057 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012058 int a = 0;
12059 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012060
12061 /* Do a binary search for an existing entry. */
12062 while (a != b)
12063 {
12064 int i = (a + b) / 2;
12065 int d = entries[i].from - from;
12066
12067 if (d == 0)
12068 {
12069 entries[i].to = to;
12070 return;
12071 }
12072 if (d < 0)
12073 a = i + 1;
12074 else
12075 b = i;
12076 }
12077
12078 if (ga_grow(&langmap_mapga, 1) != OK)
12079 return; /* out of memory */
12080
12081 /* insert new entry at position "a" */
12082 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12083 mch_memmove(entries + 1, entries,
12084 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12085 ++langmap_mapga.ga_len;
12086 entries[0].from = from;
12087 entries[0].to = to;
12088}
12089
12090/*
12091 * Apply 'langmap' to multi-byte character "c" and return the result.
12092 */
12093 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012094langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012095{
12096 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12097 int a = 0;
12098 int b = langmap_mapga.ga_len;
12099
12100 while (a != b)
12101 {
12102 int i = (a + b) / 2;
12103 int d = entries[i].from - c;
12104
12105 if (d == 0)
12106 return entries[i].to; /* found matching entry */
12107 if (d < 0)
12108 a = i + 1;
12109 else
12110 b = i;
12111 }
12112 return c; /* no entry found, return "c" unmodified */
12113}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012114
12115 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012116langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012117{
12118 int i;
12119
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012120 for (i = 0; i < 256; i++)
12121 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012122 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012123}
12124
12125/*
12126 * Called when langmap option is set; the language map can be
12127 * changed at any time!
12128 */
12129 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012130langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012131{
12132 char_u *p;
12133 char_u *p2;
12134 int from, to;
12135
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012136 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012137 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012138
12139 for (p = p_langmap; p[0] != NUL; )
12140 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012141 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012142 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012143 {
12144 if (p2[0] == '\\' && p2[1] != NUL)
12145 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146 }
12147 if (p2[0] == ';')
12148 ++p2; /* abcd;ABCD form, p2 points to A */
12149 else
12150 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12151 while (p[0])
12152 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012153 if (p[0] == ',')
12154 {
12155 ++p;
12156 break;
12157 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012158 if (p[0] == '\\' && p[1] != NUL)
12159 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012160 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012161 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012162 if (p2 == NULL)
12163 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012164 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012165 if (p[0] != ',')
12166 {
12167 if (p[0] == '\\')
12168 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012169 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012171 }
12172 else
12173 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012174 if (p2[0] != ',')
12175 {
12176 if (p2[0] == '\\')
12177 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012178 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012180 }
12181 if (to == NUL)
12182 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012183 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012184 transchar(from));
12185 return;
12186 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012187
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012188 if (from >= 256)
12189 langmap_set_entry(from, to);
12190 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012191 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012192
12193 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012194 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012195 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012196 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012197 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012198 if (*p == ';')
12199 {
12200 p = p2;
12201 if (p[0] != NUL)
12202 {
12203 if (p[0] != ',')
12204 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012205 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012206 return;
12207 }
12208 ++p;
12209 }
12210 break;
12211 }
12212 }
12213 }
12214 }
12215}
12216#endif
12217
12218/*
12219 * Return TRUE if format option 'x' is in effect.
12220 * Take care of no formatting when 'paste' is set.
12221 */
12222 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012223has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012224{
12225 if (p_paste)
12226 return FALSE;
12227 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12228}
12229
12230/*
12231 * Return TRUE if "x" is present in 'shortmess' option, or
12232 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12233 */
12234 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012235shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012237 return p_shm != NULL &&
12238 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012239 || (vim_strchr(p_shm, 'a') != NULL
12240 && vim_strchr((char_u *)SHM_A, x) != NULL));
12241}
12242
12243/*
12244 * paste_option_changed() - Called after p_paste was set or reset.
12245 */
12246 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012247paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012248{
12249 static int old_p_paste = FALSE;
12250 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012251 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012252#ifdef FEAT_CMDL_INFO
12253 static int save_ru = 0;
12254#endif
12255#ifdef FEAT_RIGHTLEFT
12256 static int save_ri = 0;
12257 static int save_hkmap = 0;
12258#endif
12259 buf_T *buf;
12260
12261 if (p_paste)
12262 {
12263 /*
12264 * Paste switched from off to on.
12265 * Save the current values, so they can be restored later.
12266 */
12267 if (!old_p_paste)
12268 {
12269 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012270 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012271 {
12272 buf->b_p_tw_nopaste = buf->b_p_tw;
12273 buf->b_p_wm_nopaste = buf->b_p_wm;
12274 buf->b_p_sts_nopaste = buf->b_p_sts;
12275 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012276 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012277#ifdef FEAT_VARTABS
12278 if (buf->b_p_vsts_nopaste)
12279 vim_free(buf->b_p_vsts_nopaste);
12280 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12281 ? vim_strsave(buf->b_p_vsts) : NULL;
12282#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012283 }
12284
12285 /* save global options */
12286 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012287 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288#ifdef FEAT_CMDL_INFO
12289 save_ru = p_ru;
12290#endif
12291#ifdef FEAT_RIGHTLEFT
12292 save_ri = p_ri;
12293 save_hkmap = p_hkmap;
12294#endif
12295 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012296 p_ai_nopaste = p_ai;
12297 p_et_nopaste = p_et;
12298 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012299 p_tw_nopaste = p_tw;
12300 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012301#ifdef FEAT_VARTABS
12302 if (p_vsts_nopaste)
12303 vim_free(p_vsts_nopaste);
12304 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12305#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306 }
12307
12308 /*
12309 * Always set the option values, also when 'paste' is set when it is
12310 * already on.
12311 */
12312 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012313 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012314 {
12315 buf->b_p_tw = 0; /* textwidth is 0 */
12316 buf->b_p_wm = 0; /* wrapmargin is 0 */
12317 buf->b_p_sts = 0; /* softtabstop is 0 */
12318 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012319 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012320#ifdef FEAT_VARTABS
12321 if (buf->b_p_vsts)
12322 free_string_option(buf->b_p_vsts);
12323 buf->b_p_vsts = empty_option;
12324 if (buf->b_p_vsts_array)
12325 vim_free(buf->b_p_vsts_array);
12326 buf->b_p_vsts_array = 0;
12327#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012328 }
12329
12330 /* set global options */
12331 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012332 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012333#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012334 if (p_ru)
12335 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012336 p_ru = 0; /* no ruler */
12337#endif
12338#ifdef FEAT_RIGHTLEFT
12339 p_ri = 0; /* no reverse insert */
12340 p_hkmap = 0; /* no Hebrew keyboard */
12341#endif
12342 /* set global values for local buffer options */
12343 p_tw = 0;
12344 p_wm = 0;
12345 p_sts = 0;
12346 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012347#ifdef FEAT_VARTABS
12348 if (p_vsts)
12349 free_string_option(p_vsts);
12350 p_vsts = empty_option;
12351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012352 }
12353
12354 /*
12355 * Paste switched from on to off: Restore saved values.
12356 */
12357 else if (old_p_paste)
12358 {
12359 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012360 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012361 {
12362 buf->b_p_tw = buf->b_p_tw_nopaste;
12363 buf->b_p_wm = buf->b_p_wm_nopaste;
12364 buf->b_p_sts = buf->b_p_sts_nopaste;
12365 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012366 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012367#ifdef FEAT_VARTABS
12368 if (buf->b_p_vsts)
12369 free_string_option(buf->b_p_vsts);
12370 buf->b_p_vsts = buf->b_p_vsts_nopaste
12371 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12372 if (buf->b_p_vsts_array)
12373 vim_free(buf->b_p_vsts_array);
12374 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12375 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12376 else
12377 buf->b_p_vsts_array = 0;
12378#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012379 }
12380
12381 /* restore global options */
12382 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012383 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012384#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012385 if (p_ru != save_ru)
12386 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012387 p_ru = save_ru;
12388#endif
12389#ifdef FEAT_RIGHTLEFT
12390 p_ri = save_ri;
12391 p_hkmap = save_hkmap;
12392#endif
12393 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012394 p_ai = p_ai_nopaste;
12395 p_et = p_et_nopaste;
12396 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012397 p_tw = p_tw_nopaste;
12398 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012399#ifdef FEAT_VARTABS
12400 if (p_vsts)
12401 free_string_option(p_vsts);
12402 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012404 }
12405
12406 old_p_paste = p_paste;
12407}
12408
12409/*
12410 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12411 *
12412 * Reset 'compatible' and set the values for options that didn't get set yet
12413 * to the Vim defaults.
12414 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012415 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012416 */
12417 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012418vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012419{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012420 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012421 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012422 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012423
12424 if (!option_was_set((char_u *)"cp"))
12425 {
12426 p_cp = FALSE;
12427 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12428 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12429 set_option_default(opt_idx, OPT_FREE, FALSE);
12430 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012431 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012432 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012433
12434 if (fname != NULL)
12435 {
12436 p = vim_getenv(envname, &dofree);
12437 if (p == NULL)
12438 {
12439 /* Set $MYVIMRC to the first vimrc file found. */
12440 p = FullName_save(fname, FALSE);
12441 if (p != NULL)
12442 {
12443 vim_setenv(envname, p);
12444 vim_free(p);
12445 }
12446 }
12447 else if (dofree)
12448 vim_free(p);
12449 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012450}
12451
12452/*
12453 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12454 */
12455 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012456change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012457{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012458 int opt_idx;
12459
Bram Moolenaar071d4272004-06-13 20:20:40 +000012460 if (p_cp != on)
12461 {
12462 p_cp = on;
12463 compatible_set();
12464 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012465 opt_idx = findoption((char_u *)"cp");
12466 if (opt_idx >= 0)
12467 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012468}
12469
12470/*
12471 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012472 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012473 */
12474 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012475option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012476{
12477 int idx;
12478
12479 idx = findoption(name);
12480 if (idx < 0) /* unknown option */
12481 return FALSE;
12482 if (options[idx].flags & P_WAS_SET)
12483 return TRUE;
12484 return FALSE;
12485}
12486
12487/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012488 * Reset the flag indicating option "name" was set.
12489 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012490 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012491reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012492{
12493 int idx = findoption(name);
12494
12495 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012496 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012497 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012498 return OK;
12499 }
12500 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012501}
12502
12503/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012504 * compatible_set() - Called when 'compatible' has been set or unset.
12505 *
12506 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12507 * flag) to a Vi compatible value.
12508 * When 'compatible' is unset: Set all options that have a different default
12509 * for Vim (without the P_VI_DEF flag) to that default.
12510 */
12511 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012512compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012513{
12514 int opt_idx;
12515
12516 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12517 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12518 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12519 set_option_default(opt_idx, OPT_FREE, p_cp);
12520 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012521 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012522}
12523
12524#ifdef FEAT_LINEBREAK
12525
12526# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12527 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012528 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012529# endif
12530
12531/*
12532 * fill_breakat_flags() -- called when 'breakat' changes value.
12533 */
12534 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012535fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012536{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012537 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012538 int i;
12539
12540 for (i = 0; i < 256; i++)
12541 breakat_flags[i] = FALSE;
12542
12543 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012544 for (p = p_breakat; *p; p++)
12545 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012546}
12547
12548# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012549 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012550# endif
12551
12552#endif
12553
12554/*
12555 * Check an option that can be a range of string values.
12556 *
12557 * Return OK for correct value, FAIL otherwise.
12558 * Empty is always OK.
12559 */
12560 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012561check_opt_strings(
12562 char_u *val,
12563 char **values,
12564 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012565{
12566 return opt_strings_flags(val, values, NULL, list);
12567}
12568
12569/*
12570 * Handle an option that can be a range of string values.
12571 * Set a flag in "*flagp" for each string present.
12572 *
12573 * Return OK for correct value, FAIL otherwise.
12574 * Empty is always OK.
12575 */
12576 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012577opt_strings_flags(
12578 char_u *val, /* new value */
12579 char **values, /* array of valid string values */
12580 unsigned *flagp,
12581 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012582{
12583 int i;
12584 int len;
12585 unsigned new_flags = 0;
12586
12587 while (*val)
12588 {
12589 for (i = 0; ; ++i)
12590 {
12591 if (values[i] == NULL) /* val not found in values[] */
12592 return FAIL;
12593
12594 len = (int)STRLEN(values[i]);
12595 if (STRNCMP(values[i], val, len) == 0
12596 && ((list && val[len] == ',') || val[len] == NUL))
12597 {
12598 val += len + (val[len] == ',');
12599 new_flags |= (1 << i);
12600 break; /* check next item in val list */
12601 }
12602 }
12603 }
12604 if (flagp != NULL)
12605 *flagp = new_flags;
12606
12607 return OK;
12608}
12609
12610/*
12611 * Read the 'wildmode' option, fill wim_flags[].
12612 */
12613 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012614check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012615{
12616 char_u new_wim_flags[4];
12617 char_u *p;
12618 int i;
12619 int idx = 0;
12620
12621 for (i = 0; i < 4; ++i)
12622 new_wim_flags[i] = 0;
12623
12624 for (p = p_wim; *p; ++p)
12625 {
12626 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12627 ;
12628 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12629 return FAIL;
12630 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12631 new_wim_flags[idx] |= WIM_LONGEST;
12632 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12633 new_wim_flags[idx] |= WIM_FULL;
12634 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12635 new_wim_flags[idx] |= WIM_LIST;
12636 else
12637 return FAIL;
12638 p += i;
12639 if (*p == NUL)
12640 break;
12641 if (*p == ',')
12642 {
12643 if (idx == 3)
12644 return FAIL;
12645 ++idx;
12646 }
12647 }
12648
12649 /* fill remaining entries with last flag */
12650 while (idx < 3)
12651 {
12652 new_wim_flags[idx + 1] = new_wim_flags[idx];
12653 ++idx;
12654 }
12655
12656 /* only when there are no errors, wim_flags[] is changed */
12657 for (i = 0; i < 4; ++i)
12658 wim_flags[i] = new_wim_flags[i];
12659 return OK;
12660}
12661
12662/*
12663 * Check if backspacing over something is allowed.
12664 */
12665 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012666can_bs(
12667 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012668{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012669#ifdef FEAT_JOB_CHANNEL
12670 if (what == BS_START && bt_prompt(curbuf))
12671 return FALSE;
12672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012673 switch (*p_bs)
12674 {
12675 case '2': return TRUE;
12676 case '1': return (what != BS_START);
12677 case '0': return FALSE;
12678 }
12679 return vim_strchr(p_bs, what) != NULL;
12680}
12681
12682/*
12683 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12684 * the file must be considered changed when the value is different.
12685 */
12686 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012687save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012688{
12689 buf->b_start_ffc = *buf->b_p_ff;
12690 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012691 buf->b_start_bomb = buf->b_p_bomb;
12692
Bram Moolenaar071d4272004-06-13 20:20:40 +000012693 /* Only use free/alloc when necessary, they take time. */
12694 if (buf->b_start_fenc == NULL
12695 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12696 {
12697 vim_free(buf->b_start_fenc);
12698 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12699 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012700}
12701
12702/*
12703 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12704 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012705 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12706 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012707 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012708 * When "ignore_empty" is true don't consider a new, empty buffer to be
12709 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012710 */
12711 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012712file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012713{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012714 /* In a buffer that was never loaded the options are not valid. */
12715 if (buf->b_flags & BF_NEVERLOADED)
12716 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012717 if (ignore_empty
12718 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012719 && buf->b_ml.ml_line_count == 1
12720 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12721 return FALSE;
12722 if (buf->b_start_ffc != *buf->b_p_ff)
12723 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012724 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012725 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012726 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12727 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012728 if (buf->b_start_fenc == NULL)
12729 return (*buf->b_p_fenc != NUL);
12730 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012731}
12732
12733/*
12734 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12735 */
12736 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012737check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012738{
12739 return check_opt_strings(p, p_ff_values, FALSE);
12740}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012741
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012742#ifdef FEAT_VARTABS
12743
12744/*
12745 * Set the integer values corresponding to the string setting of 'vartabstop'.
12746 */
12747 int
12748tabstop_set(char_u *var, int **array)
12749{
12750 int valcount = 1;
12751 int t;
12752 char_u *cp;
12753
Bram Moolenaar64f41072018-10-15 22:51:50 +020012754 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012755 {
12756 *array = NULL;
12757 return TRUE;
12758 }
12759
Bram Moolenaar64f41072018-10-15 22:51:50 +020012760 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012761 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012762 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012763 {
12764 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012765
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012766 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12767 {
12768 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012769 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012770 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012771 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012772 return FALSE;
12773 }
12774 }
12775
12776 if (VIM_ISDIGIT(*cp))
12777 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012778 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012779 {
12780 ++valcount;
12781 continue;
12782 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012783 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012784 return FALSE;
12785 }
12786
Bram Moolenaar64f41072018-10-15 22:51:50 +020012787 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012788 (*array)[0] = valcount;
12789
12790 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012791 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012792 {
12793 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012794 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012795 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012796 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012797 ++cp;
12798 }
12799
12800 return TRUE;
12801}
12802
12803/*
12804 * Calculate the number of screen spaces a tab will occupy.
12805 * If "vts" is set then the tab widths are taken from that array,
12806 * otherwise the value of ts is used.
12807 */
12808 int
12809tabstop_padding(colnr_T col, int ts_arg, int *vts)
12810{
12811 int ts = ts_arg == 0 ? 8 : ts_arg;
12812 int tabcount;
12813 colnr_T tabcol = 0;
12814 int t;
12815 int padding = 0;
12816
12817 if (vts == NULL || vts[0] == 0)
12818 return ts - (col % ts);
12819
12820 tabcount = vts[0];
12821
12822 for (t = 1; t <= tabcount; ++t)
12823 {
12824 tabcol += vts[t];
12825 if (tabcol > col)
12826 {
12827 padding = (int)(tabcol - col);
12828 break;
12829 }
12830 }
12831 if (t > tabcount)
12832 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12833
12834 return padding;
12835}
12836
12837/*
12838 * Find the size of the tab that covers a particular column.
12839 */
12840 int
12841tabstop_at(colnr_T col, int ts, int *vts)
12842{
12843 int tabcount;
12844 colnr_T tabcol = 0;
12845 int t;
12846 int tab_size = 0;
12847
12848 if (vts == 0 || vts[0] == 0)
12849 return ts;
12850
12851 tabcount = vts[0];
12852 for (t = 1; t <= tabcount; ++t)
12853 {
12854 tabcol += vts[t];
12855 if (tabcol > col)
12856 {
12857 tab_size = vts[t];
12858 break;
12859 }
12860 }
12861 if (t > tabcount)
12862 tab_size = vts[tabcount];
12863
12864 return tab_size;
12865}
12866
12867/*
12868 * Find the column on which a tab starts.
12869 */
12870 colnr_T
12871tabstop_start(colnr_T col, int ts, int *vts)
12872{
12873 int tabcount;
12874 colnr_T tabcol = 0;
12875 int t;
12876 int excess;
12877
Bram Moolenaar0119a592018-06-24 23:53:28 +020012878 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012879 return (col / ts) * ts;
12880
12881 tabcount = vts[0];
12882 for (t = 1; t <= tabcount; ++t)
12883 {
12884 tabcol += vts[t];
12885 if (tabcol > col)
12886 return tabcol - vts[t];
12887 }
12888
12889 excess = tabcol % vts[tabcount];
12890 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12891}
12892
12893/*
12894 * Find the number of tabs and spaces necessary to get from one column
12895 * to another.
12896 */
12897 void
12898tabstop_fromto(
12899 colnr_T start_col,
12900 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012901 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012902 int *vts,
12903 int *ntabs,
12904 int *nspcs)
12905{
12906 int spaces = end_col - start_col;
12907 colnr_T tabcol = 0;
12908 int padding = 0;
12909 int tabcount;
12910 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012911 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012912
Bram Moolenaar0119a592018-06-24 23:53:28 +020012913 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012914 {
12915 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012916 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012917
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012918 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012919 if (spaces >= initspc)
12920 {
12921 spaces -= initspc;
12922 tabs++;
12923 }
12924 tabs += spaces / ts;
12925 spaces -= (spaces / ts) * ts;
12926
12927 *ntabs = tabs;
12928 *nspcs = spaces;
12929 return;
12930 }
12931
12932 /* Find the padding needed to reach the next tabstop. */
12933 tabcount = vts[0];
12934 for (t = 1; t <= tabcount; ++t)
12935 {
12936 tabcol += vts[t];
12937 if (tabcol > start_col)
12938 {
12939 padding = (int)(tabcol - start_col);
12940 break;
12941 }
12942 }
12943 if (t > tabcount)
12944 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12945
12946 /* If the space needed is less than the padding no tabs can be used. */
12947 if (spaces < padding)
12948 {
12949 *ntabs = 0;
12950 *nspcs = spaces;
12951 return;
12952 }
12953
12954 *ntabs = 1;
12955 spaces -= padding;
12956
12957 /* At least one tab has been used. See if any more will fit. */
12958 while (spaces != 0 && ++t <= tabcount)
12959 {
12960 padding = vts[t];
12961 if (spaces < padding)
12962 {
12963 *nspcs = spaces;
12964 return;
12965 }
12966 ++*ntabs;
12967 spaces -= padding;
12968 }
12969
12970 *ntabs += spaces / vts[tabcount];
12971 *nspcs = spaces % vts[tabcount];
12972}
12973
12974/*
12975 * See if two tabstop arrays contain the same values.
12976 */
12977 int
12978tabstop_eq(int *ts1, int *ts2)
12979{
12980 int t;
12981
12982 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
12983 return FALSE;
12984 if (ts1 == ts2)
12985 return TRUE;
12986 if (ts1[0] != ts2[0])
12987 return FALSE;
12988
12989 for (t = 1; t <= ts1[0]; ++t)
12990 if (ts1[t] != ts2[t])
12991 return FALSE;
12992
12993 return TRUE;
12994}
12995
Bram Moolenaar113e1072019-01-20 15:30:40 +010012996#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012997/*
12998 * Copy a tabstop array, allocating space for the new array.
12999 */
13000 int *
13001tabstop_copy(int *oldts)
13002{
13003 int *newts;
13004 int t;
13005
13006 if (oldts == 0)
13007 return 0;
13008
13009 newts = (int *) alloc((unsigned) ((oldts[0] + 1) * sizeof(int)));
13010 for (t = 0; t <= oldts[0]; ++t)
13011 newts[t] = oldts[t];
13012
13013 return newts;
13014}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013015#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013016
13017/*
13018 * Return a count of the number of tabstops.
13019 */
13020 int
13021tabstop_count(int *ts)
13022{
13023 return ts != NULL ? ts[0] : 0;
13024}
13025
13026/*
13027 * Return the first tabstop, or 8 if there are no tabstops defined.
13028 */
13029 int
13030tabstop_first(int *ts)
13031{
13032 return ts != NULL ? ts[1] : 8;
13033}
13034
13035#endif
13036
Bram Moolenaar14f24742012-08-08 18:01:05 +020013037/*
13038 * Return the effective shiftwidth value for current buffer, using the
13039 * 'tabstop' value when 'shiftwidth' is zero.
13040 */
13041 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013042get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013043{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013044 return get_sw_value_col(buf, 0);
13045}
13046
13047/*
13048 * Idem, using the first non-black in the current line.
13049 */
13050 long
13051get_sw_value_indent(buf_T *buf)
13052{
13053 pos_T pos = curwin->w_cursor;
13054
13055 pos.col = getwhitecols_curline();
13056 return get_sw_value_pos(buf, &pos);
13057}
13058
13059/*
13060 * Idem, using "pos".
13061 */
13062 long
13063get_sw_value_pos(buf_T *buf, pos_T *pos)
13064{
13065 pos_T save_cursor = curwin->w_cursor;
13066 long sw_value;
13067
13068 curwin->w_cursor = *pos;
13069 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13070 curwin->w_cursor = save_cursor;
13071 return sw_value;
13072}
13073
13074/*
13075 * Idem, using virtual column "col".
13076 */
13077 long
13078get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13079{
13080 return buf->b_p_sw ? buf->b_p_sw :
13081 #ifdef FEAT_VARTABS
13082 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13083 #else
13084 buf->b_p_ts;
13085 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013086}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013087
13088/*
13089 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013090 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013091 */
13092 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013093get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013094{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013095 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013096}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013097
13098/*
13099 * Check matchpairs option for "*initc".
13100 * If there is a match set "*initc" to the matching character and "*findc" to
13101 * the opposite character. Set "*backwards" to the direction.
13102 * When "switchit" is TRUE swap the direction.
13103 */
13104 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013105find_mps_values(
13106 int *initc,
13107 int *findc,
13108 int *backwards,
13109 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013110{
13111 char_u *ptr;
13112
13113 ptr = curbuf->b_p_mps;
13114 while (*ptr != NUL)
13115 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013116 if (has_mbyte)
13117 {
13118 char_u *prev;
13119
13120 if (mb_ptr2char(ptr) == *initc)
13121 {
13122 if (switchit)
13123 {
13124 *findc = *initc;
13125 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13126 *backwards = TRUE;
13127 }
13128 else
13129 {
13130 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13131 *backwards = FALSE;
13132 }
13133 return;
13134 }
13135 prev = ptr;
13136 ptr += mb_ptr2len(ptr) + 1;
13137 if (mb_ptr2char(ptr) == *initc)
13138 {
13139 if (switchit)
13140 {
13141 *findc = *initc;
13142 *initc = mb_ptr2char(prev);
13143 *backwards = FALSE;
13144 }
13145 else
13146 {
13147 *findc = mb_ptr2char(prev);
13148 *backwards = TRUE;
13149 }
13150 return;
13151 }
13152 ptr += mb_ptr2len(ptr);
13153 }
13154 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013155 {
13156 if (*ptr == *initc)
13157 {
13158 if (switchit)
13159 {
13160 *backwards = TRUE;
13161 *findc = *initc;
13162 *initc = ptr[2];
13163 }
13164 else
13165 {
13166 *backwards = FALSE;
13167 *findc = ptr[2];
13168 }
13169 return;
13170 }
13171 ptr += 2;
13172 if (*ptr == *initc)
13173 {
13174 if (switchit)
13175 {
13176 *backwards = FALSE;
13177 *findc = *initc;
13178 *initc = ptr[-2];
13179 }
13180 else
13181 {
13182 *backwards = TRUE;
13183 *findc = ptr[-2];
13184 }
13185 return;
13186 }
13187 ++ptr;
13188 }
13189 if (*ptr == ',')
13190 ++ptr;
13191 }
13192}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013193
13194#if defined(FEAT_LINEBREAK) || defined(PROTO)
13195/*
13196 * This is called when 'breakindentopt' is changed and when a window is
13197 * initialized.
13198 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013199 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013200briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013201{
13202 char_u *p;
13203 int bri_shift = 0;
13204 long bri_min = 20;
13205 int bri_sbr = FALSE;
13206
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013207 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013208 while (*p != NUL)
13209 {
13210 if (STRNCMP(p, "shift:", 6) == 0
13211 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13212 {
13213 p += 6;
13214 bri_shift = getdigits(&p);
13215 }
13216 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13217 {
13218 p += 4;
13219 bri_min = getdigits(&p);
13220 }
13221 else if (STRNCMP(p, "sbr", 3) == 0)
13222 {
13223 p += 3;
13224 bri_sbr = TRUE;
13225 }
13226 if (*p != ',' && *p != NUL)
13227 return FAIL;
13228 if (*p == ',')
13229 ++p;
13230 }
13231
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013232 wp->w_p_brishift = bri_shift;
13233 wp->w_p_brimin = bri_min;
13234 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013235
13236 return OK;
13237}
13238#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013239
13240/*
13241 * Get the local or global value of 'backupcopy'.
13242 */
13243 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013244get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013245{
13246 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13247}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013248
13249#if defined(FEAT_SIGNS) || defined(PROTO)
13250/*
13251 * Return TRUE when window "wp" has a column to draw signs in.
13252 */
13253 int
13254signcolumn_on(win_T *wp)
13255{
13256 if (*wp->w_p_scl == 'n')
13257 return FALSE;
13258 if (*wp->w_p_scl == 'y')
13259 return TRUE;
13260 return (wp->w_buffer->b_signlist != NULL
13261# ifdef FEAT_NETBEANS_INTG
13262 || wp->w_buffer->b_has_sign_column
13263# endif
13264 );
13265}
13266#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013267
13268#if defined(FEAT_EVAL) || defined(PROTO)
13269/*
13270 * Get window or buffer local options.
13271 */
13272 dict_T *
13273get_winbuf_options(int bufopt)
13274{
13275 dict_T *d;
13276 int opt_idx;
13277
13278 d = dict_alloc();
13279 if (d == NULL)
13280 return NULL;
13281
13282 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13283 {
13284 struct vimoption *opt = &options[opt_idx];
13285
13286 if ((bufopt && (opt->indir & PV_BUF))
13287 || (!bufopt && (opt->indir & PV_WIN)))
13288 {
13289 char_u *varp = get_varp(opt);
13290
13291 if (varp != NULL)
13292 {
13293 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013294 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013295 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013296 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013297 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013298 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013299 }
13300 }
13301 }
13302
13303 return d;
13304}
13305#endif