blob: 795b40f205a597daf5f5ede15c4f8ee5ed4b7350 [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 Moolenaar071d4272004-06-13 20:20:40 +0000470
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000471#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
472
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000473/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
474 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100475#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000476# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000477#else
478# define ISP_LATIN1 (char_u *)"@,161-255"
479#endif
480
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200481# 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 +0000482
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100483/* Default python version for pyx* commands */
484#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
485# define DEFAULT_PYTHON_VER 0
486#elif defined(FEAT_PYTHON3)
487# define DEFAULT_PYTHON_VER 3
488#elif defined(FEAT_PYTHON)
489# define DEFAULT_PYTHON_VER 2
490#else
491# define DEFAULT_PYTHON_VER 0
492#endif
493
Bram Moolenaarce655742019-01-31 14:12:57 +0100494// used for 'cinkeys' and 'indentkeys'
495#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
496
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497/*
498 * options[] is initialized here.
499 * The order of the options MUST be alphabetic for ":set all" and findoption().
500 * All option names MUST start with a lowercase letter (for findoption()).
501 * Exception: "t_" options are at the end.
502 * The options with a NULL variable are 'hidden': a set command for them is
503 * ignored and they are not printed.
504 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100505static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200507 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508#ifdef FEAT_RIGHTLEFT
509 (char_u *)&p_aleph, PV_NONE,
510#else
511 (char_u *)NULL, PV_NONE,
512#endif
513 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100514#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515 (char_u *)128L,
516#else
517 (char_u *)224L,
518#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200519 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200521#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 (char_u *)&p_antialias, PV_NONE,
523 {(char_u *)FALSE, (char_u *)FALSE}
524#else
525 (char_u *)NULL, PV_NONE,
526 {(char_u *)FALSE, (char_u *)FALSE}
527#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200528 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200529 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530#ifdef FEAT_ARABIC
531 (char_u *)VAR_WIN, PV_ARAB,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200535 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
537#ifdef FEAT_ARABIC
538 (char_u *)&p_arshape, PV_NONE,
539#else
540 (char_u *)NULL, PV_NONE,
541#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200542 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
544#ifdef FEAT_RIGHTLEFT
545 (char_u *)&p_ari, PV_NONE,
546#else
547 (char_u *)NULL, PV_NONE,
548#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200549 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200552 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 (char_u *)&p_ambw, PV_NONE,
555 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200556 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100558#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100560 {(char_u *)FALSE, (char_u *)0L}
561#else
562 (char_u *)NULL, PV_NONE,
563 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200565 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autoindent", "ai", P_BOOL|P_VI_DEF,
567 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200568 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autoprint", "ap", P_BOOL|P_VI_DEF,
570 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200571 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000573 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200574 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"autowrite", "aw", P_BOOL|P_VI_DEF,
576 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200577 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"autowriteall","awa", P_BOOL|P_VI_DEF,
579 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200580 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
582 (char_u *)&p_bg, PV_NONE,
583 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100584#if (defined(MSWIN)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585 (char_u *)"dark",
586#else
587 (char_u *)"light",
588#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200589 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200590 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200592 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
594 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200595 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200596 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200597 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000598#ifdef UNIX
599 {(char_u *)"yes", (char_u *)"auto"}
600#else
601 {(char_u *)"auto", (char_u *)"auto"}
602#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200603 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200604 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
605 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200607 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000608 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609 (char_u *)&p_bex, PV_NONE,
610 {
611#ifdef VMS
612 (char_u *)"_",
613#else
614 (char_u *)"~",
615#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200616 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200617 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618#ifdef FEAT_WILDIGN
619 (char_u *)&p_bsk, PV_NONE,
620 {(char_u *)"", (char_u *)0L}
621#else
622 (char_u *)NULL, PV_NONE,
623 {(char_u *)0L, (char_u *)0L}
624#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200625 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100627#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100629 {(char_u *)600L, (char_u *)0L}
630#else
631 (char_u *)NULL, PV_NONE,
632 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200634 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100636#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100637 (char_u *)&p_beval, PV_NONE,
638 {(char_u *)FALSE, (char_u *)0L}
639#else
640 (char_u *)NULL, PV_NONE,
641 {(char_u *)0L, (char_u *)0L}
642#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200643 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100644 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100645#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100646 (char_u *)&p_bevalterm, PV_NONE,
647 {(char_u *)FALSE, (char_u *)0L}
648#else
649 (char_u *)NULL, PV_NONE,
650 {(char_u *)0L, (char_u *)0L}
651#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200652 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100653 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
654#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
655 (char_u *)&p_bexpr, PV_BEXPR,
656 {(char_u *)"", (char_u *)0L}
657#else
658 (char_u *)NULL, PV_NONE,
659 {(char_u *)0L, (char_u *)0L}
660#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200661 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662 {"beautify", "bf", P_BOOL|P_VI_DEF,
663 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200664 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200665 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
666 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200667 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
669 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200670 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200673 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200676 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
678#ifdef FEAT_LINEBREAK
679 (char_u *)&p_breakat, PV_NONE,
680 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
681#else
682 (char_u *)NULL, PV_NONE,
683 {(char_u *)0L, (char_u *)0L}
684#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200685 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200686 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
687#ifdef FEAT_LINEBREAK
688 (char_u *)VAR_WIN, PV_BRI,
689 {(char_u *)FALSE, (char_u *)0L}
690#else
691 (char_u *)NULL, PV_NONE,
692 {(char_u *)0L, (char_u *)0L}
693#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200694 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200695 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
696 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200697#ifdef FEAT_LINEBREAK
698 (char_u *)VAR_WIN, PV_BRIOPT,
699 {(char_u *)"", (char_u *)NULL}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)"", (char_u *)NULL}
703#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200704 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
706#ifdef FEAT_BROWSE
707 (char_u *)&p_bsdir, PV_NONE,
708 {(char_u *)"last", (char_u *)0L}
709#else
710 (char_u *)NULL, PV_NONE,
711 {(char_u *)0L, (char_u *)0L}
712#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200713 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 (char_u *)&p_bh, PV_BH,
716 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200717 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
719 (char_u *)&p_bl, PV_BL,
720 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200721 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 (char_u *)&p_bt, PV_BT,
724 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200725 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200726 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 (char_u *)&p_cmp, PV_NONE,
728 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200729 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
731#ifdef FEAT_SEARCHPATH
732 (char_u *)&p_cdpath, PV_NONE,
733 {(char_u *)",,", (char_u *)0L}
734#else
735 (char_u *)NULL, PV_NONE,
736 {(char_u *)0L, (char_u *)0L}
737#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200738 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739 {"cedit", NULL, P_STRING,
740#ifdef FEAT_CMDWIN
741 (char_u *)&p_cedit, PV_NONE,
742 {(char_u *)"", (char_u *)CTRL_F_STR}
743#else
744 (char_u *)NULL, PV_NONE,
745 {(char_u *)0L, (char_u *)0L}
746#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200747 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100749#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 (char_u *)&p_ccv, PV_NONE,
751 {(char_u *)"", (char_u *)0L}
752#else
753 (char_u *)NULL, PV_NONE,
754 {(char_u *)0L, (char_u *)0L}
755#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200756 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
758#ifdef FEAT_CINDENT
759 (char_u *)&p_cin, PV_CIN,
760#else
761 (char_u *)NULL, PV_NONE,
762#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200763 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200764 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765#ifdef FEAT_CINDENT
766 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100767 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768#else
769 (char_u *)NULL, PV_NONE,
770 {(char_u *)0L, (char_u *)0L}
771#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200772 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200773 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774#ifdef FEAT_CINDENT
775 (char_u *)&p_cino, PV_CINO,
776#else
777 (char_u *)NULL, PV_NONE,
778#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200779 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200780 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000781#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
782 (char_u *)&p_cinw, PV_CINW,
783 {(char_u *)"if,else,while,do,for,switch",
784 (char_u *)0L}
785#else
786 (char_u *)NULL, PV_NONE,
787 {(char_u *)0L, (char_u *)0L}
788#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200789 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200790 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791#ifdef FEAT_CLIPBOARD
792 (char_u *)&p_cb, PV_NONE,
793# ifdef FEAT_XCLIPBOARD
794 {(char_u *)"autoselect,exclude:cons\\|linux",
795 (char_u *)0L}
796# else
797 {(char_u *)"", (char_u *)0L}
798# endif
799#else
800 (char_u *)NULL, PV_NONE,
801 {(char_u *)"", (char_u *)0L}
802#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200803 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
805 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200806 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000807 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
808#ifdef FEAT_CMDWIN
809 (char_u *)&p_cwh, PV_NONE,
810#else
811 (char_u *)NULL, PV_NONE,
812#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200813 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200814 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200815#ifdef FEAT_SYN_HL
816 (char_u *)VAR_WIN, PV_CC,
817#else
818 (char_u *)NULL, PV_NONE,
819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200820 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000821 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
822 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200823 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200824 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
825 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000826#ifdef FEAT_COMMENTS
827 (char_u *)&p_com, PV_COM,
828 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
829 (char_u *)0L}
830#else
831 (char_u *)NULL, PV_NONE,
832 {(char_u *)0L, (char_u *)0L}
833#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200834 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200835 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836#ifdef FEAT_FOLDING
837 (char_u *)&p_cms, PV_CMS,
838 {(char_u *)"/*%s*/", (char_u *)0L}
839#else
840 (char_u *)NULL, PV_NONE,
841 {(char_u *)0L, (char_u *)0L}
842#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200843 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000844 /* P_PRI_MKRC isn't needed here, optval_default()
845 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846 {"compatible", "cp", P_BOOL|P_RALL,
847 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200848 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200849 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000850#ifdef FEAT_INS_EXPAND
851 (char_u *)&p_cpt, PV_CPT,
852 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
853#else
854 (char_u *)NULL, PV_NONE,
855 {(char_u *)0L, (char_u *)0L}
856#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200857 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200858 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200859#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200860 (char_u *)VAR_WIN, PV_COCU,
861 {(char_u *)"", (char_u *)NULL}
862#else
863 (char_u *)NULL, PV_NONE,
864 {(char_u *)NULL, (char_u *)0L}
865#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200866 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200867 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
868#ifdef FEAT_CONCEAL
869 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200870#else
871 (char_u *)NULL, PV_NONE,
872#endif
873 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200874 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000875 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
876#ifdef FEAT_COMPL_FUNC
877 (char_u *)&p_cfu, PV_CFU,
878 {(char_u *)"", (char_u *)0L}
879#else
880 (char_u *)NULL, PV_NONE,
881 {(char_u *)0L, (char_u *)0L}
882#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200883 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200884 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000885#ifdef FEAT_INS_EXPAND
886 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000887 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000888#else
889 (char_u *)NULL, PV_NONE,
890 {(char_u *)0L, (char_u *)0L}
891#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200892 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000893 {"confirm", "cf", P_BOOL|P_VI_DEF,
894#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
895 (char_u *)&p_confirm, PV_NONE,
896#else
897 (char_u *)NULL, PV_NONE,
898#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200899 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200902 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
904 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200905 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000906 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
907 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000908 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200909 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200910 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200911#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200912 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100913 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200914#else
915 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200916 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200917#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200918 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
920#ifdef FEAT_CSCOPE
921 (char_u *)&p_cspc, PV_NONE,
922#else
923 (char_u *)NULL, PV_NONE,
924#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200925 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000926 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
927#ifdef FEAT_CSCOPE
928 (char_u *)&p_csprg, PV_NONE,
929 {(char_u *)"cscope", (char_u *)0L}
930#else
931 (char_u *)NULL, PV_NONE,
932 {(char_u *)0L, (char_u *)0L}
933#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200934 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200935 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000936#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
937 (char_u *)&p_csqf, PV_NONE,
938 {(char_u *)"", (char_u *)0L}
939#else
940 (char_u *)NULL, PV_NONE,
941 {(char_u *)0L, (char_u *)0L}
942#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200943 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200944 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
945#ifdef FEAT_CSCOPE
946 (char_u *)&p_csre, PV_NONE,
947#else
948 (char_u *)NULL, PV_NONE,
949#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200950 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000951 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
952#ifdef FEAT_CSCOPE
953 (char_u *)&p_cst, PV_NONE,
954#else
955 (char_u *)NULL, PV_NONE,
956#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200957 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000958 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
959#ifdef FEAT_CSCOPE
960 (char_u *)&p_csto, PV_NONE,
961#else
962 (char_u *)NULL, PV_NONE,
963#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200964 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000965 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
966#ifdef FEAT_CSCOPE
967 (char_u *)&p_csverbose, PV_NONE,
968#else
969 (char_u *)NULL, PV_NONE,
970#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200971 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200972 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200973 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200974 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100975 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000976#ifdef FEAT_SYN_HL
977 (char_u *)VAR_WIN, PV_CUC,
978#else
979 (char_u *)NULL, PV_NONE,
980#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200981 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100982 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000983#ifdef FEAT_SYN_HL
984 (char_u *)VAR_WIN, PV_CUL,
985#else
986 (char_u *)NULL, PV_NONE,
987#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200988 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000989 {"debug", NULL, P_STRING|P_VI_DEF,
990 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200991 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200992 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000993#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000994 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000995 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996#else
997 (char_u *)NULL, PV_NONE,
998 {(char_u *)NULL, (char_u *)0L}
999#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001000 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001001 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001002 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001003 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001004 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001005#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001006 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#else
1008 (char_u *)NULL, PV_NONE,
1009#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001010 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1012#ifdef FEAT_DIFF
1013 (char_u *)VAR_WIN, PV_DIFF,
1014#else
1015 (char_u *)NULL, PV_NONE,
1016#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001017 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001018 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001019#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1020 (char_u *)&p_dex, PV_NONE,
1021 {(char_u *)"", (char_u *)0L}
1022#else
1023 (char_u *)NULL, PV_NONE,
1024 {(char_u *)0L, (char_u *)0L}
1025#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001026 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001027 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1028 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001029#ifdef FEAT_DIFF
1030 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001031 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032#else
1033 (char_u *)NULL, PV_NONE,
1034 {(char_u *)"", (char_u *)NULL}
1035#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001036 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001037 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1038#ifdef FEAT_DIGRAPHS
1039 (char_u *)&p_dg, PV_NONE,
1040#else
1041 (char_u *)NULL, PV_NONE,
1042#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001043 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001044 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1045 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001046 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001047 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001048 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001050 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 (char_u *)&p_ead, PV_NONE,
1053 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001054 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1056 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001057 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001058 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001059 (char_u *)&p_emoji, PV_NONE,
1060 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001061 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001062 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 (char_u *)&p_enc, PV_NONE,
1064 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001065 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1067 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001068 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1070 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001071 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001073 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001074 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1076 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001077 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1079#ifdef FEAT_QUICKFIX
1080 (char_u *)&p_ef, PV_NONE,
1081 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1082#else
1083 (char_u *)NULL, PV_NONE,
1084 {(char_u *)NULL, (char_u *)0L}
1085#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001086 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001087 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001088#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001089 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001090 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091#else
1092 (char_u *)NULL, PV_NONE,
1093 {(char_u *)NULL, (char_u *)0L}
1094#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001095 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001096 {"esckeys", "ek", P_BOOL|P_VIM,
1097 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001098 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001099 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001100 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001101 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1103 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001104 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1106 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001107 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001108 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1109 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110 (char_u *)&p_fenc, PV_FENC,
1111 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001112 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001113 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001114 (char_u *)&p_fencs, PV_NONE,
1115 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001116 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001117 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1118 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001119 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001120 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001121 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001123 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001124 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001125 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1126 (char_u *)&p_fic, PV_NONE,
1127 {
1128#ifdef CASE_INSENSITIVE_FILENAME
1129 (char_u *)TRUE,
1130#else
1131 (char_u *)FALSE,
1132#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001133 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001134 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001135 (char_u *)&p_ft, PV_FT,
1136 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001137 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001138 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001139 (char_u *)&p_fcs, PV_NONE,
1140 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001141 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001142 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1143 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001144 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001145 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001147 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 {"flash", "fl", P_BOOL|P_VI_DEF,
1149 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001150 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001151 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001152#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001153 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001154 {(char_u *)"", (char_u *)0L}
1155#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 (char_u *)NULL, PV_NONE,
1157 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001158#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001159 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001160 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1161#ifdef FEAT_FOLDING
1162 (char_u *)VAR_WIN, PV_FDC,
1163 {(char_u *)FALSE, (char_u *)0L}
1164#else
1165 (char_u *)NULL, PV_NONE,
1166 {(char_u *)NULL, (char_u *)0L}
1167#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001168 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001169 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1170#ifdef FEAT_FOLDING
1171 (char_u *)VAR_WIN, PV_FEN,
1172 {(char_u *)TRUE, (char_u *)0L}
1173#else
1174 (char_u *)NULL, PV_NONE,
1175 {(char_u *)NULL, (char_u *)0L}
1176#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001177 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001178 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1179#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1180 (char_u *)VAR_WIN, PV_FDE,
1181 {(char_u *)"0", (char_u *)NULL}
1182#else
1183 (char_u *)NULL, PV_NONE,
1184 {(char_u *)NULL, (char_u *)0L}
1185#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001186 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001187 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001188#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001189 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001190 {(char_u *)"#", (char_u *)NULL}
1191#else
1192 (char_u *)NULL, PV_NONE,
1193 {(char_u *)NULL, (char_u *)0L}
1194#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001195 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001196 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001197#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001199 {(char_u *)0L, (char_u *)0L}
1200#else
1201 (char_u *)NULL, PV_NONE,
1202 {(char_u *)NULL, (char_u *)0L}
1203#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001204 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001205 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001206#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001208 {(char_u *)-1L, (char_u *)0L}
1209#else
1210 (char_u *)NULL, PV_NONE,
1211 {(char_u *)NULL, (char_u *)0L}
1212#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001213 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001214 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001215 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001216#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001218 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001219#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 (char_u *)NULL, PV_NONE,
1221 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001223 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001224 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1225#ifdef FEAT_FOLDING
1226 (char_u *)VAR_WIN, PV_FDM,
1227 {(char_u *)"manual", (char_u *)NULL}
1228#else
1229 (char_u *)NULL, PV_NONE,
1230 {(char_u *)NULL, (char_u *)0L}
1231#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001232 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001233 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1234#ifdef FEAT_FOLDING
1235 (char_u *)VAR_WIN, PV_FML,
1236 {(char_u *)1L, (char_u *)0L}
1237#else
1238 (char_u *)NULL, PV_NONE,
1239 {(char_u *)NULL, (char_u *)0L}
1240#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001241 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001242 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1243#ifdef FEAT_FOLDING
1244 (char_u *)VAR_WIN, PV_FDN,
1245 {(char_u *)20L, (char_u *)0L}
1246#else
1247 (char_u *)NULL, PV_NONE,
1248 {(char_u *)NULL, (char_u *)0L}
1249#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001250 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001251 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1252#ifdef FEAT_FOLDING
1253 (char_u *)&p_fdo, PV_NONE,
1254 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1255 (char_u *)0L}
1256#else
1257 (char_u *)NULL, PV_NONE,
1258 {(char_u *)NULL, (char_u *)0L}
1259#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001260 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001261 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1262#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1263 (char_u *)VAR_WIN, PV_FDT,
1264 {(char_u *)"foldtext()", (char_u *)NULL}
1265#else
1266 (char_u *)NULL, PV_NONE,
1267 {(char_u *)NULL, (char_u *)0L}
1268#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001269 SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001270 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001271#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001272 (char_u *)&p_fex, PV_FEX,
1273 {(char_u *)"", (char_u *)0L}
1274#else
1275 (char_u *)NULL, PV_NONE,
1276 {(char_u *)0L, (char_u *)0L}
1277#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001278 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001279 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1280 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001281 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001282 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001283 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1284 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001285 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001286 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001287 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001288 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001289 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001290 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1291#ifdef HAVE_FSYNC
1292 (char_u *)&p_fs, PV_NONE,
1293 {(char_u *)TRUE, (char_u *)0L}
1294#else
1295 (char_u *)NULL, PV_NONE,
1296 {(char_u *)FALSE, (char_u *)0L}
1297#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001298 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001299 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1300 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001301 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 {"graphic", "gr", P_BOOL|P_VI_DEF,
1303 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001304 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001305 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306#ifdef FEAT_QUICKFIX
1307 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001308 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#else
1310 (char_u *)NULL, PV_NONE,
1311 {(char_u *)NULL, (char_u *)0L}
1312#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001313 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001314 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1315#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001316 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001318# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319 /* may be changed to "grep -n" in os_win32.c */
1320 (char_u *)"findstr /n",
1321# else
1322# ifdef UNIX
1323 /* Add an extra file name so that grep will always
1324 * insert a file name in the match line. */
1325 (char_u *)"grep -n $* /dev/null",
1326# else
1327# ifdef VMS
1328 (char_u *)"SEARCH/NUMBERS ",
1329# else
1330 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001331# endif
1332# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001334 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335#else
1336 (char_u *)NULL, PV_NONE,
1337 {(char_u *)NULL, (char_u *)0L}
1338#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001339 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001340 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001341#ifdef CURSOR_SHAPE
1342 (char_u *)&p_guicursor, PV_NONE,
1343 {
1344# ifdef FEAT_GUI
1345 (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 +01001346# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001347 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1348# endif
1349 (char_u *)0L}
1350#else
1351 (char_u *)NULL, PV_NONE,
1352 {(char_u *)NULL, (char_u *)0L}
1353#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001354 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001355 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001356#ifdef FEAT_GUI
1357 (char_u *)&p_guifont, PV_NONE,
1358 {(char_u *)"", (char_u *)0L}
1359#else
1360 (char_u *)NULL, PV_NONE,
1361 {(char_u *)NULL, (char_u *)0L}
1362#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001363 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001364 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001365#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1366 (char_u *)&p_guifontset, PV_NONE,
1367 {(char_u *)"", (char_u *)0L}
1368#else
1369 (char_u *)NULL, PV_NONE,
1370 {(char_u *)NULL, (char_u *)0L}
1371#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001372 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001373 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001374#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001375 (char_u *)&p_guifontwide, PV_NONE,
1376 {(char_u *)"", (char_u *)0L}
1377#else
1378 (char_u *)NULL, PV_NONE,
1379 {(char_u *)NULL, (char_u *)0L}
1380#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001381 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001382 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001383#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001384 (char_u *)&p_ghr, PV_NONE,
1385#else
1386 (char_u *)NULL, PV_NONE,
1387#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001388 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001389 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001390#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001391 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001392# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001393 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001394# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001395 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396# endif
1397#else
1398 (char_u *)NULL, PV_NONE,
1399 {(char_u *)NULL, (char_u *)0L}
1400#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001401 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402 {"guipty", NULL, P_BOOL|P_VI_DEF,
1403#if defined(FEAT_GUI)
1404 (char_u *)&p_guipty, PV_NONE,
1405#else
1406 (char_u *)NULL, PV_NONE,
1407#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001408 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar18144c82006-04-12 21:52:12 +00001409 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001410#if defined(FEAT_GUI_TABLINE)
1411 (char_u *)&p_gtl, PV_NONE,
1412 {(char_u *)"", (char_u *)0L}
1413#else
1414 (char_u *)NULL, PV_NONE,
1415 {(char_u *)NULL, (char_u *)0L}
1416#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001417 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001418 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001419#if defined(FEAT_GUI_TABLINE)
1420 (char_u *)&p_gtt, PV_NONE,
1421 {(char_u *)"", (char_u *)0L}
1422#else
1423 (char_u *)NULL, PV_NONE,
1424 {(char_u *)NULL, (char_u *)0L}
1425#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001426 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001427 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1428 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001429 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1431 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001432 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001433 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001434 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001435 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001436 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001437 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438#ifdef FEAT_MULTI_LANG
1439 (char_u *)&p_hlg, PV_NONE,
1440 {(char_u *)"", (char_u *)0L}
1441#else
1442 (char_u *)NULL, PV_NONE,
1443 {(char_u *)0L, (char_u *)0L}
1444#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001445 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001446 {"hidden", "hid", P_BOOL|P_VI_DEF,
1447 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001448 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001449 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001450 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001451 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001452 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 {"history", "hi", P_NUM|P_VIM,
1454 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001455 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1457#ifdef FEAT_RIGHTLEFT
1458 (char_u *)&p_hkmap, PV_NONE,
1459#else
1460 (char_u *)NULL, PV_NONE,
1461#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001462 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001463 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1464#ifdef FEAT_RIGHTLEFT
1465 (char_u *)&p_hkmapp, PV_NONE,
1466#else
1467 (char_u *)NULL, PV_NONE,
1468#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001469 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001470 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1471 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001472 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 {"icon", NULL, P_BOOL|P_VI_DEF,
1474#ifdef FEAT_TITLE
1475 (char_u *)&p_icon, PV_NONE,
1476#else
1477 (char_u *)NULL, PV_NONE,
1478#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001479 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001480 {"iconstring", NULL, P_STRING|P_VI_DEF,
1481#ifdef FEAT_TITLE
1482 (char_u *)&p_iconstring, PV_NONE,
1483#else
1484 (char_u *)NULL, PV_NONE,
1485#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001486 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001487 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1488 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001489 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001490 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001491#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001492 (char_u *)&p_imaf, PV_NONE,
1493 {(char_u *)"", (char_u *)NULL}
1494# else
1495 (char_u *)NULL, PV_NONE,
1496 {(char_u *)NULL, (char_u *)0L}
1497# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001498 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001499 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001500#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 (char_u *)&p_imak, PV_NONE,
1502#else
1503 (char_u *)NULL, PV_NONE,
1504#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001505 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001506 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001507 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001508 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511#ifdef __sgi
1512 {(char_u *)TRUE, (char_u *)0L}
1513#else
1514 {(char_u *)FALSE, (char_u *)0L}
1515#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001516 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 {"iminsert", "imi", P_NUM|P_VI_DEF,
1518 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001520 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {"imsearch", "ims", P_NUM|P_VI_DEF,
1522 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001523 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001524 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001525 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001526#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001527 (char_u *)&p_imsf, PV_NONE,
1528 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001529#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001530 (char_u *)NULL, PV_NONE,
1531 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001532#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001533 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001534 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1535#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1536 (char_u *)&p_imst, PV_NONE,
1537 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1538#else
1539 (char_u *)NULL, PV_NONE,
1540 {(char_u *)0L, (char_u *)0L}
1541#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001542 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001543 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1544#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001545 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1547#else
1548 (char_u *)NULL, PV_NONE,
1549 {(char_u *)0L, (char_u *)0L}
1550#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001551 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001552 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF,
1553#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1554 (char_u *)&p_inex, PV_INEX,
1555 {(char_u *)"", (char_u *)0L}
1556#else
1557 (char_u *)NULL, PV_NONE,
1558 {(char_u *)0L, (char_u *)0L}
1559#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001560 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001561 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1562 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001563 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM,
1565#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1566 (char_u *)&p_inde, PV_INDE,
1567 {(char_u *)"", (char_u *)0L}
1568#else
1569 (char_u *)NULL, PV_NONE,
1570 {(char_u *)0L, (char_u *)0L}
1571#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001572 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001573 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001574#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1575 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001576 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577#else
1578 (char_u *)NULL, PV_NONE,
1579 {(char_u *)0L, (char_u *)0L}
1580#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001581 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001582 {"infercase", "inf", P_BOOL|P_VI_DEF,
1583 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001584 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1586 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001587 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1589 (char_u *)&p_isf, PV_NONE,
1590 {
1591#ifdef BACKSLASH_IN_FILENAME
1592 /* Excluded are: & and ^ are special in cmd.exe
1593 * ( and ) are used in text separating fnames */
1594 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1595#else
1596# ifdef AMIGA
1597 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1598# else
1599# ifdef VMS
1600 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1601# else /* UNIX et al. */
1602# ifdef EBCDIC
1603 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1604# else
1605 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1606# endif
1607# endif
1608# endif
1609#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001610 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001611 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1612 (char_u *)&p_isi, PV_NONE,
1613 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001614#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001615 (char_u *)"@,48-57,_,128-167,224-235",
1616#else
1617# ifdef EBCDIC
1618 /* TODO: EBCDIC Check this! @ == isalpha()*/
1619 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1620 "112-120,128,140-142,156,158,172,"
1621 "174,186,191,203-207,219-225,235-239,"
1622 "251-254",
1623# else
1624 (char_u *)"@,48-57,_,192-255",
1625# endif
1626#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001627 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001628 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1629 (char_u *)&p_isk, PV_ISK,
1630 {
1631#ifdef EBCDIC
1632 (char_u *)"@,240-249,_",
1633 /* TODO: EBCDIC Check this! @ == isalpha()*/
1634 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1635 "112-120,128,140-142,156,158,172,"
1636 "174,186,191,203-207,219-225,235-239,"
1637 "251-254",
1638#else
1639 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001640# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001641 (char_u *)"@,48-57,_,128-167,224-235"
1642# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001643 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644# endif
1645#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001646 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1648 (char_u *)&p_isp, PV_NONE,
1649 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001650#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001651 (char_u *)"@,~-255",
1652#else
1653# ifdef EBCDIC
1654 /* all chars above 63 are printable */
1655 (char_u *)"63-255",
1656# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001657 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658# endif
1659#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001660 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1662 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001663 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001664 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1665#ifdef FEAT_CRYPT
1666 (char_u *)&p_key, PV_KEY,
1667 {(char_u *)"", (char_u *)0L}
1668#else
1669 (char_u *)NULL, PV_NONE,
1670 {(char_u *)0L, (char_u *)0L}
1671#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001672 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001673 {"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 +00001674#ifdef FEAT_KEYMAP
1675 (char_u *)&p_keymap, PV_KMAP,
1676 {(char_u *)"", (char_u *)0L}
1677#else
1678 (char_u *)NULL, PV_NONE,
1679 {(char_u *)"", (char_u *)0L}
1680#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001681 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001682 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001683 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001684 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001686 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001688#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 (char_u *)":help",
1690#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001691# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001693# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001694# ifdef USEMAN_S
1695 (char_u *)"man -s",
1696# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001697 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001698# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699# endif
1700#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001701 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001702 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703#ifdef FEAT_LANGMAP
1704 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001705 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706#else
1707 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001708 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001710 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001711 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1713 (char_u *)&p_lm, PV_NONE,
1714#else
1715 (char_u *)NULL, PV_NONE,
1716#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001717 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001718 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1719#ifdef FEAT_LANGMAP
1720 (char_u *)&p_lnr, PV_NONE,
1721#else
1722 (char_u *)NULL, PV_NONE,
1723#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001724 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001725 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1726#ifdef FEAT_LANGMAP
1727 (char_u *)&p_lrm, PV_NONE,
1728#else
1729 (char_u *)NULL, PV_NONE,
1730#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001731 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001732 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001733 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001734 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1736 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001737 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1739#ifdef FEAT_LINEBREAK
1740 (char_u *)VAR_WIN, PV_LBR,
1741#else
1742 (char_u *)NULL, PV_NONE,
1743#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001744 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1746 (char_u *)&Rows, PV_NONE,
1747 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001748#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749 (char_u *)25L,
1750#else
1751 (char_u *)24L,
1752#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001753 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001754 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1755#ifdef FEAT_GUI
1756 (char_u *)&p_linespace, PV_NONE,
1757#else
1758 (char_u *)NULL, PV_NONE,
1759#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001760#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001761 {(char_u *)1L, (char_u *)0L}
1762#else
1763 {(char_u *)0L, (char_u *)0L}
1764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001765 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001766 {"lisp", NULL, P_BOOL|P_VI_DEF,
1767#ifdef FEAT_LISP
1768 (char_u *)&p_lisp, PV_LISP,
1769#else
1770 (char_u *)NULL, PV_NONE,
1771#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001772 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001773 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001774#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001775 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1777#else
1778 (char_u *)NULL, PV_NONE,
1779 {(char_u *)"", (char_u *)0L}
1780#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001781 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001782 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1783 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001784 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001785 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001786 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001787 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1789 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001790 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001791 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001792#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001793 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001794 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001795#else
1796 (char_u *)NULL, PV_NONE,
1797 {(char_u *)"", (char_u *)0L}
1798#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001799 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001800 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001801#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001802 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001803 {(char_u *)TRUE, (char_u *)0L}
1804#else
1805 (char_u *)NULL, PV_NONE,
1806 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001807#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001808 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001809 {"magic", NULL, P_BOOL|P_VI_DEF,
1810 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001811 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001812 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001813#ifdef FEAT_QUICKFIX
1814 (char_u *)&p_mef, PV_NONE,
1815 {(char_u *)"", (char_u *)0L}
1816#else
1817 (char_u *)NULL, PV_NONE,
1818 {(char_u *)NULL, (char_u *)0L}
1819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001820 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001821 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001822 (char_u *)&p_menc, PV_MENC,
1823 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001824 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001825 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1826#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001827 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828# ifdef VMS
1829 {(char_u *)"MMS", (char_u *)0L}
1830# else
1831 {(char_u *)"make", (char_u *)0L}
1832# endif
1833#else
1834 (char_u *)NULL, PV_NONE,
1835 {(char_u *)NULL, (char_u *)0L}
1836#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001837 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001838 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001840 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001841 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 {"matchtime", "mat", P_NUM|P_VI_DEF,
1843 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001844 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001845 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001846 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001847 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001848 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1849#ifdef FEAT_EVAL
1850 (char_u *)&p_mfd, PV_NONE,
1851#else
1852 (char_u *)NULL, PV_NONE,
1853#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001854 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001855 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1856 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001857 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {"maxmem", "mm", P_NUM|P_VI_DEF,
1859 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001860 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001861 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001862 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1863 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001864 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001865 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1866 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001867 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001868 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"menuitems", "mis", P_NUM|P_VI_DEF,
1870#ifdef FEAT_MENU
1871 (char_u *)&p_mis, PV_NONE,
1872#else
1873 (char_u *)NULL, PV_NONE,
1874#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001875 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"mesg", NULL, P_BOOL|P_VI_DEF,
1877 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001878 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001879 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001880#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001881 (char_u *)&p_msm, PV_NONE,
1882 {(char_u *)"460000,2000,500", (char_u *)0L}
1883#else
1884 (char_u *)NULL, PV_NONE,
1885 {(char_u *)0L, (char_u *)0L}
1886#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001887 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888 {"modeline", "ml", P_BOOL|P_VIM,
1889 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001890 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"modelines", "mls", P_NUM|P_VI_DEF,
1892 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001893 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1895 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001896 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1898 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001899 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"more", NULL, P_BOOL|P_VIM,
1901 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001902 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1904 (char_u *)&p_mouse, PV_NONE,
1905 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001906#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001907 (char_u *)"a",
1908#else
1909 (char_u *)"",
1910#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001911 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1913#ifdef FEAT_GUI
1914 (char_u *)&p_mousef, PV_NONE,
1915#else
1916 (char_u *)NULL, PV_NONE,
1917#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001918 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001919 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1920#ifdef FEAT_GUI
1921 (char_u *)&p_mh, PV_NONE,
1922#else
1923 (char_u *)NULL, PV_NONE,
1924#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001925 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1927 (char_u *)&p_mousem, PV_NONE,
1928 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001929#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001930 (char_u *)"popup",
1931#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001932# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933 (char_u *)"popup_setpos",
1934# else
1935 (char_u *)"extend",
1936# endif
1937#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001938 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001939 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001940#ifdef FEAT_MOUSESHAPE
1941 (char_u *)&p_mouseshape, PV_NONE,
1942 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1943#else
1944 (char_u *)NULL, PV_NONE,
1945 {(char_u *)NULL, (char_u *)0L}
1946#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001947 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001948 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1949 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001950 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001951 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1952#if defined(DYNAMIC_MZSCHEME)
1953 (char_u *)&p_mzschemedll, PV_NONE,
1954 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1955#else
1956 (char_u *)NULL, PV_NONE,
1957 {(char_u *)"", (char_u *)0L}
1958#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001959 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001960 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1961#if defined(DYNAMIC_MZSCHEME)
1962 (char_u *)&p_mzschemegcdll, PV_NONE,
1963 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1964#else
1965 (char_u *)NULL, PV_NONE,
1966 {(char_u *)"", (char_u *)0L}
1967#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001968 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001969 {"mzquantum", "mzq", P_NUM,
1970#ifdef FEAT_MZSCHEME
1971 (char_u *)&p_mzq, PV_NONE,
1972#else
1973 (char_u *)NULL, PV_NONE,
1974#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001975 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976 {"novice", NULL, P_BOOL|P_VI_DEF,
1977 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001978 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001979 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001980 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001981 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001982 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001983 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
1984 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001985 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001986 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1987#ifdef FEAT_LINEBREAK
1988 (char_u *)VAR_WIN, PV_NUW,
1989#else
1990 (char_u *)NULL, PV_NONE,
1991#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001992 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001993 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001994#ifdef FEAT_COMPL_FUNC
1995 (char_u *)&p_ofu, PV_OFU,
1996 {(char_u *)"", (char_u *)0L}
1997#else
1998 (char_u *)NULL, PV_NONE,
1999 {(char_u *)0L, (char_u *)0L}
2000#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002001 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002002 {"open", NULL, P_BOOL|P_VI_DEF,
2003 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002004 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002005 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002006#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002007 (char_u *)&p_odev, PV_NONE,
2008#else
2009 (char_u *)NULL, PV_NONE,
2010#endif
2011 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002012 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002013 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2014 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002015 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"optimize", "opt", P_BOOL|P_VI_DEF,
2017 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002018 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002019 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002020 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002021 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002022 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2023 |P_SECURE,
2024 (char_u *)&p_pp, PV_NONE,
2025 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002026 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002027 {"paragraphs", "para", P_STRING|P_VI_DEF,
2028 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002029 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002030 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002031 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002033 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2035 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002036 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2038#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2039 (char_u *)&p_pex, PV_NONE,
2040 {(char_u *)"", (char_u *)0L}
2041#else
2042 (char_u *)NULL, PV_NONE,
2043 {(char_u *)0L, (char_u *)0L}
2044#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002045 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002046 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002047 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002048 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002049 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002050 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002052#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 (char_u *)".,,",
2054#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002057 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002058 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002059#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002060 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002061 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002062#else
2063 (char_u *)NULL, PV_NONE,
2064 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002065#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002066 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2068 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002069 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002070 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002071#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 (char_u *)&p_pvh, PV_NONE,
2073#else
2074 (char_u *)NULL, PV_NONE,
2075#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002076 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002078#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002079 (char_u *)VAR_WIN, PV_PVW,
2080#else
2081 (char_u *)NULL, PV_NONE,
2082#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002083 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002084 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002085#ifdef FEAT_PRINTER
2086 (char_u *)&p_pdev, PV_NONE,
2087 {(char_u *)"", (char_u *)0L}
2088#else
2089 (char_u *)NULL, PV_NONE,
2090 {(char_u *)NULL, (char_u *)0L}
2091#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002092 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002093 {"printencoding", "penc", P_STRING|P_VI_DEF,
2094#ifdef FEAT_POSTSCRIPT
2095 (char_u *)&p_penc, PV_NONE,
2096 {(char_u *)"", (char_u *)0L}
2097#else
2098 (char_u *)NULL, PV_NONE,
2099 {(char_u *)NULL, (char_u *)0L}
2100#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002101 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002102 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002103#ifdef FEAT_POSTSCRIPT
2104 (char_u *)&p_pexpr, PV_NONE,
2105 {(char_u *)"", (char_u *)0L}
2106#else
2107 (char_u *)NULL, PV_NONE,
2108 {(char_u *)NULL, (char_u *)0L}
2109#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002110 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002111 {"printfont", "pfn", P_STRING|P_VI_DEF,
2112#ifdef FEAT_PRINTER
2113 (char_u *)&p_pfn, PV_NONE,
2114 {
2115# ifdef MSWIN
2116 (char_u *)"Courier_New:h10",
2117# else
2118 (char_u *)"courier",
2119# endif
2120 (char_u *)0L}
2121#else
2122 (char_u *)NULL, PV_NONE,
2123 {(char_u *)NULL, (char_u *)0L}
2124#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002125 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2127#ifdef FEAT_PRINTER
2128 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002129 /* untranslated to avoid problems when 'encoding'
2130 * is changed */
2131 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002132#else
2133 (char_u *)NULL, PV_NONE,
2134 {(char_u *)NULL, (char_u *)0L}
2135#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002136 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002137 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002138#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002139 (char_u *)&p_pmcs, PV_NONE,
2140 {(char_u *)"", (char_u *)0L}
2141#else
2142 (char_u *)NULL, PV_NONE,
2143 {(char_u *)NULL, (char_u *)0L}
2144#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002145 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002146 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002147#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002148 (char_u *)&p_pmfn, PV_NONE,
2149 {(char_u *)"", (char_u *)0L}
2150#else
2151 (char_u *)NULL, PV_NONE,
2152 {(char_u *)NULL, (char_u *)0L}
2153#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002154 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002155 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002156#ifdef FEAT_PRINTER
2157 (char_u *)&p_popt, PV_NONE,
2158 {(char_u *)"", (char_u *)0L}
2159#else
2160 (char_u *)NULL, PV_NONE,
2161 {(char_u *)NULL, (char_u *)0L}
2162#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002163 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002164 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002165 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002166 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002167 {"pumheight", "ph", P_NUM|P_VI_DEF,
2168#ifdef FEAT_INS_EXPAND
2169 (char_u *)&p_ph, PV_NONE,
2170#else
2171 (char_u *)NULL, PV_NONE,
2172#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002173 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002174 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2175#ifdef FEAT_INS_EXPAND
2176 (char_u *)&p_pw, PV_NONE,
2177#else
2178 (char_u *)NULL, PV_NONE,
2179#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002180 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002181 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002182#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002183 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002184 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002185#else
2186 (char_u *)NULL, PV_NONE,
2187 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002188#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002189 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002190 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2191#if defined(FEAT_PYTHON3)
2192 (char_u *)&p_py3home, PV_NONE,
2193 {(char_u *)"", (char_u *)0L}
2194#else
2195 (char_u *)NULL, PV_NONE,
2196 {(char_u *)NULL, (char_u *)0L}
2197#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002198 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002199 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002200#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002201 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002202 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002203#else
2204 (char_u *)NULL, PV_NONE,
2205 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002206#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002207 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002208 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2209#if defined(FEAT_PYTHON)
2210 (char_u *)&p_pyhome, PV_NONE,
2211 {(char_u *)"", (char_u *)0L}
2212#else
2213 (char_u *)NULL, PV_NONE,
2214 {(char_u *)NULL, (char_u *)0L}
2215#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002216 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002217 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2218#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2219 (char_u *)&p_pyx, PV_NONE,
2220#else
2221 (char_u *)NULL, PV_NONE,
2222#endif
2223 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002224 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002225 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2226#ifdef FEAT_TEXTOBJ
2227 (char_u *)&p_qe, PV_QE,
2228 {(char_u *)"\\", (char_u *)0L}
2229#else
2230 (char_u *)NULL, PV_NONE,
2231 {(char_u *)NULL, (char_u *)0L}
2232#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002233 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002234 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2235 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002236 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002237 {"redraw", NULL, P_BOOL|P_VI_DEF,
2238 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002239 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002240 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2241#ifdef FEAT_RELTIME
2242 (char_u *)&p_rdt, PV_NONE,
2243#else
2244 (char_u *)NULL, PV_NONE,
2245#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002246 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002247 {"regexpengine", "re", P_NUM|P_VI_DEF,
2248 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002249 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar64486672010-05-16 15:46:46 +02002250 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
2251 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002252 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002253 {"remap", NULL, P_BOOL|P_VI_DEF,
2254 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002255 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002256 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002257#ifdef FEAT_RENDER_OPTIONS
2258 (char_u *)&p_rop, PV_NONE,
2259 {(char_u *)"", (char_u *)0L}
2260#else
2261 (char_u *)NULL, PV_NONE,
2262 {(char_u *)NULL, (char_u *)0L}
2263#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002264 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002265 {"report", NULL, P_NUM|P_VI_DEF,
2266 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002267 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002269#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002270 (char_u *)&p_rs, PV_NONE,
2271#else
2272 (char_u *)NULL, PV_NONE,
2273#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002274 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2276#ifdef FEAT_RIGHTLEFT
2277 (char_u *)&p_ri, PV_NONE,
2278#else
2279 (char_u *)NULL, PV_NONE,
2280#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002281 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2283#ifdef FEAT_RIGHTLEFT
2284 (char_u *)VAR_WIN, PV_RL,
2285#else
2286 (char_u *)NULL, PV_NONE,
2287#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002288 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2290#ifdef FEAT_RIGHTLEFT
2291 (char_u *)VAR_WIN, PV_RLC,
2292 {(char_u *)"search", (char_u *)NULL}
2293#else
2294 (char_u *)NULL, PV_NONE,
2295 {(char_u *)NULL, (char_u *)0L}
2296#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002297 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002298 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002299#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002300 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002301 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002302#else
2303 (char_u *)NULL, PV_NONE,
2304 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002305#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002306 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002307 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2308#ifdef FEAT_CMDL_INFO
2309 (char_u *)&p_ru, PV_NONE,
2310#else
2311 (char_u *)NULL, PV_NONE,
2312#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002313 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2315#ifdef FEAT_STL_OPT
2316 (char_u *)&p_ruf, PV_NONE,
2317#else
2318 (char_u *)NULL, PV_NONE,
2319#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002320 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002321 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2322 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002323 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002324 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002325 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002326 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2327 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002328 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002331 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002332 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2333 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002334 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002335 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002336 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002337 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002338 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 (char_u *)&p_sbo, PV_NONE,
2340 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002341 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002342 {"sections", "sect", P_STRING|P_VI_DEF,
2343 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002344 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002345 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2347 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002348 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002352 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002353 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002355 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002356 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357#ifdef FEAT_SESSION
2358 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002359 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 (char_u *)0L}
2361#else
2362 (char_u *)NULL, PV_NONE,
2363 {(char_u *)0L, (char_u *)0L}
2364#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002365 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002366 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2367 (char_u *)&p_sh, PV_NONE,
2368 {
2369#ifdef VMS
2370 (char_u *)"-",
2371#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002372# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002374# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002376# endif
2377#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002378 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002379 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2380 (char_u *)&p_shcf, PV_NONE,
2381 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002382#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383 (char_u *)"/c",
2384#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002385 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002387 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2389#ifdef FEAT_QUICKFIX
2390 (char_u *)&p_sp, PV_NONE,
2391 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002392#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394#else
2395 (char_u *)">",
2396#endif
2397 (char_u *)0L}
2398#else
2399 (char_u *)NULL, PV_NONE,
2400 {(char_u *)0L, (char_u *)0L}
2401#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002402 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2404 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002405 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002406 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2407 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002408 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2410#ifdef BACKSLASH_IN_FILENAME
2411 (char_u *)&p_ssl, PV_NONE,
2412#else
2413 (char_u *)NULL, PV_NONE,
2414#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002415 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002416 {"shelltemp", "stmp", P_BOOL,
2417 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002418 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002419 {"shelltype", "st", P_NUM|P_VI_DEF,
2420#ifdef AMIGA
2421 (char_u *)&p_st, PV_NONE,
2422#else
2423 (char_u *)NULL, PV_NONE,
2424#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002425 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2427 (char_u *)&p_sxq, PV_NONE,
2428 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002429#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002430 (char_u *)"\"",
2431#else
2432 (char_u *)"",
2433#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002434 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002435 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2436 (char_u *)&p_sxe, PV_NONE,
2437 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002438#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002439 (char_u *)"\"&|<>()@^",
2440#else
2441 (char_u *)"",
2442#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002443 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2445 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002446 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002447 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2448 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002449 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002450 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2451 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002452 {(char_u *)"", (char_u *)"filnxtToO"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002453 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002455 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002456 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2458#ifdef FEAT_LINEBREAK
2459 (char_u *)&p_sbr, PV_NONE,
2460#else
2461 (char_u *)NULL, PV_NONE,
2462#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002463 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {"showcmd", "sc", P_BOOL|P_VIM,
2465#ifdef FEAT_CMDL_INFO
2466 (char_u *)&p_sc, PV_NONE,
2467#else
2468 (char_u *)NULL, PV_NONE,
2469#endif
2470 {(char_u *)FALSE,
2471#ifdef UNIX
2472 (char_u *)FALSE
2473#else
2474 (char_u *)TRUE
2475#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002476 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002477 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2478 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002479 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002480 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2481 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002482 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002483 {"showmode", "smd", P_BOOL|P_VIM,
2484 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002485 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002486 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002487 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002488 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002489 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2490 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002491 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002493 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002494 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002495 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2496#ifdef FEAT_SIGNS
2497 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002498 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002499#else
2500 (char_u *)NULL, PV_NONE,
2501 {(char_u *)NULL, (char_u *)0L}
2502#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002503 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2505 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002506 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2508 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002509 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002510 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2511#ifdef FEAT_SMARTINDENT
2512 (char_u *)&p_si, PV_SI,
2513#else
2514 (char_u *)NULL, PV_NONE,
2515#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002516 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2518 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002519 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002520 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2521 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002522 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002523 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2524 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002525 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002526 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002527#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002528 (char_u *)VAR_WIN, PV_SPELL,
2529#else
2530 (char_u *)NULL, PV_NONE,
2531#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002532 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002533 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002534#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002535 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002536 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002537#else
2538 (char_u *)NULL, PV_NONE,
2539 {(char_u *)0L, (char_u *)0L}
2540#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002541 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002542 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2543 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002544#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002545 (char_u *)&p_spf, PV_SPF,
2546 {(char_u *)"", (char_u *)0L}
2547#else
2548 (char_u *)NULL, PV_NONE,
2549 {(char_u *)0L, (char_u *)0L}
2550#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002551 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002552 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2553 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002554#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002555 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002556 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002557#else
2558 (char_u *)NULL, PV_NONE,
2559 {(char_u *)0L, (char_u *)0L}
2560#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002561 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002562 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002563#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002564 (char_u *)&p_sps, PV_NONE,
2565 {(char_u *)"best", (char_u *)0L}
2566#else
2567 (char_u *)NULL, PV_NONE,
2568 {(char_u *)0L, (char_u *)0L}
2569#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002570 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002571 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002572 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002573 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002574 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002575 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002577 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2578 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002579 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002580 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT,
2581#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002582 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002583#else
2584 (char_u *)NULL, PV_NONE,
2585#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002586 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002587 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588 (char_u *)&p_su, PV_NONE,
2589 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002590 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002591 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002592#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002593 (char_u *)&p_sua, PV_SUA,
2594 {(char_u *)"", (char_u *)0L}
2595#else
2596 (char_u *)NULL, PV_NONE,
2597 {(char_u *)0L, (char_u *)0L}
2598#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002599 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2601 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002602 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 {"swapsync", "sws", P_STRING|P_VI_DEF,
2604 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002605 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002606 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002608 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002609 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2610#ifdef FEAT_SYN_HL
2611 (char_u *)&p_smc, PV_SMC,
2612 {(char_u *)3000L, (char_u *)0L}
2613#else
2614 (char_u *)NULL, PV_NONE,
2615 {(char_u *)0L, (char_u *)0L}
2616#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002617 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002618 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002619#ifdef FEAT_SYN_HL
2620 (char_u *)&p_syn, PV_SYN,
2621 {(char_u *)"", (char_u *)0L}
2622#else
2623 (char_u *)NULL, PV_NONE,
2624 {(char_u *)0L, (char_u *)0L}
2625#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002626 SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002627 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL,
2628#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002629 (char_u *)&p_tal, PV_NONE,
2630#else
2631 (char_u *)NULL, PV_NONE,
2632#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002633 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002634 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002635 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002636 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002637 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2638 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002639 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002640 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2641 (char_u *)&p_tbs, PV_NONE,
2642#ifdef VMS /* binary searching doesn't appear to work on VMS */
2643 {(char_u *)0L, (char_u *)0L}
2644#else
2645 {(char_u *)TRUE, (char_u *)0L}
2646#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002647 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002648 {"tagcase", "tc", P_STRING|P_VIM,
2649 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002650 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002651 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2652#ifdef FEAT_EVAL
2653 (char_u *)&p_tfu, PV_TFU,
2654 {(char_u *)"", (char_u *)0L}
2655#else
2656 (char_u *)NULL, PV_NONE,
2657 {(char_u *)0L, (char_u *)0L}
2658#endif
2659 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002660 {"taglength", "tl", P_NUM|P_VI_DEF,
2661 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002662 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002663 {"tagrelative", "tr", P_BOOL|P_VIM,
2664 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002665 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002666 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002667 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002668 {
2669#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2670 (char_u *)"./tags,./TAGS,tags,TAGS",
2671#else
2672 (char_u *)"./tags,tags",
2673#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002674 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2676 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002677 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002678 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002679#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002680 (char_u *)&p_tcldll, PV_NONE,
2681 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002682#else
2683 (char_u *)NULL, PV_NONE,
2684 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002685#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002686 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002687 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2688 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002689 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2691#ifdef FEAT_ARABIC
2692 (char_u *)&p_tbidi, PV_NONE,
2693#else
2694 (char_u *)NULL, PV_NONE,
2695#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002696 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002698 (char_u *)&p_tenc, PV_NONE,
2699 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002700 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002701 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2702#ifdef FEAT_TERMGUICOLORS
2703 (char_u *)&p_tgc, PV_NONE,
2704 {(char_u *)FALSE, (char_u *)FALSE}
2705#else
2706 (char_u*)NULL, PV_NONE,
2707 {(char_u *)FALSE, (char_u *)FALSE}
2708#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002709 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002710 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2711#ifdef FEAT_TERMINAL
2712 (char_u *)VAR_WIN, PV_TWK,
2713 {(char_u *)"", (char_u *)NULL}
2714#else
2715 (char_u *)NULL, PV_NONE,
2716 {(char_u *)NULL, (char_u *)0L}
2717#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002718 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002719 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2720#ifdef FEAT_TERMINAL
2721 (char_u *)&p_twsl, PV_TWSL,
2722 {(char_u *)10000L, (char_u *)10000L}
2723#else
2724 (char_u *)NULL, PV_NONE,
2725 {(char_u *)NULL, (char_u *)0L}
2726#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002727 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002728 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2729#ifdef FEAT_TERMINAL
2730 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002731 {(char_u *)"", (char_u *)NULL}
2732#else
2733 (char_u *)NULL, PV_NONE,
2734 {(char_u *)NULL, (char_u *)0L}
2735#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002736 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002737 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002738#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002739 (char_u *)&p_twt, PV_NONE,
2740 {(char_u *)"", (char_u *)NULL}
2741#else
2742 (char_u *)NULL, PV_NONE,
2743 {(char_u *)NULL, (char_u *)0L}
2744#endif
2745 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002746 {"terse", NULL, P_BOOL|P_VI_DEF,
2747 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002748 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002749 {"textauto", "ta", P_BOOL|P_VIM,
2750 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002751 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002752 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2754 (char_u *)&p_tx, PV_TX,
2755 {
2756#ifdef USE_CRNL
2757 (char_u *)TRUE,
2758#else
2759 (char_u *)FALSE,
2760#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002761 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002762 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002764 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002765 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002766#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002767 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768#else
2769 (char_u *)NULL, PV_NONE,
2770#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002771 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002772 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2773 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002774 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"timeout", "to", P_BOOL|P_VI_DEF,
2776 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002777 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2779 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002780 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"title", NULL, P_BOOL|P_VI_DEF,
2782#ifdef FEAT_TITLE
2783 (char_u *)&p_title, PV_NONE,
2784#else
2785 (char_u *)NULL, PV_NONE,
2786#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002787 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002788 {"titlelen", NULL, P_NUM|P_VI_DEF,
2789#ifdef FEAT_TITLE
2790 (char_u *)&p_titlelen, PV_NONE,
2791#else
2792 (char_u *)NULL, PV_NONE,
2793#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002794 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002795 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002796#ifdef FEAT_TITLE
2797 (char_u *)&p_titleold, PV_NONE,
2798 {(char_u *)N_("Thanks for flying Vim"),
2799 (char_u *)0L}
2800#else
2801 (char_u *)NULL, PV_NONE,
2802 {(char_u *)0L, (char_u *)0L}
2803#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002804 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002805 {"titlestring", NULL, P_STRING|P_VI_DEF,
2806#ifdef FEAT_TITLE
2807 (char_u *)&p_titlestring, PV_NONE,
2808#else
2809 (char_u *)NULL, PV_NONE,
2810#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002811 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002812 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002813#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002814 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002815 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002816#else
2817 (char_u *)NULL, PV_NONE,
2818 {(char_u *)0L, (char_u *)0L}
2819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002820 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002821 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002822#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002823 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002824 {(char_u *)"small", (char_u *)0L}
2825#else
2826 (char_u *)NULL, PV_NONE,
2827 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002829 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002830 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2831 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002832 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2834 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002835 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2837 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002838 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2840 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002841 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2843#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2844 (char_u *)&p_ttym, PV_NONE,
2845#else
2846 (char_u *)NULL, PV_NONE,
2847#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002848 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002849 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2850 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002851 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2853 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002854 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002855 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2856 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002857#ifdef FEAT_PERSISTENT_UNDO
2858 (char_u *)&p_udir, PV_NONE,
2859 {(char_u *)".", (char_u *)0L}
2860#else
2861 (char_u *)NULL, PV_NONE,
2862 {(char_u *)0L, (char_u *)0L}
2863#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002864 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002865 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2866#ifdef FEAT_PERSISTENT_UNDO
2867 (char_u *)&p_udf, PV_UDF,
2868#else
2869 (char_u *)NULL, PV_NONE,
2870#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002871 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002872 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002873 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002874 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002875#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002876 (char_u *)1000L,
2877#else
2878 (char_u *)100L,
2879#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002880 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002881 {"undoreload", "ur", P_NUM|P_VI_DEF,
2882 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002883 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002884 {"updatecount", "uc", P_NUM|P_VI_DEF,
2885 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002886 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"updatetime", "ut", P_NUM|P_VI_DEF,
2888 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002889 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002890 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2891#ifdef FEAT_VARTABS
2892 (char_u *)&p_vsts, PV_VSTS,
2893 {(char_u *)"", (char_u *)0L}
2894#else
2895 (char_u *)NULL, PV_NONE,
2896 {(char_u *)"", (char_u *)NULL}
2897#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002898 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002899 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2900#ifdef FEAT_VARTABS
2901 (char_u *)&p_vts, PV_VTS,
2902 {(char_u *)"", (char_u *)0L}
2903#else
2904 (char_u *)NULL, PV_NONE,
2905 {(char_u *)"", (char_u *)NULL}
2906#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002907 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002908 {"verbose", "vbs", P_NUM|P_VI_DEF,
2909 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002910 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002911 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2912 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002913 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002914 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2915#ifdef FEAT_SESSION
2916 (char_u *)&p_vdir, PV_NONE,
2917 {(char_u *)DFLT_VDIR, (char_u *)0L}
2918#else
2919 (char_u *)NULL, PV_NONE,
2920 {(char_u *)0L, (char_u *)0L}
2921#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002922 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002923 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002924#ifdef FEAT_SESSION
2925 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002926 {(char_u *)"folds,options,cursor,curdir",
2927 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928#else
2929 (char_u *)NULL, PV_NONE,
2930 {(char_u *)0L, (char_u *)0L}
2931#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002932 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002933 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002934#ifdef FEAT_VIMINFO
2935 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002936#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002937 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938#else
2939# ifdef AMIGA
2940 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002941 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002943 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002944# endif
2945#endif
2946#else
2947 (char_u *)NULL, PV_NONE,
2948 {(char_u *)0L, (char_u *)0L}
2949#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002950 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002951 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2952 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002953#ifdef FEAT_VIMINFO
2954 (char_u *)&p_viminfofile, PV_NONE,
2955 {(char_u *)"", (char_u *)0L}
2956#else
2957 (char_u *)NULL, PV_NONE,
2958 {(char_u *)0L, (char_u *)0L}
2959#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002960 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002961 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2962 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002963 (char_u *)&p_ve, PV_NONE,
2964 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002965 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2967 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002968 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 {"w300", NULL, P_NUM|P_VI_DEF,
2970 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002971 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 {"w1200", NULL, P_NUM|P_VI_DEF,
2973 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002974 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002975 {"w9600", NULL, P_NUM|P_VI_DEF,
2976 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002977 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002978 {"warn", NULL, P_BOOL|P_VI_DEF,
2979 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002980 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2982 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002983 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002984 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002985 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002986 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002987 {"wildchar", "wc", P_NUM|P_VIM,
2988 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002989 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002990 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002991 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002993 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002994 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995#ifdef FEAT_WILDIGN
2996 (char_u *)&p_wig, PV_NONE,
2997#else
2998 (char_u *)NULL, PV_NONE,
2999#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003000 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003001 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3002 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003003 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003004 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3005#ifdef FEAT_WILDMENU
3006 (char_u *)&p_wmnu, PV_NONE,
3007#else
3008 (char_u *)NULL, PV_NONE,
3009#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003010 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003011 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003012 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003013 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003014 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3015#ifdef FEAT_CMDL_COMPL
3016 (char_u *)&p_wop, PV_NONE,
3017 {(char_u *)"", (char_u *)0L}
3018#else
3019 (char_u *)NULL, PV_NONE,
3020 {(char_u *)NULL, (char_u *)0L}
3021#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003022 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3024#ifdef FEAT_WAK
3025 (char_u *)&p_wak, PV_NONE,
3026 {(char_u *)"menu", (char_u *)0L}
3027#else
3028 (char_u *)NULL, PV_NONE,
3029 {(char_u *)NULL, (char_u *)0L}
3030#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003031 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003032 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003033 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003034 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003035 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003036 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003037 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003039 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003040 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003041 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003042 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003043 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003044 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003046 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003049 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003050 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003051#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003052 (char_u *)&p_winptydll, PV_NONE, {
3053# ifdef _WIN64
3054 (char_u *)"winpty64.dll",
3055# else
3056 (char_u *)"winpty32.dll",
3057# endif
3058 (char_u *)0L}
3059#else
3060 (char_u *)NULL, PV_NONE,
3061 {(char_u *)0L, (char_u *)0L}
3062#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003063 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003064 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003066 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3068 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003069 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003070 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3071 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003072 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003073 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3074 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003075 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003076 {"write", NULL, P_BOOL|P_VI_DEF,
3077 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003078 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003079 {"writeany", "wa", P_BOOL|P_VI_DEF,
3080 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003081 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3083 (char_u *)&p_wb, PV_NONE,
3084 {
3085#ifdef FEAT_WRITEBACKUP
3086 (char_u *)TRUE,
3087#else
3088 (char_u *)FALSE,
3089#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003090 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 {"writedelay", "wd", P_NUM|P_VI_DEF,
3092 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003093 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094
3095/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003096#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003098 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099
3100 p_term("t_AB", T_CAB)
3101 p_term("t_AF", T_CAF)
3102 p_term("t_AL", T_CAL)
3103 p_term("t_al", T_AL)
3104 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003105 p_term("t_BE", T_BE)
3106 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 p_term("t_cd", T_CD)
3108 p_term("t_ce", T_CE)
3109 p_term("t_cl", T_CL)
3110 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003111 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112 p_term("t_Co", T_CCO)
3113 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003114 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003116 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 p_term("t_da", T_DA)
3118 p_term("t_db", T_DB)
3119 p_term("t_DL", T_CDL)
3120 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003121 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003122 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003123 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003124 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 p_term("t_IE", T_CIE)
3126 p_term("t_IS", T_CIS)
3127 p_term("t_ke", T_KE)
3128 p_term("t_ks", T_KS)
3129 p_term("t_le", T_LE)
3130 p_term("t_mb", T_MB)
3131 p_term("t_md", T_MD)
3132 p_term("t_me", T_ME)
3133 p_term("t_mr", T_MR)
3134 p_term("t_ms", T_MS)
3135 p_term("t_nd", T_ND)
3136 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003137 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003138 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003139 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003140 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003141 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003142 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003143 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003144 p_term("t_RV", T_CRV)
3145 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003146 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003147 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003148 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003149 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003150 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003151 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003152 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003153 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003155 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003156 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_te", T_TE)
3158 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003159 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003160 p_term("t_ts", T_TS)
3161 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_ue", T_UE)
3163 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003164 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_vb", T_VB)
3166 p_term("t_ve", T_VE)
3167 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003168 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003169 p_term("t_vs", T_VS)
3170 p_term("t_WP", T_CWP)
3171 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003172 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003173 p_term("t_xs", T_XS)
3174 p_term("t_ZH", T_CZH)
3175 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003176 p_term("t_8f", T_8F)
3177 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003178
3179/* terminal key codes are not in here */
3180
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003181 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003182 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183};
3184
3185#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3186
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003189static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003191#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003192static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003193#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003194#ifdef FEAT_CMDL_COMPL
3195static char *(p_wop_values[]) = {"tagfile", NULL};
3196#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197#ifdef FEAT_WAK
3198static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3199#endif
3200static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3202static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003203static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003204#ifdef FEAT_BROWSE
3205static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3206#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003207static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003208static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaarf2732452018-06-03 14:47:35 +02003210static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003211static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3213#ifdef FEAT_FOLDING
3214static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003215# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003216 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003217# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003218 NULL};
3219static char *(p_fcl_values[]) = {"all", NULL};
3220#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003221#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003222static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003223#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003224#ifdef FEAT_SIGNS
3225static char *(p_scl_values[]) = {"yes", "no", "auto", NULL};
3226#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003227#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003228static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003229#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003231static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003232static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003233static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003234static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003235static char_u *option_expand(int opt_idx, char_u *val);
3236static void didset_options(void);
3237static void didset_options2(void);
3238static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003239#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003240static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003241#else
3242# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3243#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003244static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003245static 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);
3246static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003247#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003248static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003249#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003250#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003251static char *did_set_spell_option(int is_spellfile);
3252static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003253#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003254#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003255static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003256#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003257static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3258static 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 +01003259static void check_redraw(long_u flags);
3260static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003261static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003262static void showoptions(int all, int opt_flags);
3263static int optval_default(struct vimoption *, char_u *varp);
3264static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003265static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3267static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3268static int istermoption(struct vimoption *);
3269static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3270static char_u *get_varp(struct vimoption *);
3271static void option_value2string(struct vimoption *, int opt_flags);
3272static void check_winopt(winopt_T *wop);
3273static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003274#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003275static void langmap_init(void);
3276static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003277#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003278static void paste_option_changed(void);
3279static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003280#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003281static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3284static int check_opt_strings(char_u *val, char **values, int);
3285static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003286#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003287static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003288#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289
3290/*
3291 * Initialize the options, first part.
3292 *
3293 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003294 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295 */
3296 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003297set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298{
3299 char_u *p;
3300 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003301 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302
3303#ifdef FEAT_LANGMAP
3304 langmap_init();
3305#endif
3306
3307 /* Be Vi compatible by default */
3308 p_cp = TRUE;
3309
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003310 /* Use POSIX compatibility when $VIM_POSIX is set. */
3311 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003312 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003313 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003314 set_string_default("shm", (char_u *)"A");
3315 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003316
Bram Moolenaar071d4272004-06-13 20:20:40 +00003317 /*
3318 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003319 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003321 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003322#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003323 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar4f974752019-02-17 17:44:42 +01003324# ifdef MSWIN
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003325 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003326# endif
3327#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003328 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003329 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330
3331#ifdef FEAT_WILDIGN
3332 /*
3333 * Set the default for 'backupskip' to include environment variables for
3334 * temp files.
3335 */
3336 {
3337# ifdef UNIX
3338 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3339# else
3340 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3341# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003342 int len;
3343 garray_T ga;
3344 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003345
3346 ga_init2(&ga, 1, 100);
3347 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3348 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003349 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350# ifdef UNIX
3351 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003352# ifdef MACOS_X
3353 p = (char_u *)"/private/tmp";
3354# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003356# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003357 else
3358# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003359 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360 if (p != NULL && *p != NUL)
3361 {
3362 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003363 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003364 if (ga_grow(&ga, len) == OK)
3365 {
3366 if (ga.ga_len > 0)
3367 STRCAT(ga.ga_data, ",");
3368 STRCAT(ga.ga_data, p);
3369 add_pathsep(ga.ga_data);
3370 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371 ga.ga_len += len;
3372 }
3373 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003374 if (mustfree)
3375 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376 }
3377 if (ga.ga_data != NULL)
3378 {
3379 set_string_default("bsk", ga.ga_data);
3380 vim_free(ga.ga_data);
3381 }
3382 }
3383#endif
3384
3385 /*
3386 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3387 */
3388 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003389 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003390 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003391#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3392 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3393#endif
3394 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003396 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003397 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398#else
3399# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003400 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003401 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003403 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404# endif
3405#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003407 opt_idx = findoption((char_u *)"maxmem");
3408 if (opt_idx >= 0)
3409 {
3410#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003411 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3412 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003413#endif
3414 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3415 }
3416 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417 }
3418
Bram Moolenaar071d4272004-06-13 20:20:40 +00003419#ifdef FEAT_SEARCHPATH
3420 {
3421 char_u *cdpath;
3422 char_u *buf;
3423 int i;
3424 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003425 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426
3427 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003428 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429 if (cdpath != NULL)
3430 {
3431 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3432 if (buf != NULL)
3433 {
3434 buf[0] = ','; /* start with ",", current dir first */
3435 j = 1;
3436 for (i = 0; cdpath[i] != NUL; ++i)
3437 {
3438 if (vim_ispathlistsep(cdpath[i]))
3439 buf[j++] = ',';
3440 else
3441 {
3442 if (cdpath[i] == ' ' || cdpath[i] == ',')
3443 buf[j++] = '\\';
3444 buf[j++] = cdpath[i];
3445 }
3446 }
3447 buf[j] = NUL;
3448 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003449 if (opt_idx >= 0)
3450 {
3451 options[opt_idx].def_val[VI_DEFAULT] = buf;
3452 options[opt_idx].flags |= P_DEF_ALLOCED;
3453 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003454 else
3455 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003456 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003457 if (mustfree)
3458 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459 }
3460 }
3461#endif
3462
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003463#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464 /* Set print encoding on platforms that don't default to latin1 */
3465 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003466# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467 (char_u *)"cp1252"
3468# else
3469# ifdef VMS
3470 (char_u *)"dec-mcs"
3471# else
3472# ifdef EBCDIC
3473 (char_u *)"ebcdic-uk"
3474# else
3475# ifdef MAC
3476 (char_u *)"mac-roman"
3477# else /* HPUX */
3478 (char_u *)"hp-roman8"
3479# endif
3480# endif
3481# endif
3482# endif
3483 );
3484#endif
3485
3486#ifdef FEAT_POSTSCRIPT
3487 /* 'printexpr' must be allocated to be able to evaluate it. */
3488 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003489# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003490 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003491# else
3492# ifdef VMS
3493 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3494
3495# else
3496 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3497# endif
3498# endif
3499 );
3500#endif
3501
3502 /*
3503 * Set all the options (except the terminal options) to their default
3504 * value. Also set the global value for local options.
3505 */
3506 set_options_default(0);
3507
Bram Moolenaar07268702018-03-01 21:57:32 +01003508#ifdef CLEAN_RUNTIMEPATH
3509 if (clean_arg)
3510 {
3511 opt_idx = findoption((char_u *)"runtimepath");
3512 if (opt_idx >= 0)
3513 {
3514 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3515 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3516 }
3517 opt_idx = findoption((char_u *)"packpath");
3518 if (opt_idx >= 0)
3519 {
3520 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3521 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3522 }
3523 }
3524#endif
3525
Bram Moolenaar071d4272004-06-13 20:20:40 +00003526#ifdef FEAT_GUI
3527 if (found_reverse_arg)
3528 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3529#endif
3530
3531 curbuf->b_p_initialized = TRUE;
3532 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003533 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003534 check_buf_options(curbuf);
3535 check_win_options(curwin);
3536 check_options();
3537
3538 /* Must be before option_expand(), because that one needs vim_isIDc() */
3539 didset_options();
3540
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003541#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003542 /* Use the current chartab for the generic chartab. This is not in
3543 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003544 init_spell_chartab();
3545#endif
3546
Bram Moolenaar071d4272004-06-13 20:20:40 +00003547 /*
3548 * Expand environment variables and things like "~" for the defaults.
3549 * If option_expand() returns non-NULL the variable is expanded. This can
3550 * only happen for non-indirect options.
3551 * Also set the default to the expanded value, so ":set" does not list
3552 * them.
3553 * Don't set the P_ALLOCED flag, because we don't want to free the
3554 * default.
3555 */
3556 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3557 {
3558 if ((options[opt_idx].flags & P_GETTEXT)
3559 && options[opt_idx].var != NULL)
3560 p = (char_u *)_(*(char **)options[opt_idx].var);
3561 else
3562 p = option_expand(opt_idx, NULL);
3563 if (p != NULL && (p = vim_strsave(p)) != NULL)
3564 {
3565 *(char_u **)options[opt_idx].var = p;
3566 /* VIMEXP
3567 * Defaults for all expanded options are currently the same for Vi
3568 * and Vim. When this changes, add some code here! Also need to
3569 * split P_DEF_ALLOCED in two.
3570 */
3571 if (options[opt_idx].flags & P_DEF_ALLOCED)
3572 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3573 options[opt_idx].def_val[VI_DEFAULT] = p;
3574 options[opt_idx].flags |= P_DEF_ALLOCED;
3575 }
3576 }
3577
Bram Moolenaar071d4272004-06-13 20:20:40 +00003578 save_file_ff(curbuf); /* Buffer is unchanged */
3579
Bram Moolenaar071d4272004-06-13 20:20:40 +00003580#if defined(FEAT_ARABIC)
3581 /* Detect use of mlterm.
3582 * Mlterm is a terminal emulator akin to xterm that has some special
3583 * abilities (bidi namely).
3584 * NOTE: mlterm's author is being asked to 'set' a variable
3585 * instead of an environment variable due to inheritance.
3586 */
3587 if (mch_getenv((char_u *)"MLTERM") != NULL)
3588 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3589#endif
3590
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003591 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592
Bram Moolenaar4f974752019-02-17 17:44:42 +01003593# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003594 /*
3595 * If $LANG isn't set, try to get a good value for it. This makes the
3596 * right language be used automatically. Don't do this for English.
3597 */
3598 if (mch_getenv((char_u *)"LANG") == NULL)
3599 {
3600 char buf[20];
3601
3602 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3603 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3604 * only the first two. */
3605 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3606 (LPTSTR)buf, 20);
3607 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3608 {
3609 /* There are a few exceptions (probably more) */
3610 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3611 STRCPY(buf, "zh_TW");
3612 else if (STRNICMP(buf, "chs", 3) == 0
3613 || STRNICMP(buf, "zhc", 3) == 0)
3614 STRCPY(buf, "zh_CN");
3615 else if (STRNICMP(buf, "jp", 2) == 0)
3616 STRCPY(buf, "ja");
3617 else
3618 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003619 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003620 }
3621 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003622# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003623# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003624 /* Moved to os_mac_conv.c to avoid dependency problems. */
3625 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003626# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003627# endif
3628
3629 /* enc_locale() will try to find the encoding of the current locale. */
3630 p = enc_locale();
3631 if (p != NULL)
3632 {
3633 char_u *save_enc;
3634
3635 /* Try setting 'encoding' and check if the value is valid.
3636 * If not, go back to the default "latin1". */
3637 save_enc = p_enc;
3638 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003639 if (STRCMP(p_enc, "gb18030") == 0)
3640 {
3641 /* We don't support "gb18030", but "cp936" is a good substitute
3642 * for practical purposes, thus use that. It's not an alias to
3643 * still support conversion between gb18030 and utf-8. */
3644 p_enc = vim_strsave((char_u *)"cp936");
3645 vim_free(p);
3646 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003647 if (mb_init() == NULL)
3648 {
3649 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003650 if (opt_idx >= 0)
3651 {
3652 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3653 options[opt_idx].flags |= P_DEF_ALLOCED;
3654 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003655
Bram Moolenaard0573012017-10-28 21:11:06 +02003656#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003657 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003658 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003659 /* Adjust the default for 'isprint' and 'iskeyword' to match
3660 * latin1. Also set the defaults for when 'nocompatible' is
3661 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003662 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003663 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003664 set_string_option_direct((char_u *)"isk", -1,
3665 ISK_LATIN1, OPT_FREE, SID_NONE);
3666 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003667 if (opt_idx >= 0)
3668 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003669 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003670 if (opt_idx >= 0)
3671 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003672 (void)init_chartab();
3673 }
3674#endif
3675
Bram Moolenaar4f974752019-02-17 17:44:42 +01003676#if defined(MSWIN) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003677 /* Win32 console: When GetACP() returns a different value from
3678 * GetConsoleCP() set 'termencoding'. */
3679 if (GetACP() != GetConsoleCP())
3680 {
3681 char buf[50];
3682
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003683 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3684 * Use an alternative value. */
3685 if (GetConsoleCP() == 0)
3686 sprintf(buf, "cp%ld", (long)GetACP());
3687 else
3688 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003689 p_tenc = vim_strsave((char_u *)buf);
3690 if (p_tenc != NULL)
3691 {
3692 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003693 if (opt_idx >= 0)
3694 {
3695 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3696 options[opt_idx].flags |= P_DEF_ALLOCED;
3697 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698 convert_setup(&input_conv, p_tenc, p_enc);
3699 convert_setup(&output_conv, p_enc, p_tenc);
3700 }
3701 else
3702 p_tenc = empty_option;
3703 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003704#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003705#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003706 /* $HOME may have characters in active code page. */
3707 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003708#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709 }
3710 else
3711 {
3712 vim_free(p_enc);
3713 p_enc = save_enc;
3714 }
3715 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716
3717#ifdef FEAT_MULTI_LANG
3718 /* Set the default for 'helplang'. */
3719 set_helplang_default(get_mess_lang());
3720#endif
3721}
3722
3723/*
3724 * Set an option to its default value.
3725 * This does not take care of side effects!
3726 */
3727 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003728set_option_default(
3729 int opt_idx,
3730 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3731 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003732{
3733 char_u *varp; /* pointer to variable for current option */
3734 int dvi; /* index in def_val[] */
3735 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003736 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003737 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3738
3739 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3740 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003741 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003742 {
3743 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3744 if (flags & P_STRING)
3745 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003746 /* Use set_string_option_direct() for local options to handle
3747 * freeing and allocating the value. */
3748 if (options[opt_idx].indir != PV_NONE)
3749 set_string_option_direct(NULL, opt_idx,
3750 options[opt_idx].def_val[dvi], opt_flags, 0);
3751 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003753 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3754 free_string_option(*(char_u **)(varp));
3755 *(char_u **)varp = options[opt_idx].def_val[dvi];
3756 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757 }
3758 }
3759 else if (flags & P_NUM)
3760 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003761 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 win_comp_scroll(curwin);
3763 else
3764 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003765 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3766
3767 if ((long *)varp == &curwin->w_p_so
3768 || (long *)varp == &curwin->w_p_siso)
3769 // 'scrolloff' and 'sidescrolloff' local values have a
3770 // different default value than the global default.
3771 *(long *)varp = -1;
3772 else
3773 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003774 /* May also set global value for local option. */
3775 if (both)
3776 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003777 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003778 }
3779 }
3780 else /* P_BOOL */
3781 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003782 /* the cast to long is required for Manx C, long_i is needed for
3783 * MSVC */
3784 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003785#ifdef UNIX
3786 /* 'modeline' defaults to off for root */
3787 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3788 *(int *)varp = FALSE;
3789#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003790 /* May also set global value for local option. */
3791 if (both)
3792 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3793 *(int *)varp;
3794 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003795
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003796 /* The default value is not insecure. */
3797 flagsp = insecure_flag(opt_idx, opt_flags);
3798 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 }
3800
3801#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003802 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003803#endif
3804}
3805
3806/*
3807 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003808 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003809 */
3810 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003811set_options_default(
3812 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813{
3814 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003816 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817
3818 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003819 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003820 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003821 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003822# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003823 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003824 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003825# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003826 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003827 set_option_default(i, opt_flags, p_cp);
3828
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003830 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003832#ifdef FEAT_CINDENT
3833 parse_cino(curbuf);
3834#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835}
3836
3837/*
3838 * Set the Vi-default value of a string option.
3839 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003840 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003841 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003842 static void
3843set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844{
3845 char_u *p;
3846 int opt_idx;
3847
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003848 if (escape && vim_strchr(val, ' ') != NULL)
3849 p = vim_strsave_escaped(val, (char_u *)" ");
3850 else
3851 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003852 if (p != NULL) /* we don't want a NULL */
3853 {
3854 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003855 if (opt_idx >= 0)
3856 {
3857 if (options[opt_idx].flags & P_DEF_ALLOCED)
3858 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3859 options[opt_idx].def_val[VI_DEFAULT] = p;
3860 options[opt_idx].flags |= P_DEF_ALLOCED;
3861 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003862 }
3863}
3864
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003865 void
3866set_string_default(char *name, char_u *val)
3867{
3868 set_string_default_esc(name, val, FALSE);
3869}
3870
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871/*
3872 * Set the Vi-default value of a number option.
3873 * Used for 'lines' and 'columns'.
3874 */
3875 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003876set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003877{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003878 int opt_idx;
3879
3880 opt_idx = findoption((char_u *)name);
3881 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003882 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003883}
3884
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003885#if defined(EXITFREE) || defined(PROTO)
3886/*
3887 * Free all options.
3888 */
3889 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003890free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003891{
3892 int i;
3893
3894 for (i = 0; !istermoption(&options[i]); i++)
3895 {
3896 if (options[i].indir == PV_NONE)
3897 {
3898 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003899 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003900 free_string_option(*(char_u **)options[i].var);
3901 if (options[i].flags & P_DEF_ALLOCED)
3902 free_string_option(options[i].def_val[VI_DEFAULT]);
3903 }
3904 else if (options[i].var != VAR_WIN
3905 && (options[i].flags & P_STRING))
3906 /* buffer-local option: free global value */
3907 free_string_option(*(char_u **)options[i].var);
3908 }
3909}
3910#endif
3911
3912
Bram Moolenaar071d4272004-06-13 20:20:40 +00003913/*
3914 * Initialize the options, part two: After getting Rows and Columns and
3915 * setting 'term'.
3916 */
3917 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003918set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003919{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003920 int idx;
3921
Bram Moolenaar071d4272004-06-13 20:20:40 +00003922 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003923 * 'scroll' defaults to half the window height. The stored default is zero,
3924 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003925 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003926 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003927 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003928 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003929 comp_col();
3930
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003931 /*
3932 * 'window' is only for backwards compatibility with Vi.
3933 * Default is Rows - 1.
3934 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003935 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003936 p_window = Rows - 1;
3937 set_number_default("window", Rows - 1);
3938
Bram Moolenaarf740b292006-02-16 22:11:02 +00003939 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003940#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003941 /*
3942 * If 'background' wasn't set by the user, try guessing the value,
3943 * depending on the terminal name. Only need to check for terminals
3944 * with a dark background, that can handle color.
3945 */
3946 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003947 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3948 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003950 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003951 /* don't mark it as set, when starting the GUI it may be
3952 * changed again */
3953 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954 }
3955#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003956
3957#ifdef CURSOR_SHAPE
3958 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3959#endif
3960#ifdef FEAT_MOUSESHAPE
3961 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3962#endif
3963#ifdef FEAT_PRINTER
3964 (void)parse_printoptions(); /* parse 'printoptions' default value */
3965#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966}
3967
3968/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003969 * Return "dark" or "light" depending on the kind of terminal.
3970 * This is just guessing! Recognized are:
3971 * "linux" Linux console
3972 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003973 * "cygwin.*" Cygwin shell
3974 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003975 * We also check the COLORFGBG environment variable, which is set by
3976 * rxvt and derivatives. This variable contains either two or three
3977 * values separated by semicolons; we want the last value in either
3978 * case. If this value is 0-6 or 8, our background is dark.
3979 */
3980 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003981term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003982{
Bram Moolenaar4f974752019-02-17 17:44:42 +01003983#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003984 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003985 return (char_u *)"dark";
3986#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003987 char_u *p;
3988
Bram Moolenaarf740b292006-02-16 22:11:02 +00003989 if (STRCMP(T_NAME, "linux") == 0
3990 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003991 || STRNCMP(T_NAME, "cygwin", 6) == 0
3992 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003993 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3994 && (p = vim_strrchr(p, ';')) != NULL
3995 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3996 && p[2] == NUL))
3997 return (char_u *)"dark";
3998 return (char_u *)"light";
3999#endif
4000}
4001
4002/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003 * Initialize the options, part three: After reading the .vimrc
4004 */
4005 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004006set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004008#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009/*
4010 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4011 * This is done after other initializations, where 'shell' might have been
4012 * set, but only if they have not been set before.
4013 */
4014 char_u *p;
4015 int idx_srr;
4016 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004017# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004018 int idx_sp;
4019 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004020# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004021
4022 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004023 if (idx_srr < 0)
4024 do_srr = FALSE;
4025 else
4026 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004027# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004028 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004029 if (idx_sp < 0)
4030 do_sp = FALSE;
4031 else
4032 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004033# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004034 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004035 if (p != NULL)
4036 {
4037 /*
4038 * Default for p_sp is "| tee", for p_srr is ">".
4039 * For known shells it is changed here to include stderr.
4040 */
4041 if ( fnamecmp(p, "csh") == 0
4042 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004043# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 || fnamecmp(p, "csh.exe") == 0
4045 || fnamecmp(p, "tcsh.exe") == 0
4046# endif
4047 )
4048 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004049# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050 if (do_sp)
4051 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004052# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4058 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004059# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060 if (do_srr)
4061 {
4062 p_srr = (char_u *)">&";
4063 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4064 }
4065 }
4066 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004067 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 if ( fnamecmp(p, "sh") == 0
4069 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004070 || fnamecmp(p, "mksh") == 0
4071 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004073 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004075 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004076# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004077 || fnamecmp(p, "cmd") == 0
4078 || fnamecmp(p, "sh.exe") == 0
4079 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004080 || fnamecmp(p, "mksh.exe") == 0
4081 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004082 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004083 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 || fnamecmp(p, "bash.exe") == 0
4085 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004087 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 if (do_sp)
4091 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004092# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004093 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004094# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4098 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004099# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 if (do_srr)
4101 {
4102 p_srr = (char_u *)">%s 2>&1";
4103 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4104 }
4105 }
4106 vim_free(p);
4107 }
4108#endif
4109
Bram Moolenaar4f974752019-02-17 17:44:42 +01004110#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004112 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4113 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 * This is done after other initializations, where 'shell' might have been
4115 * set, but only if they have not been set before. Default for p_shcf is
4116 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004117 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004119 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 {
4121 int idx3;
4122
4123 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004124 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 {
4126 p_shcf = (char_u *)"-c";
4127 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4128 }
4129
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 /* Somehow Win32 requires the quotes around the redirection too */
4131 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004132 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004133 {
4134 p_sxq = (char_u *)"\"";
4135 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4136 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004138 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4139 {
4140 int idx3;
4141
4142 /*
4143 * cmd.exe on Windows will strip the first and last double quote given
4144 * on the command line, e.g. most of the time things like:
4145 * cmd /c "my path/to/echo" "my args to echo"
4146 * become:
4147 * my path/to/echo" "my args to echo
4148 * when executed.
4149 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004150 * To avoid this, set shellxquote to surround the command in
4151 * parenthesis. This appears to make most commands work, without
4152 * breaking commands that worked previously, such as
4153 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004154 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004155 idx3 = findoption((char_u *)"sxq");
4156 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4157 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004158 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004159 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4160 }
4161
Bram Moolenaara64ba222012-02-12 23:23:31 +01004162 idx3 = findoption((char_u *)"shcf");
4163 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4164 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004165 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004166 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4167 }
4168 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169#endif
4170
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004171 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004172 {
4173 int idx_ffs = findoption((char_u *)"ffs");
4174
4175 /* Apply the first entry of 'fileformats' to the initial buffer. */
4176 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4177 set_fileformat(default_fileformat(), OPT_LOCAL);
4178 }
4179
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180#ifdef FEAT_TITLE
4181 set_title_defaults();
4182#endif
4183}
4184
4185#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4186/*
4187 * When 'helplang' is still at its default value, set it to "lang".
4188 * Only the first two characters of "lang" are used.
4189 */
4190 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004191set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004192{
4193 int idx;
4194
4195 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4196 return;
4197 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004198 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199 {
4200 if (options[idx].flags & P_ALLOCED)
4201 free_string_option(p_hlg);
4202 p_hlg = vim_strsave(lang);
4203 if (p_hlg == NULL)
4204 p_hlg = empty_option;
4205 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004206 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004207 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004208 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4209 {
4210 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4211 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4212 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004213 // any C like setting, such as C.UTF-8, becomes "en"
4214 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4215 {
4216 p_hlg[0] = 'e';
4217 p_hlg[1] = 'n';
4218 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004220 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221 options[idx].flags |= P_ALLOCED;
4222 }
4223}
4224#endif
4225
4226#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004227 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004228gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229{
4230 if (gui_get_lightness(gui.back_pixel) < 127)
4231 return (char_u *)"dark";
4232 return (char_u *)"light";
4233}
4234
4235/*
4236 * Option initializations that can only be done after opening the GUI window.
4237 */
4238 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004239init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240{
4241 /* Set the 'background' option according to the lightness of the
4242 * background color, unless the user has set it already. */
4243 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4244 {
4245 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4246 highlight_changed();
4247 }
4248}
4249#endif
4250
4251#ifdef FEAT_TITLE
4252/*
4253 * 'title' and 'icon' only default to true if they have not been set or reset
4254 * in .vimrc and we can read the old value.
4255 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4256 * they can be reset. This reduces startup time when using X on a remote
4257 * machine.
4258 */
4259 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004260set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004261{
4262 int idx1;
4263 long val;
4264
4265 /*
4266 * If GUI is (going to be) used, we can always set the window title and
4267 * icon name. Saves a bit of time, because the X11 display server does
4268 * not need to be contacted.
4269 */
4270 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004271 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004272 {
4273#ifdef FEAT_GUI
4274 if (gui.starting || gui.in_use)
4275 val = TRUE;
4276 else
4277#endif
4278 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004279 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004280 p_title = val;
4281 }
4282 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004283 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004284 {
4285#ifdef FEAT_GUI
4286 if (gui.starting || gui.in_use)
4287 val = TRUE;
4288 else
4289#endif
4290 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004291 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004292 p_icon = val;
4293 }
4294}
4295#endif
4296
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004297#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004298 static void
4299trigger_optionsset_string(
4300 int opt_idx,
4301 int opt_flags,
4302 char_u *oldval,
4303 char_u *newval)
4304{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004305 // Don't do this recursively.
4306 if (oldval != NULL && newval != NULL
4307 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004308 {
4309 char_u buf_type[7];
4310
4311 sprintf((char *)buf_type, "%s",
4312 (opt_flags & OPT_LOCAL) ? "local" : "global");
4313 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4314 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4315 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4316 apply_autocmds(EVENT_OPTIONSET,
4317 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4318 reset_v_option_vars();
4319 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004320}
4321#endif
4322
Bram Moolenaar071d4272004-06-13 20:20:40 +00004323/*
4324 * Parse 'arg' for option settings.
4325 *
4326 * 'arg' may be IObuff, but only when no errors can be present and option
4327 * does not need to be expanded with option_expand().
4328 * "opt_flags":
4329 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004330 * OPT_GLOBAL for ":setglobal"
4331 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004332 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004333 * OPT_WINONLY to only set window-local options
4334 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004335 *
4336 * returns FAIL if an error is detected, OK otherwise
4337 */
4338 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004339do_set(
4340 char_u *arg, /* option string (may be written to!) */
4341 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004342{
4343 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004344 char *errmsg;
4345 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004346 char_u *startarg;
4347 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4348 int nextchar; /* next non-white char after option name */
4349 int afterchar; /* character just after option name */
4350 int len;
4351 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004352 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004353 int key;
4354 long_u flags; /* flags for current option */
4355 char_u *varp = NULL; /* pointer to variable for current option */
4356 int did_show = FALSE; /* already showed one value */
4357 int adding; /* "opt+=arg" */
4358 int prepending; /* "opt^=arg" */
4359 int removing; /* "opt-=arg" */
4360 int cp_val = 0;
4361 char_u key_name[2];
4362
4363 if (*arg == NUL)
4364 {
4365 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004366 did_show = TRUE;
4367 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004368 }
4369
4370 while (*arg != NUL) /* loop to process all options */
4371 {
4372 errmsg = NULL;
4373 startarg = arg; /* remember for error message */
4374
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004375 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4376 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004377 {
4378 /*
4379 * ":set all" show all options.
4380 * ":set all&" set all options to their default value.
4381 */
4382 arg += 3;
4383 if (*arg == '&')
4384 {
4385 ++arg;
4386 /* Only for :set command set global value of local options. */
4387 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004388 didset_options();
4389 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004390 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004391 }
4392 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004393 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004395 did_show = TRUE;
4396 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004397 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004398 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399 {
4400 showoptions(2, opt_flags);
4401 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004402 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403 arg += 7;
4404 }
4405 else
4406 {
4407 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004408 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004409 {
4410 prefix = 0;
4411 arg += 2;
4412 }
4413 else if (STRNCMP(arg, "inv", 3) == 0)
4414 {
4415 prefix = 2;
4416 arg += 3;
4417 }
4418
4419 /* find end of name */
4420 key = 0;
4421 if (*arg == '<')
4422 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004423 opt_idx = -1;
4424 /* look out for <t_>;> */
4425 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4426 len = 5;
4427 else
4428 {
4429 len = 1;
4430 while (arg[len] != NUL && arg[len] != '>')
4431 ++len;
4432 }
4433 if (arg[len] != '>')
4434 {
4435 errmsg = e_invarg;
4436 goto skip;
4437 }
4438 arg[len] = NUL; /* put NUL after name */
4439 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4440 opt_idx = findoption(arg + 1);
4441 arg[len++] = '>'; /* restore '>' */
4442 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004443 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004444 }
4445 else
4446 {
4447 len = 0;
4448 /*
4449 * The two characters after "t_" may not be alphanumeric.
4450 */
4451 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4452 len = 4;
4453 else
4454 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4455 ++len;
4456 nextchar = arg[len];
4457 arg[len] = NUL; /* put NUL after name */
4458 opt_idx = findoption(arg);
4459 arg[len] = nextchar; /* restore nextchar */
4460 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004461 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004462 }
4463
4464 /* remember character after option name */
4465 afterchar = arg[len];
4466
4467 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004468 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004469 ++len;
4470
4471 adding = FALSE;
4472 prepending = FALSE;
4473 removing = FALSE;
4474 if (arg[len] != NUL && arg[len + 1] == '=')
4475 {
4476 if (arg[len] == '+')
4477 {
4478 adding = TRUE; /* "+=" */
4479 ++len;
4480 }
4481 else if (arg[len] == '^')
4482 {
4483 prepending = TRUE; /* "^=" */
4484 ++len;
4485 }
4486 else if (arg[len] == '-')
4487 {
4488 removing = TRUE; /* "-=" */
4489 ++len;
4490 }
4491 }
4492 nextchar = arg[len];
4493
4494 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4495 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004496 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004497 goto skip;
4498 }
4499
4500 if (opt_idx >= 0)
4501 {
4502 if (options[opt_idx].var == NULL) /* hidden option: skip */
4503 {
4504 /* Only give an error message when requesting the value of
4505 * a hidden option, ignore setting it. */
4506 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4507 && (!(options[opt_idx].flags & P_BOOL)
4508 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004509 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004510 goto skip;
4511 }
4512
4513 flags = options[opt_idx].flags;
4514 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4515 }
4516 else
4517 {
4518 flags = P_STRING;
4519 if (key < 0)
4520 {
4521 key_name[0] = KEY2TERMCAP0(key);
4522 key_name[1] = KEY2TERMCAP1(key);
4523 }
4524 else
4525 {
4526 key_name[0] = KS_KEY;
4527 key_name[1] = (key & 0xff);
4528 }
4529 }
4530
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004531 /* Skip all options that are not window-local (used when showing
4532 * an already loaded buffer in a window). */
4533 if ((opt_flags & OPT_WINONLY)
4534 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4535 goto skip;
4536
Bram Moolenaara3227e22006-03-08 21:32:40 +00004537 /* Skip all options that are window-local (used for :vimgrep). */
4538 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4539 && options[opt_idx].var == VAR_WIN)
4540 goto skip;
4541
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004542 /* Disallow changing some options from modelines. */
4543 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004544 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004545 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004546 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004547 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004548 goto skip;
4549 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004550#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004551 /* In diff mode some options are overruled. This avoids that
4552 * 'foldmethod' becomes "marker" instead of "diff" and that
4553 * "wrap" gets set. */
4554 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004555 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004556 && (
4557#ifdef FEAT_FOLDING
4558 options[opt_idx].indir == PV_FDM ||
4559#endif
4560 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004561 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004562#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004563 }
4564
4565#ifdef HAVE_SANDBOX
4566 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004567 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004568 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004569 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 goto skip;
4571 }
4572#endif
4573
4574 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4575 {
4576 arg += len;
4577 cp_val = p_cp;
4578 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4579 {
4580 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4581 {
4582 cp_val = FALSE;
4583 arg += 3;
4584 }
4585 else /* "opt&vi": set to Vi default */
4586 {
4587 cp_val = TRUE;
4588 arg += 2;
4589 }
4590 }
4591 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004592 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004593 {
4594 errmsg = e_trailing;
4595 goto skip;
4596 }
4597 }
4598
4599 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004600 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4601 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004602 */
4603 if (nextchar == '?'
4604 || (prefix == 1
4605 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4606 && !(flags & P_BOOL)))
4607 {
4608 /*
4609 * print value
4610 */
4611 if (did_show)
4612 msg_putchar('\n'); /* cursor below last one */
4613 else
4614 {
4615 gotocmdline(TRUE); /* cursor at status line */
4616 did_show = TRUE; /* remember that we did a line */
4617 }
4618 if (opt_idx >= 0)
4619 {
4620 showoneopt(&options[opt_idx], opt_flags);
4621#ifdef FEAT_EVAL
4622 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004623 {
4624 /* Mention where the option was last set. */
4625 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004626 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004627 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004628 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004629 (int)options[opt_idx].indir & PV_MASK]);
4630 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004631 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004632 (int)options[opt_idx].indir & PV_MASK]);
4633 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004634#endif
4635 }
4636 else
4637 {
4638 char_u *p;
4639
4640 p = find_termcode(key_name);
4641 if (p == NULL)
4642 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004643 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004644 goto skip;
4645 }
4646 else
4647 (void)show_one_termcode(key_name, p, TRUE);
4648 }
4649 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004650 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004651 errmsg = e_trailing;
4652 }
4653 else
4654 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004655 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004656 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004657
Bram Moolenaar071d4272004-06-13 20:20:40 +00004658 if (flags & P_BOOL) /* boolean */
4659 {
4660 if (nextchar == '=' || nextchar == ':')
4661 {
4662 errmsg = e_invarg;
4663 goto skip;
4664 }
4665
4666 /*
4667 * ":set opt!": invert
4668 * ":set opt&": reset to default value
4669 * ":set opt<": reset to global value
4670 */
4671 if (nextchar == '!')
4672 value = *(int *)(varp) ^ 1;
4673 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004674 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004675 ((flags & P_VI_DEF) || cp_val)
4676 ? VI_DEFAULT : VIM_DEFAULT];
4677 else if (nextchar == '<')
4678 {
4679 /* For 'autoread' -1 means to use global value. */
4680 if ((int *)varp == &curbuf->b_p_ar
4681 && opt_flags == OPT_LOCAL)
4682 value = -1;
4683 else
4684 value = *(int *)get_varp_scope(&(options[opt_idx]),
4685 OPT_GLOBAL);
4686 }
4687 else
4688 {
4689 /*
4690 * ":set invopt": invert
4691 * ":set opt" or ":set noopt": set or reset
4692 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004693 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004694 {
4695 errmsg = e_trailing;
4696 goto skip;
4697 }
4698 if (prefix == 2) /* inv */
4699 value = *(int *)(varp) ^ 1;
4700 else
4701 value = prefix;
4702 }
4703
4704 errmsg = set_bool_option(opt_idx, varp, (int)value,
4705 opt_flags);
4706 }
4707 else /* numeric or string */
4708 {
4709 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4710 || prefix != 1)
4711 {
4712 errmsg = e_invarg;
4713 goto skip;
4714 }
4715
4716 if (flags & P_NUM) /* numeric */
4717 {
4718 /*
4719 * Different ways to set a number option:
4720 * & set to default value
4721 * < set to global value
4722 * <xx> accept special key codes for 'wildchar'
4723 * c accept any non-digit for 'wildchar'
4724 * [-]0-9 set number
4725 * other error
4726 */
4727 ++arg;
4728 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004729 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004730 ((flags & P_VI_DEF) || cp_val)
4731 ? VI_DEFAULT : VIM_DEFAULT];
4732 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004733 {
4734 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4735 * use the global value. */
4736 if ((long *)varp == &curbuf->b_p_ul
4737 && opt_flags == OPT_LOCAL)
4738 value = NO_LOCAL_UNDOLEVEL;
4739 else
4740 value = *(long *)get_varp_scope(
4741 &(options[opt_idx]), OPT_GLOBAL);
4742 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004743 else if (((long *)varp == &p_wc
4744 || (long *)varp == &p_wcm)
4745 && (*arg == '<'
4746 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004747 || (*arg != NUL
4748 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004749 && !VIM_ISDIGIT(*arg))))
4750 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004751 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004752 if (value == 0 && (long *)varp != &p_wcm)
4753 {
4754 errmsg = e_invarg;
4755 goto skip;
4756 }
4757 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004758 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4759 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004760 /* Allow negative (for 'undolevels'), octal and
4761 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004762 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4763 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004764 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004765 {
4766 errmsg = e_invarg;
4767 goto skip;
4768 }
4769 }
4770 else
4771 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004772 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004773 goto skip;
4774 }
4775
4776 if (adding)
4777 value = *(long *)varp + value;
4778 if (prepending)
4779 value = *(long *)varp * value;
4780 if (removing)
4781 value = *(long *)varp - value;
4782 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004783 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004784 }
4785 else if (opt_idx >= 0) /* string */
4786 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004787 char_u *save_arg = NULL;
4788 char_u *s = NULL;
4789 char_u *oldval = NULL; /* previous value if *varp */
4790 char_u *newval;
4791 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004792#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004793 char_u *saved_origval = NULL;
4794 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004795#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004796 unsigned newlen;
4797 int comma;
4798 int bs;
4799 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004800 was allocated */
4801
4802 /* When using ":set opt=val" for a global option
4803 * with a local value the local value will be
4804 * reset, use the global value here. */
4805 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004806 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004807 varp = options[opt_idx].var;
4808
4809 /* The old value is kept until we are sure that the
4810 * new value is valid. */
4811 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004812
4813 /* When setting the local value of a global
4814 * option, the old value may be the global value. */
4815 if (((int)options[opt_idx].indir & PV_BOTH)
4816 && (opt_flags & OPT_LOCAL))
4817 origval = *(char_u **)get_varp(
4818 &options[opt_idx]);
4819 else
4820 origval = oldval;
4821
Bram Moolenaar071d4272004-06-13 20:20:40 +00004822 if (nextchar == '&') /* set to default val */
4823 {
4824 newval = options[opt_idx].def_val[
4825 ((flags & P_VI_DEF) || cp_val)
4826 ? VI_DEFAULT : VIM_DEFAULT];
4827 if ((char_u **)varp == &p_bg)
4828 {
4829 /* guess the value of 'background' */
4830#ifdef FEAT_GUI
4831 if (gui.in_use)
4832 newval = gui_bg_default();
4833 else
4834#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004835 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004836 }
4837
4838 /* expand environment variables and ~ (since the
4839 * default value was already expanded, only
4840 * required when an environment variable was set
4841 * later */
4842 if (newval == NULL)
4843 newval = empty_option;
4844 else
4845 {
4846 s = option_expand(opt_idx, newval);
4847 if (s == NULL)
4848 s = newval;
4849 newval = vim_strsave(s);
4850 }
4851 new_value_alloced = TRUE;
4852 }
4853 else if (nextchar == '<') /* set to global val */
4854 {
4855 newval = vim_strsave(*(char_u **)get_varp_scope(
4856 &(options[opt_idx]), OPT_GLOBAL));
4857 new_value_alloced = TRUE;
4858 }
4859 else
4860 {
4861 ++arg; /* jump to after the '=' or ':' */
4862
4863 /*
4864 * Set 'keywordprg' to ":help" if an empty
4865 * value was passed to :set by the user.
4866 * Misuse errbuf[] for the resulting string.
4867 */
4868 if (varp == (char_u *)&p_kp
4869 && (*arg == NUL || *arg == ' '))
4870 {
4871 STRCPY(errbuf, ":help");
4872 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004873 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004874 }
4875 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004876 * Convert 'backspace' number to string, for
4877 * adding, prepending and removing string.
4878 */
4879 else if (varp == (char_u *)&p_bs
4880 && VIM_ISDIGIT(**(char_u **)varp))
4881 {
4882 i = getdigits((char_u **)varp);
4883 switch (i)
4884 {
4885 case 0:
4886 *(char_u **)varp = empty_option;
4887 break;
4888 case 1:
4889 *(char_u **)varp = vim_strsave(
4890 (char_u *)"indent,eol");
4891 break;
4892 case 2:
4893 *(char_u **)varp = vim_strsave(
4894 (char_u *)"indent,eol,start");
4895 break;
4896 }
4897 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004898 if (origval == oldval)
4899 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004900 oldval = *(char_u **)varp;
4901 }
4902 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004903 * Convert 'whichwrap' number to string, for
4904 * backwards compatibility with Vim 3.0.
4905 * Misuse errbuf[] for the resulting string.
4906 */
4907 else if (varp == (char_u *)&p_ww
4908 && VIM_ISDIGIT(*arg))
4909 {
4910 *errbuf = NUL;
4911 i = getdigits(&arg);
4912 if (i & 1)
4913 STRCAT(errbuf, "b,");
4914 if (i & 2)
4915 STRCAT(errbuf, "s,");
4916 if (i & 4)
4917 STRCAT(errbuf, "h,l,");
4918 if (i & 8)
4919 STRCAT(errbuf, "<,>,");
4920 if (i & 16)
4921 STRCAT(errbuf, "[,],");
4922 if (*errbuf != NUL) /* remove trailing , */
4923 errbuf[STRLEN(errbuf) - 1] = NUL;
4924 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004925 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004926 }
4927 /*
4928 * Remove '>' before 'dir' and 'bdir', for
4929 * backwards compatibility with version 3.0
4930 */
4931 else if ( *arg == '>'
4932 && (varp == (char_u *)&p_dir
4933 || varp == (char_u *)&p_bdir))
4934 {
4935 ++arg;
4936 }
4937
Bram Moolenaar071d4272004-06-13 20:20:40 +00004938 /*
4939 * Copy the new string into allocated memory.
4940 * Can't use set_string_option_direct(), because
4941 * we need to remove the backslashes.
4942 */
4943 /* get a bit too much */
4944 newlen = (unsigned)STRLEN(arg) + 1;
4945 if (adding || prepending || removing)
4946 newlen += (unsigned)STRLEN(origval) + 1;
4947 newval = alloc(newlen);
4948 if (newval == NULL) /* out of mem, don't change */
4949 break;
4950 s = newval;
4951
4952 /*
4953 * Copy the string, skip over escaped chars.
4954 * For MS-DOS and WIN32 backslashes before normal
4955 * file name characters are not removed, and keep
4956 * backslash at start, for "\\machine\path", but
4957 * do remove it for "\\\\machine\\path".
4958 * The reverse is found in ExpandOldSetting().
4959 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004960 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004961 {
4962 if (*arg == '\\' && arg[1] != NUL
4963#ifdef BACKSLASH_IN_FILENAME
4964 && !((flags & P_EXPAND)
4965 && vim_isfilec(arg[1])
4966 && (arg[1] != '\\'
4967 || (s == newval
4968 && arg[2] != '\\')))
4969#endif
4970 )
4971 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004972 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004973 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004974 {
4975 /* copy multibyte char */
4976 mch_memmove(s, arg, (size_t)i);
4977 arg += i;
4978 s += i;
4979 }
4980 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004981 *s++ = *arg++;
4982 }
4983 *s = NUL;
4984
4985 /*
4986 * Expand environment variables and ~.
4987 * Don't do it when adding without inserting a
4988 * comma.
4989 */
4990 if (!(adding || prepending || removing)
4991 || (flags & P_COMMA))
4992 {
4993 s = option_expand(opt_idx, newval);
4994 if (s != NULL)
4995 {
4996 vim_free(newval);
4997 newlen = (unsigned)STRLEN(s) + 1;
4998 if (adding || prepending || removing)
4999 newlen += (unsigned)STRLEN(origval) + 1;
5000 newval = alloc(newlen);
5001 if (newval == NULL)
5002 break;
5003 STRCPY(newval, s);
5004 }
5005 }
5006
5007 /* locate newval[] in origval[] when removing it
5008 * and when adding to avoid duplicates */
5009 i = 0; /* init for GCC */
5010 if (removing || (flags & P_NODUP))
5011 {
5012 i = (int)STRLEN(newval);
5013 bs = 0;
5014 for (s = origval; *s; ++s)
5015 {
5016 if ((!(flags & P_COMMA)
5017 || s == origval
5018 || (s[-1] == ',' && !(bs & 1)))
5019 && STRNCMP(s, newval, i) == 0
5020 && (!(flags & P_COMMA)
5021 || s[i] == ','
5022 || s[i] == NUL))
5023 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005024 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005025 * even number of backslashes or a single
5026 * backslash preceded by a comma before it
5027 * is recognized as a separator */
5028 if ((s > origval + 1
5029 && s[-1] == '\\'
5030 && s[-2] != ',')
5031 || (s == origval + 1
5032 && s[-1] == '\\'))
5033
Bram Moolenaar071d4272004-06-13 20:20:40 +00005034 ++bs;
5035 else
5036 bs = 0;
5037 }
5038
5039 /* do not add if already there */
5040 if ((adding || prepending) && *s)
5041 {
5042 prepending = FALSE;
5043 adding = FALSE;
5044 STRCPY(newval, origval);
5045 }
5046 }
5047
5048 /* concatenate the two strings; add a ',' if
5049 * needed */
5050 if (adding || prepending)
5051 {
5052 comma = ((flags & P_COMMA) && *origval != NUL
5053 && *newval != NUL);
5054 if (adding)
5055 {
5056 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005057 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005058 if (comma && i > 1
5059 && (flags & P_ONECOMMA) == P_ONECOMMA
5060 && origval[i - 1] == ','
5061 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005062 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005063 mch_memmove(newval + i + comma, newval,
5064 STRLEN(newval) + 1);
5065 mch_memmove(newval, origval, (size_t)i);
5066 }
5067 else
5068 {
5069 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005070 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005071 }
5072 if (comma)
5073 newval[i] = ',';
5074 }
5075
5076 /* Remove newval[] from origval[]. (Note: "i" has
5077 * been set above and is used here). */
5078 if (removing)
5079 {
5080 STRCPY(newval, origval);
5081 if (*s)
5082 {
5083 /* may need to remove a comma */
5084 if (flags & P_COMMA)
5085 {
5086 if (s == origval)
5087 {
5088 /* include comma after string */
5089 if (s[i] == ',')
5090 ++i;
5091 }
5092 else
5093 {
5094 /* include comma before string */
5095 --s;
5096 ++i;
5097 }
5098 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005099 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005100 }
5101 }
5102
5103 if (flags & P_FLAGLIST)
5104 {
5105 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005106 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005107 {
5108 /* if options have P_FLAGLIST and
5109 * P_ONECOMMA such as 'whichwrap' */
5110 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005111 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005112 if (*s != ',' && *(s + 1) == ','
5113 && vim_strchr(s + 2, *s) != NULL)
5114 {
5115 /* Remove the duplicated value and
5116 * the next comma. */
5117 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005118 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005119 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005120 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005121 else
5122 {
5123 if ((!(flags & P_COMMA) || *s != ',')
5124 && vim_strchr(s + 1, *s) != NULL)
5125 {
5126 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005127 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005128 }
5129 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005130 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005132 }
5133
5134 if (save_arg != NULL) /* number for 'whichwrap' */
5135 arg = save_arg;
5136 new_value_alloced = TRUE;
5137 }
5138
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005139 /*
5140 * Set the new value.
5141 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005142 *(char_u **)(varp) = newval;
5143
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005144#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005145 if (!starting
5146# ifdef FEAT_CRYPT
5147 && options[opt_idx].indir != PV_KEY
5148# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005149 && origval != NULL && newval != NULL)
5150 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005151 /* origval may be freed by
5152 * did_set_string_option(), make a copy. */
5153 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005154 /* newval (and varp) may become invalid if the
5155 * buffer is closed by autocommands. */
5156 saved_newval = vim_strsave(newval);
5157 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005158#endif
5159
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005160 {
5161 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005162 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005163
5164 // When an option is set in the sandbox, from a
5165 // modeline or in secure mode, then deal with side
5166 // effects in secure mode. Also when the value was
5167 // set with the P_INSECURE flag and is not
5168 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005169 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005170#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005171 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005172#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005173 || (!value_is_replaced && (*p & P_INSECURE)))
5174 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005175
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005176 // Handle side effects, and set the global value
5177 // for ":set" on local options. Note: when setting
5178 // 'syntax' or 'filetype' autocommands may be
5179 // triggered that can cause havoc.
5180 errmsg = did_set_string_option(
5181 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005182 new_value_alloced, oldval, errbuf,
5183 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005184
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005185 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005186 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005187
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005188#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005189 if (errmsg == NULL)
5190 trigger_optionsset_string(opt_idx, opt_flags,
5191 saved_origval, saved_newval);
5192 vim_free(saved_origval);
5193 vim_free(saved_newval);
5194#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005195 /* If error detected, print the error message. */
5196 if (errmsg != NULL)
5197 goto skip;
5198 }
5199 else /* key code option */
5200 {
5201 char_u *p;
5202
5203 if (nextchar == '&')
5204 {
5205 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005206 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005207 }
5208 else
5209 {
5210 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005211 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005212 if (*p == '\\' && p[1] != NUL)
5213 ++p;
5214 nextchar = *p;
5215 *p = NUL;
5216 add_termcode(key_name, arg, FALSE);
5217 *p = nextchar;
5218 }
5219 if (full_screen)
5220 ttest(FALSE);
5221 redraw_all_later(CLEAR);
5222 }
5223 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005224
Bram Moolenaar071d4272004-06-13 20:20:40 +00005225 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005226 did_set_option(
5227 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005228 }
5229
5230skip:
5231 /*
5232 * Advance to next argument.
5233 * - skip until a blank found, taking care of backslashes
5234 * - skip blanks
5235 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5236 */
5237 for (i = 0; i < 2 ; ++i)
5238 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005239 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005240 if (*arg++ == '\\' && *arg != NUL)
5241 ++arg;
5242 arg = skipwhite(arg);
5243 if (*arg != '=')
5244 break;
5245 }
5246 }
5247
5248 if (errmsg != NULL)
5249 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005250 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005251 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005252 if (i + (arg - startarg) < IOSIZE)
5253 {
5254 /* append the argument with the error */
5255 STRCAT(IObuff, ": ");
5256 mch_memmove(IObuff + i, startarg, (arg - startarg));
5257 IObuff[i + (arg - startarg)] = NUL;
5258 }
5259 /* make sure all characters are printable */
5260 trans_characters(IObuff, IOSIZE);
5261
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005262 ++no_wait_return; // wait_return done later
5263 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005264 --no_wait_return;
5265
5266 return FAIL;
5267 }
5268
5269 arg = skipwhite(arg);
5270 }
5271
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005272theend:
5273 if (silent_mode && did_show)
5274 {
5275 /* After displaying option values in silent mode. */
5276 silent_mode = FALSE;
5277 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5278 msg_putchar('\n');
5279 cursor_on(); /* msg_start() switches it off */
5280 out_flush();
5281 silent_mode = TRUE;
5282 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5283 }
5284
Bram Moolenaar071d4272004-06-13 20:20:40 +00005285 return OK;
5286}
5287
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005288/*
5289 * Call this when an option has been given a new value through a user command.
5290 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5291 */
5292 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005293did_set_option(
5294 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005295 int opt_flags, // possibly with OPT_MODELINE
5296 int new_value, // value was replaced completely
5297 int value_checked) // value was checked to be safe, no need to set the
5298 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005299{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005300 long_u *p;
5301
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005302 options[opt_idx].flags |= P_WAS_SET;
5303
5304 /* When an option is set in the sandbox, from a modeline or in secure mode
5305 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005306 * flag. */
5307 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005308 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005309#ifdef HAVE_SANDBOX
5310 || sandbox != 0
5311#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005312 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005313 *p = *p | P_INSECURE;
5314 else if (new_value)
5315 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005316}
5317
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005318 static char *
5319illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320{
5321 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005322 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005323 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005324 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325 return errbuf;
5326}
5327
5328/*
5329 * Convert a key name or string into a key value.
5330 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005331 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005332 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005333 int
5334string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335{
5336 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005337 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005338 if (*arg == '^')
5339 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005340 if (multi_byte)
5341 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005342 return *arg;
5343}
5344
5345#ifdef FEAT_CMDWIN
5346/*
5347 * Check value of 'cedit' and set cedit_key.
5348 * Returns NULL if value is OK, error message otherwise.
5349 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005350 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005351check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352{
5353 int n;
5354
5355 if (*p_cedit == NUL)
5356 cedit_key = -1;
5357 else
5358 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005359 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360 if (vim_isprintc(n))
5361 return e_invarg;
5362 cedit_key = n;
5363 }
5364 return NULL;
5365}
5366#endif
5367
5368#ifdef FEAT_TITLE
5369/*
5370 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5371 * maketitle() to create and display it.
5372 * When switching the title or icon off, call mch_restore_title() to get
5373 * the old value back.
5374 */
5375 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005376did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005377{
5378 if (starting != NO_SCREEN
5379#ifdef FEAT_GUI
5380 && !gui.starting
5381#endif
5382 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005383 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005384}
5385#endif
5386
5387/*
5388 * set_options_bin - called when 'bin' changes value.
5389 */
5390 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005391set_options_bin(
5392 int oldval,
5393 int newval,
5394 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395{
5396 /*
5397 * The option values that are changed when 'bin' changes are
5398 * copied when 'bin is set and restored when 'bin' is reset.
5399 */
5400 if (newval)
5401 {
5402 if (!oldval) /* switched on */
5403 {
5404 if (!(opt_flags & OPT_GLOBAL))
5405 {
5406 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5407 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5408 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5409 curbuf->b_p_et_nobin = curbuf->b_p_et;
5410 }
5411 if (!(opt_flags & OPT_LOCAL))
5412 {
5413 p_tw_nobin = p_tw;
5414 p_wm_nobin = p_wm;
5415 p_ml_nobin = p_ml;
5416 p_et_nobin = p_et;
5417 }
5418 }
5419
5420 if (!(opt_flags & OPT_GLOBAL))
5421 {
5422 curbuf->b_p_tw = 0; /* no automatic line wrap */
5423 curbuf->b_p_wm = 0; /* no automatic line wrap */
5424 curbuf->b_p_ml = 0; /* no modelines */
5425 curbuf->b_p_et = 0; /* no expandtab */
5426 }
5427 if (!(opt_flags & OPT_LOCAL))
5428 {
5429 p_tw = 0;
5430 p_wm = 0;
5431 p_ml = FALSE;
5432 p_et = FALSE;
5433 p_bin = TRUE; /* needed when called for the "-b" argument */
5434 }
5435 }
5436 else if (oldval) /* switched off */
5437 {
5438 if (!(opt_flags & OPT_GLOBAL))
5439 {
5440 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5441 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5442 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5443 curbuf->b_p_et = curbuf->b_p_et_nobin;
5444 }
5445 if (!(opt_flags & OPT_LOCAL))
5446 {
5447 p_tw = p_tw_nobin;
5448 p_wm = p_wm_nobin;
5449 p_ml = p_ml_nobin;
5450 p_et = p_et_nobin;
5451 }
5452 }
5453}
5454
5455#ifdef FEAT_VIMINFO
5456/*
5457 * Find the parameter represented by the given character (eg ', :, ", or /),
5458 * and return its associated value in the 'viminfo' string.
5459 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005460 * If the parameter is not specified in the string or there is no following
5461 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462 */
5463 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005464get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005465{
5466 char_u *p;
5467
5468 p = find_viminfo_parameter(type);
5469 if (p != NULL && VIM_ISDIGIT(*p))
5470 return atoi((char *)p);
5471 return -1;
5472}
5473
5474/*
5475 * Find the parameter represented by the given character (eg ''', ':', '"', or
5476 * '/') in the 'viminfo' option and return a pointer to the string after it.
5477 * Return NULL if the parameter is not specified in the string.
5478 */
5479 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005480find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005481{
5482 char_u *p;
5483
5484 for (p = p_viminfo; *p; ++p)
5485 {
5486 if (*p == type)
5487 return p + 1;
5488 if (*p == 'n') /* 'n' is always the last one */
5489 break;
5490 p = vim_strchr(p, ','); /* skip until next ',' */
5491 if (p == NULL) /* hit the end without finding parameter */
5492 break;
5493 }
5494 return NULL;
5495}
5496#endif
5497
5498/*
5499 * Expand environment variables for some string options.
5500 * These string options cannot be indirect!
5501 * If "val" is NULL expand the current value of the option.
5502 * Return pointer to NameBuff, or NULL when not expanded.
5503 */
5504 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005505option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005506{
5507 /* if option doesn't need expansion nothing to do */
5508 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5509 return NULL;
5510
5511 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5512 * expand_env() would truncate the string. */
5513 if (val != NULL && STRLEN(val) > MAXPATHL)
5514 return NULL;
5515
5516 if (val == NULL)
5517 val = *(char_u **)options[opt_idx].var;
5518
5519 /*
5520 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5521 * Escape spaces when expanding 'tags', they are used to separate file
5522 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005523 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005524 */
5525 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005526 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005527#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005528 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5529#endif
5530 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005531 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5532 return NULL;
5533
5534 return NameBuff;
5535}
5536
5537/*
5538 * After setting various option values: recompute variables that depend on
5539 * option values.
5540 */
5541 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005542didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005543{
5544 /* initialize the table for 'iskeyword' et.al. */
5545 (void)init_chartab();
5546
5547 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5548 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005549 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005550#ifdef FEAT_SESSION
5551 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5552 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5553#endif
5554#ifdef FEAT_FOLDING
5555 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5556#endif
5557 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005558 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005559 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005560#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5561 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5562#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005563#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005564 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005565 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005566 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005567 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005568#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005569#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005570 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5571#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005572#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5574#endif
5575#ifdef FEAT_CMDWIN
5576 /* set cedit_key */
5577 (void)check_cedit();
5578#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005579#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005580 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005581#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005582#ifdef FEAT_LINEBREAK
5583 /* initialize the table for 'breakat'. */
5584 fill_breakat_flags();
5585#endif
5586
5587}
5588
5589/*
5590 * More side effects of setting options.
5591 */
5592 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005593didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005594{
5595 /* Initialize the highlight_attr[] table. */
5596 (void)highlight_changed();
5597
5598 /* Parse default for 'wildmode' */
5599 check_opt_wim();
5600
5601 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005602 /* Parse default for 'fillchars'. */
5603 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005604
5605#ifdef FEAT_CLIPBOARD
5606 /* Parse default for 'clipboard' */
5607 (void)check_clipboard_option();
5608#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005609#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005610 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005611 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005612 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005613 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5614#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615}
5616
5617/*
5618 * Check for string options that are NULL (normally only termcap options).
5619 */
5620 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005621check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005622{
5623 int opt_idx;
5624
5625 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5626 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5627 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5628}
5629
5630/*
5631 * Check string options in a buffer for NULL value.
5632 */
5633 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005634check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005635{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005636 check_string_option(&buf->b_p_bh);
5637 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639 check_string_option(&buf->b_p_ff);
5640#ifdef FEAT_FIND_ID
5641 check_string_option(&buf->b_p_def);
5642 check_string_option(&buf->b_p_inc);
5643# ifdef FEAT_EVAL
5644 check_string_option(&buf->b_p_inex);
5645# endif
5646#endif
5647#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5648 check_string_option(&buf->b_p_inde);
5649 check_string_option(&buf->b_p_indk);
5650#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005651#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5652 check_string_option(&buf->b_p_bexpr);
5653#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005654#if defined(FEAT_CRYPT)
5655 check_string_option(&buf->b_p_cm);
5656#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005657 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005658#if defined(FEAT_EVAL)
5659 check_string_option(&buf->b_p_fex);
5660#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005661#ifdef FEAT_CRYPT
5662 check_string_option(&buf->b_p_key);
5663#endif
5664 check_string_option(&buf->b_p_kp);
5665 check_string_option(&buf->b_p_mps);
5666 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005667 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005668 check_string_option(&buf->b_p_isk);
5669#ifdef FEAT_COMMENTS
5670 check_string_option(&buf->b_p_com);
5671#endif
5672#ifdef FEAT_FOLDING
5673 check_string_option(&buf->b_p_cms);
5674#endif
5675 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005676#ifdef FEAT_TEXTOBJ
5677 check_string_option(&buf->b_p_qe);
5678#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005679#ifdef FEAT_SYN_HL
5680 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005681 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005682#endif
5683#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005684 check_string_option(&buf->b_s.b_p_spc);
5685 check_string_option(&buf->b_s.b_p_spf);
5686 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005687#endif
5688#ifdef FEAT_SEARCHPATH
5689 check_string_option(&buf->b_p_sua);
5690#endif
5691#ifdef FEAT_CINDENT
5692 check_string_option(&buf->b_p_cink);
5693 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005694 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005695#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5698 check_string_option(&buf->b_p_cinw);
5699#endif
5700#ifdef FEAT_INS_EXPAND
5701 check_string_option(&buf->b_p_cpt);
5702#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005703#ifdef FEAT_COMPL_FUNC
5704 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005705 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005706#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005707#ifdef FEAT_EVAL
5708 check_string_option(&buf->b_p_tfu);
5709#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005710#ifdef FEAT_KEYMAP
5711 check_string_option(&buf->b_p_keymap);
5712#endif
5713#ifdef FEAT_QUICKFIX
5714 check_string_option(&buf->b_p_gp);
5715 check_string_option(&buf->b_p_mp);
5716 check_string_option(&buf->b_p_efm);
5717#endif
5718 check_string_option(&buf->b_p_ep);
5719 check_string_option(&buf->b_p_path);
5720 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005721 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005722#ifdef FEAT_INS_EXPAND
5723 check_string_option(&buf->b_p_dict);
5724 check_string_option(&buf->b_p_tsr);
5725#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005726#ifdef FEAT_LISP
5727 check_string_option(&buf->b_p_lw);
5728#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005729 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005730 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005731#ifdef FEAT_VARTABS
5732 check_string_option(&buf->b_p_vsts);
5733 check_string_option(&buf->b_p_vts);
5734#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735}
5736
5737/*
5738 * Free the string allocated for an option.
5739 * Checks for the string being empty_option. This may happen if we're out of
5740 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5741 * check_options().
5742 * Does NOT check for P_ALLOCED flag!
5743 */
5744 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005745free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746{
5747 if (p != empty_option)
5748 vim_free(p);
5749}
5750
5751 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005752clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753{
5754 if (*pp != empty_option)
5755 vim_free(*pp);
5756 *pp = empty_option;
5757}
5758
5759 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005760check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005761{
5762 if (*pp == NULL)
5763 *pp = empty_option;
5764}
5765
5766/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005767 * Return the option index found by a pointer into term_strings[].
5768 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005770 int
5771get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005772{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005773 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005774
5775 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5776 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005777 return opt_idx;
5778 return -1; // cannot happen: didn't find it!
5779}
5780
5781/*
5782 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5783 * Return the option index or -1 if not found.
5784 */
5785 int
5786set_term_option_alloced(char_u **p)
5787{
5788 int opt_idx = get_term_opt_idx(p);
5789
5790 if (opt_idx >= 0)
5791 options[opt_idx].flags |= P_ALLOCED;
5792 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005793}
5794
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005795#if defined(FEAT_EVAL) || defined(PROTO)
5796/*
5797 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5798 * Return FALSE when it wasn't.
5799 * Return -1 for an unknown option.
5800 */
5801 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005802was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005803{
5804 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005805 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005806
5807 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005808 {
5809 flagp = insecure_flag(idx, opt_flags);
5810 return (*flagp & P_INSECURE) != 0;
5811 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005812 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005813 return -1;
5814}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005815
5816/*
5817 * Get a pointer to the flags used for the P_INSECURE flag of option
5818 * "opt_idx". For some local options a local flags field is used.
5819 */
5820 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005821insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005822{
5823 if (opt_flags & OPT_LOCAL)
5824 switch ((int)options[opt_idx].indir)
5825 {
5826#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005827 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005828#endif
5829#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005830# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005831 case PV_FDE: return &curwin->w_p_fde_flags;
5832 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005833# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005834# ifdef FEAT_BEVAL
5835 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5836# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005837# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005838 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005839# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005840 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005841# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005842 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005843# endif
5844#endif
5845 }
5846
5847 /* Nothing special, return global flags field. */
5848 return &options[opt_idx].flags;
5849}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005850#endif
5851
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005852#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005853/*
5854 * Redraw the window title and/or tab page text later.
5855 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005856static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005857{
5858 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005859 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005860}
5861#endif
5862
Bram Moolenaar071d4272004-06-13 20:20:40 +00005863/*
5864 * Set a string option to a new value (without checking the effect).
5865 * The string is copied into allocated memory.
5866 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005867 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5868 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5869 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005870 */
5871 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005872set_string_option_direct(
5873 char_u *name,
5874 int opt_idx,
5875 char_u *val,
5876 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5877 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005878{
5879 char_u *s;
5880 char_u **varp;
5881 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005882 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005883
Bram Moolenaar89d40322006-08-29 15:30:07 +00005884 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005886 idx = findoption(name);
5887 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005888 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005889 semsg(_(e_intern2), "set_string_option_direct()");
5890 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005891 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005892 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 }
5894
Bram Moolenaar89d40322006-08-29 15:30:07 +00005895 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005896 return;
5897
5898 s = vim_strsave(val);
5899 if (s != NULL)
5900 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005901 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005902 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 free_string_option(*varp);
5905 *varp = s;
5906
5907 /* For buffer/window local option may also set the global value. */
5908 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005909 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005910
Bram Moolenaar89d40322006-08-29 15:30:07 +00005911 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912
5913 /* When setting both values of a global option with a local value,
5914 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005915 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005916 {
5917 free_string_option(*varp);
5918 *varp = empty_option;
5919 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005920# ifdef FEAT_EVAL
5921 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005922 {
5923 sctx_T script_ctx;
5924
5925 if (set_sid == 0)
5926 script_ctx = current_sctx;
5927 else
5928 {
5929 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005930 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005931 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005932 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005933 }
5934 set_option_sctx_idx(idx, opt_flags, script_ctx);
5935 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005936# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937 }
5938}
5939
5940/*
5941 * Set global value for string option when it's a local option.
5942 */
5943 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005944set_string_option_global(
5945 int opt_idx, /* option index */
5946 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005947{
5948 char_u **p, *s;
5949
5950 /* the global value is always allocated */
5951 if (options[opt_idx].var == VAR_WIN)
5952 p = (char_u **)GLOBAL_WO(varp);
5953 else
5954 p = (char_u **)options[opt_idx].var;
5955 if (options[opt_idx].indir != PV_NONE
5956 && p != varp
5957 && (s = vim_strsave(*varp)) != NULL)
5958 {
5959 free_string_option(*p);
5960 *p = s;
5961 }
5962}
5963
5964/*
5965 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005966 *
5967 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005968 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005969 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005970set_string_option(
5971 int opt_idx,
5972 char_u *value,
5973 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005974{
5975 char_u *s;
5976 char_u **varp;
5977 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005978#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005979 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005980 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005981#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005982 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005983 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984
5985 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005986 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005987
5988 s = vim_strsave(value);
5989 if (s != NULL)
5990 {
5991 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5992 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005993 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005994 ? OPT_GLOBAL : OPT_LOCAL)
5995 : opt_flags);
5996 oldval = *varp;
5997 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02005998
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005999#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006000 if (!starting
6001# ifdef FEAT_CRYPT
6002 && options[opt_idx].indir != PV_KEY
6003# endif
6004 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006005 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006006 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006007 saved_newval = vim_strsave(s);
6008 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006009#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006010 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006011 opt_flags, &value_checked)) == NULL)
6012 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006013
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006014#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006015 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006016 if (r == NULL)
6017 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006018 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006019 vim_free(saved_oldval);
6020 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006021#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006022 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006023 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006024}
6025
6026/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006027 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6028 * characters or characters in "allowed".
6029 */
6030 static int
6031valid_name(char_u *val, char *allowed)
6032{
6033 char_u *s;
6034
6035 for (s = val; *s != NUL; ++s)
6036 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6037 return FALSE;
6038 return TRUE;
6039}
6040
6041/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006042 * Return TRUE if "val" is a valid 'filetype' name.
6043 * Also used for 'syntax' and 'keymap'.
6044 */
6045 static int
6046valid_filetype(char_u *val)
6047{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006048 return valid_name(val, ".-_");
6049}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006050
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006051#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006052/*
6053 * Return TRUE if "val" is a valid 'spellang' value.
6054 */
6055 int
6056valid_spellang(char_u *val)
6057{
6058 return valid_name(val, ".-_,");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006059}
6060
6061/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006062 * Return TRUE if "val" is a valid 'spellfile' value.
6063 */
6064 static int
6065valid_spellfile(char_u *val)
6066{
6067 char_u *s;
6068
6069 for (s = val; *s != NUL; ++s)
6070 if (!vim_isfilec(*s) && *s != ',')
6071 return FALSE;
6072 return TRUE;
6073}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006074#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006075
6076/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006077 * Handle string options that need some action to perform when changed.
6078 * Returns NULL for success, or an error message for an error.
6079 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006080 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006081did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006082 int opt_idx, // index in options[] table
6083 char_u **varp, // pointer to the option variable
6084 int new_value_alloced, // new value was allocated
6085 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006086 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006087 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6088 int *value_checked) // value was checked to be save, no
6089 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006091 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006092 char_u *s, *p;
6093 int did_chartab = FALSE;
6094 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006095 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006096#ifdef FEAT_GUI
6097 /* set when changing an option that only requires a redraw in the GUI */
6098 int redraw_gui_only = FALSE;
6099#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006100 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006101#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6102 int did_swaptcap = FALSE;
6103#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006104
6105 /* Get the global option to compare with, otherwise we would have to check
6106 * two values for all local options. */
6107 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6108
6109 /* Disallow changing some options from secure mode */
6110 if ((secure
6111#ifdef HAVE_SANDBOX
6112 || sandbox != 0
6113#endif
6114 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006115 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116
Bram Moolenaar916a8182018-11-25 02:18:29 +01006117 // Check for a "normal" directory or file name in some options. Disallow a
6118 // path separator (slash and/or backslash), wildcards and characters that
6119 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006120 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006121 && vim_strpbrk(*varp, (char_u *)(secure
6122 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006123 || ((options[opt_idx].flags & P_NDNAME)
6124 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006125 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006126
Bram Moolenaar071d4272004-06-13 20:20:40 +00006127 /* 'term' */
6128 else if (varp == &T_NAME)
6129 {
6130 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006131 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006132#ifdef FEAT_GUI
6133 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006134 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006135 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006136 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137#endif
6138 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006139 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006140 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006141 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142 /* Screen colors may have changed. */
6143 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006144
6145 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6146 * P_ALLOCED flag on 'term'. */
6147 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006148 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006149 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006150 }
6151
6152 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006153 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006154 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006155 char_u *bkc = p_bkc;
6156 unsigned int *flags = &bkc_flags;
6157
6158 if (opt_flags & OPT_LOCAL)
6159 {
6160 bkc = curbuf->b_p_bkc;
6161 flags = &curbuf->b_bkc_flags;
6162 }
6163
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006164 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6165 /* make the local value empty: use the global value */
6166 *flags = 0;
6167 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006168 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006169 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6170 errmsg = e_invarg;
6171 if ((((int)*flags & BKC_AUTO) != 0)
6172 + (((int)*flags & BKC_YES) != 0)
6173 + (((int)*flags & BKC_NO) != 0) != 1)
6174 {
6175 /* Must have exactly one of "auto", "yes" and "no". */
6176 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6177 errmsg = e_invarg;
6178 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179 }
6180 }
6181
6182 /* 'backupext' and 'patchmode' */
6183 else if (varp == &p_bex || varp == &p_pm)
6184 {
6185 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6186 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006187 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006188 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006189#ifdef FEAT_LINEBREAK
6190 /* 'breakindentopt' */
6191 else if (varp == &curwin->w_p_briopt)
6192 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006193 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006194 errmsg = e_invarg;
6195 }
6196#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006197
6198 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006199 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006200 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006201 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 */
6203 else if ( varp == &p_isi
6204 || varp == &(curbuf->b_p_isk)
6205 || varp == &p_isp
6206 || varp == &p_isf)
6207 {
6208 if (init_chartab() == FAIL)
6209 {
6210 did_chartab = TRUE; /* need to restore it below */
6211 errmsg = e_invarg; /* error in value */
6212 }
6213 }
6214
6215 /* 'helpfile' */
6216 else if (varp == &p_hf)
6217 {
6218 /* May compute new values for $VIM and $VIMRUNTIME */
6219 if (didset_vim)
6220 {
6221 vim_setenv((char_u *)"VIM", (char_u *)"");
6222 didset_vim = FALSE;
6223 }
6224 if (didset_vimruntime)
6225 {
6226 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6227 didset_vimruntime = FALSE;
6228 }
6229 }
6230
Bram Moolenaar1a384422010-07-14 19:53:30 +02006231#ifdef FEAT_SYN_HL
6232 /* 'colorcolumn' */
6233 else if (varp == &curwin->w_p_cc)
6234 errmsg = check_colorcolumn(curwin);
6235#endif
6236
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237#ifdef FEAT_MULTI_LANG
6238 /* 'helplang' */
6239 else if (varp == &p_hlg)
6240 {
6241 /* Check for "", "ab", "ab,cd", etc. */
6242 for (s = p_hlg; *s != NUL; s += 3)
6243 {
6244 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6245 {
6246 errmsg = e_invarg;
6247 break;
6248 }
6249 if (s[2] == NUL)
6250 break;
6251 }
6252 }
6253#endif
6254
6255 /* 'highlight' */
6256 else if (varp == &p_hl)
6257 {
6258 if (highlight_changed() == FAIL)
6259 errmsg = e_invarg; /* invalid flags */
6260 }
6261
6262 /* 'nrformats' */
6263 else if (gvarp == &p_nf)
6264 {
6265 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6266 errmsg = e_invarg;
6267 }
6268
6269#ifdef FEAT_SESSION
6270 /* 'sessionoptions' */
6271 else if (varp == &p_ssop)
6272 {
6273 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6274 errmsg = e_invarg;
6275 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6276 {
6277 /* Don't allow both "sesdir" and "curdir". */
6278 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6279 errmsg = e_invarg;
6280 }
6281 }
6282 /* 'viewoptions' */
6283 else if (varp == &p_vop)
6284 {
6285 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6286 errmsg = e_invarg;
6287 }
6288#endif
6289
6290 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006291 else if (varp == &p_sbo)
6292 {
6293 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6294 errmsg = e_invarg;
6295 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296
6297 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006298 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006299 {
6300 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6301 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006302 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006303 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006304 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006305 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006306 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006307
6308 /* 'background' */
6309 else if (varp == &p_bg)
6310 {
6311 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6312 {
6313#ifdef FEAT_EVAL
6314 int dark = (*p_bg == 'd');
6315#endif
6316
6317 init_highlight(FALSE, FALSE);
6318
6319#ifdef FEAT_EVAL
6320 if (dark != (*p_bg == 'd')
6321 && get_var_value((char_u *)"g:colors_name") != NULL)
6322 {
6323 /* The color scheme must have set 'background' back to another
6324 * value, that's not what we want here. Disable the color
6325 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006326 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006327 free_string_option(p_bg);
6328 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6329 check_string_option(&p_bg);
6330 init_highlight(FALSE, FALSE);
6331 }
6332#endif
6333 }
6334 else
6335 errmsg = e_invarg;
6336 }
6337
6338 /* 'wildmode' */
6339 else if (varp == &p_wim)
6340 {
6341 if (check_opt_wim() == FAIL)
6342 errmsg = e_invarg;
6343 }
6344
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006345#ifdef FEAT_CMDL_COMPL
6346 /* 'wildoptions' */
6347 else if (varp == &p_wop)
6348 {
6349 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6350 errmsg = e_invarg;
6351 }
6352#endif
6353
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354#ifdef FEAT_WAK
6355 /* 'winaltkeys' */
6356 else if (varp == &p_wak)
6357 {
6358 if (*p_wak == NUL
6359 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6360 errmsg = e_invarg;
6361# ifdef FEAT_MENU
6362# ifdef FEAT_GUI_MOTIF
6363 else if (gui.in_use)
6364 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6365# else
6366# ifdef FEAT_GUI_GTK
6367 else if (gui.in_use)
6368 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6369# endif
6370# endif
6371# endif
6372 }
6373#endif
6374
Bram Moolenaar071d4272004-06-13 20:20:40 +00006375 /* 'eventignore' */
6376 else if (varp == &p_ei)
6377 {
6378 if (check_ei() == FAIL)
6379 errmsg = e_invarg;
6380 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006381
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006382 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6383 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6384 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006385 {
6386 if (gvarp == &p_fenc)
6387 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006388 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006389 errmsg = e_modifiable;
6390 else if (vim_strchr(*varp, ',') != NULL)
6391 /* No comma allowed in 'fileencoding'; catches confusing it
6392 * with 'fileencodings'. */
6393 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006394 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006395 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006396#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006397 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006398 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006399#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006400 /* Add 'fileencoding' to the swap file. */
6401 ml_setflags(curbuf);
6402 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006403 }
6404 if (errmsg == NULL)
6405 {
6406 /* canonize the value, so that STRCMP() can be used on it */
6407 p = enc_canonize(*varp);
6408 if (p != NULL)
6409 {
6410 vim_free(*varp);
6411 *varp = p;
6412 }
6413 if (varp == &p_enc)
6414 {
6415 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006416#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006417 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006419 }
6420 }
6421
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006422#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006423 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6424 {
6425 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6426 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006427 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006428 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006429#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430
6431 if (errmsg == NULL)
6432 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006433#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006434 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6435 * (with another encoding). */
6436 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6437 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006439
6440 /* When 'termencoding' is not empty and 'encoding' changes or when
6441 * 'termencoding' changes, need to setup for keyboard input and
6442 * display output conversion. */
6443 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6444 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006445 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6446 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6447 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006448 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006449 p_tenc, p_enc);
6450 errmsg = e_invarg;
6451 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006452 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006453
Bram Moolenaar4f974752019-02-17 17:44:42 +01006454#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006455 /* $HOME may have characters in active code page. */
6456 if (varp == &p_enc)
6457 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006459 }
6460 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006461
6462#if defined(FEAT_POSTSCRIPT)
6463 else if (varp == &p_penc)
6464 {
6465 /* Canonize printencoding if VIM standard one */
6466 p = enc_canonize(p_penc);
6467 if (p != NULL)
6468 {
6469 vim_free(p_penc);
6470 p_penc = p;
6471 }
6472 else
6473 {
6474 /* Ensure lower case and '-' for '_' */
6475 for (s = p_penc; *s != NUL; s++)
6476 {
6477 if (*s == '_')
6478 *s = '-';
6479 else
6480 *s = TOLOWER_ASC(*s);
6481 }
6482 }
6483 }
6484#endif
6485
Bram Moolenaar9372a112005-12-06 19:59:18 +00006486#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006487 else if (varp == &p_imak)
6488 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006489 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490 errmsg = e_invarg;
6491 }
6492#endif
6493
6494#ifdef FEAT_KEYMAP
6495 else if (varp == &curbuf->b_p_keymap)
6496 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006497 if (!valid_filetype(*varp))
6498 errmsg = e_invarg;
6499 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006500 {
6501 int secure_save = secure;
6502
6503 // Reset the secure flag, since the value of 'keymap' has
6504 // been checked to be safe.
6505 secure = 0;
6506
6507 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006508 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006509
Bram Moolenaar916a8182018-11-25 02:18:29 +01006510 secure = secure_save;
6511
6512 // Since we check the value, there is no need to set P_INSECURE,
6513 // even when the value comes from a modeline.
6514 *value_checked = TRUE;
6515 }
6516
Bram Moolenaarfab06232009-03-04 03:13:35 +00006517 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006519 if (*curbuf->b_p_keymap != NUL)
6520 {
6521 /* Installed a new keymap, switch on using it. */
6522 curbuf->b_p_iminsert = B_IMODE_LMAP;
6523 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6524 curbuf->b_p_imsearch = B_IMODE_LMAP;
6525 }
6526 else
6527 {
6528 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6529 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6530 curbuf->b_p_iminsert = B_IMODE_NONE;
6531 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6532 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6533 }
6534 if ((opt_flags & OPT_LOCAL) == 0)
6535 {
6536 set_iminsert_global();
6537 set_imsearch_global();
6538 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006539 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006540 }
6541 }
6542#endif
6543
6544 /* 'fileformat' */
6545 else if (gvarp == &p_ff)
6546 {
6547 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6548 errmsg = e_modifiable;
6549 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6550 errmsg = e_invarg;
6551 else
6552 {
6553 /* may also change 'textmode' */
6554 if (get_fileformat(curbuf) == EOL_DOS)
6555 curbuf->b_p_tx = TRUE;
6556 else
6557 curbuf->b_p_tx = FALSE;
6558#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006559 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006560#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006561 /* update flag in swap file */
6562 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006563 /* Redraw needed when switching to/from "mac": a CR in the text
6564 * will be displayed differently. */
6565 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6566 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 }
6568 }
6569
6570 /* 'fileformats' */
6571 else if (varp == &p_ffs)
6572 {
6573 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6574 errmsg = e_invarg;
6575 else
6576 {
6577 /* also change 'textauto' */
6578 if (*p_ffs == NUL)
6579 p_ta = FALSE;
6580 else
6581 p_ta = TRUE;
6582 }
6583 }
6584
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006585#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006586 /* 'cryptkey' */
6587 else if (gvarp == &p_key)
6588 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006589# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590 /* Make sure the ":set" command doesn't show the new value in the
6591 * history. */
6592 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006593# endif
6594 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6595 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006596 ml_set_crypt_key(curbuf, oldval,
6597 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006598 }
6599
6600 else if (gvarp == &p_cm)
6601 {
6602 if (opt_flags & OPT_LOCAL)
6603 p = curbuf->b_p_cm;
6604 else
6605 p = p_cm;
6606 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6607 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006608 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006609 errmsg = e_invarg;
6610 else
6611 {
6612 /* When setting the global value to empty, make it "zip". */
6613 if (*p_cm == NUL)
6614 {
6615 if (new_value_alloced)
6616 free_string_option(p_cm);
6617 p_cm = vim_strsave((char_u *)"zip");
6618 new_value_alloced = TRUE;
6619 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006620 /* When using ":set cm=name" the local value is going to be empty.
6621 * Do that here, otherwise the crypt functions will still use the
6622 * local value. */
6623 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6624 {
6625 free_string_option(curbuf->b_p_cm);
6626 curbuf->b_p_cm = empty_option;
6627 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006628
6629 /* Need to update the swapfile when the effective method changed.
6630 * Set "s" to the effective old value, "p" to the effective new
6631 * method and compare. */
6632 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6633 s = p_cm; /* was previously using the global value */
6634 else
6635 s = oldval;
6636 if (*curbuf->b_p_cm == NUL)
6637 p = p_cm; /* is now using the global value */
6638 else
6639 p = curbuf->b_p_cm;
6640 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006641 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006642
6643 /* If the global value changes need to update the swapfile for all
6644 * buffers using that value. */
6645 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6646 {
6647 buf_T *buf;
6648
Bram Moolenaar29323592016-07-24 22:04:11 +02006649 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006650 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006651 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006652 }
6653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 }
6655#endif
6656
6657 /* 'matchpairs' */
6658 else if (gvarp == &p_mps)
6659 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006660 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006661 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006662 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006663 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006664 int x2 = -1;
6665 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006666
6667 if (*p != NUL)
6668 p += mb_ptr2len(p);
6669 if (*p != NUL)
6670 x2 = *p++;
6671 if (*p != NUL)
6672 {
6673 x3 = mb_ptr2char(p);
6674 p += mb_ptr2len(p);
6675 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006676 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006677 {
6678 errmsg = e_invarg;
6679 break;
6680 }
6681 if (*p == NUL)
6682 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006683 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006684 }
6685 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006686 {
6687 /* Check for "x:y,x:y" */
6688 for (p = *varp; *p != NUL; p += 4)
6689 {
6690 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6691 {
6692 errmsg = e_invarg;
6693 break;
6694 }
6695 if (p[3] == NUL)
6696 break;
6697 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698 }
6699 }
6700
6701#ifdef FEAT_COMMENTS
6702 /* 'comments' */
6703 else if (gvarp == &p_com)
6704 {
6705 for (s = *varp; *s; )
6706 {
6707 while (*s && *s != ':')
6708 {
6709 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6710 && !VIM_ISDIGIT(*s) && *s != '-')
6711 {
6712 errmsg = illegal_char(errbuf, *s);
6713 break;
6714 }
6715 ++s;
6716 }
6717 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006718 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006719 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006720 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006721 if (errmsg != NULL)
6722 break;
6723 while (*s && *s != ',')
6724 {
6725 if (*s == '\\' && s[1] != NUL)
6726 ++s;
6727 ++s;
6728 }
6729 s = skip_to_option_part(s);
6730 }
6731 }
6732#endif
6733
6734 /* 'listchars' */
6735 else if (varp == &p_lcs)
6736 {
6737 errmsg = set_chars_option(varp);
6738 }
6739
Bram Moolenaar071d4272004-06-13 20:20:40 +00006740 /* 'fillchars' */
6741 else if (varp == &p_fcs)
6742 {
6743 errmsg = set_chars_option(varp);
6744 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006745
6746#ifdef FEAT_CMDWIN
6747 /* 'cedit' */
6748 else if (varp == &p_cedit)
6749 {
6750 errmsg = check_cedit();
6751 }
6752#endif
6753
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006754 /* 'verbosefile' */
6755 else if (varp == &p_vfile)
6756 {
6757 verbose_stop();
6758 if (*p_vfile != NUL && verbose_open() == FAIL)
6759 errmsg = e_invarg;
6760 }
6761
Bram Moolenaar071d4272004-06-13 20:20:40 +00006762#ifdef FEAT_VIMINFO
6763 /* 'viminfo' */
6764 else if (varp == &p_viminfo)
6765 {
6766 for (s = p_viminfo; *s;)
6767 {
6768 /* Check it's a valid character */
6769 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6770 {
6771 errmsg = illegal_char(errbuf, *s);
6772 break;
6773 }
6774 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006775 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006776 else if (*s == 'r') /* skip until next ',' */
6777 {
6778 while (*++s && *s != ',')
6779 ;
6780 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006781 else if (*s == '%')
6782 {
6783 /* optional number */
6784 while (vim_isdigit(*++s))
6785 ;
6786 }
6787 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006788 ++s; /* no extra chars */
6789 else /* must have a number */
6790 {
6791 while (vim_isdigit(*++s))
6792 ;
6793
6794 if (!VIM_ISDIGIT(*(s - 1)))
6795 {
6796 if (errbuf != NULL)
6797 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006798 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006799 transchar_byte(*(s - 1)));
6800 errmsg = errbuf;
6801 }
6802 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006803 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006804 break;
6805 }
6806 }
6807 if (*s == ',')
6808 ++s;
6809 else if (*s)
6810 {
6811 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006812 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006813 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006814 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815 break;
6816 }
6817 }
6818 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006819 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006820 }
6821#endif /* FEAT_VIMINFO */
6822
6823 /* terminal options */
6824 else if (istermoption(&options[opt_idx]) && full_screen)
6825 {
6826 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6827 if (varp == &T_CCO)
6828 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006829 int colors = atoi((char *)T_CCO);
6830
6831 /* Only reinitialize colors if t_Co value has really changed to
6832 * avoid expensive reload of colorscheme if t_Co is set to the
6833 * same value multiple times. */
6834 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006836 t_colors = colors;
6837 if (t_colors <= 1)
6838 {
6839 if (new_value_alloced)
6840 vim_free(T_CCO);
6841 T_CCO = empty_option;
6842 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006843#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6844 if (is_term_win32())
6845 {
6846 swap_tcap();
6847 did_swaptcap = TRUE;
6848 }
6849#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006850 /* We now have a different color setup, initialize it again. */
6851 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006852 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006853 }
6854 ttest(FALSE);
6855 if (varp == &T_ME)
6856 {
6857 out_str(T_ME);
6858 redraw_later(CLEAR);
Bram Moolenaar4f974752019-02-17 17:44:42 +01006859#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006860 /* Since t_me has been set, this probably means that the user
6861 * wants to use this as default colors. Need to reset default
6862 * background/foreground colors. */
6863 mch_set_normal_colors();
6864#endif
6865 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006866 if (varp == &T_BE && termcap_active)
6867 {
6868 if (*T_BE == NUL)
6869 /* When clearing t_BE we assume the user no longer wants
6870 * bracketed paste, thus disable it by writing t_BD. */
6871 out_str(T_BD);
6872 else
6873 out_str(T_BE);
6874 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006875 }
6876
6877#ifdef FEAT_LINEBREAK
6878 /* 'showbreak' */
6879 else if (varp == &p_sbr)
6880 {
6881 for (s = p_sbr; *s; )
6882 {
6883 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006884 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006885 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006886 }
6887 }
6888#endif
6889
6890#ifdef FEAT_GUI
6891 /* 'guifont' */
6892 else if (varp == &p_guifont)
6893 {
6894 if (gui.in_use)
6895 {
6896 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006897# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898 /*
6899 * Put up a font dialog and let the user select a new value.
6900 * If this is cancelled go back to the old value but don't
6901 * give an error message.
6902 */
6903 if (STRCMP(p, "*") == 0)
6904 {
6905 p = gui_mch_font_dialog(oldval);
6906
6907 if (new_value_alloced)
6908 free_string_option(p_guifont);
6909
6910 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6911 new_value_alloced = TRUE;
6912 }
6913# endif
6914 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6915 {
6916# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6917 if (STRCMP(p_guifont, "*") == 0)
6918 {
6919 /* Dialog was cancelled: Keep the old value without giving
6920 * an error message. */
6921 if (new_value_alloced)
6922 free_string_option(p_guifont);
6923 p_guifont = vim_strsave(oldval);
6924 new_value_alloced = TRUE;
6925 }
6926 else
6927# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006928 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006929 }
6930 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006931 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006932 }
6933# ifdef FEAT_XFONTSET
6934 else if (varp == &p_guifontset)
6935 {
6936 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006937 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006938 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006939 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006940 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006941 }
6942# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 else if (varp == &p_guifontwide)
6944 {
6945 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006946 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006948 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006949 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006950 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006951#endif
6952
6953#ifdef CURSOR_SHAPE
6954 /* 'guicursor' */
6955 else if (varp == &p_guicursor)
6956 errmsg = parse_shape_opt(SHAPE_CURSOR);
6957#endif
6958
6959#ifdef FEAT_MOUSESHAPE
6960 /* 'mouseshape' */
6961 else if (varp == &p_mouseshape)
6962 {
6963 errmsg = parse_shape_opt(SHAPE_MOUSE);
6964 update_mouseshape(-1);
6965 }
6966#endif
6967
6968#ifdef FEAT_PRINTER
6969 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006970 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006971# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006972 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006973 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006974# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006975#endif
6976
6977#ifdef FEAT_LANGMAP
6978 /* 'langmap' */
6979 else if (varp == &p_langmap)
6980 langmap_set();
6981#endif
6982
6983#ifdef FEAT_LINEBREAK
6984 /* 'breakat' */
6985 else if (varp == &p_breakat)
6986 fill_breakat_flags();
6987#endif
6988
6989#ifdef FEAT_TITLE
6990 /* 'titlestring' and 'iconstring' */
6991 else if (varp == &p_titlestring || varp == &p_iconstring)
6992 {
6993# ifdef FEAT_STL_OPT
6994 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
6995
6996 /* NULL => statusline syntax */
6997 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
6998 stl_syntax |= flagval;
6999 else
7000 stl_syntax &= ~flagval;
7001# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007002 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007003 }
7004#endif
7005
7006#ifdef FEAT_GUI
7007 /* 'guioptions' */
7008 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007009 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007010 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007011 redraw_gui_only = TRUE;
7012 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007013#endif
7014
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007015#if defined(FEAT_GUI_TABLINE)
7016 /* 'guitablabel' */
7017 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007018 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007019 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007020 redraw_gui_only = TRUE;
7021 }
7022 /* 'guitabtooltip' */
7023 else if (varp == &p_gtt)
7024 {
7025 redraw_gui_only = TRUE;
7026 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007027#endif
7028
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7030 /* 'ttymouse' */
7031 else if (varp == &p_ttym)
7032 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007033 /* Switch the mouse off before changing the escape sequences used for
7034 * that. */
7035 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007036 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7037 errmsg = e_invarg;
7038 else
7039 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007040 if (termcap_active)
7041 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 }
7043#endif
7044
Bram Moolenaar071d4272004-06-13 20:20:40 +00007045 /* 'selection' */
7046 else if (varp == &p_sel)
7047 {
7048 if (*p_sel == NUL
7049 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7050 errmsg = e_invarg;
7051 }
7052
7053 /* 'selectmode' */
7054 else if (varp == &p_slm)
7055 {
7056 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7057 errmsg = e_invarg;
7058 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007059
7060#ifdef FEAT_BROWSE
7061 /* 'browsedir' */
7062 else if (varp == &p_bsdir)
7063 {
7064 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7065 && !mch_isdir(p_bsdir))
7066 errmsg = e_invarg;
7067 }
7068#endif
7069
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 /* 'keymodel' */
7071 else if (varp == &p_km)
7072 {
7073 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7074 errmsg = e_invarg;
7075 else
7076 {
7077 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7078 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7079 }
7080 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007081
7082 /* 'mousemodel' */
7083 else if (varp == &p_mousem)
7084 {
7085 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7086 errmsg = e_invarg;
7087#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7088 else if (*p_mousem != *oldval)
7089 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7090 * to create or delete the popup menus. */
7091 gui_motif_update_mousemodel(root_menu);
7092#endif
7093 }
7094
7095 /* 'switchbuf' */
7096 else if (varp == &p_swb)
7097 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007098 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007099 errmsg = e_invarg;
7100 }
7101
7102 /* 'debug' */
7103 else if (varp == &p_debug)
7104 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007105 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106 errmsg = e_invarg;
7107 }
7108
7109 /* 'display' */
7110 else if (varp == &p_dy)
7111 {
7112 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7113 errmsg = e_invarg;
7114 else
7115 (void)init_chartab();
7116
7117 }
7118
Bram Moolenaar071d4272004-06-13 20:20:40 +00007119 /* 'eadirection' */
7120 else if (varp == &p_ead)
7121 {
7122 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7123 errmsg = e_invarg;
7124 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007125
7126#ifdef FEAT_CLIPBOARD
7127 /* 'clipboard' */
7128 else if (varp == &p_cb)
7129 errmsg = check_clipboard_option();
7130#endif
7131
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007132#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007133 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7134 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007135 else if (varp == &(curwin->w_s->b_p_spl)
7136 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007137 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007138 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7139
7140 if ((is_spellfile && !valid_spellfile(*varp))
7141 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007142 errmsg = e_invarg;
7143 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007144 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007145 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007146 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007147 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007148 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007149 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007150 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007151 /* 'spellsuggest' */
7152 else if (varp == &p_sps)
7153 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007154 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007155 errmsg = e_invarg;
7156 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007157 /* 'mkspellmem' */
7158 else if (varp == &p_msm)
7159 {
7160 if (spell_check_msm() != OK)
7161 errmsg = e_invarg;
7162 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007163#endif
7164
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 /* When 'bufhidden' is set, check for valid value. */
7166 else if (gvarp == &p_bh)
7167 {
7168 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7169 errmsg = e_invarg;
7170 }
7171
7172 /* When 'buftype' is set, check for valid value. */
7173 else if (gvarp == &p_bt)
7174 {
7175 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7176 errmsg = e_invarg;
7177 else
7178 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007179 if (curwin->w_status_height)
7180 {
7181 curwin->w_redr_status = TRUE;
7182 redraw_later(VALID);
7183 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007185#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007186 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007187#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007188 }
7189 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007190
7191#ifdef FEAT_STL_OPT
7192 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007193 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007194 {
7195 int wid;
7196
7197 if (varp == &p_ruf) /* reset ru_wid first */
7198 ru_wid = 0;
7199 s = *varp;
7200 if (varp == &p_ruf && *s == '%')
7201 {
7202 /* set ru_wid if 'ruf' starts with "%99(" */
7203 if (*++s == '-') /* ignore a '-' */
7204 s++;
7205 wid = getdigits(&s);
7206 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7207 ru_wid = wid;
7208 else
7209 errmsg = check_stl_option(p_ruf);
7210 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007211 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007212 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007213 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007214 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007215 comp_col();
7216 }
7217#endif
7218
7219#ifdef FEAT_INS_EXPAND
7220 /* check if it is a valid value for 'complete' -- Acevedo */
7221 else if (gvarp == &p_cpt)
7222 {
7223 for (s = *varp; *s;)
7224 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007225 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007226 s++;
7227 if (!*s)
7228 break;
7229 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7230 {
7231 errmsg = illegal_char(errbuf, *s);
7232 break;
7233 }
7234 if (*++s != NUL && *s != ',' && *s != ' ')
7235 {
7236 if (s[-1] == 'k' || s[-1] == 's')
7237 {
7238 /* skip optional filename after 'k' and 's' */
7239 while (*s && *s != ',' && *s != ' ')
7240 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007241 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242 ++s;
7243 ++s;
7244 }
7245 }
7246 else
7247 {
7248 if (errbuf != NULL)
7249 {
7250 sprintf((char *)errbuf,
7251 _("E535: Illegal character after <%c>"),
7252 *--s);
7253 errmsg = errbuf;
7254 }
7255 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007256 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007257 break;
7258 }
7259 }
7260 }
7261 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007262
7263 /* 'completeopt' */
7264 else if (varp == &p_cot)
7265 {
7266 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7267 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007268 else
7269 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007270 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007271#endif /* FEAT_INS_EXPAND */
7272
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007273#ifdef FEAT_SIGNS
7274 /* 'signcolumn' */
7275 else if (varp == &curwin->w_p_scl)
7276 {
7277 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7278 errmsg = e_invarg;
7279 }
7280#endif
7281
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282
Bram Moolenaar4f974752019-02-17 17:44:42 +01007283#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007284 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285 else if (varp == &p_toolbar)
7286 {
7287 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7288 &toolbar_flags, TRUE) != OK)
7289 errmsg = e_invarg;
7290 else
7291 {
7292 out_flush();
7293 gui_mch_show_toolbar((toolbar_flags &
7294 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7295 }
7296 }
7297#endif
7298
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007299#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007300 /* 'toolbariconsize': GTK+ 2 only */
7301 else if (varp == &p_tbis)
7302 {
7303 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7304 errmsg = e_invarg;
7305 else
7306 {
7307 out_flush();
7308 gui_mch_show_toolbar((toolbar_flags &
7309 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7310 }
7311 }
7312#endif
7313
7314 /* 'pastetoggle': translate key codes like in a mapping */
7315 else if (varp == &p_pt)
7316 {
7317 if (*p_pt)
7318 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007319 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007320 if (p != NULL)
7321 {
7322 if (new_value_alloced)
7323 free_string_option(p_pt);
7324 p_pt = p;
7325 new_value_alloced = TRUE;
7326 }
7327 }
7328 }
7329
7330 /* 'backspace' */
7331 else if (varp == &p_bs)
7332 {
7333 if (VIM_ISDIGIT(*p_bs))
7334 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007335 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336 errmsg = e_invarg;
7337 }
7338 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7339 errmsg = e_invarg;
7340 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007341 else if (varp == &p_bo)
7342 {
7343 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7344 errmsg = e_invarg;
7345 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007346
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007347 /* 'tagcase' */
7348 else if (gvarp == &p_tc)
7349 {
7350 unsigned int *flags;
7351
7352 if (opt_flags & OPT_LOCAL)
7353 {
7354 p = curbuf->b_p_tc;
7355 flags = &curbuf->b_tc_flags;
7356 }
7357 else
7358 {
7359 p = p_tc;
7360 flags = &tc_flags;
7361 }
7362
7363 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7364 /* make the local value empty: use the global value */
7365 *flags = 0;
7366 else if (*p == NUL
7367 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7368 errmsg = e_invarg;
7369 }
7370
Bram Moolenaar071d4272004-06-13 20:20:40 +00007371 /* 'casemap' */
7372 else if (varp == &p_cmp)
7373 {
7374 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7375 errmsg = e_invarg;
7376 }
7377
7378#ifdef FEAT_DIFF
7379 /* 'diffopt' */
7380 else if (varp == &p_dip)
7381 {
7382 if (diffopt_changed() == FAIL)
7383 errmsg = e_invarg;
7384 }
7385#endif
7386
7387#ifdef FEAT_FOLDING
7388 /* 'foldmethod' */
7389 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7390 {
7391 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7392 || *curwin->w_p_fdm == NUL)
7393 errmsg = e_invarg;
7394 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007395 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007396 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007397 if (foldmethodIsDiff(curwin))
7398 newFoldLevel();
7399 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007400 }
7401# ifdef FEAT_EVAL
7402 /* 'foldexpr' */
7403 else if (varp == &curwin->w_p_fde)
7404 {
7405 if (foldmethodIsExpr(curwin))
7406 foldUpdateAll(curwin);
7407 }
7408# endif
7409 /* 'foldmarker' */
7410 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7411 {
7412 p = vim_strchr(*varp, ',');
7413 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007414 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007415 else if (p == *varp || p[1] == NUL)
7416 errmsg = e_invarg;
7417 else if (foldmethodIsMarker(curwin))
7418 foldUpdateAll(curwin);
7419 }
7420 /* 'commentstring' */
7421 else if (gvarp == &p_cms)
7422 {
7423 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007424 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007425 }
7426 /* 'foldopen' */
7427 else if (varp == &p_fdo)
7428 {
7429 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7430 errmsg = e_invarg;
7431 }
7432 /* 'foldclose' */
7433 else if (varp == &p_fcl)
7434 {
7435 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7436 errmsg = e_invarg;
7437 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007438 /* 'foldignore' */
7439 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7440 {
7441 if (foldmethodIsIndent(curwin))
7442 foldUpdateAll(curwin);
7443 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007444#endif
7445
Bram Moolenaar071d4272004-06-13 20:20:40 +00007446 /* 'virtualedit' */
7447 else if (varp == &p_ve)
7448 {
7449 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7450 errmsg = e_invarg;
7451 else if (STRCMP(p_ve, oldval) != 0)
7452 {
7453 /* Recompute cursor position in case the new 've' setting
7454 * changes something. */
7455 validate_virtcol();
7456 coladvance(curwin->w_virtcol);
7457 }
7458 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007459
7460#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7461 else if (varp == &p_csqf)
7462 {
7463 if (p_csqf != NULL)
7464 {
7465 p = p_csqf;
7466 while (*p != NUL)
7467 {
7468 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7469 || p[1] == NUL
7470 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7471 || (p[2] != NUL && p[2] != ','))
7472 {
7473 errmsg = e_invarg;
7474 break;
7475 }
7476 else if (p[2] == NUL)
7477 break;
7478 else
7479 p += 3;
7480 }
7481 }
7482 }
7483#endif
7484
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007485#ifdef FEAT_CINDENT
7486 /* 'cinoptions' */
7487 else if (gvarp == &p_cino)
7488 {
7489 /* TODO: recognize errors */
7490 parse_cino(curbuf);
7491 }
7492#endif
7493
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007494#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007495 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007496 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007497 {
7498 if (!gui_mch_set_rendering_options(p_rop))
7499 errmsg = e_invarg;
7500 }
7501#endif
7502
Bram Moolenaard0b51382016-11-04 15:23:45 +01007503 else if (gvarp == &p_ft)
7504 {
7505 if (!valid_filetype(*varp))
7506 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007507 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007508 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007509 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007510
7511 // Since we check the value, there is no need to set P_INSECURE,
7512 // even when the value comes from a modeline.
7513 *value_checked = TRUE;
7514 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007515 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007516
7517#ifdef FEAT_SYN_HL
7518 else if (gvarp == &p_syn)
7519 {
7520 if (!valid_filetype(*varp))
7521 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007522 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007523 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007524 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007525
7526 // Since we check the value, there is no need to set P_INSECURE,
7527 // even when the value comes from a modeline.
7528 *value_checked = TRUE;
7529 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007530 }
7531#endif
7532
Bram Moolenaar825680f2017-07-22 17:04:02 +02007533#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007534 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007535 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007536 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007537 if (*curwin->w_p_twk != NUL
7538 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007539 errmsg = e_invarg;
7540 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007541 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007542 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007543 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007544 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007545 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007546 p = skipdigits(curwin->w_p_tws);
7547 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007548 || (*p != 'x' && *p != '*')
7549 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007550 errmsg = e_invarg;
7551 }
7552 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007553# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007554 // 'termwintype'
7555 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007556 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007557 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007558 errmsg = e_invarg;
7559 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007560# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007561#endif
7562
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007563#ifdef FEAT_VARTABS
7564 /* 'varsofttabstop' */
7565 else if (varp == &(curbuf->b_p_vsts))
7566 {
7567 char_u *cp;
7568
7569 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7570 {
7571 if (curbuf->b_p_vsts_array)
7572 {
7573 vim_free(curbuf->b_p_vsts_array);
7574 curbuf->b_p_vsts_array = 0;
7575 }
7576 }
7577 else
7578 {
7579 for (cp = *varp; *cp; ++cp)
7580 {
7581 if (vim_isdigit(*cp))
7582 continue;
7583 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7584 continue;
7585 errmsg = e_invarg;
7586 break;
7587 }
7588 if (errmsg == NULL)
7589 {
7590 int *oldarray = curbuf->b_p_vsts_array;
7591 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7592 {
7593 if (oldarray)
7594 vim_free(oldarray);
7595 }
7596 else
7597 errmsg = e_invarg;
7598 }
7599 }
7600 }
7601
7602 /* 'vartabstop' */
7603 else if (varp == &(curbuf->b_p_vts))
7604 {
7605 char_u *cp;
7606
7607 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7608 {
7609 if (curbuf->b_p_vts_array)
7610 {
7611 vim_free(curbuf->b_p_vts_array);
7612 curbuf->b_p_vts_array = NULL;
7613 }
7614 }
7615 else
7616 {
7617 for (cp = *varp; *cp; ++cp)
7618 {
7619 if (vim_isdigit(*cp))
7620 continue;
7621 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7622 continue;
7623 errmsg = e_invarg;
7624 break;
7625 }
7626 if (errmsg == NULL)
7627 {
7628 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007629
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007630 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7631 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007632 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007633#ifdef FEAT_FOLDING
7634 if (foldmethodIsIndent(curwin))
7635 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007636#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007637 }
7638 else
7639 errmsg = e_invarg;
7640 }
7641 }
7642 }
7643#endif
7644
Bram Moolenaar071d4272004-06-13 20:20:40 +00007645 /* Options that are a list of flags. */
7646 else
7647 {
7648 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007649 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007651 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007652 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007653 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007654 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007655 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007656 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007657#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007658 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007659 p = (char_u *)COCU_ALL;
7660#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007661 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007662 {
7663#ifdef FEAT_MOUSE
7664 p = (char_u *)MOUSE_ALL;
7665#else
7666 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007667 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007668#endif
7669 }
7670#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007671 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007672 p = (char_u *)GO_ALL;
7673#endif
7674 if (p != NULL)
7675 {
7676 for (s = *varp; *s; ++s)
7677 if (vim_strchr(p, *s) == NULL)
7678 {
7679 errmsg = illegal_char(errbuf, *s);
7680 break;
7681 }
7682 }
7683 }
7684
7685 /*
7686 * If error detected, restore the previous value.
7687 */
7688 if (errmsg != NULL)
7689 {
7690 if (new_value_alloced)
7691 free_string_option(*varp);
7692 *varp = oldval;
7693 /*
7694 * When resetting some values, need to act on it.
7695 */
7696 if (did_chartab)
7697 (void)init_chartab();
7698 if (varp == &p_hl)
7699 (void)highlight_changed();
7700 }
7701 else
7702 {
7703#ifdef FEAT_EVAL
7704 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007705 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007706#endif
7707 /*
7708 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007709 * Use "free_oldval", because recursiveness may change the flags under
7710 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007711 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007712 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007713 free_string_option(oldval);
7714 if (new_value_alloced)
7715 options[opt_idx].flags |= P_ALLOCED;
7716 else
7717 options[opt_idx].flags &= ~P_ALLOCED;
7718
7719 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007720 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007721 {
7722 /* global option with local value set to use global value; free
7723 * the local value and make it empty */
7724 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7725 free_string_option(*(char_u **)p);
7726 *(char_u **)p = empty_option;
7727 }
7728
7729 /* May set global value for local option. */
7730 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7731 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007732
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007733 /*
7734 * Trigger the autocommand only after setting the flags.
7735 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007736#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007737 /* When 'syntax' is set, load the syntax of that name */
7738 if (varp == &(curbuf->b_p_syn))
7739 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007740 static int syn_recursive = 0;
7741
7742 ++syn_recursive;
7743 // Only pass TRUE for "force" when the value changed or not used
7744 // recursively, to avoid endless recurrence.
7745 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7746 value_changed || syn_recursive == 1, curbuf);
7747 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007748 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007749#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007750 else if (varp == &(curbuf->b_p_ft))
7751 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007752 /* 'filetype' is set, trigger the FileType autocommand.
7753 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007754 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007755 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007756 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007757 static int ft_recursive = 0;
7758 int secure_save = secure;
7759
7760 // Reset the secure flag, since the value of 'filetype' has
7761 // been checked to be safe.
7762 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007763
7764 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007765 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007766 // Only pass TRUE for "force" when the value changed or not
7767 // used recursively, to avoid endless recurrence.
7768 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7769 value_changed || ft_recursive == 1, curbuf);
7770 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007771 /* Just in case the old "curbuf" is now invalid. */
7772 if (varp != &(curbuf->b_p_ft))
7773 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007774
7775 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007776 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007777 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007778#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007779 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007780 {
7781 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007782 char_u *q = curwin->w_s->b_p_spl;
7783
7784 /* Skip the first name if it is "cjk". */
7785 if (STRNCMP(q, "cjk,", 4) == 0)
7786 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007787
7788 /*
7789 * Source the spell/LANG.vim in 'runtimepath'.
7790 * They could set 'spellcapcheck' depending on the language.
7791 * Use the first name in 'spelllang' up to '_region' or
7792 * '.encoding'.
7793 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007794 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007795 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007796 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007797 if (p > q)
7798 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007799 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7800 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007801 source_runtime(fname, DIP_ALL);
7802 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007803 }
7804#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007805 }
7806
7807#ifdef FEAT_MOUSE
7808 if (varp == &p_mouse)
7809 {
7810# ifdef FEAT_MOUSE_TTY
7811 if (*p_mouse == NUL)
7812 mch_setmouse(FALSE); /* switch mouse off */
7813 else
7814# endif
7815 setmouse(); /* in case 'mouse' changed */
7816 }
7817#endif
7818
Bram Moolenaar913077c2012-03-28 19:59:04 +02007819 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007820 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007821 curwin->w_set_curswant = TRUE;
7822
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007823#ifdef FEAT_GUI
7824 /* check redraw when it's not a GUI option or the GUI is active. */
7825 if (!redraw_gui_only || gui.in_use)
7826#endif
7827 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007828
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007829#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7830 if (did_swaptcap)
7831 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007832 set_termname((char_u *)"win32");
7833 init_highlight(TRUE, FALSE);
7834 }
7835#endif
7836
Bram Moolenaar071d4272004-06-13 20:20:40 +00007837 return errmsg;
7838}
7839
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007840#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007841/*
7842 * Simple int comparison function for use with qsort()
7843 */
7844 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007845int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007846{
7847 return *(const int *)a - *(const int *)b;
7848}
7849
7850/*
7851 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7852 * Returns error message, NULL if it's OK.
7853 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007854 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007855check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007856{
7857 char_u *s;
7858 int col;
7859 int count = 0;
7860 int color_cols[256];
7861 int i;
7862 int j = 0;
7863
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007864 if (wp->w_buffer == NULL)
7865 return NULL; /* buffer was closed */
7866
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007867 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007868 {
7869 if (*s == '-' || *s == '+')
7870 {
7871 /* -N and +N: add to 'textwidth' */
7872 col = (*s == '-') ? -1 : 1;
7873 ++s;
7874 if (!VIM_ISDIGIT(*s))
7875 return e_invarg;
7876 col = col * getdigits(&s);
7877 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007878 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007879 col += wp->w_buffer->b_p_tw;
7880 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007881 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007882 }
7883 else if (VIM_ISDIGIT(*s))
7884 col = getdigits(&s);
7885 else
7886 return e_invarg;
7887 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007888skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007889 if (*s == NUL)
7890 break;
7891 if (*s != ',')
7892 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007893 if (*++s == NUL)
7894 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007895 }
7896
7897 vim_free(wp->w_p_cc_cols);
7898 if (count == 0)
7899 wp->w_p_cc_cols = NULL;
7900 else
7901 {
7902 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7903 if (wp->w_p_cc_cols != NULL)
7904 {
7905 /* sort the columns for faster usage on screen redraw inside
7906 * win_line() */
7907 qsort(color_cols, count, sizeof(int), int_cmp);
7908
7909 for (i = 0; i < count; ++i)
7910 /* skip duplicates */
7911 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7912 wp->w_p_cc_cols[j++] = color_cols[i];
7913 wp->w_p_cc_cols[j] = -1; /* end marker */
7914 }
7915 }
7916
7917 return NULL; /* no error */
7918}
7919#endif
7920
Bram Moolenaar071d4272004-06-13 20:20:40 +00007921/*
7922 * Handle setting 'listchars' or 'fillchars'.
7923 * Returns error message, NULL if it's OK.
7924 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007925 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007926set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007927{
7928 int round, i, len, entries;
7929 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007930 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007931 struct charstab
7932 {
7933 int *cp;
7934 char *name;
7935 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 static struct charstab filltab[] =
7937 {
7938 {&fill_stl, "stl"},
7939 {&fill_stlnc, "stlnc"},
7940 {&fill_vert, "vert"},
7941 {&fill_fold, "fold"},
7942 {&fill_diff, "diff"},
7943 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007944 static struct charstab lcstab[] =
7945 {
7946 {&lcs_eol, "eol"},
7947 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007948 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007950 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007951 {&lcs_tab2, "tab"},
7952 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007953#ifdef FEAT_CONCEAL
7954 {&lcs_conceal, "conceal"},
7955#else
7956 {NULL, "conceal"},
7957#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007958 };
7959 struct charstab *tab;
7960
Bram Moolenaar071d4272004-06-13 20:20:40 +00007961 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007962 {
7963 tab = lcstab;
7964 entries = sizeof(lcstab) / sizeof(struct charstab);
7965 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 else
7967 {
7968 tab = filltab;
7969 entries = sizeof(filltab) / sizeof(struct charstab);
7970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007971
7972 /* first round: check for valid value, second round: assign values */
7973 for (round = 0; round <= 1; ++round)
7974 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007975 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976 {
7977 /* After checking that the value is valid: set defaults: space for
7978 * 'fillchars', NUL for 'listchars' */
7979 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007980 if (tab[i].cp != NULL)
7981 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007982
Bram Moolenaar071d4272004-06-13 20:20:40 +00007983 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007984 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007985 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007986 lcs_tab3 = NUL;
7987 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988 else
7989 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990 }
7991 p = *varp;
7992 while (*p)
7993 {
7994 for (i = 0; i < entries; ++i)
7995 {
7996 len = (int)STRLEN(tab[i].name);
7997 if (STRNCMP(p, tab[i].name, len) == 0
7998 && p[len] == ':'
7999 && p[len + 1] != NUL)
8000 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008001 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008002 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008003 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008004 if (mb_char2cells(c1) > 1)
8005 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008006 if (tab[i].cp == &lcs_tab2)
8007 {
8008 if (*s == NUL)
8009 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008010 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008011 if (mb_char2cells(c2) > 1)
8012 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008013 if (!(*s == ',' || *s == NUL))
8014 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008015 c3 = mb_ptr2char_adv(&s);
8016 if (mb_char2cells(c3) > 1)
8017 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008018 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008019 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008020
Bram Moolenaar071d4272004-06-13 20:20:40 +00008021 if (*s == ',' || *s == NUL)
8022 {
8023 if (round)
8024 {
8025 if (tab[i].cp == &lcs_tab2)
8026 {
8027 lcs_tab1 = c1;
8028 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008029 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008030 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008031 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008032 *(tab[i].cp) = c1;
8033
8034 }
8035 p = s;
8036 break;
8037 }
8038 }
8039 }
8040
8041 if (i == entries)
8042 return e_invarg;
8043 if (*p == ',')
8044 ++p;
8045 }
8046 }
8047
8048 return NULL; /* no error */
8049}
8050
8051#ifdef FEAT_STL_OPT
8052/*
8053 * Check validity of options with the 'statusline' format.
8054 * Return error message or NULL.
8055 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008056 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008057check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008058{
8059 int itemcnt = 0;
8060 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008061 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008062
8063 while (*s && itemcnt < STL_MAX_ITEM)
8064 {
8065 /* Check for valid keys after % sequences */
8066 while (*s && *s != '%')
8067 s++;
8068 if (!*s)
8069 break;
8070 s++;
8071 if (*s != '%' && *s != ')')
8072 ++itemcnt;
8073 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8074 {
8075 s++;
8076 continue;
8077 }
8078 if (*s == ')')
8079 {
8080 s++;
8081 if (--groupdepth < 0)
8082 break;
8083 continue;
8084 }
8085 if (*s == '-')
8086 s++;
8087 while (VIM_ISDIGIT(*s))
8088 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008089 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008090 continue;
8091 if (*s == '.')
8092 {
8093 s++;
8094 while (*s && VIM_ISDIGIT(*s))
8095 s++;
8096 }
8097 if (*s == '(')
8098 {
8099 groupdepth++;
8100 continue;
8101 }
8102 if (vim_strchr(STL_ALL, *s) == NULL)
8103 {
8104 return illegal_char(errbuf, *s);
8105 }
8106 if (*s == '{')
8107 {
8108 s++;
8109 while (*s != '}' && *s)
8110 s++;
8111 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008112 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008113 }
8114 }
8115 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008116 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008117 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008118 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008119 return NULL;
8120}
8121#endif
8122
8123#ifdef FEAT_CLIPBOARD
8124/*
8125 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008126 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008127 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008128 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008129check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008130{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008131 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008132 int new_autoselect_star = FALSE;
8133 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008134 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008135 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008136 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008137 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008138 char_u *p;
8139
8140 for (p = p_cb; *p != NUL; )
8141 {
8142 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8143 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008144 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008145 p += 7;
8146 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008147 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008148 && (p[11] == ',' || p[11] == NUL))
8149 {
8150 new_unnamed |= CLIP_UNNAMED_PLUS;
8151 p += 11;
8152 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008154 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008155 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008156 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008157 p += 10;
8158 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008159 else if (STRNCMP(p, "autoselectplus", 14) == 0
8160 && (p[14] == ',' || p[14] == NUL))
8161 {
8162 new_autoselect_plus = TRUE;
8163 p += 14;
8164 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008166 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 {
8168 new_autoselectml = TRUE;
8169 p += 12;
8170 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008171 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8172 {
8173 new_html = TRUE;
8174 p += 4;
8175 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008176 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8177 {
8178 p += 8;
8179 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8180 if (new_exclude_prog == NULL)
8181 errmsg = e_invarg;
8182 break;
8183 }
8184 else
8185 {
8186 errmsg = e_invarg;
8187 break;
8188 }
8189 if (*p == ',')
8190 ++p;
8191 }
8192 if (errmsg == NULL)
8193 {
8194 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008195 clip_autoselect_star = new_autoselect_star;
8196 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008198 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008199 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008200 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008201#ifdef FEAT_GUI_GTK
8202 if (gui.in_use)
8203 {
8204 gui_gtk_set_selection_targets();
8205 gui_gtk_set_dnd_targets();
8206 }
8207#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008208 }
8209 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008210 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008211
8212 return errmsg;
8213}
8214#endif
8215
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008216#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008217/*
8218 * Handle side effects of setting 'spell'.
8219 * Return an error message or NULL for success.
8220 */
8221 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008222did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008223{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008224 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008225 win_T *wp;
8226 int l;
8227
8228 if (is_spellfile)
8229 {
8230 l = (int)STRLEN(curwin->w_s->b_p_spf);
8231 if (l > 0 && (l < 4
8232 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8233 errmsg = e_invarg;
8234 }
8235
8236 if (errmsg == NULL)
8237 {
8238 FOR_ALL_WINDOWS(wp)
8239 if (wp->w_buffer == curbuf && wp->w_p_spell)
8240 {
8241 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008242 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008243 }
8244 }
8245 return errmsg;
8246}
8247
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008248/*
8249 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8250 * Return error message when failed, NULL when OK.
8251 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008252 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008253compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008254{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008255 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008256 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008257
Bram Moolenaar860cae12010-06-05 23:22:07 +02008258 if (*synblock->b_p_spc == NUL)
8259 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008260 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008261 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008262 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008263 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008264 if (re != NULL)
8265 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008266 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008267 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008268 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008269 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008270 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008271 return e_invarg;
8272 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008273 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008274 }
8275
Bram Moolenaar473de612013-06-08 18:19:48 +02008276 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008277 return NULL;
8278}
8279#endif
8280
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008281#if defined(FEAT_EVAL) || defined(PROTO)
8282/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008283 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008284 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008285 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008286 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008287set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008288{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008289 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8290 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008291 sctx_T new_script_ctx = script_ctx;
8292
8293 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008294
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008295 /* Remember where the option was set. For local options need to do that
8296 * in the buffer or window structure. */
8297 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008298 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008299 if (both || (opt_flags & OPT_LOCAL))
8300 {
8301 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008302 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008303 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008304 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008305 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008306}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008307
8308/*
8309 * Set the script_ctx for a termcap option.
8310 * "name" must be the two character code, e.g. "RV".
8311 * When "name" is NULL use "opt_idx".
8312 */
8313 void
8314set_term_option_sctx_idx(char *name, int opt_idx)
8315{
8316 char_u buf[5];
8317 int idx;
8318
8319 if (name == NULL)
8320 idx = opt_idx;
8321 else
8322 {
8323 buf[0] = 't';
8324 buf[1] = '_';
8325 buf[2] = name[0];
8326 buf[3] = name[1];
8327 buf[4] = 0;
8328 idx = findoption(buf);
8329 }
8330 if (idx >= 0)
8331 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8332}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008333#endif
8334
Bram Moolenaar071d4272004-06-13 20:20:40 +00008335/*
8336 * Set the value of a boolean option, and take care of side effects.
8337 * Returns NULL for success, or an error message for an error.
8338 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008339 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008340set_bool_option(
8341 int opt_idx, /* index in options[] table */
8342 char_u *varp, /* pointer to the option variable */
8343 int value, /* new value */
8344 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345{
8346 int old_value = *(int *)varp;
8347
Bram Moolenaar071d4272004-06-13 20:20:40 +00008348 /* Disallow changing some options from secure mode */
8349 if ((secure
8350#ifdef HAVE_SANDBOX
8351 || sandbox != 0
8352#endif
8353 ) && (options[opt_idx].flags & P_SECURE))
8354 return e_secure;
8355
8356 *(int *)varp = value; /* set the new value */
8357#ifdef FEAT_EVAL
8358 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008359 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360#endif
8361
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008362#ifdef FEAT_GUI
8363 need_mouse_correct = TRUE;
8364#endif
8365
Bram Moolenaar071d4272004-06-13 20:20:40 +00008366 /* May set global value for local option. */
8367 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8368 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8369
8370 /*
8371 * Handle side effects of changing a bool option.
8372 */
8373
8374 /* 'compatible' */
8375 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008376 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008377
Bram Moolenaar920694c2016-08-21 17:45:02 +02008378#ifdef FEAT_LANGMAP
8379 if ((int *)varp == &p_lrm)
8380 /* 'langremap' -> !'langnoremap' */
8381 p_lnr = !p_lrm;
8382 else if ((int *)varp == &p_lnr)
8383 /* 'langnoremap' -> !'langremap' */
8384 p_lrm = !p_lnr;
8385#endif
8386
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008387#ifdef FEAT_SYN_HL
8388 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8389 reset_cursorline();
8390#endif
8391
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008392#ifdef FEAT_PERSISTENT_UNDO
8393 /* 'undofile' */
8394 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8395 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008396 /* Only take action when the option was set. When reset we do not
8397 * delete the undo file, the option may be set again without making
8398 * any changes in between. */
8399 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008400 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008401 char_u hash[UNDO_HASH_SIZE];
8402 buf_T *save_curbuf = curbuf;
8403
Bram Moolenaar29323592016-07-24 22:04:11 +02008404 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008405 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008406 /* When 'undofile' is set globally: for every buffer, otherwise
8407 * only for the current buffer: Try to read in the undofile,
8408 * if one exists, the buffer wasn't changed and the buffer was
8409 * loaded */
8410 if ((curbuf == save_curbuf
8411 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8412 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8413 {
8414 u_compute_hash(hash);
8415 u_read_undo(NULL, hash, curbuf->b_fname);
8416 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008417 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008418 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008419 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008420 }
8421#endif
8422
Bram Moolenaar071d4272004-06-13 20:20:40 +00008423 else if ((int *)varp == &curbuf->b_p_ro)
8424 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008425 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008426 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8427 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008428
8429 /* when 'readonly' is set may give W10 again */
8430 if (curbuf->b_p_ro)
8431 curbuf->b_did_warn = FALSE;
8432
Bram Moolenaar071d4272004-06-13 20:20:40 +00008433#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008434 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008435#endif
8436 }
8437
Bram Moolenaar9c449722010-07-20 18:44:27 +02008438#ifdef FEAT_GUI
8439 else if ((int *)varp == &p_mh)
8440 {
8441 if (!p_mh)
8442 gui_mch_mousehide(FALSE);
8443 }
8444#endif
8445
Bram Moolenaara539df02010-08-01 14:35:05 +02008446 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008447 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008448 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008449# ifdef FEAT_TERMINAL
8450 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008451 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8452 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008453 {
8454 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008455 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008456 }
8457# endif
8458# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008459 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008460# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008461 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008462#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008463 /* when 'endofline' is changed, redraw the window title */
8464 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008465 {
8466 redraw_titles();
8467 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008468 /* when 'fixeol' is changed, redraw the window title */
8469 else if ((int *)varp == &curbuf->b_p_fixeol)
8470 {
8471 redraw_titles();
8472 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008473 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008474 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008475 {
8476 redraw_titles();
8477 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008478#endif
8479
8480 /* when 'bin' is set also set some other options */
8481 else if ((int *)varp == &curbuf->b_p_bin)
8482 {
8483 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8484#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008485 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008486#endif
8487 }
8488
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489 /* when 'buflisted' changes, trigger autocommands */
8490 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8491 {
8492 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8493 NULL, NULL, TRUE, curbuf);
8494 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008495
8496 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8497 else if ((int *)varp == &curbuf->b_p_swf)
8498 {
8499 if (curbuf->b_p_swf && p_uc)
8500 ml_open_file(curbuf); /* create the swap file */
8501 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008502 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8503 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008504 mf_close_file(curbuf, TRUE); /* remove the swap file */
8505 }
8506
8507 /* when 'terse' is set change 'shortmess' */
8508 else if ((int *)varp == &p_terse)
8509 {
8510 char_u *p;
8511
8512 p = vim_strchr(p_shm, SHM_SEARCH);
8513
8514 /* insert 's' in p_shm */
8515 if (p_terse && p == NULL)
8516 {
8517 STRCPY(IObuff, p_shm);
8518 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008519 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 }
8521 /* remove 's' from p_shm */
8522 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008523 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008524 }
8525
8526 /* when 'paste' is set or reset also change other options */
8527 else if ((int *)varp == &p_paste)
8528 {
8529 paste_option_changed();
8530 }
8531
8532 /* when 'insertmode' is set from an autocommand need to do work here */
8533 else if ((int *)varp == &p_im)
8534 {
8535 if (p_im)
8536 {
8537 if ((State & INSERT) == 0)
8538 need_start_insertmode = TRUE;
8539 stop_insert_mode = FALSE;
8540 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008541 /* only reset if it was set previously */
8542 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008543 {
8544 need_start_insertmode = FALSE;
8545 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008546 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008547 clear_cmdline = TRUE; /* remove "(insert)" */
8548 restart_edit = 0;
8549 }
8550 }
8551
8552 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8553 else if ((int *)varp == &p_ic && p_hls)
8554 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008555 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008556 }
8557
8558#ifdef FEAT_SEARCH_EXTRA
8559 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8560 else if ((int *)varp == &p_hls)
8561 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008562 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008563 }
8564#endif
8565
Bram Moolenaar071d4272004-06-13 20:20:40 +00008566 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8567 * at the end of normal_cmd() */
8568 else if ((int *)varp == &curwin->w_p_scb)
8569 {
8570 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008571 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008572 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008573 curwin->w_scbind_pos = curwin->w_topline;
8574 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008576
Bram Moolenaar4033c552017-09-16 20:54:51 +02008577#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008578 /* There can be only one window with 'previewwindow' set. */
8579 else if ((int *)varp == &curwin->w_p_pvw)
8580 {
8581 if (curwin->w_p_pvw)
8582 {
8583 win_T *win;
8584
Bram Moolenaar29323592016-07-24 22:04:11 +02008585 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008586 if (win->w_p_pvw && win != curwin)
8587 {
8588 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008589 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008590 }
8591 }
8592 }
8593#endif
8594
8595 /* when 'textmode' is set or reset also change 'fileformat' */
8596 else if ((int *)varp == &curbuf->b_p_tx)
8597 {
8598 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8599 }
8600
8601 /* when 'textauto' is set or reset also change 'fileformats' */
8602 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008603 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008604 set_string_option_direct((char_u *)"ffs", -1,
8605 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008606 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008607 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008608
8609 /*
8610 * When 'lisp' option changes include/exclude '-' in
8611 * keyword characters.
8612 */
8613#ifdef FEAT_LISP
8614 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8615 {
8616 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8617 }
8618#endif
8619
8620#ifdef FEAT_TITLE
8621 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008622 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008623 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008624 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 }
8626#endif
8627
8628 else if ((int *)varp == &curbuf->b_changed)
8629 {
8630 if (!value)
8631 save_file_ff(curbuf); /* Buffer is unchanged */
8632#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008633 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008634#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008635 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636 }
8637
8638#ifdef BACKSLASH_IN_FILENAME
8639 else if ((int *)varp == &p_ssl)
8640 {
8641 if (p_ssl)
8642 {
8643 psepc = '/';
8644 psepcN = '\\';
8645 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008646 }
8647 else
8648 {
8649 psepc = '\\';
8650 psepcN = '/';
8651 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652 }
8653
8654 /* need to adjust the file name arguments and buffer names. */
8655 buflist_slash_adjust();
8656 alist_slash_adjust();
8657# ifdef FEAT_EVAL
8658 scriptnames_slash_adjust();
8659# endif
8660 }
8661#endif
8662
8663 /* If 'wrap' is set, set w_leftcol to zero. */
8664 else if ((int *)varp == &curwin->w_p_wrap)
8665 {
8666 if (curwin->w_p_wrap)
8667 curwin->w_leftcol = 0;
8668 }
8669
Bram Moolenaar071d4272004-06-13 20:20:40 +00008670 else if ((int *)varp == &p_ea)
8671 {
8672 if (p_ea && !old_value)
8673 win_equal(curwin, FALSE, 0);
8674 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008675
8676 else if ((int *)varp == &p_wiv)
8677 {
8678 /*
8679 * When 'weirdinvert' changed, set/reset 't_xs'.
8680 * Then set 'weirdinvert' according to value of 't_xs'.
8681 */
8682 if (p_wiv && !old_value)
8683 T_XS = (char_u *)"y";
8684 else if (!p_wiv && old_value)
8685 T_XS = empty_option;
8686 p_wiv = (*T_XS != NUL);
8687 }
8688
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008689#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008690 else if ((int *)varp == &p_beval)
8691 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008692 if (!balloonEvalForTerm)
8693 {
8694 if (p_beval && !old_value)
8695 gui_mch_enable_beval_area(balloonEval);
8696 else if (!p_beval && old_value)
8697 gui_mch_disable_beval_area(balloonEval);
8698 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008700#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008701#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008702 else if ((int *)varp == &p_bevalterm)
8703 {
8704 mch_bevalterm_changed();
8705 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008707
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008708#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008709 else if ((int *)varp == &p_acd)
8710 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008711 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008712 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008713 }
8714#endif
8715
8716#ifdef FEAT_DIFF
8717 /* 'diff' */
8718 else if ((int *)varp == &curwin->w_p_diff)
8719 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008720 /* May add or remove the buffer from the list of diff buffers. */
8721 diff_buf_adjust(curwin);
8722# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723 if (foldmethodIsDiff(curwin))
8724 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008725# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008726 }
8727#endif
8728
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008729#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008730 /* 'imdisable' */
8731 else if ((int *)varp == &p_imdisable)
8732 {
8733 /* Only de-activate it here, it will be enabled when changing mode. */
8734 if (p_imdisable)
8735 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008736 else if (State & INSERT)
8737 /* When the option is set from an autocommand, it may need to take
8738 * effect right away. */
8739 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008740 }
8741#endif
8742
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008743#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008744 /* 'spell' */
8745 else if ((int *)varp == &curwin->w_p_spell)
8746 {
8747 if (curwin->w_p_spell)
8748 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008749 char *errmsg = did_set_spelllang(curwin);
8750
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008751 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008752 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008753 }
8754 }
8755#endif
8756
Bram Moolenaar071d4272004-06-13 20:20:40 +00008757#ifdef FEAT_ARABIC
8758 if ((int *)varp == &curwin->w_p_arab)
8759 {
8760 if (curwin->w_p_arab)
8761 {
8762 /*
8763 * 'arabic' is set, handle various sub-settings.
8764 */
8765 if (!p_tbidi)
8766 {
8767 /* set rightleft mode */
8768 if (!curwin->w_p_rl)
8769 {
8770 curwin->w_p_rl = TRUE;
8771 changed_window_setting();
8772 }
8773
8774 /* Enable Arabic shaping (major part of what Arabic requires) */
8775 if (!p_arshape)
8776 {
8777 p_arshape = TRUE;
8778 redraw_later_clear();
8779 }
8780 }
8781
8782 /* Arabic requires a utf-8 encoding, inform the user if its not
8783 * set. */
8784 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008785 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008786 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8787
Bram Moolenaar8820b482017-03-16 17:23:31 +01008788 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008789 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008790#ifdef FEAT_EVAL
8791 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8792#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008793 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008794
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795 /* set 'delcombine' */
8796 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797
8798# ifdef FEAT_KEYMAP
8799 /* Force-set the necessary keymap for arabic */
8800 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8801 OPT_LOCAL);
8802# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008803 }
8804 else
8805 {
8806 /*
8807 * 'arabic' is reset, handle various sub-settings.
8808 */
8809 if (!p_tbidi)
8810 {
8811 /* reset rightleft mode */
8812 if (curwin->w_p_rl)
8813 {
8814 curwin->w_p_rl = FALSE;
8815 changed_window_setting();
8816 }
8817
8818 /* 'arabicshape' isn't reset, it is a global option and
8819 * another window may still need it "on". */
8820 }
8821
8822 /* 'delcombine' isn't reset, it is a global option and another
8823 * window may still want it "on". */
8824
8825# ifdef FEAT_KEYMAP
8826 /* Revert to the default keymap */
8827 curbuf->b_p_iminsert = B_IMODE_NONE;
8828 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8829# endif
8830 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008831 }
8832
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008833#endif
8834
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008835#ifdef FEAT_TERMGUICOLORS
8836 /* 'termguicolors' */
8837 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008838 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008839# ifdef FEAT_VTP
8840 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
8841 if (!has_vtp_working())
8842 {
8843 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008844 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008845 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008846 if (is_term_win32())
8847 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008848# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008849# ifdef FEAT_GUI
8850 if (!gui.in_use && !gui.starting)
8851# endif
8852 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008853# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008854 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008855 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008856 {
8857 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008858 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008859 init_highlight(TRUE, FALSE);
8860 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008861# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008862 }
8863#endif
8864
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 /*
8866 * End of handling side effects for bool options.
8867 */
8868
Bram Moolenaar53744302015-07-17 17:38:22 +02008869 /* after handling side effects, call autocommand */
8870
Bram Moolenaar071d4272004-06-13 20:20:40 +00008871 options[opt_idx].flags |= P_WAS_SET;
8872
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008873#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008874 // Don't do this while starting up or recursively.
8875 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008876 {
8877 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008878
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008879 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8880 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8881 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008882 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8883 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8884 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8885 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8886 reset_v_option_vars();
8887 }
8888#endif
8889
Bram Moolenaar071d4272004-06-13 20:20:40 +00008890 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008891 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008892 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008893 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008894 check_redraw(options[opt_idx].flags);
8895
8896 return NULL;
8897}
8898
8899/*
8900 * Set the value of a number option, and take care of side effects.
8901 * Returns NULL for success, or an error message for an error.
8902 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008903 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008904set_num_option(
8905 int opt_idx, /* index in options[] table */
8906 char_u *varp, /* pointer to the option variable */
8907 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008908 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008909 size_t errbuflen, /* length of "errbuf" */
8910 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008911 OPT_MODELINE */
8912{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008913 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008914 long old_value = *(long *)varp;
8915 long old_Rows = Rows; /* remember old Rows */
8916 long old_Columns = Columns; /* remember old Columns */
8917 long *pp = (long *)varp;
8918
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008919 /* Disallow changing some options from secure mode. */
8920 if ((secure
8921#ifdef HAVE_SANDBOX
8922 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008924 ) && (options[opt_idx].flags & P_SECURE))
8925 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926
8927 *pp = value;
8928#ifdef FEAT_EVAL
8929 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008930 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008931#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008932#ifdef FEAT_GUI
8933 need_mouse_correct = TRUE;
8934#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935
Bram Moolenaar14f24742012-08-08 18:01:05 +02008936 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008937 {
8938 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008939#ifdef FEAT_VARTABS
8940 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8941 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8942 ? tabstop_first(curbuf->b_p_vts_array)
8943 : curbuf->b_p_ts;
8944#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008946#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008947 }
8948
8949 /*
8950 * Number options that need some action when changed
8951 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952 if (pp == &p_wh || pp == &p_hh)
8953 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008954 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008955 if (p_wh < 1)
8956 {
8957 errmsg = e_positive;
8958 p_wh = 1;
8959 }
8960 if (p_wmh > p_wh)
8961 {
8962 errmsg = e_winheight;
8963 p_wh = p_wmh;
8964 }
8965 if (p_hh < 0)
8966 {
8967 errmsg = e_positive;
8968 p_hh = 0;
8969 }
8970
8971 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008972 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973 {
8974 if (pp == &p_wh && curwin->w_height < p_wh)
8975 win_setheight((int)p_wh);
8976 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8977 win_setheight((int)p_hh);
8978 }
8979 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008980 else if (pp == &p_wmh)
8981 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008982 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008983 if (p_wmh < 0)
8984 {
8985 errmsg = e_positive;
8986 p_wmh = 0;
8987 }
8988 if (p_wmh > p_wh)
8989 {
8990 errmsg = e_winheight;
8991 p_wmh = p_wh;
8992 }
8993 win_setminheight();
8994 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008995 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008996 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008997 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008998 if (p_wiw < 1)
8999 {
9000 errmsg = e_positive;
9001 p_wiw = 1;
9002 }
9003 if (p_wmw > p_wiw)
9004 {
9005 errmsg = e_winwidth;
9006 p_wiw = p_wmw;
9007 }
9008
9009 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009010 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009011 win_setwidth((int)p_wiw);
9012 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013 else if (pp == &p_wmw)
9014 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009015 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016 if (p_wmw < 0)
9017 {
9018 errmsg = e_positive;
9019 p_wmw = 0;
9020 }
9021 if (p_wmw > p_wiw)
9022 {
9023 errmsg = e_winwidth;
9024 p_wmw = p_wiw;
9025 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009026 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009027 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009028
Bram Moolenaar071d4272004-06-13 20:20:40 +00009029 /* (re)set last window status line */
9030 else if (pp == &p_ls)
9031 {
9032 last_status(FALSE);
9033 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009034
9035 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009036 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009037 {
9038 shell_new_rows(); /* recompute window positions and heights */
9039 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009040
9041#ifdef FEAT_GUI
9042 else if (pp == &p_linespace)
9043 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009044 /* Recompute gui.char_height and resize the Vim window to keep the
9045 * same number of lines. */
9046 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009047 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009048 }
9049#endif
9050
9051#ifdef FEAT_FOLDING
9052 /* 'foldlevel' */
9053 else if (pp == &curwin->w_p_fdl)
9054 {
9055 if (curwin->w_p_fdl < 0)
9056 curwin->w_p_fdl = 0;
9057 newFoldLevel();
9058 }
9059
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009060 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061 else if (pp == &curwin->w_p_fml)
9062 {
9063 foldUpdateAll(curwin);
9064 }
9065
9066 /* 'foldnestmax' */
9067 else if (pp == &curwin->w_p_fdn)
9068 {
9069 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9070 foldUpdateAll(curwin);
9071 }
9072
9073 /* 'foldcolumn' */
9074 else if (pp == &curwin->w_p_fdc)
9075 {
9076 if (curwin->w_p_fdc < 0)
9077 {
9078 errmsg = e_positive;
9079 curwin->w_p_fdc = 0;
9080 }
9081 else if (curwin->w_p_fdc > 12)
9082 {
9083 errmsg = e_invarg;
9084 curwin->w_p_fdc = 12;
9085 }
9086 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009087#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009088
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009089#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009090 /* 'shiftwidth' or 'tabstop' */
9091 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9092 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009093# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094 if (foldmethodIsIndent(curwin))
9095 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009096# endif
9097# ifdef FEAT_CINDENT
9098 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9099 * parse 'cinoptions'. */
9100 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9101 parse_cino(curbuf);
9102# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009104#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009105
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009106 /* 'maxcombine' */
9107 else if (pp == &p_mco)
9108 {
9109 if (p_mco > MAX_MCO)
9110 p_mco = MAX_MCO;
9111 else if (p_mco < 0)
9112 p_mco = 0;
9113 screenclear(); /* will re-allocate the screen */
9114 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009115
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 else if (pp == &curbuf->b_p_iminsert)
9117 {
9118 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9119 {
9120 errmsg = e_invarg;
9121 curbuf->b_p_iminsert = B_IMODE_NONE;
9122 }
9123 p_iminsert = curbuf->b_p_iminsert;
9124 if (termcap_active) /* don't do this in the alternate screen */
9125 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009126#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009127 /* Show/unshow value of 'keymap' in status lines. */
9128 status_redraw_curbuf();
9129#endif
9130 }
9131
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009132#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9133 /* 'imstyle' */
9134 else if (pp == &p_imst)
9135 {
9136 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9137 errmsg = e_invarg;
9138 }
9139#endif
9140
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009141 else if (pp == &p_window)
9142 {
9143 if (p_window < 1)
9144 p_window = 1;
9145 else if (p_window >= Rows)
9146 p_window = Rows - 1;
9147 }
9148
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149 else if (pp == &curbuf->b_p_imsearch)
9150 {
9151 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9152 {
9153 errmsg = e_invarg;
9154 curbuf->b_p_imsearch = B_IMODE_NONE;
9155 }
9156 p_imsearch = curbuf->b_p_imsearch;
9157 }
9158
9159#ifdef FEAT_TITLE
9160 /* if 'titlelen' has changed, redraw the title */
9161 else if (pp == &p_titlelen)
9162 {
9163 if (p_titlelen < 0)
9164 {
9165 errmsg = e_positive;
9166 p_titlelen = 85;
9167 }
9168 if (starting != NO_SCREEN && old_value != p_titlelen)
9169 need_maketitle = TRUE;
9170 }
9171#endif
9172
9173 /* if p_ch changed value, change the command line height */
9174 else if (pp == &p_ch)
9175 {
9176 if (p_ch < 1)
9177 {
9178 errmsg = e_positive;
9179 p_ch = 1;
9180 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009181 if (p_ch > Rows - min_rows() + 1)
9182 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009183
9184 /* Only compute the new window layout when startup has been
9185 * completed. Otherwise the frame sizes may be wrong. */
9186 if (p_ch != old_value && full_screen
9187#ifdef FEAT_GUI
9188 && !gui.starting
9189#endif
9190 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009191 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192 }
9193
9194 /* when 'updatecount' changes from zero to non-zero, open swap files */
9195 else if (pp == &p_uc)
9196 {
9197 if (p_uc < 0)
9198 {
9199 errmsg = e_positive;
9200 p_uc = 100;
9201 }
9202 if (p_uc && !old_value)
9203 ml_open_files();
9204 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009205#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009206 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009207 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009208 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009209 {
9210 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009211 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009212 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009213 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009214 {
9215 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009216 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009217 }
9218 }
9219#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009220#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009221 else if (pp == &p_mzq)
9222 mzvim_reset_timer();
9223#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009224
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009225#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9226 /* 'pyxversion' */
9227 else if (pp == &p_pyx)
9228 {
9229 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9230 errmsg = e_invarg;
9231 }
9232#endif
9233
Bram Moolenaar071d4272004-06-13 20:20:40 +00009234 /* sync undo before 'undolevels' changes */
9235 else if (pp == &p_ul)
9236 {
9237 /* use the old value, otherwise u_sync() may not work properly */
9238 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009239 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009240 p_ul = value;
9241 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009242 else if (pp == &curbuf->b_p_ul)
9243 {
9244 /* use the old value, otherwise u_sync() may not work properly */
9245 curbuf->b_p_ul = old_value;
9246 u_sync(TRUE);
9247 curbuf->b_p_ul = value;
9248 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009250#ifdef FEAT_LINEBREAK
9251 /* 'numberwidth' must be positive */
9252 else if (pp == &curwin->w_p_nuw)
9253 {
9254 if (curwin->w_p_nuw < 1)
9255 {
9256 errmsg = e_positive;
9257 curwin->w_p_nuw = 1;
9258 }
9259 if (curwin->w_p_nuw > 10)
9260 {
9261 errmsg = e_invarg;
9262 curwin->w_p_nuw = 10;
9263 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009264 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009265 }
9266#endif
9267
Bram Moolenaar1a384422010-07-14 19:53:30 +02009268 else if (pp == &curbuf->b_p_tw)
9269 {
9270 if (curbuf->b_p_tw < 0)
9271 {
9272 errmsg = e_positive;
9273 curbuf->b_p_tw = 0;
9274 }
9275#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009276 {
9277 win_T *wp;
9278 tabpage_T *tp;
9279
9280 FOR_ALL_TAB_WINDOWS(tp, wp)
9281 check_colorcolumn(wp);
9282 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009283#endif
9284 }
9285
Bram Moolenaar071d4272004-06-13 20:20:40 +00009286 /*
9287 * Check the bounds for numeric options here
9288 */
9289 if (Rows < min_rows() && full_screen)
9290 {
9291 if (errbuf != NULL)
9292 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009293 vim_snprintf((char *)errbuf, errbuflen,
9294 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295 errmsg = errbuf;
9296 }
9297 Rows = min_rows();
9298 }
9299 if (Columns < MIN_COLUMNS && full_screen)
9300 {
9301 if (errbuf != NULL)
9302 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009303 vim_snprintf((char *)errbuf, errbuflen,
9304 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009305 errmsg = errbuf;
9306 }
9307 Columns = MIN_COLUMNS;
9308 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009309 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009310
Bram Moolenaar071d4272004-06-13 20:20:40 +00009311 /*
9312 * If the screen (shell) height has been changed, assume it is the
9313 * physical screenheight.
9314 */
9315 if (old_Rows != Rows || old_Columns != Columns)
9316 {
9317 /* Changing the screen size is not allowed while updating the screen. */
9318 if (updating_screen)
9319 *pp = old_value;
9320 else if (full_screen
9321#ifdef FEAT_GUI
9322 && !gui.starting
9323#endif
9324 )
9325 set_shellsize((int)Columns, (int)Rows, TRUE);
9326 else
9327 {
9328 /* Postpone the resizing; check the size and cmdline position for
9329 * messages. */
9330 check_shellsize();
9331 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9332 cmdline_row = Rows - p_ch;
9333 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009334 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009335 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336 }
9337
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338 if (curbuf->b_p_ts <= 0)
9339 {
9340 errmsg = e_positive;
9341 curbuf->b_p_ts = 8;
9342 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009343 if (p_tm < 0)
9344 {
9345 errmsg = e_positive;
9346 p_tm = 0;
9347 }
9348 if ((curwin->w_p_scr <= 0
9349 || (curwin->w_p_scr > curwin->w_height
9350 && curwin->w_height > 0))
9351 && full_screen)
9352 {
9353 if (pp == &(curwin->w_p_scr))
9354 {
9355 if (curwin->w_p_scr != 0)
9356 errmsg = e_scroll;
9357 win_comp_scroll(curwin);
9358 }
9359 /* If 'scroll' became invalid because of a side effect silently adjust
9360 * it. */
9361 else if (curwin->w_p_scr <= 0)
9362 curwin->w_p_scr = 1;
9363 else /* curwin->w_p_scr > curwin->w_height */
9364 curwin->w_p_scr = curwin->w_height;
9365 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009366 if (p_hi < 0)
9367 {
9368 errmsg = e_positive;
9369 p_hi = 0;
9370 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009371 else if (p_hi > 10000)
9372 {
9373 errmsg = e_invarg;
9374 p_hi = 10000;
9375 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009376 if (p_re < 0 || p_re > 2)
9377 {
9378 errmsg = e_invarg;
9379 p_re = 0;
9380 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009381 if (p_report < 0)
9382 {
9383 errmsg = e_positive;
9384 p_report = 1;
9385 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009386 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009387 {
9388 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9389 p_sj = Rows / 2;
9390 else
9391 {
9392 errmsg = e_scroll;
9393 p_sj = 1;
9394 }
9395 }
9396 if (p_so < 0 && full_screen)
9397 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009398 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009399 p_so = 0;
9400 }
9401 if (p_siso < 0 && full_screen)
9402 {
9403 errmsg = e_positive;
9404 p_siso = 0;
9405 }
9406#ifdef FEAT_CMDWIN
9407 if (p_cwh < 1)
9408 {
9409 errmsg = e_positive;
9410 p_cwh = 1;
9411 }
9412#endif
9413 if (p_ut < 0)
9414 {
9415 errmsg = e_positive;
9416 p_ut = 2000;
9417 }
9418 if (p_ss < 0)
9419 {
9420 errmsg = e_positive;
9421 p_ss = 0;
9422 }
9423
9424 /* May set global value for local option. */
9425 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9426 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9427
9428 options[opt_idx].flags |= P_WAS_SET;
9429
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009430#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009431 // Don't do this while starting up, failure or recursively.
9432 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009433 {
9434 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01009435
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009436 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9437 vim_snprintf((char *)buf_new, 10, "%ld", value);
9438 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009439 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9440 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9441 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9442 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9443 reset_v_option_vars();
9444 }
9445#endif
9446
Bram Moolenaar071d4272004-06-13 20:20:40 +00009447 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009448 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009449 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009450 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009451 check_redraw(options[opt_idx].flags);
9452
9453 return errmsg;
9454}
9455
9456/*
9457 * Called after an option changed: check if something needs to be redrawn.
9458 */
9459 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009460check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009461{
9462 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009463 int doclear = (flags & P_RCLR) == P_RCLR;
9464 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009465
Bram Moolenaar071d4272004-06-13 20:20:40 +00009466 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9467 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009468
9469 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9470 changed_window_setting();
9471 if (flags & P_RBUF)
9472 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009473 if (flags & P_RWINONLY)
9474 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009475 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009476 redraw_all_later(CLEAR);
9477 else if (all)
9478 redraw_all_later(NOT_VALID);
9479}
9480
9481/*
9482 * Find index for option 'arg'.
9483 * Return -1 if not found.
9484 */
9485 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009486findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009487{
9488 int opt_idx;
9489 char *s, *p;
9490 static short quick_tab[27] = {0, 0}; /* quick access table */
9491 int is_term_opt;
9492
9493 /*
9494 * For first call: Initialize the quick-access table.
9495 * It contains the index for the first option that starts with a certain
9496 * letter. There are 26 letters, plus the first "t_" option.
9497 */
9498 if (quick_tab[1] == 0)
9499 {
9500 p = options[0].fullname;
9501 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9502 {
9503 if (s[0] != p[0])
9504 {
9505 if (s[0] == 't' && s[1] == '_')
9506 quick_tab[26] = opt_idx;
9507 else
9508 quick_tab[CharOrdLow(s[0])] = opt_idx;
9509 }
9510 p = s;
9511 }
9512 }
9513
9514 /*
9515 * Check for name starting with an illegal character.
9516 */
9517#ifdef EBCDIC
9518 if (!islower(arg[0]))
9519#else
9520 if (arg[0] < 'a' || arg[0] > 'z')
9521#endif
9522 return -1;
9523
9524 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9525 if (is_term_opt)
9526 opt_idx = quick_tab[26];
9527 else
9528 opt_idx = quick_tab[CharOrdLow(arg[0])];
9529 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9530 {
9531 if (STRCMP(arg, s) == 0) /* match full name */
9532 break;
9533 }
9534 if (s == NULL && !is_term_opt)
9535 {
9536 opt_idx = quick_tab[CharOrdLow(arg[0])];
9537 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9538 {
9539 s = options[opt_idx].shortname;
9540 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9541 break;
9542 s = NULL;
9543 }
9544 }
9545 if (s == NULL)
9546 opt_idx = -1;
9547 return opt_idx;
9548}
9549
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009550#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009551/*
9552 * Get the value for an option.
9553 *
9554 * Returns:
9555 * Number or Toggle option: 1, *numval gets value.
9556 * String option: 0, *stringval gets allocated string.
9557 * Hidden Number or Toggle option: -1.
9558 * hidden String option: -2.
9559 * unknown option: -3.
9560 */
9561 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009562get_option_value(
9563 char_u *name,
9564 long *numval,
9565 char_u **stringval, /* NULL when only checking existence */
9566 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567{
9568 int opt_idx;
9569 char_u *varp;
9570
9571 opt_idx = findoption(name);
9572 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009573 {
9574 int key;
9575
9576 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009577 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009578 {
9579 char_u key_name[2];
9580 char_u *p;
9581
9582 if (key < 0)
9583 {
9584 key_name[0] = KEY2TERMCAP0(key);
9585 key_name[1] = KEY2TERMCAP1(key);
9586 }
9587 else
9588 {
9589 key_name[0] = KS_KEY;
9590 key_name[1] = (key & 0xff);
9591 }
9592 p = find_termcode(key_name);
9593 if (p != NULL)
9594 {
9595 if (stringval != NULL)
9596 *stringval = vim_strsave(p);
9597 return 0;
9598 }
9599 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009600 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009601 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009602
9603 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9604
9605 if (options[opt_idx].flags & P_STRING)
9606 {
9607 if (varp == NULL) /* hidden option */
9608 return -2;
9609 if (stringval != NULL)
9610 {
9611#ifdef FEAT_CRYPT
9612 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009613 if ((char_u **)varp == &curbuf->b_p_key
9614 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009615 *stringval = vim_strsave((char_u *)"*****");
9616 else
9617#endif
9618 *stringval = vim_strsave(*(char_u **)(varp));
9619 }
9620 return 0;
9621 }
9622
9623 if (varp == NULL) /* hidden option */
9624 return -1;
9625 if (options[opt_idx].flags & P_NUM)
9626 *numval = *(long *)varp;
9627 else
9628 {
9629 /* Special case: 'modified' is b_changed, but we also want to consider
9630 * it set when 'ff' or 'fenc' changed. */
9631 if ((int *)varp == &curbuf->b_changed)
9632 *numval = curbufIsChanged();
9633 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009634 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009635 }
9636 return 1;
9637}
9638#endif
9639
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009640#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009641/*
9642 * Returns the option attributes and its value. Unlike the above function it
9643 * will return either global value or local value of the option depending on
9644 * what was requested, but it will never return global value if it was
9645 * requested to return local one and vice versa. Neither it will return
9646 * buffer-local value if it was requested to return window-local one.
9647 *
9648 * Pretends that option is absent if it is not present in the requested scope
9649 * (i.e. has no global, window-local or buffer-local value depending on
9650 * opt_type). Uses
9651 *
9652 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009653 * 0 hidden or unknown option, also option that does not have requested
9654 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009655 * see SOPT_* in vim.h for other flags
9656 *
9657 * Possible opt_type values: see SREQ_* in vim.h
9658 */
9659 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009660get_option_value_strict(
9661 char_u *name,
9662 long *numval,
9663 char_u **stringval, /* NULL when only obtaining attributes */
9664 int opt_type,
9665 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009666{
9667 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009668 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009669 struct vimoption *p;
9670 int r = 0;
9671
9672 opt_idx = findoption(name);
9673 if (opt_idx < 0)
9674 return 0;
9675
9676 p = &(options[opt_idx]);
9677
9678 /* Hidden option */
9679 if (p->var == NULL)
9680 return 0;
9681
9682 if (p->flags & P_BOOL)
9683 r |= SOPT_BOOL;
9684 else if (p->flags & P_NUM)
9685 r |= SOPT_NUM;
9686 else if (p->flags & P_STRING)
9687 r |= SOPT_STRING;
9688
9689 if (p->indir == PV_NONE)
9690 {
9691 if (opt_type == SREQ_GLOBAL)
9692 r |= SOPT_GLOBAL;
9693 else
9694 return 0; /* Did not request global-only option */
9695 }
9696 else
9697 {
9698 if (p->indir & PV_BOTH)
9699 r |= SOPT_GLOBAL;
9700 else if (opt_type == SREQ_GLOBAL)
9701 return 0; /* Requested global option */
9702
9703 if (p->indir & PV_WIN)
9704 {
9705 if (opt_type == SREQ_BUF)
9706 return 0; /* Did not request window-local option */
9707 else
9708 r |= SOPT_WIN;
9709 }
9710 else if (p->indir & PV_BUF)
9711 {
9712 if (opt_type == SREQ_WIN)
9713 return 0; /* Did not request buffer-local option */
9714 else
9715 r |= SOPT_BUF;
9716 }
9717 }
9718
9719 if (stringval == NULL)
9720 return r;
9721
9722 if (opt_type == SREQ_GLOBAL)
9723 varp = p->var;
9724 else
9725 {
9726 if (opt_type == SREQ_BUF)
9727 {
9728 /* Special case: 'modified' is b_changed, but we also want to
9729 * consider it set when 'ff' or 'fenc' changed. */
9730 if (p->indir == PV_MOD)
9731 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009732 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009733 varp = NULL;
9734 }
9735#ifdef FEAT_CRYPT
9736 else if (p->indir == PV_KEY)
9737 {
9738 /* never return the value of the crypt key */
9739 *stringval = NULL;
9740 varp = NULL;
9741 }
9742#endif
9743 else
9744 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009745 buf_T *save_curbuf = curbuf;
9746
9747 // only getting a pointer, no need to use aucmd_prepbuf()
9748 curbuf = (buf_T *)from;
9749 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009750 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009751 curbuf = save_curbuf;
9752 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009753 }
9754 }
9755 else if (opt_type == SREQ_WIN)
9756 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009757 win_T *save_curwin = curwin;
9758
9759 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009760 curbuf = curwin->w_buffer;
9761 varp = get_varp(p);
9762 curwin = save_curwin;
9763 curbuf = curwin->w_buffer;
9764 }
9765 if (varp == p->var)
9766 return (r | SOPT_UNSET);
9767 }
9768
9769 if (varp != NULL)
9770 {
9771 if (p->flags & P_STRING)
9772 *stringval = vim_strsave(*(char_u **)(varp));
9773 else if (p->flags & P_NUM)
9774 *numval = *(long *) varp;
9775 else
9776 *numval = *(int *)varp;
9777 }
9778
9779 return r;
9780}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009781
9782/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009783 * Iterate over options. First argument is a pointer to a pointer to a
9784 * structure inside options[] array, second is option type like in the above
9785 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009786 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009787 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009788 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009789 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009790 * first argument to NULL.
9791 *
9792 * Returns full option name for current option on each call.
9793 */
9794 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009795option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009796{
9797 struct vimoption *ret = NULL;
9798 do
9799 {
9800 if (*option == NULL)
9801 *option = (void *) options;
9802 else if (((struct vimoption *) (*option))->fullname == NULL)
9803 {
9804 *option = NULL;
9805 return NULL;
9806 }
9807 else
9808 *option = (void *) (((struct vimoption *) (*option)) + 1);
9809
9810 ret = ((struct vimoption *) (*option));
9811
9812 /* Hidden option */
9813 if (ret->var == NULL)
9814 {
9815 ret = NULL;
9816 continue;
9817 }
9818
9819 switch (opt_type)
9820 {
9821 case SREQ_GLOBAL:
9822 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9823 ret = NULL;
9824 break;
9825 case SREQ_BUF:
9826 if (!(ret->indir & PV_BUF))
9827 ret = NULL;
9828 break;
9829 case SREQ_WIN:
9830 if (!(ret->indir & PV_WIN))
9831 ret = NULL;
9832 break;
9833 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009834 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009835 return NULL;
9836 }
9837 }
9838 while (ret == NULL);
9839
9840 return (char_u *)ret->fullname;
9841}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009842#endif
9843
Bram Moolenaar071d4272004-06-13 20:20:40 +00009844/*
9845 * Set the value of option "name".
9846 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009847 *
9848 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009849 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009850 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009851set_option_value(
9852 char_u *name,
9853 long number,
9854 char_u *string,
9855 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009856{
9857 int opt_idx;
9858 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009859 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009860
9861 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009862 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009863 {
9864 int key;
9865
9866 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009867 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009868 {
9869 char_u key_name[2];
9870
9871 if (key < 0)
9872 {
9873 key_name[0] = KEY2TERMCAP0(key);
9874 key_name[1] = KEY2TERMCAP1(key);
9875 }
9876 else
9877 {
9878 key_name[0] = KS_KEY;
9879 key_name[1] = (key & 0xff);
9880 }
9881 add_termcode(key_name, string, FALSE);
9882 if (full_screen)
9883 ttest(FALSE);
9884 redraw_all_later(CLEAR);
9885 return NULL;
9886 }
9887
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009888 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009889 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009890 else
9891 {
9892 flags = options[opt_idx].flags;
9893#ifdef HAVE_SANDBOX
9894 /* Disallow changing some options in the sandbox */
9895 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009896 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009897 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009898 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009899 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009900#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009901 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009902 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009903 else
9904 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009905 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009906 if (varp != NULL) /* hidden option is not changed */
9907 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009908 if (number == 0 && string != NULL)
9909 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009910 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009911
9912 /* Either we are given a string or we are setting option
9913 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009914 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009915 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009916 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009917 {
9918 /* There's another character after zeros or the string
9919 * is empty. In both cases, we are trying to set a
9920 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009921 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009922 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009923 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009924
9925 }
9926 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009927 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009928 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009929 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009930 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009931 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009932 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009933 }
9934 }
9935 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009936 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009937}
9938
9939/*
9940 * Get the terminal code for a terminal option.
9941 * Returns NULL when not found.
9942 */
9943 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009944get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009945{
9946 int opt_idx;
9947 char_u *varp;
9948
9949 if (tname[0] != 't' || tname[1] != '_' ||
9950 tname[2] == NUL || tname[3] == NUL)
9951 return NULL;
9952 if ((opt_idx = findoption(tname)) >= 0)
9953 {
9954 varp = get_varp(&(options[opt_idx]));
9955 if (varp != NULL)
9956 varp = *(char_u **)(varp);
9957 return varp;
9958 }
9959 return find_termcode(tname + 2);
9960}
9961
9962 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009963get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009964{
9965 int i;
9966
9967 i = findoption((char_u *)"hl");
9968 if (i >= 0)
9969 return options[i].def_val[VI_DEFAULT];
9970 return (char_u *)NULL;
9971}
9972
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009973 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009974get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009975{
9976 int i;
9977
9978 i = findoption((char_u *)"enc");
9979 if (i >= 0)
9980 return options[i].def_val[VI_DEFAULT];
9981 return (char_u *)NULL;
9982}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009983
Bram Moolenaar071d4272004-06-13 20:20:40 +00009984/*
9985 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009986 * When "has_lt" is true there is a '<' before "*arg_arg".
9987 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009988 */
9989 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009990find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009991{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009992 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009994 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009995
9996 /*
9997 * Don't use get_special_key_code() for t_xx, we don't want it to call
9998 * add_termcap_entry().
9999 */
10000 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10001 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010002 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010003 {
10004 --arg; /* put arg at the '<' */
10005 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010006 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010007 if (modifiers) /* can't handle modifiers here */
10008 key = 0;
10009 }
10010 return key;
10011}
10012
10013/*
10014 * if 'all' == 0: show changed options
10015 * if 'all' == 1: show all normal options
10016 * if 'all' == 2: show all terminal options
10017 */
10018 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010019showoptions(
10020 int all,
10021 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010022{
10023 struct vimoption *p;
10024 int col;
10025 int isterm;
10026 char_u *varp;
10027 struct vimoption **items;
10028 int item_count;
10029 int run;
10030 int row, rows;
10031 int cols;
10032 int i;
10033 int len;
10034
10035#define INC 20
10036#define GAP 3
10037
10038 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10039 PARAM_COUNT));
10040 if (items == NULL)
10041 return;
10042
10043 /* Highlight title */
10044 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010045 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010046 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010047 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010048 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010049 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010050 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010051 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010052
10053 /*
10054 * do the loop two times:
10055 * 1. display the short items
10056 * 2. display the long items (only strings and numbers)
10057 */
10058 for (run = 1; run <= 2 && !got_int; ++run)
10059 {
10060 /*
10061 * collect the items in items[]
10062 */
10063 item_count = 0;
10064 for (p = &options[0]; p->fullname != NULL; p++)
10065 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010066 // apply :filter /pat/
10067 if (message_filtered((char_u *) p->fullname))
10068 continue;
10069
Bram Moolenaar071d4272004-06-13 20:20:40 +000010070 varp = NULL;
10071 isterm = istermoption(p);
10072 if (opt_flags != 0)
10073 {
10074 if (p->indir != PV_NONE && !isterm)
10075 varp = get_varp_scope(p, opt_flags);
10076 }
10077 else
10078 varp = get_varp(p);
10079 if (varp != NULL
10080 && ((all == 2 && isterm)
10081 || (all == 1 && !isterm)
10082 || (all == 0 && !optval_default(p, varp))))
10083 {
10084 if (p->flags & P_BOOL)
10085 len = 1; /* a toggle option fits always */
10086 else
10087 {
10088 option_value2string(p, opt_flags);
10089 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10090 }
10091 if ((len <= INC - GAP && run == 1) ||
10092 (len > INC - GAP && run == 2))
10093 items[item_count++] = p;
10094 }
10095 }
10096
10097 /*
10098 * display the items
10099 */
10100 if (run == 1)
10101 {
10102 cols = (Columns + GAP - 3) / INC;
10103 if (cols == 0)
10104 cols = 1;
10105 rows = (item_count + cols - 1) / cols;
10106 }
10107 else /* run == 2 */
10108 rows = item_count;
10109 for (row = 0; row < rows && !got_int; ++row)
10110 {
10111 msg_putchar('\n'); /* go to next line */
10112 if (got_int) /* 'q' typed in more */
10113 break;
10114 col = 0;
10115 for (i = row; i < item_count; i += rows)
10116 {
10117 msg_col = col; /* make columns */
10118 showoneopt(items[i], opt_flags);
10119 col += INC;
10120 }
10121 out_flush();
10122 ui_breakcheck();
10123 }
10124 }
10125 vim_free(items);
10126}
10127
10128/*
10129 * Return TRUE if option "p" has its default value.
10130 */
10131 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010132optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010133{
10134 int dvi;
10135
10136 if (varp == NULL)
10137 return TRUE; /* hidden option is always at default */
10138 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10139 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010140 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010142 /* the cast to long is required for Manx C, long_i is
10143 * needed for MSVC */
10144 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145 /* P_STRING */
10146 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10147}
10148
10149/*
10150 * showoneopt: show the value of one option
10151 * must not be called with a hidden option!
10152 */
10153 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010154showoneopt(
10155 struct vimoption *p,
10156 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010157{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010158 char_u *varp;
10159 int save_silent = silent_mode;
10160
10161 silent_mode = FALSE;
10162 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010163
10164 varp = get_varp_scope(p, opt_flags);
10165
10166 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10167 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10168 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010169 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010170 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010171 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010173 msg_puts(" ");
10174 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010175 if (!(p->flags & P_BOOL))
10176 {
10177 msg_putchar('=');
10178 /* put value string in NameBuff */
10179 option_value2string(p, opt_flags);
10180 msg_outtrans(NameBuff);
10181 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010182
10183 silent_mode = save_silent;
10184 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185}
10186
10187/*
10188 * Write modified options as ":set" commands to a file.
10189 *
10190 * There are three values for "opt_flags":
10191 * OPT_GLOBAL: Write global option values and fresh values of
10192 * buffer-local options (used for start of a session
10193 * file).
10194 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10195 * curwin (used for a vimrc file).
10196 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10197 * and local values for window-local options of
10198 * curwin. Local values are also written when at the
10199 * default value, because a modeline or autocommand
10200 * may have set them when doing ":edit file" and the
10201 * user has set them back at the default or fresh
10202 * value.
10203 * When "local_only" is TRUE, don't write fresh
10204 * values, only local values (for ":mkview").
10205 * (fresh value = value used for a new buffer or window for a local option).
10206 *
10207 * Return FAIL on error, OK otherwise.
10208 */
10209 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010210makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211{
10212 struct vimoption *p;
10213 char_u *varp; /* currently used value */
10214 char_u *varp_fresh; /* local value */
10215 char_u *varp_local = NULL; /* fresh value */
10216 char *cmd;
10217 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010218 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219
10220 /*
10221 * The options that don't have a default (terminal name, columns, lines)
10222 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010223 * Do the loop over "options[]" twice: once for options with the
10224 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010225 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010226 for (pri = 1; pri >= 0; --pri)
10227 {
10228 for (p = &options[0]; !istermoption(p); p++)
10229 if (!(p->flags & P_NO_MKRC)
10230 && !istermoption(p)
10231 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010232 {
10233 /* skip global option when only doing locals */
10234 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10235 continue;
10236
10237 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10238 * file, they are always buffer-specific. */
10239 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10240 continue;
10241
10242 /* Global values are only written when not at the default value. */
10243 varp = get_varp_scope(p, opt_flags);
10244 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10245 continue;
10246
10247 round = 2;
10248 if (p->indir != PV_NONE)
10249 {
10250 if (p->var == VAR_WIN)
10251 {
10252 /* skip window-local option when only doing globals */
10253 if (!(opt_flags & OPT_LOCAL))
10254 continue;
10255 /* When fresh value of window-local option is not at the
10256 * default, need to write it too. */
10257 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10258 {
10259 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10260 if (!optval_default(p, varp_fresh))
10261 {
10262 round = 1;
10263 varp_local = varp;
10264 varp = varp_fresh;
10265 }
10266 }
10267 }
10268 }
10269
10270 /* Round 1: fresh value for window-local options.
10271 * Round 2: other values */
10272 for ( ; round <= 2; varp = varp_local, ++round)
10273 {
10274 if (round == 1 || (opt_flags & OPT_GLOBAL))
10275 cmd = "set";
10276 else
10277 cmd = "setlocal";
10278
10279 if (p->flags & P_BOOL)
10280 {
10281 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10282 return FAIL;
10283 }
10284 else if (p->flags & P_NUM)
10285 {
10286 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10287 return FAIL;
10288 }
10289 else /* P_STRING */
10290 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010291 int do_endif = FALSE;
10292
Bram Moolenaar071d4272004-06-13 20:20:40 +000010293 /* Don't set 'syntax' and 'filetype' again if the value is
10294 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010295 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010296#if defined(FEAT_SYN_HL)
10297 p->indir == PV_SYN ||
10298#endif
10299 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300 {
10301 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10302 *(char_u **)(varp)) < 0
10303 || put_eol(fd) < 0)
10304 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010305 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306 }
10307 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010308 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010310 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010311 {
10312 if (put_line(fd, "endif") == FAIL)
10313 return FAIL;
10314 }
10315 }
10316 }
10317 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010319 return OK;
10320}
10321
10322#if defined(FEAT_FOLDING) || defined(PROTO)
10323/*
10324 * Generate set commands for the local fold options only. Used when
10325 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10326 */
10327 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010328makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010329{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010330 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010331# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010332 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010333 == FAIL
10334# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010335 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010336 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010337 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010338 == FAIL
10339 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10340 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10341 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10342 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10343 )
10344 return FAIL;
10345
10346 return OK;
10347}
10348#endif
10349
10350 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010351put_setstring(
10352 FILE *fd,
10353 char *cmd,
10354 char *name,
10355 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010356 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010357{
10358 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010359 char_u *buf = NULL;
10360 char_u *part = NULL;
10361 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010362
10363 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10364 return FAIL;
10365 if (*valuep != NULL)
10366 {
10367 /* Output 'pastetoggle' as key names. For other
10368 * options some characters have to be escaped with
10369 * CTRL-V or backslash */
10370 if (valuep == &p_pt)
10371 {
10372 s = *valuep;
10373 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010374 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010375 return FAIL;
10376 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010377 // expand the option value, replace $HOME by ~
10378 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010379 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010380 int size = (int)STRLEN(*valuep) + 1;
10381
10382 // replace home directory in the whole option value into "buf"
10383 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010384 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010385 goto fail;
10386 home_replace(NULL, *valuep, buf, size, FALSE);
10387
10388 // If the option value is longer than MAXPATHL, we need to append
10389 // earch comma separated part of the option separately, so that it
10390 // can be expanded when read back.
10391 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10392 && vim_strchr(*valuep, ',') != NULL)
10393 {
10394 part = alloc(size);
10395 if (part == NULL)
10396 goto fail;
10397
10398 // write line break to clear the option, e.g. ':set rtp='
10399 if (put_eol(fd) == FAIL)
10400 goto fail;
10401
10402 p = buf;
10403 while (*p != NUL)
10404 {
10405 // for each comma separated option part, append value to
10406 // the option, :set rtp+=value
10407 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10408 goto fail;
10409 (void)copy_option_part(&p, part, size, ",");
10410 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10411 goto fail;
10412 }
10413 vim_free(buf);
10414 vim_free(part);
10415 return OK;
10416 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010418 {
10419 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010420 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010421 }
10422 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010423 }
10424 else if (put_escstr(fd, *valuep, 2) == FAIL)
10425 return FAIL;
10426 }
10427 if (put_eol(fd) < 0)
10428 return FAIL;
10429 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010430fail:
10431 vim_free(buf);
10432 vim_free(part);
10433 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010434}
10435
10436 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010437put_setnum(
10438 FILE *fd,
10439 char *cmd,
10440 char *name,
10441 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010442{
10443 long wc;
10444
10445 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10446 return FAIL;
10447 if (wc_use_keyname((char_u *)valuep, &wc))
10448 {
10449 /* print 'wildchar' and 'wildcharm' as a key name */
10450 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10451 return FAIL;
10452 }
10453 else if (fprintf(fd, "%ld", *valuep) < 0)
10454 return FAIL;
10455 if (put_eol(fd) < 0)
10456 return FAIL;
10457 return OK;
10458}
10459
10460 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010461put_setbool(
10462 FILE *fd,
10463 char *cmd,
10464 char *name,
10465 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010466{
Bram Moolenaar893de922007-10-02 18:40:57 +000010467 if (value < 0) /* global/local option using global value */
10468 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010469 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10470 || put_eol(fd) < 0)
10471 return FAIL;
10472 return OK;
10473}
10474
10475/*
10476 * Clear all the terminal options.
10477 * If the option has been allocated, free the memory.
10478 * Terminal options are never hidden or indirect.
10479 */
10480 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010481clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010482{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010483 /*
10484 * Reset a few things before clearing the old options. This may cause
10485 * outputting a few things that the terminal doesn't understand, but the
10486 * screen will be cleared later, so this is OK.
10487 */
10488#ifdef FEAT_MOUSE_TTY
10489 mch_setmouse(FALSE); /* switch mouse off */
10490#endif
10491#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010492 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493#endif
10494#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10495 /* When starting the GUI close the display opened for the clipboard.
10496 * After restoring the title, because that will need the display. */
10497 if (gui.starting)
10498 clear_xterm_clip();
10499#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010500 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010502 free_termoptions();
10503}
10504
10505 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010506free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010507{
10508 struct vimoption *p;
10509
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010510 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010511 if (istermoption(p))
10512 {
10513 if (p->flags & P_ALLOCED)
10514 free_string_option(*(char_u **)(p->var));
10515 if (p->flags & P_DEF_ALLOCED)
10516 free_string_option(p->def_val[VI_DEFAULT]);
10517 *(char_u **)(p->var) = empty_option;
10518 p->def_val[VI_DEFAULT] = empty_option;
10519 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010520#ifdef FEAT_EVAL
10521 // remember where the option was cleared
10522 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10523#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010524 }
10525 clear_termcodes();
10526}
10527
10528/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010529 * Free the string for one term option, if it was allocated.
10530 * Set the string to empty_option and clear allocated flag.
10531 * "var" points to the option value.
10532 */
10533 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010534free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010535{
10536 struct vimoption *p;
10537
10538 for (p = &options[0]; p->fullname != NULL; p++)
10539 if (p->var == var)
10540 {
10541 if (p->flags & P_ALLOCED)
10542 free_string_option(*(char_u **)(p->var));
10543 *(char_u **)(p->var) = empty_option;
10544 p->flags &= ~P_ALLOCED;
10545 break;
10546 }
10547}
10548
10549/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010550 * Set the terminal option defaults to the current value.
10551 * Used after setting the terminal name.
10552 */
10553 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010554set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010555{
10556 struct vimoption *p;
10557
10558 for (p = &options[0]; p->fullname != NULL; p++)
10559 {
10560 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10561 {
10562 if (p->flags & P_DEF_ALLOCED)
10563 {
10564 free_string_option(p->def_val[VI_DEFAULT]);
10565 p->flags &= ~P_DEF_ALLOCED;
10566 }
10567 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10568 if (p->flags & P_ALLOCED)
10569 {
10570 p->flags |= P_DEF_ALLOCED;
10571 p->flags &= ~P_ALLOCED; /* don't free the value now */
10572 }
10573 }
10574 }
10575}
10576
10577/*
10578 * return TRUE if 'p' starts with 't_'
10579 */
10580 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010581istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582{
10583 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10584}
10585
10586/*
10587 * Compute columns for ruler and shown command. 'sc_col' is also used to
10588 * decide what the maximum length of a message on the status line can be.
10589 * If there is a status line for the last window, 'sc_col' is independent
10590 * of 'ru_col'.
10591 */
10592
10593#define COL_RULER 17 /* columns needed by standard ruler */
10594
10595 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010596comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010597{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010598#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010599 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010600
10601 sc_col = 0;
10602 ru_col = 0;
10603 if (p_ru)
10604 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010605# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010607# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010608 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010609# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010610 /* no last status line, adjust sc_col */
10611 if (!last_has_status)
10612 sc_col = ru_col;
10613 }
10614 if (p_sc)
10615 {
10616 sc_col += SHOWCMD_COLS;
10617 if (!p_ru || last_has_status) /* no need for separating space */
10618 ++sc_col;
10619 }
10620 sc_col = Columns - sc_col;
10621 ru_col = Columns - ru_col;
10622 if (sc_col <= 0) /* screen too narrow, will become a mess */
10623 sc_col = 1;
10624 if (ru_col <= 0)
10625 ru_col = 1;
10626#else
10627 sc_col = Columns;
10628 ru_col = Columns;
10629#endif
10630}
10631
Bram Moolenaar113e1072019-01-20 15:30:40 +010010632#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010634 * Unset local option value, similar to ":set opt<".
10635 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010636 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010637unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010638{
10639 struct vimoption *p;
10640 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010641 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010642
10643 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010644 if (opt_idx < 0)
10645 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010646 p = &(options[opt_idx]);
10647
10648 switch ((int)p->indir)
10649 {
10650 /* global option with local value: use local value if it's been set */
10651 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010652 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010653 break;
10654 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010655 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010656 break;
10657 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010658 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010659 break;
10660 case PV_AR:
10661 buf->b_p_ar = -1;
10662 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010663 case PV_BKC:
10664 clear_string_option(&buf->b_p_bkc);
10665 buf->b_bkc_flags = 0;
10666 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010667 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010668 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010669 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010670 case PV_TC:
10671 clear_string_option(&buf->b_p_tc);
10672 buf->b_tc_flags = 0;
10673 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010674 case PV_SISO:
10675 curwin->w_p_siso = -1;
10676 break;
10677 case PV_SO:
10678 curwin->w_p_so = -1;
10679 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010680#ifdef FEAT_FIND_ID
10681 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010682 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010683 break;
10684 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010685 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010686 break;
10687#endif
10688#ifdef FEAT_INS_EXPAND
10689 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010690 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010691 break;
10692 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010693 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010694 break;
10695#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010696 case PV_FP:
10697 clear_string_option(&buf->b_p_fp);
10698 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010699#ifdef FEAT_QUICKFIX
10700 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010701 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010702 break;
10703 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010704 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010705 break;
10706 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010707 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010708 break;
10709#endif
10710#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10711 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010712 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010713 break;
10714#endif
10715#if defined(FEAT_CRYPT)
10716 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010717 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010718 break;
10719#endif
10720#ifdef FEAT_STL_OPT
10721 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010722 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010723 break;
10724#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010725 case PV_UL:
10726 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10727 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010728#ifdef FEAT_LISP
10729 case PV_LW:
10730 clear_string_option(&buf->b_p_lw);
10731 break;
10732#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010733 case PV_MENC:
10734 clear_string_option(&buf->b_p_menc);
10735 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010736 }
10737}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010738#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010739
10740/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010741 * Get pointer to option variable, depending on local or global scope.
10742 */
10743 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010744get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010745{
10746 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10747 {
10748 if (p->var == VAR_WIN)
10749 return (char_u *)GLOBAL_WO(get_varp(p));
10750 return p->var;
10751 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010752 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010753 {
10754 switch ((int)p->indir)
10755 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010756 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010758 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10759 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10760 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010761#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010762 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10763 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10764 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010765 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010766 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010767 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010768 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10769 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010771 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10772 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010773#endif
10774#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010775 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10776 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010777#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010778#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10779 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10780#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010781#if defined(FEAT_CRYPT)
10782 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10783#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010784#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010785 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010786#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010787 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010788#ifdef FEAT_LISP
10789 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10790#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010791 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010792 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010793 }
10794 return NULL; /* "cannot happen" */
10795 }
10796 return get_varp(p);
10797}
10798
10799/*
10800 * Get pointer to option variable.
10801 */
10802 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010803get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010804{
10805 /* hidden option, always return NULL */
10806 if (p->var == NULL)
10807 return NULL;
10808
10809 switch ((int)p->indir)
10810 {
10811 case PV_NONE: return p->var;
10812
10813 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010814 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010815 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010816 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010818 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010820 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010821 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010822 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010824 case PV_TC: return *curbuf->b_p_tc != NUL
10825 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010826 case PV_BKC: return *curbuf->b_p_bkc != NUL
10827 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010828 case PV_SISO: return curwin->w_p_siso >= 0
10829 ? (char_u *)&(curwin->w_p_siso) : p->var;
10830 case PV_SO: return curwin->w_p_so >= 0
10831 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010833 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010834 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010835 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010836 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10837#endif
10838#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010839 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010841 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010842 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10843#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010844 case PV_FP: return *curbuf->b_p_fp != NUL
10845 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010846#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010847 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010848 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010849 case PV_GP: return *curbuf->b_p_gp != NUL
10850 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10851 case PV_MP: return *curbuf->b_p_mp != NUL
10852 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010854#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10855 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10856 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10857#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010858#if defined(FEAT_CRYPT)
10859 case PV_CM: return *curbuf->b_p_cm != NUL
10860 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10861#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010862#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010863 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010864 ? (char_u *)&(curwin->w_p_stl) : p->var;
10865#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010866 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10867 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010868#ifdef FEAT_LISP
10869 case PV_LW: return *curbuf->b_p_lw != NUL
10870 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10871#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010872 case PV_MENC: return *curbuf->b_p_menc != NUL
10873 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010874
10875#ifdef FEAT_ARABIC
10876 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10877#endif
10878 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010879#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010880 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10881#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010882#ifdef FEAT_SYN_HL
10883 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10884 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010885 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010886#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887#ifdef FEAT_DIFF
10888 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10889#endif
10890#ifdef FEAT_FOLDING
10891 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10892 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10893 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10894 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10895 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10896 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10897 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10898# ifdef FEAT_EVAL
10899 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10900 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10901# endif
10902 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10903#endif
10904 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010905 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010906#ifdef FEAT_LINEBREAK
10907 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10908#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010909 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010910 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010911#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010912 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10913#endif
10914#ifdef FEAT_RIGHTLEFT
10915 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10916 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10917#endif
10918 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10919 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10920#ifdef FEAT_LINEBREAK
10921 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010922 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10923 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010924#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010925 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010926 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010927#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010928 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10929 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10930#endif
10931#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010932 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10933 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10934 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010935#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010936
10937 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10938 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010939 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10941 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010942 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10943 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10944#ifdef FEAT_CINDENT
10945 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10946 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10947 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10948#endif
10949#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10950 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10951#endif
10952#ifdef FEAT_COMMENTS
10953 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10954#endif
10955#ifdef FEAT_FOLDING
10956 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10957#endif
10958#ifdef FEAT_INS_EXPAND
10959 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10960#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010961#ifdef FEAT_COMPL_FUNC
10962 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010963 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010964#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020010965#ifdef FEAT_EVAL
10966 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
10967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010968 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010969 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010970 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010971 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010972 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010973 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010974 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010975 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010976 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10977 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10978 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10979 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10980#ifdef FEAT_FIND_ID
10981# ifdef FEAT_EVAL
10982 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10983# endif
10984#endif
10985#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10986 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10987 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10988#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010989#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010990 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10991#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010992#ifdef FEAT_CRYPT
10993 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10994#endif
10995#ifdef FEAT_LISP
10996 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10997#endif
10998 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10999 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11000 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11001 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11002 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011003 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011004#ifdef FEAT_TEXTOBJ
11005 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11006#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011007 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11008#ifdef FEAT_SMARTINDENT
11009 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11010#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011011 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011012 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11013#ifdef FEAT_SEARCHPATH
11014 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11015#endif
11016 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11017#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011018 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011019 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11020#endif
11021#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011022 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11023 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11024 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025#endif
11026 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11027 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11028 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11029 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011030#ifdef FEAT_PERSISTENT_UNDO
11031 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11032#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011033 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11034#ifdef FEAT_KEYMAP
11035 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11036#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011037#ifdef FEAT_SIGNS
11038 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11039#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011040#ifdef FEAT_VARTABS
11041 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11042 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11043#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011044 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011045 }
11046 /* always return a valid pointer to avoid a crash! */
11047 return (char_u *)&(curbuf->b_p_wm);
11048}
11049
11050/*
11051 * Get the value of 'equalprg', either the buffer-local one or the global one.
11052 */
11053 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011054get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055{
11056 if (*curbuf->b_p_ep == NUL)
11057 return p_ep;
11058 return curbuf->b_p_ep;
11059}
11060
Bram Moolenaar071d4272004-06-13 20:20:40 +000011061/*
11062 * Copy options from one window to another.
11063 * Used when splitting a window.
11064 */
11065 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011066win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011067{
11068 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11069 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011070#if defined(FEAT_LINEBREAK)
11071 briopt_check(wp_to);
11072#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074
11075/*
11076 * Copy the options from one winopt_T to another.
11077 * Doesn't free the old option values in "to", use clear_winopt() for that.
11078 * The 'scroll' option is not copied, because it depends on the window height.
11079 * The 'previewwindow' option is reset, there can be only one preview window.
11080 */
11081 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011082copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083{
11084#ifdef FEAT_ARABIC
11085 to->wo_arab = from->wo_arab;
11086#endif
11087 to->wo_list = from->wo_list;
11088 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011089 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011090#ifdef FEAT_LINEBREAK
11091 to->wo_nuw = from->wo_nuw;
11092#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011093#ifdef FEAT_RIGHTLEFT
11094 to->wo_rl = from->wo_rl;
11095 to->wo_rlc = vim_strsave(from->wo_rlc);
11096#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011097#ifdef FEAT_STL_OPT
11098 to->wo_stl = vim_strsave(from->wo_stl);
11099#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011100 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011101#ifdef FEAT_DIFF
11102 to->wo_wrap_save = from->wo_wrap_save;
11103#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011104#ifdef FEAT_LINEBREAK
11105 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011106 to->wo_bri = from->wo_bri;
11107 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011110 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011111 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011112 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011113#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011114 to->wo_spell = from->wo_spell;
11115#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011116#ifdef FEAT_SYN_HL
11117 to->wo_cuc = from->wo_cuc;
11118 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011119 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011120#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011121#ifdef FEAT_DIFF
11122 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011123 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011125#ifdef FEAT_CONCEAL
11126 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011127 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011128#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011129#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011130 to->wo_twk = vim_strsave(from->wo_twk);
11131 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011132#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133#ifdef FEAT_FOLDING
11134 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011135 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011136 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011137 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011138 to->wo_fdi = vim_strsave(from->wo_fdi);
11139 to->wo_fml = from->wo_fml;
11140 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011141 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011143 to->wo_fdm_save = from->wo_diff_saved
11144 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145 to->wo_fdn = from->wo_fdn;
11146# ifdef FEAT_EVAL
11147 to->wo_fde = vim_strsave(from->wo_fde);
11148 to->wo_fdt = vim_strsave(from->wo_fdt);
11149# endif
11150 to->wo_fmr = vim_strsave(from->wo_fmr);
11151#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011152#ifdef FEAT_SIGNS
11153 to->wo_scl = vim_strsave(from->wo_scl);
11154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011155 check_winopt(to); /* don't want NULL pointers */
11156}
11157
11158/*
11159 * Check string options in a window for a NULL value.
11160 */
11161 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011162check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011163{
11164 check_winopt(&win->w_onebuf_opt);
11165 check_winopt(&win->w_allbuf_opt);
11166}
11167
11168/*
11169 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11170 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011171 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011172check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173{
11174#ifdef FEAT_FOLDING
11175 check_string_option(&wop->wo_fdi);
11176 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011177 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011178# ifdef FEAT_EVAL
11179 check_string_option(&wop->wo_fde);
11180 check_string_option(&wop->wo_fdt);
11181# endif
11182 check_string_option(&wop->wo_fmr);
11183#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011184#ifdef FEAT_SIGNS
11185 check_string_option(&wop->wo_scl);
11186#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187#ifdef FEAT_RIGHTLEFT
11188 check_string_option(&wop->wo_rlc);
11189#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011190#ifdef FEAT_STL_OPT
11191 check_string_option(&wop->wo_stl);
11192#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011193#ifdef FEAT_SYN_HL
11194 check_string_option(&wop->wo_cc);
11195#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011196#ifdef FEAT_CONCEAL
11197 check_string_option(&wop->wo_cocu);
11198#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011199#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011200 check_string_option(&wop->wo_twk);
11201 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011202#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011203#ifdef FEAT_LINEBREAK
11204 check_string_option(&wop->wo_briopt);
11205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206}
11207
11208/*
11209 * Free the allocated memory inside a winopt_T.
11210 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011211 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011212clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011213{
11214#ifdef FEAT_FOLDING
11215 clear_string_option(&wop->wo_fdi);
11216 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011217 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011218# ifdef FEAT_EVAL
11219 clear_string_option(&wop->wo_fde);
11220 clear_string_option(&wop->wo_fdt);
11221# endif
11222 clear_string_option(&wop->wo_fmr);
11223#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011224#ifdef FEAT_SIGNS
11225 clear_string_option(&wop->wo_scl);
11226#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011227#ifdef FEAT_LINEBREAK
11228 clear_string_option(&wop->wo_briopt);
11229#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011230#ifdef FEAT_RIGHTLEFT
11231 clear_string_option(&wop->wo_rlc);
11232#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011233#ifdef FEAT_STL_OPT
11234 clear_string_option(&wop->wo_stl);
11235#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011236#ifdef FEAT_SYN_HL
11237 clear_string_option(&wop->wo_cc);
11238#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011239#ifdef FEAT_CONCEAL
11240 clear_string_option(&wop->wo_cocu);
11241#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011242#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011243 clear_string_option(&wop->wo_twk);
11244 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011246}
11247
11248/*
11249 * Copy global option values to local options for one buffer.
11250 * Used when creating a new buffer and sometimes when entering a buffer.
11251 * flags:
11252 * BCO_ENTER We will enter the buf buffer.
11253 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11254 * appropriate.
11255 * BCO_NOHELP Don't copy the values to a help buffer.
11256 */
11257 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011258buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011259{
11260 int should_copy = TRUE;
11261 char_u *save_p_isk = NULL; /* init for GCC */
11262 int dont_do_help;
11263 int did_isk = FALSE;
11264
11265 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266 * Skip this when the option defaults have not been set yet. Happens when
11267 * main() allocates the first buffer.
11268 */
11269 if (p_cpo != NULL)
11270 {
11271 /*
11272 * Always copy when entering and 'cpo' contains 'S'.
11273 * Don't copy when already initialized.
11274 * Don't copy when 'cpo' contains 's' and not entering.
11275 * 'S' BCO_ENTER initialized 's' should_copy
11276 * yes yes X X TRUE
11277 * yes no yes X FALSE
11278 * no X yes X FALSE
11279 * X no no yes FALSE
11280 * X no no no TRUE
11281 * no yes no X TRUE
11282 */
11283 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11284 && (buf->b_p_initialized
11285 || (!(flags & BCO_ENTER)
11286 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11287 should_copy = FALSE;
11288
11289 if (should_copy || (flags & BCO_ALWAYS))
11290 {
11291 /* Don't copy the options specific to a help buffer when
11292 * BCO_NOHELP is given or the options were initialized already
11293 * (jumping back to a help file with CTRL-T or CTRL-O) */
11294 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11295 || buf->b_p_initialized;
11296 if (dont_do_help) /* don't free b_p_isk */
11297 {
11298 save_p_isk = buf->b_p_isk;
11299 buf->b_p_isk = NULL;
11300 }
11301 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011302 * Always free the allocated strings. If not already initialized,
11303 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011304 */
11305 if (!buf->b_p_initialized)
11306 {
11307 free_buf_options(buf, TRUE);
11308 buf->b_p_ro = FALSE; /* don't copy readonly */
11309 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011311 switch (*p_ffs)
11312 {
11313 case 'm':
11314 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11315 case 'd':
11316 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11317 case 'u':
11318 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11319 default:
11320 buf->b_p_ff = vim_strsave(p_ff);
11321 }
11322 if (buf->b_p_ff != NULL)
11323 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011324 buf->b_p_bh = empty_option;
11325 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011326 }
11327 else
11328 free_buf_options(buf, FALSE);
11329
11330 buf->b_p_ai = p_ai;
11331 buf->b_p_ai_nopaste = p_ai_nopaste;
11332 buf->b_p_sw = p_sw;
11333 buf->b_p_tw = p_tw;
11334 buf->b_p_tw_nopaste = p_tw_nopaste;
11335 buf->b_p_tw_nobin = p_tw_nobin;
11336 buf->b_p_wm = p_wm;
11337 buf->b_p_wm_nopaste = p_wm_nopaste;
11338 buf->b_p_wm_nobin = p_wm_nobin;
11339 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011340 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011341 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342 buf->b_p_et = p_et;
11343 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011344 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011345 buf->b_p_ml = p_ml;
11346 buf->b_p_ml_nobin = p_ml_nobin;
11347 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011348 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349#ifdef FEAT_INS_EXPAND
11350 buf->b_p_cpt = vim_strsave(p_cpt);
11351#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011352#ifdef FEAT_COMPL_FUNC
11353 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011354 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011355#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011356#ifdef FEAT_EVAL
11357 buf->b_p_tfu = vim_strsave(p_tfu);
11358#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011359 buf->b_p_sts = p_sts;
11360 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011361#ifdef FEAT_VARTABS
11362 buf->b_p_vsts = vim_strsave(p_vsts);
11363 if (p_vsts && p_vsts != empty_option)
11364 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11365 else
11366 buf->b_p_vsts_array = 0;
11367 buf->b_p_vsts_nopaste = p_vsts_nopaste
11368 ? vim_strsave(p_vsts_nopaste) : NULL;
11369#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011370 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011371#ifdef FEAT_COMMENTS
11372 buf->b_p_com = vim_strsave(p_com);
11373#endif
11374#ifdef FEAT_FOLDING
11375 buf->b_p_cms = vim_strsave(p_cms);
11376#endif
11377 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011378 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379 buf->b_p_nf = vim_strsave(p_nf);
11380 buf->b_p_mps = vim_strsave(p_mps);
11381#ifdef FEAT_SMARTINDENT
11382 buf->b_p_si = p_si;
11383#endif
11384 buf->b_p_ci = p_ci;
11385#ifdef FEAT_CINDENT
11386 buf->b_p_cin = p_cin;
11387 buf->b_p_cink = vim_strsave(p_cink);
11388 buf->b_p_cino = vim_strsave(p_cino);
11389#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011390 /* Don't copy 'filetype', it must be detected */
11391 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011392 buf->b_p_pi = p_pi;
11393#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11394 buf->b_p_cinw = vim_strsave(p_cinw);
11395#endif
11396#ifdef FEAT_LISP
11397 buf->b_p_lisp = p_lisp;
11398#endif
11399#ifdef FEAT_SYN_HL
11400 /* Don't copy 'syntax', it must be set */
11401 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011402 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011403 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011404#endif
11405#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011406 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011407 (void)compile_cap_prog(&buf->b_s);
11408 buf->b_s.b_p_spf = vim_strsave(p_spf);
11409 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410#endif
11411#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11412 buf->b_p_inde = vim_strsave(p_inde);
11413 buf->b_p_indk = vim_strsave(p_indk);
11414#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011415 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011416#if defined(FEAT_EVAL)
11417 buf->b_p_fex = vim_strsave(p_fex);
11418#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419#ifdef FEAT_CRYPT
11420 buf->b_p_key = vim_strsave(p_key);
11421#endif
11422#ifdef FEAT_SEARCHPATH
11423 buf->b_p_sua = vim_strsave(p_sua);
11424#endif
11425#ifdef FEAT_KEYMAP
11426 buf->b_p_keymap = vim_strsave(p_keymap);
11427 buf->b_kmap_state |= KEYMAP_INIT;
11428#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011429#ifdef FEAT_TERMINAL
11430 buf->b_p_twsl = p_twsl;
11431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011432 /* This isn't really an option, but copying the langmap and IME
11433 * state from the current buffer is better than resetting it. */
11434 buf->b_p_iminsert = p_iminsert;
11435 buf->b_p_imsearch = p_imsearch;
11436
11437 /* options that are normally global but also have a local value
11438 * are not copied, start using the global value */
11439 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011440 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011441 buf->b_p_bkc = empty_option;
11442 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011443#ifdef FEAT_QUICKFIX
11444 buf->b_p_gp = empty_option;
11445 buf->b_p_mp = empty_option;
11446 buf->b_p_efm = empty_option;
11447#endif
11448 buf->b_p_ep = empty_option;
11449 buf->b_p_kp = empty_option;
11450 buf->b_p_path = empty_option;
11451 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011452 buf->b_p_tc = empty_option;
11453 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011454#ifdef FEAT_FIND_ID
11455 buf->b_p_def = empty_option;
11456 buf->b_p_inc = empty_option;
11457# ifdef FEAT_EVAL
11458 buf->b_p_inex = vim_strsave(p_inex);
11459# endif
11460#endif
11461#ifdef FEAT_INS_EXPAND
11462 buf->b_p_dict = empty_option;
11463 buf->b_p_tsr = empty_option;
11464#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011465#ifdef FEAT_TEXTOBJ
11466 buf->b_p_qe = vim_strsave(p_qe);
11467#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011468#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11469 buf->b_p_bexpr = empty_option;
11470#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011471#if defined(FEAT_CRYPT)
11472 buf->b_p_cm = empty_option;
11473#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011474#ifdef FEAT_PERSISTENT_UNDO
11475 buf->b_p_udf = p_udf;
11476#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011477#ifdef FEAT_LISP
11478 buf->b_p_lw = empty_option;
11479#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011480 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011481
11482 /*
11483 * Don't copy the options set by ex_help(), use the saved values,
11484 * when going from a help buffer to a non-help buffer.
11485 * Don't touch these at all when BCO_NOHELP is used and going from
11486 * or to a help buffer.
11487 */
11488 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011489 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011490 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011491#ifdef FEAT_VARTABS
11492 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11493 tabstop_set(p_vts, &buf->b_p_vts_array);
11494 else
11495 buf->b_p_vts_array = NULL;
11496#endif
11497 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011498 else
11499 {
11500 buf->b_p_isk = vim_strsave(p_isk);
11501 did_isk = TRUE;
11502 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011503#ifdef FEAT_VARTABS
11504 buf->b_p_vts = vim_strsave(p_vts);
11505 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11506 tabstop_set(p_vts, &buf->b_p_vts_array);
11507 else
11508 buf->b_p_vts_array = NULL;
11509#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011510 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011511 if (buf->b_p_bt[0] == 'h')
11512 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011513 buf->b_p_ma = p_ma;
11514 }
11515 }
11516
11517 /*
11518 * When the options should be copied (ignoring BCO_ALWAYS), set the
11519 * flag that indicates that the options have been initialized.
11520 */
11521 if (should_copy)
11522 buf->b_p_initialized = TRUE;
11523 }
11524
11525 check_buf_options(buf); /* make sure we don't have NULLs */
11526 if (did_isk)
11527 (void)buf_init_chartab(buf, FALSE);
11528}
11529
11530/*
11531 * Reset the 'modifiable' option and its default value.
11532 */
11533 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011534reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011535{
11536 int opt_idx;
11537
11538 curbuf->b_p_ma = FALSE;
11539 p_ma = FALSE;
11540 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011541 if (opt_idx >= 0)
11542 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011543}
11544
11545/*
11546 * Set the global value for 'iminsert' to the local value.
11547 */
11548 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011549set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011550{
11551 p_iminsert = curbuf->b_p_iminsert;
11552}
11553
11554/*
11555 * Set the global value for 'imsearch' to the local value.
11556 */
11557 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011558set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011559{
11560 p_imsearch = curbuf->b_p_imsearch;
11561}
11562
11563#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11564static int expand_option_idx = -1;
11565static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11566static int expand_option_flags = 0;
11567
11568 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011569set_context_in_set_cmd(
11570 expand_T *xp,
11571 char_u *arg,
11572 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011573{
11574 int nextchar;
11575 long_u flags = 0; /* init for GCC */
11576 int opt_idx = 0; /* init for GCC */
11577 char_u *p;
11578 char_u *s;
11579 int is_term_option = FALSE;
11580 int key;
11581
11582 expand_option_flags = opt_flags;
11583
11584 xp->xp_context = EXPAND_SETTINGS;
11585 if (*arg == NUL)
11586 {
11587 xp->xp_pattern = arg;
11588 return;
11589 }
11590 p = arg + STRLEN(arg) - 1;
11591 if (*p == ' ' && *(p - 1) != '\\')
11592 {
11593 xp->xp_pattern = p + 1;
11594 return;
11595 }
11596 while (p > arg)
11597 {
11598 s = p;
11599 /* count number of backslashes before ' ' or ',' */
11600 if (*p == ' ' || *p == ',')
11601 {
11602 while (s > arg && *(s - 1) == '\\')
11603 --s;
11604 }
11605 /* break at a space with an even number of backslashes */
11606 if (*p == ' ' && ((p - s) & 1) == 0)
11607 {
11608 ++p;
11609 break;
11610 }
11611 --p;
11612 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011613 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011614 {
11615 xp->xp_context = EXPAND_BOOL_SETTINGS;
11616 p += 2;
11617 }
11618 if (STRNCMP(p, "inv", 3) == 0)
11619 {
11620 xp->xp_context = EXPAND_BOOL_SETTINGS;
11621 p += 3;
11622 }
11623 xp->xp_pattern = arg = p;
11624 if (*arg == '<')
11625 {
11626 while (*p != '>')
11627 if (*p++ == NUL) /* expand terminal option name */
11628 return;
11629 key = get_special_key_code(arg + 1);
11630 if (key == 0) /* unknown name */
11631 {
11632 xp->xp_context = EXPAND_NOTHING;
11633 return;
11634 }
11635 nextchar = *++p;
11636 is_term_option = TRUE;
11637 expand_option_name[2] = KEY2TERMCAP0(key);
11638 expand_option_name[3] = KEY2TERMCAP1(key);
11639 }
11640 else
11641 {
11642 if (p[0] == 't' && p[1] == '_')
11643 {
11644 p += 2;
11645 if (*p != NUL)
11646 ++p;
11647 if (*p == NUL)
11648 return; /* expand option name */
11649 nextchar = *++p;
11650 is_term_option = TRUE;
11651 expand_option_name[2] = p[-2];
11652 expand_option_name[3] = p[-1];
11653 }
11654 else
11655 {
11656 /* Allow * wildcard */
11657 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11658 p++;
11659 if (*p == NUL)
11660 return;
11661 nextchar = *p;
11662 *p = NUL;
11663 opt_idx = findoption(arg);
11664 *p = nextchar;
11665 if (opt_idx == -1 || options[opt_idx].var == NULL)
11666 {
11667 xp->xp_context = EXPAND_NOTHING;
11668 return;
11669 }
11670 flags = options[opt_idx].flags;
11671 if (flags & P_BOOL)
11672 {
11673 xp->xp_context = EXPAND_NOTHING;
11674 return;
11675 }
11676 }
11677 }
11678 /* handle "-=" and "+=" */
11679 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11680 {
11681 ++p;
11682 nextchar = '=';
11683 }
11684 if ((nextchar != '=' && nextchar != ':')
11685 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11686 {
11687 xp->xp_context = EXPAND_UNSUCCESSFUL;
11688 return;
11689 }
11690 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11691 {
11692 xp->xp_context = EXPAND_OLD_SETTING;
11693 if (is_term_option)
11694 expand_option_idx = -1;
11695 else
11696 expand_option_idx = opt_idx;
11697 xp->xp_pattern = p + 1;
11698 return;
11699 }
11700 xp->xp_context = EXPAND_NOTHING;
11701 if (is_term_option || (flags & P_NUM))
11702 return;
11703
11704 xp->xp_pattern = p + 1;
11705
11706 if (flags & P_EXPAND)
11707 {
11708 p = options[opt_idx].var;
11709 if (p == (char_u *)&p_bdir
11710 || p == (char_u *)&p_dir
11711 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011712 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011713 || p == (char_u *)&p_rtp
11714#ifdef FEAT_SEARCHPATH
11715 || p == (char_u *)&p_cdpath
11716#endif
11717#ifdef FEAT_SESSION
11718 || p == (char_u *)&p_vdir
11719#endif
11720 )
11721 {
11722 xp->xp_context = EXPAND_DIRECTORIES;
11723 if (p == (char_u *)&p_path
11724#ifdef FEAT_SEARCHPATH
11725 || p == (char_u *)&p_cdpath
11726#endif
11727 )
11728 xp->xp_backslash = XP_BS_THREE;
11729 else
11730 xp->xp_backslash = XP_BS_ONE;
11731 }
11732 else
11733 {
11734 xp->xp_context = EXPAND_FILES;
11735 /* for 'tags' need three backslashes for a space */
11736 if (p == (char_u *)&p_tags)
11737 xp->xp_backslash = XP_BS_THREE;
11738 else
11739 xp->xp_backslash = XP_BS_ONE;
11740 }
11741 }
11742
11743 /* For an option that is a list of file names, find the start of the
11744 * last file name. */
11745 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11746 {
11747 /* count number of backslashes before ' ' or ',' */
11748 if (*p == ' ' || *p == ',')
11749 {
11750 s = p;
11751 while (s > xp->xp_pattern && *(s - 1) == '\\')
11752 --s;
11753 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11754 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11755 {
11756 xp->xp_pattern = p + 1;
11757 break;
11758 }
11759 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011760
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011761#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011762 /* for 'spellsuggest' start at "file:" */
11763 if (options[opt_idx].var == (char_u *)&p_sps
11764 && STRNCMP(p, "file:", 5) == 0)
11765 {
11766 xp->xp_pattern = p + 5;
11767 break;
11768 }
11769#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011770 }
11771
11772 return;
11773}
11774
11775 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011776ExpandSettings(
11777 expand_T *xp,
11778 regmatch_T *regmatch,
11779 int *num_file,
11780 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011781{
11782 int num_normal = 0; /* Nr of matching non-term-code settings */
11783 int num_term = 0; /* Nr of matching terminal code settings */
11784 int opt_idx;
11785 int match;
11786 int count = 0;
11787 char_u *str;
11788 int loop;
11789 int is_term_opt;
11790 char_u name_buf[MAX_KEY_NAME_LEN];
11791 static char *(names[]) = {"all", "termcap"};
11792 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11793
11794 /* do this loop twice:
11795 * loop == 0: count the number of matching options
11796 * loop == 1: copy the matching options into allocated memory
11797 */
11798 for (loop = 0; loop <= 1; ++loop)
11799 {
11800 regmatch->rm_ic = ic;
11801 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11802 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011803 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11804 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011805 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11806 {
11807 if (loop == 0)
11808 num_normal++;
11809 else
11810 (*file)[count++] = vim_strsave((char_u *)names[match]);
11811 }
11812 }
11813 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11814 opt_idx++)
11815 {
11816 if (options[opt_idx].var == NULL)
11817 continue;
11818 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11819 && !(options[opt_idx].flags & P_BOOL))
11820 continue;
11821 is_term_opt = istermoption(&options[opt_idx]);
11822 if (is_term_opt && num_normal > 0)
11823 continue;
11824 match = FALSE;
11825 if (vim_regexec(regmatch, str, (colnr_T)0)
11826 || (options[opt_idx].shortname != NULL
11827 && vim_regexec(regmatch,
11828 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11829 match = TRUE;
11830 else if (is_term_opt)
11831 {
11832 name_buf[0] = '<';
11833 name_buf[1] = 't';
11834 name_buf[2] = '_';
11835 name_buf[3] = str[2];
11836 name_buf[4] = str[3];
11837 name_buf[5] = '>';
11838 name_buf[6] = NUL;
11839 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11840 {
11841 match = TRUE;
11842 str = name_buf;
11843 }
11844 }
11845 if (match)
11846 {
11847 if (loop == 0)
11848 {
11849 if (is_term_opt)
11850 num_term++;
11851 else
11852 num_normal++;
11853 }
11854 else
11855 (*file)[count++] = vim_strsave(str);
11856 }
11857 }
11858 /*
11859 * Check terminal key codes, these are not in the option table
11860 */
11861 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11862 {
11863 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11864 {
11865 if (!isprint(str[0]) || !isprint(str[1]))
11866 continue;
11867
11868 name_buf[0] = 't';
11869 name_buf[1] = '_';
11870 name_buf[2] = str[0];
11871 name_buf[3] = str[1];
11872 name_buf[4] = NUL;
11873
11874 match = FALSE;
11875 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11876 match = TRUE;
11877 else
11878 {
11879 name_buf[0] = '<';
11880 name_buf[1] = 't';
11881 name_buf[2] = '_';
11882 name_buf[3] = str[0];
11883 name_buf[4] = str[1];
11884 name_buf[5] = '>';
11885 name_buf[6] = NUL;
11886
11887 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11888 match = TRUE;
11889 }
11890 if (match)
11891 {
11892 if (loop == 0)
11893 num_term++;
11894 else
11895 (*file)[count++] = vim_strsave(name_buf);
11896 }
11897 }
11898
11899 /*
11900 * Check special key names.
11901 */
11902 regmatch->rm_ic = TRUE; /* ignore case here */
11903 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11904 {
11905 name_buf[0] = '<';
11906 STRCPY(name_buf + 1, str);
11907 STRCAT(name_buf, ">");
11908
11909 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11910 {
11911 if (loop == 0)
11912 num_term++;
11913 else
11914 (*file)[count++] = vim_strsave(name_buf);
11915 }
11916 }
11917 }
11918 if (loop == 0)
11919 {
11920 if (num_normal > 0)
11921 *num_file = num_normal;
11922 else if (num_term > 0)
11923 *num_file = num_term;
11924 else
11925 return OK;
11926 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11927 if (*file == NULL)
11928 {
11929 *file = (char_u **)"";
11930 return FAIL;
11931 }
11932 }
11933 }
11934 return OK;
11935}
11936
11937 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011938ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011939{
11940 char_u *var = NULL; /* init for GCC */
11941 char_u *buf;
11942
11943 *num_file = 0;
11944 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11945 if (*file == NULL)
11946 return FAIL;
11947
11948 /*
11949 * For a terminal key code expand_option_idx is < 0.
11950 */
11951 if (expand_option_idx < 0)
11952 {
11953 var = find_termcode(expand_option_name + 2);
11954 if (var == NULL)
11955 expand_option_idx = findoption(expand_option_name);
11956 }
11957
11958 if (expand_option_idx >= 0)
11959 {
11960 /* put string of option value in NameBuff */
11961 option_value2string(&options[expand_option_idx], expand_option_flags);
11962 var = NameBuff;
11963 }
11964 else if (var == NULL)
11965 var = (char_u *)"";
11966
11967 /* A backslash is required before some characters. This is the reverse of
11968 * what happens in do_set(). */
11969 buf = vim_strsave_escaped(var, escape_chars);
11970
11971 if (buf == NULL)
11972 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011973 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011974 return FAIL;
11975 }
11976
11977#ifdef BACKSLASH_IN_FILENAME
11978 /* For MS-Windows et al. we don't double backslashes at the start and
11979 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011980 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011981 if (var[0] == '\\' && var[1] == '\\'
11982 && expand_option_idx >= 0
11983 && (options[expand_option_idx].flags & P_EXPAND)
11984 && vim_isfilec(var[2])
11985 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011986 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011987#endif
11988
11989 *file[0] = buf;
11990 *num_file = 1;
11991 return OK;
11992}
11993#endif
11994
11995/*
11996 * Get the value for the numeric or string option *opp in a nice format into
11997 * NameBuff[]. Must not be called with a hidden option!
11998 */
11999 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012000option_value2string(
12001 struct vimoption *opp,
12002 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012003{
12004 char_u *varp;
12005
12006 varp = get_varp_scope(opp, opt_flags);
12007
12008 if (opp->flags & P_NUM)
12009 {
12010 long wc = 0;
12011
12012 if (wc_use_keyname(varp, &wc))
12013 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12014 else if (wc != 0)
12015 STRCPY(NameBuff, transchar((int)wc));
12016 else
12017 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12018 }
12019 else /* P_STRING */
12020 {
12021 varp = *(char_u **)(varp);
12022 if (varp == NULL) /* just in case */
12023 NameBuff[0] = NUL;
12024#ifdef FEAT_CRYPT
12025 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012026 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012027 STRCPY(NameBuff, "*****");
12028#endif
12029 else if (opp->flags & P_EXPAND)
12030 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12031 /* Translate 'pastetoggle' into special key names */
12032 else if ((char_u **)opp->var == &p_pt)
12033 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12034 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012035 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036 }
12037}
12038
12039/*
12040 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12041 * printed as a keyname.
12042 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12043 */
12044 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012045wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012046{
12047 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12048 {
12049 *wcp = *(long *)varp;
12050 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12051 return TRUE;
12052 }
12053 return FALSE;
12054}
12055
Bram Moolenaar01615492015-02-03 13:00:38 +010012056#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012057/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012058 * Any character has an equivalent 'langmap' character. This is used for
12059 * keyboards that have a special language mode that sends characters above
12060 * 128 (although other characters can be translated too). The "to" field is a
12061 * Vim command character. This avoids having to switch the keyboard back to
12062 * ASCII mode when leaving Insert mode.
12063 *
12064 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12065 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012066 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12067 * same as langmap_mapchar[] for characters >= 256.
12068 *
12069 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012070 */
12071typedef struct
12072{
12073 int from;
12074 int to;
12075} langmap_entry_T;
12076
12077static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012078
12079/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012080 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12081 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012082 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012083 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012084langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012085{
12086 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012087 int a = 0;
12088 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012089
12090 /* Do a binary search for an existing entry. */
12091 while (a != b)
12092 {
12093 int i = (a + b) / 2;
12094 int d = entries[i].from - from;
12095
12096 if (d == 0)
12097 {
12098 entries[i].to = to;
12099 return;
12100 }
12101 if (d < 0)
12102 a = i + 1;
12103 else
12104 b = i;
12105 }
12106
12107 if (ga_grow(&langmap_mapga, 1) != OK)
12108 return; /* out of memory */
12109
12110 /* insert new entry at position "a" */
12111 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12112 mch_memmove(entries + 1, entries,
12113 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12114 ++langmap_mapga.ga_len;
12115 entries[0].from = from;
12116 entries[0].to = to;
12117}
12118
12119/*
12120 * Apply 'langmap' to multi-byte character "c" and return the result.
12121 */
12122 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012123langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012124{
12125 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12126 int a = 0;
12127 int b = langmap_mapga.ga_len;
12128
12129 while (a != b)
12130 {
12131 int i = (a + b) / 2;
12132 int d = entries[i].from - c;
12133
12134 if (d == 0)
12135 return entries[i].to; /* found matching entry */
12136 if (d < 0)
12137 a = i + 1;
12138 else
12139 b = i;
12140 }
12141 return c; /* no entry found, return "c" unmodified */
12142}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012143
12144 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012145langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012146{
12147 int i;
12148
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012149 for (i = 0; i < 256; i++)
12150 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012151 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152}
12153
12154/*
12155 * Called when langmap option is set; the language map can be
12156 * changed at any time!
12157 */
12158 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012159langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012160{
12161 char_u *p;
12162 char_u *p2;
12163 int from, to;
12164
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012165 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012166 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012167
12168 for (p = p_langmap; p[0] != NUL; )
12169 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012170 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012171 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012172 {
12173 if (p2[0] == '\\' && p2[1] != NUL)
12174 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012175 }
12176 if (p2[0] == ';')
12177 ++p2; /* abcd;ABCD form, p2 points to A */
12178 else
12179 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12180 while (p[0])
12181 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012182 if (p[0] == ',')
12183 {
12184 ++p;
12185 break;
12186 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012187 if (p[0] == '\\' && p[1] != NUL)
12188 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012189 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012190 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012191 if (p2 == NULL)
12192 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012193 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012194 if (p[0] != ',')
12195 {
12196 if (p[0] == '\\')
12197 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012198 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012199 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012200 }
12201 else
12202 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012203 if (p2[0] != ',')
12204 {
12205 if (p2[0] == '\\')
12206 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012207 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012208 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 }
12210 if (to == NUL)
12211 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012212 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012213 transchar(from));
12214 return;
12215 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012216
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012217 if (from >= 256)
12218 langmap_set_entry(from, to);
12219 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012220 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012221
12222 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012223 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012224 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012225 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012226 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012227 if (*p == ';')
12228 {
12229 p = p2;
12230 if (p[0] != NUL)
12231 {
12232 if (p[0] != ',')
12233 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012234 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012235 return;
12236 }
12237 ++p;
12238 }
12239 break;
12240 }
12241 }
12242 }
12243 }
12244}
12245#endif
12246
12247/*
12248 * Return TRUE if format option 'x' is in effect.
12249 * Take care of no formatting when 'paste' is set.
12250 */
12251 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012252has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012253{
12254 if (p_paste)
12255 return FALSE;
12256 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12257}
12258
12259/*
12260 * Return TRUE if "x" is present in 'shortmess' option, or
12261 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12262 */
12263 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012264shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012265{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012266 return p_shm != NULL &&
12267 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012268 || (vim_strchr(p_shm, 'a') != NULL
12269 && vim_strchr((char_u *)SHM_A, x) != NULL));
12270}
12271
12272/*
12273 * paste_option_changed() - Called after p_paste was set or reset.
12274 */
12275 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012276paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012277{
12278 static int old_p_paste = FALSE;
12279 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012280 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012281#ifdef FEAT_CMDL_INFO
12282 static int save_ru = 0;
12283#endif
12284#ifdef FEAT_RIGHTLEFT
12285 static int save_ri = 0;
12286 static int save_hkmap = 0;
12287#endif
12288 buf_T *buf;
12289
12290 if (p_paste)
12291 {
12292 /*
12293 * Paste switched from off to on.
12294 * Save the current values, so they can be restored later.
12295 */
12296 if (!old_p_paste)
12297 {
12298 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012299 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012300 {
12301 buf->b_p_tw_nopaste = buf->b_p_tw;
12302 buf->b_p_wm_nopaste = buf->b_p_wm;
12303 buf->b_p_sts_nopaste = buf->b_p_sts;
12304 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012305 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012306#ifdef FEAT_VARTABS
12307 if (buf->b_p_vsts_nopaste)
12308 vim_free(buf->b_p_vsts_nopaste);
12309 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12310 ? vim_strsave(buf->b_p_vsts) : NULL;
12311#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012312 }
12313
12314 /* save global options */
12315 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012316 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012317#ifdef FEAT_CMDL_INFO
12318 save_ru = p_ru;
12319#endif
12320#ifdef FEAT_RIGHTLEFT
12321 save_ri = p_ri;
12322 save_hkmap = p_hkmap;
12323#endif
12324 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012325 p_ai_nopaste = p_ai;
12326 p_et_nopaste = p_et;
12327 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012328 p_tw_nopaste = p_tw;
12329 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012330#ifdef FEAT_VARTABS
12331 if (p_vsts_nopaste)
12332 vim_free(p_vsts_nopaste);
12333 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12334#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012335 }
12336
12337 /*
12338 * Always set the option values, also when 'paste' is set when it is
12339 * already on.
12340 */
12341 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012342 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012343 {
12344 buf->b_p_tw = 0; /* textwidth is 0 */
12345 buf->b_p_wm = 0; /* wrapmargin is 0 */
12346 buf->b_p_sts = 0; /* softtabstop is 0 */
12347 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012348 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012349#ifdef FEAT_VARTABS
12350 if (buf->b_p_vsts)
12351 free_string_option(buf->b_p_vsts);
12352 buf->b_p_vsts = empty_option;
12353 if (buf->b_p_vsts_array)
12354 vim_free(buf->b_p_vsts_array);
12355 buf->b_p_vsts_array = 0;
12356#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012357 }
12358
12359 /* set global options */
12360 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012361 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012362#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012363 if (p_ru)
12364 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012365 p_ru = 0; /* no ruler */
12366#endif
12367#ifdef FEAT_RIGHTLEFT
12368 p_ri = 0; /* no reverse insert */
12369 p_hkmap = 0; /* no Hebrew keyboard */
12370#endif
12371 /* set global values for local buffer options */
12372 p_tw = 0;
12373 p_wm = 0;
12374 p_sts = 0;
12375 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012376#ifdef FEAT_VARTABS
12377 if (p_vsts)
12378 free_string_option(p_vsts);
12379 p_vsts = empty_option;
12380#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012381 }
12382
12383 /*
12384 * Paste switched from on to off: Restore saved values.
12385 */
12386 else if (old_p_paste)
12387 {
12388 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012389 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012390 {
12391 buf->b_p_tw = buf->b_p_tw_nopaste;
12392 buf->b_p_wm = buf->b_p_wm_nopaste;
12393 buf->b_p_sts = buf->b_p_sts_nopaste;
12394 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012395 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012396#ifdef FEAT_VARTABS
12397 if (buf->b_p_vsts)
12398 free_string_option(buf->b_p_vsts);
12399 buf->b_p_vsts = buf->b_p_vsts_nopaste
12400 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12401 if (buf->b_p_vsts_array)
12402 vim_free(buf->b_p_vsts_array);
12403 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12404 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12405 else
12406 buf->b_p_vsts_array = 0;
12407#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012408 }
12409
12410 /* restore global options */
12411 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012412 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012413#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012414 if (p_ru != save_ru)
12415 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012416 p_ru = save_ru;
12417#endif
12418#ifdef FEAT_RIGHTLEFT
12419 p_ri = save_ri;
12420 p_hkmap = save_hkmap;
12421#endif
12422 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012423 p_ai = p_ai_nopaste;
12424 p_et = p_et_nopaste;
12425 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012426 p_tw = p_tw_nopaste;
12427 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012428#ifdef FEAT_VARTABS
12429 if (p_vsts)
12430 free_string_option(p_vsts);
12431 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12432#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012433 }
12434
12435 old_p_paste = p_paste;
12436}
12437
12438/*
12439 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12440 *
12441 * Reset 'compatible' and set the values for options that didn't get set yet
12442 * to the Vim defaults.
12443 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012444 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445 */
12446 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012447vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012448{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012449 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012450 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012451 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012452
12453 if (!option_was_set((char_u *)"cp"))
12454 {
12455 p_cp = FALSE;
12456 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12457 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12458 set_option_default(opt_idx, OPT_FREE, FALSE);
12459 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012460 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012461 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012462
12463 if (fname != NULL)
12464 {
12465 p = vim_getenv(envname, &dofree);
12466 if (p == NULL)
12467 {
12468 /* Set $MYVIMRC to the first vimrc file found. */
12469 p = FullName_save(fname, FALSE);
12470 if (p != NULL)
12471 {
12472 vim_setenv(envname, p);
12473 vim_free(p);
12474 }
12475 }
12476 else if (dofree)
12477 vim_free(p);
12478 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012479}
12480
12481/*
12482 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12483 */
12484 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012485change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012486{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012487 int opt_idx;
12488
Bram Moolenaar071d4272004-06-13 20:20:40 +000012489 if (p_cp != on)
12490 {
12491 p_cp = on;
12492 compatible_set();
12493 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012494 opt_idx = findoption((char_u *)"cp");
12495 if (opt_idx >= 0)
12496 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012497}
12498
12499/*
12500 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012501 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012502 */
12503 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012504option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012505{
12506 int idx;
12507
12508 idx = findoption(name);
12509 if (idx < 0) /* unknown option */
12510 return FALSE;
12511 if (options[idx].flags & P_WAS_SET)
12512 return TRUE;
12513 return FALSE;
12514}
12515
12516/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012517 * Reset the flag indicating option "name" was set.
12518 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012519 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012520reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012521{
12522 int idx = findoption(name);
12523
12524 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012525 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012526 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012527 return OK;
12528 }
12529 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012530}
12531
12532/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012533 * compatible_set() - Called when 'compatible' has been set or unset.
12534 *
12535 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12536 * flag) to a Vi compatible value.
12537 * When 'compatible' is unset: Set all options that have a different default
12538 * for Vim (without the P_VI_DEF flag) to that default.
12539 */
12540 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012541compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012542{
12543 int opt_idx;
12544
12545 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12546 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12547 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12548 set_option_default(opt_idx, OPT_FREE, p_cp);
12549 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012550 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012551}
12552
12553#ifdef FEAT_LINEBREAK
12554
12555# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12556 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012557 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012558# endif
12559
12560/*
12561 * fill_breakat_flags() -- called when 'breakat' changes value.
12562 */
12563 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012564fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012565{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012566 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012567 int i;
12568
12569 for (i = 0; i < 256; i++)
12570 breakat_flags[i] = FALSE;
12571
12572 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012573 for (p = p_breakat; *p; p++)
12574 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012575}
12576
12577# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012578 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012579# endif
12580
12581#endif
12582
12583/*
12584 * Check an option that can be a range of string values.
12585 *
12586 * Return OK for correct value, FAIL otherwise.
12587 * Empty is always OK.
12588 */
12589 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012590check_opt_strings(
12591 char_u *val,
12592 char **values,
12593 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012594{
12595 return opt_strings_flags(val, values, NULL, list);
12596}
12597
12598/*
12599 * Handle an option that can be a range of string values.
12600 * Set a flag in "*flagp" for each string present.
12601 *
12602 * Return OK for correct value, FAIL otherwise.
12603 * Empty is always OK.
12604 */
12605 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012606opt_strings_flags(
12607 char_u *val, /* new value */
12608 char **values, /* array of valid string values */
12609 unsigned *flagp,
12610 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012611{
12612 int i;
12613 int len;
12614 unsigned new_flags = 0;
12615
12616 while (*val)
12617 {
12618 for (i = 0; ; ++i)
12619 {
12620 if (values[i] == NULL) /* val not found in values[] */
12621 return FAIL;
12622
12623 len = (int)STRLEN(values[i]);
12624 if (STRNCMP(values[i], val, len) == 0
12625 && ((list && val[len] == ',') || val[len] == NUL))
12626 {
12627 val += len + (val[len] == ',');
12628 new_flags |= (1 << i);
12629 break; /* check next item in val list */
12630 }
12631 }
12632 }
12633 if (flagp != NULL)
12634 *flagp = new_flags;
12635
12636 return OK;
12637}
12638
12639/*
12640 * Read the 'wildmode' option, fill wim_flags[].
12641 */
12642 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012643check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012644{
12645 char_u new_wim_flags[4];
12646 char_u *p;
12647 int i;
12648 int idx = 0;
12649
12650 for (i = 0; i < 4; ++i)
12651 new_wim_flags[i] = 0;
12652
12653 for (p = p_wim; *p; ++p)
12654 {
12655 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12656 ;
12657 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12658 return FAIL;
12659 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12660 new_wim_flags[idx] |= WIM_LONGEST;
12661 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12662 new_wim_flags[idx] |= WIM_FULL;
12663 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12664 new_wim_flags[idx] |= WIM_LIST;
12665 else
12666 return FAIL;
12667 p += i;
12668 if (*p == NUL)
12669 break;
12670 if (*p == ',')
12671 {
12672 if (idx == 3)
12673 return FAIL;
12674 ++idx;
12675 }
12676 }
12677
12678 /* fill remaining entries with last flag */
12679 while (idx < 3)
12680 {
12681 new_wim_flags[idx + 1] = new_wim_flags[idx];
12682 ++idx;
12683 }
12684
12685 /* only when there are no errors, wim_flags[] is changed */
12686 for (i = 0; i < 4; ++i)
12687 wim_flags[i] = new_wim_flags[i];
12688 return OK;
12689}
12690
12691/*
12692 * Check if backspacing over something is allowed.
12693 */
12694 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012695can_bs(
12696 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012697{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012698#ifdef FEAT_JOB_CHANNEL
12699 if (what == BS_START && bt_prompt(curbuf))
12700 return FALSE;
12701#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012702 switch (*p_bs)
12703 {
12704 case '2': return TRUE;
12705 case '1': return (what != BS_START);
12706 case '0': return FALSE;
12707 }
12708 return vim_strchr(p_bs, what) != NULL;
12709}
12710
12711/*
12712 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12713 * the file must be considered changed when the value is different.
12714 */
12715 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012716save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012717{
12718 buf->b_start_ffc = *buf->b_p_ff;
12719 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012720 buf->b_start_bomb = buf->b_p_bomb;
12721
Bram Moolenaar071d4272004-06-13 20:20:40 +000012722 /* Only use free/alloc when necessary, they take time. */
12723 if (buf->b_start_fenc == NULL
12724 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12725 {
12726 vim_free(buf->b_start_fenc);
12727 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12728 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012729}
12730
12731/*
12732 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12733 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012734 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12735 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012736 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012737 * When "ignore_empty" is true don't consider a new, empty buffer to be
12738 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012739 */
12740 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012741file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012742{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012743 /* In a buffer that was never loaded the options are not valid. */
12744 if (buf->b_flags & BF_NEVERLOADED)
12745 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012746 if (ignore_empty
12747 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012748 && buf->b_ml.ml_line_count == 1
12749 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12750 return FALSE;
12751 if (buf->b_start_ffc != *buf->b_p_ff)
12752 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012753 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012754 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012755 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12756 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012757 if (buf->b_start_fenc == NULL)
12758 return (*buf->b_p_fenc != NUL);
12759 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012760}
12761
12762/*
12763 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12764 */
12765 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012766check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012767{
12768 return check_opt_strings(p, p_ff_values, FALSE);
12769}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012770
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012771#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012772
12773/*
12774 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012775 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012776 */
12777 int
12778tabstop_set(char_u *var, int **array)
12779{
12780 int valcount = 1;
12781 int t;
12782 char_u *cp;
12783
Bram Moolenaar64f41072018-10-15 22:51:50 +020012784 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012785 {
12786 *array = NULL;
12787 return TRUE;
12788 }
12789
Bram Moolenaar64f41072018-10-15 22:51:50 +020012790 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012791 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012792 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012793 {
12794 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012795
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012796 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12797 {
12798 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012799 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012800 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012801 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012802 return FALSE;
12803 }
12804 }
12805
12806 if (VIM_ISDIGIT(*cp))
12807 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012808 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012809 {
12810 ++valcount;
12811 continue;
12812 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012813 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012814 return FALSE;
12815 }
12816
Bram Moolenaar64f41072018-10-15 22:51:50 +020012817 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012818 if (*array == NULL)
12819 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012820 (*array)[0] = valcount;
12821
12822 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012823 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012824 {
12825 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012826 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012827 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012828 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012829 ++cp;
12830 }
12831
12832 return TRUE;
12833}
12834
12835/*
12836 * Calculate the number of screen spaces a tab will occupy.
12837 * If "vts" is set then the tab widths are taken from that array,
12838 * otherwise the value of ts is used.
12839 */
12840 int
12841tabstop_padding(colnr_T col, int ts_arg, int *vts)
12842{
12843 int ts = ts_arg == 0 ? 8 : ts_arg;
12844 int tabcount;
12845 colnr_T tabcol = 0;
12846 int t;
12847 int padding = 0;
12848
12849 if (vts == NULL || vts[0] == 0)
12850 return ts - (col % ts);
12851
12852 tabcount = vts[0];
12853
12854 for (t = 1; t <= tabcount; ++t)
12855 {
12856 tabcol += vts[t];
12857 if (tabcol > col)
12858 {
12859 padding = (int)(tabcol - col);
12860 break;
12861 }
12862 }
12863 if (t > tabcount)
12864 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12865
12866 return padding;
12867}
12868
12869/*
12870 * Find the size of the tab that covers a particular column.
12871 */
12872 int
12873tabstop_at(colnr_T col, int ts, int *vts)
12874{
12875 int tabcount;
12876 colnr_T tabcol = 0;
12877 int t;
12878 int tab_size = 0;
12879
12880 if (vts == 0 || vts[0] == 0)
12881 return ts;
12882
12883 tabcount = vts[0];
12884 for (t = 1; t <= tabcount; ++t)
12885 {
12886 tabcol += vts[t];
12887 if (tabcol > col)
12888 {
12889 tab_size = vts[t];
12890 break;
12891 }
12892 }
12893 if (t > tabcount)
12894 tab_size = vts[tabcount];
12895
12896 return tab_size;
12897}
12898
12899/*
12900 * Find the column on which a tab starts.
12901 */
12902 colnr_T
12903tabstop_start(colnr_T col, int ts, int *vts)
12904{
12905 int tabcount;
12906 colnr_T tabcol = 0;
12907 int t;
12908 int excess;
12909
Bram Moolenaar0119a592018-06-24 23:53:28 +020012910 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012911 return (col / ts) * ts;
12912
12913 tabcount = vts[0];
12914 for (t = 1; t <= tabcount; ++t)
12915 {
12916 tabcol += vts[t];
12917 if (tabcol > col)
12918 return tabcol - vts[t];
12919 }
12920
12921 excess = tabcol % vts[tabcount];
12922 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12923}
12924
12925/*
12926 * Find the number of tabs and spaces necessary to get from one column
12927 * to another.
12928 */
12929 void
12930tabstop_fromto(
12931 colnr_T start_col,
12932 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012933 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012934 int *vts,
12935 int *ntabs,
12936 int *nspcs)
12937{
12938 int spaces = end_col - start_col;
12939 colnr_T tabcol = 0;
12940 int padding = 0;
12941 int tabcount;
12942 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012943 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012944
Bram Moolenaar0119a592018-06-24 23:53:28 +020012945 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012946 {
12947 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012948 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012949
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012950 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012951 if (spaces >= initspc)
12952 {
12953 spaces -= initspc;
12954 tabs++;
12955 }
12956 tabs += spaces / ts;
12957 spaces -= (spaces / ts) * ts;
12958
12959 *ntabs = tabs;
12960 *nspcs = spaces;
12961 return;
12962 }
12963
12964 /* Find the padding needed to reach the next tabstop. */
12965 tabcount = vts[0];
12966 for (t = 1; t <= tabcount; ++t)
12967 {
12968 tabcol += vts[t];
12969 if (tabcol > start_col)
12970 {
12971 padding = (int)(tabcol - start_col);
12972 break;
12973 }
12974 }
12975 if (t > tabcount)
12976 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12977
12978 /* If the space needed is less than the padding no tabs can be used. */
12979 if (spaces < padding)
12980 {
12981 *ntabs = 0;
12982 *nspcs = spaces;
12983 return;
12984 }
12985
12986 *ntabs = 1;
12987 spaces -= padding;
12988
12989 /* At least one tab has been used. See if any more will fit. */
12990 while (spaces != 0 && ++t <= tabcount)
12991 {
12992 padding = vts[t];
12993 if (spaces < padding)
12994 {
12995 *nspcs = spaces;
12996 return;
12997 }
12998 ++*ntabs;
12999 spaces -= padding;
13000 }
13001
13002 *ntabs += spaces / vts[tabcount];
13003 *nspcs = spaces % vts[tabcount];
13004}
13005
13006/*
13007 * See if two tabstop arrays contain the same values.
13008 */
13009 int
13010tabstop_eq(int *ts1, int *ts2)
13011{
13012 int t;
13013
13014 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13015 return FALSE;
13016 if (ts1 == ts2)
13017 return TRUE;
13018 if (ts1[0] != ts2[0])
13019 return FALSE;
13020
13021 for (t = 1; t <= ts1[0]; ++t)
13022 if (ts1[t] != ts2[t])
13023 return FALSE;
13024
13025 return TRUE;
13026}
13027
Bram Moolenaar113e1072019-01-20 15:30:40 +010013028#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013029/*
13030 * Copy a tabstop array, allocating space for the new array.
13031 */
13032 int *
13033tabstop_copy(int *oldts)
13034{
13035 int *newts;
13036 int t;
13037
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013038 if (oldts == NULL)
13039 return NULL;
13040 newts = (int *)alloc((unsigned)((oldts[0] + 1) * sizeof(int)));
13041 if (newts != NULL)
13042 for (t = 0; t <= oldts[0]; ++t)
13043 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013044 return newts;
13045}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013046#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013047
13048/*
13049 * Return a count of the number of tabstops.
13050 */
13051 int
13052tabstop_count(int *ts)
13053{
13054 return ts != NULL ? ts[0] : 0;
13055}
13056
13057/*
13058 * Return the first tabstop, or 8 if there are no tabstops defined.
13059 */
13060 int
13061tabstop_first(int *ts)
13062{
13063 return ts != NULL ? ts[1] : 8;
13064}
13065
13066#endif
13067
Bram Moolenaar14f24742012-08-08 18:01:05 +020013068/*
13069 * Return the effective shiftwidth value for current buffer, using the
13070 * 'tabstop' value when 'shiftwidth' is zero.
13071 */
13072 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013073get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013074{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013075 return get_sw_value_col(buf, 0);
13076}
13077
13078/*
13079 * Idem, using the first non-black in the current line.
13080 */
13081 long
13082get_sw_value_indent(buf_T *buf)
13083{
13084 pos_T pos = curwin->w_cursor;
13085
13086 pos.col = getwhitecols_curline();
13087 return get_sw_value_pos(buf, &pos);
13088}
13089
13090/*
13091 * Idem, using "pos".
13092 */
13093 long
13094get_sw_value_pos(buf_T *buf, pos_T *pos)
13095{
13096 pos_T save_cursor = curwin->w_cursor;
13097 long sw_value;
13098
13099 curwin->w_cursor = *pos;
13100 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13101 curwin->w_cursor = save_cursor;
13102 return sw_value;
13103}
13104
13105/*
13106 * Idem, using virtual column "col".
13107 */
13108 long
13109get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13110{
13111 return buf->b_p_sw ? buf->b_p_sw :
13112 #ifdef FEAT_VARTABS
13113 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13114 #else
13115 buf->b_p_ts;
13116 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013117}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013118
13119/*
13120 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013121 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013122 */
13123 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013124get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013125{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013126 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013127}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013128
13129/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013130 * Return the effective 'scrolloff' value for the current window, using the
13131 * global value when appropriate.
13132 */
13133 long
13134get_scrolloff_value(void)
13135{
13136 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13137}
13138
13139/*
13140 * Return the effective 'sidescrolloff' value for the current window, using the
13141 * global value when appropriate.
13142 */
13143 long
13144get_sidescrolloff_value(void)
13145{
13146 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13147}
13148
13149/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013150 * Check matchpairs option for "*initc".
13151 * If there is a match set "*initc" to the matching character and "*findc" to
13152 * the opposite character. Set "*backwards" to the direction.
13153 * When "switchit" is TRUE swap the direction.
13154 */
13155 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013156find_mps_values(
13157 int *initc,
13158 int *findc,
13159 int *backwards,
13160 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013161{
13162 char_u *ptr;
13163
13164 ptr = curbuf->b_p_mps;
13165 while (*ptr != NUL)
13166 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013167 if (has_mbyte)
13168 {
13169 char_u *prev;
13170
13171 if (mb_ptr2char(ptr) == *initc)
13172 {
13173 if (switchit)
13174 {
13175 *findc = *initc;
13176 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13177 *backwards = TRUE;
13178 }
13179 else
13180 {
13181 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13182 *backwards = FALSE;
13183 }
13184 return;
13185 }
13186 prev = ptr;
13187 ptr += mb_ptr2len(ptr) + 1;
13188 if (mb_ptr2char(ptr) == *initc)
13189 {
13190 if (switchit)
13191 {
13192 *findc = *initc;
13193 *initc = mb_ptr2char(prev);
13194 *backwards = FALSE;
13195 }
13196 else
13197 {
13198 *findc = mb_ptr2char(prev);
13199 *backwards = TRUE;
13200 }
13201 return;
13202 }
13203 ptr += mb_ptr2len(ptr);
13204 }
13205 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013206 {
13207 if (*ptr == *initc)
13208 {
13209 if (switchit)
13210 {
13211 *backwards = TRUE;
13212 *findc = *initc;
13213 *initc = ptr[2];
13214 }
13215 else
13216 {
13217 *backwards = FALSE;
13218 *findc = ptr[2];
13219 }
13220 return;
13221 }
13222 ptr += 2;
13223 if (*ptr == *initc)
13224 {
13225 if (switchit)
13226 {
13227 *backwards = FALSE;
13228 *findc = *initc;
13229 *initc = ptr[-2];
13230 }
13231 else
13232 {
13233 *backwards = TRUE;
13234 *findc = ptr[-2];
13235 }
13236 return;
13237 }
13238 ++ptr;
13239 }
13240 if (*ptr == ',')
13241 ++ptr;
13242 }
13243}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013244
13245#if defined(FEAT_LINEBREAK) || defined(PROTO)
13246/*
13247 * This is called when 'breakindentopt' is changed and when a window is
13248 * initialized.
13249 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013250 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013251briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013252{
13253 char_u *p;
13254 int bri_shift = 0;
13255 long bri_min = 20;
13256 int bri_sbr = FALSE;
13257
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013258 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013259 while (*p != NUL)
13260 {
13261 if (STRNCMP(p, "shift:", 6) == 0
13262 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13263 {
13264 p += 6;
13265 bri_shift = getdigits(&p);
13266 }
13267 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13268 {
13269 p += 4;
13270 bri_min = getdigits(&p);
13271 }
13272 else if (STRNCMP(p, "sbr", 3) == 0)
13273 {
13274 p += 3;
13275 bri_sbr = TRUE;
13276 }
13277 if (*p != ',' && *p != NUL)
13278 return FAIL;
13279 if (*p == ',')
13280 ++p;
13281 }
13282
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013283 wp->w_p_brishift = bri_shift;
13284 wp->w_p_brimin = bri_min;
13285 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013286
13287 return OK;
13288}
13289#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013290
13291/*
13292 * Get the local or global value of 'backupcopy'.
13293 */
13294 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013295get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013296{
13297 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13298}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013299
13300#if defined(FEAT_SIGNS) || defined(PROTO)
13301/*
13302 * Return TRUE when window "wp" has a column to draw signs in.
13303 */
13304 int
13305signcolumn_on(win_T *wp)
13306{
13307 if (*wp->w_p_scl == 'n')
13308 return FALSE;
13309 if (*wp->w_p_scl == 'y')
13310 return TRUE;
13311 return (wp->w_buffer->b_signlist != NULL
13312# ifdef FEAT_NETBEANS_INTG
13313 || wp->w_buffer->b_has_sign_column
13314# endif
13315 );
13316}
13317#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013318
13319#if defined(FEAT_EVAL) || defined(PROTO)
13320/*
13321 * Get window or buffer local options.
13322 */
13323 dict_T *
13324get_winbuf_options(int bufopt)
13325{
13326 dict_T *d;
13327 int opt_idx;
13328
13329 d = dict_alloc();
13330 if (d == NULL)
13331 return NULL;
13332
13333 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13334 {
13335 struct vimoption *opt = &options[opt_idx];
13336
13337 if ((bufopt && (opt->indir & PV_BUF))
13338 || (!bufopt && (opt->indir & PV_WIN)))
13339 {
13340 char_u *varp = get_varp(opt);
13341
13342 if (varp != NULL)
13343 {
13344 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013345 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013346 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013347 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013348 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013349 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013350 }
13351 }
13352 }
13353
13354 return d;
13355}
13356#endif