blob: 8e62efc9955c40c4670a052cb95e1ae2ed258697 [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)
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200170#ifdef FEAT_EVAL
171# define PV_TFU OPT_BUF(BV_TFU)
172#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000173#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100174#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000175#define PV_TS OPT_BUF(BV_TS)
176#define PV_TW OPT_BUF(BV_TW)
177#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200178#ifdef FEAT_PERSISTENT_UNDO
179# define PV_UDF OPT_BUF(BV_UDF)
180#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000181#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200182#ifdef FEAT_VARTABS
183# define PV_VSTS OPT_BUF(BV_VSTS)
184# define PV_VTS OPT_BUF(BV_VTS)
185#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186
187/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000188 * Definition of the PV_ values for window-local options.
189 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191#define PV_LIST OPT_WIN(WV_LIST)
192#ifdef FEAT_ARABIC
193# define PV_ARAB OPT_WIN(WV_ARAB)
194#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200195#ifdef FEAT_LINEBREAK
196# define PV_BRI OPT_WIN(WV_BRI)
197# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
198#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000199#ifdef FEAT_DIFF
200# define PV_DIFF OPT_WIN(WV_DIFF)
201#endif
202#ifdef FEAT_FOLDING
203# define PV_FDC OPT_WIN(WV_FDC)
204# define PV_FEN OPT_WIN(WV_FEN)
205# define PV_FDI OPT_WIN(WV_FDI)
206# define PV_FDL OPT_WIN(WV_FDL)
207# define PV_FDM OPT_WIN(WV_FDM)
208# define PV_FML OPT_WIN(WV_FML)
209# define PV_FDN OPT_WIN(WV_FDN)
210# ifdef FEAT_EVAL
211# define PV_FDE OPT_WIN(WV_FDE)
212# define PV_FDT OPT_WIN(WV_FDT)
213# endif
214# define PV_FMR OPT_WIN(WV_FMR)
215#endif
216#ifdef FEAT_LINEBREAK
217# define PV_LBR OPT_WIN(WV_LBR)
218#endif
219#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200220#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000221#ifdef FEAT_LINEBREAK
222# define PV_NUW OPT_WIN(WV_NUW)
223#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200224#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000225# define PV_PVW OPT_WIN(WV_PVW)
226#endif
227#ifdef FEAT_RIGHTLEFT
228# define PV_RL OPT_WIN(WV_RL)
229# define PV_RLC OPT_WIN(WV_RLC)
230#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100231#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000232#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100233#define PV_SISO OPT_BOTH(OPT_WIN(WV_SISO))
234#define PV_SO OPT_BOTH(OPT_WIN(WV_SO))
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000235#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000236# define PV_SPELL OPT_WIN(WV_SPELL)
237#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000238#ifdef FEAT_SYN_HL
239# define PV_CUC OPT_WIN(WV_CUC)
240# define PV_CUL OPT_WIN(WV_CUL)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200241# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000242#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000243#ifdef FEAT_STL_OPT
244# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
245#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100246#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000247# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000248# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000249#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100250#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200251#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200252# define PV_COCU OPT_WIN(WV_COCU)
253# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200254#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200255#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200256# define PV_TWK OPT_WIN(WV_TWK)
257# define PV_TWS OPT_WIN(WV_TWS)
258# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200259#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200260#ifdef FEAT_SIGNS
261# define PV_SCL OPT_WIN(WV_SCL)
262#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000263
264/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000265typedef enum
266{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000267 PV_NONE = 0,
268 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000269} idopt_T;
270
271/*
272 * Options local to a window have a value local to a buffer and global to all
273 * buffers. Indicate this by setting "var" to VAR_WIN.
274 */
275#define VAR_WIN ((char_u *)-1)
276
277/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000278 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279 * Only to be used in option.c!
280 */
281static int p_ai;
282static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284static char_u *p_bh;
285static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000286static int p_bl;
287static int p_ci;
288#ifdef FEAT_CINDENT
289static int p_cin;
290static char_u *p_cink;
291static char_u *p_cino;
292#endif
293#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
294static char_u *p_cinw;
295#endif
296#ifdef FEAT_COMMENTS
297static char_u *p_com;
298#endif
299#ifdef FEAT_FOLDING
300static char_u *p_cms;
301#endif
302#ifdef FEAT_INS_EXPAND
303static char_u *p_cpt;
304#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000305#ifdef FEAT_COMPL_FUNC
306static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000307static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000308#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200309#ifdef FEAT_EVAL
310static char_u *p_tfu;
311#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200313static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316static char_u *p_ff;
317static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000318static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320static long p_iminsert;
321static long p_imsearch;
322#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
323static char_u *p_inex;
324#endif
325#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
326static char_u *p_inde;
327static char_u *p_indk;
328#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000329#if defined(FEAT_EVAL)
330static char_u *p_fex;
331#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000332static int p_inf;
333static char_u *p_isk;
334#ifdef FEAT_CRYPT
335static char_u *p_key;
336#endif
337#ifdef FEAT_LISP
338static int p_lisp;
339#endif
340static int p_ml;
341static int p_ma;
342static int p_mod;
343static char_u *p_mps;
344static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000345static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000346#ifdef FEAT_TEXTOBJ
347static char_u *p_qe;
348#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000349static int p_ro;
350#ifdef FEAT_SMARTINDENT
351static int p_si;
352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000353static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static long p_sts;
355#if defined(FEAT_SEARCHPATH)
356static char_u *p_sua;
357#endif
358static long p_sw;
359static int p_swf;
360#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000361static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000362static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000363#endif
364#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000365static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000366static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000367static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000368#endif
369static long p_ts;
370static long p_tw;
371static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200372#ifdef FEAT_PERSISTENT_UNDO
373static int p_udf;
374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200376#ifdef FEAT_VARTABS
377static char_u *p_vsts;
378static char_u *p_vts;
379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000380#ifdef FEAT_KEYMAP
381static char_u *p_keymap;
382#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200383#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200384static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000386
387/* Saved values for when 'bin' is set. */
388static int p_et_nobin;
389static int p_ml_nobin;
390static long p_tw_nobin;
391static long p_wm_nobin;
392
393/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200394static int p_ai_nopaste;
395static int p_et_nopaste;
396static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397static long p_tw_nopaste;
398static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200399#ifdef FEAT_VARTABS
400static char_u *p_vsts_nopaste;
401#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000402
403struct vimoption
404{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200405 char *fullname; // full option name
406 char *shortname; // permissible abbreviation
407 long_u flags; // see below
408 char_u *var; // global option: pointer to variable;
409 // window-local option: VAR_WIN;
410 // buffer-local option: global value
411 idopt_T indir; // global option: PV_NONE;
412 // local option: indirect option index
413 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000414#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200415 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaar558ca4a2019-04-04 18:15:38 +0200416# define SCTX_INIT , {0, 0, 0, 1}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000417#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200418# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000419#endif
420};
421
422#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
423#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
424
425/*
426 * Flags
427 */
428#define P_BOOL 0x01 /* the option is boolean */
429#define P_NUM 0x02 /* the option is numeric */
430#define P_STRING 0x04 /* the option is a string */
431#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000432 must use free_string_option() when
433 assigning new value. Not set if default is
434 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000435#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
436 never be used for local or hidden options! */
437#define P_NODEFAULT 0x40 /* don't set to default value */
438#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
439 use vim_free() when assigning new value */
440#define P_WAS_SET 0x100 /* option has been set/reset */
441#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
442#define P_VI_DEF 0x400 /* Use Vi default for Vim */
443#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
444
445 /* when option changed, what to display: */
446#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100447#define P_RWIN 0x2000 /* redraw current window and recompute text */
448#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000449#define P_RALL 0x6000 /* redraw all windows */
450#define P_RCLR 0x7000 /* clear and redraw all */
451
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200452#define P_COMMA 0x8000 /* comma separated list */
453#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
454 * commas */
455#define P_NODUP 0x20000L /* don't allow duplicate strings */
456#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000457
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200458#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
459#define P_GETTEXT 0x100000L /* expand default value with _() */
460#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
461#define P_NFNAME 0x400000L /* only normal file name chars allowed */
462#define P_INSECURE 0x800000L /* option was set from a modeline */
463#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100464 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200465#define P_NO_ML 0x2000000L /* not allowed in modeline */
466#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200467 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100468#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100469#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar110289e2019-05-23 15:38:06 +0200470#define P_MLE 0x20000000L /* under control of 'modelineexpr' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000471
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000472#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
473
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000474/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
475 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100476#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000477# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000478#else
479# define ISP_LATIN1 (char_u *)"@,161-255"
480#endif
481
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200482# 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 +0000483
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100484/* Default python version for pyx* commands */
485#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
486# define DEFAULT_PYTHON_VER 0
487#elif defined(FEAT_PYTHON3)
488# define DEFAULT_PYTHON_VER 3
489#elif defined(FEAT_PYTHON)
490# define DEFAULT_PYTHON_VER 2
491#else
492# define DEFAULT_PYTHON_VER 0
493#endif
494
Bram Moolenaarce655742019-01-31 14:12:57 +0100495// used for 'cinkeys' and 'indentkeys'
496#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
497
Bram Moolenaar071d4272004-06-13 20:20:40 +0000498/*
499 * options[] is initialized here.
500 * The order of the options MUST be alphabetic for ":set all" and findoption().
501 * All option names MUST start with a lowercase letter (for findoption()).
502 * Exception: "t_" options are at the end.
503 * The options with a NULL variable are 'hidden': a set command for them is
504 * ignored and they are not printed.
505 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100506static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200508 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000509#ifdef FEAT_RIGHTLEFT
510 (char_u *)&p_aleph, PV_NONE,
511#else
512 (char_u *)NULL, PV_NONE,
513#endif
514 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100515#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000516 (char_u *)128L,
517#else
518 (char_u *)224L,
519#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200520 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000521 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200522#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000523 (char_u *)&p_antialias, PV_NONE,
524 {(char_u *)FALSE, (char_u *)FALSE}
525#else
526 (char_u *)NULL, PV_NONE,
527 {(char_u *)FALSE, (char_u *)FALSE}
528#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200529 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200530 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000531#ifdef FEAT_ARABIC
532 (char_u *)VAR_WIN, PV_ARAB,
533#else
534 (char_u *)NULL, PV_NONE,
535#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200536 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000537 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
538#ifdef FEAT_ARABIC
539 (char_u *)&p_arshape, PV_NONE,
540#else
541 (char_u *)NULL, PV_NONE,
542#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200543 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000544 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
545#ifdef FEAT_RIGHTLEFT
546 (char_u *)&p_ari, PV_NONE,
547#else
548 (char_u *)NULL, PV_NONE,
549#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200550 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200553 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 (char_u *)&p_ambw, PV_NONE,
556 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200557 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100559#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100561 {(char_u *)FALSE, (char_u *)0L}
562#else
563 (char_u *)NULL, PV_NONE,
564 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200566 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000567 {"autoindent", "ai", P_BOOL|P_VI_DEF,
568 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200569 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000570 {"autoprint", "ap", P_BOOL|P_VI_DEF,
571 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200572 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000573 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000574 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200575 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000576 {"autowrite", "aw", P_BOOL|P_VI_DEF,
577 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200578 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000579 {"autowriteall","awa", P_BOOL|P_VI_DEF,
580 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200581 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000582 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
583 (char_u *)&p_bg, PV_NONE,
584 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100585#if (defined(MSWIN)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000586 (char_u *)"dark",
587#else
588 (char_u *)"light",
589#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200590 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200591 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200593 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000594 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
595 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200596 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200597 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200598 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000599#ifdef UNIX
600 {(char_u *)"yes", (char_u *)"auto"}
601#else
602 {(char_u *)"auto", (char_u *)"auto"}
603#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200604 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200605 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
606 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000607 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200608 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000609 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000610 (char_u *)&p_bex, PV_NONE,
611 {
612#ifdef VMS
613 (char_u *)"_",
614#else
615 (char_u *)"~",
616#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200617 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200618 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000619#ifdef FEAT_WILDIGN
620 (char_u *)&p_bsk, PV_NONE,
621 {(char_u *)"", (char_u *)0L}
622#else
623 (char_u *)NULL, PV_NONE,
624 {(char_u *)0L, (char_u *)0L}
625#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200626 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000629 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100630 {(char_u *)600L, (char_u *)0L}
631#else
632 (char_u *)NULL, PV_NONE,
633 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000634#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200635 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100636 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100637#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100638 (char_u *)&p_beval, PV_NONE,
639 {(char_u *)FALSE, (char_u *)0L}
640#else
641 (char_u *)NULL, PV_NONE,
642 {(char_u *)0L, (char_u *)0L}
643#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200644 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100645 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100646#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100647 (char_u *)&p_bevalterm, PV_NONE,
648 {(char_u *)FALSE, (char_u *)0L}
649#else
650 (char_u *)NULL, PV_NONE,
651 {(char_u *)0L, (char_u *)0L}
652#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200653 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200654 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100655#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
656 (char_u *)&p_bexpr, PV_BEXPR,
657 {(char_u *)"", (char_u *)0L}
658#else
659 (char_u *)NULL, PV_NONE,
660 {(char_u *)0L, (char_u *)0L}
661#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200662 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000663 {"beautify", "bf", P_BOOL|P_VI_DEF,
664 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200665 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200666 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
667 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200668 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
670 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200671 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200674 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200677 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000678 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
679#ifdef FEAT_LINEBREAK
680 (char_u *)&p_breakat, PV_NONE,
681 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
682#else
683 (char_u *)NULL, PV_NONE,
684 {(char_u *)0L, (char_u *)0L}
685#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200686 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200687 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
688#ifdef FEAT_LINEBREAK
689 (char_u *)VAR_WIN, PV_BRI,
690 {(char_u *)FALSE, (char_u *)0L}
691#else
692 (char_u *)NULL, PV_NONE,
693 {(char_u *)0L, (char_u *)0L}
694#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200695 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200696 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
697 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200698#ifdef FEAT_LINEBREAK
699 (char_u *)VAR_WIN, PV_BRIOPT,
700 {(char_u *)"", (char_u *)NULL}
701#else
702 (char_u *)NULL, PV_NONE,
703 {(char_u *)"", (char_u *)NULL}
704#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200705 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000706 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
707#ifdef FEAT_BROWSE
708 (char_u *)&p_bsdir, PV_NONE,
709 {(char_u *)"last", (char_u *)0L}
710#else
711 (char_u *)NULL, PV_NONE,
712 {(char_u *)0L, (char_u *)0L}
713#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200714 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 (char_u *)&p_bh, PV_BH,
717 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200718 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
720 (char_u *)&p_bl, PV_BL,
721 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200722 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 (char_u *)&p_bt, PV_BT,
725 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200726 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200727 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000728 (char_u *)&p_cmp, PV_NONE,
729 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200730 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200731 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000732#ifdef FEAT_SEARCHPATH
733 (char_u *)&p_cdpath, PV_NONE,
734 {(char_u *)",,", (char_u *)0L}
735#else
736 (char_u *)NULL, PV_NONE,
737 {(char_u *)0L, (char_u *)0L}
738#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200739 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740 {"cedit", NULL, P_STRING,
741#ifdef FEAT_CMDWIN
742 (char_u *)&p_cedit, PV_NONE,
743 {(char_u *)"", (char_u *)CTRL_F_STR}
744#else
745 (char_u *)NULL, PV_NONE,
746 {(char_u *)0L, (char_u *)0L}
747#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200748 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100750#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000751 (char_u *)&p_ccv, PV_NONE,
752 {(char_u *)"", (char_u *)0L}
753#else
754 (char_u *)NULL, PV_NONE,
755 {(char_u *)0L, (char_u *)0L}
756#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200757 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000758 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
759#ifdef FEAT_CINDENT
760 (char_u *)&p_cin, PV_CIN,
761#else
762 (char_u *)NULL, PV_NONE,
763#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200764 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200765 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000766#ifdef FEAT_CINDENT
767 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100768 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000769#else
770 (char_u *)NULL, PV_NONE,
771 {(char_u *)0L, (char_u *)0L}
772#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200773 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200774 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000775#ifdef FEAT_CINDENT
776 (char_u *)&p_cino, PV_CINO,
777#else
778 (char_u *)NULL, PV_NONE,
779#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200780 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200781 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
783 (char_u *)&p_cinw, PV_CINW,
784 {(char_u *)"if,else,while,do,for,switch",
785 (char_u *)0L}
786#else
787 (char_u *)NULL, PV_NONE,
788 {(char_u *)0L, (char_u *)0L}
789#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200790 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200791 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792#ifdef FEAT_CLIPBOARD
793 (char_u *)&p_cb, PV_NONE,
794# ifdef FEAT_XCLIPBOARD
795 {(char_u *)"autoselect,exclude:cons\\|linux",
796 (char_u *)0L}
797# else
798 {(char_u *)"", (char_u *)0L}
799# endif
800#else
801 (char_u *)NULL, PV_NONE,
802 {(char_u *)"", (char_u *)0L}
803#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200804 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000805 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
806 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200807 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000808 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
809#ifdef FEAT_CMDWIN
810 (char_u *)&p_cwh, PV_NONE,
811#else
812 (char_u *)NULL, PV_NONE,
813#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200814 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200815 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200816#ifdef FEAT_SYN_HL
817 (char_u *)VAR_WIN, PV_CC,
818#else
819 (char_u *)NULL, PV_NONE,
820#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200821 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
823 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200824 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200825 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
826 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000827#ifdef FEAT_COMMENTS
828 (char_u *)&p_com, PV_COM,
829 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
830 (char_u *)0L}
831#else
832 (char_u *)NULL, PV_NONE,
833 {(char_u *)0L, (char_u *)0L}
834#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200835 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200836 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000837#ifdef FEAT_FOLDING
838 (char_u *)&p_cms, PV_CMS,
839 {(char_u *)"/*%s*/", (char_u *)0L}
840#else
841 (char_u *)NULL, PV_NONE,
842 {(char_u *)0L, (char_u *)0L}
843#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200844 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000845 /* P_PRI_MKRC isn't needed here, optval_default()
846 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000847 {"compatible", "cp", P_BOOL|P_RALL,
848 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200849 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200850 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000851#ifdef FEAT_INS_EXPAND
852 (char_u *)&p_cpt, PV_CPT,
853 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
854#else
855 (char_u *)NULL, PV_NONE,
856 {(char_u *)0L, (char_u *)0L}
857#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200858 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200859 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200860#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200861 (char_u *)VAR_WIN, PV_COCU,
862 {(char_u *)"", (char_u *)NULL}
863#else
864 (char_u *)NULL, PV_NONE,
865 {(char_u *)NULL, (char_u *)0L}
866#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200867 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200868 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
869#ifdef FEAT_CONCEAL
870 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200871#else
872 (char_u *)NULL, PV_NONE,
873#endif
874 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200875 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000876 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
877#ifdef FEAT_COMPL_FUNC
878 (char_u *)&p_cfu, PV_CFU,
879 {(char_u *)"", (char_u *)0L}
880#else
881 (char_u *)NULL, PV_NONE,
882 {(char_u *)0L, (char_u *)0L}
883#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200884 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200885 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000886#ifdef FEAT_INS_EXPAND
887 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000888 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000889#else
890 (char_u *)NULL, PV_NONE,
891 {(char_u *)0L, (char_u *)0L}
892#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200893 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000894 {"confirm", "cf", P_BOOL|P_VI_DEF,
895#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
896 (char_u *)&p_confirm, PV_NONE,
897#else
898 (char_u *)NULL, PV_NONE,
899#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200900 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200903 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000904 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
905 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200906 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
908 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000909 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200910 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200911 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200912#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200913 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100914 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200915#else
916 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200917 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200918#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200919 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000920 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
921#ifdef FEAT_CSCOPE
922 (char_u *)&p_cspc, PV_NONE,
923#else
924 (char_u *)NULL, PV_NONE,
925#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200926 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
928#ifdef FEAT_CSCOPE
929 (char_u *)&p_csprg, PV_NONE,
930 {(char_u *)"cscope", (char_u *)0L}
931#else
932 (char_u *)NULL, PV_NONE,
933 {(char_u *)0L, (char_u *)0L}
934#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200935 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200936 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000937#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
938 (char_u *)&p_csqf, PV_NONE,
939 {(char_u *)"", (char_u *)0L}
940#else
941 (char_u *)NULL, PV_NONE,
942 {(char_u *)0L, (char_u *)0L}
943#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200944 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200945 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
946#ifdef FEAT_CSCOPE
947 (char_u *)&p_csre, PV_NONE,
948#else
949 (char_u *)NULL, PV_NONE,
950#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200951 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_cst, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200958 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
960#ifdef FEAT_CSCOPE
961 (char_u *)&p_csto, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200965 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
967#ifdef FEAT_CSCOPE
968 (char_u *)&p_csverbose, PV_NONE,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200972 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200973 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200974 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200975 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100976 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000977#ifdef FEAT_SYN_HL
978 (char_u *)VAR_WIN, PV_CUC,
979#else
980 (char_u *)NULL, PV_NONE,
981#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200982 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100983 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000984#ifdef FEAT_SYN_HL
985 (char_u *)VAR_WIN, PV_CUL,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200989 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000990 {"debug", NULL, P_STRING|P_VI_DEF,
991 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200992 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200993 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000994#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000995 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000996 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000997#else
998 (char_u *)NULL, PV_NONE,
999 {(char_u *)NULL, (char_u *)0L}
1000#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001001 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001004 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001005 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001006#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001007 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008#else
1009 (char_u *)NULL, PV_NONE,
1010#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001011 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1013#ifdef FEAT_DIFF
1014 (char_u *)VAR_WIN, PV_DIFF,
1015#else
1016 (char_u *)NULL, PV_NONE,
1017#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001018 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001019 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001020#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1021 (char_u *)&p_dex, PV_NONE,
1022 {(char_u *)"", (char_u *)0L}
1023#else
1024 (char_u *)NULL, PV_NONE,
1025 {(char_u *)0L, (char_u *)0L}
1026#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001027 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001028 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1029 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030#ifdef FEAT_DIFF
1031 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001032 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001033#else
1034 (char_u *)NULL, PV_NONE,
1035 {(char_u *)"", (char_u *)NULL}
1036#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001037 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001038 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1039#ifdef FEAT_DIGRAPHS
1040 (char_u *)&p_dg, PV_NONE,
1041#else
1042 (char_u *)NULL, PV_NONE,
1043#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001044 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001045 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1046 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001047 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001048 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001049 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001050 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001051 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 (char_u *)&p_ead, PV_NONE,
1054 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001055 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001056 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1057 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001058 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001059 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001060 (char_u *)&p_emoji, PV_NONE,
1061 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001062 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001063 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001064 (char_u *)&p_enc, PV_NONE,
1065 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001066 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001067 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1068 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001069 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001070 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1071 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001072 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001073 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001074 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001075 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001076 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1077 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001078 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001079 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1080#ifdef FEAT_QUICKFIX
1081 (char_u *)&p_ef, PV_NONE,
1082 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1083#else
1084 (char_u *)NULL, PV_NONE,
1085 {(char_u *)NULL, (char_u *)0L}
1086#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001087 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001088 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001090 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001091 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001092#else
1093 (char_u *)NULL, PV_NONE,
1094 {(char_u *)NULL, (char_u *)0L}
1095#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001096 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001097 {"esckeys", "ek", P_BOOL|P_VIM,
1098 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001099 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001100 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001102 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1104 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001105 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001106 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1107 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001108 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001109 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1110 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111 (char_u *)&p_fenc, PV_FENC,
1112 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001113 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001114 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001115 (char_u *)&p_fencs, PV_NONE,
1116 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001117 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001118 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1119 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001120 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001121 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001122 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001123 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001124 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001125 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001126 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1127 (char_u *)&p_fic, PV_NONE,
1128 {
1129#ifdef CASE_INSENSITIVE_FILENAME
1130 (char_u *)TRUE,
1131#else
1132 (char_u *)FALSE,
1133#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001134 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001135 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001136 (char_u *)&p_ft, PV_FT,
1137 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001138 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001139 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 (char_u *)&p_fcs, PV_NONE,
1141 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001142 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001143 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1144 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001145 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001148 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 {"flash", "fl", P_BOOL|P_VI_DEF,
1150 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001151 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001152 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001153#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001154 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001155 {(char_u *)"", (char_u *)0L}
1156#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157 (char_u *)NULL, PV_NONE,
1158 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001159#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001160 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001161 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1162#ifdef FEAT_FOLDING
1163 (char_u *)VAR_WIN, PV_FDC,
1164 {(char_u *)FALSE, (char_u *)0L}
1165#else
1166 (char_u *)NULL, PV_NONE,
1167 {(char_u *)NULL, (char_u *)0L}
1168#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001169 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001170 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1171#ifdef FEAT_FOLDING
1172 (char_u *)VAR_WIN, PV_FEN,
1173 {(char_u *)TRUE, (char_u *)0L}
1174#else
1175 (char_u *)NULL, PV_NONE,
1176 {(char_u *)NULL, (char_u *)0L}
1177#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001178 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001179 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001180#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1181 (char_u *)VAR_WIN, PV_FDE,
1182 {(char_u *)"0", (char_u *)NULL}
1183#else
1184 (char_u *)NULL, PV_NONE,
1185 {(char_u *)NULL, (char_u *)0L}
1186#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001187 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001188 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001189#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001191 {(char_u *)"#", (char_u *)NULL}
1192#else
1193 (char_u *)NULL, PV_NONE,
1194 {(char_u *)NULL, (char_u *)0L}
1195#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001196 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001197 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001198#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200 {(char_u *)0L, (char_u *)0L}
1201#else
1202 (char_u *)NULL, PV_NONE,
1203 {(char_u *)NULL, (char_u *)0L}
1204#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001205 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001206 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001207#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001208 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001209 {(char_u *)-1L, (char_u *)0L}
1210#else
1211 (char_u *)NULL, PV_NONE,
1212 {(char_u *)NULL, (char_u *)0L}
1213#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001214 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001215 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001216 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001217#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001219 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001220#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001221 (char_u *)NULL, PV_NONE,
1222 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001224 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001225 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1226#ifdef FEAT_FOLDING
1227 (char_u *)VAR_WIN, PV_FDM,
1228 {(char_u *)"manual", (char_u *)NULL}
1229#else
1230 (char_u *)NULL, PV_NONE,
1231 {(char_u *)NULL, (char_u *)0L}
1232#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001233 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001234 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1235#ifdef FEAT_FOLDING
1236 (char_u *)VAR_WIN, PV_FML,
1237 {(char_u *)1L, (char_u *)0L}
1238#else
1239 (char_u *)NULL, PV_NONE,
1240 {(char_u *)NULL, (char_u *)0L}
1241#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001242 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001243 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1244#ifdef FEAT_FOLDING
1245 (char_u *)VAR_WIN, PV_FDN,
1246 {(char_u *)20L, (char_u *)0L}
1247#else
1248 (char_u *)NULL, PV_NONE,
1249 {(char_u *)NULL, (char_u *)0L}
1250#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001251 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001252 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1253#ifdef FEAT_FOLDING
1254 (char_u *)&p_fdo, PV_NONE,
1255 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1256 (char_u *)0L}
1257#else
1258 (char_u *)NULL, PV_NONE,
1259 {(char_u *)NULL, (char_u *)0L}
1260#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001261 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001262 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001263#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1264 (char_u *)VAR_WIN, PV_FDT,
1265 {(char_u *)"foldtext()", (char_u *)NULL}
1266#else
1267 (char_u *)NULL, PV_NONE,
1268 {(char_u *)NULL, (char_u *)0L}
1269#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001270 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001271 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001272#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001273 (char_u *)&p_fex, PV_FEX,
1274 {(char_u *)"", (char_u *)0L}
1275#else
1276 (char_u *)NULL, PV_NONE,
1277 {(char_u *)0L, (char_u *)0L}
1278#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001279 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001280 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1281 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001282 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001283 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001284 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1285 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001286 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001287 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001288 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001289 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001290 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001291 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1292#ifdef HAVE_FSYNC
1293 (char_u *)&p_fs, PV_NONE,
1294 {(char_u *)TRUE, (char_u *)0L}
1295#else
1296 (char_u *)NULL, PV_NONE,
1297 {(char_u *)FALSE, (char_u *)0L}
1298#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001299 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001300 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1301 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001302 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001303 {"graphic", "gr", P_BOOL|P_VI_DEF,
1304 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001305 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001306 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001307#ifdef FEAT_QUICKFIX
1308 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001309 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001310#else
1311 (char_u *)NULL, PV_NONE,
1312 {(char_u *)NULL, (char_u *)0L}
1313#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001314 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1316#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001317 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001318 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001319# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320 /* may be changed to "grep -n" in os_win32.c */
1321 (char_u *)"findstr /n",
1322# else
1323# ifdef UNIX
1324 /* Add an extra file name so that grep will always
1325 * insert a file name in the match line. */
1326 (char_u *)"grep -n $* /dev/null",
1327# else
1328# ifdef VMS
1329 (char_u *)"SEARCH/NUMBERS ",
1330# else
1331 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001332# endif
1333# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001335 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336#else
1337 (char_u *)NULL, PV_NONE,
1338 {(char_u *)NULL, (char_u *)0L}
1339#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001340 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001341 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001342#ifdef CURSOR_SHAPE
1343 (char_u *)&p_guicursor, PV_NONE,
1344 {
1345# ifdef FEAT_GUI
1346 (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 +01001347# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001348 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1349# endif
1350 (char_u *)0L}
1351#else
1352 (char_u *)NULL, PV_NONE,
1353 {(char_u *)NULL, (char_u *)0L}
1354#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001355 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001356 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001357#ifdef FEAT_GUI
1358 (char_u *)&p_guifont, PV_NONE,
1359 {(char_u *)"", (char_u *)0L}
1360#else
1361 (char_u *)NULL, PV_NONE,
1362 {(char_u *)NULL, (char_u *)0L}
1363#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001364 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001365 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001366#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1367 (char_u *)&p_guifontset, PV_NONE,
1368 {(char_u *)"", (char_u *)0L}
1369#else
1370 (char_u *)NULL, PV_NONE,
1371 {(char_u *)NULL, (char_u *)0L}
1372#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001373 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001374 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001375#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376 (char_u *)&p_guifontwide, PV_NONE,
1377 {(char_u *)"", (char_u *)0L}
1378#else
1379 (char_u *)NULL, PV_NONE,
1380 {(char_u *)NULL, (char_u *)0L}
1381#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001382 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001383 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001384#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 (char_u *)&p_ghr, PV_NONE,
1386#else
1387 (char_u *)NULL, PV_NONE,
1388#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001389 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001390 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001391#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001393# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001394 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001396 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001397# endif
1398#else
1399 (char_u *)NULL, PV_NONE,
1400 {(char_u *)NULL, (char_u *)0L}
1401#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001402 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001403 {"guipty", NULL, P_BOOL|P_VI_DEF,
1404#if defined(FEAT_GUI)
1405 (char_u *)&p_guipty, PV_NONE,
1406#else
1407 (char_u *)NULL, PV_NONE,
1408#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001409 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001410 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001411#if defined(FEAT_GUI_TABLINE)
1412 (char_u *)&p_gtl, PV_NONE,
1413 {(char_u *)"", (char_u *)0L}
1414#else
1415 (char_u *)NULL, PV_NONE,
1416 {(char_u *)NULL, (char_u *)0L}
1417#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001418 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001419 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001420#if defined(FEAT_GUI_TABLINE)
1421 (char_u *)&p_gtt, PV_NONE,
1422 {(char_u *)"", (char_u *)0L}
1423#else
1424 (char_u *)NULL, PV_NONE,
1425 {(char_u *)NULL, (char_u *)0L}
1426#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001427 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001428 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1429 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001430 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001431 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1432 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001433 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001434 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001437 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001438 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001439#ifdef FEAT_MULTI_LANG
1440 (char_u *)&p_hlg, PV_NONE,
1441 {(char_u *)"", (char_u *)0L}
1442#else
1443 (char_u *)NULL, PV_NONE,
1444 {(char_u *)0L, (char_u *)0L}
1445#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001446 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001447 {"hidden", "hid", P_BOOL|P_VI_DEF,
1448 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001449 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001450 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001451 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001452 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001453 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001454 {"history", "hi", P_NUM|P_VIM,
1455 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001456 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1458#ifdef FEAT_RIGHTLEFT
1459 (char_u *)&p_hkmap, PV_NONE,
1460#else
1461 (char_u *)NULL, PV_NONE,
1462#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001463 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1465#ifdef FEAT_RIGHTLEFT
1466 (char_u *)&p_hkmapp, PV_NONE,
1467#else
1468 (char_u *)NULL, PV_NONE,
1469#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001470 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001471 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1472 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001473 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474 {"icon", NULL, P_BOOL|P_VI_DEF,
1475#ifdef FEAT_TITLE
1476 (char_u *)&p_icon, PV_NONE,
1477#else
1478 (char_u *)NULL, PV_NONE,
1479#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001480 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001481 {"iconstring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001482#ifdef FEAT_TITLE
1483 (char_u *)&p_iconstring, PV_NONE,
1484#else
1485 (char_u *)NULL, PV_NONE,
1486#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001487 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001488 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1489 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001490 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001491 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001492#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001493 (char_u *)&p_imaf, PV_NONE,
1494 {(char_u *)"", (char_u *)NULL}
1495# else
1496 (char_u *)NULL, PV_NONE,
1497 {(char_u *)NULL, (char_u *)0L}
1498# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001499 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001500 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001501#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502 (char_u *)&p_imak, PV_NONE,
1503#else
1504 (char_u *)NULL, PV_NONE,
1505#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001506 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001509 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512#ifdef __sgi
1513 {(char_u *)TRUE, (char_u *)0L}
1514#else
1515 {(char_u *)FALSE, (char_u *)0L}
1516#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001517 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518 {"iminsert", "imi", P_NUM|P_VI_DEF,
1519 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001521 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {"imsearch", "ims", P_NUM|P_VI_DEF,
1523 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001524 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001525 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001526 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001527#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001528 (char_u *)&p_imsf, PV_NONE,
1529 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001530#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001531 (char_u *)NULL, PV_NONE,
1532 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001533#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001534 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001535 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1536#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1537 (char_u *)&p_imst, PV_NONE,
1538 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1539#else
1540 (char_u *)NULL, PV_NONE,
1541 {(char_u *)0L, (char_u *)0L}
1542#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001543 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001544 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1545#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001546 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001547 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1548#else
1549 (char_u *)NULL, PV_NONE,
1550 {(char_u *)0L, (char_u *)0L}
1551#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001552 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001553 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1555 (char_u *)&p_inex, PV_INEX,
1556 {(char_u *)"", (char_u *)0L}
1557#else
1558 (char_u *)NULL, PV_NONE,
1559 {(char_u *)0L, (char_u *)0L}
1560#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001561 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001562 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1563 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001564 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001565 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001566#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1567 (char_u *)&p_inde, PV_INDE,
1568 {(char_u *)"", (char_u *)0L}
1569#else
1570 (char_u *)NULL, PV_NONE,
1571 {(char_u *)0L, (char_u *)0L}
1572#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001573 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001574 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001575#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1576 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001577 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001578#else
1579 (char_u *)NULL, PV_NONE,
1580 {(char_u *)0L, (char_u *)0L}
1581#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001582 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001583 {"infercase", "inf", P_BOOL|P_VI_DEF,
1584 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001585 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001586 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1587 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001588 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001589 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1590 (char_u *)&p_isf, PV_NONE,
1591 {
1592#ifdef BACKSLASH_IN_FILENAME
1593 /* Excluded are: & and ^ are special in cmd.exe
1594 * ( and ) are used in text separating fnames */
1595 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1596#else
1597# ifdef AMIGA
1598 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1599# else
1600# ifdef VMS
1601 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1602# else /* UNIX et al. */
1603# ifdef EBCDIC
1604 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1605# else
1606 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1607# endif
1608# endif
1609# endif
1610#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001611 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001612 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1613 (char_u *)&p_isi, PV_NONE,
1614 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001615#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001616 (char_u *)"@,48-57,_,128-167,224-235",
1617#else
1618# ifdef EBCDIC
1619 /* TODO: EBCDIC Check this! @ == isalpha()*/
1620 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1621 "112-120,128,140-142,156,158,172,"
1622 "174,186,191,203-207,219-225,235-239,"
1623 "251-254",
1624# else
1625 (char_u *)"@,48-57,_,192-255",
1626# endif
1627#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001628 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001629 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1630 (char_u *)&p_isk, PV_ISK,
1631 {
1632#ifdef EBCDIC
1633 (char_u *)"@,240-249,_",
1634 /* TODO: EBCDIC Check this! @ == isalpha()*/
1635 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1636 "112-120,128,140-142,156,158,172,"
1637 "174,186,191,203-207,219-225,235-239,"
1638 "251-254",
1639#else
1640 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001641# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001642 (char_u *)"@,48-57,_,128-167,224-235"
1643# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001644 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001645# endif
1646#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001647 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001648 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1649 (char_u *)&p_isp, PV_NONE,
1650 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001651#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001652 (char_u *)"@,~-255",
1653#else
1654# ifdef EBCDIC
1655 /* all chars above 63 are printable */
1656 (char_u *)"63-255",
1657# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001658 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001659# endif
1660#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001661 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1663 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001664 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001665 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1666#ifdef FEAT_CRYPT
1667 (char_u *)&p_key, PV_KEY,
1668 {(char_u *)"", (char_u *)0L}
1669#else
1670 (char_u *)NULL, PV_NONE,
1671 {(char_u *)0L, (char_u *)0L}
1672#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001673 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001674 {"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 +00001675#ifdef FEAT_KEYMAP
1676 (char_u *)&p_keymap, PV_KMAP,
1677 {(char_u *)"", (char_u *)0L}
1678#else
1679 (char_u *)NULL, PV_NONE,
1680 {(char_u *)"", (char_u *)0L}
1681#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001682 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001683 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001685 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001687 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001689#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690 (char_u *)":help",
1691#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001692# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001693 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001694# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001695# ifdef USEMAN_S
1696 (char_u *)"man -s",
1697# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001699# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700# endif
1701#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001702 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001703 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704#ifdef FEAT_LANGMAP
1705 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001706 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001707#else
1708 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001709 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001711 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001712 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001713#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1714 (char_u *)&p_lm, PV_NONE,
1715#else
1716 (char_u *)NULL, PV_NONE,
1717#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001718 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001719 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1720#ifdef FEAT_LANGMAP
1721 (char_u *)&p_lnr, PV_NONE,
1722#else
1723 (char_u *)NULL, PV_NONE,
1724#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001725 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001726 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1727#ifdef FEAT_LANGMAP
1728 (char_u *)&p_lrm, PV_NONE,
1729#else
1730 (char_u *)NULL, PV_NONE,
1731#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001732 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001735 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1737 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001738 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001739 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1740#ifdef FEAT_LINEBREAK
1741 (char_u *)VAR_WIN, PV_LBR,
1742#else
1743 (char_u *)NULL, PV_NONE,
1744#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001745 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1747 (char_u *)&Rows, PV_NONE,
1748 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001749#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001750 (char_u *)25L,
1751#else
1752 (char_u *)24L,
1753#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001754 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001755 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1756#ifdef FEAT_GUI
1757 (char_u *)&p_linespace, PV_NONE,
1758#else
1759 (char_u *)NULL, PV_NONE,
1760#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001761#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 {(char_u *)1L, (char_u *)0L}
1763#else
1764 {(char_u *)0L, (char_u *)0L}
1765#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001766 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001767 {"lisp", NULL, P_BOOL|P_VI_DEF,
1768#ifdef FEAT_LISP
1769 (char_u *)&p_lisp, PV_LISP,
1770#else
1771 (char_u *)NULL, PV_NONE,
1772#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001773 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001774 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001775#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001776 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1778#else
1779 (char_u *)NULL, PV_NONE,
1780 {(char_u *)"", (char_u *)0L}
1781#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001782 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001783 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1784 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001785 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001786 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001788 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1790 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001791 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001792 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001793#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001794 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001795 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001796#else
1797 (char_u *)NULL, PV_NONE,
1798 {(char_u *)"", (char_u *)0L}
1799#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001800 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001801 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001802#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001803 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001804 {(char_u *)TRUE, (char_u *)0L}
1805#else
1806 (char_u *)NULL, PV_NONE,
1807 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001808#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001809 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001810 {"magic", NULL, P_BOOL|P_VI_DEF,
1811 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001812 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001813 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001814#ifdef FEAT_QUICKFIX
1815 (char_u *)&p_mef, PV_NONE,
1816 {(char_u *)"", (char_u *)0L}
1817#else
1818 (char_u *)NULL, PV_NONE,
1819 {(char_u *)NULL, (char_u *)0L}
1820#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001821 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001822 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001823 (char_u *)&p_menc, PV_MENC,
1824 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001825 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001826 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1827#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001828 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001829# ifdef VMS
1830 {(char_u *)"MMS", (char_u *)0L}
1831# else
1832 {(char_u *)"make", (char_u *)0L}
1833# endif
1834#else
1835 (char_u *)NULL, PV_NONE,
1836 {(char_u *)NULL, (char_u *)0L}
1837#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001838 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001839 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001840 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001841 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001842 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001843 {"matchtime", "mat", P_NUM|P_VI_DEF,
1844 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001845 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001846 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001847 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001848 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001849 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1850#ifdef FEAT_EVAL
1851 (char_u *)&p_mfd, PV_NONE,
1852#else
1853 (char_u *)NULL, PV_NONE,
1854#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001855 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001856 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1857 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001858 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"maxmem", "mm", P_NUM|P_VI_DEF,
1860 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001861 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001862 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001863 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1864 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001865 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1867 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001868 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001869 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001870 {"menuitems", "mis", P_NUM|P_VI_DEF,
1871#ifdef FEAT_MENU
1872 (char_u *)&p_mis, PV_NONE,
1873#else
1874 (char_u *)NULL, PV_NONE,
1875#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001876 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001877 {"mesg", NULL, P_BOOL|P_VI_DEF,
1878 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001879 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001880 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001881#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001882 (char_u *)&p_msm, PV_NONE,
1883 {(char_u *)"460000,2000,500", (char_u *)0L}
1884#else
1885 (char_u *)NULL, PV_NONE,
1886 {(char_u *)0L, (char_u *)0L}
1887#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001888 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001889 {"modeline", "ml", P_BOOL|P_VIM,
1890 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001891 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001892 {"modelineexpr", "mle", P_BOOL|P_VI_DEF,
1893 (char_u *)&p_mle, PV_NONE,
1894 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001895 {"modelines", "mls", P_NUM|P_VI_DEF,
1896 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001897 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001898 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1899 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001900 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001901 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1902 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001903 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001904 {"more", NULL, P_BOOL|P_VIM,
1905 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001906 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1908 (char_u *)&p_mouse, PV_NONE,
1909 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001910#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001911 (char_u *)"a",
1912#else
1913 (char_u *)"",
1914#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001915 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001916 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1917#ifdef FEAT_GUI
1918 (char_u *)&p_mousef, PV_NONE,
1919#else
1920 (char_u *)NULL, PV_NONE,
1921#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001922 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001923 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1924#ifdef FEAT_GUI
1925 (char_u *)&p_mh, PV_NONE,
1926#else
1927 (char_u *)NULL, PV_NONE,
1928#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001929 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001930 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1931 (char_u *)&p_mousem, PV_NONE,
1932 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001933#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001934 (char_u *)"popup",
1935#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001936# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937 (char_u *)"popup_setpos",
1938# else
1939 (char_u *)"extend",
1940# endif
1941#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001942 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001943 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944#ifdef FEAT_MOUSESHAPE
1945 (char_u *)&p_mouseshape, PV_NONE,
1946 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1947#else
1948 (char_u *)NULL, PV_NONE,
1949 {(char_u *)NULL, (char_u *)0L}
1950#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001951 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001952 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1953 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001954 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001955 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1956#if defined(DYNAMIC_MZSCHEME)
1957 (char_u *)&p_mzschemedll, PV_NONE,
1958 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1959#else
1960 (char_u *)NULL, PV_NONE,
1961 {(char_u *)"", (char_u *)0L}
1962#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001963 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001964 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1965#if defined(DYNAMIC_MZSCHEME)
1966 (char_u *)&p_mzschemegcdll, PV_NONE,
1967 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1968#else
1969 (char_u *)NULL, PV_NONE,
1970 {(char_u *)"", (char_u *)0L}
1971#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001972 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001973 {"mzquantum", "mzq", P_NUM,
1974#ifdef FEAT_MZSCHEME
1975 (char_u *)&p_mzq, PV_NONE,
1976#else
1977 (char_u *)NULL, PV_NONE,
1978#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001979 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 {"novice", NULL, P_BOOL|P_VI_DEF,
1981 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001982 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001983 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001984 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001985 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001986 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001987 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1988 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001989 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001990 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1991#ifdef FEAT_LINEBREAK
1992 (char_u *)VAR_WIN, PV_NUW,
1993#else
1994 (char_u *)NULL, PV_NONE,
1995#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001996 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001997 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001998#ifdef FEAT_COMPL_FUNC
1999 (char_u *)&p_ofu, PV_OFU,
2000 {(char_u *)"", (char_u *)0L}
2001#else
2002 (char_u *)NULL, PV_NONE,
2003 {(char_u *)0L, (char_u *)0L}
2004#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002005 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002006 {"open", NULL, P_BOOL|P_VI_DEF,
2007 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002008 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002009 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002010#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002011 (char_u *)&p_odev, PV_NONE,
2012#else
2013 (char_u *)NULL, PV_NONE,
2014#endif
2015 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002016 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002017 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2018 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002019 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 {"optimize", "opt", P_BOOL|P_VI_DEF,
2021 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002022 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002023 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002025 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002026 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2027 |P_SECURE,
2028 (char_u *)&p_pp, PV_NONE,
2029 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002030 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002031 {"paragraphs", "para", P_STRING|P_VI_DEF,
2032 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002033 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002034 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002035 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002036 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002037 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2039 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002040 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002041 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2042#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2043 (char_u *)&p_pex, PV_NONE,
2044 {(char_u *)"", (char_u *)0L}
2045#else
2046 (char_u *)NULL, PV_NONE,
2047 {(char_u *)0L, (char_u *)0L}
2048#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002049 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002050 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002052 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002054 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002056#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002057 (char_u *)".,,",
2058#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002060#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002061 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002062 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002063#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002064 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002065 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002066#else
2067 (char_u *)NULL, PV_NONE,
2068 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002069#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002070 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002071 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2072 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002073 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002074 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002075#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002076 (char_u *)&p_pvh, PV_NONE,
2077#else
2078 (char_u *)NULL, PV_NONE,
2079#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002080 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002082#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002083 (char_u *)VAR_WIN, PV_PVW,
2084#else
2085 (char_u *)NULL, PV_NONE,
2086#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002087 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002088 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002089#ifdef FEAT_PRINTER
2090 (char_u *)&p_pdev, PV_NONE,
2091 {(char_u *)"", (char_u *)0L}
2092#else
2093 (char_u *)NULL, PV_NONE,
2094 {(char_u *)NULL, (char_u *)0L}
2095#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002096 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002097 {"printencoding", "penc", P_STRING|P_VI_DEF,
2098#ifdef FEAT_POSTSCRIPT
2099 (char_u *)&p_penc, PV_NONE,
2100 {(char_u *)"", (char_u *)0L}
2101#else
2102 (char_u *)NULL, PV_NONE,
2103 {(char_u *)NULL, (char_u *)0L}
2104#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002105 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002106 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107#ifdef FEAT_POSTSCRIPT
2108 (char_u *)&p_pexpr, PV_NONE,
2109 {(char_u *)"", (char_u *)0L}
2110#else
2111 (char_u *)NULL, PV_NONE,
2112 {(char_u *)NULL, (char_u *)0L}
2113#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002114 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002115 {"printfont", "pfn", P_STRING|P_VI_DEF,
2116#ifdef FEAT_PRINTER
2117 (char_u *)&p_pfn, PV_NONE,
2118 {
2119# ifdef MSWIN
2120 (char_u *)"Courier_New:h10",
2121# else
2122 (char_u *)"courier",
2123# endif
2124 (char_u *)0L}
2125#else
2126 (char_u *)NULL, PV_NONE,
2127 {(char_u *)NULL, (char_u *)0L}
2128#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002129 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002130 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2131#ifdef FEAT_PRINTER
2132 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002133 /* untranslated to avoid problems when 'encoding'
2134 * is changed */
2135 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002136#else
2137 (char_u *)NULL, PV_NONE,
2138 {(char_u *)NULL, (char_u *)0L}
2139#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002140 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002141 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002142#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002143 (char_u *)&p_pmcs, PV_NONE,
2144 {(char_u *)"", (char_u *)0L}
2145#else
2146 (char_u *)NULL, PV_NONE,
2147 {(char_u *)NULL, (char_u *)0L}
2148#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002149 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002150 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002151#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002152 (char_u *)&p_pmfn, PV_NONE,
2153 {(char_u *)"", (char_u *)0L}
2154#else
2155 (char_u *)NULL, PV_NONE,
2156 {(char_u *)NULL, (char_u *)0L}
2157#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002158 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002159 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002160#ifdef FEAT_PRINTER
2161 (char_u *)&p_popt, PV_NONE,
2162 {(char_u *)"", (char_u *)0L}
2163#else
2164 (char_u *)NULL, PV_NONE,
2165 {(char_u *)NULL, (char_u *)0L}
2166#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002167 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002168 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002169 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002170 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002171 {"pumheight", "ph", P_NUM|P_VI_DEF,
2172#ifdef FEAT_INS_EXPAND
2173 (char_u *)&p_ph, PV_NONE,
2174#else
2175 (char_u *)NULL, PV_NONE,
2176#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002177 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002178 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2179#ifdef FEAT_INS_EXPAND
2180 (char_u *)&p_pw, PV_NONE,
2181#else
2182 (char_u *)NULL, PV_NONE,
2183#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002184 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002185 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002186#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002187 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002188 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002189#else
2190 (char_u *)NULL, PV_NONE,
2191 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002192#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002193 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002194 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2195#if defined(FEAT_PYTHON3)
2196 (char_u *)&p_py3home, PV_NONE,
2197 {(char_u *)"", (char_u *)0L}
2198#else
2199 (char_u *)NULL, PV_NONE,
2200 {(char_u *)NULL, (char_u *)0L}
2201#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002202 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002203 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002204#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002205 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002206 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002207#else
2208 (char_u *)NULL, PV_NONE,
2209 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002210#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002211 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002212 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2213#if defined(FEAT_PYTHON)
2214 (char_u *)&p_pyhome, PV_NONE,
2215 {(char_u *)"", (char_u *)0L}
2216#else
2217 (char_u *)NULL, PV_NONE,
2218 {(char_u *)NULL, (char_u *)0L}
2219#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002220 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002221 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2222#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2223 (char_u *)&p_pyx, PV_NONE,
2224#else
2225 (char_u *)NULL, PV_NONE,
2226#endif
2227 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002228 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002229 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2230#ifdef FEAT_TEXTOBJ
2231 (char_u *)&p_qe, PV_QE,
2232 {(char_u *)"\\", (char_u *)0L}
2233#else
2234 (char_u *)NULL, PV_NONE,
2235 {(char_u *)NULL, (char_u *)0L}
2236#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002237 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002238 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2239 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002240 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 {"redraw", NULL, P_BOOL|P_VI_DEF,
2242 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002243 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002244 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2245#ifdef FEAT_RELTIME
2246 (char_u *)&p_rdt, PV_NONE,
2247#else
2248 (char_u *)NULL, PV_NONE,
2249#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002250 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002251 {"regexpengine", "re", P_NUM|P_VI_DEF,
2252 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002253 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002254 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2255 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002256 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002257 {"remap", NULL, P_BOOL|P_VI_DEF,
2258 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002259 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002260 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002261#ifdef FEAT_RENDER_OPTIONS
2262 (char_u *)&p_rop, PV_NONE,
2263 {(char_u *)"", (char_u *)0L}
2264#else
2265 (char_u *)NULL, PV_NONE,
2266 {(char_u *)NULL, (char_u *)0L}
2267#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002268 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002269 {"report", NULL, P_NUM|P_VI_DEF,
2270 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002271 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002273#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002274 (char_u *)&p_rs, PV_NONE,
2275#else
2276 (char_u *)NULL, PV_NONE,
2277#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002278 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2280#ifdef FEAT_RIGHTLEFT
2281 (char_u *)&p_ri, PV_NONE,
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 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2287#ifdef FEAT_RIGHTLEFT
2288 (char_u *)VAR_WIN, PV_RL,
2289#else
2290 (char_u *)NULL, PV_NONE,
2291#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002292 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002293 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2294#ifdef FEAT_RIGHTLEFT
2295 (char_u *)VAR_WIN, PV_RLC,
2296 {(char_u *)"search", (char_u *)NULL}
2297#else
2298 (char_u *)NULL, PV_NONE,
2299 {(char_u *)NULL, (char_u *)0L}
2300#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002301 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002302 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002303#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002304 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002305 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002306#else
2307 (char_u *)NULL, PV_NONE,
2308 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002309#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002310 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002311 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2312#ifdef FEAT_CMDL_INFO
2313 (char_u *)&p_ru, PV_NONE,
2314#else
2315 (char_u *)NULL, PV_NONE,
2316#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002317 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002318 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002319#ifdef FEAT_STL_OPT
2320 (char_u *)&p_ruf, PV_NONE,
2321#else
2322 (char_u *)NULL, PV_NONE,
2323#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002324 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002325 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2326 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002327 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002328 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002329 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2331 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002332 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002334 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002335 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2337 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002338 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002340 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002341 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002342 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 (char_u *)&p_sbo, PV_NONE,
2344 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002345 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"sections", "sect", P_STRING|P_VI_DEF,
2347 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002348 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002349 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2351 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002352 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002355 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002356 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002357 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002358 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002359 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002360 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361#ifdef FEAT_SESSION
2362 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002363 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 (char_u *)0L}
2365#else
2366 (char_u *)NULL, PV_NONE,
2367 {(char_u *)0L, (char_u *)0L}
2368#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002369 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002370 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2371 (char_u *)&p_sh, PV_NONE,
2372 {
2373#ifdef VMS
2374 (char_u *)"-",
2375#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002376# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002377 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002378# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380# endif
2381#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002382 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2384 (char_u *)&p_shcf, PV_NONE,
2385 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002386#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 (char_u *)"/c",
2388#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002391 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2393#ifdef FEAT_QUICKFIX
2394 (char_u *)&p_sp, PV_NONE,
2395 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002396#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398#else
2399 (char_u *)">",
2400#endif
2401 (char_u *)0L}
2402#else
2403 (char_u *)NULL, PV_NONE,
2404 {(char_u *)0L, (char_u *)0L}
2405#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002406 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2408 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002409 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2411 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002412 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2414#ifdef BACKSLASH_IN_FILENAME
2415 (char_u *)&p_ssl, PV_NONE,
2416#else
2417 (char_u *)NULL, PV_NONE,
2418#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002419 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002420 {"shelltemp", "stmp", P_BOOL,
2421 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002422 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"shelltype", "st", P_NUM|P_VI_DEF,
2424#ifdef AMIGA
2425 (char_u *)&p_st, PV_NONE,
2426#else
2427 (char_u *)NULL, PV_NONE,
2428#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002429 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2431 (char_u *)&p_sxq, PV_NONE,
2432 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002433#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 (char_u *)"\"",
2435#else
2436 (char_u *)"",
2437#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002438 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002439 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2440 (char_u *)&p_sxe, PV_NONE,
2441 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002442#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002443 (char_u *)"\"&|<>()@^",
2444#else
2445 (char_u *)"",
2446#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002447 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002448 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2449 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002450 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2452 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002453 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2455 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02002456 {(char_u *)"S", (char_u *)"filnxtToOS"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002457 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002460 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2462#ifdef FEAT_LINEBREAK
2463 (char_u *)&p_sbr, PV_NONE,
2464#else
2465 (char_u *)NULL, PV_NONE,
2466#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002467 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"showcmd", "sc", P_BOOL|P_VIM,
2469#ifdef FEAT_CMDL_INFO
2470 (char_u *)&p_sc, PV_NONE,
2471#else
2472 (char_u *)NULL, PV_NONE,
2473#endif
2474 {(char_u *)FALSE,
2475#ifdef UNIX
2476 (char_u *)FALSE
2477#else
2478 (char_u *)TRUE
2479#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002480 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002481 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2482 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002483 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2485 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002486 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"showmode", "smd", P_BOOL|P_VIM,
2488 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002489 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002490 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002491 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002492 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002493 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2494 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002495 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002497 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002498 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002499 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2500#ifdef FEAT_SIGNS
2501 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002502 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002503#else
2504 (char_u *)NULL, PV_NONE,
2505 {(char_u *)NULL, (char_u *)0L}
2506#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002507 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002508 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2509 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002510 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2512 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002513 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2515#ifdef FEAT_SMARTINDENT
2516 (char_u *)&p_si, PV_SI,
2517#else
2518 (char_u *)NULL, PV_NONE,
2519#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002520 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2522 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002523 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2525 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002526 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2528 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002529 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002530 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002531#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002532 (char_u *)VAR_WIN, PV_SPELL,
2533#else
2534 (char_u *)NULL, PV_NONE,
2535#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002536 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002537 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002538#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002539 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002540 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002541#else
2542 (char_u *)NULL, PV_NONE,
2543 {(char_u *)0L, (char_u *)0L}
2544#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002545 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002546 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2547 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002548#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002549 (char_u *)&p_spf, PV_SPF,
2550 {(char_u *)"", (char_u *)0L}
2551#else
2552 (char_u *)NULL, PV_NONE,
2553 {(char_u *)0L, (char_u *)0L}
2554#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002555 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002556 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2557 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002558#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002559 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002560 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)0L, (char_u *)0L}
2564#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002565 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002566 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002567#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002568 (char_u *)&p_sps, PV_NONE,
2569 {(char_u *)"best", (char_u *)0L}
2570#else
2571 (char_u *)NULL, PV_NONE,
2572 {(char_u *)0L, (char_u *)0L}
2573#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002574 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002576 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002577 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002580 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002581 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2582 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002583 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002584 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002586 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587#else
2588 (char_u *)NULL, PV_NONE,
2589#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002590 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002591 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 (char_u *)&p_su, PV_NONE,
2593 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002594 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002595 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002596#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597 (char_u *)&p_sua, PV_SUA,
2598 {(char_u *)"", (char_u *)0L}
2599#else
2600 (char_u *)NULL, PV_NONE,
2601 {(char_u *)0L, (char_u *)0L}
2602#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002603 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002604 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2605 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002606 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"swapsync", "sws", P_STRING|P_VI_DEF,
2608 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002609 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002610 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002611 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002612 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002613 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2614#ifdef FEAT_SYN_HL
2615 (char_u *)&p_smc, PV_SMC,
2616 {(char_u *)3000L, (char_u *)0L}
2617#else
2618 (char_u *)NULL, PV_NONE,
2619 {(char_u *)0L, (char_u *)0L}
2620#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002621 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002622 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002623#ifdef FEAT_SYN_HL
2624 (char_u *)&p_syn, PV_SYN,
2625 {(char_u *)"", (char_u *)0L}
2626#else
2627 (char_u *)NULL, PV_NONE,
2628 {(char_u *)0L, (char_u *)0L}
2629#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002630 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002631 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL|P_MLE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002632#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002633 (char_u *)&p_tal, PV_NONE,
2634#else
2635 (char_u *)NULL, PV_NONE,
2636#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002637 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002638 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002639 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002640 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002641 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2642 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002643 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2645 (char_u *)&p_tbs, PV_NONE,
2646#ifdef VMS /* binary searching doesn't appear to work on VMS */
2647 {(char_u *)0L, (char_u *)0L}
2648#else
2649 {(char_u *)TRUE, (char_u *)0L}
2650#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002651 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002652 {"tagcase", "tc", P_STRING|P_VIM,
2653 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002654 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002655 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2656#ifdef FEAT_EVAL
2657 (char_u *)&p_tfu, PV_TFU,
2658 {(char_u *)"", (char_u *)0L}
2659#else
2660 (char_u *)NULL, PV_NONE,
2661 {(char_u *)0L, (char_u *)0L}
2662#endif
2663 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002664 {"taglength", "tl", P_NUM|P_VI_DEF,
2665 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002666 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"tagrelative", "tr", P_BOOL|P_VIM,
2668 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002669 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002670 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002671 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002672 {
2673#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2674 (char_u *)"./tags,./TAGS,tags,TAGS",
2675#else
2676 (char_u *)"./tags,tags",
2677#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002678 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002679 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2680 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002681 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002682 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002683#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002684 (char_u *)&p_tcldll, PV_NONE,
2685 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002686#else
2687 (char_u *)NULL, PV_NONE,
2688 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002689#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002690 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002691 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2692 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002693 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2695#ifdef FEAT_ARABIC
2696 (char_u *)&p_tbidi, PV_NONE,
2697#else
2698 (char_u *)NULL, PV_NONE,
2699#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002700 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 (char_u *)&p_tenc, PV_NONE,
2703 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002704 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002705 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2706#ifdef FEAT_TERMGUICOLORS
2707 (char_u *)&p_tgc, PV_NONE,
2708 {(char_u *)FALSE, (char_u *)FALSE}
2709#else
2710 (char_u*)NULL, PV_NONE,
2711 {(char_u *)FALSE, (char_u *)FALSE}
2712#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002713 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002714 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2715#ifdef FEAT_TERMINAL
2716 (char_u *)VAR_WIN, PV_TWK,
2717 {(char_u *)"", (char_u *)NULL}
2718#else
2719 (char_u *)NULL, PV_NONE,
2720 {(char_u *)NULL, (char_u *)0L}
2721#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002722 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002723 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2724#ifdef FEAT_TERMINAL
2725 (char_u *)&p_twsl, PV_TWSL,
2726 {(char_u *)10000L, (char_u *)10000L}
2727#else
2728 (char_u *)NULL, PV_NONE,
2729 {(char_u *)NULL, (char_u *)0L}
2730#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002731 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002732 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2733#ifdef FEAT_TERMINAL
2734 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002735 {(char_u *)"", (char_u *)NULL}
2736#else
2737 (char_u *)NULL, PV_NONE,
2738 {(char_u *)NULL, (char_u *)0L}
2739#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002740 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002741 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002742#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002743 (char_u *)&p_twt, PV_NONE,
2744 {(char_u *)"", (char_u *)NULL}
2745#else
2746 (char_u *)NULL, PV_NONE,
2747 {(char_u *)NULL, (char_u *)0L}
2748#endif
2749 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002750 {"terse", NULL, P_BOOL|P_VI_DEF,
2751 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002752 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"textauto", "ta", P_BOOL|P_VIM,
2754 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002755 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002756 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002757 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2758 (char_u *)&p_tx, PV_TX,
2759 {
2760#ifdef USE_CRNL
2761 (char_u *)TRUE,
2762#else
2763 (char_u *)FALSE,
2764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002765 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002766 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002768 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002769 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002771 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772#else
2773 (char_u *)NULL, PV_NONE,
2774#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002775 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002776 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2777 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002778 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002779 {"timeout", "to", P_BOOL|P_VI_DEF,
2780 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002781 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2783 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002784 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002785 {"title", NULL, P_BOOL|P_VI_DEF,
2786#ifdef FEAT_TITLE
2787 (char_u *)&p_title, PV_NONE,
2788#else
2789 (char_u *)NULL, PV_NONE,
2790#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002791 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 {"titlelen", NULL, P_NUM|P_VI_DEF,
2793#ifdef FEAT_TITLE
2794 (char_u *)&p_titlelen, PV_NONE,
2795#else
2796 (char_u *)NULL, PV_NONE,
2797#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002798 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002799 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002800#ifdef FEAT_TITLE
2801 (char_u *)&p_titleold, PV_NONE,
2802 {(char_u *)N_("Thanks for flying Vim"),
2803 (char_u *)0L}
2804#else
2805 (char_u *)NULL, PV_NONE,
2806 {(char_u *)0L, (char_u *)0L}
2807#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002808 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002809 {"titlestring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810#ifdef FEAT_TITLE
2811 (char_u *)&p_titlestring, PV_NONE,
2812#else
2813 (char_u *)NULL, PV_NONE,
2814#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002815 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002816 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002817#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002818 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002819 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002820#else
2821 (char_u *)NULL, PV_NONE,
2822 {(char_u *)0L, (char_u *)0L}
2823#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002824 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002826#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002827 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002828 {(char_u *)"small", (char_u *)0L}
2829#else
2830 (char_u *)NULL, PV_NONE,
2831 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002833 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2835 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002836 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2838 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002839 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002840 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2841 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002842 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002843 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2844 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002845 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002846 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2847#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2848 (char_u *)&p_ttym, PV_NONE,
2849#else
2850 (char_u *)NULL, PV_NONE,
2851#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002852 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2854 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002855 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2857 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002858 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002859 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2860 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002861#ifdef FEAT_PERSISTENT_UNDO
2862 (char_u *)&p_udir, PV_NONE,
2863 {(char_u *)".", (char_u *)0L}
2864#else
2865 (char_u *)NULL, PV_NONE,
2866 {(char_u *)0L, (char_u *)0L}
2867#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002868 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002869 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2870#ifdef FEAT_PERSISTENT_UNDO
2871 (char_u *)&p_udf, PV_UDF,
2872#else
2873 (char_u *)NULL, PV_NONE,
2874#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002875 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002877 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002878 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002879#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002880 (char_u *)1000L,
2881#else
2882 (char_u *)100L,
2883#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002884 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002885 {"undoreload", "ur", P_NUM|P_VI_DEF,
2886 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002887 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 {"updatecount", "uc", P_NUM|P_VI_DEF,
2889 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002890 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002891 {"updatetime", "ut", P_NUM|P_VI_DEF,
2892 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002893 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002894 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2895#ifdef FEAT_VARTABS
2896 (char_u *)&p_vsts, PV_VSTS,
2897 {(char_u *)"", (char_u *)0L}
2898#else
2899 (char_u *)NULL, PV_NONE,
2900 {(char_u *)"", (char_u *)NULL}
2901#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002902 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002903 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2904#ifdef FEAT_VARTABS
2905 (char_u *)&p_vts, PV_VTS,
2906 {(char_u *)"", (char_u *)0L}
2907#else
2908 (char_u *)NULL, PV_NONE,
2909 {(char_u *)"", (char_u *)NULL}
2910#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002911 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002912 {"verbose", "vbs", P_NUM|P_VI_DEF,
2913 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002914 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002915 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2916 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002917 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002918 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2919#ifdef FEAT_SESSION
2920 (char_u *)&p_vdir, PV_NONE,
2921 {(char_u *)DFLT_VDIR, (char_u *)0L}
2922#else
2923 (char_u *)NULL, PV_NONE,
2924 {(char_u *)0L, (char_u *)0L}
2925#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002926 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002927 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928#ifdef FEAT_SESSION
2929 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002930 {(char_u *)"folds,options,cursor,curdir",
2931 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002932#else
2933 (char_u *)NULL, PV_NONE,
2934 {(char_u *)0L, (char_u *)0L}
2935#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002936 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002937 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938#ifdef FEAT_VIMINFO
2939 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002940#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002941 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942#else
2943# ifdef AMIGA
2944 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002945 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002946# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002947 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948# endif
2949#endif
2950#else
2951 (char_u *)NULL, PV_NONE,
2952 {(char_u *)0L, (char_u *)0L}
2953#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002954 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002955 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2956 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002957#ifdef FEAT_VIMINFO
2958 (char_u *)&p_viminfofile, PV_NONE,
2959 {(char_u *)"", (char_u *)0L}
2960#else
2961 (char_u *)NULL, PV_NONE,
2962 {(char_u *)0L, (char_u *)0L}
2963#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002964 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002965 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2966 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002967 (char_u *)&p_ve, PV_NONE,
2968 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002969 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002970 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2971 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002972 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002973 {"w300", NULL, P_NUM|P_VI_DEF,
2974 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002975 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002976 {"w1200", NULL, P_NUM|P_VI_DEF,
2977 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002978 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002979 {"w9600", NULL, P_NUM|P_VI_DEF,
2980 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002981 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002982 {"warn", NULL, P_BOOL|P_VI_DEF,
2983 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002984 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2986 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002987 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002988 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002990 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002991 {"wildchar", "wc", P_NUM|P_VIM,
2992 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002993 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002994 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002995 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002997 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002998 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999#ifdef FEAT_WILDIGN
3000 (char_u *)&p_wig, PV_NONE,
3001#else
3002 (char_u *)NULL, PV_NONE,
3003#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003004 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003005 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3006 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003007 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003008 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3009#ifdef FEAT_WILDMENU
3010 (char_u *)&p_wmnu, PV_NONE,
3011#else
3012 (char_u *)NULL, PV_NONE,
3013#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003014 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003015 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003016 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003017 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003018 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3019#ifdef FEAT_CMDL_COMPL
3020 (char_u *)&p_wop, PV_NONE,
3021 {(char_u *)"", (char_u *)0L}
3022#else
3023 (char_u *)NULL, PV_NONE,
3024 {(char_u *)NULL, (char_u *)0L}
3025#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003026 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003027 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3028#ifdef FEAT_WAK
3029 (char_u *)&p_wak, PV_NONE,
3030 {(char_u *)"menu", (char_u *)0L}
3031#else
3032 (char_u *)NULL, PV_NONE,
3033 {(char_u *)NULL, (char_u *)0L}
3034#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003035 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003037 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003038 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003041 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003043 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003044 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003045 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003046 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003047 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003050 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003051 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003052 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003053 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003054 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003055#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003056 (char_u *)&p_winptydll, PV_NONE, {
3057# ifdef _WIN64
3058 (char_u *)"winpty64.dll",
3059# else
3060 (char_u *)"winpty32.dll",
3061# endif
3062 (char_u *)0L}
3063#else
3064 (char_u *)NULL, PV_NONE,
3065 {(char_u *)0L, (char_u *)0L}
3066#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003067 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003068 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003070 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003071 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3072 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003073 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3075 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003076 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3078 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003079 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 {"write", NULL, P_BOOL|P_VI_DEF,
3081 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003082 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 {"writeany", "wa", P_BOOL|P_VI_DEF,
3084 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003085 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3087 (char_u *)&p_wb, PV_NONE,
3088 {
3089#ifdef FEAT_WRITEBACKUP
3090 (char_u *)TRUE,
3091#else
3092 (char_u *)FALSE,
3093#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003094 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003095 {"writedelay", "wd", P_NUM|P_VI_DEF,
3096 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003097 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003098
3099/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003100#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003102 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003103
3104 p_term("t_AB", T_CAB)
3105 p_term("t_AF", T_CAF)
3106 p_term("t_AL", T_CAL)
3107 p_term("t_al", T_AL)
3108 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003109 p_term("t_BE", T_BE)
3110 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003111 p_term("t_cd", T_CD)
3112 p_term("t_ce", T_CE)
3113 p_term("t_cl", T_CL)
3114 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003115 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116 p_term("t_Co", T_CCO)
3117 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003118 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003120 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003121 p_term("t_da", T_DA)
3122 p_term("t_db", T_DB)
3123 p_term("t_DL", T_CDL)
3124 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003125 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003126 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003128 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003129 p_term("t_IE", T_CIE)
3130 p_term("t_IS", T_CIS)
3131 p_term("t_ke", T_KE)
3132 p_term("t_ks", T_KS)
3133 p_term("t_le", T_LE)
3134 p_term("t_mb", T_MB)
3135 p_term("t_md", T_MD)
3136 p_term("t_me", T_ME)
3137 p_term("t_mr", T_MR)
3138 p_term("t_ms", T_MS)
3139 p_term("t_nd", T_ND)
3140 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003141 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003142 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003143 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003145 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003146 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003147 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003148 p_term("t_RV", T_CRV)
3149 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003150 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003151 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003152 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003153 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003154 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003155 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003157 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003159 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003160 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003161 p_term("t_te", T_TE)
3162 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003163 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003164 p_term("t_ts", T_TS)
3165 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003166 p_term("t_ue", T_UE)
3167 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003168 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_vb", T_VB)
3170 p_term("t_ve", T_VE)
3171 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003172 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 p_term("t_vs", T_VS)
3174 p_term("t_WP", T_CWP)
3175 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003176 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003177 p_term("t_xs", T_XS)
3178 p_term("t_ZH", T_CZH)
3179 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003180 p_term("t_8f", T_8F)
3181 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003182
3183/* terminal key codes are not in here */
3184
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003185 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003186 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187};
3188
3189#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3190
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003193static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003194static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003195#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003196static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003197#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003198#ifdef FEAT_CMDL_COMPL
3199static char *(p_wop_values[]) = {"tagfile", NULL};
3200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201#ifdef FEAT_WAK
3202static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3203#endif
3204static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3206static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208#ifdef FEAT_BROWSE
3209static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003212static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003213static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003214static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003215static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3217#ifdef FEAT_FOLDING
3218static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003219# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003221# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222 NULL};
3223static char *(p_fcl_values[]) = {"all", NULL};
3224#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003225#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003226static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003227#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003228#ifdef FEAT_SIGNS
3229static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3230#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003231#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003232static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003233#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003235static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003236static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003237static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003238static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003239static char_u *option_expand(int opt_idx, char_u *val);
3240static void didset_options(void);
3241static void didset_options2(void);
3242static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003243#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003244static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003245#else
3246# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3247#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003248static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003249static 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);
3250static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003252static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003254#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003255static char *did_set_spell_option(int is_spellfile);
3256static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003257#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003258#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003259static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003260#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003261static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3262static 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 +01003263static void check_redraw(long_u flags);
3264static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003265static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static void showoptions(int all, int opt_flags);
3267static int optval_default(struct vimoption *, char_u *varp);
3268static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003269static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003270static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3271static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3272static int istermoption(struct vimoption *);
3273static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3274static char_u *get_varp(struct vimoption *);
3275static void option_value2string(struct vimoption *, int opt_flags);
3276static void check_winopt(winopt_T *wop);
3277static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003279static void langmap_init(void);
3280static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003281#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003282static void paste_option_changed(void);
3283static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003284#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003285static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003286#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3288static int check_opt_strings(char_u *val, char **values, int);
3289static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003290#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003291static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003292#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003293
3294/*
3295 * Initialize the options, first part.
3296 *
3297 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003298 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003299 */
3300 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003301set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302{
3303 char_u *p;
3304 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003305 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003306
3307#ifdef FEAT_LANGMAP
3308 langmap_init();
3309#endif
3310
3311 /* Be Vi compatible by default */
3312 p_cp = TRUE;
3313
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003314 /* Use POSIX compatibility when $VIM_POSIX is set. */
3315 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003316 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003317 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003318 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003319 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003320
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321 /*
3322 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003323 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003325 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003326#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003327 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003328 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003329#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003330 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003331 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332
3333#ifdef FEAT_WILDIGN
3334 /*
3335 * Set the default for 'backupskip' to include environment variables for
3336 * temp files.
3337 */
3338 {
3339# ifdef UNIX
3340 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3341# else
3342 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3343# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003344 int len;
3345 garray_T ga;
3346 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003347
3348 ga_init2(&ga, 1, 100);
3349 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3350 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003351 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003352# ifdef UNIX
3353 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003354# ifdef MACOS_X
3355 p = (char_u *)"/private/tmp";
3356# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003358# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003359 else
3360# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003361 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362 if (p != NULL && *p != NUL)
3363 {
3364 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003365 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366 if (ga_grow(&ga, len) == OK)
3367 {
3368 if (ga.ga_len > 0)
3369 STRCAT(ga.ga_data, ",");
3370 STRCAT(ga.ga_data, p);
3371 add_pathsep(ga.ga_data);
3372 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373 ga.ga_len += len;
3374 }
3375 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003376 if (mustfree)
3377 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003378 }
3379 if (ga.ga_data != NULL)
3380 {
3381 set_string_default("bsk", ga.ga_data);
3382 vim_free(ga.ga_data);
3383 }
3384 }
3385#endif
3386
3387 /*
3388 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3389 */
3390 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003391 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003393#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3394 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3395#endif
3396 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003397#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003398 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003399 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400#else
3401# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003402 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003403 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003405 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406# endif
3407#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003408 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003409 opt_idx = findoption((char_u *)"maxmem");
3410 if (opt_idx >= 0)
3411 {
3412#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003413 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3414 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003415#endif
3416 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3417 }
3418 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419 }
3420
Bram Moolenaar071d4272004-06-13 20:20:40 +00003421#ifdef FEAT_SEARCHPATH
3422 {
3423 char_u *cdpath;
3424 char_u *buf;
3425 int i;
3426 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003427 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003428
3429 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003430 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431 if (cdpath != NULL)
3432 {
3433 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3434 if (buf != NULL)
3435 {
3436 buf[0] = ','; /* start with ",", current dir first */
3437 j = 1;
3438 for (i = 0; cdpath[i] != NUL; ++i)
3439 {
3440 if (vim_ispathlistsep(cdpath[i]))
3441 buf[j++] = ',';
3442 else
3443 {
3444 if (cdpath[i] == ' ' || cdpath[i] == ',')
3445 buf[j++] = '\\';
3446 buf[j++] = cdpath[i];
3447 }
3448 }
3449 buf[j] = NUL;
3450 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003451 if (opt_idx >= 0)
3452 {
3453 options[opt_idx].def_val[VI_DEFAULT] = buf;
3454 options[opt_idx].flags |= P_DEF_ALLOCED;
3455 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003456 else
3457 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003459 if (mustfree)
3460 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461 }
3462 }
3463#endif
3464
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003465#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003466 /* Set print encoding on platforms that don't default to latin1 */
3467 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003468# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 (char_u *)"cp1252"
3470# else
3471# ifdef VMS
3472 (char_u *)"dec-mcs"
3473# else
3474# ifdef EBCDIC
3475 (char_u *)"ebcdic-uk"
3476# else
3477# ifdef MAC
3478 (char_u *)"mac-roman"
3479# else /* HPUX */
3480 (char_u *)"hp-roman8"
3481# endif
3482# endif
3483# endif
3484# endif
3485 );
3486#endif
3487
3488#ifdef FEAT_POSTSCRIPT
3489 /* 'printexpr' must be allocated to be able to evaluate it. */
3490 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003491# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003492 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003493# else
3494# ifdef VMS
3495 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3496
3497# else
3498 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3499# endif
3500# endif
3501 );
3502#endif
3503
3504 /*
3505 * Set all the options (except the terminal options) to their default
3506 * value. Also set the global value for local options.
3507 */
3508 set_options_default(0);
3509
Bram Moolenaar07268702018-03-01 21:57:32 +01003510#ifdef CLEAN_RUNTIMEPATH
3511 if (clean_arg)
3512 {
3513 opt_idx = findoption((char_u *)"runtimepath");
3514 if (opt_idx >= 0)
3515 {
3516 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3517 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3518 }
3519 opt_idx = findoption((char_u *)"packpath");
3520 if (opt_idx >= 0)
3521 {
3522 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3523 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3524 }
3525 }
3526#endif
3527
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528#ifdef FEAT_GUI
3529 if (found_reverse_arg)
3530 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3531#endif
3532
3533 curbuf->b_p_initialized = TRUE;
3534 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003535 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003536 check_buf_options(curbuf);
3537 check_win_options(curwin);
3538 check_options();
3539
3540 /* Must be before option_expand(), because that one needs vim_isIDc() */
3541 didset_options();
3542
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003543#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003544 /* Use the current chartab for the generic chartab. This is not in
3545 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003546 init_spell_chartab();
3547#endif
3548
Bram Moolenaar071d4272004-06-13 20:20:40 +00003549 /*
3550 * Expand environment variables and things like "~" for the defaults.
3551 * If option_expand() returns non-NULL the variable is expanded. This can
3552 * only happen for non-indirect options.
3553 * Also set the default to the expanded value, so ":set" does not list
3554 * them.
3555 * Don't set the P_ALLOCED flag, because we don't want to free the
3556 * default.
3557 */
3558 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3559 {
3560 if ((options[opt_idx].flags & P_GETTEXT)
3561 && options[opt_idx].var != NULL)
3562 p = (char_u *)_(*(char **)options[opt_idx].var);
3563 else
3564 p = option_expand(opt_idx, NULL);
3565 if (p != NULL && (p = vim_strsave(p)) != NULL)
3566 {
3567 *(char_u **)options[opt_idx].var = p;
3568 /* VIMEXP
3569 * Defaults for all expanded options are currently the same for Vi
3570 * and Vim. When this changes, add some code here! Also need to
3571 * split P_DEF_ALLOCED in two.
3572 */
3573 if (options[opt_idx].flags & P_DEF_ALLOCED)
3574 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3575 options[opt_idx].def_val[VI_DEFAULT] = p;
3576 options[opt_idx].flags |= P_DEF_ALLOCED;
3577 }
3578 }
3579
Bram Moolenaar071d4272004-06-13 20:20:40 +00003580 save_file_ff(curbuf); /* Buffer is unchanged */
3581
Bram Moolenaar071d4272004-06-13 20:20:40 +00003582#if defined(FEAT_ARABIC)
3583 /* Detect use of mlterm.
3584 * Mlterm is a terminal emulator akin to xterm that has some special
3585 * abilities (bidi namely).
3586 * NOTE: mlterm's author is being asked to 'set' a variable
3587 * instead of an environment variable due to inheritance.
3588 */
3589 if (mch_getenv((char_u *)"MLTERM") != NULL)
3590 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3591#endif
3592
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003593 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003594
Bram Moolenaar4f974752019-02-17 17:44:42 +01003595# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596 /*
3597 * If $LANG isn't set, try to get a good value for it. This makes the
3598 * right language be used automatically. Don't do this for English.
3599 */
3600 if (mch_getenv((char_u *)"LANG") == NULL)
3601 {
3602 char buf[20];
3603
3604 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3605 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3606 * only the first two. */
3607 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3608 (LPTSTR)buf, 20);
3609 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3610 {
3611 /* There are a few exceptions (probably more) */
3612 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3613 STRCPY(buf, "zh_TW");
3614 else if (STRNICMP(buf, "chs", 3) == 0
3615 || STRNICMP(buf, "zhc", 3) == 0)
3616 STRCPY(buf, "zh_CN");
3617 else if (STRNICMP(buf, "jp", 2) == 0)
3618 STRCPY(buf, "ja");
3619 else
3620 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003621 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003622 }
3623 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003624# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003625# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003626 /* Moved to os_mac_conv.c to avoid dependency problems. */
3627 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003628# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003629# endif
3630
3631 /* enc_locale() will try to find the encoding of the current locale. */
3632 p = enc_locale();
3633 if (p != NULL)
3634 {
3635 char_u *save_enc;
3636
3637 /* Try setting 'encoding' and check if the value is valid.
3638 * If not, go back to the default "latin1". */
3639 save_enc = p_enc;
3640 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003641 if (STRCMP(p_enc, "gb18030") == 0)
3642 {
3643 /* We don't support "gb18030", but "cp936" is a good substitute
3644 * for practical purposes, thus use that. It's not an alias to
3645 * still support conversion between gb18030 and utf-8. */
3646 p_enc = vim_strsave((char_u *)"cp936");
3647 vim_free(p);
3648 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649 if (mb_init() == NULL)
3650 {
3651 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003652 if (opt_idx >= 0)
3653 {
3654 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3655 options[opt_idx].flags |= P_DEF_ALLOCED;
3656 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003657
Bram Moolenaard0573012017-10-28 21:11:06 +02003658#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003659 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003660 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003661 /* Adjust the default for 'isprint' and 'iskeyword' to match
3662 * latin1. Also set the defaults for when 'nocompatible' is
3663 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003664 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003665 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003666 set_string_option_direct((char_u *)"isk", -1,
3667 ISK_LATIN1, OPT_FREE, SID_NONE);
3668 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003669 if (opt_idx >= 0)
3670 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003671 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003672 if (opt_idx >= 0)
3673 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003674 (void)init_chartab();
3675 }
3676#endif
3677
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003678#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003679 /* Win32 console: When GetACP() returns a different value from
3680 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003681 if (
3682# ifdef VIMDLL
3683 (!gui.in_use && !gui.starting) &&
3684# endif
3685 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003686 {
3687 char buf[50];
3688
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003689 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3690 * Use an alternative value. */
3691 if (GetConsoleCP() == 0)
3692 sprintf(buf, "cp%ld", (long)GetACP());
3693 else
3694 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003695 p_tenc = vim_strsave((char_u *)buf);
3696 if (p_tenc != NULL)
3697 {
3698 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003699 if (opt_idx >= 0)
3700 {
3701 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3702 options[opt_idx].flags |= P_DEF_ALLOCED;
3703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003704 convert_setup(&input_conv, p_tenc, p_enc);
3705 convert_setup(&output_conv, p_enc, p_tenc);
3706 }
3707 else
3708 p_tenc = empty_option;
3709 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003710#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003711#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003712 /* $HOME may have characters in active code page. */
3713 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003714#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003715 }
3716 else
3717 {
3718 vim_free(p_enc);
3719 p_enc = save_enc;
3720 }
3721 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003722
3723#ifdef FEAT_MULTI_LANG
3724 /* Set the default for 'helplang'. */
3725 set_helplang_default(get_mess_lang());
3726#endif
3727}
3728
3729/*
3730 * Set an option to its default value.
3731 * This does not take care of side effects!
3732 */
3733 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003734set_option_default(
3735 int opt_idx,
3736 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3737 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003738{
3739 char_u *varp; /* pointer to variable for current option */
3740 int dvi; /* index in def_val[] */
3741 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003742 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003743 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3744
3745 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3746 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003747 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003748 {
3749 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3750 if (flags & P_STRING)
3751 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003752 /* Use set_string_option_direct() for local options to handle
3753 * freeing and allocating the value. */
3754 if (options[opt_idx].indir != PV_NONE)
3755 set_string_option_direct(NULL, opt_idx,
3756 options[opt_idx].def_val[dvi], opt_flags, 0);
3757 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003758 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003759 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3760 free_string_option(*(char_u **)(varp));
3761 *(char_u **)varp = options[opt_idx].def_val[dvi];
3762 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003763 }
3764 }
3765 else if (flags & P_NUM)
3766 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003767 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003768 win_comp_scroll(curwin);
3769 else
3770 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003771 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3772
3773 if ((long *)varp == &curwin->w_p_so
3774 || (long *)varp == &curwin->w_p_siso)
3775 // 'scrolloff' and 'sidescrolloff' local values have a
3776 // different default value than the global default.
3777 *(long *)varp = -1;
3778 else
3779 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780 /* May also set global value for local option. */
3781 if (both)
3782 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003783 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003784 }
3785 }
3786 else /* P_BOOL */
3787 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003788 /* the cast to long is required for Manx C, long_i is needed for
3789 * MSVC */
3790 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003791#ifdef UNIX
3792 /* 'modeline' defaults to off for root */
3793 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3794 *(int *)varp = FALSE;
3795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003796 /* May also set global value for local option. */
3797 if (both)
3798 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3799 *(int *)varp;
3800 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003801
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003802 /* The default value is not insecure. */
3803 flagsp = insecure_flag(opt_idx, opt_flags);
3804 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805 }
3806
3807#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003808 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809#endif
3810}
3811
3812/*
3813 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003814 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 */
3816 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003817set_options_default(
3818 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819{
3820 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003821 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003822 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823
3824 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003825 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003826 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003827 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003828# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003829 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003830 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003831# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003832 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 set_option_default(i, opt_flags, p_cp);
3834
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003836 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003838#ifdef FEAT_CINDENT
3839 parse_cino(curbuf);
3840#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841}
3842
3843/*
3844 * Set the Vi-default value of a string option.
3845 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003846 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003848 static void
3849set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850{
3851 char_u *p;
3852 int opt_idx;
3853
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003854 if (escape && vim_strchr(val, ' ') != NULL)
3855 p = vim_strsave_escaped(val, (char_u *)" ");
3856 else
3857 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003858 if (p != NULL) /* we don't want a NULL */
3859 {
3860 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003861 if (opt_idx >= 0)
3862 {
3863 if (options[opt_idx].flags & P_DEF_ALLOCED)
3864 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3865 options[opt_idx].def_val[VI_DEFAULT] = p;
3866 options[opt_idx].flags |= P_DEF_ALLOCED;
3867 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003868 }
3869}
3870
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003871 void
3872set_string_default(char *name, char_u *val)
3873{
3874 set_string_default_esc(name, val, FALSE);
3875}
3876
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877/*
3878 * Set the Vi-default value of a number option.
3879 * Used for 'lines' and 'columns'.
3880 */
3881 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003882set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003884 int opt_idx;
3885
3886 opt_idx = findoption((char_u *)name);
3887 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003888 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003889}
3890
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003891#if defined(EXITFREE) || defined(PROTO)
3892/*
3893 * Free all options.
3894 */
3895 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003896free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003897{
3898 int i;
3899
3900 for (i = 0; !istermoption(&options[i]); i++)
3901 {
3902 if (options[i].indir == PV_NONE)
3903 {
3904 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003905 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003906 free_string_option(*(char_u **)options[i].var);
3907 if (options[i].flags & P_DEF_ALLOCED)
3908 free_string_option(options[i].def_val[VI_DEFAULT]);
3909 }
3910 else if (options[i].var != VAR_WIN
3911 && (options[i].flags & P_STRING))
3912 /* buffer-local option: free global value */
3913 free_string_option(*(char_u **)options[i].var);
3914 }
3915}
3916#endif
3917
3918
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919/*
3920 * Initialize the options, part two: After getting Rows and Columns and
3921 * setting 'term'.
3922 */
3923 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003924set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003926 int idx;
3927
Bram Moolenaar071d4272004-06-13 20:20:40 +00003928 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003929 * 'scroll' defaults to half the window height. The stored default is zero,
3930 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003932 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003933 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003934 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003935 comp_col();
3936
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003937 /*
3938 * 'window' is only for backwards compatibility with Vi.
3939 * Default is Rows - 1.
3940 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003941 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003942 p_window = Rows - 1;
3943 set_number_default("window", Rows - 1);
3944
Bram Moolenaarf740b292006-02-16 22:11:02 +00003945 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003946#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003947 /*
3948 * If 'background' wasn't set by the user, try guessing the value,
3949 * depending on the terminal name. Only need to check for terminals
3950 * with a dark background, that can handle color.
3951 */
3952 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003953 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3954 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003956 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003957 /* don't mark it as set, when starting the GUI it may be
3958 * changed again */
3959 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960 }
3961#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003962
3963#ifdef CURSOR_SHAPE
3964 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3965#endif
3966#ifdef FEAT_MOUSESHAPE
3967 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3968#endif
3969#ifdef FEAT_PRINTER
3970 (void)parse_printoptions(); /* parse 'printoptions' default value */
3971#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972}
3973
3974/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003975 * Return "dark" or "light" depending on the kind of terminal.
3976 * This is just guessing! Recognized are:
3977 * "linux" Linux console
3978 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003979 * "cygwin.*" Cygwin shell
3980 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003981 * We also check the COLORFGBG environment variable, which is set by
3982 * rxvt and derivatives. This variable contains either two or three
3983 * values separated by semicolons; we want the last value in either
3984 * case. If this value is 0-6 or 8, our background is dark.
3985 */
3986 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003987term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003988{
Bram Moolenaar4f974752019-02-17 17:44:42 +01003989#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003990 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003991 return (char_u *)"dark";
3992#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003993 char_u *p;
3994
Bram Moolenaarf740b292006-02-16 22:11:02 +00003995 if (STRCMP(T_NAME, "linux") == 0
3996 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003997 || STRNCMP(T_NAME, "cygwin", 6) == 0
3998 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003999 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4000 && (p = vim_strrchr(p, ';')) != NULL
4001 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4002 && p[2] == NUL))
4003 return (char_u *)"dark";
4004 return (char_u *)"light";
4005#endif
4006}
4007
4008/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009 * Initialize the options, part three: After reading the .vimrc
4010 */
4011 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004012set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004013{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004014#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004015/*
4016 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4017 * This is done after other initializations, where 'shell' might have been
4018 * set, but only if they have not been set before.
4019 */
4020 char_u *p;
4021 int idx_srr;
4022 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004023# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004024 int idx_sp;
4025 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004026# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004027
4028 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004029 if (idx_srr < 0)
4030 do_srr = FALSE;
4031 else
4032 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004033# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004034 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004035 if (idx_sp < 0)
4036 do_sp = FALSE;
4037 else
4038 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004039# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004040 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004041 if (p != NULL)
4042 {
4043 /*
4044 * Default for p_sp is "| tee", for p_srr is ">".
4045 * For known shells it is changed here to include stderr.
4046 */
4047 if ( fnamecmp(p, "csh") == 0
4048 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004049# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050 || fnamecmp(p, "csh.exe") == 0
4051 || fnamecmp(p, "tcsh.exe") == 0
4052# endif
4053 )
4054 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004055# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004056 if (do_sp)
4057 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004058# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004060# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004061 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004062# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004063 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4064 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004065# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004066 if (do_srr)
4067 {
4068 p_srr = (char_u *)">&";
4069 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4070 }
4071 }
4072 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004073 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 if ( fnamecmp(p, "sh") == 0
4075 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004076 || fnamecmp(p, "mksh") == 0
4077 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004079 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004081 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004082# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 || fnamecmp(p, "cmd") == 0
4084 || fnamecmp(p, "sh.exe") == 0
4085 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004086 || fnamecmp(p, "mksh.exe") == 0
4087 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004089 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 || fnamecmp(p, "bash.exe") == 0
4091 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004095# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 if (do_sp)
4097 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004098# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004100# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004102# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4104 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004105# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004106 if (do_srr)
4107 {
4108 p_srr = (char_u *)">%s 2>&1";
4109 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4110 }
4111 }
4112 vim_free(p);
4113 }
4114#endif
4115
Bram Moolenaar4f974752019-02-17 17:44:42 +01004116#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004117 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004118 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4119 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 * This is done after other initializations, where 'shell' might have been
4121 * set, but only if they have not been set before. Default for p_shcf is
4122 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004123 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004125 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004126 {
4127 int idx3;
4128
4129 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004130 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 {
4132 p_shcf = (char_u *)"-c";
4133 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4134 }
4135
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 /* Somehow Win32 requires the quotes around the redirection too */
4137 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004138 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 {
4140 p_sxq = (char_u *)"\"";
4141 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4142 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004144 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4145 {
4146 int idx3;
4147
4148 /*
4149 * cmd.exe on Windows will strip the first and last double quote given
4150 * on the command line, e.g. most of the time things like:
4151 * cmd /c "my path/to/echo" "my args to echo"
4152 * become:
4153 * my path/to/echo" "my args to echo
4154 * when executed.
4155 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004156 * To avoid this, set shellxquote to surround the command in
4157 * parenthesis. This appears to make most commands work, without
4158 * breaking commands that worked previously, such as
4159 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004160 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004161 idx3 = findoption((char_u *)"sxq");
4162 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4163 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004164 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004165 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4166 }
4167
Bram Moolenaara64ba222012-02-12 23:23:31 +01004168 idx3 = findoption((char_u *)"shcf");
4169 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4170 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004171 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004172 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4173 }
4174 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004175#endif
4176
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004177 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004178 {
4179 int idx_ffs = findoption((char_u *)"ffs");
4180
4181 /* Apply the first entry of 'fileformats' to the initial buffer. */
4182 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4183 set_fileformat(default_fileformat(), OPT_LOCAL);
4184 }
4185
Bram Moolenaar071d4272004-06-13 20:20:40 +00004186#ifdef FEAT_TITLE
4187 set_title_defaults();
4188#endif
4189}
4190
4191#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4192/*
4193 * When 'helplang' is still at its default value, set it to "lang".
4194 * Only the first two characters of "lang" are used.
4195 */
4196 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004197set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004198{
4199 int idx;
4200
4201 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4202 return;
4203 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004204 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004205 {
4206 if (options[idx].flags & P_ALLOCED)
4207 free_string_option(p_hlg);
4208 p_hlg = vim_strsave(lang);
4209 if (p_hlg == NULL)
4210 p_hlg = empty_option;
4211 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004212 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004213 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004214 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4215 {
4216 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4217 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4218 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004219 // any C like setting, such as C.UTF-8, becomes "en"
4220 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4221 {
4222 p_hlg[0] = 'e';
4223 p_hlg[1] = 'n';
4224 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004225 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004226 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 options[idx].flags |= P_ALLOCED;
4228 }
4229}
4230#endif
4231
4232#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004234gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004235{
4236 if (gui_get_lightness(gui.back_pixel) < 127)
4237 return (char_u *)"dark";
4238 return (char_u *)"light";
4239}
4240
4241/*
4242 * Option initializations that can only be done after opening the GUI window.
4243 */
4244 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004245init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004246{
4247 /* Set the 'background' option according to the lightness of the
4248 * background color, unless the user has set it already. */
4249 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4250 {
4251 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4252 highlight_changed();
4253 }
4254}
4255#endif
4256
4257#ifdef FEAT_TITLE
4258/*
4259 * 'title' and 'icon' only default to true if they have not been set or reset
4260 * in .vimrc and we can read the old value.
4261 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4262 * they can be reset. This reduces startup time when using X on a remote
4263 * machine.
4264 */
4265 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004266set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004267{
4268 int idx1;
4269 long val;
4270
4271 /*
4272 * If GUI is (going to be) used, we can always set the window title and
4273 * icon name. Saves a bit of time, because the X11 display server does
4274 * not need to be contacted.
4275 */
4276 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004277 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004278 {
4279#ifdef FEAT_GUI
4280 if (gui.starting || gui.in_use)
4281 val = TRUE;
4282 else
4283#endif
4284 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004285 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004286 p_title = val;
4287 }
4288 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004289 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004290 {
4291#ifdef FEAT_GUI
4292 if (gui.starting || gui.in_use)
4293 val = TRUE;
4294 else
4295#endif
4296 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004297 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004298 p_icon = val;
4299 }
4300}
4301#endif
4302
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004303#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004304 static void
4305trigger_optionsset_string(
4306 int opt_idx,
4307 int opt_flags,
4308 char_u *oldval,
4309 char_u *newval)
4310{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004311 // Don't do this recursively.
4312 if (oldval != NULL && newval != NULL
4313 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004314 {
4315 char_u buf_type[7];
4316
4317 sprintf((char *)buf_type, "%s",
4318 (opt_flags & OPT_LOCAL) ? "local" : "global");
4319 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4320 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4321 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4322 apply_autocmds(EVENT_OPTIONSET,
4323 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4324 reset_v_option_vars();
4325 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004326}
4327#endif
4328
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329/*
4330 * Parse 'arg' for option settings.
4331 *
4332 * 'arg' may be IObuff, but only when no errors can be present and option
4333 * does not need to be expanded with option_expand().
4334 * "opt_flags":
4335 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004336 * OPT_GLOBAL for ":setglobal"
4337 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004338 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004339 * OPT_WINONLY to only set window-local options
4340 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004341 *
4342 * returns FAIL if an error is detected, OK otherwise
4343 */
4344 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004345do_set(
4346 char_u *arg, /* option string (may be written to!) */
4347 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004348{
4349 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004350 char *errmsg;
4351 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004352 char_u *startarg;
4353 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4354 int nextchar; /* next non-white char after option name */
4355 int afterchar; /* character just after option name */
4356 int len;
4357 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004358 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004359 int key;
4360 long_u flags; /* flags for current option */
4361 char_u *varp = NULL; /* pointer to variable for current option */
4362 int did_show = FALSE; /* already showed one value */
4363 int adding; /* "opt+=arg" */
4364 int prepending; /* "opt^=arg" */
4365 int removing; /* "opt-=arg" */
4366 int cp_val = 0;
4367 char_u key_name[2];
4368
4369 if (*arg == NUL)
4370 {
4371 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004372 did_show = TRUE;
4373 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004374 }
4375
4376 while (*arg != NUL) /* loop to process all options */
4377 {
4378 errmsg = NULL;
4379 startarg = arg; /* remember for error message */
4380
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004381 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4382 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004383 {
4384 /*
4385 * ":set all" show all options.
4386 * ":set all&" set all options to their default value.
4387 */
4388 arg += 3;
4389 if (*arg == '&')
4390 {
4391 ++arg;
4392 /* Only for :set command set global value of local options. */
4393 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004394 didset_options();
4395 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004396 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004397 }
4398 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004399 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004400 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004401 did_show = TRUE;
4402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004404 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004405 {
4406 showoptions(2, opt_flags);
4407 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004408 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004409 arg += 7;
4410 }
4411 else
4412 {
4413 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004414 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004415 {
4416 prefix = 0;
4417 arg += 2;
4418 }
4419 else if (STRNCMP(arg, "inv", 3) == 0)
4420 {
4421 prefix = 2;
4422 arg += 3;
4423 }
4424
4425 /* find end of name */
4426 key = 0;
4427 if (*arg == '<')
4428 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004429 opt_idx = -1;
4430 /* look out for <t_>;> */
4431 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4432 len = 5;
4433 else
4434 {
4435 len = 1;
4436 while (arg[len] != NUL && arg[len] != '>')
4437 ++len;
4438 }
4439 if (arg[len] != '>')
4440 {
4441 errmsg = e_invarg;
4442 goto skip;
4443 }
4444 arg[len] = NUL; /* put NUL after name */
4445 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4446 opt_idx = findoption(arg + 1);
4447 arg[len++] = '>'; /* restore '>' */
4448 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004449 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450 }
4451 else
4452 {
4453 len = 0;
4454 /*
4455 * The two characters after "t_" may not be alphanumeric.
4456 */
4457 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4458 len = 4;
4459 else
4460 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4461 ++len;
4462 nextchar = arg[len];
4463 arg[len] = NUL; /* put NUL after name */
4464 opt_idx = findoption(arg);
4465 arg[len] = nextchar; /* restore nextchar */
4466 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004467 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004468 }
4469
4470 /* remember character after option name */
4471 afterchar = arg[len];
4472
4473 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004474 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004475 ++len;
4476
4477 adding = FALSE;
4478 prepending = FALSE;
4479 removing = FALSE;
4480 if (arg[len] != NUL && arg[len + 1] == '=')
4481 {
4482 if (arg[len] == '+')
4483 {
4484 adding = TRUE; /* "+=" */
4485 ++len;
4486 }
4487 else if (arg[len] == '^')
4488 {
4489 prepending = TRUE; /* "^=" */
4490 ++len;
4491 }
4492 else if (arg[len] == '-')
4493 {
4494 removing = TRUE; /* "-=" */
4495 ++len;
4496 }
4497 }
4498 nextchar = arg[len];
4499
4500 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4501 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004502 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004503 goto skip;
4504 }
4505
4506 if (opt_idx >= 0)
4507 {
4508 if (options[opt_idx].var == NULL) /* hidden option: skip */
4509 {
4510 /* Only give an error message when requesting the value of
4511 * a hidden option, ignore setting it. */
4512 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4513 && (!(options[opt_idx].flags & P_BOOL)
4514 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004515 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004516 goto skip;
4517 }
4518
4519 flags = options[opt_idx].flags;
4520 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4521 }
4522 else
4523 {
4524 flags = P_STRING;
4525 if (key < 0)
4526 {
4527 key_name[0] = KEY2TERMCAP0(key);
4528 key_name[1] = KEY2TERMCAP1(key);
4529 }
4530 else
4531 {
4532 key_name[0] = KS_KEY;
4533 key_name[1] = (key & 0xff);
4534 }
4535 }
4536
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004537 /* Skip all options that are not window-local (used when showing
4538 * an already loaded buffer in a window). */
4539 if ((opt_flags & OPT_WINONLY)
4540 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4541 goto skip;
4542
Bram Moolenaara3227e22006-03-08 21:32:40 +00004543 /* Skip all options that are window-local (used for :vimgrep). */
4544 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4545 && options[opt_idx].var == VAR_WIN)
4546 goto skip;
4547
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004548 /* Disallow changing some options from modelines. */
4549 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004550 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004551 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004552 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004553 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004554 goto skip;
4555 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004556 if ((flags & P_MLE) && !p_mle)
4557 {
4558 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4559 goto skip;
4560 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004561#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004562 /* In diff mode some options are overruled. This avoids that
4563 * 'foldmethod' becomes "marker" instead of "diff" and that
4564 * "wrap" gets set. */
4565 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004566 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004567 && (
4568#ifdef FEAT_FOLDING
4569 options[opt_idx].indir == PV_FDM ||
4570#endif
4571 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004572 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004573#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004574 }
4575
4576#ifdef HAVE_SANDBOX
4577 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004578 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004579 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004580 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 goto skip;
4582 }
4583#endif
4584
4585 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4586 {
4587 arg += len;
4588 cp_val = p_cp;
4589 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4590 {
4591 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4592 {
4593 cp_val = FALSE;
4594 arg += 3;
4595 }
4596 else /* "opt&vi": set to Vi default */
4597 {
4598 cp_val = TRUE;
4599 arg += 2;
4600 }
4601 }
4602 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004603 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004604 {
4605 errmsg = e_trailing;
4606 goto skip;
4607 }
4608 }
4609
4610 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004611 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4612 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004613 */
4614 if (nextchar == '?'
4615 || (prefix == 1
4616 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4617 && !(flags & P_BOOL)))
4618 {
4619 /*
4620 * print value
4621 */
4622 if (did_show)
4623 msg_putchar('\n'); /* cursor below last one */
4624 else
4625 {
4626 gotocmdline(TRUE); /* cursor at status line */
4627 did_show = TRUE; /* remember that we did a line */
4628 }
4629 if (opt_idx >= 0)
4630 {
4631 showoneopt(&options[opt_idx], opt_flags);
4632#ifdef FEAT_EVAL
4633 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004634 {
4635 /* Mention where the option was last set. */
4636 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004637 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004638 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004639 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004640 (int)options[opt_idx].indir & PV_MASK]);
4641 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004642 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004643 (int)options[opt_idx].indir & PV_MASK]);
4644 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004645#endif
4646 }
4647 else
4648 {
4649 char_u *p;
4650
4651 p = find_termcode(key_name);
4652 if (p == NULL)
4653 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004654 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004655 goto skip;
4656 }
4657 else
4658 (void)show_one_termcode(key_name, p, TRUE);
4659 }
4660 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004661 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004662 errmsg = e_trailing;
4663 }
4664 else
4665 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004666 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004667 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004668
Bram Moolenaar071d4272004-06-13 20:20:40 +00004669 if (flags & P_BOOL) /* boolean */
4670 {
4671 if (nextchar == '=' || nextchar == ':')
4672 {
4673 errmsg = e_invarg;
4674 goto skip;
4675 }
4676
4677 /*
4678 * ":set opt!": invert
4679 * ":set opt&": reset to default value
4680 * ":set opt<": reset to global value
4681 */
4682 if (nextchar == '!')
4683 value = *(int *)(varp) ^ 1;
4684 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004685 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004686 ((flags & P_VI_DEF) || cp_val)
4687 ? VI_DEFAULT : VIM_DEFAULT];
4688 else if (nextchar == '<')
4689 {
4690 /* For 'autoread' -1 means to use global value. */
4691 if ((int *)varp == &curbuf->b_p_ar
4692 && opt_flags == OPT_LOCAL)
4693 value = -1;
4694 else
4695 value = *(int *)get_varp_scope(&(options[opt_idx]),
4696 OPT_GLOBAL);
4697 }
4698 else
4699 {
4700 /*
4701 * ":set invopt": invert
4702 * ":set opt" or ":set noopt": set or reset
4703 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004704 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004705 {
4706 errmsg = e_trailing;
4707 goto skip;
4708 }
4709 if (prefix == 2) /* inv */
4710 value = *(int *)(varp) ^ 1;
4711 else
4712 value = prefix;
4713 }
4714
4715 errmsg = set_bool_option(opt_idx, varp, (int)value,
4716 opt_flags);
4717 }
4718 else /* numeric or string */
4719 {
4720 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4721 || prefix != 1)
4722 {
4723 errmsg = e_invarg;
4724 goto skip;
4725 }
4726
4727 if (flags & P_NUM) /* numeric */
4728 {
4729 /*
4730 * Different ways to set a number option:
4731 * & set to default value
4732 * < set to global value
4733 * <xx> accept special key codes for 'wildchar'
4734 * c accept any non-digit for 'wildchar'
4735 * [-]0-9 set number
4736 * other error
4737 */
4738 ++arg;
4739 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004740 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004741 ((flags & P_VI_DEF) || cp_val)
4742 ? VI_DEFAULT : VIM_DEFAULT];
4743 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004744 {
4745 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4746 * use the global value. */
4747 if ((long *)varp == &curbuf->b_p_ul
4748 && opt_flags == OPT_LOCAL)
4749 value = NO_LOCAL_UNDOLEVEL;
4750 else
4751 value = *(long *)get_varp_scope(
4752 &(options[opt_idx]), OPT_GLOBAL);
4753 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004754 else if (((long *)varp == &p_wc
4755 || (long *)varp == &p_wcm)
4756 && (*arg == '<'
4757 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004758 || (*arg != NUL
4759 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760 && !VIM_ISDIGIT(*arg))))
4761 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004762 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004763 if (value == 0 && (long *)varp != &p_wcm)
4764 {
4765 errmsg = e_invarg;
4766 goto skip;
4767 }
4768 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004769 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4770 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004771 /* Allow negative (for 'undolevels'), octal and
4772 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004773 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004774 &value, NULL, 0, TRUE);
4775 if (i == 0 || (arg[i] != NUL && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004776 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004777 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004778 goto skip;
4779 }
4780 }
4781 else
4782 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004783 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004784 goto skip;
4785 }
4786
4787 if (adding)
4788 value = *(long *)varp + value;
4789 if (prepending)
4790 value = *(long *)varp * value;
4791 if (removing)
4792 value = *(long *)varp - value;
4793 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004794 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004795 }
4796 else if (opt_idx >= 0) /* string */
4797 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004798 char_u *save_arg = NULL;
4799 char_u *s = NULL;
4800 char_u *oldval = NULL; /* previous value if *varp */
4801 char_u *newval;
4802 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004803#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004804 char_u *saved_origval = NULL;
4805 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004806#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004807 unsigned newlen;
4808 int comma;
4809 int bs;
4810 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004811 was allocated */
4812
4813 /* When using ":set opt=val" for a global option
4814 * with a local value the local value will be
4815 * reset, use the global value here. */
4816 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004817 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004818 varp = options[opt_idx].var;
4819
4820 /* The old value is kept until we are sure that the
4821 * new value is valid. */
4822 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004823
4824 /* When setting the local value of a global
4825 * option, the old value may be the global value. */
4826 if (((int)options[opt_idx].indir & PV_BOTH)
4827 && (opt_flags & OPT_LOCAL))
4828 origval = *(char_u **)get_varp(
4829 &options[opt_idx]);
4830 else
4831 origval = oldval;
4832
Bram Moolenaar071d4272004-06-13 20:20:40 +00004833 if (nextchar == '&') /* set to default val */
4834 {
4835 newval = options[opt_idx].def_val[
4836 ((flags & P_VI_DEF) || cp_val)
4837 ? VI_DEFAULT : VIM_DEFAULT];
4838 if ((char_u **)varp == &p_bg)
4839 {
4840 /* guess the value of 'background' */
4841#ifdef FEAT_GUI
4842 if (gui.in_use)
4843 newval = gui_bg_default();
4844 else
4845#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004846 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004847 }
4848
4849 /* expand environment variables and ~ (since the
4850 * default value was already expanded, only
4851 * required when an environment variable was set
4852 * later */
4853 if (newval == NULL)
4854 newval = empty_option;
4855 else
4856 {
4857 s = option_expand(opt_idx, newval);
4858 if (s == NULL)
4859 s = newval;
4860 newval = vim_strsave(s);
4861 }
4862 new_value_alloced = TRUE;
4863 }
4864 else if (nextchar == '<') /* set to global val */
4865 {
4866 newval = vim_strsave(*(char_u **)get_varp_scope(
4867 &(options[opt_idx]), OPT_GLOBAL));
4868 new_value_alloced = TRUE;
4869 }
4870 else
4871 {
4872 ++arg; /* jump to after the '=' or ':' */
4873
4874 /*
4875 * Set 'keywordprg' to ":help" if an empty
4876 * value was passed to :set by the user.
4877 * Misuse errbuf[] for the resulting string.
4878 */
4879 if (varp == (char_u *)&p_kp
4880 && (*arg == NUL || *arg == ' '))
4881 {
4882 STRCPY(errbuf, ":help");
4883 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004884 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004885 }
4886 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004887 * Convert 'backspace' number to string, for
4888 * adding, prepending and removing string.
4889 */
4890 else if (varp == (char_u *)&p_bs
4891 && VIM_ISDIGIT(**(char_u **)varp))
4892 {
4893 i = getdigits((char_u **)varp);
4894 switch (i)
4895 {
4896 case 0:
4897 *(char_u **)varp = empty_option;
4898 break;
4899 case 1:
4900 *(char_u **)varp = vim_strsave(
4901 (char_u *)"indent,eol");
4902 break;
4903 case 2:
4904 *(char_u **)varp = vim_strsave(
4905 (char_u *)"indent,eol,start");
4906 break;
4907 }
4908 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004909 if (origval == oldval)
4910 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004911 oldval = *(char_u **)varp;
4912 }
4913 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004914 * Convert 'whichwrap' number to string, for
4915 * backwards compatibility with Vim 3.0.
4916 * Misuse errbuf[] for the resulting string.
4917 */
4918 else if (varp == (char_u *)&p_ww
4919 && VIM_ISDIGIT(*arg))
4920 {
4921 *errbuf = NUL;
4922 i = getdigits(&arg);
4923 if (i & 1)
4924 STRCAT(errbuf, "b,");
4925 if (i & 2)
4926 STRCAT(errbuf, "s,");
4927 if (i & 4)
4928 STRCAT(errbuf, "h,l,");
4929 if (i & 8)
4930 STRCAT(errbuf, "<,>,");
4931 if (i & 16)
4932 STRCAT(errbuf, "[,],");
4933 if (*errbuf != NUL) /* remove trailing , */
4934 errbuf[STRLEN(errbuf) - 1] = NUL;
4935 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004936 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004937 }
4938 /*
4939 * Remove '>' before 'dir' and 'bdir', for
4940 * backwards compatibility with version 3.0
4941 */
4942 else if ( *arg == '>'
4943 && (varp == (char_u *)&p_dir
4944 || varp == (char_u *)&p_bdir))
4945 {
4946 ++arg;
4947 }
4948
Bram Moolenaar071d4272004-06-13 20:20:40 +00004949 /*
4950 * Copy the new string into allocated memory.
4951 * Can't use set_string_option_direct(), because
4952 * we need to remove the backslashes.
4953 */
4954 /* get a bit too much */
4955 newlen = (unsigned)STRLEN(arg) + 1;
4956 if (adding || prepending || removing)
4957 newlen += (unsigned)STRLEN(origval) + 1;
4958 newval = alloc(newlen);
4959 if (newval == NULL) /* out of mem, don't change */
4960 break;
4961 s = newval;
4962
4963 /*
4964 * Copy the string, skip over escaped chars.
4965 * For MS-DOS and WIN32 backslashes before normal
4966 * file name characters are not removed, and keep
4967 * backslash at start, for "\\machine\path", but
4968 * do remove it for "\\\\machine\\path".
4969 * The reverse is found in ExpandOldSetting().
4970 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004971 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004972 {
4973 if (*arg == '\\' && arg[1] != NUL
4974#ifdef BACKSLASH_IN_FILENAME
4975 && !((flags & P_EXPAND)
4976 && vim_isfilec(arg[1])
4977 && (arg[1] != '\\'
4978 || (s == newval
4979 && arg[2] != '\\')))
4980#endif
4981 )
4982 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004983 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004984 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004985 {
4986 /* copy multibyte char */
4987 mch_memmove(s, arg, (size_t)i);
4988 arg += i;
4989 s += i;
4990 }
4991 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004992 *s++ = *arg++;
4993 }
4994 *s = NUL;
4995
4996 /*
4997 * Expand environment variables and ~.
4998 * Don't do it when adding without inserting a
4999 * comma.
5000 */
5001 if (!(adding || prepending || removing)
5002 || (flags & P_COMMA))
5003 {
5004 s = option_expand(opt_idx, newval);
5005 if (s != NULL)
5006 {
5007 vim_free(newval);
5008 newlen = (unsigned)STRLEN(s) + 1;
5009 if (adding || prepending || removing)
5010 newlen += (unsigned)STRLEN(origval) + 1;
5011 newval = alloc(newlen);
5012 if (newval == NULL)
5013 break;
5014 STRCPY(newval, s);
5015 }
5016 }
5017
5018 /* locate newval[] in origval[] when removing it
5019 * and when adding to avoid duplicates */
5020 i = 0; /* init for GCC */
5021 if (removing || (flags & P_NODUP))
5022 {
5023 i = (int)STRLEN(newval);
5024 bs = 0;
5025 for (s = origval; *s; ++s)
5026 {
5027 if ((!(flags & P_COMMA)
5028 || s == origval
5029 || (s[-1] == ',' && !(bs & 1)))
5030 && STRNCMP(s, newval, i) == 0
5031 && (!(flags & P_COMMA)
5032 || s[i] == ','
5033 || s[i] == NUL))
5034 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005035 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005036 * even number of backslashes or a single
5037 * backslash preceded by a comma before it
5038 * is recognized as a separator */
5039 if ((s > origval + 1
5040 && s[-1] == '\\'
5041 && s[-2] != ',')
5042 || (s == origval + 1
5043 && s[-1] == '\\'))
5044
Bram Moolenaar071d4272004-06-13 20:20:40 +00005045 ++bs;
5046 else
5047 bs = 0;
5048 }
5049
5050 /* do not add if already there */
5051 if ((adding || prepending) && *s)
5052 {
5053 prepending = FALSE;
5054 adding = FALSE;
5055 STRCPY(newval, origval);
5056 }
5057 }
5058
5059 /* concatenate the two strings; add a ',' if
5060 * needed */
5061 if (adding || prepending)
5062 {
5063 comma = ((flags & P_COMMA) && *origval != NUL
5064 && *newval != NUL);
5065 if (adding)
5066 {
5067 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005068 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005069 if (comma && i > 1
5070 && (flags & P_ONECOMMA) == P_ONECOMMA
5071 && origval[i - 1] == ','
5072 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005073 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005074 mch_memmove(newval + i + comma, newval,
5075 STRLEN(newval) + 1);
5076 mch_memmove(newval, origval, (size_t)i);
5077 }
5078 else
5079 {
5080 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005081 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005082 }
5083 if (comma)
5084 newval[i] = ',';
5085 }
5086
5087 /* Remove newval[] from origval[]. (Note: "i" has
5088 * been set above and is used here). */
5089 if (removing)
5090 {
5091 STRCPY(newval, origval);
5092 if (*s)
5093 {
5094 /* may need to remove a comma */
5095 if (flags & P_COMMA)
5096 {
5097 if (s == origval)
5098 {
5099 /* include comma after string */
5100 if (s[i] == ',')
5101 ++i;
5102 }
5103 else
5104 {
5105 /* include comma before string */
5106 --s;
5107 ++i;
5108 }
5109 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005110 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 }
5112 }
5113
5114 if (flags & P_FLAGLIST)
5115 {
5116 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005117 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005118 {
5119 /* if options have P_FLAGLIST and
5120 * P_ONECOMMA such as 'whichwrap' */
5121 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005122 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005123 if (*s != ',' && *(s + 1) == ','
5124 && vim_strchr(s + 2, *s) != NULL)
5125 {
5126 /* Remove the duplicated value and
5127 * the next comma. */
5128 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005129 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005130 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005131 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005132 else
5133 {
5134 if ((!(flags & P_COMMA) || *s != ',')
5135 && vim_strchr(s + 1, *s) != NULL)
5136 {
5137 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005138 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005139 }
5140 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005141 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005142 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005143 }
5144
5145 if (save_arg != NULL) /* number for 'whichwrap' */
5146 arg = save_arg;
5147 new_value_alloced = TRUE;
5148 }
5149
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005150 /*
5151 * Set the new value.
5152 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005153 *(char_u **)(varp) = newval;
5154
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005155#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005156 if (!starting
5157# ifdef FEAT_CRYPT
5158 && options[opt_idx].indir != PV_KEY
5159# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005160 && origval != NULL && newval != NULL)
5161 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005162 /* origval may be freed by
5163 * did_set_string_option(), make a copy. */
5164 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005165 /* newval (and varp) may become invalid if the
5166 * buffer is closed by autocommands. */
5167 saved_newval = vim_strsave(newval);
5168 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005169#endif
5170
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005171 {
5172 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005173 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005174
5175 // When an option is set in the sandbox, from a
5176 // modeline or in secure mode, then deal with side
5177 // effects in secure mode. Also when the value was
5178 // set with the P_INSECURE flag and is not
5179 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005180 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005181#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005182 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005183#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005184 || (!value_is_replaced && (*p & P_INSECURE)))
5185 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005186
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005187 // Handle side effects, and set the global value
5188 // for ":set" on local options. Note: when setting
5189 // 'syntax' or 'filetype' autocommands may be
5190 // triggered that can cause havoc.
5191 errmsg = did_set_string_option(
5192 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005193 new_value_alloced, oldval, errbuf,
5194 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005195
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005196 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005197 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005198
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005199#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005200 if (errmsg == NULL)
5201 trigger_optionsset_string(opt_idx, opt_flags,
5202 saved_origval, saved_newval);
5203 vim_free(saved_origval);
5204 vim_free(saved_newval);
5205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005206 /* If error detected, print the error message. */
5207 if (errmsg != NULL)
5208 goto skip;
5209 }
5210 else /* key code option */
5211 {
5212 char_u *p;
5213
5214 if (nextchar == '&')
5215 {
5216 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005217 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005218 }
5219 else
5220 {
5221 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005222 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005223 if (*p == '\\' && p[1] != NUL)
5224 ++p;
5225 nextchar = *p;
5226 *p = NUL;
5227 add_termcode(key_name, arg, FALSE);
5228 *p = nextchar;
5229 }
5230 if (full_screen)
5231 ttest(FALSE);
5232 redraw_all_later(CLEAR);
5233 }
5234 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005235
Bram Moolenaar071d4272004-06-13 20:20:40 +00005236 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005237 did_set_option(
5238 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005239 }
5240
5241skip:
5242 /*
5243 * Advance to next argument.
5244 * - skip until a blank found, taking care of backslashes
5245 * - skip blanks
5246 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5247 */
5248 for (i = 0; i < 2 ; ++i)
5249 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005250 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005251 if (*arg++ == '\\' && *arg != NUL)
5252 ++arg;
5253 arg = skipwhite(arg);
5254 if (*arg != '=')
5255 break;
5256 }
5257 }
5258
5259 if (errmsg != NULL)
5260 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005261 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005262 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005263 if (i + (arg - startarg) < IOSIZE)
5264 {
5265 /* append the argument with the error */
5266 STRCAT(IObuff, ": ");
5267 mch_memmove(IObuff + i, startarg, (arg - startarg));
5268 IObuff[i + (arg - startarg)] = NUL;
5269 }
5270 /* make sure all characters are printable */
5271 trans_characters(IObuff, IOSIZE);
5272
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005273 ++no_wait_return; // wait_return done later
5274 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005275 --no_wait_return;
5276
5277 return FAIL;
5278 }
5279
5280 arg = skipwhite(arg);
5281 }
5282
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005283theend:
5284 if (silent_mode && did_show)
5285 {
5286 /* After displaying option values in silent mode. */
5287 silent_mode = FALSE;
5288 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5289 msg_putchar('\n');
5290 cursor_on(); /* msg_start() switches it off */
5291 out_flush();
5292 silent_mode = TRUE;
5293 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5294 }
5295
Bram Moolenaar071d4272004-06-13 20:20:40 +00005296 return OK;
5297}
5298
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005299/*
5300 * Call this when an option has been given a new value through a user command.
5301 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5302 */
5303 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005304did_set_option(
5305 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005306 int opt_flags, // possibly with OPT_MODELINE
5307 int new_value, // value was replaced completely
5308 int value_checked) // value was checked to be safe, no need to set the
5309 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005310{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005311 long_u *p;
5312
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005313 options[opt_idx].flags |= P_WAS_SET;
5314
5315 /* When an option is set in the sandbox, from a modeline or in secure mode
5316 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005317 * flag. */
5318 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005319 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005320#ifdef HAVE_SANDBOX
5321 || sandbox != 0
5322#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005323 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005324 *p = *p | P_INSECURE;
5325 else if (new_value)
5326 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005327}
5328
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005329 static char *
5330illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005331{
5332 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005333 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005335 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336 return errbuf;
5337}
5338
5339/*
5340 * Convert a key name or string into a key value.
5341 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005342 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005343 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005344 int
5345string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346{
5347 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005348 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349 if (*arg == '^')
5350 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005351 if (multi_byte)
5352 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353 return *arg;
5354}
5355
5356#ifdef FEAT_CMDWIN
5357/*
5358 * Check value of 'cedit' and set cedit_key.
5359 * Returns NULL if value is OK, error message otherwise.
5360 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005361 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005362check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005363{
5364 int n;
5365
5366 if (*p_cedit == NUL)
5367 cedit_key = -1;
5368 else
5369 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005370 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005371 if (vim_isprintc(n))
5372 return e_invarg;
5373 cedit_key = n;
5374 }
5375 return NULL;
5376}
5377#endif
5378
5379#ifdef FEAT_TITLE
5380/*
5381 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5382 * maketitle() to create and display it.
5383 * When switching the title or icon off, call mch_restore_title() to get
5384 * the old value back.
5385 */
5386 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005387did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005388{
5389 if (starting != NO_SCREEN
5390#ifdef FEAT_GUI
5391 && !gui.starting
5392#endif
5393 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005394 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395}
5396#endif
5397
5398/*
5399 * set_options_bin - called when 'bin' changes value.
5400 */
5401 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005402set_options_bin(
5403 int oldval,
5404 int newval,
5405 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005406{
5407 /*
5408 * The option values that are changed when 'bin' changes are
5409 * copied when 'bin is set and restored when 'bin' is reset.
5410 */
5411 if (newval)
5412 {
5413 if (!oldval) /* switched on */
5414 {
5415 if (!(opt_flags & OPT_GLOBAL))
5416 {
5417 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5418 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5419 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5420 curbuf->b_p_et_nobin = curbuf->b_p_et;
5421 }
5422 if (!(opt_flags & OPT_LOCAL))
5423 {
5424 p_tw_nobin = p_tw;
5425 p_wm_nobin = p_wm;
5426 p_ml_nobin = p_ml;
5427 p_et_nobin = p_et;
5428 }
5429 }
5430
5431 if (!(opt_flags & OPT_GLOBAL))
5432 {
5433 curbuf->b_p_tw = 0; /* no automatic line wrap */
5434 curbuf->b_p_wm = 0; /* no automatic line wrap */
5435 curbuf->b_p_ml = 0; /* no modelines */
5436 curbuf->b_p_et = 0; /* no expandtab */
5437 }
5438 if (!(opt_flags & OPT_LOCAL))
5439 {
5440 p_tw = 0;
5441 p_wm = 0;
5442 p_ml = FALSE;
5443 p_et = FALSE;
5444 p_bin = TRUE; /* needed when called for the "-b" argument */
5445 }
5446 }
5447 else if (oldval) /* switched off */
5448 {
5449 if (!(opt_flags & OPT_GLOBAL))
5450 {
5451 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5452 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5453 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5454 curbuf->b_p_et = curbuf->b_p_et_nobin;
5455 }
5456 if (!(opt_flags & OPT_LOCAL))
5457 {
5458 p_tw = p_tw_nobin;
5459 p_wm = p_wm_nobin;
5460 p_ml = p_ml_nobin;
5461 p_et = p_et_nobin;
5462 }
5463 }
5464}
5465
5466#ifdef FEAT_VIMINFO
5467/*
5468 * Find the parameter represented by the given character (eg ', :, ", or /),
5469 * and return its associated value in the 'viminfo' string.
5470 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005471 * If the parameter is not specified in the string or there is no following
5472 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005473 */
5474 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005475get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005476{
5477 char_u *p;
5478
5479 p = find_viminfo_parameter(type);
5480 if (p != NULL && VIM_ISDIGIT(*p))
5481 return atoi((char *)p);
5482 return -1;
5483}
5484
5485/*
5486 * Find the parameter represented by the given character (eg ''', ':', '"', or
5487 * '/') in the 'viminfo' option and return a pointer to the string after it.
5488 * Return NULL if the parameter is not specified in the string.
5489 */
5490 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005491find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492{
5493 char_u *p;
5494
5495 for (p = p_viminfo; *p; ++p)
5496 {
5497 if (*p == type)
5498 return p + 1;
5499 if (*p == 'n') /* 'n' is always the last one */
5500 break;
5501 p = vim_strchr(p, ','); /* skip until next ',' */
5502 if (p == NULL) /* hit the end without finding parameter */
5503 break;
5504 }
5505 return NULL;
5506}
5507#endif
5508
5509/*
5510 * Expand environment variables for some string options.
5511 * These string options cannot be indirect!
5512 * If "val" is NULL expand the current value of the option.
5513 * Return pointer to NameBuff, or NULL when not expanded.
5514 */
5515 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005516option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005517{
5518 /* if option doesn't need expansion nothing to do */
5519 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5520 return NULL;
5521
5522 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5523 * expand_env() would truncate the string. */
5524 if (val != NULL && STRLEN(val) > MAXPATHL)
5525 return NULL;
5526
5527 if (val == NULL)
5528 val = *(char_u **)options[opt_idx].var;
5529
5530 /*
5531 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5532 * Escape spaces when expanding 'tags', they are used to separate file
5533 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005534 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005535 */
5536 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005537 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005538#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005539 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5540#endif
5541 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005542 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5543 return NULL;
5544
5545 return NameBuff;
5546}
5547
5548/*
5549 * After setting various option values: recompute variables that depend on
5550 * option values.
5551 */
5552 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005553didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005554{
5555 /* initialize the table for 'iskeyword' et.al. */
5556 (void)init_chartab();
5557
5558 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5559 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005560 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005561#ifdef FEAT_SESSION
5562 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5563 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5564#endif
5565#ifdef FEAT_FOLDING
5566 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5567#endif
5568 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005569 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005570 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5572 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5573#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005574#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005575 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005576 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005577 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005578 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005579#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005580#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005581 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5582#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005583#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005584 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5585#endif
5586#ifdef FEAT_CMDWIN
5587 /* set cedit_key */
5588 (void)check_cedit();
5589#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005590#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005591 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005592#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005593#ifdef FEAT_LINEBREAK
5594 /* initialize the table for 'breakat'. */
5595 fill_breakat_flags();
5596#endif
5597
5598}
5599
5600/*
5601 * More side effects of setting options.
5602 */
5603 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005604didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005605{
5606 /* Initialize the highlight_attr[] table. */
5607 (void)highlight_changed();
5608
5609 /* Parse default for 'wildmode' */
5610 check_opt_wim();
5611
5612 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005613 /* Parse default for 'fillchars'. */
5614 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005615
5616#ifdef FEAT_CLIPBOARD
5617 /* Parse default for 'clipboard' */
5618 (void)check_clipboard_option();
5619#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005620#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005621 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005622 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005623 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005624 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5625#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005626}
5627
5628/*
5629 * Check for string options that are NULL (normally only termcap options).
5630 */
5631 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005632check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005633{
5634 int opt_idx;
5635
5636 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5637 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5638 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5639}
5640
5641/*
5642 * Check string options in a buffer for NULL value.
5643 */
5644 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005645check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005646{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005647 check_string_option(&buf->b_p_bh);
5648 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005649 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005650 check_string_option(&buf->b_p_ff);
5651#ifdef FEAT_FIND_ID
5652 check_string_option(&buf->b_p_def);
5653 check_string_option(&buf->b_p_inc);
5654# ifdef FEAT_EVAL
5655 check_string_option(&buf->b_p_inex);
5656# endif
5657#endif
5658#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5659 check_string_option(&buf->b_p_inde);
5660 check_string_option(&buf->b_p_indk);
5661#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005662#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5663 check_string_option(&buf->b_p_bexpr);
5664#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005665#if defined(FEAT_CRYPT)
5666 check_string_option(&buf->b_p_cm);
5667#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005668 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005669#if defined(FEAT_EVAL)
5670 check_string_option(&buf->b_p_fex);
5671#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005672#ifdef FEAT_CRYPT
5673 check_string_option(&buf->b_p_key);
5674#endif
5675 check_string_option(&buf->b_p_kp);
5676 check_string_option(&buf->b_p_mps);
5677 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005678 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005679 check_string_option(&buf->b_p_isk);
5680#ifdef FEAT_COMMENTS
5681 check_string_option(&buf->b_p_com);
5682#endif
5683#ifdef FEAT_FOLDING
5684 check_string_option(&buf->b_p_cms);
5685#endif
5686 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005687#ifdef FEAT_TEXTOBJ
5688 check_string_option(&buf->b_p_qe);
5689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005690#ifdef FEAT_SYN_HL
5691 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005692 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005693#endif
5694#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005695 check_string_option(&buf->b_s.b_p_spc);
5696 check_string_option(&buf->b_s.b_p_spf);
5697 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698#endif
5699#ifdef FEAT_SEARCHPATH
5700 check_string_option(&buf->b_p_sua);
5701#endif
5702#ifdef FEAT_CINDENT
5703 check_string_option(&buf->b_p_cink);
5704 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005705 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5709 check_string_option(&buf->b_p_cinw);
5710#endif
5711#ifdef FEAT_INS_EXPAND
5712 check_string_option(&buf->b_p_cpt);
5713#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005714#ifdef FEAT_COMPL_FUNC
5715 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005716 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005717#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005718#ifdef FEAT_EVAL
5719 check_string_option(&buf->b_p_tfu);
5720#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005721#ifdef FEAT_KEYMAP
5722 check_string_option(&buf->b_p_keymap);
5723#endif
5724#ifdef FEAT_QUICKFIX
5725 check_string_option(&buf->b_p_gp);
5726 check_string_option(&buf->b_p_mp);
5727 check_string_option(&buf->b_p_efm);
5728#endif
5729 check_string_option(&buf->b_p_ep);
5730 check_string_option(&buf->b_p_path);
5731 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005732 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005733#ifdef FEAT_INS_EXPAND
5734 check_string_option(&buf->b_p_dict);
5735 check_string_option(&buf->b_p_tsr);
5736#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005737#ifdef FEAT_LISP
5738 check_string_option(&buf->b_p_lw);
5739#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005740 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005741 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005742#ifdef FEAT_VARTABS
5743 check_string_option(&buf->b_p_vsts);
5744 check_string_option(&buf->b_p_vts);
5745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746}
5747
5748/*
5749 * Free the string allocated for an option.
5750 * Checks for the string being empty_option. This may happen if we're out of
5751 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5752 * check_options().
5753 * Does NOT check for P_ALLOCED flag!
5754 */
5755 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005756free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757{
5758 if (p != empty_option)
5759 vim_free(p);
5760}
5761
5762 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005763clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764{
5765 if (*pp != empty_option)
5766 vim_free(*pp);
5767 *pp = empty_option;
5768}
5769
5770 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005771check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772{
5773 if (*pp == NULL)
5774 *pp = empty_option;
5775}
5776
5777/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005778 * Return the option index found by a pointer into term_strings[].
5779 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005780 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005781 int
5782get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005783{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005784 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785
5786 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5787 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005788 return opt_idx;
5789 return -1; // cannot happen: didn't find it!
5790}
5791
5792/*
5793 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5794 * Return the option index or -1 if not found.
5795 */
5796 int
5797set_term_option_alloced(char_u **p)
5798{
5799 int opt_idx = get_term_opt_idx(p);
5800
5801 if (opt_idx >= 0)
5802 options[opt_idx].flags |= P_ALLOCED;
5803 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005804}
5805
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005806#if defined(FEAT_EVAL) || defined(PROTO)
5807/*
5808 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5809 * Return FALSE when it wasn't.
5810 * Return -1 for an unknown option.
5811 */
5812 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005813was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005814{
5815 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005816 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005817
5818 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005819 {
5820 flagp = insecure_flag(idx, opt_flags);
5821 return (*flagp & P_INSECURE) != 0;
5822 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005823 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005824 return -1;
5825}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005826
5827/*
5828 * Get a pointer to the flags used for the P_INSECURE flag of option
5829 * "opt_idx". For some local options a local flags field is used.
5830 */
5831 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005832insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005833{
5834 if (opt_flags & OPT_LOCAL)
5835 switch ((int)options[opt_idx].indir)
5836 {
5837#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005838 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005839#endif
5840#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005841# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005842 case PV_FDE: return &curwin->w_p_fde_flags;
5843 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005844# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005845# ifdef FEAT_BEVAL
5846 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5847# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005848# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005849 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005850# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005851 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005852# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005853 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005854# endif
5855#endif
5856 }
5857
5858 /* Nothing special, return global flags field. */
5859 return &options[opt_idx].flags;
5860}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005861#endif
5862
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005863#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005864/*
5865 * Redraw the window title and/or tab page text later.
5866 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005867static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005868{
5869 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005870 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005871}
5872#endif
5873
Bram Moolenaar071d4272004-06-13 20:20:40 +00005874/*
5875 * Set a string option to a new value (without checking the effect).
5876 * The string is copied into allocated memory.
5877 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005878 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5879 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5880 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005881 */
5882 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005883set_string_option_direct(
5884 char_u *name,
5885 int opt_idx,
5886 char_u *val,
5887 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5888 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005889{
5890 char_u *s;
5891 char_u **varp;
5892 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005893 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005894
Bram Moolenaar89d40322006-08-29 15:30:07 +00005895 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005897 idx = findoption(name);
5898 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005899 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005900 semsg(_(e_intern2), "set_string_option_direct()");
5901 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005902 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005903 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 }
5905
Bram Moolenaar89d40322006-08-29 15:30:07 +00005906 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005907 return;
5908
5909 s = vim_strsave(val);
5910 if (s != NULL)
5911 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005912 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005913 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005914 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005915 free_string_option(*varp);
5916 *varp = s;
5917
5918 /* For buffer/window local option may also set the global value. */
5919 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005920 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005921
Bram Moolenaar89d40322006-08-29 15:30:07 +00005922 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005923
5924 /* When setting both values of a global option with a local value,
5925 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005926 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005927 {
5928 free_string_option(*varp);
5929 *varp = empty_option;
5930 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005931# ifdef FEAT_EVAL
5932 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005933 {
5934 sctx_T script_ctx;
5935
5936 if (set_sid == 0)
5937 script_ctx = current_sctx;
5938 else
5939 {
5940 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005941 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005942 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005943 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005944 }
5945 set_option_sctx_idx(idx, opt_flags, script_ctx);
5946 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005947# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005948 }
5949}
5950
5951/*
5952 * Set global value for string option when it's a local option.
5953 */
5954 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005955set_string_option_global(
5956 int opt_idx, /* option index */
5957 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005958{
5959 char_u **p, *s;
5960
5961 /* the global value is always allocated */
5962 if (options[opt_idx].var == VAR_WIN)
5963 p = (char_u **)GLOBAL_WO(varp);
5964 else
5965 p = (char_u **)options[opt_idx].var;
5966 if (options[opt_idx].indir != PV_NONE
5967 && p != varp
5968 && (s = vim_strsave(*varp)) != NULL)
5969 {
5970 free_string_option(*p);
5971 *p = s;
5972 }
5973}
5974
5975/*
5976 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005977 *
5978 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005979 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005980 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005981set_string_option(
5982 int opt_idx,
5983 char_u *value,
5984 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005985{
5986 char_u *s;
5987 char_u **varp;
5988 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005989#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005990 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005991 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005992#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005993 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005994 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005995
5996 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005997 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005998
5999 s = vim_strsave(value);
6000 if (s != NULL)
6001 {
6002 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6003 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006004 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006005 ? OPT_GLOBAL : OPT_LOCAL)
6006 : opt_flags);
6007 oldval = *varp;
6008 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006009
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006010#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006011 if (!starting
6012# ifdef FEAT_CRYPT
6013 && options[opt_idx].indir != PV_KEY
6014# endif
6015 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006016 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006017 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006018 saved_newval = vim_strsave(s);
6019 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006020#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006021 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006022 opt_flags, &value_checked)) == NULL)
6023 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006024
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006025#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006026 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006027 if (r == NULL)
6028 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006029 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006030 vim_free(saved_oldval);
6031 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006032#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006033 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006034 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006035}
6036
6037/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006038 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6039 * characters or characters in "allowed".
6040 */
6041 static int
6042valid_name(char_u *val, char *allowed)
6043{
6044 char_u *s;
6045
6046 for (s = val; *s != NUL; ++s)
6047 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6048 return FALSE;
6049 return TRUE;
6050}
6051
6052/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006053 * Return TRUE if "val" is a valid 'filetype' name.
6054 * Also used for 'syntax' and 'keymap'.
6055 */
6056 static int
6057valid_filetype(char_u *val)
6058{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006059 return valid_name(val, ".-_");
6060}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006061
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006062#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006063/*
6064 * Return TRUE if "val" is a valid 'spellang' value.
6065 */
6066 int
6067valid_spellang(char_u *val)
6068{
Bram Moolenaar9a061cb2019-05-05 16:55:03 +02006069 return valid_name(val, ".-_,@");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006070}
6071
6072/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006073 * Return TRUE if "val" is a valid 'spellfile' value.
6074 */
6075 static int
6076valid_spellfile(char_u *val)
6077{
6078 char_u *s;
6079
6080 for (s = val; *s != NUL; ++s)
6081 if (!vim_isfilec(*s) && *s != ',')
6082 return FALSE;
6083 return TRUE;
6084}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006085#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006086
6087/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006088 * Handle string options that need some action to perform when changed.
6089 * Returns NULL for success, or an error message for an error.
6090 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006091 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006092did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006093 int opt_idx, // index in options[] table
6094 char_u **varp, // pointer to the option variable
6095 int new_value_alloced, // new value was allocated
6096 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006097 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006098 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6099 int *value_checked) // value was checked to be save, no
6100 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006102 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006103 char_u *s, *p;
6104 int did_chartab = FALSE;
6105 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006106 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006107#ifdef FEAT_GUI
6108 /* set when changing an option that only requires a redraw in the GUI */
6109 int redraw_gui_only = FALSE;
6110#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006111 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006112#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6113 int did_swaptcap = FALSE;
6114#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006115
6116 /* Get the global option to compare with, otherwise we would have to check
6117 * two values for all local options. */
6118 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6119
6120 /* Disallow changing some options from secure mode */
6121 if ((secure
6122#ifdef HAVE_SANDBOX
6123 || sandbox != 0
6124#endif
6125 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006126 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127
Bram Moolenaar916a8182018-11-25 02:18:29 +01006128 // Check for a "normal" directory or file name in some options. Disallow a
6129 // path separator (slash and/or backslash), wildcards and characters that
6130 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006131 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006132 && vim_strpbrk(*varp, (char_u *)(secure
6133 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006134 || ((options[opt_idx].flags & P_NDNAME)
6135 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006136 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006137
Bram Moolenaar071d4272004-06-13 20:20:40 +00006138 /* 'term' */
6139 else if (varp == &T_NAME)
6140 {
6141 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006142 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143#ifdef FEAT_GUI
6144 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006145 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006146 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006147 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006148#endif
6149 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006150 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006152 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006153 /* Screen colors may have changed. */
6154 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006155
6156 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6157 * P_ALLOCED flag on 'term'. */
6158 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006159 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006160 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006161 }
6162
6163 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006164 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006165 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006166 char_u *bkc = p_bkc;
6167 unsigned int *flags = &bkc_flags;
6168
6169 if (opt_flags & OPT_LOCAL)
6170 {
6171 bkc = curbuf->b_p_bkc;
6172 flags = &curbuf->b_bkc_flags;
6173 }
6174
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006175 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6176 /* make the local value empty: use the global value */
6177 *flags = 0;
6178 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006180 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6181 errmsg = e_invarg;
6182 if ((((int)*flags & BKC_AUTO) != 0)
6183 + (((int)*flags & BKC_YES) != 0)
6184 + (((int)*flags & BKC_NO) != 0) != 1)
6185 {
6186 /* Must have exactly one of "auto", "yes" and "no". */
6187 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6188 errmsg = e_invarg;
6189 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006190 }
6191 }
6192
6193 /* 'backupext' and 'patchmode' */
6194 else if (varp == &p_bex || varp == &p_pm)
6195 {
6196 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6197 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006198 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006199 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006200#ifdef FEAT_LINEBREAK
6201 /* 'breakindentopt' */
6202 else if (varp == &curwin->w_p_briopt)
6203 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006204 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006205 errmsg = e_invarg;
6206 }
6207#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006208
6209 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006210 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006211 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006212 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006213 */
6214 else if ( varp == &p_isi
6215 || varp == &(curbuf->b_p_isk)
6216 || varp == &p_isp
6217 || varp == &p_isf)
6218 {
6219 if (init_chartab() == FAIL)
6220 {
6221 did_chartab = TRUE; /* need to restore it below */
6222 errmsg = e_invarg; /* error in value */
6223 }
6224 }
6225
6226 /* 'helpfile' */
6227 else if (varp == &p_hf)
6228 {
6229 /* May compute new values for $VIM and $VIMRUNTIME */
6230 if (didset_vim)
6231 {
6232 vim_setenv((char_u *)"VIM", (char_u *)"");
6233 didset_vim = FALSE;
6234 }
6235 if (didset_vimruntime)
6236 {
6237 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6238 didset_vimruntime = FALSE;
6239 }
6240 }
6241
Bram Moolenaar1a384422010-07-14 19:53:30 +02006242#ifdef FEAT_SYN_HL
6243 /* 'colorcolumn' */
6244 else if (varp == &curwin->w_p_cc)
6245 errmsg = check_colorcolumn(curwin);
6246#endif
6247
Bram Moolenaar071d4272004-06-13 20:20:40 +00006248#ifdef FEAT_MULTI_LANG
6249 /* 'helplang' */
6250 else if (varp == &p_hlg)
6251 {
6252 /* Check for "", "ab", "ab,cd", etc. */
6253 for (s = p_hlg; *s != NUL; s += 3)
6254 {
6255 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6256 {
6257 errmsg = e_invarg;
6258 break;
6259 }
6260 if (s[2] == NUL)
6261 break;
6262 }
6263 }
6264#endif
6265
6266 /* 'highlight' */
6267 else if (varp == &p_hl)
6268 {
6269 if (highlight_changed() == FAIL)
6270 errmsg = e_invarg; /* invalid flags */
6271 }
6272
6273 /* 'nrformats' */
6274 else if (gvarp == &p_nf)
6275 {
6276 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6277 errmsg = e_invarg;
6278 }
6279
6280#ifdef FEAT_SESSION
6281 /* 'sessionoptions' */
6282 else if (varp == &p_ssop)
6283 {
6284 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6285 errmsg = e_invarg;
6286 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6287 {
6288 /* Don't allow both "sesdir" and "curdir". */
6289 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6290 errmsg = e_invarg;
6291 }
6292 }
6293 /* 'viewoptions' */
6294 else if (varp == &p_vop)
6295 {
6296 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6297 errmsg = e_invarg;
6298 }
6299#endif
6300
6301 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006302 else if (varp == &p_sbo)
6303 {
6304 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6305 errmsg = e_invarg;
6306 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006307
6308 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006309 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310 {
6311 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6312 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006313 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006314 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006315 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006316 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006317 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006318
6319 /* 'background' */
6320 else if (varp == &p_bg)
6321 {
6322 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6323 {
6324#ifdef FEAT_EVAL
6325 int dark = (*p_bg == 'd');
6326#endif
6327
6328 init_highlight(FALSE, FALSE);
6329
6330#ifdef FEAT_EVAL
6331 if (dark != (*p_bg == 'd')
6332 && get_var_value((char_u *)"g:colors_name") != NULL)
6333 {
6334 /* The color scheme must have set 'background' back to another
6335 * value, that's not what we want here. Disable the color
6336 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006337 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006338 free_string_option(p_bg);
6339 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6340 check_string_option(&p_bg);
6341 init_highlight(FALSE, FALSE);
6342 }
6343#endif
6344 }
6345 else
6346 errmsg = e_invarg;
6347 }
6348
6349 /* 'wildmode' */
6350 else if (varp == &p_wim)
6351 {
6352 if (check_opt_wim() == FAIL)
6353 errmsg = e_invarg;
6354 }
6355
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006356#ifdef FEAT_CMDL_COMPL
6357 /* 'wildoptions' */
6358 else if (varp == &p_wop)
6359 {
6360 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6361 errmsg = e_invarg;
6362 }
6363#endif
6364
Bram Moolenaar071d4272004-06-13 20:20:40 +00006365#ifdef FEAT_WAK
6366 /* 'winaltkeys' */
6367 else if (varp == &p_wak)
6368 {
6369 if (*p_wak == NUL
6370 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6371 errmsg = e_invarg;
6372# ifdef FEAT_MENU
6373# ifdef FEAT_GUI_MOTIF
6374 else if (gui.in_use)
6375 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6376# else
6377# ifdef FEAT_GUI_GTK
6378 else if (gui.in_use)
6379 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6380# endif
6381# endif
6382# endif
6383 }
6384#endif
6385
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386 /* 'eventignore' */
6387 else if (varp == &p_ei)
6388 {
6389 if (check_ei() == FAIL)
6390 errmsg = e_invarg;
6391 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006392
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006393 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6394 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6395 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396 {
6397 if (gvarp == &p_fenc)
6398 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006399 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006400 errmsg = e_modifiable;
6401 else if (vim_strchr(*varp, ',') != NULL)
6402 /* No comma allowed in 'fileencoding'; catches confusing it
6403 * with 'fileencodings'. */
6404 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006405 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006406 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006407#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006409 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006410#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006411 /* Add 'fileencoding' to the swap file. */
6412 ml_setflags(curbuf);
6413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006414 }
6415 if (errmsg == NULL)
6416 {
6417 /* canonize the value, so that STRCMP() can be used on it */
6418 p = enc_canonize(*varp);
6419 if (p != NULL)
6420 {
6421 vim_free(*varp);
6422 *varp = p;
6423 }
6424 if (varp == &p_enc)
6425 {
6426 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006427#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006428 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430 }
6431 }
6432
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006433#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006434 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6435 {
6436 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6437 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006438 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441
6442 if (errmsg == NULL)
6443 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006444#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006445 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6446 * (with another encoding). */
6447 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6448 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006449#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006450
6451 /* When 'termencoding' is not empty and 'encoding' changes or when
6452 * 'termencoding' changes, need to setup for keyboard input and
6453 * display output conversion. */
6454 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6455 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006456 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6457 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6458 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006459 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006460 p_tenc, p_enc);
6461 errmsg = e_invarg;
6462 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006463 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006464
Bram Moolenaar4f974752019-02-17 17:44:42 +01006465#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006466 /* $HOME may have characters in active code page. */
6467 if (varp == &p_enc)
6468 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006469#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006470 }
6471 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006472
6473#if defined(FEAT_POSTSCRIPT)
6474 else if (varp == &p_penc)
6475 {
6476 /* Canonize printencoding if VIM standard one */
6477 p = enc_canonize(p_penc);
6478 if (p != NULL)
6479 {
6480 vim_free(p_penc);
6481 p_penc = p;
6482 }
6483 else
6484 {
6485 /* Ensure lower case and '-' for '_' */
6486 for (s = p_penc; *s != NUL; s++)
6487 {
6488 if (*s == '_')
6489 *s = '-';
6490 else
6491 *s = TOLOWER_ASC(*s);
6492 }
6493 }
6494 }
6495#endif
6496
Bram Moolenaar9372a112005-12-06 19:59:18 +00006497#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 else if (varp == &p_imak)
6499 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006500 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006501 errmsg = e_invarg;
6502 }
6503#endif
6504
6505#ifdef FEAT_KEYMAP
6506 else if (varp == &curbuf->b_p_keymap)
6507 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006508 if (!valid_filetype(*varp))
6509 errmsg = e_invarg;
6510 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006511 {
6512 int secure_save = secure;
6513
6514 // Reset the secure flag, since the value of 'keymap' has
6515 // been checked to be safe.
6516 secure = 0;
6517
6518 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006519 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006520
Bram Moolenaar916a8182018-11-25 02:18:29 +01006521 secure = secure_save;
6522
6523 // Since we check the value, there is no need to set P_INSECURE,
6524 // even when the value comes from a modeline.
6525 *value_checked = TRUE;
6526 }
6527
Bram Moolenaarfab06232009-03-04 03:13:35 +00006528 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006530 if (*curbuf->b_p_keymap != NUL)
6531 {
6532 /* Installed a new keymap, switch on using it. */
6533 curbuf->b_p_iminsert = B_IMODE_LMAP;
6534 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6535 curbuf->b_p_imsearch = B_IMODE_LMAP;
6536 }
6537 else
6538 {
6539 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6540 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6541 curbuf->b_p_iminsert = B_IMODE_NONE;
6542 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6543 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6544 }
6545 if ((opt_flags & OPT_LOCAL) == 0)
6546 {
6547 set_iminsert_global();
6548 set_imsearch_global();
6549 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006550 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006551 }
6552 }
6553#endif
6554
6555 /* 'fileformat' */
6556 else if (gvarp == &p_ff)
6557 {
6558 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6559 errmsg = e_modifiable;
6560 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6561 errmsg = e_invarg;
6562 else
6563 {
6564 /* may also change 'textmode' */
6565 if (get_fileformat(curbuf) == EOL_DOS)
6566 curbuf->b_p_tx = TRUE;
6567 else
6568 curbuf->b_p_tx = FALSE;
6569#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006570 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006571#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006572 /* update flag in swap file */
6573 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006574 /* Redraw needed when switching to/from "mac": a CR in the text
6575 * will be displayed differently. */
6576 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6577 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 }
6579 }
6580
6581 /* 'fileformats' */
6582 else if (varp == &p_ffs)
6583 {
6584 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6585 errmsg = e_invarg;
6586 else
6587 {
6588 /* also change 'textauto' */
6589 if (*p_ffs == NUL)
6590 p_ta = FALSE;
6591 else
6592 p_ta = TRUE;
6593 }
6594 }
6595
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006596#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006597 /* 'cryptkey' */
6598 else if (gvarp == &p_key)
6599 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006600# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006601 /* Make sure the ":set" command doesn't show the new value in the
6602 * history. */
6603 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006604# endif
6605 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6606 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006607 ml_set_crypt_key(curbuf, oldval,
6608 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006609 }
6610
6611 else if (gvarp == &p_cm)
6612 {
6613 if (opt_flags & OPT_LOCAL)
6614 p = curbuf->b_p_cm;
6615 else
6616 p = p_cm;
6617 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6618 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006619 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006620 errmsg = e_invarg;
6621 else
6622 {
6623 /* When setting the global value to empty, make it "zip". */
6624 if (*p_cm == NUL)
6625 {
6626 if (new_value_alloced)
6627 free_string_option(p_cm);
6628 p_cm = vim_strsave((char_u *)"zip");
6629 new_value_alloced = TRUE;
6630 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006631 /* When using ":set cm=name" the local value is going to be empty.
6632 * Do that here, otherwise the crypt functions will still use the
6633 * local value. */
6634 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6635 {
6636 free_string_option(curbuf->b_p_cm);
6637 curbuf->b_p_cm = empty_option;
6638 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006639
6640 /* Need to update the swapfile when the effective method changed.
6641 * Set "s" to the effective old value, "p" to the effective new
6642 * method and compare. */
6643 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6644 s = p_cm; /* was previously using the global value */
6645 else
6646 s = oldval;
6647 if (*curbuf->b_p_cm == NUL)
6648 p = p_cm; /* is now using the global value */
6649 else
6650 p = curbuf->b_p_cm;
6651 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006652 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006653
6654 /* If the global value changes need to update the swapfile for all
6655 * buffers using that value. */
6656 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6657 {
6658 buf_T *buf;
6659
Bram Moolenaar29323592016-07-24 22:04:11 +02006660 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006661 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006662 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006663 }
6664 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665 }
6666#endif
6667
6668 /* 'matchpairs' */
6669 else if (gvarp == &p_mps)
6670 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006671 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006672 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006673 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006674 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006675 int x2 = -1;
6676 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006677
6678 if (*p != NUL)
6679 p += mb_ptr2len(p);
6680 if (*p != NUL)
6681 x2 = *p++;
6682 if (*p != NUL)
6683 {
6684 x3 = mb_ptr2char(p);
6685 p += mb_ptr2len(p);
6686 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006687 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006688 {
6689 errmsg = e_invarg;
6690 break;
6691 }
6692 if (*p == NUL)
6693 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006694 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006695 }
6696 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006697 {
6698 /* Check for "x:y,x:y" */
6699 for (p = *varp; *p != NUL; p += 4)
6700 {
6701 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6702 {
6703 errmsg = e_invarg;
6704 break;
6705 }
6706 if (p[3] == NUL)
6707 break;
6708 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006709 }
6710 }
6711
6712#ifdef FEAT_COMMENTS
6713 /* 'comments' */
6714 else if (gvarp == &p_com)
6715 {
6716 for (s = *varp; *s; )
6717 {
6718 while (*s && *s != ':')
6719 {
6720 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6721 && !VIM_ISDIGIT(*s) && *s != '-')
6722 {
6723 errmsg = illegal_char(errbuf, *s);
6724 break;
6725 }
6726 ++s;
6727 }
6728 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006729 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006730 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006731 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006732 if (errmsg != NULL)
6733 break;
6734 while (*s && *s != ',')
6735 {
6736 if (*s == '\\' && s[1] != NUL)
6737 ++s;
6738 ++s;
6739 }
6740 s = skip_to_option_part(s);
6741 }
6742 }
6743#endif
6744
6745 /* 'listchars' */
6746 else if (varp == &p_lcs)
6747 {
6748 errmsg = set_chars_option(varp);
6749 }
6750
Bram Moolenaar071d4272004-06-13 20:20:40 +00006751 /* 'fillchars' */
6752 else if (varp == &p_fcs)
6753 {
6754 errmsg = set_chars_option(varp);
6755 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756
6757#ifdef FEAT_CMDWIN
6758 /* 'cedit' */
6759 else if (varp == &p_cedit)
6760 {
6761 errmsg = check_cedit();
6762 }
6763#endif
6764
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006765 /* 'verbosefile' */
6766 else if (varp == &p_vfile)
6767 {
6768 verbose_stop();
6769 if (*p_vfile != NUL && verbose_open() == FAIL)
6770 errmsg = e_invarg;
6771 }
6772
Bram Moolenaar071d4272004-06-13 20:20:40 +00006773#ifdef FEAT_VIMINFO
6774 /* 'viminfo' */
6775 else if (varp == &p_viminfo)
6776 {
6777 for (s = p_viminfo; *s;)
6778 {
6779 /* Check it's a valid character */
6780 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6781 {
6782 errmsg = illegal_char(errbuf, *s);
6783 break;
6784 }
6785 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006786 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006787 else if (*s == 'r') /* skip until next ',' */
6788 {
6789 while (*++s && *s != ',')
6790 ;
6791 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006792 else if (*s == '%')
6793 {
6794 /* optional number */
6795 while (vim_isdigit(*++s))
6796 ;
6797 }
6798 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006799 ++s; /* no extra chars */
6800 else /* must have a number */
6801 {
6802 while (vim_isdigit(*++s))
6803 ;
6804
6805 if (!VIM_ISDIGIT(*(s - 1)))
6806 {
6807 if (errbuf != NULL)
6808 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006809 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006810 transchar_byte(*(s - 1)));
6811 errmsg = errbuf;
6812 }
6813 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006814 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815 break;
6816 }
6817 }
6818 if (*s == ',')
6819 ++s;
6820 else if (*s)
6821 {
6822 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006823 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006824 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006825 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006826 break;
6827 }
6828 }
6829 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006830 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006831 }
6832#endif /* FEAT_VIMINFO */
6833
6834 /* terminal options */
6835 else if (istermoption(&options[opt_idx]) && full_screen)
6836 {
6837 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6838 if (varp == &T_CCO)
6839 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006840 int colors = atoi((char *)T_CCO);
6841
6842 /* Only reinitialize colors if t_Co value has really changed to
6843 * avoid expensive reload of colorscheme if t_Co is set to the
6844 * same value multiple times. */
6845 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006846 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006847 t_colors = colors;
6848 if (t_colors <= 1)
6849 {
6850 if (new_value_alloced)
6851 vim_free(T_CCO);
6852 T_CCO = empty_option;
6853 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006854#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6855 if (is_term_win32())
6856 {
6857 swap_tcap();
6858 did_swaptcap = TRUE;
6859 }
6860#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006861 /* We now have a different color setup, initialize it again. */
6862 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006863 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006864 }
6865 ttest(FALSE);
6866 if (varp == &T_ME)
6867 {
6868 out_str(T_ME);
6869 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006870#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871 /* Since t_me has been set, this probably means that the user
6872 * wants to use this as default colors. Need to reset default
6873 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006874# ifdef VIMDLL
6875 if (!gui.in_use && !gui.starting)
6876# endif
6877 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006878#endif
6879 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006880 if (varp == &T_BE && termcap_active)
6881 {
6882 if (*T_BE == NUL)
6883 /* When clearing t_BE we assume the user no longer wants
6884 * bracketed paste, thus disable it by writing t_BD. */
6885 out_str(T_BD);
6886 else
6887 out_str(T_BE);
6888 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006889 }
6890
6891#ifdef FEAT_LINEBREAK
6892 /* 'showbreak' */
6893 else if (varp == &p_sbr)
6894 {
6895 for (s = p_sbr; *s; )
6896 {
6897 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006898 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006899 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006900 }
6901 }
6902#endif
6903
6904#ifdef FEAT_GUI
6905 /* 'guifont' */
6906 else if (varp == &p_guifont)
6907 {
6908 if (gui.in_use)
6909 {
6910 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006911# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006912 /*
6913 * Put up a font dialog and let the user select a new value.
6914 * If this is cancelled go back to the old value but don't
6915 * give an error message.
6916 */
6917 if (STRCMP(p, "*") == 0)
6918 {
6919 p = gui_mch_font_dialog(oldval);
6920
6921 if (new_value_alloced)
6922 free_string_option(p_guifont);
6923
6924 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6925 new_value_alloced = TRUE;
6926 }
6927# endif
6928 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6929 {
6930# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6931 if (STRCMP(p_guifont, "*") == 0)
6932 {
6933 /* Dialog was cancelled: Keep the old value without giving
6934 * an error message. */
6935 if (new_value_alloced)
6936 free_string_option(p_guifont);
6937 p_guifont = vim_strsave(oldval);
6938 new_value_alloced = TRUE;
6939 }
6940 else
6941# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006942 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 }
6944 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006945 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 }
6947# ifdef FEAT_XFONTSET
6948 else if (varp == &p_guifontset)
6949 {
6950 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006951 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006952 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006953 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006954 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006955 }
6956# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006957 else if (varp == &p_guifontwide)
6958 {
6959 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006960 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006962 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006963 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006964 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965#endif
6966
6967#ifdef CURSOR_SHAPE
6968 /* 'guicursor' */
6969 else if (varp == &p_guicursor)
6970 errmsg = parse_shape_opt(SHAPE_CURSOR);
6971#endif
6972
6973#ifdef FEAT_MOUSESHAPE
6974 /* 'mouseshape' */
6975 else if (varp == &p_mouseshape)
6976 {
6977 errmsg = parse_shape_opt(SHAPE_MOUSE);
6978 update_mouseshape(-1);
6979 }
6980#endif
6981
6982#ifdef FEAT_PRINTER
6983 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006984 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006985# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006986 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006987 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006988# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006989#endif
6990
6991#ifdef FEAT_LANGMAP
6992 /* 'langmap' */
6993 else if (varp == &p_langmap)
6994 langmap_set();
6995#endif
6996
6997#ifdef FEAT_LINEBREAK
6998 /* 'breakat' */
6999 else if (varp == &p_breakat)
7000 fill_breakat_flags();
7001#endif
7002
7003#ifdef FEAT_TITLE
7004 /* 'titlestring' and 'iconstring' */
7005 else if (varp == &p_titlestring || varp == &p_iconstring)
7006 {
7007# ifdef FEAT_STL_OPT
7008 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7009
7010 /* NULL => statusline syntax */
7011 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7012 stl_syntax |= flagval;
7013 else
7014 stl_syntax &= ~flagval;
7015# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007016 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 }
7018#endif
7019
7020#ifdef FEAT_GUI
7021 /* 'guioptions' */
7022 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007023 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007024 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007025 redraw_gui_only = TRUE;
7026 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027#endif
7028
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007029#if defined(FEAT_GUI_TABLINE)
7030 /* 'guitablabel' */
7031 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007032 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007033 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007034 redraw_gui_only = TRUE;
7035 }
7036 /* 'guitabtooltip' */
7037 else if (varp == &p_gtt)
7038 {
7039 redraw_gui_only = TRUE;
7040 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007041#endif
7042
Bram Moolenaar071d4272004-06-13 20:20:40 +00007043#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7044 /* 'ttymouse' */
7045 else if (varp == &p_ttym)
7046 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007047 /* Switch the mouse off before changing the escape sequences used for
7048 * that. */
7049 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7051 errmsg = e_invarg;
7052 else
7053 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007054 if (termcap_active)
7055 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007056 }
7057#endif
7058
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059 /* 'selection' */
7060 else if (varp == &p_sel)
7061 {
7062 if (*p_sel == NUL
7063 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7064 errmsg = e_invarg;
7065 }
7066
7067 /* 'selectmode' */
7068 else if (varp == &p_slm)
7069 {
7070 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7071 errmsg = e_invarg;
7072 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007073
7074#ifdef FEAT_BROWSE
7075 /* 'browsedir' */
7076 else if (varp == &p_bsdir)
7077 {
7078 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7079 && !mch_isdir(p_bsdir))
7080 errmsg = e_invarg;
7081 }
7082#endif
7083
Bram Moolenaar071d4272004-06-13 20:20:40 +00007084 /* 'keymodel' */
7085 else if (varp == &p_km)
7086 {
7087 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7088 errmsg = e_invarg;
7089 else
7090 {
7091 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7092 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7093 }
7094 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007095
7096 /* 'mousemodel' */
7097 else if (varp == &p_mousem)
7098 {
7099 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7100 errmsg = e_invarg;
7101#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7102 else if (*p_mousem != *oldval)
7103 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7104 * to create or delete the popup menus. */
7105 gui_motif_update_mousemodel(root_menu);
7106#endif
7107 }
7108
7109 /* 'switchbuf' */
7110 else if (varp == &p_swb)
7111 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007112 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007113 errmsg = e_invarg;
7114 }
7115
7116 /* 'debug' */
7117 else if (varp == &p_debug)
7118 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007119 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 errmsg = e_invarg;
7121 }
7122
7123 /* 'display' */
7124 else if (varp == &p_dy)
7125 {
7126 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7127 errmsg = e_invarg;
7128 else
7129 (void)init_chartab();
7130
7131 }
7132
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 /* 'eadirection' */
7134 else if (varp == &p_ead)
7135 {
7136 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7137 errmsg = e_invarg;
7138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007139
7140#ifdef FEAT_CLIPBOARD
7141 /* 'clipboard' */
7142 else if (varp == &p_cb)
7143 errmsg = check_clipboard_option();
7144#endif
7145
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007146#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007147 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7148 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007149 else if (varp == &(curwin->w_s->b_p_spl)
7150 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007151 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007152 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7153
7154 if ((is_spellfile && !valid_spellfile(*varp))
7155 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007156 errmsg = e_invarg;
7157 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007158 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007159 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007160 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007161 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007162 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007163 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007164 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007165 /* 'spellsuggest' */
7166 else if (varp == &p_sps)
7167 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007168 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007169 errmsg = e_invarg;
7170 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007171 /* 'mkspellmem' */
7172 else if (varp == &p_msm)
7173 {
7174 if (spell_check_msm() != OK)
7175 errmsg = e_invarg;
7176 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007177#endif
7178
Bram Moolenaar071d4272004-06-13 20:20:40 +00007179 /* When 'bufhidden' is set, check for valid value. */
7180 else if (gvarp == &p_bh)
7181 {
7182 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7183 errmsg = e_invarg;
7184 }
7185
7186 /* When 'buftype' is set, check for valid value. */
7187 else if (gvarp == &p_bt)
7188 {
7189 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7190 errmsg = e_invarg;
7191 else
7192 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007193 if (curwin->w_status_height)
7194 {
7195 curwin->w_redr_status = TRUE;
7196 redraw_later(VALID);
7197 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007199#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007200 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007201#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007202 }
7203 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007204
7205#ifdef FEAT_STL_OPT
7206 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007207 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007208 {
7209 int wid;
7210
7211 if (varp == &p_ruf) /* reset ru_wid first */
7212 ru_wid = 0;
7213 s = *varp;
7214 if (varp == &p_ruf && *s == '%')
7215 {
7216 /* set ru_wid if 'ruf' starts with "%99(" */
7217 if (*++s == '-') /* ignore a '-' */
7218 s++;
7219 wid = getdigits(&s);
7220 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7221 ru_wid = wid;
7222 else
7223 errmsg = check_stl_option(p_ruf);
7224 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007225 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007226 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007227 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007228 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007229 comp_col();
7230 }
7231#endif
7232
7233#ifdef FEAT_INS_EXPAND
7234 /* check if it is a valid value for 'complete' -- Acevedo */
7235 else if (gvarp == &p_cpt)
7236 {
7237 for (s = *varp; *s;)
7238 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007239 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007240 s++;
7241 if (!*s)
7242 break;
7243 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7244 {
7245 errmsg = illegal_char(errbuf, *s);
7246 break;
7247 }
7248 if (*++s != NUL && *s != ',' && *s != ' ')
7249 {
7250 if (s[-1] == 'k' || s[-1] == 's')
7251 {
7252 /* skip optional filename after 'k' and 's' */
7253 while (*s && *s != ',' && *s != ' ')
7254 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007255 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007256 ++s;
7257 ++s;
7258 }
7259 }
7260 else
7261 {
7262 if (errbuf != NULL)
7263 {
7264 sprintf((char *)errbuf,
7265 _("E535: Illegal character after <%c>"),
7266 *--s);
7267 errmsg = errbuf;
7268 }
7269 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007270 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007271 break;
7272 }
7273 }
7274 }
7275 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007276
7277 /* 'completeopt' */
7278 else if (varp == &p_cot)
7279 {
7280 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7281 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007282 else
7283 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007284 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285#endif /* FEAT_INS_EXPAND */
7286
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007287#ifdef FEAT_SIGNS
7288 /* 'signcolumn' */
7289 else if (varp == &curwin->w_p_scl)
7290 {
7291 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7292 errmsg = e_invarg;
7293 }
7294#endif
7295
Bram Moolenaar071d4272004-06-13 20:20:40 +00007296
Bram Moolenaar4f974752019-02-17 17:44:42 +01007297#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007298 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007299 else if (varp == &p_toolbar)
7300 {
7301 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7302 &toolbar_flags, TRUE) != OK)
7303 errmsg = e_invarg;
7304 else
7305 {
7306 out_flush();
7307 gui_mch_show_toolbar((toolbar_flags &
7308 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7309 }
7310 }
7311#endif
7312
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007313#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007314 /* 'toolbariconsize': GTK+ 2 only */
7315 else if (varp == &p_tbis)
7316 {
7317 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7318 errmsg = e_invarg;
7319 else
7320 {
7321 out_flush();
7322 gui_mch_show_toolbar((toolbar_flags &
7323 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7324 }
7325 }
7326#endif
7327
7328 /* 'pastetoggle': translate key codes like in a mapping */
7329 else if (varp == &p_pt)
7330 {
7331 if (*p_pt)
7332 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007333 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007334 if (p != NULL)
7335 {
7336 if (new_value_alloced)
7337 free_string_option(p_pt);
7338 p_pt = p;
7339 new_value_alloced = TRUE;
7340 }
7341 }
7342 }
7343
7344 /* 'backspace' */
7345 else if (varp == &p_bs)
7346 {
7347 if (VIM_ISDIGIT(*p_bs))
7348 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007349 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350 errmsg = e_invarg;
7351 }
7352 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7353 errmsg = e_invarg;
7354 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007355 else if (varp == &p_bo)
7356 {
7357 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7358 errmsg = e_invarg;
7359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007360
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007361 /* 'tagcase' */
7362 else if (gvarp == &p_tc)
7363 {
7364 unsigned int *flags;
7365
7366 if (opt_flags & OPT_LOCAL)
7367 {
7368 p = curbuf->b_p_tc;
7369 flags = &curbuf->b_tc_flags;
7370 }
7371 else
7372 {
7373 p = p_tc;
7374 flags = &tc_flags;
7375 }
7376
7377 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7378 /* make the local value empty: use the global value */
7379 *flags = 0;
7380 else if (*p == NUL
7381 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7382 errmsg = e_invarg;
7383 }
7384
Bram Moolenaar071d4272004-06-13 20:20:40 +00007385 /* 'casemap' */
7386 else if (varp == &p_cmp)
7387 {
7388 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7389 errmsg = e_invarg;
7390 }
7391
7392#ifdef FEAT_DIFF
7393 /* 'diffopt' */
7394 else if (varp == &p_dip)
7395 {
7396 if (diffopt_changed() == FAIL)
7397 errmsg = e_invarg;
7398 }
7399#endif
7400
7401#ifdef FEAT_FOLDING
7402 /* 'foldmethod' */
7403 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7404 {
7405 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7406 || *curwin->w_p_fdm == NUL)
7407 errmsg = e_invarg;
7408 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007409 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007410 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007411 if (foldmethodIsDiff(curwin))
7412 newFoldLevel();
7413 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007414 }
7415# ifdef FEAT_EVAL
7416 /* 'foldexpr' */
7417 else if (varp == &curwin->w_p_fde)
7418 {
7419 if (foldmethodIsExpr(curwin))
7420 foldUpdateAll(curwin);
7421 }
7422# endif
7423 /* 'foldmarker' */
7424 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7425 {
7426 p = vim_strchr(*varp, ',');
7427 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007428 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007429 else if (p == *varp || p[1] == NUL)
7430 errmsg = e_invarg;
7431 else if (foldmethodIsMarker(curwin))
7432 foldUpdateAll(curwin);
7433 }
7434 /* 'commentstring' */
7435 else if (gvarp == &p_cms)
7436 {
7437 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007438 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007439 }
7440 /* 'foldopen' */
7441 else if (varp == &p_fdo)
7442 {
7443 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7444 errmsg = e_invarg;
7445 }
7446 /* 'foldclose' */
7447 else if (varp == &p_fcl)
7448 {
7449 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7450 errmsg = e_invarg;
7451 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007452 /* 'foldignore' */
7453 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7454 {
7455 if (foldmethodIsIndent(curwin))
7456 foldUpdateAll(curwin);
7457 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007458#endif
7459
Bram Moolenaar071d4272004-06-13 20:20:40 +00007460 /* 'virtualedit' */
7461 else if (varp == &p_ve)
7462 {
7463 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7464 errmsg = e_invarg;
7465 else if (STRCMP(p_ve, oldval) != 0)
7466 {
7467 /* Recompute cursor position in case the new 've' setting
7468 * changes something. */
7469 validate_virtcol();
7470 coladvance(curwin->w_virtcol);
7471 }
7472 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007473
7474#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7475 else if (varp == &p_csqf)
7476 {
7477 if (p_csqf != NULL)
7478 {
7479 p = p_csqf;
7480 while (*p != NUL)
7481 {
7482 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7483 || p[1] == NUL
7484 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7485 || (p[2] != NUL && p[2] != ','))
7486 {
7487 errmsg = e_invarg;
7488 break;
7489 }
7490 else if (p[2] == NUL)
7491 break;
7492 else
7493 p += 3;
7494 }
7495 }
7496 }
7497#endif
7498
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007499#ifdef FEAT_CINDENT
7500 /* 'cinoptions' */
7501 else if (gvarp == &p_cino)
7502 {
7503 /* TODO: recognize errors */
7504 parse_cino(curbuf);
7505 }
7506#endif
7507
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007508#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007509 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007510 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007511 {
7512 if (!gui_mch_set_rendering_options(p_rop))
7513 errmsg = e_invarg;
7514 }
7515#endif
7516
Bram Moolenaard0b51382016-11-04 15:23:45 +01007517 else if (gvarp == &p_ft)
7518 {
7519 if (!valid_filetype(*varp))
7520 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007521 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007522 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007523 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007524
7525 // Since we check the value, there is no need to set P_INSECURE,
7526 // even when the value comes from a modeline.
7527 *value_checked = TRUE;
7528 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007529 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007530
7531#ifdef FEAT_SYN_HL
7532 else if (gvarp == &p_syn)
7533 {
7534 if (!valid_filetype(*varp))
7535 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007536 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007537 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007538 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007539
7540 // Since we check the value, there is no need to set P_INSECURE,
7541 // even when the value comes from a modeline.
7542 *value_checked = TRUE;
7543 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007544 }
7545#endif
7546
Bram Moolenaar825680f2017-07-22 17:04:02 +02007547#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007548 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007549 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007550 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007551 if (*curwin->w_p_twk != NUL
7552 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007553 errmsg = e_invarg;
7554 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007555 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007556 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007557 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007558 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007559 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007560 p = skipdigits(curwin->w_p_tws);
7561 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007562 || (*p != 'x' && *p != '*')
7563 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007564 errmsg = e_invarg;
7565 }
7566 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007567# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007568 // 'termwintype'
7569 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007570 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007571 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007572 errmsg = e_invarg;
7573 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007574# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007575#endif
7576
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007577#ifdef FEAT_VARTABS
7578 /* 'varsofttabstop' */
7579 else if (varp == &(curbuf->b_p_vsts))
7580 {
7581 char_u *cp;
7582
7583 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7584 {
7585 if (curbuf->b_p_vsts_array)
7586 {
7587 vim_free(curbuf->b_p_vsts_array);
7588 curbuf->b_p_vsts_array = 0;
7589 }
7590 }
7591 else
7592 {
7593 for (cp = *varp; *cp; ++cp)
7594 {
7595 if (vim_isdigit(*cp))
7596 continue;
7597 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7598 continue;
7599 errmsg = e_invarg;
7600 break;
7601 }
7602 if (errmsg == NULL)
7603 {
7604 int *oldarray = curbuf->b_p_vsts_array;
7605 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7606 {
7607 if (oldarray)
7608 vim_free(oldarray);
7609 }
7610 else
7611 errmsg = e_invarg;
7612 }
7613 }
7614 }
7615
7616 /* 'vartabstop' */
7617 else if (varp == &(curbuf->b_p_vts))
7618 {
7619 char_u *cp;
7620
7621 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7622 {
7623 if (curbuf->b_p_vts_array)
7624 {
7625 vim_free(curbuf->b_p_vts_array);
7626 curbuf->b_p_vts_array = NULL;
7627 }
7628 }
7629 else
7630 {
7631 for (cp = *varp; *cp; ++cp)
7632 {
7633 if (vim_isdigit(*cp))
7634 continue;
7635 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7636 continue;
7637 errmsg = e_invarg;
7638 break;
7639 }
7640 if (errmsg == NULL)
7641 {
7642 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007643
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007644 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7645 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007646 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007647#ifdef FEAT_FOLDING
7648 if (foldmethodIsIndent(curwin))
7649 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007650#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007651 }
7652 else
7653 errmsg = e_invarg;
7654 }
7655 }
7656 }
7657#endif
7658
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 /* Options that are a list of flags. */
7660 else
7661 {
7662 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007663 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007664 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007665 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007666 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007667 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007668 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007669 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007670 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007671#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007672 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007673 p = (char_u *)COCU_ALL;
7674#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007675 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007676 {
7677#ifdef FEAT_MOUSE
7678 p = (char_u *)MOUSE_ALL;
7679#else
7680 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007681 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007682#endif
7683 }
7684#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007685 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007686 p = (char_u *)GO_ALL;
7687#endif
7688 if (p != NULL)
7689 {
7690 for (s = *varp; *s; ++s)
7691 if (vim_strchr(p, *s) == NULL)
7692 {
7693 errmsg = illegal_char(errbuf, *s);
7694 break;
7695 }
7696 }
7697 }
7698
7699 /*
7700 * If error detected, restore the previous value.
7701 */
7702 if (errmsg != NULL)
7703 {
7704 if (new_value_alloced)
7705 free_string_option(*varp);
7706 *varp = oldval;
7707 /*
7708 * When resetting some values, need to act on it.
7709 */
7710 if (did_chartab)
7711 (void)init_chartab();
7712 if (varp == &p_hl)
7713 (void)highlight_changed();
7714 }
7715 else
7716 {
7717#ifdef FEAT_EVAL
7718 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007719 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007720#endif
7721 /*
7722 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007723 * Use "free_oldval", because recursiveness may change the flags under
7724 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007725 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007726 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007727 free_string_option(oldval);
7728 if (new_value_alloced)
7729 options[opt_idx].flags |= P_ALLOCED;
7730 else
7731 options[opt_idx].flags &= ~P_ALLOCED;
7732
7733 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007734 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007735 {
7736 /* global option with local value set to use global value; free
7737 * the local value and make it empty */
7738 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7739 free_string_option(*(char_u **)p);
7740 *(char_u **)p = empty_option;
7741 }
7742
7743 /* May set global value for local option. */
7744 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7745 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007746
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007747 /*
7748 * Trigger the autocommand only after setting the flags.
7749 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007750#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007751 /* When 'syntax' is set, load the syntax of that name */
7752 if (varp == &(curbuf->b_p_syn))
7753 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007754 static int syn_recursive = 0;
7755
7756 ++syn_recursive;
7757 // Only pass TRUE for "force" when the value changed or not used
7758 // recursively, to avoid endless recurrence.
7759 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7760 value_changed || syn_recursive == 1, curbuf);
7761 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007762 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007763#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007764 else if (varp == &(curbuf->b_p_ft))
7765 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007766 /* 'filetype' is set, trigger the FileType autocommand.
7767 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007768 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007769 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007770 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007771 static int ft_recursive = 0;
7772 int secure_save = secure;
7773
7774 // Reset the secure flag, since the value of 'filetype' has
7775 // been checked to be safe.
7776 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007777
7778 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007779 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007780 // Only pass TRUE for "force" when the value changed or not
7781 // used recursively, to avoid endless recurrence.
7782 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7783 value_changed || ft_recursive == 1, curbuf);
7784 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007785 /* Just in case the old "curbuf" is now invalid. */
7786 if (varp != &(curbuf->b_p_ft))
7787 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007788
7789 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007790 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007791 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007792#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007793 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007794 {
7795 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007796 char_u *q = curwin->w_s->b_p_spl;
7797
7798 /* Skip the first name if it is "cjk". */
7799 if (STRNCMP(q, "cjk,", 4) == 0)
7800 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007801
7802 /*
7803 * Source the spell/LANG.vim in 'runtimepath'.
7804 * They could set 'spellcapcheck' depending on the language.
7805 * Use the first name in 'spelllang' up to '_region' or
7806 * '.encoding'.
7807 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007808 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007809 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007810 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007811 if (p > q)
7812 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007813 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7814 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007815 source_runtime(fname, DIP_ALL);
7816 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007817 }
7818#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007819 }
7820
7821#ifdef FEAT_MOUSE
7822 if (varp == &p_mouse)
7823 {
7824# ifdef FEAT_MOUSE_TTY
7825 if (*p_mouse == NUL)
7826 mch_setmouse(FALSE); /* switch mouse off */
7827 else
7828# endif
7829 setmouse(); /* in case 'mouse' changed */
7830 }
7831#endif
7832
Bram Moolenaar913077c2012-03-28 19:59:04 +02007833 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007834 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007835 curwin->w_set_curswant = TRUE;
7836
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007837#ifdef FEAT_GUI
7838 /* check redraw when it's not a GUI option or the GUI is active. */
7839 if (!redraw_gui_only || gui.in_use)
7840#endif
7841 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007842
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007843#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7844 if (did_swaptcap)
7845 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007846 set_termname((char_u *)"win32");
7847 init_highlight(TRUE, FALSE);
7848 }
7849#endif
7850
Bram Moolenaar071d4272004-06-13 20:20:40 +00007851 return errmsg;
7852}
7853
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007854#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007855/*
7856 * Simple int comparison function for use with qsort()
7857 */
7858 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007859int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007860{
7861 return *(const int *)a - *(const int *)b;
7862}
7863
7864/*
7865 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7866 * Returns error message, NULL if it's OK.
7867 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007868 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007869check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007870{
7871 char_u *s;
7872 int col;
7873 int count = 0;
7874 int color_cols[256];
7875 int i;
7876 int j = 0;
7877
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007878 if (wp->w_buffer == NULL)
7879 return NULL; /* buffer was closed */
7880
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007881 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007882 {
7883 if (*s == '-' || *s == '+')
7884 {
7885 /* -N and +N: add to 'textwidth' */
7886 col = (*s == '-') ? -1 : 1;
7887 ++s;
7888 if (!VIM_ISDIGIT(*s))
7889 return e_invarg;
7890 col = col * getdigits(&s);
7891 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007892 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007893 col += wp->w_buffer->b_p_tw;
7894 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007895 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007896 }
7897 else if (VIM_ISDIGIT(*s))
7898 col = getdigits(&s);
7899 else
7900 return e_invarg;
7901 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007902skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007903 if (*s == NUL)
7904 break;
7905 if (*s != ',')
7906 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007907 if (*++s == NUL)
7908 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007909 }
7910
7911 vim_free(wp->w_p_cc_cols);
7912 if (count == 0)
7913 wp->w_p_cc_cols = NULL;
7914 else
7915 {
7916 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7917 if (wp->w_p_cc_cols != NULL)
7918 {
7919 /* sort the columns for faster usage on screen redraw inside
7920 * win_line() */
7921 qsort(color_cols, count, sizeof(int), int_cmp);
7922
7923 for (i = 0; i < count; ++i)
7924 /* skip duplicates */
7925 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7926 wp->w_p_cc_cols[j++] = color_cols[i];
7927 wp->w_p_cc_cols[j] = -1; /* end marker */
7928 }
7929 }
7930
7931 return NULL; /* no error */
7932}
7933#endif
7934
Bram Moolenaar071d4272004-06-13 20:20:40 +00007935/*
7936 * Handle setting 'listchars' or 'fillchars'.
7937 * Returns error message, NULL if it's OK.
7938 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007939 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007940set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007941{
7942 int round, i, len, entries;
7943 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007944 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007945 struct charstab
7946 {
7947 int *cp;
7948 char *name;
7949 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007950 static struct charstab filltab[] =
7951 {
7952 {&fill_stl, "stl"},
7953 {&fill_stlnc, "stlnc"},
7954 {&fill_vert, "vert"},
7955 {&fill_fold, "fold"},
7956 {&fill_diff, "diff"},
7957 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 static struct charstab lcstab[] =
7959 {
7960 {&lcs_eol, "eol"},
7961 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007962 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007964 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007965 {&lcs_tab2, "tab"},
7966 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007967#ifdef FEAT_CONCEAL
7968 {&lcs_conceal, "conceal"},
7969#else
7970 {NULL, "conceal"},
7971#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007972 };
7973 struct charstab *tab;
7974
Bram Moolenaar071d4272004-06-13 20:20:40 +00007975 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976 {
7977 tab = lcstab;
7978 entries = sizeof(lcstab) / sizeof(struct charstab);
7979 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980 else
7981 {
7982 tab = filltab;
7983 entries = sizeof(filltab) / sizeof(struct charstab);
7984 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985
7986 /* first round: check for valid value, second round: assign values */
7987 for (round = 0; round <= 1; ++round)
7988 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007989 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990 {
7991 /* After checking that the value is valid: set defaults: space for
7992 * 'fillchars', NUL for 'listchars' */
7993 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007994 if (tab[i].cp != NULL)
7995 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007996
Bram Moolenaar071d4272004-06-13 20:20:40 +00007997 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007998 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007999 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008000 lcs_tab3 = NUL;
8001 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 else
8003 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008004 }
8005 p = *varp;
8006 while (*p)
8007 {
8008 for (i = 0; i < entries; ++i)
8009 {
8010 len = (int)STRLEN(tab[i].name);
8011 if (STRNCMP(p, tab[i].name, len) == 0
8012 && p[len] == ':'
8013 && p[len + 1] != NUL)
8014 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008015 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008016 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008017 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008018 if (mb_char2cells(c1) > 1)
8019 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008020 if (tab[i].cp == &lcs_tab2)
8021 {
8022 if (*s == NUL)
8023 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008024 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008025 if (mb_char2cells(c2) > 1)
8026 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008027 if (!(*s == ',' || *s == NUL))
8028 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008029 c3 = mb_ptr2char_adv(&s);
8030 if (mb_char2cells(c3) > 1)
8031 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008032 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008033 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008034
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035 if (*s == ',' || *s == NUL)
8036 {
8037 if (round)
8038 {
8039 if (tab[i].cp == &lcs_tab2)
8040 {
8041 lcs_tab1 = c1;
8042 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008043 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008044 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008045 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008046 *(tab[i].cp) = c1;
8047
8048 }
8049 p = s;
8050 break;
8051 }
8052 }
8053 }
8054
8055 if (i == entries)
8056 return e_invarg;
8057 if (*p == ',')
8058 ++p;
8059 }
8060 }
8061
8062 return NULL; /* no error */
8063}
8064
8065#ifdef FEAT_STL_OPT
8066/*
8067 * Check validity of options with the 'statusline' format.
8068 * Return error message or NULL.
8069 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008070 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008071check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072{
8073 int itemcnt = 0;
8074 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008075 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008076
8077 while (*s && itemcnt < STL_MAX_ITEM)
8078 {
8079 /* Check for valid keys after % sequences */
8080 while (*s && *s != '%')
8081 s++;
8082 if (!*s)
8083 break;
8084 s++;
8085 if (*s != '%' && *s != ')')
8086 ++itemcnt;
8087 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8088 {
8089 s++;
8090 continue;
8091 }
8092 if (*s == ')')
8093 {
8094 s++;
8095 if (--groupdepth < 0)
8096 break;
8097 continue;
8098 }
8099 if (*s == '-')
8100 s++;
8101 while (VIM_ISDIGIT(*s))
8102 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008103 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008104 continue;
8105 if (*s == '.')
8106 {
8107 s++;
8108 while (*s && VIM_ISDIGIT(*s))
8109 s++;
8110 }
8111 if (*s == '(')
8112 {
8113 groupdepth++;
8114 continue;
8115 }
8116 if (vim_strchr(STL_ALL, *s) == NULL)
8117 {
8118 return illegal_char(errbuf, *s);
8119 }
8120 if (*s == '{')
8121 {
8122 s++;
8123 while (*s != '}' && *s)
8124 s++;
8125 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008126 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008127 }
8128 }
8129 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008130 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008131 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008132 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008133 return NULL;
8134}
8135#endif
8136
8137#ifdef FEAT_CLIPBOARD
8138/*
8139 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008140 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008142 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008143check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008145 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008146 int new_autoselect_star = FALSE;
8147 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008149 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008151 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008152 char_u *p;
8153
8154 for (p = p_cb; *p != NUL; )
8155 {
8156 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8157 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008158 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008159 p += 7;
8160 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008161 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008162 && (p[11] == ',' || p[11] == NUL))
8163 {
8164 new_unnamed |= CLIP_UNNAMED_PLUS;
8165 p += 11;
8166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008168 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008170 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 p += 10;
8172 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008173 else if (STRNCMP(p, "autoselectplus", 14) == 0
8174 && (p[14] == ',' || p[14] == NUL))
8175 {
8176 new_autoselect_plus = TRUE;
8177 p += 14;
8178 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008179 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008180 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181 {
8182 new_autoselectml = TRUE;
8183 p += 12;
8184 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008185 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8186 {
8187 new_html = TRUE;
8188 p += 4;
8189 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8191 {
8192 p += 8;
8193 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8194 if (new_exclude_prog == NULL)
8195 errmsg = e_invarg;
8196 break;
8197 }
8198 else
8199 {
8200 errmsg = e_invarg;
8201 break;
8202 }
8203 if (*p == ',')
8204 ++p;
8205 }
8206 if (errmsg == NULL)
8207 {
8208 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008209 clip_autoselect_star = new_autoselect_star;
8210 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008211 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008212 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008213 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008214 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008215#ifdef FEAT_GUI_GTK
8216 if (gui.in_use)
8217 {
8218 gui_gtk_set_selection_targets();
8219 gui_gtk_set_dnd_targets();
8220 }
8221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008222 }
8223 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008224 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225
8226 return errmsg;
8227}
8228#endif
8229
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008230#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008231/*
8232 * Handle side effects of setting 'spell'.
8233 * Return an error message or NULL for success.
8234 */
8235 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008236did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008237{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008238 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008239 win_T *wp;
8240 int l;
8241
8242 if (is_spellfile)
8243 {
8244 l = (int)STRLEN(curwin->w_s->b_p_spf);
8245 if (l > 0 && (l < 4
8246 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8247 errmsg = e_invarg;
8248 }
8249
8250 if (errmsg == NULL)
8251 {
8252 FOR_ALL_WINDOWS(wp)
8253 if (wp->w_buffer == curbuf && wp->w_p_spell)
8254 {
8255 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008256 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008257 }
8258 }
8259 return errmsg;
8260}
8261
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008262/*
8263 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8264 * Return error message when failed, NULL when OK.
8265 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008266 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008267compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008268{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008269 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008270 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008271
Bram Moolenaar860cae12010-06-05 23:22:07 +02008272 if (*synblock->b_p_spc == NUL)
8273 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008274 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008275 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008276 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008277 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008278 if (re != NULL)
8279 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008280 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008281 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008282 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008283 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008284 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008285 return e_invarg;
8286 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008287 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008288 }
8289
Bram Moolenaar473de612013-06-08 18:19:48 +02008290 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008291 return NULL;
8292}
8293#endif
8294
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008295#if defined(FEAT_EVAL) || defined(PROTO)
8296/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008297 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008298 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008299 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008300 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008301set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008302{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008303 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8304 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008305 sctx_T new_script_ctx = script_ctx;
8306
8307 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008308
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008309 /* Remember where the option was set. For local options need to do that
8310 * in the buffer or window structure. */
8311 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008312 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008313 if (both || (opt_flags & OPT_LOCAL))
8314 {
8315 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008316 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008317 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008318 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008319 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008320}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008321
8322/*
8323 * Set the script_ctx for a termcap option.
8324 * "name" must be the two character code, e.g. "RV".
8325 * When "name" is NULL use "opt_idx".
8326 */
8327 void
8328set_term_option_sctx_idx(char *name, int opt_idx)
8329{
8330 char_u buf[5];
8331 int idx;
8332
8333 if (name == NULL)
8334 idx = opt_idx;
8335 else
8336 {
8337 buf[0] = 't';
8338 buf[1] = '_';
8339 buf[2] = name[0];
8340 buf[3] = name[1];
8341 buf[4] = 0;
8342 idx = findoption(buf);
8343 }
8344 if (idx >= 0)
8345 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8346}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008347#endif
8348
Bram Moolenaar071d4272004-06-13 20:20:40 +00008349/*
8350 * Set the value of a boolean option, and take care of side effects.
8351 * Returns NULL for success, or an error message for an error.
8352 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008353 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008354set_bool_option(
8355 int opt_idx, /* index in options[] table */
8356 char_u *varp, /* pointer to the option variable */
8357 int value, /* new value */
8358 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008359{
8360 int old_value = *(int *)varp;
8361
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362 /* Disallow changing some options from secure mode */
8363 if ((secure
8364#ifdef HAVE_SANDBOX
8365 || sandbox != 0
8366#endif
8367 ) && (options[opt_idx].flags & P_SECURE))
8368 return e_secure;
8369
8370 *(int *)varp = value; /* set the new value */
8371#ifdef FEAT_EVAL
8372 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008373 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374#endif
8375
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008376#ifdef FEAT_GUI
8377 need_mouse_correct = TRUE;
8378#endif
8379
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380 /* May set global value for local option. */
8381 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8382 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8383
8384 /*
8385 * Handle side effects of changing a bool option.
8386 */
8387
8388 /* 'compatible' */
8389 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008390 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008391
Bram Moolenaar920694c2016-08-21 17:45:02 +02008392#ifdef FEAT_LANGMAP
8393 if ((int *)varp == &p_lrm)
8394 /* 'langremap' -> !'langnoremap' */
8395 p_lnr = !p_lrm;
8396 else if ((int *)varp == &p_lnr)
8397 /* 'langnoremap' -> !'langremap' */
8398 p_lrm = !p_lnr;
8399#endif
8400
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008401#ifdef FEAT_SYN_HL
8402 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8403 reset_cursorline();
8404#endif
8405
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008406#ifdef FEAT_PERSISTENT_UNDO
8407 /* 'undofile' */
8408 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8409 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008410 /* Only take action when the option was set. When reset we do not
8411 * delete the undo file, the option may be set again without making
8412 * any changes in between. */
8413 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008414 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008415 char_u hash[UNDO_HASH_SIZE];
8416 buf_T *save_curbuf = curbuf;
8417
Bram Moolenaar29323592016-07-24 22:04:11 +02008418 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008419 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008420 /* When 'undofile' is set globally: for every buffer, otherwise
8421 * only for the current buffer: Try to read in the undofile,
8422 * if one exists, the buffer wasn't changed and the buffer was
8423 * loaded */
8424 if ((curbuf == save_curbuf
8425 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8426 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8427 {
8428 u_compute_hash(hash);
8429 u_read_undo(NULL, hash, curbuf->b_fname);
8430 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008431 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008432 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008433 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008434 }
8435#endif
8436
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 else if ((int *)varp == &curbuf->b_p_ro)
8438 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008439 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8441 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008442
8443 /* when 'readonly' is set may give W10 again */
8444 if (curbuf->b_p_ro)
8445 curbuf->b_did_warn = FALSE;
8446
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008448 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008449#endif
8450 }
8451
Bram Moolenaar9c449722010-07-20 18:44:27 +02008452#ifdef FEAT_GUI
8453 else if ((int *)varp == &p_mh)
8454 {
8455 if (!p_mh)
8456 gui_mch_mousehide(FALSE);
8457 }
8458#endif
8459
Bram Moolenaara539df02010-08-01 14:35:05 +02008460 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008461 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008462 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008463# ifdef FEAT_TERMINAL
8464 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008465 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8466 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008467 {
8468 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008469 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008470 }
8471# endif
8472# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008473 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008474# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008475 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008476#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008477 /* when 'endofline' is changed, redraw the window title */
8478 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008479 {
8480 redraw_titles();
8481 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008482 /* when 'fixeol' is changed, redraw the window title */
8483 else if ((int *)varp == &curbuf->b_p_fixeol)
8484 {
8485 redraw_titles();
8486 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008487 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008488 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008489 {
8490 redraw_titles();
8491 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008492#endif
8493
8494 /* when 'bin' is set also set some other options */
8495 else if ((int *)varp == &curbuf->b_p_bin)
8496 {
8497 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8498#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008499 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500#endif
8501 }
8502
Bram Moolenaar071d4272004-06-13 20:20:40 +00008503 /* when 'buflisted' changes, trigger autocommands */
8504 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8505 {
8506 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8507 NULL, NULL, TRUE, curbuf);
8508 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008509
8510 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8511 else if ((int *)varp == &curbuf->b_p_swf)
8512 {
8513 if (curbuf->b_p_swf && p_uc)
8514 ml_open_file(curbuf); /* create the swap file */
8515 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008516 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8517 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008518 mf_close_file(curbuf, TRUE); /* remove the swap file */
8519 }
8520
8521 /* when 'terse' is set change 'shortmess' */
8522 else if ((int *)varp == &p_terse)
8523 {
8524 char_u *p;
8525
8526 p = vim_strchr(p_shm, SHM_SEARCH);
8527
8528 /* insert 's' in p_shm */
8529 if (p_terse && p == NULL)
8530 {
8531 STRCPY(IObuff, p_shm);
8532 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008533 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008534 }
8535 /* remove 's' from p_shm */
8536 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008537 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008538 }
8539
8540 /* when 'paste' is set or reset also change other options */
8541 else if ((int *)varp == &p_paste)
8542 {
8543 paste_option_changed();
8544 }
8545
8546 /* when 'insertmode' is set from an autocommand need to do work here */
8547 else if ((int *)varp == &p_im)
8548 {
8549 if (p_im)
8550 {
8551 if ((State & INSERT) == 0)
8552 need_start_insertmode = TRUE;
8553 stop_insert_mode = FALSE;
8554 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008555 /* only reset if it was set previously */
8556 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008557 {
8558 need_start_insertmode = FALSE;
8559 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008560 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561 clear_cmdline = TRUE; /* remove "(insert)" */
8562 restart_edit = 0;
8563 }
8564 }
8565
8566 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8567 else if ((int *)varp == &p_ic && p_hls)
8568 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008569 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008570 }
8571
8572#ifdef FEAT_SEARCH_EXTRA
8573 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8574 else if ((int *)varp == &p_hls)
8575 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008576 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577 }
8578#endif
8579
Bram Moolenaar071d4272004-06-13 20:20:40 +00008580 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8581 * at the end of normal_cmd() */
8582 else if ((int *)varp == &curwin->w_p_scb)
8583 {
8584 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008585 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008587 curwin->w_scbind_pos = curwin->w_topline;
8588 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590
Bram Moolenaar4033c552017-09-16 20:54:51 +02008591#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008592 /* There can be only one window with 'previewwindow' set. */
8593 else if ((int *)varp == &curwin->w_p_pvw)
8594 {
8595 if (curwin->w_p_pvw)
8596 {
8597 win_T *win;
8598
Bram Moolenaar29323592016-07-24 22:04:11 +02008599 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008600 if (win->w_p_pvw && win != curwin)
8601 {
8602 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008603 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008604 }
8605 }
8606 }
8607#endif
8608
8609 /* when 'textmode' is set or reset also change 'fileformat' */
8610 else if ((int *)varp == &curbuf->b_p_tx)
8611 {
8612 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8613 }
8614
8615 /* when 'textauto' is set or reset also change 'fileformats' */
8616 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008617 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008618 set_string_option_direct((char_u *)"ffs", -1,
8619 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008620 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008621 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622
8623 /*
8624 * When 'lisp' option changes include/exclude '-' in
8625 * keyword characters.
8626 */
8627#ifdef FEAT_LISP
8628 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8629 {
8630 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8631 }
8632#endif
8633
8634#ifdef FEAT_TITLE
8635 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008636 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008637 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008638 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639 }
8640#endif
8641
8642 else if ((int *)varp == &curbuf->b_changed)
8643 {
8644 if (!value)
8645 save_file_ff(curbuf); /* Buffer is unchanged */
8646#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008647 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008648#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008649 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008650 }
8651
8652#ifdef BACKSLASH_IN_FILENAME
8653 else if ((int *)varp == &p_ssl)
8654 {
8655 if (p_ssl)
8656 {
8657 psepc = '/';
8658 psepcN = '\\';
8659 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008660 }
8661 else
8662 {
8663 psepc = '\\';
8664 psepcN = '/';
8665 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008666 }
8667
8668 /* need to adjust the file name arguments and buffer names. */
8669 buflist_slash_adjust();
8670 alist_slash_adjust();
8671# ifdef FEAT_EVAL
8672 scriptnames_slash_adjust();
8673# endif
8674 }
8675#endif
8676
8677 /* If 'wrap' is set, set w_leftcol to zero. */
8678 else if ((int *)varp == &curwin->w_p_wrap)
8679 {
8680 if (curwin->w_p_wrap)
8681 curwin->w_leftcol = 0;
8682 }
8683
Bram Moolenaar071d4272004-06-13 20:20:40 +00008684 else if ((int *)varp == &p_ea)
8685 {
8686 if (p_ea && !old_value)
8687 win_equal(curwin, FALSE, 0);
8688 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008689
8690 else if ((int *)varp == &p_wiv)
8691 {
8692 /*
8693 * When 'weirdinvert' changed, set/reset 't_xs'.
8694 * Then set 'weirdinvert' according to value of 't_xs'.
8695 */
8696 if (p_wiv && !old_value)
8697 T_XS = (char_u *)"y";
8698 else if (!p_wiv && old_value)
8699 T_XS = empty_option;
8700 p_wiv = (*T_XS != NUL);
8701 }
8702
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008703#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704 else if ((int *)varp == &p_beval)
8705 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008706 if (!balloonEvalForTerm)
8707 {
8708 if (p_beval && !old_value)
8709 gui_mch_enable_beval_area(balloonEval);
8710 else if (!p_beval && old_value)
8711 gui_mch_disable_beval_area(balloonEval);
8712 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008713 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008714#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008715#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008716 else if ((int *)varp == &p_bevalterm)
8717 {
8718 mch_bevalterm_changed();
8719 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008720#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008721
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008722#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723 else if ((int *)varp == &p_acd)
8724 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008725 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008726 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008727 }
8728#endif
8729
8730#ifdef FEAT_DIFF
8731 /* 'diff' */
8732 else if ((int *)varp == &curwin->w_p_diff)
8733 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008734 /* May add or remove the buffer from the list of diff buffers. */
8735 diff_buf_adjust(curwin);
8736# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008737 if (foldmethodIsDiff(curwin))
8738 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008739# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740 }
8741#endif
8742
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008743#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008744 /* 'imdisable' */
8745 else if ((int *)varp == &p_imdisable)
8746 {
8747 /* Only de-activate it here, it will be enabled when changing mode. */
8748 if (p_imdisable)
8749 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008750 else if (State & INSERT)
8751 /* When the option is set from an autocommand, it may need to take
8752 * effect right away. */
8753 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008754 }
8755#endif
8756
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008757#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008758 /* 'spell' */
8759 else if ((int *)varp == &curwin->w_p_spell)
8760 {
8761 if (curwin->w_p_spell)
8762 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008763 char *errmsg = did_set_spelllang(curwin);
8764
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008765 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008766 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008767 }
8768 }
8769#endif
8770
Bram Moolenaar071d4272004-06-13 20:20:40 +00008771#ifdef FEAT_ARABIC
8772 if ((int *)varp == &curwin->w_p_arab)
8773 {
8774 if (curwin->w_p_arab)
8775 {
8776 /*
8777 * 'arabic' is set, handle various sub-settings.
8778 */
8779 if (!p_tbidi)
8780 {
8781 /* set rightleft mode */
8782 if (!curwin->w_p_rl)
8783 {
8784 curwin->w_p_rl = TRUE;
8785 changed_window_setting();
8786 }
8787
8788 /* Enable Arabic shaping (major part of what Arabic requires) */
8789 if (!p_arshape)
8790 {
8791 p_arshape = TRUE;
8792 redraw_later_clear();
8793 }
8794 }
8795
8796 /* Arabic requires a utf-8 encoding, inform the user if its not
8797 * set. */
8798 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008799 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008800 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8801
Bram Moolenaar8820b482017-03-16 17:23:31 +01008802 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008803 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008804#ifdef FEAT_EVAL
8805 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8806#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008807 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008808
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 /* set 'delcombine' */
8810 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008811
8812# ifdef FEAT_KEYMAP
8813 /* Force-set the necessary keymap for arabic */
8814 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8815 OPT_LOCAL);
8816# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008817 }
8818 else
8819 {
8820 /*
8821 * 'arabic' is reset, handle various sub-settings.
8822 */
8823 if (!p_tbidi)
8824 {
8825 /* reset rightleft mode */
8826 if (curwin->w_p_rl)
8827 {
8828 curwin->w_p_rl = FALSE;
8829 changed_window_setting();
8830 }
8831
8832 /* 'arabicshape' isn't reset, it is a global option and
8833 * another window may still need it "on". */
8834 }
8835
8836 /* 'delcombine' isn't reset, it is a global option and another
8837 * window may still want it "on". */
8838
8839# ifdef FEAT_KEYMAP
8840 /* Revert to the default keymap */
8841 curbuf->b_p_iminsert = B_IMODE_NONE;
8842 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8843# endif
8844 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008845 }
8846
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008847#endif
8848
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008849#ifdef FEAT_TERMGUICOLORS
8850 /* 'termguicolors' */
8851 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008852 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008853# ifdef FEAT_VTP
8854 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02008855 if (
8856# ifdef VIMDLL
8857 !gui.in_use && !gui.starting &&
8858# endif
8859 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008860 {
8861 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008862 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008863 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008864 if (is_term_win32())
8865 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008866# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008867# ifdef FEAT_GUI
8868 if (!gui.in_use && !gui.starting)
8869# endif
8870 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008871# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008872 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008873 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008874 {
8875 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008876 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008877 init_highlight(TRUE, FALSE);
8878 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008879# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008880 }
8881#endif
8882
Bram Moolenaar071d4272004-06-13 20:20:40 +00008883 /*
8884 * End of handling side effects for bool options.
8885 */
8886
Bram Moolenaar53744302015-07-17 17:38:22 +02008887 /* after handling side effects, call autocommand */
8888
Bram Moolenaar071d4272004-06-13 20:20:40 +00008889 options[opt_idx].flags |= P_WAS_SET;
8890
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008891#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008892 // Don't do this while starting up or recursively.
8893 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008894 {
8895 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008896
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008897 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8898 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8899 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008900 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8901 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8902 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8903 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8904 reset_v_option_vars();
8905 }
8906#endif
8907
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008909 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008910 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008911 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008912 check_redraw(options[opt_idx].flags);
8913
8914 return NULL;
8915}
8916
8917/*
8918 * Set the value of a number option, and take care of side effects.
8919 * Returns NULL for success, or an error message for an error.
8920 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008921 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008922set_num_option(
8923 int opt_idx, /* index in options[] table */
8924 char_u *varp, /* pointer to the option variable */
8925 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008926 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008927 size_t errbuflen, /* length of "errbuf" */
8928 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008929 OPT_MODELINE */
8930{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008931 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 long old_value = *(long *)varp;
8933 long old_Rows = Rows; /* remember old Rows */
8934 long old_Columns = Columns; /* remember old Columns */
8935 long *pp = (long *)varp;
8936
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008937 /* Disallow changing some options from secure mode. */
8938 if ((secure
8939#ifdef HAVE_SANDBOX
8940 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008942 ) && (options[opt_idx].flags & P_SECURE))
8943 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944
8945 *pp = value;
8946#ifdef FEAT_EVAL
8947 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008948 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008949#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008950#ifdef FEAT_GUI
8951 need_mouse_correct = TRUE;
8952#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008953
Bram Moolenaar14f24742012-08-08 18:01:05 +02008954 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008955 {
8956 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008957#ifdef FEAT_VARTABS
8958 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8959 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8960 ? tabstop_first(curbuf->b_p_vts_array)
8961 : curbuf->b_p_ts;
8962#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008963 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008964#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965 }
8966
8967 /*
8968 * Number options that need some action when changed
8969 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970 if (pp == &p_wh || pp == &p_hh)
8971 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008972 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973 if (p_wh < 1)
8974 {
8975 errmsg = e_positive;
8976 p_wh = 1;
8977 }
8978 if (p_wmh > p_wh)
8979 {
8980 errmsg = e_winheight;
8981 p_wh = p_wmh;
8982 }
8983 if (p_hh < 0)
8984 {
8985 errmsg = e_positive;
8986 p_hh = 0;
8987 }
8988
8989 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008990 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008991 {
8992 if (pp == &p_wh && curwin->w_height < p_wh)
8993 win_setheight((int)p_wh);
8994 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8995 win_setheight((int)p_hh);
8996 }
8997 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008998 else if (pp == &p_wmh)
8999 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009000 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009001 if (p_wmh < 0)
9002 {
9003 errmsg = e_positive;
9004 p_wmh = 0;
9005 }
9006 if (p_wmh > p_wh)
9007 {
9008 errmsg = e_winheight;
9009 p_wmh = p_wh;
9010 }
9011 win_setminheight();
9012 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009013 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009014 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009015 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016 if (p_wiw < 1)
9017 {
9018 errmsg = e_positive;
9019 p_wiw = 1;
9020 }
9021 if (p_wmw > p_wiw)
9022 {
9023 errmsg = e_winwidth;
9024 p_wiw = p_wmw;
9025 }
9026
9027 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009028 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009029 win_setwidth((int)p_wiw);
9030 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009031 else if (pp == &p_wmw)
9032 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009033 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009034 if (p_wmw < 0)
9035 {
9036 errmsg = e_positive;
9037 p_wmw = 0;
9038 }
9039 if (p_wmw > p_wiw)
9040 {
9041 errmsg = e_winwidth;
9042 p_wmw = p_wiw;
9043 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009044 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009045 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009046
Bram Moolenaar071d4272004-06-13 20:20:40 +00009047 /* (re)set last window status line */
9048 else if (pp == &p_ls)
9049 {
9050 last_status(FALSE);
9051 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009052
9053 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009054 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009055 {
9056 shell_new_rows(); /* recompute window positions and heights */
9057 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009058
9059#ifdef FEAT_GUI
9060 else if (pp == &p_linespace)
9061 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009062 /* Recompute gui.char_height and resize the Vim window to keep the
9063 * same number of lines. */
9064 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009065 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009066 }
9067#endif
9068
9069#ifdef FEAT_FOLDING
9070 /* 'foldlevel' */
9071 else if (pp == &curwin->w_p_fdl)
9072 {
9073 if (curwin->w_p_fdl < 0)
9074 curwin->w_p_fdl = 0;
9075 newFoldLevel();
9076 }
9077
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009078 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009079 else if (pp == &curwin->w_p_fml)
9080 {
9081 foldUpdateAll(curwin);
9082 }
9083
9084 /* 'foldnestmax' */
9085 else if (pp == &curwin->w_p_fdn)
9086 {
9087 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9088 foldUpdateAll(curwin);
9089 }
9090
9091 /* 'foldcolumn' */
9092 else if (pp == &curwin->w_p_fdc)
9093 {
9094 if (curwin->w_p_fdc < 0)
9095 {
9096 errmsg = e_positive;
9097 curwin->w_p_fdc = 0;
9098 }
9099 else if (curwin->w_p_fdc > 12)
9100 {
9101 errmsg = e_invarg;
9102 curwin->w_p_fdc = 12;
9103 }
9104 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009105#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009106
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009107#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009108 /* 'shiftwidth' or 'tabstop' */
9109 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9110 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009111# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112 if (foldmethodIsIndent(curwin))
9113 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009114# endif
9115# ifdef FEAT_CINDENT
9116 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9117 * parse 'cinoptions'. */
9118 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9119 parse_cino(curbuf);
9120# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009121 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009122#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009123
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009124 /* 'maxcombine' */
9125 else if (pp == &p_mco)
9126 {
9127 if (p_mco > MAX_MCO)
9128 p_mco = MAX_MCO;
9129 else if (p_mco < 0)
9130 p_mco = 0;
9131 screenclear(); /* will re-allocate the screen */
9132 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009133
Bram Moolenaar071d4272004-06-13 20:20:40 +00009134 else if (pp == &curbuf->b_p_iminsert)
9135 {
9136 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9137 {
9138 errmsg = e_invarg;
9139 curbuf->b_p_iminsert = B_IMODE_NONE;
9140 }
9141 p_iminsert = curbuf->b_p_iminsert;
9142 if (termcap_active) /* don't do this in the alternate screen */
9143 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009144#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009145 /* Show/unshow value of 'keymap' in status lines. */
9146 status_redraw_curbuf();
9147#endif
9148 }
9149
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009150#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9151 /* 'imstyle' */
9152 else if (pp == &p_imst)
9153 {
9154 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9155 errmsg = e_invarg;
9156 }
9157#endif
9158
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009159 else if (pp == &p_window)
9160 {
9161 if (p_window < 1)
9162 p_window = 1;
9163 else if (p_window >= Rows)
9164 p_window = Rows - 1;
9165 }
9166
Bram Moolenaar071d4272004-06-13 20:20:40 +00009167 else if (pp == &curbuf->b_p_imsearch)
9168 {
9169 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9170 {
9171 errmsg = e_invarg;
9172 curbuf->b_p_imsearch = B_IMODE_NONE;
9173 }
9174 p_imsearch = curbuf->b_p_imsearch;
9175 }
9176
9177#ifdef FEAT_TITLE
9178 /* if 'titlelen' has changed, redraw the title */
9179 else if (pp == &p_titlelen)
9180 {
9181 if (p_titlelen < 0)
9182 {
9183 errmsg = e_positive;
9184 p_titlelen = 85;
9185 }
9186 if (starting != NO_SCREEN && old_value != p_titlelen)
9187 need_maketitle = TRUE;
9188 }
9189#endif
9190
9191 /* if p_ch changed value, change the command line height */
9192 else if (pp == &p_ch)
9193 {
9194 if (p_ch < 1)
9195 {
9196 errmsg = e_positive;
9197 p_ch = 1;
9198 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009199 if (p_ch > Rows - min_rows() + 1)
9200 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009201
9202 /* Only compute the new window layout when startup has been
9203 * completed. Otherwise the frame sizes may be wrong. */
9204 if (p_ch != old_value && full_screen
9205#ifdef FEAT_GUI
9206 && !gui.starting
9207#endif
9208 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009209 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009210 }
9211
9212 /* when 'updatecount' changes from zero to non-zero, open swap files */
9213 else if (pp == &p_uc)
9214 {
9215 if (p_uc < 0)
9216 {
9217 errmsg = e_positive;
9218 p_uc = 100;
9219 }
9220 if (p_uc && !old_value)
9221 ml_open_files();
9222 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009223#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009224 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009225 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009226 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009227 {
9228 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009229 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009230 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009231 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009232 {
9233 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009234 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009235 }
9236 }
9237#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009238#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009239 else if (pp == &p_mzq)
9240 mzvim_reset_timer();
9241#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009242
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009243#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9244 /* 'pyxversion' */
9245 else if (pp == &p_pyx)
9246 {
9247 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9248 errmsg = e_invarg;
9249 }
9250#endif
9251
Bram Moolenaar071d4272004-06-13 20:20:40 +00009252 /* sync undo before 'undolevels' changes */
9253 else if (pp == &p_ul)
9254 {
9255 /* use the old value, otherwise u_sync() may not work properly */
9256 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009257 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009258 p_ul = value;
9259 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009260 else if (pp == &curbuf->b_p_ul)
9261 {
9262 /* use the old value, otherwise u_sync() may not work properly */
9263 curbuf->b_p_ul = old_value;
9264 u_sync(TRUE);
9265 curbuf->b_p_ul = value;
9266 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009267
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009268#ifdef FEAT_LINEBREAK
9269 /* 'numberwidth' must be positive */
9270 else if (pp == &curwin->w_p_nuw)
9271 {
9272 if (curwin->w_p_nuw < 1)
9273 {
9274 errmsg = e_positive;
9275 curwin->w_p_nuw = 1;
9276 }
9277 if (curwin->w_p_nuw > 10)
9278 {
9279 errmsg = e_invarg;
9280 curwin->w_p_nuw = 10;
9281 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009282 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009283 }
9284#endif
9285
Bram Moolenaar1a384422010-07-14 19:53:30 +02009286 else if (pp == &curbuf->b_p_tw)
9287 {
9288 if (curbuf->b_p_tw < 0)
9289 {
9290 errmsg = e_positive;
9291 curbuf->b_p_tw = 0;
9292 }
9293#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009294 {
9295 win_T *wp;
9296 tabpage_T *tp;
9297
9298 FOR_ALL_TAB_WINDOWS(tp, wp)
9299 check_colorcolumn(wp);
9300 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009301#endif
9302 }
9303
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304 /*
9305 * Check the bounds for numeric options here
9306 */
9307 if (Rows < min_rows() && full_screen)
9308 {
9309 if (errbuf != NULL)
9310 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009311 vim_snprintf((char *)errbuf, errbuflen,
9312 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009313 errmsg = errbuf;
9314 }
9315 Rows = min_rows();
9316 }
9317 if (Columns < MIN_COLUMNS && full_screen)
9318 {
9319 if (errbuf != NULL)
9320 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009321 vim_snprintf((char *)errbuf, errbuflen,
9322 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009323 errmsg = errbuf;
9324 }
9325 Columns = MIN_COLUMNS;
9326 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009327 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009328
Bram Moolenaar071d4272004-06-13 20:20:40 +00009329 /*
9330 * If the screen (shell) height has been changed, assume it is the
9331 * physical screenheight.
9332 */
9333 if (old_Rows != Rows || old_Columns != Columns)
9334 {
9335 /* Changing the screen size is not allowed while updating the screen. */
9336 if (updating_screen)
9337 *pp = old_value;
9338 else if (full_screen
9339#ifdef FEAT_GUI
9340 && !gui.starting
9341#endif
9342 )
9343 set_shellsize((int)Columns, (int)Rows, TRUE);
9344 else
9345 {
9346 /* Postpone the resizing; check the size and cmdline position for
9347 * messages. */
9348 check_shellsize();
9349 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9350 cmdline_row = Rows - p_ch;
9351 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009352 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009353 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009354 }
9355
Bram Moolenaar071d4272004-06-13 20:20:40 +00009356 if (curbuf->b_p_ts <= 0)
9357 {
9358 errmsg = e_positive;
9359 curbuf->b_p_ts = 8;
9360 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009361 if (p_tm < 0)
9362 {
9363 errmsg = e_positive;
9364 p_tm = 0;
9365 }
9366 if ((curwin->w_p_scr <= 0
9367 || (curwin->w_p_scr > curwin->w_height
9368 && curwin->w_height > 0))
9369 && full_screen)
9370 {
9371 if (pp == &(curwin->w_p_scr))
9372 {
9373 if (curwin->w_p_scr != 0)
9374 errmsg = e_scroll;
9375 win_comp_scroll(curwin);
9376 }
9377 /* If 'scroll' became invalid because of a side effect silently adjust
9378 * it. */
9379 else if (curwin->w_p_scr <= 0)
9380 curwin->w_p_scr = 1;
9381 else /* curwin->w_p_scr > curwin->w_height */
9382 curwin->w_p_scr = curwin->w_height;
9383 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009384 if (p_hi < 0)
9385 {
9386 errmsg = e_positive;
9387 p_hi = 0;
9388 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009389 else if (p_hi > 10000)
9390 {
9391 errmsg = e_invarg;
9392 p_hi = 10000;
9393 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009394 if (p_re < 0 || p_re > 2)
9395 {
9396 errmsg = e_invarg;
9397 p_re = 0;
9398 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009399 if (p_report < 0)
9400 {
9401 errmsg = e_positive;
9402 p_report = 1;
9403 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009404 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009405 {
9406 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9407 p_sj = Rows / 2;
9408 else
9409 {
9410 errmsg = e_scroll;
9411 p_sj = 1;
9412 }
9413 }
9414 if (p_so < 0 && full_screen)
9415 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009416 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009417 p_so = 0;
9418 }
9419 if (p_siso < 0 && full_screen)
9420 {
9421 errmsg = e_positive;
9422 p_siso = 0;
9423 }
9424#ifdef FEAT_CMDWIN
9425 if (p_cwh < 1)
9426 {
9427 errmsg = e_positive;
9428 p_cwh = 1;
9429 }
9430#endif
9431 if (p_ut < 0)
9432 {
9433 errmsg = e_positive;
9434 p_ut = 2000;
9435 }
9436 if (p_ss < 0)
9437 {
9438 errmsg = e_positive;
9439 p_ss = 0;
9440 }
9441
9442 /* May set global value for local option. */
9443 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9444 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9445
9446 options[opt_idx].flags |= P_WAS_SET;
9447
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009448#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009449 // Don't do this while starting up, failure or recursively.
9450 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009451 {
9452 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01009453
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009454 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9455 vim_snprintf((char *)buf_new, 10, "%ld", value);
9456 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009457 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9458 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9459 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9460 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9461 reset_v_option_vars();
9462 }
9463#endif
9464
Bram Moolenaar071d4272004-06-13 20:20:40 +00009465 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009466 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009467 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009468 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009469 check_redraw(options[opt_idx].flags);
9470
9471 return errmsg;
9472}
9473
9474/*
9475 * Called after an option changed: check if something needs to be redrawn.
9476 */
9477 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009478check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009479{
9480 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009481 int doclear = (flags & P_RCLR) == P_RCLR;
9482 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009483
Bram Moolenaar071d4272004-06-13 20:20:40 +00009484 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9485 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009486
9487 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9488 changed_window_setting();
9489 if (flags & P_RBUF)
9490 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009491 if (flags & P_RWINONLY)
9492 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009493 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009494 redraw_all_later(CLEAR);
9495 else if (all)
9496 redraw_all_later(NOT_VALID);
9497}
9498
9499/*
9500 * Find index for option 'arg'.
9501 * Return -1 if not found.
9502 */
9503 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009504findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009505{
9506 int opt_idx;
9507 char *s, *p;
9508 static short quick_tab[27] = {0, 0}; /* quick access table */
9509 int is_term_opt;
9510
9511 /*
9512 * For first call: Initialize the quick-access table.
9513 * It contains the index for the first option that starts with a certain
9514 * letter. There are 26 letters, plus the first "t_" option.
9515 */
9516 if (quick_tab[1] == 0)
9517 {
9518 p = options[0].fullname;
9519 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9520 {
9521 if (s[0] != p[0])
9522 {
9523 if (s[0] == 't' && s[1] == '_')
9524 quick_tab[26] = opt_idx;
9525 else
9526 quick_tab[CharOrdLow(s[0])] = opt_idx;
9527 }
9528 p = s;
9529 }
9530 }
9531
9532 /*
9533 * Check for name starting with an illegal character.
9534 */
9535#ifdef EBCDIC
9536 if (!islower(arg[0]))
9537#else
9538 if (arg[0] < 'a' || arg[0] > 'z')
9539#endif
9540 return -1;
9541
9542 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9543 if (is_term_opt)
9544 opt_idx = quick_tab[26];
9545 else
9546 opt_idx = quick_tab[CharOrdLow(arg[0])];
9547 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9548 {
9549 if (STRCMP(arg, s) == 0) /* match full name */
9550 break;
9551 }
9552 if (s == NULL && !is_term_opt)
9553 {
9554 opt_idx = quick_tab[CharOrdLow(arg[0])];
9555 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9556 {
9557 s = options[opt_idx].shortname;
9558 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9559 break;
9560 s = NULL;
9561 }
9562 }
9563 if (s == NULL)
9564 opt_idx = -1;
9565 return opt_idx;
9566}
9567
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009568#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009569/*
9570 * Get the value for an option.
9571 *
9572 * Returns:
9573 * Number or Toggle option: 1, *numval gets value.
9574 * String option: 0, *stringval gets allocated string.
9575 * Hidden Number or Toggle option: -1.
9576 * hidden String option: -2.
9577 * unknown option: -3.
9578 */
9579 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009580get_option_value(
9581 char_u *name,
9582 long *numval,
9583 char_u **stringval, /* NULL when only checking existence */
9584 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009585{
9586 int opt_idx;
9587 char_u *varp;
9588
9589 opt_idx = findoption(name);
9590 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009591 {
9592 int key;
9593
9594 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009595 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009596 {
9597 char_u key_name[2];
9598 char_u *p;
9599
9600 if (key < 0)
9601 {
9602 key_name[0] = KEY2TERMCAP0(key);
9603 key_name[1] = KEY2TERMCAP1(key);
9604 }
9605 else
9606 {
9607 key_name[0] = KS_KEY;
9608 key_name[1] = (key & 0xff);
9609 }
9610 p = find_termcode(key_name);
9611 if (p != NULL)
9612 {
9613 if (stringval != NULL)
9614 *stringval = vim_strsave(p);
9615 return 0;
9616 }
9617 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009618 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009619 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620
9621 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9622
9623 if (options[opt_idx].flags & P_STRING)
9624 {
9625 if (varp == NULL) /* hidden option */
9626 return -2;
9627 if (stringval != NULL)
9628 {
9629#ifdef FEAT_CRYPT
9630 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009631 if ((char_u **)varp == &curbuf->b_p_key
9632 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009633 *stringval = vim_strsave((char_u *)"*****");
9634 else
9635#endif
9636 *stringval = vim_strsave(*(char_u **)(varp));
9637 }
9638 return 0;
9639 }
9640
9641 if (varp == NULL) /* hidden option */
9642 return -1;
9643 if (options[opt_idx].flags & P_NUM)
9644 *numval = *(long *)varp;
9645 else
9646 {
9647 /* Special case: 'modified' is b_changed, but we also want to consider
9648 * it set when 'ff' or 'fenc' changed. */
9649 if ((int *)varp == &curbuf->b_changed)
9650 *numval = curbufIsChanged();
9651 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009652 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009653 }
9654 return 1;
9655}
9656#endif
9657
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009658#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009659/*
9660 * Returns the option attributes and its value. Unlike the above function it
9661 * will return either global value or local value of the option depending on
9662 * what was requested, but it will never return global value if it was
9663 * requested to return local one and vice versa. Neither it will return
9664 * buffer-local value if it was requested to return window-local one.
9665 *
9666 * Pretends that option is absent if it is not present in the requested scope
9667 * (i.e. has no global, window-local or buffer-local value depending on
9668 * opt_type). Uses
9669 *
9670 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009671 * 0 hidden or unknown option, also option that does not have requested
9672 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009673 * see SOPT_* in vim.h for other flags
9674 *
9675 * Possible opt_type values: see SREQ_* in vim.h
9676 */
9677 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009678get_option_value_strict(
9679 char_u *name,
9680 long *numval,
9681 char_u **stringval, /* NULL when only obtaining attributes */
9682 int opt_type,
9683 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009684{
9685 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009686 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009687 struct vimoption *p;
9688 int r = 0;
9689
9690 opt_idx = findoption(name);
9691 if (opt_idx < 0)
9692 return 0;
9693
9694 p = &(options[opt_idx]);
9695
9696 /* Hidden option */
9697 if (p->var == NULL)
9698 return 0;
9699
9700 if (p->flags & P_BOOL)
9701 r |= SOPT_BOOL;
9702 else if (p->flags & P_NUM)
9703 r |= SOPT_NUM;
9704 else if (p->flags & P_STRING)
9705 r |= SOPT_STRING;
9706
9707 if (p->indir == PV_NONE)
9708 {
9709 if (opt_type == SREQ_GLOBAL)
9710 r |= SOPT_GLOBAL;
9711 else
9712 return 0; /* Did not request global-only option */
9713 }
9714 else
9715 {
9716 if (p->indir & PV_BOTH)
9717 r |= SOPT_GLOBAL;
9718 else if (opt_type == SREQ_GLOBAL)
9719 return 0; /* Requested global option */
9720
9721 if (p->indir & PV_WIN)
9722 {
9723 if (opt_type == SREQ_BUF)
9724 return 0; /* Did not request window-local option */
9725 else
9726 r |= SOPT_WIN;
9727 }
9728 else if (p->indir & PV_BUF)
9729 {
9730 if (opt_type == SREQ_WIN)
9731 return 0; /* Did not request buffer-local option */
9732 else
9733 r |= SOPT_BUF;
9734 }
9735 }
9736
9737 if (stringval == NULL)
9738 return r;
9739
9740 if (opt_type == SREQ_GLOBAL)
9741 varp = p->var;
9742 else
9743 {
9744 if (opt_type == SREQ_BUF)
9745 {
9746 /* Special case: 'modified' is b_changed, but we also want to
9747 * consider it set when 'ff' or 'fenc' changed. */
9748 if (p->indir == PV_MOD)
9749 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009750 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009751 varp = NULL;
9752 }
9753#ifdef FEAT_CRYPT
9754 else if (p->indir == PV_KEY)
9755 {
9756 /* never return the value of the crypt key */
9757 *stringval = NULL;
9758 varp = NULL;
9759 }
9760#endif
9761 else
9762 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009763 buf_T *save_curbuf = curbuf;
9764
9765 // only getting a pointer, no need to use aucmd_prepbuf()
9766 curbuf = (buf_T *)from;
9767 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009768 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009769 curbuf = save_curbuf;
9770 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009771 }
9772 }
9773 else if (opt_type == SREQ_WIN)
9774 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009775 win_T *save_curwin = curwin;
9776
9777 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009778 curbuf = curwin->w_buffer;
9779 varp = get_varp(p);
9780 curwin = save_curwin;
9781 curbuf = curwin->w_buffer;
9782 }
9783 if (varp == p->var)
9784 return (r | SOPT_UNSET);
9785 }
9786
9787 if (varp != NULL)
9788 {
9789 if (p->flags & P_STRING)
9790 *stringval = vim_strsave(*(char_u **)(varp));
9791 else if (p->flags & P_NUM)
9792 *numval = *(long *) varp;
9793 else
9794 *numval = *(int *)varp;
9795 }
9796
9797 return r;
9798}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009799
9800/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009801 * Iterate over options. First argument is a pointer to a pointer to a
9802 * structure inside options[] array, second is option type like in the above
9803 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009804 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009805 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009806 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009807 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009808 * first argument to NULL.
9809 *
9810 * Returns full option name for current option on each call.
9811 */
9812 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009813option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009814{
9815 struct vimoption *ret = NULL;
9816 do
9817 {
9818 if (*option == NULL)
9819 *option = (void *) options;
9820 else if (((struct vimoption *) (*option))->fullname == NULL)
9821 {
9822 *option = NULL;
9823 return NULL;
9824 }
9825 else
9826 *option = (void *) (((struct vimoption *) (*option)) + 1);
9827
9828 ret = ((struct vimoption *) (*option));
9829
9830 /* Hidden option */
9831 if (ret->var == NULL)
9832 {
9833 ret = NULL;
9834 continue;
9835 }
9836
9837 switch (opt_type)
9838 {
9839 case SREQ_GLOBAL:
9840 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9841 ret = NULL;
9842 break;
9843 case SREQ_BUF:
9844 if (!(ret->indir & PV_BUF))
9845 ret = NULL;
9846 break;
9847 case SREQ_WIN:
9848 if (!(ret->indir & PV_WIN))
9849 ret = NULL;
9850 break;
9851 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009852 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009853 return NULL;
9854 }
9855 }
9856 while (ret == NULL);
9857
9858 return (char_u *)ret->fullname;
9859}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009860#endif
9861
Bram Moolenaar071d4272004-06-13 20:20:40 +00009862/*
9863 * Set the value of option "name".
9864 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009865 *
9866 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009867 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009868 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009869set_option_value(
9870 char_u *name,
9871 long number,
9872 char_u *string,
9873 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009874{
9875 int opt_idx;
9876 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009877 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009878
9879 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009880 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009881 {
9882 int key;
9883
9884 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009885 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009886 {
9887 char_u key_name[2];
9888
9889 if (key < 0)
9890 {
9891 key_name[0] = KEY2TERMCAP0(key);
9892 key_name[1] = KEY2TERMCAP1(key);
9893 }
9894 else
9895 {
9896 key_name[0] = KS_KEY;
9897 key_name[1] = (key & 0xff);
9898 }
9899 add_termcode(key_name, string, FALSE);
9900 if (full_screen)
9901 ttest(FALSE);
9902 redraw_all_later(CLEAR);
9903 return NULL;
9904 }
9905
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009906 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009907 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009908 else
9909 {
9910 flags = options[opt_idx].flags;
9911#ifdef HAVE_SANDBOX
9912 /* Disallow changing some options in the sandbox */
9913 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009914 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009915 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009916 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009917 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009918#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009919 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009920 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009921 else
9922 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009923 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009924 if (varp != NULL) /* hidden option is not changed */
9925 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009926 if (number == 0 && string != NULL)
9927 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009928 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009929
9930 /* Either we are given a string or we are setting option
9931 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009932 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009933 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009934 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009935 {
9936 /* There's another character after zeros or the string
9937 * is empty. In both cases, we are trying to set a
9938 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009939 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009940 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009941 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009942
9943 }
9944 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009945 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009946 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009947 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009948 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009949 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009950 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009951 }
9952 }
9953 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009954 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009955}
9956
9957/*
9958 * Get the terminal code for a terminal option.
9959 * Returns NULL when not found.
9960 */
9961 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009962get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009963{
9964 int opt_idx;
9965 char_u *varp;
9966
9967 if (tname[0] != 't' || tname[1] != '_' ||
9968 tname[2] == NUL || tname[3] == NUL)
9969 return NULL;
9970 if ((opt_idx = findoption(tname)) >= 0)
9971 {
9972 varp = get_varp(&(options[opt_idx]));
9973 if (varp != NULL)
9974 varp = *(char_u **)(varp);
9975 return varp;
9976 }
9977 return find_termcode(tname + 2);
9978}
9979
9980 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009981get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009982{
9983 int i;
9984
9985 i = findoption((char_u *)"hl");
9986 if (i >= 0)
9987 return options[i].def_val[VI_DEFAULT];
9988 return (char_u *)NULL;
9989}
9990
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009991 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009992get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009993{
9994 int i;
9995
9996 i = findoption((char_u *)"enc");
9997 if (i >= 0)
9998 return options[i].def_val[VI_DEFAULT];
9999 return (char_u *)NULL;
10000}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010001
Bram Moolenaar071d4272004-06-13 20:20:40 +000010002/*
10003 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010004 * When "has_lt" is true there is a '<' before "*arg_arg".
10005 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006 */
10007 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010008find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010009{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010010 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010011 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010012 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010013
10014 /*
10015 * Don't use get_special_key_code() for t_xx, we don't want it to call
10016 * add_termcap_entry().
10017 */
10018 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10019 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010020 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010021 {
10022 --arg; /* put arg at the '<' */
10023 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010024 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010025 if (modifiers) /* can't handle modifiers here */
10026 key = 0;
10027 }
10028 return key;
10029}
10030
10031/*
10032 * if 'all' == 0: show changed options
10033 * if 'all' == 1: show all normal options
10034 * if 'all' == 2: show all terminal options
10035 */
10036 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010037showoptions(
10038 int all,
10039 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010040{
10041 struct vimoption *p;
10042 int col;
10043 int isterm;
10044 char_u *varp;
10045 struct vimoption **items;
10046 int item_count;
10047 int run;
10048 int row, rows;
10049 int cols;
10050 int i;
10051 int len;
10052
10053#define INC 20
10054#define GAP 3
10055
10056 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10057 PARAM_COUNT));
10058 if (items == NULL)
10059 return;
10060
10061 /* Highlight title */
10062 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010063 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010064 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010065 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010066 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010067 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010068 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010069 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070
10071 /*
10072 * do the loop two times:
10073 * 1. display the short items
10074 * 2. display the long items (only strings and numbers)
10075 */
10076 for (run = 1; run <= 2 && !got_int; ++run)
10077 {
10078 /*
10079 * collect the items in items[]
10080 */
10081 item_count = 0;
10082 for (p = &options[0]; p->fullname != NULL; p++)
10083 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010084 // apply :filter /pat/
10085 if (message_filtered((char_u *) p->fullname))
10086 continue;
10087
Bram Moolenaar071d4272004-06-13 20:20:40 +000010088 varp = NULL;
10089 isterm = istermoption(p);
10090 if (opt_flags != 0)
10091 {
10092 if (p->indir != PV_NONE && !isterm)
10093 varp = get_varp_scope(p, opt_flags);
10094 }
10095 else
10096 varp = get_varp(p);
10097 if (varp != NULL
10098 && ((all == 2 && isterm)
10099 || (all == 1 && !isterm)
10100 || (all == 0 && !optval_default(p, varp))))
10101 {
10102 if (p->flags & P_BOOL)
10103 len = 1; /* a toggle option fits always */
10104 else
10105 {
10106 option_value2string(p, opt_flags);
10107 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10108 }
10109 if ((len <= INC - GAP && run == 1) ||
10110 (len > INC - GAP && run == 2))
10111 items[item_count++] = p;
10112 }
10113 }
10114
10115 /*
10116 * display the items
10117 */
10118 if (run == 1)
10119 {
10120 cols = (Columns + GAP - 3) / INC;
10121 if (cols == 0)
10122 cols = 1;
10123 rows = (item_count + cols - 1) / cols;
10124 }
10125 else /* run == 2 */
10126 rows = item_count;
10127 for (row = 0; row < rows && !got_int; ++row)
10128 {
10129 msg_putchar('\n'); /* go to next line */
10130 if (got_int) /* 'q' typed in more */
10131 break;
10132 col = 0;
10133 for (i = row; i < item_count; i += rows)
10134 {
10135 msg_col = col; /* make columns */
10136 showoneopt(items[i], opt_flags);
10137 col += INC;
10138 }
10139 out_flush();
10140 ui_breakcheck();
10141 }
10142 }
10143 vim_free(items);
10144}
10145
10146/*
10147 * Return TRUE if option "p" has its default value.
10148 */
10149 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010150optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151{
10152 int dvi;
10153
10154 if (varp == NULL)
10155 return TRUE; /* hidden option is always at default */
10156 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10157 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010158 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010159 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010160 /* the cast to long is required for Manx C, long_i is
10161 * needed for MSVC */
10162 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010163 /* P_STRING */
10164 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10165}
10166
10167/*
10168 * showoneopt: show the value of one option
10169 * must not be called with a hidden option!
10170 */
10171 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010172showoneopt(
10173 struct vimoption *p,
10174 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010176 char_u *varp;
10177 int save_silent = silent_mode;
10178
10179 silent_mode = FALSE;
10180 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010181
10182 varp = get_varp_scope(p, opt_flags);
10183
10184 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10185 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10186 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010187 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010189 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010191 msg_puts(" ");
10192 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010193 if (!(p->flags & P_BOOL))
10194 {
10195 msg_putchar('=');
10196 /* put value string in NameBuff */
10197 option_value2string(p, opt_flags);
10198 msg_outtrans(NameBuff);
10199 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010200
10201 silent_mode = save_silent;
10202 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010203}
10204
10205/*
10206 * Write modified options as ":set" commands to a file.
10207 *
10208 * There are three values for "opt_flags":
10209 * OPT_GLOBAL: Write global option values and fresh values of
10210 * buffer-local options (used for start of a session
10211 * file).
10212 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10213 * curwin (used for a vimrc file).
10214 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10215 * and local values for window-local options of
10216 * curwin. Local values are also written when at the
10217 * default value, because a modeline or autocommand
10218 * may have set them when doing ":edit file" and the
10219 * user has set them back at the default or fresh
10220 * value.
10221 * When "local_only" is TRUE, don't write fresh
10222 * values, only local values (for ":mkview").
10223 * (fresh value = value used for a new buffer or window for a local option).
10224 *
10225 * Return FAIL on error, OK otherwise.
10226 */
10227 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010228makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010229{
10230 struct vimoption *p;
10231 char_u *varp; /* currently used value */
10232 char_u *varp_fresh; /* local value */
10233 char_u *varp_local = NULL; /* fresh value */
10234 char *cmd;
10235 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010236 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010237
10238 /*
10239 * The options that don't have a default (terminal name, columns, lines)
10240 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010241 * Do the loop over "options[]" twice: once for options with the
10242 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010243 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010244 for (pri = 1; pri >= 0; --pri)
10245 {
10246 for (p = &options[0]; !istermoption(p); p++)
10247 if (!(p->flags & P_NO_MKRC)
10248 && !istermoption(p)
10249 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010250 {
10251 /* skip global option when only doing locals */
10252 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10253 continue;
10254
10255 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10256 * file, they are always buffer-specific. */
10257 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10258 continue;
10259
10260 /* Global values are only written when not at the default value. */
10261 varp = get_varp_scope(p, opt_flags);
10262 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10263 continue;
10264
10265 round = 2;
10266 if (p->indir != PV_NONE)
10267 {
10268 if (p->var == VAR_WIN)
10269 {
10270 /* skip window-local option when only doing globals */
10271 if (!(opt_flags & OPT_LOCAL))
10272 continue;
10273 /* When fresh value of window-local option is not at the
10274 * default, need to write it too. */
10275 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10276 {
10277 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10278 if (!optval_default(p, varp_fresh))
10279 {
10280 round = 1;
10281 varp_local = varp;
10282 varp = varp_fresh;
10283 }
10284 }
10285 }
10286 }
10287
10288 /* Round 1: fresh value for window-local options.
10289 * Round 2: other values */
10290 for ( ; round <= 2; varp = varp_local, ++round)
10291 {
10292 if (round == 1 || (opt_flags & OPT_GLOBAL))
10293 cmd = "set";
10294 else
10295 cmd = "setlocal";
10296
10297 if (p->flags & P_BOOL)
10298 {
10299 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10300 return FAIL;
10301 }
10302 else if (p->flags & P_NUM)
10303 {
10304 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10305 return FAIL;
10306 }
10307 else /* P_STRING */
10308 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010309 int do_endif = FALSE;
10310
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311 /* Don't set 'syntax' and 'filetype' again if the value is
10312 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010313 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010314#if defined(FEAT_SYN_HL)
10315 p->indir == PV_SYN ||
10316#endif
10317 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318 {
10319 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10320 *(char_u **)(varp)) < 0
10321 || put_eol(fd) < 0)
10322 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010323 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324 }
10325 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010326 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010327 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010328 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329 {
10330 if (put_line(fd, "endif") == FAIL)
10331 return FAIL;
10332 }
10333 }
10334 }
10335 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337 return OK;
10338}
10339
10340#if defined(FEAT_FOLDING) || defined(PROTO)
10341/*
10342 * Generate set commands for the local fold options only. Used when
10343 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10344 */
10345 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010346makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010348 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010349# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010350 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010351 == FAIL
10352# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010353 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010354 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010355 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010356 == FAIL
10357 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10358 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10359 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10360 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10361 )
10362 return FAIL;
10363
10364 return OK;
10365}
10366#endif
10367
10368 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010369put_setstring(
10370 FILE *fd,
10371 char *cmd,
10372 char *name,
10373 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010374 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375{
10376 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010377 char_u *buf = NULL;
10378 char_u *part = NULL;
10379 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010380
10381 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10382 return FAIL;
10383 if (*valuep != NULL)
10384 {
10385 /* Output 'pastetoggle' as key names. For other
10386 * options some characters have to be escaped with
10387 * CTRL-V or backslash */
10388 if (valuep == &p_pt)
10389 {
10390 s = *valuep;
10391 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010392 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010393 return FAIL;
10394 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010395 // expand the option value, replace $HOME by ~
10396 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010397 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010398 int size = (int)STRLEN(*valuep) + 1;
10399
10400 // replace home directory in the whole option value into "buf"
10401 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010402 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010403 goto fail;
10404 home_replace(NULL, *valuep, buf, size, FALSE);
10405
10406 // If the option value is longer than MAXPATHL, we need to append
10407 // earch comma separated part of the option separately, so that it
10408 // can be expanded when read back.
10409 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10410 && vim_strchr(*valuep, ',') != NULL)
10411 {
10412 part = alloc(size);
10413 if (part == NULL)
10414 goto fail;
10415
10416 // write line break to clear the option, e.g. ':set rtp='
10417 if (put_eol(fd) == FAIL)
10418 goto fail;
10419
10420 p = buf;
10421 while (*p != NUL)
10422 {
10423 // for each comma separated option part, append value to
10424 // the option, :set rtp+=value
10425 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10426 goto fail;
10427 (void)copy_option_part(&p, part, size, ",");
10428 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10429 goto fail;
10430 }
10431 vim_free(buf);
10432 vim_free(part);
10433 return OK;
10434 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010436 {
10437 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010438 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010439 }
10440 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010441 }
10442 else if (put_escstr(fd, *valuep, 2) == FAIL)
10443 return FAIL;
10444 }
10445 if (put_eol(fd) < 0)
10446 return FAIL;
10447 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010448fail:
10449 vim_free(buf);
10450 vim_free(part);
10451 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452}
10453
10454 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010455put_setnum(
10456 FILE *fd,
10457 char *cmd,
10458 char *name,
10459 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010460{
10461 long wc;
10462
10463 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10464 return FAIL;
10465 if (wc_use_keyname((char_u *)valuep, &wc))
10466 {
10467 /* print 'wildchar' and 'wildcharm' as a key name */
10468 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10469 return FAIL;
10470 }
10471 else if (fprintf(fd, "%ld", *valuep) < 0)
10472 return FAIL;
10473 if (put_eol(fd) < 0)
10474 return FAIL;
10475 return OK;
10476}
10477
10478 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010479put_setbool(
10480 FILE *fd,
10481 char *cmd,
10482 char *name,
10483 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010484{
Bram Moolenaar893de922007-10-02 18:40:57 +000010485 if (value < 0) /* global/local option using global value */
10486 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010487 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10488 || put_eol(fd) < 0)
10489 return FAIL;
10490 return OK;
10491}
10492
10493/*
10494 * Clear all the terminal options.
10495 * If the option has been allocated, free the memory.
10496 * Terminal options are never hidden or indirect.
10497 */
10498 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010499clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010500{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501 /*
10502 * Reset a few things before clearing the old options. This may cause
10503 * outputting a few things that the terminal doesn't understand, but the
10504 * screen will be cleared later, so this is OK.
10505 */
10506#ifdef FEAT_MOUSE_TTY
10507 mch_setmouse(FALSE); /* switch mouse off */
10508#endif
10509#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010510 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511#endif
10512#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10513 /* When starting the GUI close the display opened for the clipboard.
10514 * After restoring the title, because that will need the display. */
10515 if (gui.starting)
10516 clear_xterm_clip();
10517#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010518 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010519
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010520 free_termoptions();
10521}
10522
10523 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010524free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010525{
10526 struct vimoption *p;
10527
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010528 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010529 if (istermoption(p))
10530 {
10531 if (p->flags & P_ALLOCED)
10532 free_string_option(*(char_u **)(p->var));
10533 if (p->flags & P_DEF_ALLOCED)
10534 free_string_option(p->def_val[VI_DEFAULT]);
10535 *(char_u **)(p->var) = empty_option;
10536 p->def_val[VI_DEFAULT] = empty_option;
10537 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010538#ifdef FEAT_EVAL
10539 // remember where the option was cleared
10540 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10541#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010542 }
10543 clear_termcodes();
10544}
10545
10546/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010547 * Free the string for one term option, if it was allocated.
10548 * Set the string to empty_option and clear allocated flag.
10549 * "var" points to the option value.
10550 */
10551 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010552free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010553{
10554 struct vimoption *p;
10555
10556 for (p = &options[0]; p->fullname != NULL; p++)
10557 if (p->var == var)
10558 {
10559 if (p->flags & P_ALLOCED)
10560 free_string_option(*(char_u **)(p->var));
10561 *(char_u **)(p->var) = empty_option;
10562 p->flags &= ~P_ALLOCED;
10563 break;
10564 }
10565}
10566
10567/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010568 * Set the terminal option defaults to the current value.
10569 * Used after setting the terminal name.
10570 */
10571 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010572set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573{
10574 struct vimoption *p;
10575
10576 for (p = &options[0]; p->fullname != NULL; p++)
10577 {
10578 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10579 {
10580 if (p->flags & P_DEF_ALLOCED)
10581 {
10582 free_string_option(p->def_val[VI_DEFAULT]);
10583 p->flags &= ~P_DEF_ALLOCED;
10584 }
10585 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10586 if (p->flags & P_ALLOCED)
10587 {
10588 p->flags |= P_DEF_ALLOCED;
10589 p->flags &= ~P_ALLOCED; /* don't free the value now */
10590 }
10591 }
10592 }
10593}
10594
10595/*
10596 * return TRUE if 'p' starts with 't_'
10597 */
10598 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010599istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600{
10601 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10602}
10603
10604/*
10605 * Compute columns for ruler and shown command. 'sc_col' is also used to
10606 * decide what the maximum length of a message on the status line can be.
10607 * If there is a status line for the last window, 'sc_col' is independent
10608 * of 'ru_col'.
10609 */
10610
10611#define COL_RULER 17 /* columns needed by standard ruler */
10612
10613 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010614comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010616#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010617 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618
10619 sc_col = 0;
10620 ru_col = 0;
10621 if (p_ru)
10622 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010623# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010624 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010625# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010626 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010627# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010628 /* no last status line, adjust sc_col */
10629 if (!last_has_status)
10630 sc_col = ru_col;
10631 }
10632 if (p_sc)
10633 {
10634 sc_col += SHOWCMD_COLS;
10635 if (!p_ru || last_has_status) /* no need for separating space */
10636 ++sc_col;
10637 }
10638 sc_col = Columns - sc_col;
10639 ru_col = Columns - ru_col;
10640 if (sc_col <= 0) /* screen too narrow, will become a mess */
10641 sc_col = 1;
10642 if (ru_col <= 0)
10643 ru_col = 1;
10644#else
10645 sc_col = Columns;
10646 ru_col = Columns;
10647#endif
10648}
10649
Bram Moolenaar113e1072019-01-20 15:30:40 +010010650#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010651/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010652 * Unset local option value, similar to ":set opt<".
10653 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010654 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010655unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010656{
10657 struct vimoption *p;
10658 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010659 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010660
10661 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010662 if (opt_idx < 0)
10663 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010664 p = &(options[opt_idx]);
10665
10666 switch ((int)p->indir)
10667 {
10668 /* global option with local value: use local value if it's been set */
10669 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010670 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010671 break;
10672 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010673 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010674 break;
10675 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010676 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010677 break;
10678 case PV_AR:
10679 buf->b_p_ar = -1;
10680 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010681 case PV_BKC:
10682 clear_string_option(&buf->b_p_bkc);
10683 buf->b_bkc_flags = 0;
10684 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010685 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010686 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010687 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010688 case PV_TC:
10689 clear_string_option(&buf->b_p_tc);
10690 buf->b_tc_flags = 0;
10691 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010692 case PV_SISO:
10693 curwin->w_p_siso = -1;
10694 break;
10695 case PV_SO:
10696 curwin->w_p_so = -1;
10697 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010698#ifdef FEAT_FIND_ID
10699 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010700 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010701 break;
10702 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010703 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010704 break;
10705#endif
10706#ifdef FEAT_INS_EXPAND
10707 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010708 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010709 break;
10710 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010711 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010712 break;
10713#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010714 case PV_FP:
10715 clear_string_option(&buf->b_p_fp);
10716 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010717#ifdef FEAT_QUICKFIX
10718 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010719 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010720 break;
10721 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010722 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010723 break;
10724 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010725 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010726 break;
10727#endif
10728#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10729 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010730 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010731 break;
10732#endif
10733#if defined(FEAT_CRYPT)
10734 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010735 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010736 break;
10737#endif
10738#ifdef FEAT_STL_OPT
10739 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010740 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010741 break;
10742#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010743 case PV_UL:
10744 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10745 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010746#ifdef FEAT_LISP
10747 case PV_LW:
10748 clear_string_option(&buf->b_p_lw);
10749 break;
10750#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010751 case PV_MENC:
10752 clear_string_option(&buf->b_p_menc);
10753 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010754 }
10755}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010756#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010757
10758/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010759 * Get pointer to option variable, depending on local or global scope.
10760 */
10761 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010762get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010763{
10764 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10765 {
10766 if (p->var == VAR_WIN)
10767 return (char_u *)GLOBAL_WO(get_varp(p));
10768 return p->var;
10769 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010770 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010771 {
10772 switch ((int)p->indir)
10773 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010774 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010776 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10777 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10778 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010780 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10781 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10782 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010783 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010784 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010785 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010786 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10787 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010789 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10790 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010791#endif
10792#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010793 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10794 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010795#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010796#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10797 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10798#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010799#if defined(FEAT_CRYPT)
10800 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10801#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010802#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010803 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010804#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010805 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010806#ifdef FEAT_LISP
10807 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10808#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010809 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010810 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811 }
10812 return NULL; /* "cannot happen" */
10813 }
10814 return get_varp(p);
10815}
10816
10817/*
10818 * Get pointer to option variable.
10819 */
10820 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010821get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010822{
10823 /* hidden option, always return NULL */
10824 if (p->var == NULL)
10825 return NULL;
10826
10827 switch ((int)p->indir)
10828 {
10829 case PV_NONE: return p->var;
10830
10831 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010832 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010834 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010835 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010836 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010838 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010839 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010840 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010841 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010842 case PV_TC: return *curbuf->b_p_tc != NUL
10843 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010844 case PV_BKC: return *curbuf->b_p_bkc != NUL
10845 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010846 case PV_SISO: return curwin->w_p_siso >= 0
10847 ? (char_u *)&(curwin->w_p_siso) : p->var;
10848 case PV_SO: return curwin->w_p_so >= 0
10849 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010850#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010851 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010853 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10855#endif
10856#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010857 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010858 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010859 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10861#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010862 case PV_FP: return *curbuf->b_p_fp != NUL
10863 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010865 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010867 case PV_GP: return *curbuf->b_p_gp != NUL
10868 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10869 case PV_MP: return *curbuf->b_p_mp != NUL
10870 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010872#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10873 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10874 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10875#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010876#if defined(FEAT_CRYPT)
10877 case PV_CM: return *curbuf->b_p_cm != NUL
10878 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10879#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010880#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010881 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010882 ? (char_u *)&(curwin->w_p_stl) : p->var;
10883#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010884 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10885 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010886#ifdef FEAT_LISP
10887 case PV_LW: return *curbuf->b_p_lw != NUL
10888 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10889#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010890 case PV_MENC: return *curbuf->b_p_menc != NUL
10891 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892
10893#ifdef FEAT_ARABIC
10894 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10895#endif
10896 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010897#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010898 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10899#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010900#ifdef FEAT_SYN_HL
10901 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10902 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010903 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010904#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010905#ifdef FEAT_DIFF
10906 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10907#endif
10908#ifdef FEAT_FOLDING
10909 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10910 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10911 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10912 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10913 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10914 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10915 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10916# ifdef FEAT_EVAL
10917 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10918 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10919# endif
10920 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10921#endif
10922 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010923 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010924#ifdef FEAT_LINEBREAK
10925 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10926#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010927 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010928 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010929#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010930 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10931#endif
10932#ifdef FEAT_RIGHTLEFT
10933 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10934 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10935#endif
10936 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10937 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10938#ifdef FEAT_LINEBREAK
10939 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010940 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10941 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010942#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010943 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010944 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010945#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010946 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10947 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10948#endif
10949#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010950 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10951 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10952 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010953#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010954
10955 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10956 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010957 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010958 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10959 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010960 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10961 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10962#ifdef FEAT_CINDENT
10963 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10964 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10965 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10966#endif
10967#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10968 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10969#endif
10970#ifdef FEAT_COMMENTS
10971 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10972#endif
10973#ifdef FEAT_FOLDING
10974 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10975#endif
10976#ifdef FEAT_INS_EXPAND
10977 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10978#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010979#ifdef FEAT_COMPL_FUNC
10980 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010981 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010982#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020010983#ifdef FEAT_EVAL
10984 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
10985#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010986 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010987 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010990 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010991 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010992 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010993 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010994 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10995 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10996 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10997 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10998#ifdef FEAT_FIND_ID
10999# ifdef FEAT_EVAL
11000 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11001# endif
11002#endif
11003#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11004 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11005 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11006#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011007#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011008 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11009#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010#ifdef FEAT_CRYPT
11011 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11012#endif
11013#ifdef FEAT_LISP
11014 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11015#endif
11016 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11017 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11018 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11019 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11020 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011021 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011022#ifdef FEAT_TEXTOBJ
11023 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11026#ifdef FEAT_SMARTINDENT
11027 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011029 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011030 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11031#ifdef FEAT_SEARCHPATH
11032 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11033#endif
11034 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11035#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011036 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011037 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11038#endif
11039#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011040 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11041 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11042 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011043#endif
11044 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11045 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11046 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11047 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011048#ifdef FEAT_PERSISTENT_UNDO
11049 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11052#ifdef FEAT_KEYMAP
11053 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11054#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011055#ifdef FEAT_SIGNS
11056 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11057#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011058#ifdef FEAT_VARTABS
11059 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11060 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11061#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011062 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063 }
11064 /* always return a valid pointer to avoid a crash! */
11065 return (char_u *)&(curbuf->b_p_wm);
11066}
11067
11068/*
11069 * Get the value of 'equalprg', either the buffer-local one or the global one.
11070 */
11071 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011072get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073{
11074 if (*curbuf->b_p_ep == NUL)
11075 return p_ep;
11076 return curbuf->b_p_ep;
11077}
11078
Bram Moolenaar071d4272004-06-13 20:20:40 +000011079/*
11080 * Copy options from one window to another.
11081 * Used when splitting a window.
11082 */
11083 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011084win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011085{
11086 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11087 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011088#if defined(FEAT_LINEBREAK)
11089 briopt_check(wp_to);
11090#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011092
11093/*
11094 * Copy the options from one winopt_T to another.
11095 * Doesn't free the old option values in "to", use clear_winopt() for that.
11096 * The 'scroll' option is not copied, because it depends on the window height.
11097 * The 'previewwindow' option is reset, there can be only one preview window.
11098 */
11099 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011100copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011101{
11102#ifdef FEAT_ARABIC
11103 to->wo_arab = from->wo_arab;
11104#endif
11105 to->wo_list = from->wo_list;
11106 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011107 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011108#ifdef FEAT_LINEBREAK
11109 to->wo_nuw = from->wo_nuw;
11110#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011111#ifdef FEAT_RIGHTLEFT
11112 to->wo_rl = from->wo_rl;
11113 to->wo_rlc = vim_strsave(from->wo_rlc);
11114#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011115#ifdef FEAT_STL_OPT
11116 to->wo_stl = vim_strsave(from->wo_stl);
11117#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011119#ifdef FEAT_DIFF
11120 to->wo_wrap_save = from->wo_wrap_save;
11121#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122#ifdef FEAT_LINEBREAK
11123 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011124 to->wo_bri = from->wo_bri;
11125 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011126#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011127 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011128 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011129 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011130 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011131#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011132 to->wo_spell = from->wo_spell;
11133#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011134#ifdef FEAT_SYN_HL
11135 to->wo_cuc = from->wo_cuc;
11136 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011137 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011138#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011139#ifdef FEAT_DIFF
11140 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011141 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011143#ifdef FEAT_CONCEAL
11144 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011145 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011146#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011147#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011148 to->wo_twk = vim_strsave(from->wo_twk);
11149 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011150#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011151#ifdef FEAT_FOLDING
11152 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011153 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011155 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156 to->wo_fdi = vim_strsave(from->wo_fdi);
11157 to->wo_fml = from->wo_fml;
11158 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011159 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011160 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011161 to->wo_fdm_save = from->wo_diff_saved
11162 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011163 to->wo_fdn = from->wo_fdn;
11164# ifdef FEAT_EVAL
11165 to->wo_fde = vim_strsave(from->wo_fde);
11166 to->wo_fdt = vim_strsave(from->wo_fdt);
11167# endif
11168 to->wo_fmr = vim_strsave(from->wo_fmr);
11169#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011170#ifdef FEAT_SIGNS
11171 to->wo_scl = vim_strsave(from->wo_scl);
11172#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173 check_winopt(to); /* don't want NULL pointers */
11174}
11175
11176/*
11177 * Check string options in a window for a NULL value.
11178 */
11179 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011180check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181{
11182 check_winopt(&win->w_onebuf_opt);
11183 check_winopt(&win->w_allbuf_opt);
11184}
11185
11186/*
11187 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11188 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011189 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011190check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011191{
11192#ifdef FEAT_FOLDING
11193 check_string_option(&wop->wo_fdi);
11194 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011195 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011196# ifdef FEAT_EVAL
11197 check_string_option(&wop->wo_fde);
11198 check_string_option(&wop->wo_fdt);
11199# endif
11200 check_string_option(&wop->wo_fmr);
11201#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011202#ifdef FEAT_SIGNS
11203 check_string_option(&wop->wo_scl);
11204#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011205#ifdef FEAT_RIGHTLEFT
11206 check_string_option(&wop->wo_rlc);
11207#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011208#ifdef FEAT_STL_OPT
11209 check_string_option(&wop->wo_stl);
11210#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011211#ifdef FEAT_SYN_HL
11212 check_string_option(&wop->wo_cc);
11213#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011214#ifdef FEAT_CONCEAL
11215 check_string_option(&wop->wo_cocu);
11216#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011217#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011218 check_string_option(&wop->wo_twk);
11219 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011220#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011221#ifdef FEAT_LINEBREAK
11222 check_string_option(&wop->wo_briopt);
11223#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011224}
11225
11226/*
11227 * Free the allocated memory inside a winopt_T.
11228 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011229 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011230clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011231{
11232#ifdef FEAT_FOLDING
11233 clear_string_option(&wop->wo_fdi);
11234 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011235 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011236# ifdef FEAT_EVAL
11237 clear_string_option(&wop->wo_fde);
11238 clear_string_option(&wop->wo_fdt);
11239# endif
11240 clear_string_option(&wop->wo_fmr);
11241#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011242#ifdef FEAT_SIGNS
11243 clear_string_option(&wop->wo_scl);
11244#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011245#ifdef FEAT_LINEBREAK
11246 clear_string_option(&wop->wo_briopt);
11247#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248#ifdef FEAT_RIGHTLEFT
11249 clear_string_option(&wop->wo_rlc);
11250#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011251#ifdef FEAT_STL_OPT
11252 clear_string_option(&wop->wo_stl);
11253#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011254#ifdef FEAT_SYN_HL
11255 clear_string_option(&wop->wo_cc);
11256#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011257#ifdef FEAT_CONCEAL
11258 clear_string_option(&wop->wo_cocu);
11259#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011260#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011261 clear_string_option(&wop->wo_twk);
11262 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011263#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011264}
11265
11266/*
11267 * Copy global option values to local options for one buffer.
11268 * Used when creating a new buffer and sometimes when entering a buffer.
11269 * flags:
11270 * BCO_ENTER We will enter the buf buffer.
11271 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11272 * appropriate.
11273 * BCO_NOHELP Don't copy the values to a help buffer.
11274 */
11275 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011276buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011277{
11278 int should_copy = TRUE;
11279 char_u *save_p_isk = NULL; /* init for GCC */
11280 int dont_do_help;
11281 int did_isk = FALSE;
11282
11283 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011284 * Skip this when the option defaults have not been set yet. Happens when
11285 * main() allocates the first buffer.
11286 */
11287 if (p_cpo != NULL)
11288 {
11289 /*
11290 * Always copy when entering and 'cpo' contains 'S'.
11291 * Don't copy when already initialized.
11292 * Don't copy when 'cpo' contains 's' and not entering.
11293 * 'S' BCO_ENTER initialized 's' should_copy
11294 * yes yes X X TRUE
11295 * yes no yes X FALSE
11296 * no X yes X FALSE
11297 * X no no yes FALSE
11298 * X no no no TRUE
11299 * no yes no X TRUE
11300 */
11301 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11302 && (buf->b_p_initialized
11303 || (!(flags & BCO_ENTER)
11304 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11305 should_copy = FALSE;
11306
11307 if (should_copy || (flags & BCO_ALWAYS))
11308 {
11309 /* Don't copy the options specific to a help buffer when
11310 * BCO_NOHELP is given or the options were initialized already
11311 * (jumping back to a help file with CTRL-T or CTRL-O) */
11312 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11313 || buf->b_p_initialized;
11314 if (dont_do_help) /* don't free b_p_isk */
11315 {
11316 save_p_isk = buf->b_p_isk;
11317 buf->b_p_isk = NULL;
11318 }
11319 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011320 * Always free the allocated strings. If not already initialized,
11321 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322 */
11323 if (!buf->b_p_initialized)
11324 {
11325 free_buf_options(buf, TRUE);
11326 buf->b_p_ro = FALSE; /* don't copy readonly */
11327 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011328 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011329 switch (*p_ffs)
11330 {
11331 case 'm':
11332 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11333 case 'd':
11334 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11335 case 'u':
11336 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11337 default:
11338 buf->b_p_ff = vim_strsave(p_ff);
11339 }
11340 if (buf->b_p_ff != NULL)
11341 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342 buf->b_p_bh = empty_option;
11343 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344 }
11345 else
11346 free_buf_options(buf, FALSE);
11347
11348 buf->b_p_ai = p_ai;
11349 buf->b_p_ai_nopaste = p_ai_nopaste;
11350 buf->b_p_sw = p_sw;
11351 buf->b_p_tw = p_tw;
11352 buf->b_p_tw_nopaste = p_tw_nopaste;
11353 buf->b_p_tw_nobin = p_tw_nobin;
11354 buf->b_p_wm = p_wm;
11355 buf->b_p_wm_nopaste = p_wm_nopaste;
11356 buf->b_p_wm_nobin = p_wm_nobin;
11357 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011358 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011359 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011360 buf->b_p_et = p_et;
11361 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011362 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011363 buf->b_p_ml = p_ml;
11364 buf->b_p_ml_nobin = p_ml_nobin;
11365 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011366 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011367#ifdef FEAT_INS_EXPAND
11368 buf->b_p_cpt = vim_strsave(p_cpt);
11369#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011370#ifdef FEAT_COMPL_FUNC
11371 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011372 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011373#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011374#ifdef FEAT_EVAL
11375 buf->b_p_tfu = vim_strsave(p_tfu);
11376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011377 buf->b_p_sts = p_sts;
11378 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011379#ifdef FEAT_VARTABS
11380 buf->b_p_vsts = vim_strsave(p_vsts);
11381 if (p_vsts && p_vsts != empty_option)
11382 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11383 else
11384 buf->b_p_vsts_array = 0;
11385 buf->b_p_vsts_nopaste = p_vsts_nopaste
11386 ? vim_strsave(p_vsts_nopaste) : NULL;
11387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011389#ifdef FEAT_COMMENTS
11390 buf->b_p_com = vim_strsave(p_com);
11391#endif
11392#ifdef FEAT_FOLDING
11393 buf->b_p_cms = vim_strsave(p_cms);
11394#endif
11395 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011396 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011397 buf->b_p_nf = vim_strsave(p_nf);
11398 buf->b_p_mps = vim_strsave(p_mps);
11399#ifdef FEAT_SMARTINDENT
11400 buf->b_p_si = p_si;
11401#endif
11402 buf->b_p_ci = p_ci;
11403#ifdef FEAT_CINDENT
11404 buf->b_p_cin = p_cin;
11405 buf->b_p_cink = vim_strsave(p_cink);
11406 buf->b_p_cino = vim_strsave(p_cino);
11407#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408 /* Don't copy 'filetype', it must be detected */
11409 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410 buf->b_p_pi = p_pi;
11411#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11412 buf->b_p_cinw = vim_strsave(p_cinw);
11413#endif
11414#ifdef FEAT_LISP
11415 buf->b_p_lisp = p_lisp;
11416#endif
11417#ifdef FEAT_SYN_HL
11418 /* Don't copy 'syntax', it must be set */
11419 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011420 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011421 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011422#endif
11423#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011424 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011425 (void)compile_cap_prog(&buf->b_s);
11426 buf->b_s.b_p_spf = vim_strsave(p_spf);
11427 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428#endif
11429#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11430 buf->b_p_inde = vim_strsave(p_inde);
11431 buf->b_p_indk = vim_strsave(p_indk);
11432#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011433 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011434#if defined(FEAT_EVAL)
11435 buf->b_p_fex = vim_strsave(p_fex);
11436#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011437#ifdef FEAT_CRYPT
11438 buf->b_p_key = vim_strsave(p_key);
11439#endif
11440#ifdef FEAT_SEARCHPATH
11441 buf->b_p_sua = vim_strsave(p_sua);
11442#endif
11443#ifdef FEAT_KEYMAP
11444 buf->b_p_keymap = vim_strsave(p_keymap);
11445 buf->b_kmap_state |= KEYMAP_INIT;
11446#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011447#ifdef FEAT_TERMINAL
11448 buf->b_p_twsl = p_twsl;
11449#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011450 /* This isn't really an option, but copying the langmap and IME
11451 * state from the current buffer is better than resetting it. */
11452 buf->b_p_iminsert = p_iminsert;
11453 buf->b_p_imsearch = p_imsearch;
11454
11455 /* options that are normally global but also have a local value
11456 * are not copied, start using the global value */
11457 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011458 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011459 buf->b_p_bkc = empty_option;
11460 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011461#ifdef FEAT_QUICKFIX
11462 buf->b_p_gp = empty_option;
11463 buf->b_p_mp = empty_option;
11464 buf->b_p_efm = empty_option;
11465#endif
11466 buf->b_p_ep = empty_option;
11467 buf->b_p_kp = empty_option;
11468 buf->b_p_path = empty_option;
11469 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011470 buf->b_p_tc = empty_option;
11471 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011472#ifdef FEAT_FIND_ID
11473 buf->b_p_def = empty_option;
11474 buf->b_p_inc = empty_option;
11475# ifdef FEAT_EVAL
11476 buf->b_p_inex = vim_strsave(p_inex);
11477# endif
11478#endif
11479#ifdef FEAT_INS_EXPAND
11480 buf->b_p_dict = empty_option;
11481 buf->b_p_tsr = empty_option;
11482#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011483#ifdef FEAT_TEXTOBJ
11484 buf->b_p_qe = vim_strsave(p_qe);
11485#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011486#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11487 buf->b_p_bexpr = empty_option;
11488#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011489#if defined(FEAT_CRYPT)
11490 buf->b_p_cm = empty_option;
11491#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011492#ifdef FEAT_PERSISTENT_UNDO
11493 buf->b_p_udf = p_udf;
11494#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011495#ifdef FEAT_LISP
11496 buf->b_p_lw = empty_option;
11497#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011498 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499
11500 /*
11501 * Don't copy the options set by ex_help(), use the saved values,
11502 * when going from a help buffer to a non-help buffer.
11503 * Don't touch these at all when BCO_NOHELP is used and going from
11504 * or to a help buffer.
11505 */
11506 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011507 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011508 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011509#ifdef FEAT_VARTABS
11510 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11511 tabstop_set(p_vts, &buf->b_p_vts_array);
11512 else
11513 buf->b_p_vts_array = NULL;
11514#endif
11515 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011516 else
11517 {
11518 buf->b_p_isk = vim_strsave(p_isk);
11519 did_isk = TRUE;
11520 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011521#ifdef FEAT_VARTABS
11522 buf->b_p_vts = vim_strsave(p_vts);
11523 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11524 tabstop_set(p_vts, &buf->b_p_vts_array);
11525 else
11526 buf->b_p_vts_array = NULL;
11527#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011528 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011529 if (buf->b_p_bt[0] == 'h')
11530 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011531 buf->b_p_ma = p_ma;
11532 }
11533 }
11534
11535 /*
11536 * When the options should be copied (ignoring BCO_ALWAYS), set the
11537 * flag that indicates that the options have been initialized.
11538 */
11539 if (should_copy)
11540 buf->b_p_initialized = TRUE;
11541 }
11542
11543 check_buf_options(buf); /* make sure we don't have NULLs */
11544 if (did_isk)
11545 (void)buf_init_chartab(buf, FALSE);
11546}
11547
11548/*
11549 * Reset the 'modifiable' option and its default value.
11550 */
11551 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011552reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011553{
11554 int opt_idx;
11555
11556 curbuf->b_p_ma = FALSE;
11557 p_ma = FALSE;
11558 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011559 if (opt_idx >= 0)
11560 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561}
11562
11563/*
11564 * Set the global value for 'iminsert' to the local value.
11565 */
11566 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011567set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011568{
11569 p_iminsert = curbuf->b_p_iminsert;
11570}
11571
11572/*
11573 * Set the global value for 'imsearch' to the local value.
11574 */
11575 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011576set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011577{
11578 p_imsearch = curbuf->b_p_imsearch;
11579}
11580
11581#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11582static int expand_option_idx = -1;
11583static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11584static int expand_option_flags = 0;
11585
11586 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011587set_context_in_set_cmd(
11588 expand_T *xp,
11589 char_u *arg,
11590 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011591{
11592 int nextchar;
11593 long_u flags = 0; /* init for GCC */
11594 int opt_idx = 0; /* init for GCC */
11595 char_u *p;
11596 char_u *s;
11597 int is_term_option = FALSE;
11598 int key;
11599
11600 expand_option_flags = opt_flags;
11601
11602 xp->xp_context = EXPAND_SETTINGS;
11603 if (*arg == NUL)
11604 {
11605 xp->xp_pattern = arg;
11606 return;
11607 }
11608 p = arg + STRLEN(arg) - 1;
11609 if (*p == ' ' && *(p - 1) != '\\')
11610 {
11611 xp->xp_pattern = p + 1;
11612 return;
11613 }
11614 while (p > arg)
11615 {
11616 s = p;
11617 /* count number of backslashes before ' ' or ',' */
11618 if (*p == ' ' || *p == ',')
11619 {
11620 while (s > arg && *(s - 1) == '\\')
11621 --s;
11622 }
11623 /* break at a space with an even number of backslashes */
11624 if (*p == ' ' && ((p - s) & 1) == 0)
11625 {
11626 ++p;
11627 break;
11628 }
11629 --p;
11630 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011631 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011632 {
11633 xp->xp_context = EXPAND_BOOL_SETTINGS;
11634 p += 2;
11635 }
11636 if (STRNCMP(p, "inv", 3) == 0)
11637 {
11638 xp->xp_context = EXPAND_BOOL_SETTINGS;
11639 p += 3;
11640 }
11641 xp->xp_pattern = arg = p;
11642 if (*arg == '<')
11643 {
11644 while (*p != '>')
11645 if (*p++ == NUL) /* expand terminal option name */
11646 return;
11647 key = get_special_key_code(arg + 1);
11648 if (key == 0) /* unknown name */
11649 {
11650 xp->xp_context = EXPAND_NOTHING;
11651 return;
11652 }
11653 nextchar = *++p;
11654 is_term_option = TRUE;
11655 expand_option_name[2] = KEY2TERMCAP0(key);
11656 expand_option_name[3] = KEY2TERMCAP1(key);
11657 }
11658 else
11659 {
11660 if (p[0] == 't' && p[1] == '_')
11661 {
11662 p += 2;
11663 if (*p != NUL)
11664 ++p;
11665 if (*p == NUL)
11666 return; /* expand option name */
11667 nextchar = *++p;
11668 is_term_option = TRUE;
11669 expand_option_name[2] = p[-2];
11670 expand_option_name[3] = p[-1];
11671 }
11672 else
11673 {
11674 /* Allow * wildcard */
11675 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11676 p++;
11677 if (*p == NUL)
11678 return;
11679 nextchar = *p;
11680 *p = NUL;
11681 opt_idx = findoption(arg);
11682 *p = nextchar;
11683 if (opt_idx == -1 || options[opt_idx].var == NULL)
11684 {
11685 xp->xp_context = EXPAND_NOTHING;
11686 return;
11687 }
11688 flags = options[opt_idx].flags;
11689 if (flags & P_BOOL)
11690 {
11691 xp->xp_context = EXPAND_NOTHING;
11692 return;
11693 }
11694 }
11695 }
11696 /* handle "-=" and "+=" */
11697 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11698 {
11699 ++p;
11700 nextchar = '=';
11701 }
11702 if ((nextchar != '=' && nextchar != ':')
11703 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11704 {
11705 xp->xp_context = EXPAND_UNSUCCESSFUL;
11706 return;
11707 }
11708 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11709 {
11710 xp->xp_context = EXPAND_OLD_SETTING;
11711 if (is_term_option)
11712 expand_option_idx = -1;
11713 else
11714 expand_option_idx = opt_idx;
11715 xp->xp_pattern = p + 1;
11716 return;
11717 }
11718 xp->xp_context = EXPAND_NOTHING;
11719 if (is_term_option || (flags & P_NUM))
11720 return;
11721
11722 xp->xp_pattern = p + 1;
11723
11724 if (flags & P_EXPAND)
11725 {
11726 p = options[opt_idx].var;
11727 if (p == (char_u *)&p_bdir
11728 || p == (char_u *)&p_dir
11729 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011730 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011731 || p == (char_u *)&p_rtp
11732#ifdef FEAT_SEARCHPATH
11733 || p == (char_u *)&p_cdpath
11734#endif
11735#ifdef FEAT_SESSION
11736 || p == (char_u *)&p_vdir
11737#endif
11738 )
11739 {
11740 xp->xp_context = EXPAND_DIRECTORIES;
11741 if (p == (char_u *)&p_path
11742#ifdef FEAT_SEARCHPATH
11743 || p == (char_u *)&p_cdpath
11744#endif
11745 )
11746 xp->xp_backslash = XP_BS_THREE;
11747 else
11748 xp->xp_backslash = XP_BS_ONE;
11749 }
11750 else
11751 {
11752 xp->xp_context = EXPAND_FILES;
11753 /* for 'tags' need three backslashes for a space */
11754 if (p == (char_u *)&p_tags)
11755 xp->xp_backslash = XP_BS_THREE;
11756 else
11757 xp->xp_backslash = XP_BS_ONE;
11758 }
11759 }
11760
11761 /* For an option that is a list of file names, find the start of the
11762 * last file name. */
11763 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11764 {
11765 /* count number of backslashes before ' ' or ',' */
11766 if (*p == ' ' || *p == ',')
11767 {
11768 s = p;
11769 while (s > xp->xp_pattern && *(s - 1) == '\\')
11770 --s;
11771 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11772 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11773 {
11774 xp->xp_pattern = p + 1;
11775 break;
11776 }
11777 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011778
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011779#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011780 /* for 'spellsuggest' start at "file:" */
11781 if (options[opt_idx].var == (char_u *)&p_sps
11782 && STRNCMP(p, "file:", 5) == 0)
11783 {
11784 xp->xp_pattern = p + 5;
11785 break;
11786 }
11787#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011788 }
11789
11790 return;
11791}
11792
11793 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011794ExpandSettings(
11795 expand_T *xp,
11796 regmatch_T *regmatch,
11797 int *num_file,
11798 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799{
11800 int num_normal = 0; /* Nr of matching non-term-code settings */
11801 int num_term = 0; /* Nr of matching terminal code settings */
11802 int opt_idx;
11803 int match;
11804 int count = 0;
11805 char_u *str;
11806 int loop;
11807 int is_term_opt;
11808 char_u name_buf[MAX_KEY_NAME_LEN];
11809 static char *(names[]) = {"all", "termcap"};
11810 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11811
11812 /* do this loop twice:
11813 * loop == 0: count the number of matching options
11814 * loop == 1: copy the matching options into allocated memory
11815 */
11816 for (loop = 0; loop <= 1; ++loop)
11817 {
11818 regmatch->rm_ic = ic;
11819 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11820 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011821 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11822 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11824 {
11825 if (loop == 0)
11826 num_normal++;
11827 else
11828 (*file)[count++] = vim_strsave((char_u *)names[match]);
11829 }
11830 }
11831 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11832 opt_idx++)
11833 {
11834 if (options[opt_idx].var == NULL)
11835 continue;
11836 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11837 && !(options[opt_idx].flags & P_BOOL))
11838 continue;
11839 is_term_opt = istermoption(&options[opt_idx]);
11840 if (is_term_opt && num_normal > 0)
11841 continue;
11842 match = FALSE;
11843 if (vim_regexec(regmatch, str, (colnr_T)0)
11844 || (options[opt_idx].shortname != NULL
11845 && vim_regexec(regmatch,
11846 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11847 match = TRUE;
11848 else if (is_term_opt)
11849 {
11850 name_buf[0] = '<';
11851 name_buf[1] = 't';
11852 name_buf[2] = '_';
11853 name_buf[3] = str[2];
11854 name_buf[4] = str[3];
11855 name_buf[5] = '>';
11856 name_buf[6] = NUL;
11857 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11858 {
11859 match = TRUE;
11860 str = name_buf;
11861 }
11862 }
11863 if (match)
11864 {
11865 if (loop == 0)
11866 {
11867 if (is_term_opt)
11868 num_term++;
11869 else
11870 num_normal++;
11871 }
11872 else
11873 (*file)[count++] = vim_strsave(str);
11874 }
11875 }
11876 /*
11877 * Check terminal key codes, these are not in the option table
11878 */
11879 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11880 {
11881 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11882 {
11883 if (!isprint(str[0]) || !isprint(str[1]))
11884 continue;
11885
11886 name_buf[0] = 't';
11887 name_buf[1] = '_';
11888 name_buf[2] = str[0];
11889 name_buf[3] = str[1];
11890 name_buf[4] = NUL;
11891
11892 match = FALSE;
11893 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11894 match = TRUE;
11895 else
11896 {
11897 name_buf[0] = '<';
11898 name_buf[1] = 't';
11899 name_buf[2] = '_';
11900 name_buf[3] = str[0];
11901 name_buf[4] = str[1];
11902 name_buf[5] = '>';
11903 name_buf[6] = NUL;
11904
11905 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11906 match = TRUE;
11907 }
11908 if (match)
11909 {
11910 if (loop == 0)
11911 num_term++;
11912 else
11913 (*file)[count++] = vim_strsave(name_buf);
11914 }
11915 }
11916
11917 /*
11918 * Check special key names.
11919 */
11920 regmatch->rm_ic = TRUE; /* ignore case here */
11921 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11922 {
11923 name_buf[0] = '<';
11924 STRCPY(name_buf + 1, str);
11925 STRCAT(name_buf, ">");
11926
11927 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11928 {
11929 if (loop == 0)
11930 num_term++;
11931 else
11932 (*file)[count++] = vim_strsave(name_buf);
11933 }
11934 }
11935 }
11936 if (loop == 0)
11937 {
11938 if (num_normal > 0)
11939 *num_file = num_normal;
11940 else if (num_term > 0)
11941 *num_file = num_term;
11942 else
11943 return OK;
11944 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11945 if (*file == NULL)
11946 {
11947 *file = (char_u **)"";
11948 return FAIL;
11949 }
11950 }
11951 }
11952 return OK;
11953}
11954
11955 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011956ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011957{
11958 char_u *var = NULL; /* init for GCC */
11959 char_u *buf;
11960
11961 *num_file = 0;
11962 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11963 if (*file == NULL)
11964 return FAIL;
11965
11966 /*
11967 * For a terminal key code expand_option_idx is < 0.
11968 */
11969 if (expand_option_idx < 0)
11970 {
11971 var = find_termcode(expand_option_name + 2);
11972 if (var == NULL)
11973 expand_option_idx = findoption(expand_option_name);
11974 }
11975
11976 if (expand_option_idx >= 0)
11977 {
11978 /* put string of option value in NameBuff */
11979 option_value2string(&options[expand_option_idx], expand_option_flags);
11980 var = NameBuff;
11981 }
11982 else if (var == NULL)
11983 var = (char_u *)"";
11984
11985 /* A backslash is required before some characters. This is the reverse of
11986 * what happens in do_set(). */
11987 buf = vim_strsave_escaped(var, escape_chars);
11988
11989 if (buf == NULL)
11990 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011991 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011992 return FAIL;
11993 }
11994
11995#ifdef BACKSLASH_IN_FILENAME
11996 /* For MS-Windows et al. we don't double backslashes at the start and
11997 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011998 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999 if (var[0] == '\\' && var[1] == '\\'
12000 && expand_option_idx >= 0
12001 && (options[expand_option_idx].flags & P_EXPAND)
12002 && vim_isfilec(var[2])
12003 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012004 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012005#endif
12006
12007 *file[0] = buf;
12008 *num_file = 1;
12009 return OK;
12010}
12011#endif
12012
12013/*
12014 * Get the value for the numeric or string option *opp in a nice format into
12015 * NameBuff[]. Must not be called with a hidden option!
12016 */
12017 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012018option_value2string(
12019 struct vimoption *opp,
12020 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021{
12022 char_u *varp;
12023
12024 varp = get_varp_scope(opp, opt_flags);
12025
12026 if (opp->flags & P_NUM)
12027 {
12028 long wc = 0;
12029
12030 if (wc_use_keyname(varp, &wc))
12031 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12032 else if (wc != 0)
12033 STRCPY(NameBuff, transchar((int)wc));
12034 else
12035 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12036 }
12037 else /* P_STRING */
12038 {
12039 varp = *(char_u **)(varp);
12040 if (varp == NULL) /* just in case */
12041 NameBuff[0] = NUL;
12042#ifdef FEAT_CRYPT
12043 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012044 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045 STRCPY(NameBuff, "*****");
12046#endif
12047 else if (opp->flags & P_EXPAND)
12048 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12049 /* Translate 'pastetoggle' into special key names */
12050 else if ((char_u **)opp->var == &p_pt)
12051 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12052 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012053 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012054 }
12055}
12056
12057/*
12058 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12059 * printed as a keyname.
12060 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12061 */
12062 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012063wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012064{
12065 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12066 {
12067 *wcp = *(long *)varp;
12068 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12069 return TRUE;
12070 }
12071 return FALSE;
12072}
12073
Bram Moolenaar01615492015-02-03 13:00:38 +010012074#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012075/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012076 * Any character has an equivalent 'langmap' character. This is used for
12077 * keyboards that have a special language mode that sends characters above
12078 * 128 (although other characters can be translated too). The "to" field is a
12079 * Vim command character. This avoids having to switch the keyboard back to
12080 * ASCII mode when leaving Insert mode.
12081 *
12082 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12083 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012084 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12085 * same as langmap_mapchar[] for characters >= 256.
12086 *
12087 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012088 */
12089typedef struct
12090{
12091 int from;
12092 int to;
12093} langmap_entry_T;
12094
12095static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012096
12097/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012098 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12099 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012100 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012101 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012102langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012103{
12104 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012105 int a = 0;
12106 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012107
12108 /* Do a binary search for an existing entry. */
12109 while (a != b)
12110 {
12111 int i = (a + b) / 2;
12112 int d = entries[i].from - from;
12113
12114 if (d == 0)
12115 {
12116 entries[i].to = to;
12117 return;
12118 }
12119 if (d < 0)
12120 a = i + 1;
12121 else
12122 b = i;
12123 }
12124
12125 if (ga_grow(&langmap_mapga, 1) != OK)
12126 return; /* out of memory */
12127
12128 /* insert new entry at position "a" */
12129 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12130 mch_memmove(entries + 1, entries,
12131 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12132 ++langmap_mapga.ga_len;
12133 entries[0].from = from;
12134 entries[0].to = to;
12135}
12136
12137/*
12138 * Apply 'langmap' to multi-byte character "c" and return the result.
12139 */
12140 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012141langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012142{
12143 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12144 int a = 0;
12145 int b = langmap_mapga.ga_len;
12146
12147 while (a != b)
12148 {
12149 int i = (a + b) / 2;
12150 int d = entries[i].from - c;
12151
12152 if (d == 0)
12153 return entries[i].to; /* found matching entry */
12154 if (d < 0)
12155 a = i + 1;
12156 else
12157 b = i;
12158 }
12159 return c; /* no entry found, return "c" unmodified */
12160}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161
12162 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012163langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012164{
12165 int i;
12166
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012167 for (i = 0; i < 256; i++)
12168 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012169 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012170}
12171
12172/*
12173 * Called when langmap option is set; the language map can be
12174 * changed at any time!
12175 */
12176 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012177langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012178{
12179 char_u *p;
12180 char_u *p2;
12181 int from, to;
12182
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012183 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012184 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012185
12186 for (p = p_langmap; p[0] != NUL; )
12187 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012188 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012189 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012190 {
12191 if (p2[0] == '\\' && p2[1] != NUL)
12192 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193 }
12194 if (p2[0] == ';')
12195 ++p2; /* abcd;ABCD form, p2 points to A */
12196 else
12197 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12198 while (p[0])
12199 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012200 if (p[0] == ',')
12201 {
12202 ++p;
12203 break;
12204 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012205 if (p[0] == '\\' && p[1] != NUL)
12206 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012207 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012208 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 if (p2 == NULL)
12210 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012211 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012212 if (p[0] != ',')
12213 {
12214 if (p[0] == '\\')
12215 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012216 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012217 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012218 }
12219 else
12220 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012221 if (p2[0] != ',')
12222 {
12223 if (p2[0] == '\\')
12224 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012225 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012226 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012227 }
12228 if (to == NUL)
12229 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012230 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012231 transchar(from));
12232 return;
12233 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012234
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012235 if (from >= 256)
12236 langmap_set_entry(from, to);
12237 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012238 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012239
12240 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012241 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012242 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012243 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012244 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012245 if (*p == ';')
12246 {
12247 p = p2;
12248 if (p[0] != NUL)
12249 {
12250 if (p[0] != ',')
12251 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012252 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012253 return;
12254 }
12255 ++p;
12256 }
12257 break;
12258 }
12259 }
12260 }
12261 }
12262}
12263#endif
12264
12265/*
12266 * Return TRUE if format option 'x' is in effect.
12267 * Take care of no formatting when 'paste' is set.
12268 */
12269 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012270has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012271{
12272 if (p_paste)
12273 return FALSE;
12274 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12275}
12276
12277/*
12278 * Return TRUE if "x" is present in 'shortmess' option, or
12279 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12280 */
12281 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012282shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012283{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012284 return p_shm != NULL &&
12285 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012286 || (vim_strchr(p_shm, 'a') != NULL
12287 && vim_strchr((char_u *)SHM_A, x) != NULL));
12288}
12289
12290/*
12291 * paste_option_changed() - Called after p_paste was set or reset.
12292 */
12293 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012294paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295{
12296 static int old_p_paste = FALSE;
12297 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012298 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012299#ifdef FEAT_CMDL_INFO
12300 static int save_ru = 0;
12301#endif
12302#ifdef FEAT_RIGHTLEFT
12303 static int save_ri = 0;
12304 static int save_hkmap = 0;
12305#endif
12306 buf_T *buf;
12307
12308 if (p_paste)
12309 {
12310 /*
12311 * Paste switched from off to on.
12312 * Save the current values, so they can be restored later.
12313 */
12314 if (!old_p_paste)
12315 {
12316 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012317 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012318 {
12319 buf->b_p_tw_nopaste = buf->b_p_tw;
12320 buf->b_p_wm_nopaste = buf->b_p_wm;
12321 buf->b_p_sts_nopaste = buf->b_p_sts;
12322 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012323 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012324#ifdef FEAT_VARTABS
12325 if (buf->b_p_vsts_nopaste)
12326 vim_free(buf->b_p_vsts_nopaste);
12327 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12328 ? vim_strsave(buf->b_p_vsts) : NULL;
12329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012330 }
12331
12332 /* save global options */
12333 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012334 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012335#ifdef FEAT_CMDL_INFO
12336 save_ru = p_ru;
12337#endif
12338#ifdef FEAT_RIGHTLEFT
12339 save_ri = p_ri;
12340 save_hkmap = p_hkmap;
12341#endif
12342 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012343 p_ai_nopaste = p_ai;
12344 p_et_nopaste = p_et;
12345 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012346 p_tw_nopaste = p_tw;
12347 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012348#ifdef FEAT_VARTABS
12349 if (p_vsts_nopaste)
12350 vim_free(p_vsts_nopaste);
12351 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012353 }
12354
12355 /*
12356 * Always set the option values, also when 'paste' is set when it is
12357 * already on.
12358 */
12359 /* set 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 = 0; /* textwidth is 0 */
12363 buf->b_p_wm = 0; /* wrapmargin is 0 */
12364 buf->b_p_sts = 0; /* softtabstop is 0 */
12365 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012366 buf->b_p_et = 0; /* no expandtab */
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 = empty_option;
12371 if (buf->b_p_vsts_array)
12372 vim_free(buf->b_p_vsts_array);
12373 buf->b_p_vsts_array = 0;
12374#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012375 }
12376
12377 /* set global options */
12378 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012379 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012380#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012381 if (p_ru)
12382 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012383 p_ru = 0; /* no ruler */
12384#endif
12385#ifdef FEAT_RIGHTLEFT
12386 p_ri = 0; /* no reverse insert */
12387 p_hkmap = 0; /* no Hebrew keyboard */
12388#endif
12389 /* set global values for local buffer options */
12390 p_tw = 0;
12391 p_wm = 0;
12392 p_sts = 0;
12393 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012394#ifdef FEAT_VARTABS
12395 if (p_vsts)
12396 free_string_option(p_vsts);
12397 p_vsts = empty_option;
12398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012399 }
12400
12401 /*
12402 * Paste switched from on to off: Restore saved values.
12403 */
12404 else if (old_p_paste)
12405 {
12406 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012407 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012408 {
12409 buf->b_p_tw = buf->b_p_tw_nopaste;
12410 buf->b_p_wm = buf->b_p_wm_nopaste;
12411 buf->b_p_sts = buf->b_p_sts_nopaste;
12412 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012413 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012414#ifdef FEAT_VARTABS
12415 if (buf->b_p_vsts)
12416 free_string_option(buf->b_p_vsts);
12417 buf->b_p_vsts = buf->b_p_vsts_nopaste
12418 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12419 if (buf->b_p_vsts_array)
12420 vim_free(buf->b_p_vsts_array);
12421 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12422 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12423 else
12424 buf->b_p_vsts_array = 0;
12425#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012426 }
12427
12428 /* restore global options */
12429 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012430 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012431#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012432 if (p_ru != save_ru)
12433 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012434 p_ru = save_ru;
12435#endif
12436#ifdef FEAT_RIGHTLEFT
12437 p_ri = save_ri;
12438 p_hkmap = save_hkmap;
12439#endif
12440 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012441 p_ai = p_ai_nopaste;
12442 p_et = p_et_nopaste;
12443 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012444 p_tw = p_tw_nopaste;
12445 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012446#ifdef FEAT_VARTABS
12447 if (p_vsts)
12448 free_string_option(p_vsts);
12449 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12450#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012451 }
12452
12453 old_p_paste = p_paste;
12454}
12455
12456/*
12457 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12458 *
12459 * Reset 'compatible' and set the values for options that didn't get set yet
12460 * to the Vim defaults.
12461 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012462 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012463 */
12464 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012465vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012466{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012467 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012468 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012469 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012470
12471 if (!option_was_set((char_u *)"cp"))
12472 {
12473 p_cp = FALSE;
12474 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12475 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12476 set_option_default(opt_idx, OPT_FREE, FALSE);
12477 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012478 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012479 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012480
12481 if (fname != NULL)
12482 {
12483 p = vim_getenv(envname, &dofree);
12484 if (p == NULL)
12485 {
12486 /* Set $MYVIMRC to the first vimrc file found. */
12487 p = FullName_save(fname, FALSE);
12488 if (p != NULL)
12489 {
12490 vim_setenv(envname, p);
12491 vim_free(p);
12492 }
12493 }
12494 else if (dofree)
12495 vim_free(p);
12496 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012497}
12498
12499/*
12500 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12501 */
12502 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012503change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012504{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012505 int opt_idx;
12506
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507 if (p_cp != on)
12508 {
12509 p_cp = on;
12510 compatible_set();
12511 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012512 opt_idx = findoption((char_u *)"cp");
12513 if (opt_idx >= 0)
12514 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012515}
12516
12517/*
12518 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012519 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012520 */
12521 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012522option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012523{
12524 int idx;
12525
12526 idx = findoption(name);
12527 if (idx < 0) /* unknown option */
12528 return FALSE;
12529 if (options[idx].flags & P_WAS_SET)
12530 return TRUE;
12531 return FALSE;
12532}
12533
12534/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012535 * Reset the flag indicating option "name" was set.
12536 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012537 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012538reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012539{
12540 int idx = findoption(name);
12541
12542 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012543 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012544 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012545 return OK;
12546 }
12547 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012548}
12549
12550/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012551 * compatible_set() - Called when 'compatible' has been set or unset.
12552 *
12553 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12554 * flag) to a Vi compatible value.
12555 * When 'compatible' is unset: Set all options that have a different default
12556 * for Vim (without the P_VI_DEF flag) to that default.
12557 */
12558 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012559compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012560{
12561 int opt_idx;
12562
12563 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12564 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12565 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12566 set_option_default(opt_idx, OPT_FREE, p_cp);
12567 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012568 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012569}
12570
12571#ifdef FEAT_LINEBREAK
12572
Bram Moolenaar071d4272004-06-13 20:20:40 +000012573/*
12574 * fill_breakat_flags() -- called when 'breakat' changes value.
12575 */
12576 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012577fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012578{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012579 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012580 int i;
12581
12582 for (i = 0; i < 256; i++)
12583 breakat_flags[i] = FALSE;
12584
12585 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012586 for (p = p_breakat; *p; p++)
12587 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012588}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012589#endif
12590
12591/*
12592 * Check an option that can be a range of string values.
12593 *
12594 * Return OK for correct value, FAIL otherwise.
12595 * Empty is always OK.
12596 */
12597 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012598check_opt_strings(
12599 char_u *val,
12600 char **values,
12601 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012602{
12603 return opt_strings_flags(val, values, NULL, list);
12604}
12605
12606/*
12607 * Handle an option that can be a range of string values.
12608 * Set a flag in "*flagp" for each string present.
12609 *
12610 * Return OK for correct value, FAIL otherwise.
12611 * Empty is always OK.
12612 */
12613 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012614opt_strings_flags(
12615 char_u *val, /* new value */
12616 char **values, /* array of valid string values */
12617 unsigned *flagp,
12618 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012619{
12620 int i;
12621 int len;
12622 unsigned new_flags = 0;
12623
12624 while (*val)
12625 {
12626 for (i = 0; ; ++i)
12627 {
12628 if (values[i] == NULL) /* val not found in values[] */
12629 return FAIL;
12630
12631 len = (int)STRLEN(values[i]);
12632 if (STRNCMP(values[i], val, len) == 0
12633 && ((list && val[len] == ',') || val[len] == NUL))
12634 {
12635 val += len + (val[len] == ',');
12636 new_flags |= (1 << i);
12637 break; /* check next item in val list */
12638 }
12639 }
12640 }
12641 if (flagp != NULL)
12642 *flagp = new_flags;
12643
12644 return OK;
12645}
12646
12647/*
12648 * Read the 'wildmode' option, fill wim_flags[].
12649 */
12650 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012651check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012652{
12653 char_u new_wim_flags[4];
12654 char_u *p;
12655 int i;
12656 int idx = 0;
12657
12658 for (i = 0; i < 4; ++i)
12659 new_wim_flags[i] = 0;
12660
12661 for (p = p_wim; *p; ++p)
12662 {
12663 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12664 ;
12665 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12666 return FAIL;
12667 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12668 new_wim_flags[idx] |= WIM_LONGEST;
12669 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12670 new_wim_flags[idx] |= WIM_FULL;
12671 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12672 new_wim_flags[idx] |= WIM_LIST;
12673 else
12674 return FAIL;
12675 p += i;
12676 if (*p == NUL)
12677 break;
12678 if (*p == ',')
12679 {
12680 if (idx == 3)
12681 return FAIL;
12682 ++idx;
12683 }
12684 }
12685
12686 /* fill remaining entries with last flag */
12687 while (idx < 3)
12688 {
12689 new_wim_flags[idx + 1] = new_wim_flags[idx];
12690 ++idx;
12691 }
12692
12693 /* only when there are no errors, wim_flags[] is changed */
12694 for (i = 0; i < 4; ++i)
12695 wim_flags[i] = new_wim_flags[i];
12696 return OK;
12697}
12698
12699/*
12700 * Check if backspacing over something is allowed.
12701 */
12702 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012703can_bs(
12704 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012705{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012706#ifdef FEAT_JOB_CHANNEL
12707 if (what == BS_START && bt_prompt(curbuf))
12708 return FALSE;
12709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012710 switch (*p_bs)
12711 {
12712 case '2': return TRUE;
12713 case '1': return (what != BS_START);
12714 case '0': return FALSE;
12715 }
12716 return vim_strchr(p_bs, what) != NULL;
12717}
12718
12719/*
12720 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12721 * the file must be considered changed when the value is different.
12722 */
12723 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012724save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012725{
12726 buf->b_start_ffc = *buf->b_p_ff;
12727 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012728 buf->b_start_bomb = buf->b_p_bomb;
12729
Bram Moolenaar071d4272004-06-13 20:20:40 +000012730 /* Only use free/alloc when necessary, they take time. */
12731 if (buf->b_start_fenc == NULL
12732 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12733 {
12734 vim_free(buf->b_start_fenc);
12735 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12736 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012737}
12738
12739/*
12740 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12741 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012742 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12743 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012744 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012745 * When "ignore_empty" is true don't consider a new, empty buffer to be
12746 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012747 */
12748 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012749file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012750{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012751 /* In a buffer that was never loaded the options are not valid. */
12752 if (buf->b_flags & BF_NEVERLOADED)
12753 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012754 if (ignore_empty
12755 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012756 && buf->b_ml.ml_line_count == 1
12757 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12758 return FALSE;
12759 if (buf->b_start_ffc != *buf->b_p_ff)
12760 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012761 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012762 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012763 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12764 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012765 if (buf->b_start_fenc == NULL)
12766 return (*buf->b_p_fenc != NUL);
12767 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012768}
12769
12770/*
12771 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12772 */
12773 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012774check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012775{
12776 return check_opt_strings(p, p_ff_values, FALSE);
12777}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012778
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012779#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012780
12781/*
12782 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012783 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012784 */
12785 int
12786tabstop_set(char_u *var, int **array)
12787{
12788 int valcount = 1;
12789 int t;
12790 char_u *cp;
12791
Bram Moolenaar64f41072018-10-15 22:51:50 +020012792 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012793 {
12794 *array = NULL;
12795 return TRUE;
12796 }
12797
Bram Moolenaar64f41072018-10-15 22:51:50 +020012798 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012799 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012800 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012801 {
12802 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012803
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012804 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12805 {
12806 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012807 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012808 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012809 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012810 return FALSE;
12811 }
12812 }
12813
12814 if (VIM_ISDIGIT(*cp))
12815 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012816 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012817 {
12818 ++valcount;
12819 continue;
12820 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012821 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012822 return FALSE;
12823 }
12824
Bram Moolenaar64f41072018-10-15 22:51:50 +020012825 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012826 if (*array == NULL)
12827 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012828 (*array)[0] = valcount;
12829
12830 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012831 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012832 {
12833 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012834 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012835 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012836 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012837 ++cp;
12838 }
12839
12840 return TRUE;
12841}
12842
12843/*
12844 * Calculate the number of screen spaces a tab will occupy.
12845 * If "vts" is set then the tab widths are taken from that array,
12846 * otherwise the value of ts is used.
12847 */
12848 int
12849tabstop_padding(colnr_T col, int ts_arg, int *vts)
12850{
12851 int ts = ts_arg == 0 ? 8 : ts_arg;
12852 int tabcount;
12853 colnr_T tabcol = 0;
12854 int t;
12855 int padding = 0;
12856
12857 if (vts == NULL || vts[0] == 0)
12858 return ts - (col % ts);
12859
12860 tabcount = vts[0];
12861
12862 for (t = 1; t <= tabcount; ++t)
12863 {
12864 tabcol += vts[t];
12865 if (tabcol > col)
12866 {
12867 padding = (int)(tabcol - col);
12868 break;
12869 }
12870 }
12871 if (t > tabcount)
12872 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12873
12874 return padding;
12875}
12876
12877/*
12878 * Find the size of the tab that covers a particular column.
12879 */
12880 int
12881tabstop_at(colnr_T col, int ts, int *vts)
12882{
12883 int tabcount;
12884 colnr_T tabcol = 0;
12885 int t;
12886 int tab_size = 0;
12887
12888 if (vts == 0 || vts[0] == 0)
12889 return ts;
12890
12891 tabcount = vts[0];
12892 for (t = 1; t <= tabcount; ++t)
12893 {
12894 tabcol += vts[t];
12895 if (tabcol > col)
12896 {
12897 tab_size = vts[t];
12898 break;
12899 }
12900 }
12901 if (t > tabcount)
12902 tab_size = vts[tabcount];
12903
12904 return tab_size;
12905}
12906
12907/*
12908 * Find the column on which a tab starts.
12909 */
12910 colnr_T
12911tabstop_start(colnr_T col, int ts, int *vts)
12912{
12913 int tabcount;
12914 colnr_T tabcol = 0;
12915 int t;
12916 int excess;
12917
Bram Moolenaar0119a592018-06-24 23:53:28 +020012918 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012919 return (col / ts) * ts;
12920
12921 tabcount = vts[0];
12922 for (t = 1; t <= tabcount; ++t)
12923 {
12924 tabcol += vts[t];
12925 if (tabcol > col)
12926 return tabcol - vts[t];
12927 }
12928
12929 excess = tabcol % vts[tabcount];
12930 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12931}
12932
12933/*
12934 * Find the number of tabs and spaces necessary to get from one column
12935 * to another.
12936 */
12937 void
12938tabstop_fromto(
12939 colnr_T start_col,
12940 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012941 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012942 int *vts,
12943 int *ntabs,
12944 int *nspcs)
12945{
12946 int spaces = end_col - start_col;
12947 colnr_T tabcol = 0;
12948 int padding = 0;
12949 int tabcount;
12950 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012951 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012952
Bram Moolenaar0119a592018-06-24 23:53:28 +020012953 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012954 {
12955 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012956 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012957
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012958 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012959 if (spaces >= initspc)
12960 {
12961 spaces -= initspc;
12962 tabs++;
12963 }
12964 tabs += spaces / ts;
12965 spaces -= (spaces / ts) * ts;
12966
12967 *ntabs = tabs;
12968 *nspcs = spaces;
12969 return;
12970 }
12971
12972 /* Find the padding needed to reach the next tabstop. */
12973 tabcount = vts[0];
12974 for (t = 1; t <= tabcount; ++t)
12975 {
12976 tabcol += vts[t];
12977 if (tabcol > start_col)
12978 {
12979 padding = (int)(tabcol - start_col);
12980 break;
12981 }
12982 }
12983 if (t > tabcount)
12984 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12985
12986 /* If the space needed is less than the padding no tabs can be used. */
12987 if (spaces < padding)
12988 {
12989 *ntabs = 0;
12990 *nspcs = spaces;
12991 return;
12992 }
12993
12994 *ntabs = 1;
12995 spaces -= padding;
12996
12997 /* At least one tab has been used. See if any more will fit. */
12998 while (spaces != 0 && ++t <= tabcount)
12999 {
13000 padding = vts[t];
13001 if (spaces < padding)
13002 {
13003 *nspcs = spaces;
13004 return;
13005 }
13006 ++*ntabs;
13007 spaces -= padding;
13008 }
13009
13010 *ntabs += spaces / vts[tabcount];
13011 *nspcs = spaces % vts[tabcount];
13012}
13013
13014/*
13015 * See if two tabstop arrays contain the same values.
13016 */
13017 int
13018tabstop_eq(int *ts1, int *ts2)
13019{
13020 int t;
13021
13022 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13023 return FALSE;
13024 if (ts1 == ts2)
13025 return TRUE;
13026 if (ts1[0] != ts2[0])
13027 return FALSE;
13028
13029 for (t = 1; t <= ts1[0]; ++t)
13030 if (ts1[t] != ts2[t])
13031 return FALSE;
13032
13033 return TRUE;
13034}
13035
Bram Moolenaar113e1072019-01-20 15:30:40 +010013036#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013037/*
13038 * Copy a tabstop array, allocating space for the new array.
13039 */
13040 int *
13041tabstop_copy(int *oldts)
13042{
13043 int *newts;
13044 int t;
13045
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013046 if (oldts == NULL)
13047 return NULL;
13048 newts = (int *)alloc((unsigned)((oldts[0] + 1) * sizeof(int)));
13049 if (newts != NULL)
13050 for (t = 0; t <= oldts[0]; ++t)
13051 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013052 return newts;
13053}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013054#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013055
13056/*
13057 * Return a count of the number of tabstops.
13058 */
13059 int
13060tabstop_count(int *ts)
13061{
13062 return ts != NULL ? ts[0] : 0;
13063}
13064
13065/*
13066 * Return the first tabstop, or 8 if there are no tabstops defined.
13067 */
13068 int
13069tabstop_first(int *ts)
13070{
13071 return ts != NULL ? ts[1] : 8;
13072}
13073
13074#endif
13075
Bram Moolenaar14f24742012-08-08 18:01:05 +020013076/*
13077 * Return the effective shiftwidth value for current buffer, using the
13078 * 'tabstop' value when 'shiftwidth' is zero.
13079 */
13080 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013081get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013082{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013083 return get_sw_value_col(buf, 0);
13084}
13085
13086/*
13087 * Idem, using the first non-black in the current line.
13088 */
13089 long
13090get_sw_value_indent(buf_T *buf)
13091{
13092 pos_T pos = curwin->w_cursor;
13093
13094 pos.col = getwhitecols_curline();
13095 return get_sw_value_pos(buf, &pos);
13096}
13097
13098/*
13099 * Idem, using "pos".
13100 */
13101 long
13102get_sw_value_pos(buf_T *buf, pos_T *pos)
13103{
13104 pos_T save_cursor = curwin->w_cursor;
13105 long sw_value;
13106
13107 curwin->w_cursor = *pos;
13108 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13109 curwin->w_cursor = save_cursor;
13110 return sw_value;
13111}
13112
13113/*
13114 * Idem, using virtual column "col".
13115 */
13116 long
13117get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13118{
13119 return buf->b_p_sw ? buf->b_p_sw :
13120 #ifdef FEAT_VARTABS
13121 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13122 #else
13123 buf->b_p_ts;
13124 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013125}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013126
13127/*
13128 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013129 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013130 */
13131 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013132get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013133{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013134 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013135}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013136
13137/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013138 * Return the effective 'scrolloff' value for the current window, using the
13139 * global value when appropriate.
13140 */
13141 long
13142get_scrolloff_value(void)
13143{
13144 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13145}
13146
13147/*
13148 * Return the effective 'sidescrolloff' value for the current window, using the
13149 * global value when appropriate.
13150 */
13151 long
13152get_sidescrolloff_value(void)
13153{
13154 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13155}
13156
13157/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013158 * Check matchpairs option for "*initc".
13159 * If there is a match set "*initc" to the matching character and "*findc" to
13160 * the opposite character. Set "*backwards" to the direction.
13161 * When "switchit" is TRUE swap the direction.
13162 */
13163 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013164find_mps_values(
13165 int *initc,
13166 int *findc,
13167 int *backwards,
13168 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013169{
13170 char_u *ptr;
13171
13172 ptr = curbuf->b_p_mps;
13173 while (*ptr != NUL)
13174 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013175 if (has_mbyte)
13176 {
13177 char_u *prev;
13178
13179 if (mb_ptr2char(ptr) == *initc)
13180 {
13181 if (switchit)
13182 {
13183 *findc = *initc;
13184 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13185 *backwards = TRUE;
13186 }
13187 else
13188 {
13189 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13190 *backwards = FALSE;
13191 }
13192 return;
13193 }
13194 prev = ptr;
13195 ptr += mb_ptr2len(ptr) + 1;
13196 if (mb_ptr2char(ptr) == *initc)
13197 {
13198 if (switchit)
13199 {
13200 *findc = *initc;
13201 *initc = mb_ptr2char(prev);
13202 *backwards = FALSE;
13203 }
13204 else
13205 {
13206 *findc = mb_ptr2char(prev);
13207 *backwards = TRUE;
13208 }
13209 return;
13210 }
13211 ptr += mb_ptr2len(ptr);
13212 }
13213 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013214 {
13215 if (*ptr == *initc)
13216 {
13217 if (switchit)
13218 {
13219 *backwards = TRUE;
13220 *findc = *initc;
13221 *initc = ptr[2];
13222 }
13223 else
13224 {
13225 *backwards = FALSE;
13226 *findc = ptr[2];
13227 }
13228 return;
13229 }
13230 ptr += 2;
13231 if (*ptr == *initc)
13232 {
13233 if (switchit)
13234 {
13235 *backwards = FALSE;
13236 *findc = *initc;
13237 *initc = ptr[-2];
13238 }
13239 else
13240 {
13241 *backwards = TRUE;
13242 *findc = ptr[-2];
13243 }
13244 return;
13245 }
13246 ++ptr;
13247 }
13248 if (*ptr == ',')
13249 ++ptr;
13250 }
13251}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013252
13253#if defined(FEAT_LINEBREAK) || defined(PROTO)
13254/*
13255 * This is called when 'breakindentopt' is changed and when a window is
13256 * initialized.
13257 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013258 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013259briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013260{
13261 char_u *p;
13262 int bri_shift = 0;
13263 long bri_min = 20;
13264 int bri_sbr = FALSE;
13265
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013266 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013267 while (*p != NUL)
13268 {
13269 if (STRNCMP(p, "shift:", 6) == 0
13270 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13271 {
13272 p += 6;
13273 bri_shift = getdigits(&p);
13274 }
13275 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13276 {
13277 p += 4;
13278 bri_min = getdigits(&p);
13279 }
13280 else if (STRNCMP(p, "sbr", 3) == 0)
13281 {
13282 p += 3;
13283 bri_sbr = TRUE;
13284 }
13285 if (*p != ',' && *p != NUL)
13286 return FAIL;
13287 if (*p == ',')
13288 ++p;
13289 }
13290
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013291 wp->w_p_brishift = bri_shift;
13292 wp->w_p_brimin = bri_min;
13293 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013294
13295 return OK;
13296}
13297#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013298
13299/*
13300 * Get the local or global value of 'backupcopy'.
13301 */
13302 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013303get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013304{
13305 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13306}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013307
13308#if defined(FEAT_SIGNS) || defined(PROTO)
13309/*
13310 * Return TRUE when window "wp" has a column to draw signs in.
13311 */
13312 int
13313signcolumn_on(win_T *wp)
13314{
13315 if (*wp->w_p_scl == 'n')
13316 return FALSE;
13317 if (*wp->w_p_scl == 'y')
13318 return TRUE;
13319 return (wp->w_buffer->b_signlist != NULL
13320# ifdef FEAT_NETBEANS_INTG
13321 || wp->w_buffer->b_has_sign_column
13322# endif
13323 );
13324}
13325#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013326
13327#if defined(FEAT_EVAL) || defined(PROTO)
13328/*
13329 * Get window or buffer local options.
13330 */
13331 dict_T *
13332get_winbuf_options(int bufopt)
13333{
13334 dict_T *d;
13335 int opt_idx;
13336
13337 d = dict_alloc();
13338 if (d == NULL)
13339 return NULL;
13340
13341 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13342 {
13343 struct vimoption *opt = &options[opt_idx];
13344
13345 if ((bufopt && (opt->indir & PV_BUF))
13346 || (!bufopt && (opt->indir & PV_WIN)))
13347 {
13348 char_u *varp = get_varp(opt);
13349
13350 if (varp != NULL)
13351 {
13352 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013353 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013354 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013355 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013356 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013357 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013358 }
13359 }
13360 }
13361
13362 return d;
13363}
13364#endif