blob: 9583aa3697de472d43e60977bddb597e8a3e76f5 [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 Moolenaar9dfa3132019-05-04 21:08:40 +02002452 {(char_u *)"S", (char_u *)"filnxtToOS"}
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 Moolenaar9dfa3132019-05-04 21:08:40 +02003314 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003315 }
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 Moolenaar6aa2cd42016-02-16 15:06:59 +01003324 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003326 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003327 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003328
3329#ifdef FEAT_WILDIGN
3330 /*
3331 * Set the default for 'backupskip' to include environment variables for
3332 * temp files.
3333 */
3334 {
3335# ifdef UNIX
3336 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3337# else
3338 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3339# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003340 int len;
3341 garray_T ga;
3342 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343
3344 ga_init2(&ga, 1, 100);
3345 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3346 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003347 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348# ifdef UNIX
3349 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003350# ifdef MACOS_X
3351 p = (char_u *)"/private/tmp";
3352# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003354# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355 else
3356# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003357 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358 if (p != NULL && *p != NUL)
3359 {
3360 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003361 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362 if (ga_grow(&ga, len) == OK)
3363 {
3364 if (ga.ga_len > 0)
3365 STRCAT(ga.ga_data, ",");
3366 STRCAT(ga.ga_data, p);
3367 add_pathsep(ga.ga_data);
3368 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369 ga.ga_len += len;
3370 }
3371 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003372 if (mustfree)
3373 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374 }
3375 if (ga.ga_data != NULL)
3376 {
3377 set_string_default("bsk", ga.ga_data);
3378 vim_free(ga.ga_data);
3379 }
3380 }
3381#endif
3382
3383 /*
3384 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3385 */
3386 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003387 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003388 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003389#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3390 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3391#endif
3392 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003394 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003395 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396#else
3397# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003398 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003399 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003401 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003402# endif
3403#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003404 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003405 opt_idx = findoption((char_u *)"maxmem");
3406 if (opt_idx >= 0)
3407 {
3408#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003409 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3410 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003411#endif
3412 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3413 }
3414 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003415 }
3416
Bram Moolenaar071d4272004-06-13 20:20:40 +00003417#ifdef FEAT_SEARCHPATH
3418 {
3419 char_u *cdpath;
3420 char_u *buf;
3421 int i;
3422 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003423 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424
3425 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003426 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003427 if (cdpath != NULL)
3428 {
3429 buf = alloc((unsigned)((STRLEN(cdpath) << 1) + 2));
3430 if (buf != NULL)
3431 {
3432 buf[0] = ','; /* start with ",", current dir first */
3433 j = 1;
3434 for (i = 0; cdpath[i] != NUL; ++i)
3435 {
3436 if (vim_ispathlistsep(cdpath[i]))
3437 buf[j++] = ',';
3438 else
3439 {
3440 if (cdpath[i] == ' ' || cdpath[i] == ',')
3441 buf[j++] = '\\';
3442 buf[j++] = cdpath[i];
3443 }
3444 }
3445 buf[j] = NUL;
3446 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003447 if (opt_idx >= 0)
3448 {
3449 options[opt_idx].def_val[VI_DEFAULT] = buf;
3450 options[opt_idx].flags |= P_DEF_ALLOCED;
3451 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003452 else
3453 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003454 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003455 if (mustfree)
3456 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003457 }
3458 }
3459#endif
3460
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003461#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462 /* Set print encoding on platforms that don't default to latin1 */
3463 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003464# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003465 (char_u *)"cp1252"
3466# else
3467# ifdef VMS
3468 (char_u *)"dec-mcs"
3469# else
3470# ifdef EBCDIC
3471 (char_u *)"ebcdic-uk"
3472# else
3473# ifdef MAC
3474 (char_u *)"mac-roman"
3475# else /* HPUX */
3476 (char_u *)"hp-roman8"
3477# endif
3478# endif
3479# endif
3480# endif
3481 );
3482#endif
3483
3484#ifdef FEAT_POSTSCRIPT
3485 /* 'printexpr' must be allocated to be able to evaluate it. */
3486 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003487# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003488 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003489# else
3490# ifdef VMS
3491 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3492
3493# else
3494 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3495# endif
3496# endif
3497 );
3498#endif
3499
3500 /*
3501 * Set all the options (except the terminal options) to their default
3502 * value. Also set the global value for local options.
3503 */
3504 set_options_default(0);
3505
Bram Moolenaar07268702018-03-01 21:57:32 +01003506#ifdef CLEAN_RUNTIMEPATH
3507 if (clean_arg)
3508 {
3509 opt_idx = findoption((char_u *)"runtimepath");
3510 if (opt_idx >= 0)
3511 {
3512 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3513 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3514 }
3515 opt_idx = findoption((char_u *)"packpath");
3516 if (opt_idx >= 0)
3517 {
3518 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3519 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3520 }
3521 }
3522#endif
3523
Bram Moolenaar071d4272004-06-13 20:20:40 +00003524#ifdef FEAT_GUI
3525 if (found_reverse_arg)
3526 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3527#endif
3528
3529 curbuf->b_p_initialized = TRUE;
3530 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003531 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003532 check_buf_options(curbuf);
3533 check_win_options(curwin);
3534 check_options();
3535
3536 /* Must be before option_expand(), because that one needs vim_isIDc() */
3537 didset_options();
3538
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003539#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003540 /* Use the current chartab for the generic chartab. This is not in
3541 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003542 init_spell_chartab();
3543#endif
3544
Bram Moolenaar071d4272004-06-13 20:20:40 +00003545 /*
3546 * Expand environment variables and things like "~" for the defaults.
3547 * If option_expand() returns non-NULL the variable is expanded. This can
3548 * only happen for non-indirect options.
3549 * Also set the default to the expanded value, so ":set" does not list
3550 * them.
3551 * Don't set the P_ALLOCED flag, because we don't want to free the
3552 * default.
3553 */
3554 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3555 {
3556 if ((options[opt_idx].flags & P_GETTEXT)
3557 && options[opt_idx].var != NULL)
3558 p = (char_u *)_(*(char **)options[opt_idx].var);
3559 else
3560 p = option_expand(opt_idx, NULL);
3561 if (p != NULL && (p = vim_strsave(p)) != NULL)
3562 {
3563 *(char_u **)options[opt_idx].var = p;
3564 /* VIMEXP
3565 * Defaults for all expanded options are currently the same for Vi
3566 * and Vim. When this changes, add some code here! Also need to
3567 * split P_DEF_ALLOCED in two.
3568 */
3569 if (options[opt_idx].flags & P_DEF_ALLOCED)
3570 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3571 options[opt_idx].def_val[VI_DEFAULT] = p;
3572 options[opt_idx].flags |= P_DEF_ALLOCED;
3573 }
3574 }
3575
Bram Moolenaar071d4272004-06-13 20:20:40 +00003576 save_file_ff(curbuf); /* Buffer is unchanged */
3577
Bram Moolenaar071d4272004-06-13 20:20:40 +00003578#if defined(FEAT_ARABIC)
3579 /* Detect use of mlterm.
3580 * Mlterm is a terminal emulator akin to xterm that has some special
3581 * abilities (bidi namely).
3582 * NOTE: mlterm's author is being asked to 'set' a variable
3583 * instead of an environment variable due to inheritance.
3584 */
3585 if (mch_getenv((char_u *)"MLTERM") != NULL)
3586 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3587#endif
3588
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003589 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003590
Bram Moolenaar4f974752019-02-17 17:44:42 +01003591# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003592 /*
3593 * If $LANG isn't set, try to get a good value for it. This makes the
3594 * right language be used automatically. Don't do this for English.
3595 */
3596 if (mch_getenv((char_u *)"LANG") == NULL)
3597 {
3598 char buf[20];
3599
3600 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3601 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3602 * only the first two. */
3603 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3604 (LPTSTR)buf, 20);
3605 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3606 {
3607 /* There are a few exceptions (probably more) */
3608 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3609 STRCPY(buf, "zh_TW");
3610 else if (STRNICMP(buf, "chs", 3) == 0
3611 || STRNICMP(buf, "zhc", 3) == 0)
3612 STRCPY(buf, "zh_CN");
3613 else if (STRNICMP(buf, "jp", 2) == 0)
3614 STRCPY(buf, "ja");
3615 else
3616 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003617 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003618 }
3619 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003620# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003621# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003622 /* Moved to os_mac_conv.c to avoid dependency problems. */
3623 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003624# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625# endif
3626
3627 /* enc_locale() will try to find the encoding of the current locale. */
3628 p = enc_locale();
3629 if (p != NULL)
3630 {
3631 char_u *save_enc;
3632
3633 /* Try setting 'encoding' and check if the value is valid.
3634 * If not, go back to the default "latin1". */
3635 save_enc = p_enc;
3636 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003637 if (STRCMP(p_enc, "gb18030") == 0)
3638 {
3639 /* We don't support "gb18030", but "cp936" is a good substitute
3640 * for practical purposes, thus use that. It's not an alias to
3641 * still support conversion between gb18030 and utf-8. */
3642 p_enc = vim_strsave((char_u *)"cp936");
3643 vim_free(p);
3644 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003645 if (mb_init() == NULL)
3646 {
3647 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003648 if (opt_idx >= 0)
3649 {
3650 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3651 options[opt_idx].flags |= P_DEF_ALLOCED;
3652 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003653
Bram Moolenaard0573012017-10-28 21:11:06 +02003654#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003655 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003656 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003657 /* Adjust the default for 'isprint' and 'iskeyword' to match
3658 * latin1. Also set the defaults for when 'nocompatible' is
3659 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003660 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003661 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003662 set_string_option_direct((char_u *)"isk", -1,
3663 ISK_LATIN1, OPT_FREE, SID_NONE);
3664 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003665 if (opt_idx >= 0)
3666 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003667 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003668 if (opt_idx >= 0)
3669 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003670 (void)init_chartab();
3671 }
3672#endif
3673
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003674#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003675 /* Win32 console: When GetACP() returns a different value from
3676 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003677 if (
3678# ifdef VIMDLL
3679 (!gui.in_use && !gui.starting) &&
3680# endif
3681 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003682 {
3683 char buf[50];
3684
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003685 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3686 * Use an alternative value. */
3687 if (GetConsoleCP() == 0)
3688 sprintf(buf, "cp%ld", (long)GetACP());
3689 else
3690 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003691 p_tenc = vim_strsave((char_u *)buf);
3692 if (p_tenc != NULL)
3693 {
3694 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003695 if (opt_idx >= 0)
3696 {
3697 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3698 options[opt_idx].flags |= P_DEF_ALLOCED;
3699 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700 convert_setup(&input_conv, p_tenc, p_enc);
3701 convert_setup(&output_conv, p_enc, p_tenc);
3702 }
3703 else
3704 p_tenc = empty_option;
3705 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003706#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003707#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003708 /* $HOME may have characters in active code page. */
3709 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003711 }
3712 else
3713 {
3714 vim_free(p_enc);
3715 p_enc = save_enc;
3716 }
3717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718
3719#ifdef FEAT_MULTI_LANG
3720 /* Set the default for 'helplang'. */
3721 set_helplang_default(get_mess_lang());
3722#endif
3723}
3724
3725/*
3726 * Set an option to its default value.
3727 * This does not take care of side effects!
3728 */
3729 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003730set_option_default(
3731 int opt_idx,
3732 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3733 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003734{
3735 char_u *varp; /* pointer to variable for current option */
3736 int dvi; /* index in def_val[] */
3737 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003738 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3740
3741 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3742 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003743 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 {
3745 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3746 if (flags & P_STRING)
3747 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003748 /* Use set_string_option_direct() for local options to handle
3749 * freeing and allocating the value. */
3750 if (options[opt_idx].indir != PV_NONE)
3751 set_string_option_direct(NULL, opt_idx,
3752 options[opt_idx].def_val[dvi], opt_flags, 0);
3753 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003754 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003755 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3756 free_string_option(*(char_u **)(varp));
3757 *(char_u **)varp = options[opt_idx].def_val[dvi];
3758 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 }
3760 }
3761 else if (flags & P_NUM)
3762 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003763 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003764 win_comp_scroll(curwin);
3765 else
3766 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003767 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3768
3769 if ((long *)varp == &curwin->w_p_so
3770 || (long *)varp == &curwin->w_p_siso)
3771 // 'scrolloff' and 'sidescrolloff' local values have a
3772 // different default value than the global default.
3773 *(long *)varp = -1;
3774 else
3775 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 /* May also set global value for local option. */
3777 if (both)
3778 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003779 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003780 }
3781 }
3782 else /* P_BOOL */
3783 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003784 /* the cast to long is required for Manx C, long_i is needed for
3785 * MSVC */
3786 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003787#ifdef UNIX
3788 /* 'modeline' defaults to off for root */
3789 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3790 *(int *)varp = FALSE;
3791#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003792 /* May also set global value for local option. */
3793 if (both)
3794 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3795 *(int *)varp;
3796 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003797
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003798 /* The default value is not insecure. */
3799 flagsp = insecure_flag(opt_idx, opt_flags);
3800 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801 }
3802
3803#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003804 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003805#endif
3806}
3807
3808/*
3809 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003810 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811 */
3812 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003813set_options_default(
3814 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815{
3816 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003817 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003818 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819
3820 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003821 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003822 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003823 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003824# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003825 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003826 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003827# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003828 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 set_option_default(i, opt_flags, p_cp);
3830
Bram Moolenaar071d4272004-06-13 20:20:40 +00003831 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003832 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003834#ifdef FEAT_CINDENT
3835 parse_cino(curbuf);
3836#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837}
3838
3839/*
3840 * Set the Vi-default value of a string option.
3841 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003842 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003843 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003844 static void
3845set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003846{
3847 char_u *p;
3848 int opt_idx;
3849
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003850 if (escape && vim_strchr(val, ' ') != NULL)
3851 p = vim_strsave_escaped(val, (char_u *)" ");
3852 else
3853 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003854 if (p != NULL) /* we don't want a NULL */
3855 {
3856 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003857 if (opt_idx >= 0)
3858 {
3859 if (options[opt_idx].flags & P_DEF_ALLOCED)
3860 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3861 options[opt_idx].def_val[VI_DEFAULT] = p;
3862 options[opt_idx].flags |= P_DEF_ALLOCED;
3863 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864 }
3865}
3866
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003867 void
3868set_string_default(char *name, char_u *val)
3869{
3870 set_string_default_esc(name, val, FALSE);
3871}
3872
Bram Moolenaar071d4272004-06-13 20:20:40 +00003873/*
3874 * Set the Vi-default value of a number option.
3875 * Used for 'lines' and 'columns'.
3876 */
3877 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003878set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003879{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003880 int opt_idx;
3881
3882 opt_idx = findoption((char_u *)name);
3883 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003884 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003885}
3886
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003887#if defined(EXITFREE) || defined(PROTO)
3888/*
3889 * Free all options.
3890 */
3891 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003892free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003893{
3894 int i;
3895
3896 for (i = 0; !istermoption(&options[i]); i++)
3897 {
3898 if (options[i].indir == PV_NONE)
3899 {
3900 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003901 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003902 free_string_option(*(char_u **)options[i].var);
3903 if (options[i].flags & P_DEF_ALLOCED)
3904 free_string_option(options[i].def_val[VI_DEFAULT]);
3905 }
3906 else if (options[i].var != VAR_WIN
3907 && (options[i].flags & P_STRING))
3908 /* buffer-local option: free global value */
3909 free_string_option(*(char_u **)options[i].var);
3910 }
3911}
3912#endif
3913
3914
Bram Moolenaar071d4272004-06-13 20:20:40 +00003915/*
3916 * Initialize the options, part two: After getting Rows and Columns and
3917 * setting 'term'.
3918 */
3919 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003920set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003921{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003922 int idx;
3923
Bram Moolenaar071d4272004-06-13 20:20:40 +00003924 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003925 * 'scroll' defaults to half the window height. The stored default is zero,
3926 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003927 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003928 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003929 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003930 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003931 comp_col();
3932
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003933 /*
3934 * 'window' is only for backwards compatibility with Vi.
3935 * Default is Rows - 1.
3936 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003937 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003938 p_window = Rows - 1;
3939 set_number_default("window", Rows - 1);
3940
Bram Moolenaarf740b292006-02-16 22:11:02 +00003941 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003942#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003943 /*
3944 * If 'background' wasn't set by the user, try guessing the value,
3945 * depending on the terminal name. Only need to check for terminals
3946 * with a dark background, that can handle color.
3947 */
3948 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003949 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3950 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003951 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003952 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003953 /* don't mark it as set, when starting the GUI it may be
3954 * changed again */
3955 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956 }
3957#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003958
3959#ifdef CURSOR_SHAPE
3960 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3961#endif
3962#ifdef FEAT_MOUSESHAPE
3963 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3964#endif
3965#ifdef FEAT_PRINTER
3966 (void)parse_printoptions(); /* parse 'printoptions' default value */
3967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968}
3969
3970/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003971 * Return "dark" or "light" depending on the kind of terminal.
3972 * This is just guessing! Recognized are:
3973 * "linux" Linux console
3974 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003975 * "cygwin.*" Cygwin shell
3976 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00003977 * We also check the COLORFGBG environment variable, which is set by
3978 * rxvt and derivatives. This variable contains either two or three
3979 * values separated by semicolons; we want the last value in either
3980 * case. If this value is 0-6 or 8, our background is dark.
3981 */
3982 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01003983term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00003984{
Bram Moolenaar4f974752019-02-17 17:44:42 +01003985#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003986 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003987 return (char_u *)"dark";
3988#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00003989 char_u *p;
3990
Bram Moolenaarf740b292006-02-16 22:11:02 +00003991 if (STRCMP(T_NAME, "linux") == 0
3992 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02003993 || STRNCMP(T_NAME, "cygwin", 6) == 0
3994 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00003995 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
3996 && (p = vim_strrchr(p, ';')) != NULL
3997 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
3998 && p[2] == NUL))
3999 return (char_u *)"dark";
4000 return (char_u *)"light";
4001#endif
4002}
4003
4004/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005 * Initialize the options, part three: After reading the .vimrc
4006 */
4007 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004008set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004009{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004010#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004011/*
4012 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4013 * This is done after other initializations, where 'shell' might have been
4014 * set, but only if they have not been set before.
4015 */
4016 char_u *p;
4017 int idx_srr;
4018 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004019# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004020 int idx_sp;
4021 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004022# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004023
4024 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004025 if (idx_srr < 0)
4026 do_srr = FALSE;
4027 else
4028 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004029# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004030 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004031 if (idx_sp < 0)
4032 do_sp = FALSE;
4033 else
4034 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004035# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004036 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037 if (p != NULL)
4038 {
4039 /*
4040 * Default for p_sp is "| tee", for p_srr is ">".
4041 * For known shells it is changed here to include stderr.
4042 */
4043 if ( fnamecmp(p, "csh") == 0
4044 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004045# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046 || fnamecmp(p, "csh.exe") == 0
4047 || fnamecmp(p, "tcsh.exe") == 0
4048# endif
4049 )
4050 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004051# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004052 if (do_sp)
4053 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004054# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004058# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4060 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062 if (do_srr)
4063 {
4064 p_srr = (char_u *)">&";
4065 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4066 }
4067 }
4068 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004069 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004070 if ( fnamecmp(p, "sh") == 0
4071 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004072 || fnamecmp(p, "mksh") == 0
4073 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004075 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004077 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004078# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004079 || fnamecmp(p, "cmd") == 0
4080 || fnamecmp(p, "sh.exe") == 0
4081 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004082 || fnamecmp(p, "mksh.exe") == 0
4083 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004084 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004085 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004086 || fnamecmp(p, "bash.exe") == 0
4087 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004088# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004091# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 if (do_sp)
4093 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004094# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004095 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4100 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004101# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 if (do_srr)
4103 {
4104 p_srr = (char_u *)">%s 2>&1";
4105 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4106 }
4107 }
4108 vim_free(p);
4109 }
4110#endif
4111
Bram Moolenaar4f974752019-02-17 17:44:42 +01004112#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004114 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4115 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 * This is done after other initializations, where 'shell' might have been
4117 * set, but only if they have not been set before. Default for p_shcf is
4118 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004119 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004121 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 {
4123 int idx3;
4124
4125 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004126 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
4128 p_shcf = (char_u *)"-c";
4129 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4130 }
4131
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 /* Somehow Win32 requires the quotes around the redirection too */
4133 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004134 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004135 {
4136 p_sxq = (char_u *)"\"";
4137 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4138 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004140 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4141 {
4142 int idx3;
4143
4144 /*
4145 * cmd.exe on Windows will strip the first and last double quote given
4146 * on the command line, e.g. most of the time things like:
4147 * cmd /c "my path/to/echo" "my args to echo"
4148 * become:
4149 * my path/to/echo" "my args to echo
4150 * when executed.
4151 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004152 * To avoid this, set shellxquote to surround the command in
4153 * parenthesis. This appears to make most commands work, without
4154 * breaking commands that worked previously, such as
4155 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004156 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004157 idx3 = findoption((char_u *)"sxq");
4158 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4159 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004160 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004161 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4162 }
4163
Bram Moolenaara64ba222012-02-12 23:23:31 +01004164 idx3 = findoption((char_u *)"shcf");
4165 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4166 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004167 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004168 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4169 }
4170 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171#endif
4172
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004173 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004174 {
4175 int idx_ffs = findoption((char_u *)"ffs");
4176
4177 /* Apply the first entry of 'fileformats' to the initial buffer. */
4178 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4179 set_fileformat(default_fileformat(), OPT_LOCAL);
4180 }
4181
Bram Moolenaar071d4272004-06-13 20:20:40 +00004182#ifdef FEAT_TITLE
4183 set_title_defaults();
4184#endif
4185}
4186
4187#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4188/*
4189 * When 'helplang' is still at its default value, set it to "lang".
4190 * Only the first two characters of "lang" are used.
4191 */
4192 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004193set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004194{
4195 int idx;
4196
4197 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4198 return;
4199 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004200 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004201 {
4202 if (options[idx].flags & P_ALLOCED)
4203 free_string_option(p_hlg);
4204 p_hlg = vim_strsave(lang);
4205 if (p_hlg == NULL)
4206 p_hlg = empty_option;
4207 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004208 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004209 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004210 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4211 {
4212 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4213 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4214 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004215 // any C like setting, such as C.UTF-8, becomes "en"
4216 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4217 {
4218 p_hlg[0] = 'e';
4219 p_hlg[1] = 'n';
4220 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004222 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004223 options[idx].flags |= P_ALLOCED;
4224 }
4225}
4226#endif
4227
4228#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004230gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004231{
4232 if (gui_get_lightness(gui.back_pixel) < 127)
4233 return (char_u *)"dark";
4234 return (char_u *)"light";
4235}
4236
4237/*
4238 * Option initializations that can only be done after opening the GUI window.
4239 */
4240 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004241init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242{
4243 /* Set the 'background' option according to the lightness of the
4244 * background color, unless the user has set it already. */
4245 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4246 {
4247 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4248 highlight_changed();
4249 }
4250}
4251#endif
4252
4253#ifdef FEAT_TITLE
4254/*
4255 * 'title' and 'icon' only default to true if they have not been set or reset
4256 * in .vimrc and we can read the old value.
4257 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4258 * they can be reset. This reduces startup time when using X on a remote
4259 * machine.
4260 */
4261 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004262set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004263{
4264 int idx1;
4265 long val;
4266
4267 /*
4268 * If GUI is (going to be) used, we can always set the window title and
4269 * icon name. Saves a bit of time, because the X11 display server does
4270 * not need to be contacted.
4271 */
4272 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004273 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004274 {
4275#ifdef FEAT_GUI
4276 if (gui.starting || gui.in_use)
4277 val = TRUE;
4278 else
4279#endif
4280 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004281 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004282 p_title = val;
4283 }
4284 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004285 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004286 {
4287#ifdef FEAT_GUI
4288 if (gui.starting || gui.in_use)
4289 val = TRUE;
4290 else
4291#endif
4292 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004293 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004294 p_icon = val;
4295 }
4296}
4297#endif
4298
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004299#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004300 static void
4301trigger_optionsset_string(
4302 int opt_idx,
4303 int opt_flags,
4304 char_u *oldval,
4305 char_u *newval)
4306{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004307 // Don't do this recursively.
4308 if (oldval != NULL && newval != NULL
4309 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004310 {
4311 char_u buf_type[7];
4312
4313 sprintf((char *)buf_type, "%s",
4314 (opt_flags & OPT_LOCAL) ? "local" : "global");
4315 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4316 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4317 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
4318 apply_autocmds(EVENT_OPTIONSET,
4319 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4320 reset_v_option_vars();
4321 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004322}
4323#endif
4324
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325/*
4326 * Parse 'arg' for option settings.
4327 *
4328 * 'arg' may be IObuff, but only when no errors can be present and option
4329 * does not need to be expanded with option_expand().
4330 * "opt_flags":
4331 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004332 * OPT_GLOBAL for ":setglobal"
4333 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004335 * OPT_WINONLY to only set window-local options
4336 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004337 *
4338 * returns FAIL if an error is detected, OK otherwise
4339 */
4340 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004341do_set(
4342 char_u *arg, /* option string (may be written to!) */
4343 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004344{
4345 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004346 char *errmsg;
4347 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004348 char_u *startarg;
4349 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4350 int nextchar; /* next non-white char after option name */
4351 int afterchar; /* character just after option name */
4352 int len;
4353 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004354 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004355 int key;
4356 long_u flags; /* flags for current option */
4357 char_u *varp = NULL; /* pointer to variable for current option */
4358 int did_show = FALSE; /* already showed one value */
4359 int adding; /* "opt+=arg" */
4360 int prepending; /* "opt^=arg" */
4361 int removing; /* "opt-=arg" */
4362 int cp_val = 0;
4363 char_u key_name[2];
4364
4365 if (*arg == NUL)
4366 {
4367 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004368 did_show = TRUE;
4369 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004370 }
4371
4372 while (*arg != NUL) /* loop to process all options */
4373 {
4374 errmsg = NULL;
4375 startarg = arg; /* remember for error message */
4376
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004377 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4378 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004379 {
4380 /*
4381 * ":set all" show all options.
4382 * ":set all&" set all options to their default value.
4383 */
4384 arg += 3;
4385 if (*arg == '&')
4386 {
4387 ++arg;
4388 /* Only for :set command set global value of local options. */
4389 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004390 didset_options();
4391 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004392 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004393 }
4394 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004395 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004396 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004397 did_show = TRUE;
4398 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004400 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004401 {
4402 showoptions(2, opt_flags);
4403 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004404 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004405 arg += 7;
4406 }
4407 else
4408 {
4409 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004410 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004411 {
4412 prefix = 0;
4413 arg += 2;
4414 }
4415 else if (STRNCMP(arg, "inv", 3) == 0)
4416 {
4417 prefix = 2;
4418 arg += 3;
4419 }
4420
4421 /* find end of name */
4422 key = 0;
4423 if (*arg == '<')
4424 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004425 opt_idx = -1;
4426 /* look out for <t_>;> */
4427 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4428 len = 5;
4429 else
4430 {
4431 len = 1;
4432 while (arg[len] != NUL && arg[len] != '>')
4433 ++len;
4434 }
4435 if (arg[len] != '>')
4436 {
4437 errmsg = e_invarg;
4438 goto skip;
4439 }
4440 arg[len] = NUL; /* put NUL after name */
4441 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4442 opt_idx = findoption(arg + 1);
4443 arg[len++] = '>'; /* restore '>' */
4444 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004445 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004446 }
4447 else
4448 {
4449 len = 0;
4450 /*
4451 * The two characters after "t_" may not be alphanumeric.
4452 */
4453 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4454 len = 4;
4455 else
4456 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4457 ++len;
4458 nextchar = arg[len];
4459 arg[len] = NUL; /* put NUL after name */
4460 opt_idx = findoption(arg);
4461 arg[len] = nextchar; /* restore nextchar */
4462 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004463 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004464 }
4465
4466 /* remember character after option name */
4467 afterchar = arg[len];
4468
4469 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004470 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004471 ++len;
4472
4473 adding = FALSE;
4474 prepending = FALSE;
4475 removing = FALSE;
4476 if (arg[len] != NUL && arg[len + 1] == '=')
4477 {
4478 if (arg[len] == '+')
4479 {
4480 adding = TRUE; /* "+=" */
4481 ++len;
4482 }
4483 else if (arg[len] == '^')
4484 {
4485 prepending = TRUE; /* "^=" */
4486 ++len;
4487 }
4488 else if (arg[len] == '-')
4489 {
4490 removing = TRUE; /* "-=" */
4491 ++len;
4492 }
4493 }
4494 nextchar = arg[len];
4495
4496 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4497 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004498 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004499 goto skip;
4500 }
4501
4502 if (opt_idx >= 0)
4503 {
4504 if (options[opt_idx].var == NULL) /* hidden option: skip */
4505 {
4506 /* Only give an error message when requesting the value of
4507 * a hidden option, ignore setting it. */
4508 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4509 && (!(options[opt_idx].flags & P_BOOL)
4510 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004511 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004512 goto skip;
4513 }
4514
4515 flags = options[opt_idx].flags;
4516 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4517 }
4518 else
4519 {
4520 flags = P_STRING;
4521 if (key < 0)
4522 {
4523 key_name[0] = KEY2TERMCAP0(key);
4524 key_name[1] = KEY2TERMCAP1(key);
4525 }
4526 else
4527 {
4528 key_name[0] = KS_KEY;
4529 key_name[1] = (key & 0xff);
4530 }
4531 }
4532
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004533 /* Skip all options that are not window-local (used when showing
4534 * an already loaded buffer in a window). */
4535 if ((opt_flags & OPT_WINONLY)
4536 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4537 goto skip;
4538
Bram Moolenaara3227e22006-03-08 21:32:40 +00004539 /* Skip all options that are window-local (used for :vimgrep). */
4540 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4541 && options[opt_idx].var == VAR_WIN)
4542 goto skip;
4543
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004544 /* Disallow changing some options from modelines. */
4545 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004546 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004547 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004548 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004549 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004550 goto skip;
4551 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004552#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004553 /* In diff mode some options are overruled. This avoids that
4554 * 'foldmethod' becomes "marker" instead of "diff" and that
4555 * "wrap" gets set. */
4556 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004557 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004558 && (
4559#ifdef FEAT_FOLDING
4560 options[opt_idx].indir == PV_FDM ||
4561#endif
4562 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004563 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004564#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004565 }
4566
4567#ifdef HAVE_SANDBOX
4568 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004569 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004571 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004572 goto skip;
4573 }
4574#endif
4575
4576 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4577 {
4578 arg += len;
4579 cp_val = p_cp;
4580 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4581 {
4582 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4583 {
4584 cp_val = FALSE;
4585 arg += 3;
4586 }
4587 else /* "opt&vi": set to Vi default */
4588 {
4589 cp_val = TRUE;
4590 arg += 2;
4591 }
4592 }
4593 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004594 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004595 {
4596 errmsg = e_trailing;
4597 goto skip;
4598 }
4599 }
4600
4601 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004602 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4603 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004604 */
4605 if (nextchar == '?'
4606 || (prefix == 1
4607 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4608 && !(flags & P_BOOL)))
4609 {
4610 /*
4611 * print value
4612 */
4613 if (did_show)
4614 msg_putchar('\n'); /* cursor below last one */
4615 else
4616 {
4617 gotocmdline(TRUE); /* cursor at status line */
4618 did_show = TRUE; /* remember that we did a line */
4619 }
4620 if (opt_idx >= 0)
4621 {
4622 showoneopt(&options[opt_idx], opt_flags);
4623#ifdef FEAT_EVAL
4624 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004625 {
4626 /* Mention where the option was last set. */
4627 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004628 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004629 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004630 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004631 (int)options[opt_idx].indir & PV_MASK]);
4632 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004633 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004634 (int)options[opt_idx].indir & PV_MASK]);
4635 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004636#endif
4637 }
4638 else
4639 {
4640 char_u *p;
4641
4642 p = find_termcode(key_name);
4643 if (p == NULL)
4644 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004645 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004646 goto skip;
4647 }
4648 else
4649 (void)show_one_termcode(key_name, p, TRUE);
4650 }
4651 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004652 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004653 errmsg = e_trailing;
4654 }
4655 else
4656 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004657 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004658 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004659
Bram Moolenaar071d4272004-06-13 20:20:40 +00004660 if (flags & P_BOOL) /* boolean */
4661 {
4662 if (nextchar == '=' || nextchar == ':')
4663 {
4664 errmsg = e_invarg;
4665 goto skip;
4666 }
4667
4668 /*
4669 * ":set opt!": invert
4670 * ":set opt&": reset to default value
4671 * ":set opt<": reset to global value
4672 */
4673 if (nextchar == '!')
4674 value = *(int *)(varp) ^ 1;
4675 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004676 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004677 ((flags & P_VI_DEF) || cp_val)
4678 ? VI_DEFAULT : VIM_DEFAULT];
4679 else if (nextchar == '<')
4680 {
4681 /* For 'autoread' -1 means to use global value. */
4682 if ((int *)varp == &curbuf->b_p_ar
4683 && opt_flags == OPT_LOCAL)
4684 value = -1;
4685 else
4686 value = *(int *)get_varp_scope(&(options[opt_idx]),
4687 OPT_GLOBAL);
4688 }
4689 else
4690 {
4691 /*
4692 * ":set invopt": invert
4693 * ":set opt" or ":set noopt": set or reset
4694 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004695 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004696 {
4697 errmsg = e_trailing;
4698 goto skip;
4699 }
4700 if (prefix == 2) /* inv */
4701 value = *(int *)(varp) ^ 1;
4702 else
4703 value = prefix;
4704 }
4705
4706 errmsg = set_bool_option(opt_idx, varp, (int)value,
4707 opt_flags);
4708 }
4709 else /* numeric or string */
4710 {
4711 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4712 || prefix != 1)
4713 {
4714 errmsg = e_invarg;
4715 goto skip;
4716 }
4717
4718 if (flags & P_NUM) /* numeric */
4719 {
4720 /*
4721 * Different ways to set a number option:
4722 * & set to default value
4723 * < set to global value
4724 * <xx> accept special key codes for 'wildchar'
4725 * c accept any non-digit for 'wildchar'
4726 * [-]0-9 set number
4727 * other error
4728 */
4729 ++arg;
4730 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004731 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004732 ((flags & P_VI_DEF) || cp_val)
4733 ? VI_DEFAULT : VIM_DEFAULT];
4734 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004735 {
4736 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4737 * use the global value. */
4738 if ((long *)varp == &curbuf->b_p_ul
4739 && opt_flags == OPT_LOCAL)
4740 value = NO_LOCAL_UNDOLEVEL;
4741 else
4742 value = *(long *)get_varp_scope(
4743 &(options[opt_idx]), OPT_GLOBAL);
4744 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004745 else if (((long *)varp == &p_wc
4746 || (long *)varp == &p_wcm)
4747 && (*arg == '<'
4748 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004749 || (*arg != NUL
4750 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004751 && !VIM_ISDIGIT(*arg))))
4752 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004753 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004754 if (value == 0 && (long *)varp != &p_wcm)
4755 {
4756 errmsg = e_invarg;
4757 goto skip;
4758 }
4759 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004760 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4761 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004762 /* Allow negative (for 'undolevels'), octal and
4763 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004764 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
4765 &value, NULL, 0);
Bram Moolenaar1c465442017-03-12 20:10:05 +01004766 if (arg[i] != NUL && !VIM_ISWHITE(arg[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004767 {
4768 errmsg = e_invarg;
4769 goto skip;
4770 }
4771 }
4772 else
4773 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004774 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004775 goto skip;
4776 }
4777
4778 if (adding)
4779 value = *(long *)varp + value;
4780 if (prepending)
4781 value = *(long *)varp * value;
4782 if (removing)
4783 value = *(long *)varp - value;
4784 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004785 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004786 }
4787 else if (opt_idx >= 0) /* string */
4788 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004789 char_u *save_arg = NULL;
4790 char_u *s = NULL;
4791 char_u *oldval = NULL; /* previous value if *varp */
4792 char_u *newval;
4793 char_u *origval = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004794#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004795 char_u *saved_origval = NULL;
4796 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004797#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004798 unsigned newlen;
4799 int comma;
4800 int bs;
4801 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004802 was allocated */
4803
4804 /* When using ":set opt=val" for a global option
4805 * with a local value the local value will be
4806 * reset, use the global value here. */
4807 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004808 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004809 varp = options[opt_idx].var;
4810
4811 /* The old value is kept until we are sure that the
4812 * new value is valid. */
4813 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004814
4815 /* When setting the local value of a global
4816 * option, the old value may be the global value. */
4817 if (((int)options[opt_idx].indir & PV_BOTH)
4818 && (opt_flags & OPT_LOCAL))
4819 origval = *(char_u **)get_varp(
4820 &options[opt_idx]);
4821 else
4822 origval = oldval;
4823
Bram Moolenaar071d4272004-06-13 20:20:40 +00004824 if (nextchar == '&') /* set to default val */
4825 {
4826 newval = options[opt_idx].def_val[
4827 ((flags & P_VI_DEF) || cp_val)
4828 ? VI_DEFAULT : VIM_DEFAULT];
4829 if ((char_u **)varp == &p_bg)
4830 {
4831 /* guess the value of 'background' */
4832#ifdef FEAT_GUI
4833 if (gui.in_use)
4834 newval = gui_bg_default();
4835 else
4836#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004837 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004838 }
4839
4840 /* expand environment variables and ~ (since the
4841 * default value was already expanded, only
4842 * required when an environment variable was set
4843 * later */
4844 if (newval == NULL)
4845 newval = empty_option;
4846 else
4847 {
4848 s = option_expand(opt_idx, newval);
4849 if (s == NULL)
4850 s = newval;
4851 newval = vim_strsave(s);
4852 }
4853 new_value_alloced = TRUE;
4854 }
4855 else if (nextchar == '<') /* set to global val */
4856 {
4857 newval = vim_strsave(*(char_u **)get_varp_scope(
4858 &(options[opt_idx]), OPT_GLOBAL));
4859 new_value_alloced = TRUE;
4860 }
4861 else
4862 {
4863 ++arg; /* jump to after the '=' or ':' */
4864
4865 /*
4866 * Set 'keywordprg' to ":help" if an empty
4867 * value was passed to :set by the user.
4868 * Misuse errbuf[] for the resulting string.
4869 */
4870 if (varp == (char_u *)&p_kp
4871 && (*arg == NUL || *arg == ' '))
4872 {
4873 STRCPY(errbuf, ":help");
4874 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004875 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004876 }
4877 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004878 * Convert 'backspace' number to string, for
4879 * adding, prepending and removing string.
4880 */
4881 else if (varp == (char_u *)&p_bs
4882 && VIM_ISDIGIT(**(char_u **)varp))
4883 {
4884 i = getdigits((char_u **)varp);
4885 switch (i)
4886 {
4887 case 0:
4888 *(char_u **)varp = empty_option;
4889 break;
4890 case 1:
4891 *(char_u **)varp = vim_strsave(
4892 (char_u *)"indent,eol");
4893 break;
4894 case 2:
4895 *(char_u **)varp = vim_strsave(
4896 (char_u *)"indent,eol,start");
4897 break;
4898 }
4899 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004900 if (origval == oldval)
4901 origval = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004902 oldval = *(char_u **)varp;
4903 }
4904 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004905 * Convert 'whichwrap' number to string, for
4906 * backwards compatibility with Vim 3.0.
4907 * Misuse errbuf[] for the resulting string.
4908 */
4909 else if (varp == (char_u *)&p_ww
4910 && VIM_ISDIGIT(*arg))
4911 {
4912 *errbuf = NUL;
4913 i = getdigits(&arg);
4914 if (i & 1)
4915 STRCAT(errbuf, "b,");
4916 if (i & 2)
4917 STRCAT(errbuf, "s,");
4918 if (i & 4)
4919 STRCAT(errbuf, "h,l,");
4920 if (i & 8)
4921 STRCAT(errbuf, "<,>,");
4922 if (i & 16)
4923 STRCAT(errbuf, "[,],");
4924 if (*errbuf != NUL) /* remove trailing , */
4925 errbuf[STRLEN(errbuf) - 1] = NUL;
4926 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004927 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004928 }
4929 /*
4930 * Remove '>' before 'dir' and 'bdir', for
4931 * backwards compatibility with version 3.0
4932 */
4933 else if ( *arg == '>'
4934 && (varp == (char_u *)&p_dir
4935 || varp == (char_u *)&p_bdir))
4936 {
4937 ++arg;
4938 }
4939
Bram Moolenaar071d4272004-06-13 20:20:40 +00004940 /*
4941 * Copy the new string into allocated memory.
4942 * Can't use set_string_option_direct(), because
4943 * we need to remove the backslashes.
4944 */
4945 /* get a bit too much */
4946 newlen = (unsigned)STRLEN(arg) + 1;
4947 if (adding || prepending || removing)
4948 newlen += (unsigned)STRLEN(origval) + 1;
4949 newval = alloc(newlen);
4950 if (newval == NULL) /* out of mem, don't change */
4951 break;
4952 s = newval;
4953
4954 /*
4955 * Copy the string, skip over escaped chars.
4956 * For MS-DOS and WIN32 backslashes before normal
4957 * file name characters are not removed, and keep
4958 * backslash at start, for "\\machine\path", but
4959 * do remove it for "\\\\machine\\path".
4960 * The reverse is found in ExpandOldSetting().
4961 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004962 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004963 {
4964 if (*arg == '\\' && arg[1] != NUL
4965#ifdef BACKSLASH_IN_FILENAME
4966 && !((flags & P_EXPAND)
4967 && vim_isfilec(arg[1])
4968 && (arg[1] != '\\'
4969 || (s == newval
4970 && arg[2] != '\\')))
4971#endif
4972 )
4973 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004974 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00004975 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004976 {
4977 /* copy multibyte char */
4978 mch_memmove(s, arg, (size_t)i);
4979 arg += i;
4980 s += i;
4981 }
4982 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004983 *s++ = *arg++;
4984 }
4985 *s = NUL;
4986
4987 /*
4988 * Expand environment variables and ~.
4989 * Don't do it when adding without inserting a
4990 * comma.
4991 */
4992 if (!(adding || prepending || removing)
4993 || (flags & P_COMMA))
4994 {
4995 s = option_expand(opt_idx, newval);
4996 if (s != NULL)
4997 {
4998 vim_free(newval);
4999 newlen = (unsigned)STRLEN(s) + 1;
5000 if (adding || prepending || removing)
5001 newlen += (unsigned)STRLEN(origval) + 1;
5002 newval = alloc(newlen);
5003 if (newval == NULL)
5004 break;
5005 STRCPY(newval, s);
5006 }
5007 }
5008
5009 /* locate newval[] in origval[] when removing it
5010 * and when adding to avoid duplicates */
5011 i = 0; /* init for GCC */
5012 if (removing || (flags & P_NODUP))
5013 {
5014 i = (int)STRLEN(newval);
5015 bs = 0;
5016 for (s = origval; *s; ++s)
5017 {
5018 if ((!(flags & P_COMMA)
5019 || s == origval
5020 || (s[-1] == ',' && !(bs & 1)))
5021 && STRNCMP(s, newval, i) == 0
5022 && (!(flags & P_COMMA)
5023 || s[i] == ','
5024 || s[i] == NUL))
5025 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005026 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005027 * even number of backslashes or a single
5028 * backslash preceded by a comma before it
5029 * is recognized as a separator */
5030 if ((s > origval + 1
5031 && s[-1] == '\\'
5032 && s[-2] != ',')
5033 || (s == origval + 1
5034 && s[-1] == '\\'))
5035
Bram Moolenaar071d4272004-06-13 20:20:40 +00005036 ++bs;
5037 else
5038 bs = 0;
5039 }
5040
5041 /* do not add if already there */
5042 if ((adding || prepending) && *s)
5043 {
5044 prepending = FALSE;
5045 adding = FALSE;
5046 STRCPY(newval, origval);
5047 }
5048 }
5049
5050 /* concatenate the two strings; add a ',' if
5051 * needed */
5052 if (adding || prepending)
5053 {
5054 comma = ((flags & P_COMMA) && *origval != NUL
5055 && *newval != NUL);
5056 if (adding)
5057 {
5058 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005059 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005060 if (comma && i > 1
5061 && (flags & P_ONECOMMA) == P_ONECOMMA
5062 && origval[i - 1] == ','
5063 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005064 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005065 mch_memmove(newval + i + comma, newval,
5066 STRLEN(newval) + 1);
5067 mch_memmove(newval, origval, (size_t)i);
5068 }
5069 else
5070 {
5071 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005072 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005073 }
5074 if (comma)
5075 newval[i] = ',';
5076 }
5077
5078 /* Remove newval[] from origval[]. (Note: "i" has
5079 * been set above and is used here). */
5080 if (removing)
5081 {
5082 STRCPY(newval, origval);
5083 if (*s)
5084 {
5085 /* may need to remove a comma */
5086 if (flags & P_COMMA)
5087 {
5088 if (s == origval)
5089 {
5090 /* include comma after string */
5091 if (s[i] == ',')
5092 ++i;
5093 }
5094 else
5095 {
5096 /* include comma before string */
5097 --s;
5098 ++i;
5099 }
5100 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005101 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005102 }
5103 }
5104
5105 if (flags & P_FLAGLIST)
5106 {
5107 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005108 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005109 {
5110 /* if options have P_FLAGLIST and
5111 * P_ONECOMMA such as 'whichwrap' */
5112 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005113 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005114 if (*s != ',' && *(s + 1) == ','
5115 && vim_strchr(s + 2, *s) != NULL)
5116 {
5117 /* Remove the duplicated value and
5118 * the next comma. */
5119 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005120 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005121 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005122 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005123 else
5124 {
5125 if ((!(flags & P_COMMA) || *s != ',')
5126 && vim_strchr(s + 1, *s) != NULL)
5127 {
5128 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005129 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005130 }
5131 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005132 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005133 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134 }
5135
5136 if (save_arg != NULL) /* number for 'whichwrap' */
5137 arg = save_arg;
5138 new_value_alloced = TRUE;
5139 }
5140
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005141 /*
5142 * Set the new value.
5143 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005144 *(char_u **)(varp) = newval;
5145
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005146#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005147 if (!starting
5148# ifdef FEAT_CRYPT
5149 && options[opt_idx].indir != PV_KEY
5150# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005151 && origval != NULL && newval != NULL)
5152 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005153 /* origval may be freed by
5154 * did_set_string_option(), make a copy. */
5155 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005156 /* newval (and varp) may become invalid if the
5157 * buffer is closed by autocommands. */
5158 saved_newval = vim_strsave(newval);
5159 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005160#endif
5161
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005162 {
5163 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005164 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005165
5166 // When an option is set in the sandbox, from a
5167 // modeline or in secure mode, then deal with side
5168 // effects in secure mode. Also when the value was
5169 // set with the P_INSECURE flag and is not
5170 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005171 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005172#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005173 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005174#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005175 || (!value_is_replaced && (*p & P_INSECURE)))
5176 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005177
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005178 // Handle side effects, and set the global value
5179 // for ":set" on local options. Note: when setting
5180 // 'syntax' or 'filetype' autocommands may be
5181 // triggered that can cause havoc.
5182 errmsg = did_set_string_option(
5183 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005184 new_value_alloced, oldval, errbuf,
5185 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005186
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005187 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005189
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005190#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005191 if (errmsg == NULL)
5192 trigger_optionsset_string(opt_idx, opt_flags,
5193 saved_origval, saved_newval);
5194 vim_free(saved_origval);
5195 vim_free(saved_newval);
5196#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005197 /* If error detected, print the error message. */
5198 if (errmsg != NULL)
5199 goto skip;
5200 }
5201 else /* key code option */
5202 {
5203 char_u *p;
5204
5205 if (nextchar == '&')
5206 {
5207 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005208 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005209 }
5210 else
5211 {
5212 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005213 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005214 if (*p == '\\' && p[1] != NUL)
5215 ++p;
5216 nextchar = *p;
5217 *p = NUL;
5218 add_termcode(key_name, arg, FALSE);
5219 *p = nextchar;
5220 }
5221 if (full_screen)
5222 ttest(FALSE);
5223 redraw_all_later(CLEAR);
5224 }
5225 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005226
Bram Moolenaar071d4272004-06-13 20:20:40 +00005227 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005228 did_set_option(
5229 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005230 }
5231
5232skip:
5233 /*
5234 * Advance to next argument.
5235 * - skip until a blank found, taking care of backslashes
5236 * - skip blanks
5237 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5238 */
5239 for (i = 0; i < 2 ; ++i)
5240 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005241 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 if (*arg++ == '\\' && *arg != NUL)
5243 ++arg;
5244 arg = skipwhite(arg);
5245 if (*arg != '=')
5246 break;
5247 }
5248 }
5249
5250 if (errmsg != NULL)
5251 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005252 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005253 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005254 if (i + (arg - startarg) < IOSIZE)
5255 {
5256 /* append the argument with the error */
5257 STRCAT(IObuff, ": ");
5258 mch_memmove(IObuff + i, startarg, (arg - startarg));
5259 IObuff[i + (arg - startarg)] = NUL;
5260 }
5261 /* make sure all characters are printable */
5262 trans_characters(IObuff, IOSIZE);
5263
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005264 ++no_wait_return; // wait_return done later
5265 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005266 --no_wait_return;
5267
5268 return FAIL;
5269 }
5270
5271 arg = skipwhite(arg);
5272 }
5273
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005274theend:
5275 if (silent_mode && did_show)
5276 {
5277 /* After displaying option values in silent mode. */
5278 silent_mode = FALSE;
5279 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5280 msg_putchar('\n');
5281 cursor_on(); /* msg_start() switches it off */
5282 out_flush();
5283 silent_mode = TRUE;
5284 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5285 }
5286
Bram Moolenaar071d4272004-06-13 20:20:40 +00005287 return OK;
5288}
5289
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005290/*
5291 * Call this when an option has been given a new value through a user command.
5292 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5293 */
5294 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005295did_set_option(
5296 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005297 int opt_flags, // possibly with OPT_MODELINE
5298 int new_value, // value was replaced completely
5299 int value_checked) // value was checked to be safe, no need to set the
5300 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005301{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005302 long_u *p;
5303
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005304 options[opt_idx].flags |= P_WAS_SET;
5305
5306 /* When an option is set in the sandbox, from a modeline or in secure mode
5307 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005308 * flag. */
5309 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005310 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005311#ifdef HAVE_SANDBOX
5312 || sandbox != 0
5313#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005314 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005315 *p = *p | P_INSECURE;
5316 else if (new_value)
5317 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005318}
5319
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005320 static char *
5321illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322{
5323 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005324 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005325 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005326 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005327 return errbuf;
5328}
5329
5330/*
5331 * Convert a key name or string into a key value.
5332 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005333 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005334 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005335 int
5336string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337{
5338 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005339 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005340 if (*arg == '^')
5341 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005342 if (multi_byte)
5343 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005344 return *arg;
5345}
5346
5347#ifdef FEAT_CMDWIN
5348/*
5349 * Check value of 'cedit' and set cedit_key.
5350 * Returns NULL if value is OK, error message otherwise.
5351 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005352 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005353check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005354{
5355 int n;
5356
5357 if (*p_cedit == NUL)
5358 cedit_key = -1;
5359 else
5360 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005361 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362 if (vim_isprintc(n))
5363 return e_invarg;
5364 cedit_key = n;
5365 }
5366 return NULL;
5367}
5368#endif
5369
5370#ifdef FEAT_TITLE
5371/*
5372 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5373 * maketitle() to create and display it.
5374 * When switching the title or icon off, call mch_restore_title() to get
5375 * the old value back.
5376 */
5377 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005378did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005379{
5380 if (starting != NO_SCREEN
5381#ifdef FEAT_GUI
5382 && !gui.starting
5383#endif
5384 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005386}
5387#endif
5388
5389/*
5390 * set_options_bin - called when 'bin' changes value.
5391 */
5392 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005393set_options_bin(
5394 int oldval,
5395 int newval,
5396 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397{
5398 /*
5399 * The option values that are changed when 'bin' changes are
5400 * copied when 'bin is set and restored when 'bin' is reset.
5401 */
5402 if (newval)
5403 {
5404 if (!oldval) /* switched on */
5405 {
5406 if (!(opt_flags & OPT_GLOBAL))
5407 {
5408 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5409 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5410 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5411 curbuf->b_p_et_nobin = curbuf->b_p_et;
5412 }
5413 if (!(opt_flags & OPT_LOCAL))
5414 {
5415 p_tw_nobin = p_tw;
5416 p_wm_nobin = p_wm;
5417 p_ml_nobin = p_ml;
5418 p_et_nobin = p_et;
5419 }
5420 }
5421
5422 if (!(opt_flags & OPT_GLOBAL))
5423 {
5424 curbuf->b_p_tw = 0; /* no automatic line wrap */
5425 curbuf->b_p_wm = 0; /* no automatic line wrap */
5426 curbuf->b_p_ml = 0; /* no modelines */
5427 curbuf->b_p_et = 0; /* no expandtab */
5428 }
5429 if (!(opt_flags & OPT_LOCAL))
5430 {
5431 p_tw = 0;
5432 p_wm = 0;
5433 p_ml = FALSE;
5434 p_et = FALSE;
5435 p_bin = TRUE; /* needed when called for the "-b" argument */
5436 }
5437 }
5438 else if (oldval) /* switched off */
5439 {
5440 if (!(opt_flags & OPT_GLOBAL))
5441 {
5442 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5443 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5444 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5445 curbuf->b_p_et = curbuf->b_p_et_nobin;
5446 }
5447 if (!(opt_flags & OPT_LOCAL))
5448 {
5449 p_tw = p_tw_nobin;
5450 p_wm = p_wm_nobin;
5451 p_ml = p_ml_nobin;
5452 p_et = p_et_nobin;
5453 }
5454 }
5455}
5456
5457#ifdef FEAT_VIMINFO
5458/*
5459 * Find the parameter represented by the given character (eg ', :, ", or /),
5460 * and return its associated value in the 'viminfo' string.
5461 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005462 * If the parameter is not specified in the string or there is no following
5463 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005464 */
5465 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005466get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005467{
5468 char_u *p;
5469
5470 p = find_viminfo_parameter(type);
5471 if (p != NULL && VIM_ISDIGIT(*p))
5472 return atoi((char *)p);
5473 return -1;
5474}
5475
5476/*
5477 * Find the parameter represented by the given character (eg ''', ':', '"', or
5478 * '/') in the 'viminfo' option and return a pointer to the string after it.
5479 * Return NULL if the parameter is not specified in the string.
5480 */
5481 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005482find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005483{
5484 char_u *p;
5485
5486 for (p = p_viminfo; *p; ++p)
5487 {
5488 if (*p == type)
5489 return p + 1;
5490 if (*p == 'n') /* 'n' is always the last one */
5491 break;
5492 p = vim_strchr(p, ','); /* skip until next ',' */
5493 if (p == NULL) /* hit the end without finding parameter */
5494 break;
5495 }
5496 return NULL;
5497}
5498#endif
5499
5500/*
5501 * Expand environment variables for some string options.
5502 * These string options cannot be indirect!
5503 * If "val" is NULL expand the current value of the option.
5504 * Return pointer to NameBuff, or NULL when not expanded.
5505 */
5506 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005507option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005508{
5509 /* if option doesn't need expansion nothing to do */
5510 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5511 return NULL;
5512
5513 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5514 * expand_env() would truncate the string. */
5515 if (val != NULL && STRLEN(val) > MAXPATHL)
5516 return NULL;
5517
5518 if (val == NULL)
5519 val = *(char_u **)options[opt_idx].var;
5520
5521 /*
5522 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5523 * Escape spaces when expanding 'tags', they are used to separate file
5524 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005525 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005526 */
5527 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005528 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005529#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005530 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5531#endif
5532 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005533 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5534 return NULL;
5535
5536 return NameBuff;
5537}
5538
5539/*
5540 * After setting various option values: recompute variables that depend on
5541 * option values.
5542 */
5543 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005544didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005545{
5546 /* initialize the table for 'iskeyword' et.al. */
5547 (void)init_chartab();
5548
5549 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5550 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005551 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005552#ifdef FEAT_SESSION
5553 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5554 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5555#endif
5556#ifdef FEAT_FOLDING
5557 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5558#endif
5559 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005560 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005561 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005562#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5563 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5564#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005565#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005566 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005567 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005568 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005569 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005570#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005571#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005572 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5573#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005574#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5576#endif
5577#ifdef FEAT_CMDWIN
5578 /* set cedit_key */
5579 (void)check_cedit();
5580#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005581#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005582 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005583#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005584#ifdef FEAT_LINEBREAK
5585 /* initialize the table for 'breakat'. */
5586 fill_breakat_flags();
5587#endif
5588
5589}
5590
5591/*
5592 * More side effects of setting options.
5593 */
5594 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005595didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005596{
5597 /* Initialize the highlight_attr[] table. */
5598 (void)highlight_changed();
5599
5600 /* Parse default for 'wildmode' */
5601 check_opt_wim();
5602
5603 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005604 /* Parse default for 'fillchars'. */
5605 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005606
5607#ifdef FEAT_CLIPBOARD
5608 /* Parse default for 'clipboard' */
5609 (void)check_clipboard_option();
5610#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005611#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005612 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005613 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005614 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005615 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617}
5618
5619/*
5620 * Check for string options that are NULL (normally only termcap options).
5621 */
5622 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005623check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005624{
5625 int opt_idx;
5626
5627 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5628 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5629 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5630}
5631
5632/*
5633 * Check string options in a buffer for NULL value.
5634 */
5635 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005636check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005637{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638 check_string_option(&buf->b_p_bh);
5639 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005641 check_string_option(&buf->b_p_ff);
5642#ifdef FEAT_FIND_ID
5643 check_string_option(&buf->b_p_def);
5644 check_string_option(&buf->b_p_inc);
5645# ifdef FEAT_EVAL
5646 check_string_option(&buf->b_p_inex);
5647# endif
5648#endif
5649#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5650 check_string_option(&buf->b_p_inde);
5651 check_string_option(&buf->b_p_indk);
5652#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005653#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5654 check_string_option(&buf->b_p_bexpr);
5655#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005656#if defined(FEAT_CRYPT)
5657 check_string_option(&buf->b_p_cm);
5658#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005659 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005660#if defined(FEAT_EVAL)
5661 check_string_option(&buf->b_p_fex);
5662#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005663#ifdef FEAT_CRYPT
5664 check_string_option(&buf->b_p_key);
5665#endif
5666 check_string_option(&buf->b_p_kp);
5667 check_string_option(&buf->b_p_mps);
5668 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005669 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005670 check_string_option(&buf->b_p_isk);
5671#ifdef FEAT_COMMENTS
5672 check_string_option(&buf->b_p_com);
5673#endif
5674#ifdef FEAT_FOLDING
5675 check_string_option(&buf->b_p_cms);
5676#endif
5677 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005678#ifdef FEAT_TEXTOBJ
5679 check_string_option(&buf->b_p_qe);
5680#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681#ifdef FEAT_SYN_HL
5682 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005683 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005684#endif
5685#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005686 check_string_option(&buf->b_s.b_p_spc);
5687 check_string_option(&buf->b_s.b_p_spf);
5688 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689#endif
5690#ifdef FEAT_SEARCHPATH
5691 check_string_option(&buf->b_p_sua);
5692#endif
5693#ifdef FEAT_CINDENT
5694 check_string_option(&buf->b_p_cink);
5695 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005696 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005698 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005699#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5700 check_string_option(&buf->b_p_cinw);
5701#endif
5702#ifdef FEAT_INS_EXPAND
5703 check_string_option(&buf->b_p_cpt);
5704#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005705#ifdef FEAT_COMPL_FUNC
5706 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005707 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005708#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005709#ifdef FEAT_EVAL
5710 check_string_option(&buf->b_p_tfu);
5711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005712#ifdef FEAT_KEYMAP
5713 check_string_option(&buf->b_p_keymap);
5714#endif
5715#ifdef FEAT_QUICKFIX
5716 check_string_option(&buf->b_p_gp);
5717 check_string_option(&buf->b_p_mp);
5718 check_string_option(&buf->b_p_efm);
5719#endif
5720 check_string_option(&buf->b_p_ep);
5721 check_string_option(&buf->b_p_path);
5722 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005723 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005724#ifdef FEAT_INS_EXPAND
5725 check_string_option(&buf->b_p_dict);
5726 check_string_option(&buf->b_p_tsr);
5727#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005728#ifdef FEAT_LISP
5729 check_string_option(&buf->b_p_lw);
5730#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005731 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005732 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005733#ifdef FEAT_VARTABS
5734 check_string_option(&buf->b_p_vsts);
5735 check_string_option(&buf->b_p_vts);
5736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737}
5738
5739/*
5740 * Free the string allocated for an option.
5741 * Checks for the string being empty_option. This may happen if we're out of
5742 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5743 * check_options().
5744 * Does NOT check for P_ALLOCED flag!
5745 */
5746 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005747free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005748{
5749 if (p != empty_option)
5750 vim_free(p);
5751}
5752
5753 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005754clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755{
5756 if (*pp != empty_option)
5757 vim_free(*pp);
5758 *pp = empty_option;
5759}
5760
5761 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005762check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005763{
5764 if (*pp == NULL)
5765 *pp = empty_option;
5766}
5767
5768/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005769 * Return the option index found by a pointer into term_strings[].
5770 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005771 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005772 int
5773get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005774{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005775 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005776
5777 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5778 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005779 return opt_idx;
5780 return -1; // cannot happen: didn't find it!
5781}
5782
5783/*
5784 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5785 * Return the option index or -1 if not found.
5786 */
5787 int
5788set_term_option_alloced(char_u **p)
5789{
5790 int opt_idx = get_term_opt_idx(p);
5791
5792 if (opt_idx >= 0)
5793 options[opt_idx].flags |= P_ALLOCED;
5794 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005795}
5796
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005797#if defined(FEAT_EVAL) || defined(PROTO)
5798/*
5799 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5800 * Return FALSE when it wasn't.
5801 * Return -1 for an unknown option.
5802 */
5803 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005804was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005805{
5806 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005807 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005808
5809 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005810 {
5811 flagp = insecure_flag(idx, opt_flags);
5812 return (*flagp & P_INSECURE) != 0;
5813 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005814 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005815 return -1;
5816}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005817
5818/*
5819 * Get a pointer to the flags used for the P_INSECURE flag of option
5820 * "opt_idx". For some local options a local flags field is used.
5821 */
5822 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005823insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005824{
5825 if (opt_flags & OPT_LOCAL)
5826 switch ((int)options[opt_idx].indir)
5827 {
5828#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005829 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005830#endif
5831#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005832# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005833 case PV_FDE: return &curwin->w_p_fde_flags;
5834 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005835# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005836# ifdef FEAT_BEVAL
5837 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5838# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005839# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005840 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005841# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005842 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005843# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005844 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005845# endif
5846#endif
5847 }
5848
5849 /* Nothing special, return global flags field. */
5850 return &options[opt_idx].flags;
5851}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005852#endif
5853
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005854#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005855/*
5856 * Redraw the window title and/or tab page text later.
5857 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005858static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005859{
5860 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005861 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005862}
5863#endif
5864
Bram Moolenaar071d4272004-06-13 20:20:40 +00005865/*
5866 * Set a string option to a new value (without checking the effect).
5867 * The string is copied into allocated memory.
5868 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005869 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5870 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5871 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005872 */
5873 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005874set_string_option_direct(
5875 char_u *name,
5876 int opt_idx,
5877 char_u *val,
5878 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5879 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005880{
5881 char_u *s;
5882 char_u **varp;
5883 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005884 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005885
Bram Moolenaar89d40322006-08-29 15:30:07 +00005886 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005887 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005888 idx = findoption(name);
5889 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005890 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005891 semsg(_(e_intern2), "set_string_option_direct()");
5892 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005894 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005895 }
5896
Bram Moolenaar89d40322006-08-29 15:30:07 +00005897 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005898 return;
5899
5900 s = vim_strsave(val);
5901 if (s != NULL)
5902 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005903 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005904 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005905 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005906 free_string_option(*varp);
5907 *varp = s;
5908
5909 /* For buffer/window local option may also set the global value. */
5910 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005911 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005912
Bram Moolenaar89d40322006-08-29 15:30:07 +00005913 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005914
5915 /* When setting both values of a global option with a local value,
5916 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005917 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005918 {
5919 free_string_option(*varp);
5920 *varp = empty_option;
5921 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005922# ifdef FEAT_EVAL
5923 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005924 {
5925 sctx_T script_ctx;
5926
5927 if (set_sid == 0)
5928 script_ctx = current_sctx;
5929 else
5930 {
5931 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005932 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005933 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005934 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005935 }
5936 set_option_sctx_idx(idx, opt_flags, script_ctx);
5937 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005938# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005939 }
5940}
5941
5942/*
5943 * Set global value for string option when it's a local option.
5944 */
5945 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005946set_string_option_global(
5947 int opt_idx, /* option index */
5948 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005949{
5950 char_u **p, *s;
5951
5952 /* the global value is always allocated */
5953 if (options[opt_idx].var == VAR_WIN)
5954 p = (char_u **)GLOBAL_WO(varp);
5955 else
5956 p = (char_u **)options[opt_idx].var;
5957 if (options[opt_idx].indir != PV_NONE
5958 && p != varp
5959 && (s = vim_strsave(*varp)) != NULL)
5960 {
5961 free_string_option(*p);
5962 *p = s;
5963 }
5964}
5965
5966/*
5967 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005968 *
5969 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005970 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005971 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005972set_string_option(
5973 int opt_idx,
5974 char_u *value,
5975 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005976{
5977 char_u *s;
5978 char_u **varp;
5979 char_u *oldval;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005980#if defined(FEAT_EVAL)
Bram Moolenaar53744302015-07-17 17:38:22 +02005981 char_u *saved_oldval = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005982 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02005983#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005984 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01005985 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005986
5987 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02005988 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005989
5990 s = vim_strsave(value);
5991 if (s != NULL)
5992 {
5993 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
5994 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00005995 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005996 ? OPT_GLOBAL : OPT_LOCAL)
5997 : opt_flags);
5998 oldval = *varp;
5999 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006000
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006001#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006002 if (!starting
6003# ifdef FEAT_CRYPT
6004 && options[opt_idx].indir != PV_KEY
6005# endif
6006 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006007 {
Bram Moolenaar53744302015-07-17 17:38:22 +02006008 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006009 saved_newval = vim_strsave(s);
6010 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006011#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006012 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006013 opt_flags, &value_checked)) == NULL)
6014 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006015
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006016#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006017 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006018 if (r == NULL)
6019 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006020 saved_oldval, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006021 vim_free(saved_oldval);
6022 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006023#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006024 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006025 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006026}
6027
6028/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006029 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6030 * characters or characters in "allowed".
6031 */
6032 static int
6033valid_name(char_u *val, char *allowed)
6034{
6035 char_u *s;
6036
6037 for (s = val; *s != NUL; ++s)
6038 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6039 return FALSE;
6040 return TRUE;
6041}
6042
6043/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006044 * Return TRUE if "val" is a valid 'filetype' name.
6045 * Also used for 'syntax' and 'keymap'.
6046 */
6047 static int
6048valid_filetype(char_u *val)
6049{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006050 return valid_name(val, ".-_");
6051}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006052
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006053#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006054/*
6055 * Return TRUE if "val" is a valid 'spellang' value.
6056 */
6057 int
6058valid_spellang(char_u *val)
6059{
6060 return valid_name(val, ".-_,");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006061}
6062
6063/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006064 * Return TRUE if "val" is a valid 'spellfile' value.
6065 */
6066 static int
6067valid_spellfile(char_u *val)
6068{
6069 char_u *s;
6070
6071 for (s = val; *s != NUL; ++s)
6072 if (!vim_isfilec(*s) && *s != ',')
6073 return FALSE;
6074 return TRUE;
6075}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006076#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006077
6078/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079 * Handle string options that need some action to perform when changed.
6080 * Returns NULL for success, or an error message for an error.
6081 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006082 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006083did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006084 int opt_idx, // index in options[] table
6085 char_u **varp, // pointer to the option variable
6086 int new_value_alloced, // new value was allocated
6087 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006088 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006089 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6090 int *value_checked) // value was checked to be save, no
6091 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006092{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006093 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006094 char_u *s, *p;
6095 int did_chartab = FALSE;
6096 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006097 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006098#ifdef FEAT_GUI
6099 /* set when changing an option that only requires a redraw in the GUI */
6100 int redraw_gui_only = FALSE;
6101#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006102 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006103#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6104 int did_swaptcap = FALSE;
6105#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006106
6107 /* Get the global option to compare with, otherwise we would have to check
6108 * two values for all local options. */
6109 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6110
6111 /* Disallow changing some options from secure mode */
6112 if ((secure
6113#ifdef HAVE_SANDBOX
6114 || sandbox != 0
6115#endif
6116 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006117 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006118
Bram Moolenaar916a8182018-11-25 02:18:29 +01006119 // Check for a "normal" directory or file name in some options. Disallow a
6120 // path separator (slash and/or backslash), wildcards and characters that
6121 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006122 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006123 && vim_strpbrk(*varp, (char_u *)(secure
6124 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006125 || ((options[opt_idx].flags & P_NDNAME)
6126 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006127 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006128
Bram Moolenaar071d4272004-06-13 20:20:40 +00006129 /* 'term' */
6130 else if (varp == &T_NAME)
6131 {
6132 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006133 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006134#ifdef FEAT_GUI
6135 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006136 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006138 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006139#endif
6140 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006141 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006142 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006143 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144 /* Screen colors may have changed. */
6145 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006146
6147 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6148 * P_ALLOCED flag on 'term'. */
6149 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006150 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006151 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006152 }
6153
6154 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006155 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006156 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006157 char_u *bkc = p_bkc;
6158 unsigned int *flags = &bkc_flags;
6159
6160 if (opt_flags & OPT_LOCAL)
6161 {
6162 bkc = curbuf->b_p_bkc;
6163 flags = &curbuf->b_bkc_flags;
6164 }
6165
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006166 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6167 /* make the local value empty: use the global value */
6168 *flags = 0;
6169 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006170 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006171 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6172 errmsg = e_invarg;
6173 if ((((int)*flags & BKC_AUTO) != 0)
6174 + (((int)*flags & BKC_YES) != 0)
6175 + (((int)*flags & BKC_NO) != 0) != 1)
6176 {
6177 /* Must have exactly one of "auto", "yes" and "no". */
6178 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6179 errmsg = e_invarg;
6180 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006181 }
6182 }
6183
6184 /* 'backupext' and 'patchmode' */
6185 else if (varp == &p_bex || varp == &p_pm)
6186 {
6187 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6188 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006189 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006190 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006191#ifdef FEAT_LINEBREAK
6192 /* 'breakindentopt' */
6193 else if (varp == &curwin->w_p_briopt)
6194 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006195 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006196 errmsg = e_invarg;
6197 }
6198#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006199
6200 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006201 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006202 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006203 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006204 */
6205 else if ( varp == &p_isi
6206 || varp == &(curbuf->b_p_isk)
6207 || varp == &p_isp
6208 || varp == &p_isf)
6209 {
6210 if (init_chartab() == FAIL)
6211 {
6212 did_chartab = TRUE; /* need to restore it below */
6213 errmsg = e_invarg; /* error in value */
6214 }
6215 }
6216
6217 /* 'helpfile' */
6218 else if (varp == &p_hf)
6219 {
6220 /* May compute new values for $VIM and $VIMRUNTIME */
6221 if (didset_vim)
6222 {
6223 vim_setenv((char_u *)"VIM", (char_u *)"");
6224 didset_vim = FALSE;
6225 }
6226 if (didset_vimruntime)
6227 {
6228 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6229 didset_vimruntime = FALSE;
6230 }
6231 }
6232
Bram Moolenaar1a384422010-07-14 19:53:30 +02006233#ifdef FEAT_SYN_HL
6234 /* 'colorcolumn' */
6235 else if (varp == &curwin->w_p_cc)
6236 errmsg = check_colorcolumn(curwin);
6237#endif
6238
Bram Moolenaar071d4272004-06-13 20:20:40 +00006239#ifdef FEAT_MULTI_LANG
6240 /* 'helplang' */
6241 else if (varp == &p_hlg)
6242 {
6243 /* Check for "", "ab", "ab,cd", etc. */
6244 for (s = p_hlg; *s != NUL; s += 3)
6245 {
6246 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6247 {
6248 errmsg = e_invarg;
6249 break;
6250 }
6251 if (s[2] == NUL)
6252 break;
6253 }
6254 }
6255#endif
6256
6257 /* 'highlight' */
6258 else if (varp == &p_hl)
6259 {
6260 if (highlight_changed() == FAIL)
6261 errmsg = e_invarg; /* invalid flags */
6262 }
6263
6264 /* 'nrformats' */
6265 else if (gvarp == &p_nf)
6266 {
6267 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6268 errmsg = e_invarg;
6269 }
6270
6271#ifdef FEAT_SESSION
6272 /* 'sessionoptions' */
6273 else if (varp == &p_ssop)
6274 {
6275 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6276 errmsg = e_invarg;
6277 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6278 {
6279 /* Don't allow both "sesdir" and "curdir". */
6280 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6281 errmsg = e_invarg;
6282 }
6283 }
6284 /* 'viewoptions' */
6285 else if (varp == &p_vop)
6286 {
6287 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6288 errmsg = e_invarg;
6289 }
6290#endif
6291
6292 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293 else if (varp == &p_sbo)
6294 {
6295 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6296 errmsg = e_invarg;
6297 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006298
6299 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006300 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006301 {
6302 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6303 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006304 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006305 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006306 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006307 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006308 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006309
6310 /* 'background' */
6311 else if (varp == &p_bg)
6312 {
6313 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6314 {
6315#ifdef FEAT_EVAL
6316 int dark = (*p_bg == 'd');
6317#endif
6318
6319 init_highlight(FALSE, FALSE);
6320
6321#ifdef FEAT_EVAL
6322 if (dark != (*p_bg == 'd')
6323 && get_var_value((char_u *)"g:colors_name") != NULL)
6324 {
6325 /* The color scheme must have set 'background' back to another
6326 * value, that's not what we want here. Disable the color
6327 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006328 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006329 free_string_option(p_bg);
6330 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6331 check_string_option(&p_bg);
6332 init_highlight(FALSE, FALSE);
6333 }
6334#endif
6335 }
6336 else
6337 errmsg = e_invarg;
6338 }
6339
6340 /* 'wildmode' */
6341 else if (varp == &p_wim)
6342 {
6343 if (check_opt_wim() == FAIL)
6344 errmsg = e_invarg;
6345 }
6346
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006347#ifdef FEAT_CMDL_COMPL
6348 /* 'wildoptions' */
6349 else if (varp == &p_wop)
6350 {
6351 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6352 errmsg = e_invarg;
6353 }
6354#endif
6355
Bram Moolenaar071d4272004-06-13 20:20:40 +00006356#ifdef FEAT_WAK
6357 /* 'winaltkeys' */
6358 else if (varp == &p_wak)
6359 {
6360 if (*p_wak == NUL
6361 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6362 errmsg = e_invarg;
6363# ifdef FEAT_MENU
6364# ifdef FEAT_GUI_MOTIF
6365 else if (gui.in_use)
6366 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6367# else
6368# ifdef FEAT_GUI_GTK
6369 else if (gui.in_use)
6370 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6371# endif
6372# endif
6373# endif
6374 }
6375#endif
6376
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 /* 'eventignore' */
6378 else if (varp == &p_ei)
6379 {
6380 if (check_ei() == FAIL)
6381 errmsg = e_invarg;
6382 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006383
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006384 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6385 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6386 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006387 {
6388 if (gvarp == &p_fenc)
6389 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006390 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006391 errmsg = e_modifiable;
6392 else if (vim_strchr(*varp, ',') != NULL)
6393 /* No comma allowed in 'fileencoding'; catches confusing it
6394 * with 'fileencodings'. */
6395 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006397 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006398#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006399 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006400 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006401#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006402 /* Add 'fileencoding' to the swap file. */
6403 ml_setflags(curbuf);
6404 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006405 }
6406 if (errmsg == NULL)
6407 {
6408 /* canonize the value, so that STRCMP() can be used on it */
6409 p = enc_canonize(*varp);
6410 if (p != NULL)
6411 {
6412 vim_free(*varp);
6413 *varp = p;
6414 }
6415 if (varp == &p_enc)
6416 {
6417 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006418#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006419 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006420#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006421 }
6422 }
6423
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006424#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006425 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6426 {
6427 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6428 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006429 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006431#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006432
6433 if (errmsg == NULL)
6434 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006435#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006436 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6437 * (with another encoding). */
6438 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6439 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006441
6442 /* When 'termencoding' is not empty and 'encoding' changes or when
6443 * 'termencoding' changes, need to setup for keyboard input and
6444 * display output conversion. */
6445 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6446 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006447 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6448 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6449 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006450 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006451 p_tenc, p_enc);
6452 errmsg = e_invarg;
6453 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006454 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006455
Bram Moolenaar4f974752019-02-17 17:44:42 +01006456#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006457 /* $HOME may have characters in active code page. */
6458 if (varp == &p_enc)
6459 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006460#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006461 }
6462 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006463
6464#if defined(FEAT_POSTSCRIPT)
6465 else if (varp == &p_penc)
6466 {
6467 /* Canonize printencoding if VIM standard one */
6468 p = enc_canonize(p_penc);
6469 if (p != NULL)
6470 {
6471 vim_free(p_penc);
6472 p_penc = p;
6473 }
6474 else
6475 {
6476 /* Ensure lower case and '-' for '_' */
6477 for (s = p_penc; *s != NUL; s++)
6478 {
6479 if (*s == '_')
6480 *s = '-';
6481 else
6482 *s = TOLOWER_ASC(*s);
6483 }
6484 }
6485 }
6486#endif
6487
Bram Moolenaar9372a112005-12-06 19:59:18 +00006488#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006489 else if (varp == &p_imak)
6490 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006491 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492 errmsg = e_invarg;
6493 }
6494#endif
6495
6496#ifdef FEAT_KEYMAP
6497 else if (varp == &curbuf->b_p_keymap)
6498 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006499 if (!valid_filetype(*varp))
6500 errmsg = e_invarg;
6501 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006502 {
6503 int secure_save = secure;
6504
6505 // Reset the secure flag, since the value of 'keymap' has
6506 // been checked to be safe.
6507 secure = 0;
6508
6509 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006510 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006511
Bram Moolenaar916a8182018-11-25 02:18:29 +01006512 secure = secure_save;
6513
6514 // Since we check the value, there is no need to set P_INSECURE,
6515 // even when the value comes from a modeline.
6516 *value_checked = TRUE;
6517 }
6518
Bram Moolenaarfab06232009-03-04 03:13:35 +00006519 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006520 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006521 if (*curbuf->b_p_keymap != NUL)
6522 {
6523 /* Installed a new keymap, switch on using it. */
6524 curbuf->b_p_iminsert = B_IMODE_LMAP;
6525 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6526 curbuf->b_p_imsearch = B_IMODE_LMAP;
6527 }
6528 else
6529 {
6530 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6531 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6532 curbuf->b_p_iminsert = B_IMODE_NONE;
6533 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6534 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6535 }
6536 if ((opt_flags & OPT_LOCAL) == 0)
6537 {
6538 set_iminsert_global();
6539 set_imsearch_global();
6540 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006541 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006542 }
6543 }
6544#endif
6545
6546 /* 'fileformat' */
6547 else if (gvarp == &p_ff)
6548 {
6549 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6550 errmsg = e_modifiable;
6551 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6552 errmsg = e_invarg;
6553 else
6554 {
6555 /* may also change 'textmode' */
6556 if (get_fileformat(curbuf) == EOL_DOS)
6557 curbuf->b_p_tx = TRUE;
6558 else
6559 curbuf->b_p_tx = FALSE;
6560#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006561 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006562#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006563 /* update flag in swap file */
6564 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006565 /* Redraw needed when switching to/from "mac": a CR in the text
6566 * will be displayed differently. */
6567 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6568 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006569 }
6570 }
6571
6572 /* 'fileformats' */
6573 else if (varp == &p_ffs)
6574 {
6575 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6576 errmsg = e_invarg;
6577 else
6578 {
6579 /* also change 'textauto' */
6580 if (*p_ffs == NUL)
6581 p_ta = FALSE;
6582 else
6583 p_ta = TRUE;
6584 }
6585 }
6586
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006587#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006588 /* 'cryptkey' */
6589 else if (gvarp == &p_key)
6590 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006591# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006592 /* Make sure the ":set" command doesn't show the new value in the
6593 * history. */
6594 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006595# endif
6596 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6597 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006598 ml_set_crypt_key(curbuf, oldval,
6599 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006600 }
6601
6602 else if (gvarp == &p_cm)
6603 {
6604 if (opt_flags & OPT_LOCAL)
6605 p = curbuf->b_p_cm;
6606 else
6607 p = p_cm;
6608 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6609 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006610 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006611 errmsg = e_invarg;
6612 else
6613 {
6614 /* When setting the global value to empty, make it "zip". */
6615 if (*p_cm == NUL)
6616 {
6617 if (new_value_alloced)
6618 free_string_option(p_cm);
6619 p_cm = vim_strsave((char_u *)"zip");
6620 new_value_alloced = TRUE;
6621 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006622 /* When using ":set cm=name" the local value is going to be empty.
6623 * Do that here, otherwise the crypt functions will still use the
6624 * local value. */
6625 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6626 {
6627 free_string_option(curbuf->b_p_cm);
6628 curbuf->b_p_cm = empty_option;
6629 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006630
6631 /* Need to update the swapfile when the effective method changed.
6632 * Set "s" to the effective old value, "p" to the effective new
6633 * method and compare. */
6634 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6635 s = p_cm; /* was previously using the global value */
6636 else
6637 s = oldval;
6638 if (*curbuf->b_p_cm == NUL)
6639 p = p_cm; /* is now using the global value */
6640 else
6641 p = curbuf->b_p_cm;
6642 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006643 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006644
6645 /* If the global value changes need to update the swapfile for all
6646 * buffers using that value. */
6647 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6648 {
6649 buf_T *buf;
6650
Bram Moolenaar29323592016-07-24 22:04:11 +02006651 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006652 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006653 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006654 }
6655 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006656 }
6657#endif
6658
6659 /* 'matchpairs' */
6660 else if (gvarp == &p_mps)
6661 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006662 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006663 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006664 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006665 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006666 int x2 = -1;
6667 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006668
6669 if (*p != NUL)
6670 p += mb_ptr2len(p);
6671 if (*p != NUL)
6672 x2 = *p++;
6673 if (*p != NUL)
6674 {
6675 x3 = mb_ptr2char(p);
6676 p += mb_ptr2len(p);
6677 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006678 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006679 {
6680 errmsg = e_invarg;
6681 break;
6682 }
6683 if (*p == NUL)
6684 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006685 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006686 }
6687 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006688 {
6689 /* Check for "x:y,x:y" */
6690 for (p = *varp; *p != NUL; p += 4)
6691 {
6692 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6693 {
6694 errmsg = e_invarg;
6695 break;
6696 }
6697 if (p[3] == NUL)
6698 break;
6699 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006700 }
6701 }
6702
6703#ifdef FEAT_COMMENTS
6704 /* 'comments' */
6705 else if (gvarp == &p_com)
6706 {
6707 for (s = *varp; *s; )
6708 {
6709 while (*s && *s != ':')
6710 {
6711 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6712 && !VIM_ISDIGIT(*s) && *s != '-')
6713 {
6714 errmsg = illegal_char(errbuf, *s);
6715 break;
6716 }
6717 ++s;
6718 }
6719 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006720 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006721 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006722 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006723 if (errmsg != NULL)
6724 break;
6725 while (*s && *s != ',')
6726 {
6727 if (*s == '\\' && s[1] != NUL)
6728 ++s;
6729 ++s;
6730 }
6731 s = skip_to_option_part(s);
6732 }
6733 }
6734#endif
6735
6736 /* 'listchars' */
6737 else if (varp == &p_lcs)
6738 {
6739 errmsg = set_chars_option(varp);
6740 }
6741
Bram Moolenaar071d4272004-06-13 20:20:40 +00006742 /* 'fillchars' */
6743 else if (varp == &p_fcs)
6744 {
6745 errmsg = set_chars_option(varp);
6746 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006747
6748#ifdef FEAT_CMDWIN
6749 /* 'cedit' */
6750 else if (varp == &p_cedit)
6751 {
6752 errmsg = check_cedit();
6753 }
6754#endif
6755
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006756 /* 'verbosefile' */
6757 else if (varp == &p_vfile)
6758 {
6759 verbose_stop();
6760 if (*p_vfile != NUL && verbose_open() == FAIL)
6761 errmsg = e_invarg;
6762 }
6763
Bram Moolenaar071d4272004-06-13 20:20:40 +00006764#ifdef FEAT_VIMINFO
6765 /* 'viminfo' */
6766 else if (varp == &p_viminfo)
6767 {
6768 for (s = p_viminfo; *s;)
6769 {
6770 /* Check it's a valid character */
6771 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6772 {
6773 errmsg = illegal_char(errbuf, *s);
6774 break;
6775 }
6776 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006778 else if (*s == 'r') /* skip until next ',' */
6779 {
6780 while (*++s && *s != ',')
6781 ;
6782 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006783 else if (*s == '%')
6784 {
6785 /* optional number */
6786 while (vim_isdigit(*++s))
6787 ;
6788 }
6789 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006790 ++s; /* no extra chars */
6791 else /* must have a number */
6792 {
6793 while (vim_isdigit(*++s))
6794 ;
6795
6796 if (!VIM_ISDIGIT(*(s - 1)))
6797 {
6798 if (errbuf != NULL)
6799 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006800 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006801 transchar_byte(*(s - 1)));
6802 errmsg = errbuf;
6803 }
6804 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006805 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006806 break;
6807 }
6808 }
6809 if (*s == ',')
6810 ++s;
6811 else if (*s)
6812 {
6813 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006814 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006816 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006817 break;
6818 }
6819 }
6820 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006821 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006822 }
6823#endif /* FEAT_VIMINFO */
6824
6825 /* terminal options */
6826 else if (istermoption(&options[opt_idx]) && full_screen)
6827 {
6828 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6829 if (varp == &T_CCO)
6830 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006831 int colors = atoi((char *)T_CCO);
6832
6833 /* Only reinitialize colors if t_Co value has really changed to
6834 * avoid expensive reload of colorscheme if t_Co is set to the
6835 * same value multiple times. */
6836 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006837 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006838 t_colors = colors;
6839 if (t_colors <= 1)
6840 {
6841 if (new_value_alloced)
6842 vim_free(T_CCO);
6843 T_CCO = empty_option;
6844 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006845#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6846 if (is_term_win32())
6847 {
6848 swap_tcap();
6849 did_swaptcap = TRUE;
6850 }
6851#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006852 /* We now have a different color setup, initialize it again. */
6853 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006854 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006855 }
6856 ttest(FALSE);
6857 if (varp == &T_ME)
6858 {
6859 out_str(T_ME);
6860 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006861#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006862 /* Since t_me has been set, this probably means that the user
6863 * wants to use this as default colors. Need to reset default
6864 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006865# ifdef VIMDLL
6866 if (!gui.in_use && !gui.starting)
6867# endif
6868 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006869#endif
6870 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006871 if (varp == &T_BE && termcap_active)
6872 {
6873 if (*T_BE == NUL)
6874 /* When clearing t_BE we assume the user no longer wants
6875 * bracketed paste, thus disable it by writing t_BD. */
6876 out_str(T_BD);
6877 else
6878 out_str(T_BE);
6879 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006880 }
6881
6882#ifdef FEAT_LINEBREAK
6883 /* 'showbreak' */
6884 else if (varp == &p_sbr)
6885 {
6886 for (s = p_sbr; *s; )
6887 {
6888 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006889 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006890 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006891 }
6892 }
6893#endif
6894
6895#ifdef FEAT_GUI
6896 /* 'guifont' */
6897 else if (varp == &p_guifont)
6898 {
6899 if (gui.in_use)
6900 {
6901 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006902# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903 /*
6904 * Put up a font dialog and let the user select a new value.
6905 * If this is cancelled go back to the old value but don't
6906 * give an error message.
6907 */
6908 if (STRCMP(p, "*") == 0)
6909 {
6910 p = gui_mch_font_dialog(oldval);
6911
6912 if (new_value_alloced)
6913 free_string_option(p_guifont);
6914
6915 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
6916 new_value_alloced = TRUE;
6917 }
6918# endif
6919 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
6920 {
6921# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
6922 if (STRCMP(p_guifont, "*") == 0)
6923 {
6924 /* Dialog was cancelled: Keep the old value without giving
6925 * an error message. */
6926 if (new_value_alloced)
6927 free_string_option(p_guifont);
6928 p_guifont = vim_strsave(oldval);
6929 new_value_alloced = TRUE;
6930 }
6931 else
6932# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006933 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006934 }
6935 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006936 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006937 }
6938# ifdef FEAT_XFONTSET
6939 else if (varp == &p_guifontset)
6940 {
6941 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006942 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01006944 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006945 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 }
6947# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006948 else if (varp == &p_guifontwide)
6949 {
6950 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006951 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006952 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006953 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006954 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006955 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006956#endif
6957
6958#ifdef CURSOR_SHAPE
6959 /* 'guicursor' */
6960 else if (varp == &p_guicursor)
6961 errmsg = parse_shape_opt(SHAPE_CURSOR);
6962#endif
6963
6964#ifdef FEAT_MOUSESHAPE
6965 /* 'mouseshape' */
6966 else if (varp == &p_mouseshape)
6967 {
6968 errmsg = parse_shape_opt(SHAPE_MOUSE);
6969 update_mouseshape(-1);
6970 }
6971#endif
6972
6973#ifdef FEAT_PRINTER
6974 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006975 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006976# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00006977 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00006978 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00006979# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980#endif
6981
6982#ifdef FEAT_LANGMAP
6983 /* 'langmap' */
6984 else if (varp == &p_langmap)
6985 langmap_set();
6986#endif
6987
6988#ifdef FEAT_LINEBREAK
6989 /* 'breakat' */
6990 else if (varp == &p_breakat)
6991 fill_breakat_flags();
6992#endif
6993
6994#ifdef FEAT_TITLE
6995 /* 'titlestring' and 'iconstring' */
6996 else if (varp == &p_titlestring || varp == &p_iconstring)
6997 {
6998# ifdef FEAT_STL_OPT
6999 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7000
7001 /* NULL => statusline syntax */
7002 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7003 stl_syntax |= flagval;
7004 else
7005 stl_syntax &= ~flagval;
7006# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007007 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007008 }
7009#endif
7010
7011#ifdef FEAT_GUI
7012 /* 'guioptions' */
7013 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007014 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007016 redraw_gui_only = TRUE;
7017 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007018#endif
7019
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007020#if defined(FEAT_GUI_TABLINE)
7021 /* 'guitablabel' */
7022 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007023 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007024 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007025 redraw_gui_only = TRUE;
7026 }
7027 /* 'guitabtooltip' */
7028 else if (varp == &p_gtt)
7029 {
7030 redraw_gui_only = TRUE;
7031 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007032#endif
7033
Bram Moolenaar071d4272004-06-13 20:20:40 +00007034#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7035 /* 'ttymouse' */
7036 else if (varp == &p_ttym)
7037 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007038 /* Switch the mouse off before changing the escape sequences used for
7039 * that. */
7040 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7042 errmsg = e_invarg;
7043 else
7044 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007045 if (termcap_active)
7046 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007047 }
7048#endif
7049
Bram Moolenaar071d4272004-06-13 20:20:40 +00007050 /* 'selection' */
7051 else if (varp == &p_sel)
7052 {
7053 if (*p_sel == NUL
7054 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7055 errmsg = e_invarg;
7056 }
7057
7058 /* 'selectmode' */
7059 else if (varp == &p_slm)
7060 {
7061 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7062 errmsg = e_invarg;
7063 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007064
7065#ifdef FEAT_BROWSE
7066 /* 'browsedir' */
7067 else if (varp == &p_bsdir)
7068 {
7069 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7070 && !mch_isdir(p_bsdir))
7071 errmsg = e_invarg;
7072 }
7073#endif
7074
Bram Moolenaar071d4272004-06-13 20:20:40 +00007075 /* 'keymodel' */
7076 else if (varp == &p_km)
7077 {
7078 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7079 errmsg = e_invarg;
7080 else
7081 {
7082 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7083 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7084 }
7085 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007086
7087 /* 'mousemodel' */
7088 else if (varp == &p_mousem)
7089 {
7090 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7091 errmsg = e_invarg;
7092#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7093 else if (*p_mousem != *oldval)
7094 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7095 * to create or delete the popup menus. */
7096 gui_motif_update_mousemodel(root_menu);
7097#endif
7098 }
7099
7100 /* 'switchbuf' */
7101 else if (varp == &p_swb)
7102 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007103 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007104 errmsg = e_invarg;
7105 }
7106
7107 /* 'debug' */
7108 else if (varp == &p_debug)
7109 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007110 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007111 errmsg = e_invarg;
7112 }
7113
7114 /* 'display' */
7115 else if (varp == &p_dy)
7116 {
7117 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7118 errmsg = e_invarg;
7119 else
7120 (void)init_chartab();
7121
7122 }
7123
Bram Moolenaar071d4272004-06-13 20:20:40 +00007124 /* 'eadirection' */
7125 else if (varp == &p_ead)
7126 {
7127 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7128 errmsg = e_invarg;
7129 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130
7131#ifdef FEAT_CLIPBOARD
7132 /* 'clipboard' */
7133 else if (varp == &p_cb)
7134 errmsg = check_clipboard_option();
7135#endif
7136
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007137#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007138 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7139 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007140 else if (varp == &(curwin->w_s->b_p_spl)
7141 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007142 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007143 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7144
7145 if ((is_spellfile && !valid_spellfile(*varp))
7146 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007147 errmsg = e_invarg;
7148 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007149 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007150 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007151 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007152 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007153 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007154 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007155 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007156 /* 'spellsuggest' */
7157 else if (varp == &p_sps)
7158 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007159 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007160 errmsg = e_invarg;
7161 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007162 /* 'mkspellmem' */
7163 else if (varp == &p_msm)
7164 {
7165 if (spell_check_msm() != OK)
7166 errmsg = e_invarg;
7167 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007168#endif
7169
Bram Moolenaar071d4272004-06-13 20:20:40 +00007170 /* When 'bufhidden' is set, check for valid value. */
7171 else if (gvarp == &p_bh)
7172 {
7173 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7174 errmsg = e_invarg;
7175 }
7176
7177 /* When 'buftype' is set, check for valid value. */
7178 else if (gvarp == &p_bt)
7179 {
7180 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7181 errmsg = e_invarg;
7182 else
7183 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007184 if (curwin->w_status_height)
7185 {
7186 curwin->w_redr_status = TRUE;
7187 redraw_later(VALID);
7188 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007189 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007190#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007191 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007192#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007193 }
7194 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007195
7196#ifdef FEAT_STL_OPT
7197 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007198 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007199 {
7200 int wid;
7201
7202 if (varp == &p_ruf) /* reset ru_wid first */
7203 ru_wid = 0;
7204 s = *varp;
7205 if (varp == &p_ruf && *s == '%')
7206 {
7207 /* set ru_wid if 'ruf' starts with "%99(" */
7208 if (*++s == '-') /* ignore a '-' */
7209 s++;
7210 wid = getdigits(&s);
7211 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7212 ru_wid = wid;
7213 else
7214 errmsg = check_stl_option(p_ruf);
7215 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007216 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007217 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007218 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007219 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007220 comp_col();
7221 }
7222#endif
7223
7224#ifdef FEAT_INS_EXPAND
7225 /* check if it is a valid value for 'complete' -- Acevedo */
7226 else if (gvarp == &p_cpt)
7227 {
7228 for (s = *varp; *s;)
7229 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007230 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007231 s++;
7232 if (!*s)
7233 break;
7234 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7235 {
7236 errmsg = illegal_char(errbuf, *s);
7237 break;
7238 }
7239 if (*++s != NUL && *s != ',' && *s != ' ')
7240 {
7241 if (s[-1] == 'k' || s[-1] == 's')
7242 {
7243 /* skip optional filename after 'k' and 's' */
7244 while (*s && *s != ',' && *s != ' ')
7245 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007246 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007247 ++s;
7248 ++s;
7249 }
7250 }
7251 else
7252 {
7253 if (errbuf != NULL)
7254 {
7255 sprintf((char *)errbuf,
7256 _("E535: Illegal character after <%c>"),
7257 *--s);
7258 errmsg = errbuf;
7259 }
7260 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007261 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007262 break;
7263 }
7264 }
7265 }
7266 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007267
7268 /* 'completeopt' */
7269 else if (varp == &p_cot)
7270 {
7271 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7272 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007273 else
7274 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007275 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007276#endif /* FEAT_INS_EXPAND */
7277
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007278#ifdef FEAT_SIGNS
7279 /* 'signcolumn' */
7280 else if (varp == &curwin->w_p_scl)
7281 {
7282 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7283 errmsg = e_invarg;
7284 }
7285#endif
7286
Bram Moolenaar071d4272004-06-13 20:20:40 +00007287
Bram Moolenaar4f974752019-02-17 17:44:42 +01007288#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007289 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007290 else if (varp == &p_toolbar)
7291 {
7292 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7293 &toolbar_flags, TRUE) != OK)
7294 errmsg = e_invarg;
7295 else
7296 {
7297 out_flush();
7298 gui_mch_show_toolbar((toolbar_flags &
7299 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7300 }
7301 }
7302#endif
7303
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007304#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007305 /* 'toolbariconsize': GTK+ 2 only */
7306 else if (varp == &p_tbis)
7307 {
7308 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7309 errmsg = e_invarg;
7310 else
7311 {
7312 out_flush();
7313 gui_mch_show_toolbar((toolbar_flags &
7314 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7315 }
7316 }
7317#endif
7318
7319 /* 'pastetoggle': translate key codes like in a mapping */
7320 else if (varp == &p_pt)
7321 {
7322 if (*p_pt)
7323 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007324 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007325 if (p != NULL)
7326 {
7327 if (new_value_alloced)
7328 free_string_option(p_pt);
7329 p_pt = p;
7330 new_value_alloced = TRUE;
7331 }
7332 }
7333 }
7334
7335 /* 'backspace' */
7336 else if (varp == &p_bs)
7337 {
7338 if (VIM_ISDIGIT(*p_bs))
7339 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007340 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007341 errmsg = e_invarg;
7342 }
7343 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7344 errmsg = e_invarg;
7345 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007346 else if (varp == &p_bo)
7347 {
7348 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7349 errmsg = e_invarg;
7350 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007351
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007352 /* 'tagcase' */
7353 else if (gvarp == &p_tc)
7354 {
7355 unsigned int *flags;
7356
7357 if (opt_flags & OPT_LOCAL)
7358 {
7359 p = curbuf->b_p_tc;
7360 flags = &curbuf->b_tc_flags;
7361 }
7362 else
7363 {
7364 p = p_tc;
7365 flags = &tc_flags;
7366 }
7367
7368 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7369 /* make the local value empty: use the global value */
7370 *flags = 0;
7371 else if (*p == NUL
7372 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7373 errmsg = e_invarg;
7374 }
7375
Bram Moolenaar071d4272004-06-13 20:20:40 +00007376 /* 'casemap' */
7377 else if (varp == &p_cmp)
7378 {
7379 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7380 errmsg = e_invarg;
7381 }
7382
7383#ifdef FEAT_DIFF
7384 /* 'diffopt' */
7385 else if (varp == &p_dip)
7386 {
7387 if (diffopt_changed() == FAIL)
7388 errmsg = e_invarg;
7389 }
7390#endif
7391
7392#ifdef FEAT_FOLDING
7393 /* 'foldmethod' */
7394 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7395 {
7396 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7397 || *curwin->w_p_fdm == NUL)
7398 errmsg = e_invarg;
7399 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007400 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007401 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007402 if (foldmethodIsDiff(curwin))
7403 newFoldLevel();
7404 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007405 }
7406# ifdef FEAT_EVAL
7407 /* 'foldexpr' */
7408 else if (varp == &curwin->w_p_fde)
7409 {
7410 if (foldmethodIsExpr(curwin))
7411 foldUpdateAll(curwin);
7412 }
7413# endif
7414 /* 'foldmarker' */
7415 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7416 {
7417 p = vim_strchr(*varp, ',');
7418 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007419 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007420 else if (p == *varp || p[1] == NUL)
7421 errmsg = e_invarg;
7422 else if (foldmethodIsMarker(curwin))
7423 foldUpdateAll(curwin);
7424 }
7425 /* 'commentstring' */
7426 else if (gvarp == &p_cms)
7427 {
7428 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007429 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007430 }
7431 /* 'foldopen' */
7432 else if (varp == &p_fdo)
7433 {
7434 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7435 errmsg = e_invarg;
7436 }
7437 /* 'foldclose' */
7438 else if (varp == &p_fcl)
7439 {
7440 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7441 errmsg = e_invarg;
7442 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007443 /* 'foldignore' */
7444 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7445 {
7446 if (foldmethodIsIndent(curwin))
7447 foldUpdateAll(curwin);
7448 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449#endif
7450
Bram Moolenaar071d4272004-06-13 20:20:40 +00007451 /* 'virtualedit' */
7452 else if (varp == &p_ve)
7453 {
7454 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7455 errmsg = e_invarg;
7456 else if (STRCMP(p_ve, oldval) != 0)
7457 {
7458 /* Recompute cursor position in case the new 've' setting
7459 * changes something. */
7460 validate_virtcol();
7461 coladvance(curwin->w_virtcol);
7462 }
7463 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007464
7465#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7466 else if (varp == &p_csqf)
7467 {
7468 if (p_csqf != NULL)
7469 {
7470 p = p_csqf;
7471 while (*p != NUL)
7472 {
7473 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7474 || p[1] == NUL
7475 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7476 || (p[2] != NUL && p[2] != ','))
7477 {
7478 errmsg = e_invarg;
7479 break;
7480 }
7481 else if (p[2] == NUL)
7482 break;
7483 else
7484 p += 3;
7485 }
7486 }
7487 }
7488#endif
7489
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007490#ifdef FEAT_CINDENT
7491 /* 'cinoptions' */
7492 else if (gvarp == &p_cino)
7493 {
7494 /* TODO: recognize errors */
7495 parse_cino(curbuf);
7496 }
7497#endif
7498
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007499#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007500 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007501 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007502 {
7503 if (!gui_mch_set_rendering_options(p_rop))
7504 errmsg = e_invarg;
7505 }
7506#endif
7507
Bram Moolenaard0b51382016-11-04 15:23:45 +01007508 else if (gvarp == &p_ft)
7509 {
7510 if (!valid_filetype(*varp))
7511 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007512 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007513 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007514 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007515
7516 // Since we check the value, there is no need to set P_INSECURE,
7517 // even when the value comes from a modeline.
7518 *value_checked = TRUE;
7519 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007520 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007521
7522#ifdef FEAT_SYN_HL
7523 else if (gvarp == &p_syn)
7524 {
7525 if (!valid_filetype(*varp))
7526 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007527 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007528 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007529 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007530
7531 // Since we check the value, there is no need to set P_INSECURE,
7532 // even when the value comes from a modeline.
7533 *value_checked = TRUE;
7534 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007535 }
7536#endif
7537
Bram Moolenaar825680f2017-07-22 17:04:02 +02007538#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007539 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007540 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007541 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007542 if (*curwin->w_p_twk != NUL
7543 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007544 errmsg = e_invarg;
7545 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007546 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007547 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007548 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007549 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007550 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007551 p = skipdigits(curwin->w_p_tws);
7552 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007553 || (*p != 'x' && *p != '*')
7554 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007555 errmsg = e_invarg;
7556 }
7557 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007558# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007559 // 'termwintype'
7560 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007561 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007562 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007563 errmsg = e_invarg;
7564 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007565# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007566#endif
7567
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007568#ifdef FEAT_VARTABS
7569 /* 'varsofttabstop' */
7570 else if (varp == &(curbuf->b_p_vsts))
7571 {
7572 char_u *cp;
7573
7574 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7575 {
7576 if (curbuf->b_p_vsts_array)
7577 {
7578 vim_free(curbuf->b_p_vsts_array);
7579 curbuf->b_p_vsts_array = 0;
7580 }
7581 }
7582 else
7583 {
7584 for (cp = *varp; *cp; ++cp)
7585 {
7586 if (vim_isdigit(*cp))
7587 continue;
7588 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7589 continue;
7590 errmsg = e_invarg;
7591 break;
7592 }
7593 if (errmsg == NULL)
7594 {
7595 int *oldarray = curbuf->b_p_vsts_array;
7596 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7597 {
7598 if (oldarray)
7599 vim_free(oldarray);
7600 }
7601 else
7602 errmsg = e_invarg;
7603 }
7604 }
7605 }
7606
7607 /* 'vartabstop' */
7608 else if (varp == &(curbuf->b_p_vts))
7609 {
7610 char_u *cp;
7611
7612 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7613 {
7614 if (curbuf->b_p_vts_array)
7615 {
7616 vim_free(curbuf->b_p_vts_array);
7617 curbuf->b_p_vts_array = NULL;
7618 }
7619 }
7620 else
7621 {
7622 for (cp = *varp; *cp; ++cp)
7623 {
7624 if (vim_isdigit(*cp))
7625 continue;
7626 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7627 continue;
7628 errmsg = e_invarg;
7629 break;
7630 }
7631 if (errmsg == NULL)
7632 {
7633 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007634
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007635 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7636 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007637 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007638#ifdef FEAT_FOLDING
7639 if (foldmethodIsIndent(curwin))
7640 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007641#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007642 }
7643 else
7644 errmsg = e_invarg;
7645 }
7646 }
7647 }
7648#endif
7649
Bram Moolenaar071d4272004-06-13 20:20:40 +00007650 /* Options that are a list of flags. */
7651 else
7652 {
7653 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007654 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007655 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007656 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007657 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007658 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007659 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007660 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007661 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007662#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007663 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007664 p = (char_u *)COCU_ALL;
7665#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007666 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007667 {
7668#ifdef FEAT_MOUSE
7669 p = (char_u *)MOUSE_ALL;
7670#else
7671 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007672 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007673#endif
7674 }
7675#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007676 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007677 p = (char_u *)GO_ALL;
7678#endif
7679 if (p != NULL)
7680 {
7681 for (s = *varp; *s; ++s)
7682 if (vim_strchr(p, *s) == NULL)
7683 {
7684 errmsg = illegal_char(errbuf, *s);
7685 break;
7686 }
7687 }
7688 }
7689
7690 /*
7691 * If error detected, restore the previous value.
7692 */
7693 if (errmsg != NULL)
7694 {
7695 if (new_value_alloced)
7696 free_string_option(*varp);
7697 *varp = oldval;
7698 /*
7699 * When resetting some values, need to act on it.
7700 */
7701 if (did_chartab)
7702 (void)init_chartab();
7703 if (varp == &p_hl)
7704 (void)highlight_changed();
7705 }
7706 else
7707 {
7708#ifdef FEAT_EVAL
7709 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007710 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007711#endif
7712 /*
7713 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007714 * Use "free_oldval", because recursiveness may change the flags under
7715 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007716 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007717 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007718 free_string_option(oldval);
7719 if (new_value_alloced)
7720 options[opt_idx].flags |= P_ALLOCED;
7721 else
7722 options[opt_idx].flags &= ~P_ALLOCED;
7723
7724 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007725 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007726 {
7727 /* global option with local value set to use global value; free
7728 * the local value and make it empty */
7729 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7730 free_string_option(*(char_u **)p);
7731 *(char_u **)p = empty_option;
7732 }
7733
7734 /* May set global value for local option. */
7735 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7736 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007737
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007738 /*
7739 * Trigger the autocommand only after setting the flags.
7740 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007741#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007742 /* When 'syntax' is set, load the syntax of that name */
7743 if (varp == &(curbuf->b_p_syn))
7744 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007745 static int syn_recursive = 0;
7746
7747 ++syn_recursive;
7748 // Only pass TRUE for "force" when the value changed or not used
7749 // recursively, to avoid endless recurrence.
7750 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7751 value_changed || syn_recursive == 1, curbuf);
7752 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007753 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007754#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007755 else if (varp == &(curbuf->b_p_ft))
7756 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007757 /* 'filetype' is set, trigger the FileType autocommand.
7758 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007759 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007760 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007761 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007762 static int ft_recursive = 0;
7763 int secure_save = secure;
7764
7765 // Reset the secure flag, since the value of 'filetype' has
7766 // been checked to be safe.
7767 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007768
7769 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007770 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007771 // Only pass TRUE for "force" when the value changed or not
7772 // used recursively, to avoid endless recurrence.
7773 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7774 value_changed || ft_recursive == 1, curbuf);
7775 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007776 /* Just in case the old "curbuf" is now invalid. */
7777 if (varp != &(curbuf->b_p_ft))
7778 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007779
7780 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007781 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007782 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007783#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007784 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007785 {
7786 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007787 char_u *q = curwin->w_s->b_p_spl;
7788
7789 /* Skip the first name if it is "cjk". */
7790 if (STRNCMP(q, "cjk,", 4) == 0)
7791 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007792
7793 /*
7794 * Source the spell/LANG.vim in 'runtimepath'.
7795 * They could set 'spellcapcheck' depending on the language.
7796 * Use the first name in 'spelllang' up to '_region' or
7797 * '.encoding'.
7798 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007799 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007800 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007801 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007802 if (p > q)
7803 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007804 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7805 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007806 source_runtime(fname, DIP_ALL);
7807 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007808 }
7809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810 }
7811
7812#ifdef FEAT_MOUSE
7813 if (varp == &p_mouse)
7814 {
7815# ifdef FEAT_MOUSE_TTY
7816 if (*p_mouse == NUL)
7817 mch_setmouse(FALSE); /* switch mouse off */
7818 else
7819# endif
7820 setmouse(); /* in case 'mouse' changed */
7821 }
7822#endif
7823
Bram Moolenaar913077c2012-03-28 19:59:04 +02007824 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007825 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007826 curwin->w_set_curswant = TRUE;
7827
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007828#ifdef FEAT_GUI
7829 /* check redraw when it's not a GUI option or the GUI is active. */
7830 if (!redraw_gui_only || gui.in_use)
7831#endif
7832 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007833
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007834#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7835 if (did_swaptcap)
7836 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007837 set_termname((char_u *)"win32");
7838 init_highlight(TRUE, FALSE);
7839 }
7840#endif
7841
Bram Moolenaar071d4272004-06-13 20:20:40 +00007842 return errmsg;
7843}
7844
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01007845#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007846/*
7847 * Simple int comparison function for use with qsort()
7848 */
7849 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01007850int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007851{
7852 return *(const int *)a - *(const int *)b;
7853}
7854
7855/*
7856 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
7857 * Returns error message, NULL if it's OK.
7858 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007859 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007860check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007861{
7862 char_u *s;
7863 int col;
7864 int count = 0;
7865 int color_cols[256];
7866 int i;
7867 int j = 0;
7868
Bram Moolenaar50f834d2011-09-21 13:40:17 +02007869 if (wp->w_buffer == NULL)
7870 return NULL; /* buffer was closed */
7871
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007872 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02007873 {
7874 if (*s == '-' || *s == '+')
7875 {
7876 /* -N and +N: add to 'textwidth' */
7877 col = (*s == '-') ? -1 : 1;
7878 ++s;
7879 if (!VIM_ISDIGIT(*s))
7880 return e_invarg;
7881 col = col * getdigits(&s);
7882 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007883 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007884 col += wp->w_buffer->b_p_tw;
7885 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007886 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02007887 }
7888 else if (VIM_ISDIGIT(*s))
7889 col = getdigits(&s);
7890 else
7891 return e_invarg;
7892 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007893skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02007894 if (*s == NUL)
7895 break;
7896 if (*s != ',')
7897 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02007898 if (*++s == NUL)
7899 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02007900 }
7901
7902 vim_free(wp->w_p_cc_cols);
7903 if (count == 0)
7904 wp->w_p_cc_cols = NULL;
7905 else
7906 {
7907 wp->w_p_cc_cols = (int *)alloc((unsigned)sizeof(int) * (count + 1));
7908 if (wp->w_p_cc_cols != NULL)
7909 {
7910 /* sort the columns for faster usage on screen redraw inside
7911 * win_line() */
7912 qsort(color_cols, count, sizeof(int), int_cmp);
7913
7914 for (i = 0; i < count; ++i)
7915 /* skip duplicates */
7916 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
7917 wp->w_p_cc_cols[j++] = color_cols[i];
7918 wp->w_p_cc_cols[j] = -1; /* end marker */
7919 }
7920 }
7921
7922 return NULL; /* no error */
7923}
7924#endif
7925
Bram Moolenaar071d4272004-06-13 20:20:40 +00007926/*
7927 * Handle setting 'listchars' or 'fillchars'.
7928 * Returns error message, NULL if it's OK.
7929 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007930 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007931set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007932{
7933 int round, i, len, entries;
7934 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007935 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007936 struct charstab
7937 {
7938 int *cp;
7939 char *name;
7940 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007941 static struct charstab filltab[] =
7942 {
7943 {&fill_stl, "stl"},
7944 {&fill_stlnc, "stlnc"},
7945 {&fill_vert, "vert"},
7946 {&fill_fold, "fold"},
7947 {&fill_diff, "diff"},
7948 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00007949 static struct charstab lcstab[] =
7950 {
7951 {&lcs_eol, "eol"},
7952 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00007953 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02007955 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00007956 {&lcs_tab2, "tab"},
7957 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02007958#ifdef FEAT_CONCEAL
7959 {&lcs_conceal, "conceal"},
7960#else
7961 {NULL, "conceal"},
7962#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007963 };
7964 struct charstab *tab;
7965
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007967 {
7968 tab = lcstab;
7969 entries = sizeof(lcstab) / sizeof(struct charstab);
7970 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007971 else
7972 {
7973 tab = filltab;
7974 entries = sizeof(filltab) / sizeof(struct charstab);
7975 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976
7977 /* first round: check for valid value, second round: assign values */
7978 for (round = 0; round <= 1; ++round)
7979 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007980 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007981 {
7982 /* After checking that the value is valid: set defaults: space for
7983 * 'fillchars', NUL for 'listchars' */
7984 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02007985 if (tab[i].cp != NULL)
7986 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01007987
Bram Moolenaar071d4272004-06-13 20:20:40 +00007988 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01007989 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007990 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01007991 lcs_tab3 = NUL;
7992 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007993 else
7994 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00007995 }
7996 p = *varp;
7997 while (*p)
7998 {
7999 for (i = 0; i < entries; ++i)
8000 {
8001 len = (int)STRLEN(tab[i].name);
8002 if (STRNCMP(p, tab[i].name, len) == 0
8003 && p[len] == ':'
8004 && p[len + 1] != NUL)
8005 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008006 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008007 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008008 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008009 if (mb_char2cells(c1) > 1)
8010 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008011 if (tab[i].cp == &lcs_tab2)
8012 {
8013 if (*s == NUL)
8014 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008015 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008016 if (mb_char2cells(c2) > 1)
8017 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008018 if (!(*s == ',' || *s == NUL))
8019 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008020 c3 = mb_ptr2char_adv(&s);
8021 if (mb_char2cells(c3) > 1)
8022 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008023 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008024 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008025
Bram Moolenaar071d4272004-06-13 20:20:40 +00008026 if (*s == ',' || *s == NUL)
8027 {
8028 if (round)
8029 {
8030 if (tab[i].cp == &lcs_tab2)
8031 {
8032 lcs_tab1 = c1;
8033 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008034 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008036 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 *(tab[i].cp) = c1;
8038
8039 }
8040 p = s;
8041 break;
8042 }
8043 }
8044 }
8045
8046 if (i == entries)
8047 return e_invarg;
8048 if (*p == ',')
8049 ++p;
8050 }
8051 }
8052
8053 return NULL; /* no error */
8054}
8055
8056#ifdef FEAT_STL_OPT
8057/*
8058 * Check validity of options with the 'statusline' format.
8059 * Return error message or NULL.
8060 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008061 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008062check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008063{
8064 int itemcnt = 0;
8065 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008066 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008067
8068 while (*s && itemcnt < STL_MAX_ITEM)
8069 {
8070 /* Check for valid keys after % sequences */
8071 while (*s && *s != '%')
8072 s++;
8073 if (!*s)
8074 break;
8075 s++;
8076 if (*s != '%' && *s != ')')
8077 ++itemcnt;
8078 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8079 {
8080 s++;
8081 continue;
8082 }
8083 if (*s == ')')
8084 {
8085 s++;
8086 if (--groupdepth < 0)
8087 break;
8088 continue;
8089 }
8090 if (*s == '-')
8091 s++;
8092 while (VIM_ISDIGIT(*s))
8093 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008094 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095 continue;
8096 if (*s == '.')
8097 {
8098 s++;
8099 while (*s && VIM_ISDIGIT(*s))
8100 s++;
8101 }
8102 if (*s == '(')
8103 {
8104 groupdepth++;
8105 continue;
8106 }
8107 if (vim_strchr(STL_ALL, *s) == NULL)
8108 {
8109 return illegal_char(errbuf, *s);
8110 }
8111 if (*s == '{')
8112 {
8113 s++;
8114 while (*s != '}' && *s)
8115 s++;
8116 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008117 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118 }
8119 }
8120 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008121 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008122 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008123 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 return NULL;
8125}
8126#endif
8127
8128#ifdef FEAT_CLIPBOARD
8129/*
8130 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008131 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008133 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008134check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008136 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008137 int new_autoselect_star = FALSE;
8138 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008140 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008141 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008142 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 char_u *p;
8144
8145 for (p = p_cb; *p != NUL; )
8146 {
8147 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8148 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008149 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008150 p += 7;
8151 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008152 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008153 && (p[11] == ',' || p[11] == NUL))
8154 {
8155 new_unnamed |= CLIP_UNNAMED_PLUS;
8156 p += 11;
8157 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008159 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008160 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008161 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008162 p += 10;
8163 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008164 else if (STRNCMP(p, "autoselectplus", 14) == 0
8165 && (p[14] == ',' || p[14] == NUL))
8166 {
8167 new_autoselect_plus = TRUE;
8168 p += 14;
8169 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008170 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008171 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008172 {
8173 new_autoselectml = TRUE;
8174 p += 12;
8175 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008176 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8177 {
8178 new_html = TRUE;
8179 p += 4;
8180 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008181 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8182 {
8183 p += 8;
8184 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8185 if (new_exclude_prog == NULL)
8186 errmsg = e_invarg;
8187 break;
8188 }
8189 else
8190 {
8191 errmsg = e_invarg;
8192 break;
8193 }
8194 if (*p == ',')
8195 ++p;
8196 }
8197 if (errmsg == NULL)
8198 {
8199 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008200 clip_autoselect_star = new_autoselect_star;
8201 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008202 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008203 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008204 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008205 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008206#ifdef FEAT_GUI_GTK
8207 if (gui.in_use)
8208 {
8209 gui_gtk_set_selection_targets();
8210 gui_gtk_set_dnd_targets();
8211 }
8212#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008213 }
8214 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008215 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008216
8217 return errmsg;
8218}
8219#endif
8220
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008221#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008222/*
8223 * Handle side effects of setting 'spell'.
8224 * Return an error message or NULL for success.
8225 */
8226 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008227did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008228{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008229 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008230 win_T *wp;
8231 int l;
8232
8233 if (is_spellfile)
8234 {
8235 l = (int)STRLEN(curwin->w_s->b_p_spf);
8236 if (l > 0 && (l < 4
8237 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8238 errmsg = e_invarg;
8239 }
8240
8241 if (errmsg == NULL)
8242 {
8243 FOR_ALL_WINDOWS(wp)
8244 if (wp->w_buffer == curbuf && wp->w_p_spell)
8245 {
8246 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008247 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008248 }
8249 }
8250 return errmsg;
8251}
8252
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008253/*
8254 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8255 * Return error message when failed, NULL when OK.
8256 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008257 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008258compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008259{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008260 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008261 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008262
Bram Moolenaar860cae12010-06-05 23:22:07 +02008263 if (*synblock->b_p_spc == NUL)
8264 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008265 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008266 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008267 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008268 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008269 if (re != NULL)
8270 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008271 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008272 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008273 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008274 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008275 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008276 return e_invarg;
8277 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008278 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008279 }
8280
Bram Moolenaar473de612013-06-08 18:19:48 +02008281 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008282 return NULL;
8283}
8284#endif
8285
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008286#if defined(FEAT_EVAL) || defined(PROTO)
8287/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008288 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008289 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008290 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008291 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008292set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008293{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008294 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8295 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008296 sctx_T new_script_ctx = script_ctx;
8297
8298 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008299
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008300 /* Remember where the option was set. For local options need to do that
8301 * in the buffer or window structure. */
8302 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008303 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008304 if (both || (opt_flags & OPT_LOCAL))
8305 {
8306 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008307 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008308 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008309 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008310 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008311}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008312
8313/*
8314 * Set the script_ctx for a termcap option.
8315 * "name" must be the two character code, e.g. "RV".
8316 * When "name" is NULL use "opt_idx".
8317 */
8318 void
8319set_term_option_sctx_idx(char *name, int opt_idx)
8320{
8321 char_u buf[5];
8322 int idx;
8323
8324 if (name == NULL)
8325 idx = opt_idx;
8326 else
8327 {
8328 buf[0] = 't';
8329 buf[1] = '_';
8330 buf[2] = name[0];
8331 buf[3] = name[1];
8332 buf[4] = 0;
8333 idx = findoption(buf);
8334 }
8335 if (idx >= 0)
8336 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8337}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008338#endif
8339
Bram Moolenaar071d4272004-06-13 20:20:40 +00008340/*
8341 * Set the value of a boolean option, and take care of side effects.
8342 * Returns NULL for success, or an error message for an error.
8343 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008344 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008345set_bool_option(
8346 int opt_idx, /* index in options[] table */
8347 char_u *varp, /* pointer to the option variable */
8348 int value, /* new value */
8349 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008350{
8351 int old_value = *(int *)varp;
8352
Bram Moolenaar071d4272004-06-13 20:20:40 +00008353 /* Disallow changing some options from secure mode */
8354 if ((secure
8355#ifdef HAVE_SANDBOX
8356 || sandbox != 0
8357#endif
8358 ) && (options[opt_idx].flags & P_SECURE))
8359 return e_secure;
8360
8361 *(int *)varp = value; /* set the new value */
8362#ifdef FEAT_EVAL
8363 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008364 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008365#endif
8366
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008367#ifdef FEAT_GUI
8368 need_mouse_correct = TRUE;
8369#endif
8370
Bram Moolenaar071d4272004-06-13 20:20:40 +00008371 /* May set global value for local option. */
8372 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8373 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8374
8375 /*
8376 * Handle side effects of changing a bool option.
8377 */
8378
8379 /* 'compatible' */
8380 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008381 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008382
Bram Moolenaar920694c2016-08-21 17:45:02 +02008383#ifdef FEAT_LANGMAP
8384 if ((int *)varp == &p_lrm)
8385 /* 'langremap' -> !'langnoremap' */
8386 p_lnr = !p_lrm;
8387 else if ((int *)varp == &p_lnr)
8388 /* 'langnoremap' -> !'langremap' */
8389 p_lrm = !p_lnr;
8390#endif
8391
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008392#ifdef FEAT_SYN_HL
8393 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8394 reset_cursorline();
8395#endif
8396
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008397#ifdef FEAT_PERSISTENT_UNDO
8398 /* 'undofile' */
8399 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8400 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008401 /* Only take action when the option was set. When reset we do not
8402 * delete the undo file, the option may be set again without making
8403 * any changes in between. */
8404 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008405 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008406 char_u hash[UNDO_HASH_SIZE];
8407 buf_T *save_curbuf = curbuf;
8408
Bram Moolenaar29323592016-07-24 22:04:11 +02008409 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008410 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008411 /* When 'undofile' is set globally: for every buffer, otherwise
8412 * only for the current buffer: Try to read in the undofile,
8413 * if one exists, the buffer wasn't changed and the buffer was
8414 * loaded */
8415 if ((curbuf == save_curbuf
8416 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8417 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8418 {
8419 u_compute_hash(hash);
8420 u_read_undo(NULL, hash, curbuf->b_fname);
8421 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008422 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008423 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008424 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008425 }
8426#endif
8427
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428 else if ((int *)varp == &curbuf->b_p_ro)
8429 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008430 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8432 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008433
8434 /* when 'readonly' is set may give W10 again */
8435 if (curbuf->b_p_ro)
8436 curbuf->b_did_warn = FALSE;
8437
Bram Moolenaar071d4272004-06-13 20:20:40 +00008438#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008439 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440#endif
8441 }
8442
Bram Moolenaar9c449722010-07-20 18:44:27 +02008443#ifdef FEAT_GUI
8444 else if ((int *)varp == &p_mh)
8445 {
8446 if (!p_mh)
8447 gui_mch_mousehide(FALSE);
8448 }
8449#endif
8450
Bram Moolenaara539df02010-08-01 14:35:05 +02008451 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008452 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008453 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008454# ifdef FEAT_TERMINAL
8455 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008456 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8457 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008458 {
8459 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008460 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008461 }
8462# endif
8463# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008464 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008465# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008466 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008467#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008468 /* when 'endofline' is changed, redraw the window title */
8469 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008470 {
8471 redraw_titles();
8472 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008473 /* when 'fixeol' is changed, redraw the window title */
8474 else if ((int *)varp == &curbuf->b_p_fixeol)
8475 {
8476 redraw_titles();
8477 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008478 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008479 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008480 {
8481 redraw_titles();
8482 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008483#endif
8484
8485 /* when 'bin' is set also set some other options */
8486 else if ((int *)varp == &curbuf->b_p_bin)
8487 {
8488 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8489#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008490 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008491#endif
8492 }
8493
Bram Moolenaar071d4272004-06-13 20:20:40 +00008494 /* when 'buflisted' changes, trigger autocommands */
8495 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8496 {
8497 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8498 NULL, NULL, TRUE, curbuf);
8499 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500
8501 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8502 else if ((int *)varp == &curbuf->b_p_swf)
8503 {
8504 if (curbuf->b_p_swf && p_uc)
8505 ml_open_file(curbuf); /* create the swap file */
8506 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008507 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8508 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008509 mf_close_file(curbuf, TRUE); /* remove the swap file */
8510 }
8511
8512 /* when 'terse' is set change 'shortmess' */
8513 else if ((int *)varp == &p_terse)
8514 {
8515 char_u *p;
8516
8517 p = vim_strchr(p_shm, SHM_SEARCH);
8518
8519 /* insert 's' in p_shm */
8520 if (p_terse && p == NULL)
8521 {
8522 STRCPY(IObuff, p_shm);
8523 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008524 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008525 }
8526 /* remove 's' from p_shm */
8527 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008528 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529 }
8530
8531 /* when 'paste' is set or reset also change other options */
8532 else if ((int *)varp == &p_paste)
8533 {
8534 paste_option_changed();
8535 }
8536
8537 /* when 'insertmode' is set from an autocommand need to do work here */
8538 else if ((int *)varp == &p_im)
8539 {
8540 if (p_im)
8541 {
8542 if ((State & INSERT) == 0)
8543 need_start_insertmode = TRUE;
8544 stop_insert_mode = FALSE;
8545 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008546 /* only reset if it was set previously */
8547 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008548 {
8549 need_start_insertmode = FALSE;
8550 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008551 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008552 clear_cmdline = TRUE; /* remove "(insert)" */
8553 restart_edit = 0;
8554 }
8555 }
8556
8557 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8558 else if ((int *)varp == &p_ic && p_hls)
8559 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008560 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008561 }
8562
8563#ifdef FEAT_SEARCH_EXTRA
8564 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8565 else if ((int *)varp == &p_hls)
8566 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008567 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008568 }
8569#endif
8570
Bram Moolenaar071d4272004-06-13 20:20:40 +00008571 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8572 * at the end of normal_cmd() */
8573 else if ((int *)varp == &curwin->w_p_scb)
8574 {
8575 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008576 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008577 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008578 curwin->w_scbind_pos = curwin->w_topline;
8579 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008581
Bram Moolenaar4033c552017-09-16 20:54:51 +02008582#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008583 /* There can be only one window with 'previewwindow' set. */
8584 else if ((int *)varp == &curwin->w_p_pvw)
8585 {
8586 if (curwin->w_p_pvw)
8587 {
8588 win_T *win;
8589
Bram Moolenaar29323592016-07-24 22:04:11 +02008590 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 if (win->w_p_pvw && win != curwin)
8592 {
8593 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008594 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008595 }
8596 }
8597 }
8598#endif
8599
8600 /* when 'textmode' is set or reset also change 'fileformat' */
8601 else if ((int *)varp == &curbuf->b_p_tx)
8602 {
8603 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8604 }
8605
8606 /* when 'textauto' is set or reset also change 'fileformats' */
8607 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008608 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008609 set_string_option_direct((char_u *)"ffs", -1,
8610 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008611 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008612 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008613
8614 /*
8615 * When 'lisp' option changes include/exclude '-' in
8616 * keyword characters.
8617 */
8618#ifdef FEAT_LISP
8619 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8620 {
8621 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8622 }
8623#endif
8624
8625#ifdef FEAT_TITLE
8626 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008627 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008628 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008629 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008630 }
8631#endif
8632
8633 else if ((int *)varp == &curbuf->b_changed)
8634 {
8635 if (!value)
8636 save_file_ff(curbuf); /* Buffer is unchanged */
8637#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008638 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008639#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008640 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008641 }
8642
8643#ifdef BACKSLASH_IN_FILENAME
8644 else if ((int *)varp == &p_ssl)
8645 {
8646 if (p_ssl)
8647 {
8648 psepc = '/';
8649 psepcN = '\\';
8650 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008651 }
8652 else
8653 {
8654 psepc = '\\';
8655 psepcN = '/';
8656 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008657 }
8658
8659 /* need to adjust the file name arguments and buffer names. */
8660 buflist_slash_adjust();
8661 alist_slash_adjust();
8662# ifdef FEAT_EVAL
8663 scriptnames_slash_adjust();
8664# endif
8665 }
8666#endif
8667
8668 /* If 'wrap' is set, set w_leftcol to zero. */
8669 else if ((int *)varp == &curwin->w_p_wrap)
8670 {
8671 if (curwin->w_p_wrap)
8672 curwin->w_leftcol = 0;
8673 }
8674
Bram Moolenaar071d4272004-06-13 20:20:40 +00008675 else if ((int *)varp == &p_ea)
8676 {
8677 if (p_ea && !old_value)
8678 win_equal(curwin, FALSE, 0);
8679 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008680
8681 else if ((int *)varp == &p_wiv)
8682 {
8683 /*
8684 * When 'weirdinvert' changed, set/reset 't_xs'.
8685 * Then set 'weirdinvert' according to value of 't_xs'.
8686 */
8687 if (p_wiv && !old_value)
8688 T_XS = (char_u *)"y";
8689 else if (!p_wiv && old_value)
8690 T_XS = empty_option;
8691 p_wiv = (*T_XS != NUL);
8692 }
8693
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008694#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695 else if ((int *)varp == &p_beval)
8696 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008697 if (!balloonEvalForTerm)
8698 {
8699 if (p_beval && !old_value)
8700 gui_mch_enable_beval_area(balloonEval);
8701 else if (!p_beval && old_value)
8702 gui_mch_disable_beval_area(balloonEval);
8703 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008704 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008705#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008706#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008707 else if ((int *)varp == &p_bevalterm)
8708 {
8709 mch_bevalterm_changed();
8710 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008711#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008712
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008713#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714 else if ((int *)varp == &p_acd)
8715 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008716 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008717 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718 }
8719#endif
8720
8721#ifdef FEAT_DIFF
8722 /* 'diff' */
8723 else if ((int *)varp == &curwin->w_p_diff)
8724 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008725 /* May add or remove the buffer from the list of diff buffers. */
8726 diff_buf_adjust(curwin);
8727# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008728 if (foldmethodIsDiff(curwin))
8729 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008730# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008731 }
8732#endif
8733
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008734#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008735 /* 'imdisable' */
8736 else if ((int *)varp == &p_imdisable)
8737 {
8738 /* Only de-activate it here, it will be enabled when changing mode. */
8739 if (p_imdisable)
8740 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008741 else if (State & INSERT)
8742 /* When the option is set from an autocommand, it may need to take
8743 * effect right away. */
8744 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745 }
8746#endif
8747
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008748#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008749 /* 'spell' */
8750 else if ((int *)varp == &curwin->w_p_spell)
8751 {
8752 if (curwin->w_p_spell)
8753 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008754 char *errmsg = did_set_spelllang(curwin);
8755
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008756 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008757 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008758 }
8759 }
8760#endif
8761
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762#ifdef FEAT_ARABIC
8763 if ((int *)varp == &curwin->w_p_arab)
8764 {
8765 if (curwin->w_p_arab)
8766 {
8767 /*
8768 * 'arabic' is set, handle various sub-settings.
8769 */
8770 if (!p_tbidi)
8771 {
8772 /* set rightleft mode */
8773 if (!curwin->w_p_rl)
8774 {
8775 curwin->w_p_rl = TRUE;
8776 changed_window_setting();
8777 }
8778
8779 /* Enable Arabic shaping (major part of what Arabic requires) */
8780 if (!p_arshape)
8781 {
8782 p_arshape = TRUE;
8783 redraw_later_clear();
8784 }
8785 }
8786
8787 /* Arabic requires a utf-8 encoding, inform the user if its not
8788 * set. */
8789 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008790 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008791 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8792
Bram Moolenaar8820b482017-03-16 17:23:31 +01008793 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008794 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008795#ifdef FEAT_EVAL
8796 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8797#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008798 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008799
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800 /* set 'delcombine' */
8801 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802
8803# ifdef FEAT_KEYMAP
8804 /* Force-set the necessary keymap for arabic */
8805 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8806 OPT_LOCAL);
8807# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008808 }
8809 else
8810 {
8811 /*
8812 * 'arabic' is reset, handle various sub-settings.
8813 */
8814 if (!p_tbidi)
8815 {
8816 /* reset rightleft mode */
8817 if (curwin->w_p_rl)
8818 {
8819 curwin->w_p_rl = FALSE;
8820 changed_window_setting();
8821 }
8822
8823 /* 'arabicshape' isn't reset, it is a global option and
8824 * another window may still need it "on". */
8825 }
8826
8827 /* 'delcombine' isn't reset, it is a global option and another
8828 * window may still want it "on". */
8829
8830# ifdef FEAT_KEYMAP
8831 /* Revert to the default keymap */
8832 curbuf->b_p_iminsert = B_IMODE_NONE;
8833 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8834# endif
8835 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008836 }
8837
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008838#endif
8839
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008840#ifdef FEAT_TERMGUICOLORS
8841 /* 'termguicolors' */
8842 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008843 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008844# ifdef FEAT_VTP
8845 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02008846 if (
8847# ifdef VIMDLL
8848 !gui.in_use && !gui.starting &&
8849# endif
8850 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008851 {
8852 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008853 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008854 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008855 if (is_term_win32())
8856 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008857# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008858# ifdef FEAT_GUI
8859 if (!gui.in_use && !gui.starting)
8860# endif
8861 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008862# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008863 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008864 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008865 {
8866 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008867 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008868 init_highlight(TRUE, FALSE);
8869 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008870# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008871 }
8872#endif
8873
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874 /*
8875 * End of handling side effects for bool options.
8876 */
8877
Bram Moolenaar53744302015-07-17 17:38:22 +02008878 /* after handling side effects, call autocommand */
8879
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880 options[opt_idx].flags |= P_WAS_SET;
8881
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008882#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008883 // Don't do this while starting up or recursively.
8884 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008885 {
8886 char_u buf_old[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008887
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008888 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
8889 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
8890 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008891 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8892 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8893 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
8894 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
8895 reset_v_option_vars();
8896 }
8897#endif
8898
Bram Moolenaar071d4272004-06-13 20:20:40 +00008899 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008900 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008901 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008902 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008903 check_redraw(options[opt_idx].flags);
8904
8905 return NULL;
8906}
8907
8908/*
8909 * Set the value of a number option, and take care of side effects.
8910 * Returns NULL for success, or an error message for an error.
8911 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008912 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008913set_num_option(
8914 int opt_idx, /* index in options[] table */
8915 char_u *varp, /* pointer to the option variable */
8916 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008917 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008918 size_t errbuflen, /* length of "errbuf" */
8919 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008920 OPT_MODELINE */
8921{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008922 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923 long old_value = *(long *)varp;
8924 long old_Rows = Rows; /* remember old Rows */
8925 long old_Columns = Columns; /* remember old Columns */
8926 long *pp = (long *)varp;
8927
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008928 /* Disallow changing some options from secure mode. */
8929 if ((secure
8930#ifdef HAVE_SANDBOX
8931 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008933 ) && (options[opt_idx].flags & P_SECURE))
8934 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008935
8936 *pp = value;
8937#ifdef FEAT_EVAL
8938 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008939 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008940#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008941#ifdef FEAT_GUI
8942 need_mouse_correct = TRUE;
8943#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008944
Bram Moolenaar14f24742012-08-08 18:01:05 +02008945 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008946 {
8947 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008948#ifdef FEAT_VARTABS
8949 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8950 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8951 ? tabstop_first(curbuf->b_p_vts_array)
8952 : curbuf->b_p_ts;
8953#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008954 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008955#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956 }
8957
8958 /*
8959 * Number options that need some action when changed
8960 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008961 if (pp == &p_wh || pp == &p_hh)
8962 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008963 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008964 if (p_wh < 1)
8965 {
8966 errmsg = e_positive;
8967 p_wh = 1;
8968 }
8969 if (p_wmh > p_wh)
8970 {
8971 errmsg = e_winheight;
8972 p_wh = p_wmh;
8973 }
8974 if (p_hh < 0)
8975 {
8976 errmsg = e_positive;
8977 p_hh = 0;
8978 }
8979
8980 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008981 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008982 {
8983 if (pp == &p_wh && curwin->w_height < p_wh)
8984 win_setheight((int)p_wh);
8985 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8986 win_setheight((int)p_hh);
8987 }
8988 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008989 else if (pp == &p_wmh)
8990 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008991 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008992 if (p_wmh < 0)
8993 {
8994 errmsg = e_positive;
8995 p_wmh = 0;
8996 }
8997 if (p_wmh > p_wh)
8998 {
8999 errmsg = e_winheight;
9000 p_wmh = p_wh;
9001 }
9002 win_setminheight();
9003 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009004 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009005 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009006 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009007 if (p_wiw < 1)
9008 {
9009 errmsg = e_positive;
9010 p_wiw = 1;
9011 }
9012 if (p_wmw > p_wiw)
9013 {
9014 errmsg = e_winwidth;
9015 p_wiw = p_wmw;
9016 }
9017
9018 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009019 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009020 win_setwidth((int)p_wiw);
9021 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009022 else if (pp == &p_wmw)
9023 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009024 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009025 if (p_wmw < 0)
9026 {
9027 errmsg = e_positive;
9028 p_wmw = 0;
9029 }
9030 if (p_wmw > p_wiw)
9031 {
9032 errmsg = e_winwidth;
9033 p_wmw = p_wiw;
9034 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009035 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009036 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009037
Bram Moolenaar071d4272004-06-13 20:20:40 +00009038 /* (re)set last window status line */
9039 else if (pp == &p_ls)
9040 {
9041 last_status(FALSE);
9042 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009043
9044 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009045 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009046 {
9047 shell_new_rows(); /* recompute window positions and heights */
9048 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009049
9050#ifdef FEAT_GUI
9051 else if (pp == &p_linespace)
9052 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009053 /* Recompute gui.char_height and resize the Vim window to keep the
9054 * same number of lines. */
9055 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009056 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009057 }
9058#endif
9059
9060#ifdef FEAT_FOLDING
9061 /* 'foldlevel' */
9062 else if (pp == &curwin->w_p_fdl)
9063 {
9064 if (curwin->w_p_fdl < 0)
9065 curwin->w_p_fdl = 0;
9066 newFoldLevel();
9067 }
9068
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009069 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009070 else if (pp == &curwin->w_p_fml)
9071 {
9072 foldUpdateAll(curwin);
9073 }
9074
9075 /* 'foldnestmax' */
9076 else if (pp == &curwin->w_p_fdn)
9077 {
9078 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9079 foldUpdateAll(curwin);
9080 }
9081
9082 /* 'foldcolumn' */
9083 else if (pp == &curwin->w_p_fdc)
9084 {
9085 if (curwin->w_p_fdc < 0)
9086 {
9087 errmsg = e_positive;
9088 curwin->w_p_fdc = 0;
9089 }
9090 else if (curwin->w_p_fdc > 12)
9091 {
9092 errmsg = e_invarg;
9093 curwin->w_p_fdc = 12;
9094 }
9095 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009096#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009097
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009098#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009099 /* 'shiftwidth' or 'tabstop' */
9100 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9101 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009102# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009103 if (foldmethodIsIndent(curwin))
9104 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009105# endif
9106# ifdef FEAT_CINDENT
9107 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9108 * parse 'cinoptions'. */
9109 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9110 parse_cino(curbuf);
9111# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009113#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009114
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009115 /* 'maxcombine' */
9116 else if (pp == &p_mco)
9117 {
9118 if (p_mco > MAX_MCO)
9119 p_mco = MAX_MCO;
9120 else if (p_mco < 0)
9121 p_mco = 0;
9122 screenclear(); /* will re-allocate the screen */
9123 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009124
Bram Moolenaar071d4272004-06-13 20:20:40 +00009125 else if (pp == &curbuf->b_p_iminsert)
9126 {
9127 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9128 {
9129 errmsg = e_invarg;
9130 curbuf->b_p_iminsert = B_IMODE_NONE;
9131 }
9132 p_iminsert = curbuf->b_p_iminsert;
9133 if (termcap_active) /* don't do this in the alternate screen */
9134 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009135#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136 /* Show/unshow value of 'keymap' in status lines. */
9137 status_redraw_curbuf();
9138#endif
9139 }
9140
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009141#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9142 /* 'imstyle' */
9143 else if (pp == &p_imst)
9144 {
9145 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9146 errmsg = e_invarg;
9147 }
9148#endif
9149
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009150 else if (pp == &p_window)
9151 {
9152 if (p_window < 1)
9153 p_window = 1;
9154 else if (p_window >= Rows)
9155 p_window = Rows - 1;
9156 }
9157
Bram Moolenaar071d4272004-06-13 20:20:40 +00009158 else if (pp == &curbuf->b_p_imsearch)
9159 {
9160 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9161 {
9162 errmsg = e_invarg;
9163 curbuf->b_p_imsearch = B_IMODE_NONE;
9164 }
9165 p_imsearch = curbuf->b_p_imsearch;
9166 }
9167
9168#ifdef FEAT_TITLE
9169 /* if 'titlelen' has changed, redraw the title */
9170 else if (pp == &p_titlelen)
9171 {
9172 if (p_titlelen < 0)
9173 {
9174 errmsg = e_positive;
9175 p_titlelen = 85;
9176 }
9177 if (starting != NO_SCREEN && old_value != p_titlelen)
9178 need_maketitle = TRUE;
9179 }
9180#endif
9181
9182 /* if p_ch changed value, change the command line height */
9183 else if (pp == &p_ch)
9184 {
9185 if (p_ch < 1)
9186 {
9187 errmsg = e_positive;
9188 p_ch = 1;
9189 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009190 if (p_ch > Rows - min_rows() + 1)
9191 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192
9193 /* Only compute the new window layout when startup has been
9194 * completed. Otherwise the frame sizes may be wrong. */
9195 if (p_ch != old_value && full_screen
9196#ifdef FEAT_GUI
9197 && !gui.starting
9198#endif
9199 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009200 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009201 }
9202
9203 /* when 'updatecount' changes from zero to non-zero, open swap files */
9204 else if (pp == &p_uc)
9205 {
9206 if (p_uc < 0)
9207 {
9208 errmsg = e_positive;
9209 p_uc = 100;
9210 }
9211 if (p_uc && !old_value)
9212 ml_open_files();
9213 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009214#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009215 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009216 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009217 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009218 {
9219 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009220 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009221 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009222 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009223 {
9224 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009225 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009226 }
9227 }
9228#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009229#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009230 else if (pp == &p_mzq)
9231 mzvim_reset_timer();
9232#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009234#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9235 /* 'pyxversion' */
9236 else if (pp == &p_pyx)
9237 {
9238 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9239 errmsg = e_invarg;
9240 }
9241#endif
9242
Bram Moolenaar071d4272004-06-13 20:20:40 +00009243 /* sync undo before 'undolevels' changes */
9244 else if (pp == &p_ul)
9245 {
9246 /* use the old value, otherwise u_sync() may not work properly */
9247 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009248 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249 p_ul = value;
9250 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009251 else if (pp == &curbuf->b_p_ul)
9252 {
9253 /* use the old value, otherwise u_sync() may not work properly */
9254 curbuf->b_p_ul = old_value;
9255 u_sync(TRUE);
9256 curbuf->b_p_ul = value;
9257 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009258
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009259#ifdef FEAT_LINEBREAK
9260 /* 'numberwidth' must be positive */
9261 else if (pp == &curwin->w_p_nuw)
9262 {
9263 if (curwin->w_p_nuw < 1)
9264 {
9265 errmsg = e_positive;
9266 curwin->w_p_nuw = 1;
9267 }
9268 if (curwin->w_p_nuw > 10)
9269 {
9270 errmsg = e_invarg;
9271 curwin->w_p_nuw = 10;
9272 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009273 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009274 }
9275#endif
9276
Bram Moolenaar1a384422010-07-14 19:53:30 +02009277 else if (pp == &curbuf->b_p_tw)
9278 {
9279 if (curbuf->b_p_tw < 0)
9280 {
9281 errmsg = e_positive;
9282 curbuf->b_p_tw = 0;
9283 }
9284#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009285 {
9286 win_T *wp;
9287 tabpage_T *tp;
9288
9289 FOR_ALL_TAB_WINDOWS(tp, wp)
9290 check_colorcolumn(wp);
9291 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009292#endif
9293 }
9294
Bram Moolenaar071d4272004-06-13 20:20:40 +00009295 /*
9296 * Check the bounds for numeric options here
9297 */
9298 if (Rows < min_rows() && full_screen)
9299 {
9300 if (errbuf != NULL)
9301 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009302 vim_snprintf((char *)errbuf, errbuflen,
9303 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009304 errmsg = errbuf;
9305 }
9306 Rows = min_rows();
9307 }
9308 if (Columns < MIN_COLUMNS && full_screen)
9309 {
9310 if (errbuf != NULL)
9311 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009312 vim_snprintf((char *)errbuf, errbuflen,
9313 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009314 errmsg = errbuf;
9315 }
9316 Columns = MIN_COLUMNS;
9317 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009318 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009319
Bram Moolenaar071d4272004-06-13 20:20:40 +00009320 /*
9321 * If the screen (shell) height has been changed, assume it is the
9322 * physical screenheight.
9323 */
9324 if (old_Rows != Rows || old_Columns != Columns)
9325 {
9326 /* Changing the screen size is not allowed while updating the screen. */
9327 if (updating_screen)
9328 *pp = old_value;
9329 else if (full_screen
9330#ifdef FEAT_GUI
9331 && !gui.starting
9332#endif
9333 )
9334 set_shellsize((int)Columns, (int)Rows, TRUE);
9335 else
9336 {
9337 /* Postpone the resizing; check the size and cmdline position for
9338 * messages. */
9339 check_shellsize();
9340 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9341 cmdline_row = Rows - p_ch;
9342 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009343 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009344 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009345 }
9346
Bram Moolenaar071d4272004-06-13 20:20:40 +00009347 if (curbuf->b_p_ts <= 0)
9348 {
9349 errmsg = e_positive;
9350 curbuf->b_p_ts = 8;
9351 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009352 if (p_tm < 0)
9353 {
9354 errmsg = e_positive;
9355 p_tm = 0;
9356 }
9357 if ((curwin->w_p_scr <= 0
9358 || (curwin->w_p_scr > curwin->w_height
9359 && curwin->w_height > 0))
9360 && full_screen)
9361 {
9362 if (pp == &(curwin->w_p_scr))
9363 {
9364 if (curwin->w_p_scr != 0)
9365 errmsg = e_scroll;
9366 win_comp_scroll(curwin);
9367 }
9368 /* If 'scroll' became invalid because of a side effect silently adjust
9369 * it. */
9370 else if (curwin->w_p_scr <= 0)
9371 curwin->w_p_scr = 1;
9372 else /* curwin->w_p_scr > curwin->w_height */
9373 curwin->w_p_scr = curwin->w_height;
9374 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009375 if (p_hi < 0)
9376 {
9377 errmsg = e_positive;
9378 p_hi = 0;
9379 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009380 else if (p_hi > 10000)
9381 {
9382 errmsg = e_invarg;
9383 p_hi = 10000;
9384 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009385 if (p_re < 0 || p_re > 2)
9386 {
9387 errmsg = e_invarg;
9388 p_re = 0;
9389 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009390 if (p_report < 0)
9391 {
9392 errmsg = e_positive;
9393 p_report = 1;
9394 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009395 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009396 {
9397 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9398 p_sj = Rows / 2;
9399 else
9400 {
9401 errmsg = e_scroll;
9402 p_sj = 1;
9403 }
9404 }
9405 if (p_so < 0 && full_screen)
9406 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009407 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009408 p_so = 0;
9409 }
9410 if (p_siso < 0 && full_screen)
9411 {
9412 errmsg = e_positive;
9413 p_siso = 0;
9414 }
9415#ifdef FEAT_CMDWIN
9416 if (p_cwh < 1)
9417 {
9418 errmsg = e_positive;
9419 p_cwh = 1;
9420 }
9421#endif
9422 if (p_ut < 0)
9423 {
9424 errmsg = e_positive;
9425 p_ut = 2000;
9426 }
9427 if (p_ss < 0)
9428 {
9429 errmsg = e_positive;
9430 p_ss = 0;
9431 }
9432
9433 /* May set global value for local option. */
9434 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9435 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9436
9437 options[opt_idx].flags |= P_WAS_SET;
9438
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009439#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009440 // Don't do this while starting up, failure or recursively.
9441 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009442 {
9443 char_u buf_old[11], buf_new[11], buf_type[7];
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01009444
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009445 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
9446 vim_snprintf((char *)buf_new, 10, "%ld", value);
9447 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009448 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9449 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9450 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
9451 apply_autocmds(EVENT_OPTIONSET, (char_u *) options[opt_idx].fullname, NULL, FALSE, NULL);
9452 reset_v_option_vars();
9453 }
9454#endif
9455
Bram Moolenaar071d4272004-06-13 20:20:40 +00009456 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009457 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009458 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009459 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009460 check_redraw(options[opt_idx].flags);
9461
9462 return errmsg;
9463}
9464
9465/*
9466 * Called after an option changed: check if something needs to be redrawn.
9467 */
9468 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009469check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009470{
9471 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009472 int doclear = (flags & P_RCLR) == P_RCLR;
9473 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009474
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9476 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009477
9478 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9479 changed_window_setting();
9480 if (flags & P_RBUF)
9481 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009482 if (flags & P_RWINONLY)
9483 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009484 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009485 redraw_all_later(CLEAR);
9486 else if (all)
9487 redraw_all_later(NOT_VALID);
9488}
9489
9490/*
9491 * Find index for option 'arg'.
9492 * Return -1 if not found.
9493 */
9494 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009495findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009496{
9497 int opt_idx;
9498 char *s, *p;
9499 static short quick_tab[27] = {0, 0}; /* quick access table */
9500 int is_term_opt;
9501
9502 /*
9503 * For first call: Initialize the quick-access table.
9504 * It contains the index for the first option that starts with a certain
9505 * letter. There are 26 letters, plus the first "t_" option.
9506 */
9507 if (quick_tab[1] == 0)
9508 {
9509 p = options[0].fullname;
9510 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9511 {
9512 if (s[0] != p[0])
9513 {
9514 if (s[0] == 't' && s[1] == '_')
9515 quick_tab[26] = opt_idx;
9516 else
9517 quick_tab[CharOrdLow(s[0])] = opt_idx;
9518 }
9519 p = s;
9520 }
9521 }
9522
9523 /*
9524 * Check for name starting with an illegal character.
9525 */
9526#ifdef EBCDIC
9527 if (!islower(arg[0]))
9528#else
9529 if (arg[0] < 'a' || arg[0] > 'z')
9530#endif
9531 return -1;
9532
9533 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9534 if (is_term_opt)
9535 opt_idx = quick_tab[26];
9536 else
9537 opt_idx = quick_tab[CharOrdLow(arg[0])];
9538 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9539 {
9540 if (STRCMP(arg, s) == 0) /* match full name */
9541 break;
9542 }
9543 if (s == NULL && !is_term_opt)
9544 {
9545 opt_idx = quick_tab[CharOrdLow(arg[0])];
9546 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9547 {
9548 s = options[opt_idx].shortname;
9549 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9550 break;
9551 s = NULL;
9552 }
9553 }
9554 if (s == NULL)
9555 opt_idx = -1;
9556 return opt_idx;
9557}
9558
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009559#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009560/*
9561 * Get the value for an option.
9562 *
9563 * Returns:
9564 * Number or Toggle option: 1, *numval gets value.
9565 * String option: 0, *stringval gets allocated string.
9566 * Hidden Number or Toggle option: -1.
9567 * hidden String option: -2.
9568 * unknown option: -3.
9569 */
9570 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009571get_option_value(
9572 char_u *name,
9573 long *numval,
9574 char_u **stringval, /* NULL when only checking existence */
9575 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576{
9577 int opt_idx;
9578 char_u *varp;
9579
9580 opt_idx = findoption(name);
9581 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009582 {
9583 int key;
9584
9585 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009586 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009587 {
9588 char_u key_name[2];
9589 char_u *p;
9590
9591 if (key < 0)
9592 {
9593 key_name[0] = KEY2TERMCAP0(key);
9594 key_name[1] = KEY2TERMCAP1(key);
9595 }
9596 else
9597 {
9598 key_name[0] = KS_KEY;
9599 key_name[1] = (key & 0xff);
9600 }
9601 p = find_termcode(key_name);
9602 if (p != NULL)
9603 {
9604 if (stringval != NULL)
9605 *stringval = vim_strsave(p);
9606 return 0;
9607 }
9608 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009609 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009610 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009611
9612 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9613
9614 if (options[opt_idx].flags & P_STRING)
9615 {
9616 if (varp == NULL) /* hidden option */
9617 return -2;
9618 if (stringval != NULL)
9619 {
9620#ifdef FEAT_CRYPT
9621 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009622 if ((char_u **)varp == &curbuf->b_p_key
9623 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009624 *stringval = vim_strsave((char_u *)"*****");
9625 else
9626#endif
9627 *stringval = vim_strsave(*(char_u **)(varp));
9628 }
9629 return 0;
9630 }
9631
9632 if (varp == NULL) /* hidden option */
9633 return -1;
9634 if (options[opt_idx].flags & P_NUM)
9635 *numval = *(long *)varp;
9636 else
9637 {
9638 /* Special case: 'modified' is b_changed, but we also want to consider
9639 * it set when 'ff' or 'fenc' changed. */
9640 if ((int *)varp == &curbuf->b_changed)
9641 *numval = curbufIsChanged();
9642 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009643 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009644 }
9645 return 1;
9646}
9647#endif
9648
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009649#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009650/*
9651 * Returns the option attributes and its value. Unlike the above function it
9652 * will return either global value or local value of the option depending on
9653 * what was requested, but it will never return global value if it was
9654 * requested to return local one and vice versa. Neither it will return
9655 * buffer-local value if it was requested to return window-local one.
9656 *
9657 * Pretends that option is absent if it is not present in the requested scope
9658 * (i.e. has no global, window-local or buffer-local value depending on
9659 * opt_type). Uses
9660 *
9661 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009662 * 0 hidden or unknown option, also option that does not have requested
9663 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009664 * see SOPT_* in vim.h for other flags
9665 *
9666 * Possible opt_type values: see SREQ_* in vim.h
9667 */
9668 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009669get_option_value_strict(
9670 char_u *name,
9671 long *numval,
9672 char_u **stringval, /* NULL when only obtaining attributes */
9673 int opt_type,
9674 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009675{
9676 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009677 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009678 struct vimoption *p;
9679 int r = 0;
9680
9681 opt_idx = findoption(name);
9682 if (opt_idx < 0)
9683 return 0;
9684
9685 p = &(options[opt_idx]);
9686
9687 /* Hidden option */
9688 if (p->var == NULL)
9689 return 0;
9690
9691 if (p->flags & P_BOOL)
9692 r |= SOPT_BOOL;
9693 else if (p->flags & P_NUM)
9694 r |= SOPT_NUM;
9695 else if (p->flags & P_STRING)
9696 r |= SOPT_STRING;
9697
9698 if (p->indir == PV_NONE)
9699 {
9700 if (opt_type == SREQ_GLOBAL)
9701 r |= SOPT_GLOBAL;
9702 else
9703 return 0; /* Did not request global-only option */
9704 }
9705 else
9706 {
9707 if (p->indir & PV_BOTH)
9708 r |= SOPT_GLOBAL;
9709 else if (opt_type == SREQ_GLOBAL)
9710 return 0; /* Requested global option */
9711
9712 if (p->indir & PV_WIN)
9713 {
9714 if (opt_type == SREQ_BUF)
9715 return 0; /* Did not request window-local option */
9716 else
9717 r |= SOPT_WIN;
9718 }
9719 else if (p->indir & PV_BUF)
9720 {
9721 if (opt_type == SREQ_WIN)
9722 return 0; /* Did not request buffer-local option */
9723 else
9724 r |= SOPT_BUF;
9725 }
9726 }
9727
9728 if (stringval == NULL)
9729 return r;
9730
9731 if (opt_type == SREQ_GLOBAL)
9732 varp = p->var;
9733 else
9734 {
9735 if (opt_type == SREQ_BUF)
9736 {
9737 /* Special case: 'modified' is b_changed, but we also want to
9738 * consider it set when 'ff' or 'fenc' changed. */
9739 if (p->indir == PV_MOD)
9740 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009741 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009742 varp = NULL;
9743 }
9744#ifdef FEAT_CRYPT
9745 else if (p->indir == PV_KEY)
9746 {
9747 /* never return the value of the crypt key */
9748 *stringval = NULL;
9749 varp = NULL;
9750 }
9751#endif
9752 else
9753 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009754 buf_T *save_curbuf = curbuf;
9755
9756 // only getting a pointer, no need to use aucmd_prepbuf()
9757 curbuf = (buf_T *)from;
9758 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009759 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009760 curbuf = save_curbuf;
9761 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009762 }
9763 }
9764 else if (opt_type == SREQ_WIN)
9765 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009766 win_T *save_curwin = curwin;
9767
9768 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009769 curbuf = curwin->w_buffer;
9770 varp = get_varp(p);
9771 curwin = save_curwin;
9772 curbuf = curwin->w_buffer;
9773 }
9774 if (varp == p->var)
9775 return (r | SOPT_UNSET);
9776 }
9777
9778 if (varp != NULL)
9779 {
9780 if (p->flags & P_STRING)
9781 *stringval = vim_strsave(*(char_u **)(varp));
9782 else if (p->flags & P_NUM)
9783 *numval = *(long *) varp;
9784 else
9785 *numval = *(int *)varp;
9786 }
9787
9788 return r;
9789}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009790
9791/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009792 * Iterate over options. First argument is a pointer to a pointer to a
9793 * structure inside options[] array, second is option type like in the above
9794 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009795 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009796 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009797 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009798 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009799 * first argument to NULL.
9800 *
9801 * Returns full option name for current option on each call.
9802 */
9803 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009804option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009805{
9806 struct vimoption *ret = NULL;
9807 do
9808 {
9809 if (*option == NULL)
9810 *option = (void *) options;
9811 else if (((struct vimoption *) (*option))->fullname == NULL)
9812 {
9813 *option = NULL;
9814 return NULL;
9815 }
9816 else
9817 *option = (void *) (((struct vimoption *) (*option)) + 1);
9818
9819 ret = ((struct vimoption *) (*option));
9820
9821 /* Hidden option */
9822 if (ret->var == NULL)
9823 {
9824 ret = NULL;
9825 continue;
9826 }
9827
9828 switch (opt_type)
9829 {
9830 case SREQ_GLOBAL:
9831 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9832 ret = NULL;
9833 break;
9834 case SREQ_BUF:
9835 if (!(ret->indir & PV_BUF))
9836 ret = NULL;
9837 break;
9838 case SREQ_WIN:
9839 if (!(ret->indir & PV_WIN))
9840 ret = NULL;
9841 break;
9842 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009843 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009844 return NULL;
9845 }
9846 }
9847 while (ret == NULL);
9848
9849 return (char_u *)ret->fullname;
9850}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009851#endif
9852
Bram Moolenaar071d4272004-06-13 20:20:40 +00009853/*
9854 * Set the value of option "name".
9855 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009856 *
9857 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009858 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009859 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009860set_option_value(
9861 char_u *name,
9862 long number,
9863 char_u *string,
9864 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009865{
9866 int opt_idx;
9867 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009868 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009869
9870 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009871 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009872 {
9873 int key;
9874
9875 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009876 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009877 {
9878 char_u key_name[2];
9879
9880 if (key < 0)
9881 {
9882 key_name[0] = KEY2TERMCAP0(key);
9883 key_name[1] = KEY2TERMCAP1(key);
9884 }
9885 else
9886 {
9887 key_name[0] = KS_KEY;
9888 key_name[1] = (key & 0xff);
9889 }
9890 add_termcode(key_name, string, FALSE);
9891 if (full_screen)
9892 ttest(FALSE);
9893 redraw_all_later(CLEAR);
9894 return NULL;
9895 }
9896
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009897 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009898 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009899 else
9900 {
9901 flags = options[opt_idx].flags;
9902#ifdef HAVE_SANDBOX
9903 /* Disallow changing some options in the sandbox */
9904 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009905 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009906 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009907 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009908 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009909#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009910 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009911 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912 else
9913 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009914 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009915 if (varp != NULL) /* hidden option is not changed */
9916 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009917 if (number == 0 && string != NULL)
9918 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009919 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009920
9921 /* Either we are given a string or we are setting option
9922 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009923 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009924 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009925 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009926 {
9927 /* There's another character after zeros or the string
9928 * is empty. In both cases, we are trying to set a
9929 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009930 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009931 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009932 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009933
9934 }
9935 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009936 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009937 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009938 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009939 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009940 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009941 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009942 }
9943 }
9944 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009945 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009946}
9947
9948/*
9949 * Get the terminal code for a terminal option.
9950 * Returns NULL when not found.
9951 */
9952 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009953get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009954{
9955 int opt_idx;
9956 char_u *varp;
9957
9958 if (tname[0] != 't' || tname[1] != '_' ||
9959 tname[2] == NUL || tname[3] == NUL)
9960 return NULL;
9961 if ((opt_idx = findoption(tname)) >= 0)
9962 {
9963 varp = get_varp(&(options[opt_idx]));
9964 if (varp != NULL)
9965 varp = *(char_u **)(varp);
9966 return varp;
9967 }
9968 return find_termcode(tname + 2);
9969}
9970
9971 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009972get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009973{
9974 int i;
9975
9976 i = findoption((char_u *)"hl");
9977 if (i >= 0)
9978 return options[i].def_val[VI_DEFAULT];
9979 return (char_u *)NULL;
9980}
9981
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009982 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009983get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009984{
9985 int i;
9986
9987 i = findoption((char_u *)"enc");
9988 if (i >= 0)
9989 return options[i].def_val[VI_DEFAULT];
9990 return (char_u *)NULL;
9991}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009992
Bram Moolenaar071d4272004-06-13 20:20:40 +00009993/*
9994 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009995 * When "has_lt" is true there is a '<' before "*arg_arg".
9996 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009997 */
9998 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009999find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010000{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010001 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010002 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010003 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010004
10005 /*
10006 * Don't use get_special_key_code() for t_xx, we don't want it to call
10007 * add_termcap_entry().
10008 */
10009 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10010 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010011 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010012 {
10013 --arg; /* put arg at the '<' */
10014 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010015 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016 if (modifiers) /* can't handle modifiers here */
10017 key = 0;
10018 }
10019 return key;
10020}
10021
10022/*
10023 * if 'all' == 0: show changed options
10024 * if 'all' == 1: show all normal options
10025 * if 'all' == 2: show all terminal options
10026 */
10027 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010028showoptions(
10029 int all,
10030 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010031{
10032 struct vimoption *p;
10033 int col;
10034 int isterm;
10035 char_u *varp;
10036 struct vimoption **items;
10037 int item_count;
10038 int run;
10039 int row, rows;
10040 int cols;
10041 int i;
10042 int len;
10043
10044#define INC 20
10045#define GAP 3
10046
10047 items = (struct vimoption **)alloc((unsigned)(sizeof(struct vimoption *) *
10048 PARAM_COUNT));
10049 if (items == NULL)
10050 return;
10051
10052 /* Highlight title */
10053 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010054 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010055 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010056 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010057 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010058 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010059 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010060 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010061
10062 /*
10063 * do the loop two times:
10064 * 1. display the short items
10065 * 2. display the long items (only strings and numbers)
10066 */
10067 for (run = 1; run <= 2 && !got_int; ++run)
10068 {
10069 /*
10070 * collect the items in items[]
10071 */
10072 item_count = 0;
10073 for (p = &options[0]; p->fullname != NULL; p++)
10074 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010075 // apply :filter /pat/
10076 if (message_filtered((char_u *) p->fullname))
10077 continue;
10078
Bram Moolenaar071d4272004-06-13 20:20:40 +000010079 varp = NULL;
10080 isterm = istermoption(p);
10081 if (opt_flags != 0)
10082 {
10083 if (p->indir != PV_NONE && !isterm)
10084 varp = get_varp_scope(p, opt_flags);
10085 }
10086 else
10087 varp = get_varp(p);
10088 if (varp != NULL
10089 && ((all == 2 && isterm)
10090 || (all == 1 && !isterm)
10091 || (all == 0 && !optval_default(p, varp))))
10092 {
10093 if (p->flags & P_BOOL)
10094 len = 1; /* a toggle option fits always */
10095 else
10096 {
10097 option_value2string(p, opt_flags);
10098 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10099 }
10100 if ((len <= INC - GAP && run == 1) ||
10101 (len > INC - GAP && run == 2))
10102 items[item_count++] = p;
10103 }
10104 }
10105
10106 /*
10107 * display the items
10108 */
10109 if (run == 1)
10110 {
10111 cols = (Columns + GAP - 3) / INC;
10112 if (cols == 0)
10113 cols = 1;
10114 rows = (item_count + cols - 1) / cols;
10115 }
10116 else /* run == 2 */
10117 rows = item_count;
10118 for (row = 0; row < rows && !got_int; ++row)
10119 {
10120 msg_putchar('\n'); /* go to next line */
10121 if (got_int) /* 'q' typed in more */
10122 break;
10123 col = 0;
10124 for (i = row; i < item_count; i += rows)
10125 {
10126 msg_col = col; /* make columns */
10127 showoneopt(items[i], opt_flags);
10128 col += INC;
10129 }
10130 out_flush();
10131 ui_breakcheck();
10132 }
10133 }
10134 vim_free(items);
10135}
10136
10137/*
10138 * Return TRUE if option "p" has its default value.
10139 */
10140 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010141optval_default(struct vimoption *p, char_u *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010142{
10143 int dvi;
10144
10145 if (varp == NULL)
10146 return TRUE; /* hidden option is always at default */
10147 dvi = ((p->flags & P_VI_DEF) || p_cp) ? VI_DEFAULT : VIM_DEFAULT;
10148 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010149 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010150 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010151 /* the cast to long is required for Manx C, long_i is
10152 * needed for MSVC */
10153 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010154 /* P_STRING */
10155 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10156}
10157
10158/*
10159 * showoneopt: show the value of one option
10160 * must not be called with a hidden option!
10161 */
10162 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010163showoneopt(
10164 struct vimoption *p,
10165 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010166{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010167 char_u *varp;
10168 int save_silent = silent_mode;
10169
10170 silent_mode = FALSE;
10171 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010172
10173 varp = get_varp_scope(p, opt_flags);
10174
10175 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10176 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10177 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010178 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010179 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010180 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010181 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010182 msg_puts(" ");
10183 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184 if (!(p->flags & P_BOOL))
10185 {
10186 msg_putchar('=');
10187 /* put value string in NameBuff */
10188 option_value2string(p, opt_flags);
10189 msg_outtrans(NameBuff);
10190 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010191
10192 silent_mode = save_silent;
10193 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194}
10195
10196/*
10197 * Write modified options as ":set" commands to a file.
10198 *
10199 * There are three values for "opt_flags":
10200 * OPT_GLOBAL: Write global option values and fresh values of
10201 * buffer-local options (used for start of a session
10202 * file).
10203 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10204 * curwin (used for a vimrc file).
10205 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10206 * and local values for window-local options of
10207 * curwin. Local values are also written when at the
10208 * default value, because a modeline or autocommand
10209 * may have set them when doing ":edit file" and the
10210 * user has set them back at the default or fresh
10211 * value.
10212 * When "local_only" is TRUE, don't write fresh
10213 * values, only local values (for ":mkview").
10214 * (fresh value = value used for a new buffer or window for a local option).
10215 *
10216 * Return FAIL on error, OK otherwise.
10217 */
10218 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010219makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220{
10221 struct vimoption *p;
10222 char_u *varp; /* currently used value */
10223 char_u *varp_fresh; /* local value */
10224 char_u *varp_local = NULL; /* fresh value */
10225 char *cmd;
10226 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010227 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228
10229 /*
10230 * The options that don't have a default (terminal name, columns, lines)
10231 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010232 * Do the loop over "options[]" twice: once for options with the
10233 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010234 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010235 for (pri = 1; pri >= 0; --pri)
10236 {
10237 for (p = &options[0]; !istermoption(p); p++)
10238 if (!(p->flags & P_NO_MKRC)
10239 && !istermoption(p)
10240 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241 {
10242 /* skip global option when only doing locals */
10243 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10244 continue;
10245
10246 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10247 * file, they are always buffer-specific. */
10248 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10249 continue;
10250
10251 /* Global values are only written when not at the default value. */
10252 varp = get_varp_scope(p, opt_flags);
10253 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp))
10254 continue;
10255
10256 round = 2;
10257 if (p->indir != PV_NONE)
10258 {
10259 if (p->var == VAR_WIN)
10260 {
10261 /* skip window-local option when only doing globals */
10262 if (!(opt_flags & OPT_LOCAL))
10263 continue;
10264 /* When fresh value of window-local option is not at the
10265 * default, need to write it too. */
10266 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10267 {
10268 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
10269 if (!optval_default(p, varp_fresh))
10270 {
10271 round = 1;
10272 varp_local = varp;
10273 varp = varp_fresh;
10274 }
10275 }
10276 }
10277 }
10278
10279 /* Round 1: fresh value for window-local options.
10280 * Round 2: other values */
10281 for ( ; round <= 2; varp = varp_local, ++round)
10282 {
10283 if (round == 1 || (opt_flags & OPT_GLOBAL))
10284 cmd = "set";
10285 else
10286 cmd = "setlocal";
10287
10288 if (p->flags & P_BOOL)
10289 {
10290 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10291 return FAIL;
10292 }
10293 else if (p->flags & P_NUM)
10294 {
10295 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10296 return FAIL;
10297 }
10298 else /* P_STRING */
10299 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010300 int do_endif = FALSE;
10301
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 /* Don't set 'syntax' and 'filetype' again if the value is
10303 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010304 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010305#if defined(FEAT_SYN_HL)
10306 p->indir == PV_SYN ||
10307#endif
10308 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010309 {
10310 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10311 *(char_u **)(varp)) < 0
10312 || put_eol(fd) < 0)
10313 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010314 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010315 }
10316 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010317 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010318 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010319 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010320 {
10321 if (put_line(fd, "endif") == FAIL)
10322 return FAIL;
10323 }
10324 }
10325 }
10326 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010327 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010328 return OK;
10329}
10330
10331#if defined(FEAT_FOLDING) || defined(PROTO)
10332/*
10333 * Generate set commands for the local fold options only. Used when
10334 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10335 */
10336 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010337makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010338{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010339 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010340# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010341 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010342 == FAIL
10343# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010344 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010346 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010347 == FAIL
10348 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10349 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10350 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10351 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10352 )
10353 return FAIL;
10354
10355 return OK;
10356}
10357#endif
10358
10359 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010360put_setstring(
10361 FILE *fd,
10362 char *cmd,
10363 char *name,
10364 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010365 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010366{
10367 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010368 char_u *buf = NULL;
10369 char_u *part = NULL;
10370 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010371
10372 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10373 return FAIL;
10374 if (*valuep != NULL)
10375 {
10376 /* Output 'pastetoggle' as key names. For other
10377 * options some characters have to be escaped with
10378 * CTRL-V or backslash */
10379 if (valuep == &p_pt)
10380 {
10381 s = *valuep;
10382 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010383 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010384 return FAIL;
10385 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010386 // expand the option value, replace $HOME by ~
10387 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010389 int size = (int)STRLEN(*valuep) + 1;
10390
10391 // replace home directory in the whole option value into "buf"
10392 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010393 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010394 goto fail;
10395 home_replace(NULL, *valuep, buf, size, FALSE);
10396
10397 // If the option value is longer than MAXPATHL, we need to append
10398 // earch comma separated part of the option separately, so that it
10399 // can be expanded when read back.
10400 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10401 && vim_strchr(*valuep, ',') != NULL)
10402 {
10403 part = alloc(size);
10404 if (part == NULL)
10405 goto fail;
10406
10407 // write line break to clear the option, e.g. ':set rtp='
10408 if (put_eol(fd) == FAIL)
10409 goto fail;
10410
10411 p = buf;
10412 while (*p != NUL)
10413 {
10414 // for each comma separated option part, append value to
10415 // the option, :set rtp+=value
10416 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10417 goto fail;
10418 (void)copy_option_part(&p, part, size, ",");
10419 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10420 goto fail;
10421 }
10422 vim_free(buf);
10423 vim_free(part);
10424 return OK;
10425 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010427 {
10428 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010430 }
10431 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432 }
10433 else if (put_escstr(fd, *valuep, 2) == FAIL)
10434 return FAIL;
10435 }
10436 if (put_eol(fd) < 0)
10437 return FAIL;
10438 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010439fail:
10440 vim_free(buf);
10441 vim_free(part);
10442 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010443}
10444
10445 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010446put_setnum(
10447 FILE *fd,
10448 char *cmd,
10449 char *name,
10450 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010451{
10452 long wc;
10453
10454 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10455 return FAIL;
10456 if (wc_use_keyname((char_u *)valuep, &wc))
10457 {
10458 /* print 'wildchar' and 'wildcharm' as a key name */
10459 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10460 return FAIL;
10461 }
10462 else if (fprintf(fd, "%ld", *valuep) < 0)
10463 return FAIL;
10464 if (put_eol(fd) < 0)
10465 return FAIL;
10466 return OK;
10467}
10468
10469 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010470put_setbool(
10471 FILE *fd,
10472 char *cmd,
10473 char *name,
10474 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475{
Bram Moolenaar893de922007-10-02 18:40:57 +000010476 if (value < 0) /* global/local option using global value */
10477 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010478 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10479 || put_eol(fd) < 0)
10480 return FAIL;
10481 return OK;
10482}
10483
10484/*
10485 * Clear all the terminal options.
10486 * If the option has been allocated, free the memory.
10487 * Terminal options are never hidden or indirect.
10488 */
10489 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010490clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010491{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010492 /*
10493 * Reset a few things before clearing the old options. This may cause
10494 * outputting a few things that the terminal doesn't understand, but the
10495 * screen will be cleared later, so this is OK.
10496 */
10497#ifdef FEAT_MOUSE_TTY
10498 mch_setmouse(FALSE); /* switch mouse off */
10499#endif
10500#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010501 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010502#endif
10503#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10504 /* When starting the GUI close the display opened for the clipboard.
10505 * After restoring the title, because that will need the display. */
10506 if (gui.starting)
10507 clear_xterm_clip();
10508#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010509 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010510
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010511 free_termoptions();
10512}
10513
10514 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010515free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010516{
10517 struct vimoption *p;
10518
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010519 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010520 if (istermoption(p))
10521 {
10522 if (p->flags & P_ALLOCED)
10523 free_string_option(*(char_u **)(p->var));
10524 if (p->flags & P_DEF_ALLOCED)
10525 free_string_option(p->def_val[VI_DEFAULT]);
10526 *(char_u **)(p->var) = empty_option;
10527 p->def_val[VI_DEFAULT] = empty_option;
10528 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010529#ifdef FEAT_EVAL
10530 // remember where the option was cleared
10531 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10532#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533 }
10534 clear_termcodes();
10535}
10536
10537/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010538 * Free the string for one term option, if it was allocated.
10539 * Set the string to empty_option and clear allocated flag.
10540 * "var" points to the option value.
10541 */
10542 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010543free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010544{
10545 struct vimoption *p;
10546
10547 for (p = &options[0]; p->fullname != NULL; p++)
10548 if (p->var == var)
10549 {
10550 if (p->flags & P_ALLOCED)
10551 free_string_option(*(char_u **)(p->var));
10552 *(char_u **)(p->var) = empty_option;
10553 p->flags &= ~P_ALLOCED;
10554 break;
10555 }
10556}
10557
10558/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010559 * Set the terminal option defaults to the current value.
10560 * Used after setting the terminal name.
10561 */
10562 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010563set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010564{
10565 struct vimoption *p;
10566
10567 for (p = &options[0]; p->fullname != NULL; p++)
10568 {
10569 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10570 {
10571 if (p->flags & P_DEF_ALLOCED)
10572 {
10573 free_string_option(p->def_val[VI_DEFAULT]);
10574 p->flags &= ~P_DEF_ALLOCED;
10575 }
10576 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10577 if (p->flags & P_ALLOCED)
10578 {
10579 p->flags |= P_DEF_ALLOCED;
10580 p->flags &= ~P_ALLOCED; /* don't free the value now */
10581 }
10582 }
10583 }
10584}
10585
10586/*
10587 * return TRUE if 'p' starts with 't_'
10588 */
10589 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010590istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591{
10592 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10593}
10594
10595/*
10596 * Compute columns for ruler and shown command. 'sc_col' is also used to
10597 * decide what the maximum length of a message on the status line can be.
10598 * If there is a status line for the last window, 'sc_col' is independent
10599 * of 'ru_col'.
10600 */
10601
10602#define COL_RULER 17 /* columns needed by standard ruler */
10603
10604 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010605comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010606{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010607#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010608 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010609
10610 sc_col = 0;
10611 ru_col = 0;
10612 if (p_ru)
10613 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010614# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010616# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010617 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010618# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010619 /* no last status line, adjust sc_col */
10620 if (!last_has_status)
10621 sc_col = ru_col;
10622 }
10623 if (p_sc)
10624 {
10625 sc_col += SHOWCMD_COLS;
10626 if (!p_ru || last_has_status) /* no need for separating space */
10627 ++sc_col;
10628 }
10629 sc_col = Columns - sc_col;
10630 ru_col = Columns - ru_col;
10631 if (sc_col <= 0) /* screen too narrow, will become a mess */
10632 sc_col = 1;
10633 if (ru_col <= 0)
10634 ru_col = 1;
10635#else
10636 sc_col = Columns;
10637 ru_col = Columns;
10638#endif
10639}
10640
Bram Moolenaar113e1072019-01-20 15:30:40 +010010641#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010642/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010643 * Unset local option value, similar to ":set opt<".
10644 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010645 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010646unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010647{
10648 struct vimoption *p;
10649 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010650 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010651
10652 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010653 if (opt_idx < 0)
10654 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010655 p = &(options[opt_idx]);
10656
10657 switch ((int)p->indir)
10658 {
10659 /* global option with local value: use local value if it's been set */
10660 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010661 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010662 break;
10663 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010664 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010665 break;
10666 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010667 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010668 break;
10669 case PV_AR:
10670 buf->b_p_ar = -1;
10671 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010672 case PV_BKC:
10673 clear_string_option(&buf->b_p_bkc);
10674 buf->b_bkc_flags = 0;
10675 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010676 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010677 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010678 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010679 case PV_TC:
10680 clear_string_option(&buf->b_p_tc);
10681 buf->b_tc_flags = 0;
10682 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010683 case PV_SISO:
10684 curwin->w_p_siso = -1;
10685 break;
10686 case PV_SO:
10687 curwin->w_p_so = -1;
10688 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010689#ifdef FEAT_FIND_ID
10690 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010691 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010692 break;
10693 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010694 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010695 break;
10696#endif
10697#ifdef FEAT_INS_EXPAND
10698 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010699 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010700 break;
10701 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010702 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010703 break;
10704#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010705 case PV_FP:
10706 clear_string_option(&buf->b_p_fp);
10707 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010708#ifdef FEAT_QUICKFIX
10709 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010710 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010711 break;
10712 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010713 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010714 break;
10715 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010716 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010717 break;
10718#endif
10719#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10720 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010721 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010722 break;
10723#endif
10724#if defined(FEAT_CRYPT)
10725 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010726 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010727 break;
10728#endif
10729#ifdef FEAT_STL_OPT
10730 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010731 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010732 break;
10733#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010734 case PV_UL:
10735 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10736 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010737#ifdef FEAT_LISP
10738 case PV_LW:
10739 clear_string_option(&buf->b_p_lw);
10740 break;
10741#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010742 case PV_MENC:
10743 clear_string_option(&buf->b_p_menc);
10744 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010745 }
10746}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010747#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010748
10749/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750 * Get pointer to option variable, depending on local or global scope.
10751 */
10752 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010753get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010754{
10755 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10756 {
10757 if (p->var == VAR_WIN)
10758 return (char_u *)GLOBAL_WO(get_varp(p));
10759 return p->var;
10760 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010761 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762 {
10763 switch ((int)p->indir)
10764 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010765 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010766#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010767 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10768 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10769 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010770#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010771 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10772 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10773 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010774 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010775 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010776 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010777 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10778 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010779#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010780 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10781 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010782#endif
10783#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010784 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10785 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010786#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010787#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10788 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10789#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010790#if defined(FEAT_CRYPT)
10791 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10792#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010793#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010794 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010795#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010796 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010797#ifdef FEAT_LISP
10798 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10799#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010800 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010801 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010802 }
10803 return NULL; /* "cannot happen" */
10804 }
10805 return get_varp(p);
10806}
10807
10808/*
10809 * Get pointer to option variable.
10810 */
10811 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010812get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010813{
10814 /* hidden option, always return NULL */
10815 if (p->var == NULL)
10816 return NULL;
10817
10818 switch ((int)p->indir)
10819 {
10820 case PV_NONE: return p->var;
10821
10822 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010823 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010824 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010825 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010826 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010827 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010828 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010829 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010830 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010831 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010833 case PV_TC: return *curbuf->b_p_tc != NUL
10834 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010835 case PV_BKC: return *curbuf->b_p_bkc != NUL
10836 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010837 case PV_SISO: return curwin->w_p_siso >= 0
10838 ? (char_u *)&(curwin->w_p_siso) : p->var;
10839 case PV_SO: return curwin->w_p_so >= 0
10840 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010841#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010842 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010843 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010844 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010845 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10846#endif
10847#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010848 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010849 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010850 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
10852#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010853 case PV_FP: return *curbuf->b_p_fp != NUL
10854 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010856 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010858 case PV_GP: return *curbuf->b_p_gp != NUL
10859 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10860 case PV_MP: return *curbuf->b_p_mp != NUL
10861 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010863#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10864 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10865 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10866#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010867#if defined(FEAT_CRYPT)
10868 case PV_CM: return *curbuf->b_p_cm != NUL
10869 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10870#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010871#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010872 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010873 ? (char_u *)&(curwin->w_p_stl) : p->var;
10874#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010875 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10876 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010877#ifdef FEAT_LISP
10878 case PV_LW: return *curbuf->b_p_lw != NUL
10879 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10880#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010881 case PV_MENC: return *curbuf->b_p_menc != NUL
10882 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010883
10884#ifdef FEAT_ARABIC
10885 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10886#endif
10887 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010888#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010889 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10890#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010891#ifdef FEAT_SYN_HL
10892 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10893 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010894 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010895#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010896#ifdef FEAT_DIFF
10897 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10898#endif
10899#ifdef FEAT_FOLDING
10900 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10901 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10902 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10903 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10904 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10905 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10906 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10907# ifdef FEAT_EVAL
10908 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10909 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10910# endif
10911 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10912#endif
10913 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010914 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010915#ifdef FEAT_LINEBREAK
10916 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10917#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010918 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010919 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010920#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010921 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10922#endif
10923#ifdef FEAT_RIGHTLEFT
10924 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10925 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10926#endif
10927 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10928 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10929#ifdef FEAT_LINEBREAK
10930 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010931 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10932 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010934 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010935 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010936#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010937 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10938 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10939#endif
10940#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010941 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10942 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10943 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010944#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010945
10946 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10947 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010948 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10950 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010951 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10952 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10953#ifdef FEAT_CINDENT
10954 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10955 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10956 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10957#endif
10958#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10959 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10960#endif
10961#ifdef FEAT_COMMENTS
10962 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10963#endif
10964#ifdef FEAT_FOLDING
10965 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10966#endif
10967#ifdef FEAT_INS_EXPAND
10968 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
10969#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010970#ifdef FEAT_COMPL_FUNC
10971 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010972 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010973#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020010974#ifdef FEAT_EVAL
10975 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
10976#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010977 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010978 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010979 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010980 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010981 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010982 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010983 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010984 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010985 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10986 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10987 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10988 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10989#ifdef FEAT_FIND_ID
10990# ifdef FEAT_EVAL
10991 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10992# endif
10993#endif
10994#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10995 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10996 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10997#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010998#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010999 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11000#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011001#ifdef FEAT_CRYPT
11002 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11003#endif
11004#ifdef FEAT_LISP
11005 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11006#endif
11007 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11008 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11009 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11010 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11011 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011012 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011013#ifdef FEAT_TEXTOBJ
11014 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011016 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11017#ifdef FEAT_SMARTINDENT
11018 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011020 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011021 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11022#ifdef FEAT_SEARCHPATH
11023 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11024#endif
11025 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11026#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011027 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011028 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11029#endif
11030#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011031 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11032 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11033 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011034#endif
11035 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11036 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11037 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11038 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011039#ifdef FEAT_PERSISTENT_UNDO
11040 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11041#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011042 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11043#ifdef FEAT_KEYMAP
11044 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11045#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011046#ifdef FEAT_SIGNS
11047 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11048#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011049#ifdef FEAT_VARTABS
11050 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11051 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11052#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011053 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054 }
11055 /* always return a valid pointer to avoid a crash! */
11056 return (char_u *)&(curbuf->b_p_wm);
11057}
11058
11059/*
11060 * Get the value of 'equalprg', either the buffer-local one or the global one.
11061 */
11062 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011063get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011064{
11065 if (*curbuf->b_p_ep == NUL)
11066 return p_ep;
11067 return curbuf->b_p_ep;
11068}
11069
Bram Moolenaar071d4272004-06-13 20:20:40 +000011070/*
11071 * Copy options from one window to another.
11072 * Used when splitting a window.
11073 */
11074 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011075win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076{
11077 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11078 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011079#if defined(FEAT_LINEBREAK)
11080 briopt_check(wp_to);
11081#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083
11084/*
11085 * Copy the options from one winopt_T to another.
11086 * Doesn't free the old option values in "to", use clear_winopt() for that.
11087 * The 'scroll' option is not copied, because it depends on the window height.
11088 * The 'previewwindow' option is reset, there can be only one preview window.
11089 */
11090 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011091copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011092{
11093#ifdef FEAT_ARABIC
11094 to->wo_arab = from->wo_arab;
11095#endif
11096 to->wo_list = from->wo_list;
11097 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011098 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011099#ifdef FEAT_LINEBREAK
11100 to->wo_nuw = from->wo_nuw;
11101#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011102#ifdef FEAT_RIGHTLEFT
11103 to->wo_rl = from->wo_rl;
11104 to->wo_rlc = vim_strsave(from->wo_rlc);
11105#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011106#ifdef FEAT_STL_OPT
11107 to->wo_stl = vim_strsave(from->wo_stl);
11108#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011109 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011110#ifdef FEAT_DIFF
11111 to->wo_wrap_save = from->wo_wrap_save;
11112#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011113#ifdef FEAT_LINEBREAK
11114 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011115 to->wo_bri = from->wo_bri;
11116 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011117#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011119 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011120 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011121 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011122#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011123 to->wo_spell = from->wo_spell;
11124#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011125#ifdef FEAT_SYN_HL
11126 to->wo_cuc = from->wo_cuc;
11127 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011128 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011130#ifdef FEAT_DIFF
11131 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011132 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011134#ifdef FEAT_CONCEAL
11135 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011136 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011137#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011138#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011139 to->wo_twk = vim_strsave(from->wo_twk);
11140 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011141#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011142#ifdef FEAT_FOLDING
11143 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011144 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011145 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011146 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011147 to->wo_fdi = vim_strsave(from->wo_fdi);
11148 to->wo_fml = from->wo_fml;
11149 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011150 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011151 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011152 to->wo_fdm_save = from->wo_diff_saved
11153 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011154 to->wo_fdn = from->wo_fdn;
11155# ifdef FEAT_EVAL
11156 to->wo_fde = vim_strsave(from->wo_fde);
11157 to->wo_fdt = vim_strsave(from->wo_fdt);
11158# endif
11159 to->wo_fmr = vim_strsave(from->wo_fmr);
11160#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011161#ifdef FEAT_SIGNS
11162 to->wo_scl = vim_strsave(from->wo_scl);
11163#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164 check_winopt(to); /* don't want NULL pointers */
11165}
11166
11167/*
11168 * Check string options in a window for a NULL value.
11169 */
11170 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011171check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011172{
11173 check_winopt(&win->w_onebuf_opt);
11174 check_winopt(&win->w_allbuf_opt);
11175}
11176
11177/*
11178 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11179 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011180 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011181check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011182{
11183#ifdef FEAT_FOLDING
11184 check_string_option(&wop->wo_fdi);
11185 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011186 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187# ifdef FEAT_EVAL
11188 check_string_option(&wop->wo_fde);
11189 check_string_option(&wop->wo_fdt);
11190# endif
11191 check_string_option(&wop->wo_fmr);
11192#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011193#ifdef FEAT_SIGNS
11194 check_string_option(&wop->wo_scl);
11195#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011196#ifdef FEAT_RIGHTLEFT
11197 check_string_option(&wop->wo_rlc);
11198#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011199#ifdef FEAT_STL_OPT
11200 check_string_option(&wop->wo_stl);
11201#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011202#ifdef FEAT_SYN_HL
11203 check_string_option(&wop->wo_cc);
11204#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011205#ifdef FEAT_CONCEAL
11206 check_string_option(&wop->wo_cocu);
11207#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011208#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011209 check_string_option(&wop->wo_twk);
11210 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011211#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011212#ifdef FEAT_LINEBREAK
11213 check_string_option(&wop->wo_briopt);
11214#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011215}
11216
11217/*
11218 * Free the allocated memory inside a winopt_T.
11219 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011220 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011221clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011222{
11223#ifdef FEAT_FOLDING
11224 clear_string_option(&wop->wo_fdi);
11225 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011226 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011227# ifdef FEAT_EVAL
11228 clear_string_option(&wop->wo_fde);
11229 clear_string_option(&wop->wo_fdt);
11230# endif
11231 clear_string_option(&wop->wo_fmr);
11232#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011233#ifdef FEAT_SIGNS
11234 clear_string_option(&wop->wo_scl);
11235#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011236#ifdef FEAT_LINEBREAK
11237 clear_string_option(&wop->wo_briopt);
11238#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011239#ifdef FEAT_RIGHTLEFT
11240 clear_string_option(&wop->wo_rlc);
11241#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011242#ifdef FEAT_STL_OPT
11243 clear_string_option(&wop->wo_stl);
11244#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011245#ifdef FEAT_SYN_HL
11246 clear_string_option(&wop->wo_cc);
11247#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011248#ifdef FEAT_CONCEAL
11249 clear_string_option(&wop->wo_cocu);
11250#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011251#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011252 clear_string_option(&wop->wo_twk);
11253 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011254#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011255}
11256
11257/*
11258 * Copy global option values to local options for one buffer.
11259 * Used when creating a new buffer and sometimes when entering a buffer.
11260 * flags:
11261 * BCO_ENTER We will enter the buf buffer.
11262 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11263 * appropriate.
11264 * BCO_NOHELP Don't copy the values to a help buffer.
11265 */
11266 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011267buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011268{
11269 int should_copy = TRUE;
11270 char_u *save_p_isk = NULL; /* init for GCC */
11271 int dont_do_help;
11272 int did_isk = FALSE;
11273
11274 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011275 * Skip this when the option defaults have not been set yet. Happens when
11276 * main() allocates the first buffer.
11277 */
11278 if (p_cpo != NULL)
11279 {
11280 /*
11281 * Always copy when entering and 'cpo' contains 'S'.
11282 * Don't copy when already initialized.
11283 * Don't copy when 'cpo' contains 's' and not entering.
11284 * 'S' BCO_ENTER initialized 's' should_copy
11285 * yes yes X X TRUE
11286 * yes no yes X FALSE
11287 * no X yes X FALSE
11288 * X no no yes FALSE
11289 * X no no no TRUE
11290 * no yes no X TRUE
11291 */
11292 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11293 && (buf->b_p_initialized
11294 || (!(flags & BCO_ENTER)
11295 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11296 should_copy = FALSE;
11297
11298 if (should_copy || (flags & BCO_ALWAYS))
11299 {
11300 /* Don't copy the options specific to a help buffer when
11301 * BCO_NOHELP is given or the options were initialized already
11302 * (jumping back to a help file with CTRL-T or CTRL-O) */
11303 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11304 || buf->b_p_initialized;
11305 if (dont_do_help) /* don't free b_p_isk */
11306 {
11307 save_p_isk = buf->b_p_isk;
11308 buf->b_p_isk = NULL;
11309 }
11310 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011311 * Always free the allocated strings. If not already initialized,
11312 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011313 */
11314 if (!buf->b_p_initialized)
11315 {
11316 free_buf_options(buf, TRUE);
11317 buf->b_p_ro = FALSE; /* don't copy readonly */
11318 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011319 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011320 switch (*p_ffs)
11321 {
11322 case 'm':
11323 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11324 case 'd':
11325 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11326 case 'u':
11327 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11328 default:
11329 buf->b_p_ff = vim_strsave(p_ff);
11330 }
11331 if (buf->b_p_ff != NULL)
11332 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011333 buf->b_p_bh = empty_option;
11334 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011335 }
11336 else
11337 free_buf_options(buf, FALSE);
11338
11339 buf->b_p_ai = p_ai;
11340 buf->b_p_ai_nopaste = p_ai_nopaste;
11341 buf->b_p_sw = p_sw;
11342 buf->b_p_tw = p_tw;
11343 buf->b_p_tw_nopaste = p_tw_nopaste;
11344 buf->b_p_tw_nobin = p_tw_nobin;
11345 buf->b_p_wm = p_wm;
11346 buf->b_p_wm_nopaste = p_wm_nopaste;
11347 buf->b_p_wm_nobin = p_wm_nobin;
11348 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011349 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011350 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011351 buf->b_p_et = p_et;
11352 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011353 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011354 buf->b_p_ml = p_ml;
11355 buf->b_p_ml_nobin = p_ml_nobin;
11356 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011357 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011358#ifdef FEAT_INS_EXPAND
11359 buf->b_p_cpt = vim_strsave(p_cpt);
11360#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011361#ifdef FEAT_COMPL_FUNC
11362 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011363 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011364#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011365#ifdef FEAT_EVAL
11366 buf->b_p_tfu = vim_strsave(p_tfu);
11367#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011368 buf->b_p_sts = p_sts;
11369 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011370#ifdef FEAT_VARTABS
11371 buf->b_p_vsts = vim_strsave(p_vsts);
11372 if (p_vsts && p_vsts != empty_option)
11373 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11374 else
11375 buf->b_p_vsts_array = 0;
11376 buf->b_p_vsts_nopaste = p_vsts_nopaste
11377 ? vim_strsave(p_vsts_nopaste) : NULL;
11378#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011380#ifdef FEAT_COMMENTS
11381 buf->b_p_com = vim_strsave(p_com);
11382#endif
11383#ifdef FEAT_FOLDING
11384 buf->b_p_cms = vim_strsave(p_cms);
11385#endif
11386 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011387 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388 buf->b_p_nf = vim_strsave(p_nf);
11389 buf->b_p_mps = vim_strsave(p_mps);
11390#ifdef FEAT_SMARTINDENT
11391 buf->b_p_si = p_si;
11392#endif
11393 buf->b_p_ci = p_ci;
11394#ifdef FEAT_CINDENT
11395 buf->b_p_cin = p_cin;
11396 buf->b_p_cink = vim_strsave(p_cink);
11397 buf->b_p_cino = vim_strsave(p_cino);
11398#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011399 /* Don't copy 'filetype', it must be detected */
11400 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011401 buf->b_p_pi = p_pi;
11402#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11403 buf->b_p_cinw = vim_strsave(p_cinw);
11404#endif
11405#ifdef FEAT_LISP
11406 buf->b_p_lisp = p_lisp;
11407#endif
11408#ifdef FEAT_SYN_HL
11409 /* Don't copy 'syntax', it must be set */
11410 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011411 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011412 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011413#endif
11414#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011415 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011416 (void)compile_cap_prog(&buf->b_s);
11417 buf->b_s.b_p_spf = vim_strsave(p_spf);
11418 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419#endif
11420#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11421 buf->b_p_inde = vim_strsave(p_inde);
11422 buf->b_p_indk = vim_strsave(p_indk);
11423#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011424 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011425#if defined(FEAT_EVAL)
11426 buf->b_p_fex = vim_strsave(p_fex);
11427#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428#ifdef FEAT_CRYPT
11429 buf->b_p_key = vim_strsave(p_key);
11430#endif
11431#ifdef FEAT_SEARCHPATH
11432 buf->b_p_sua = vim_strsave(p_sua);
11433#endif
11434#ifdef FEAT_KEYMAP
11435 buf->b_p_keymap = vim_strsave(p_keymap);
11436 buf->b_kmap_state |= KEYMAP_INIT;
11437#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011438#ifdef FEAT_TERMINAL
11439 buf->b_p_twsl = p_twsl;
11440#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011441 /* This isn't really an option, but copying the langmap and IME
11442 * state from the current buffer is better than resetting it. */
11443 buf->b_p_iminsert = p_iminsert;
11444 buf->b_p_imsearch = p_imsearch;
11445
11446 /* options that are normally global but also have a local value
11447 * are not copied, start using the global value */
11448 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011449 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011450 buf->b_p_bkc = empty_option;
11451 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011452#ifdef FEAT_QUICKFIX
11453 buf->b_p_gp = empty_option;
11454 buf->b_p_mp = empty_option;
11455 buf->b_p_efm = empty_option;
11456#endif
11457 buf->b_p_ep = empty_option;
11458 buf->b_p_kp = empty_option;
11459 buf->b_p_path = empty_option;
11460 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011461 buf->b_p_tc = empty_option;
11462 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011463#ifdef FEAT_FIND_ID
11464 buf->b_p_def = empty_option;
11465 buf->b_p_inc = empty_option;
11466# ifdef FEAT_EVAL
11467 buf->b_p_inex = vim_strsave(p_inex);
11468# endif
11469#endif
11470#ifdef FEAT_INS_EXPAND
11471 buf->b_p_dict = empty_option;
11472 buf->b_p_tsr = empty_option;
11473#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011474#ifdef FEAT_TEXTOBJ
11475 buf->b_p_qe = vim_strsave(p_qe);
11476#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011477#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11478 buf->b_p_bexpr = empty_option;
11479#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011480#if defined(FEAT_CRYPT)
11481 buf->b_p_cm = empty_option;
11482#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011483#ifdef FEAT_PERSISTENT_UNDO
11484 buf->b_p_udf = p_udf;
11485#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011486#ifdef FEAT_LISP
11487 buf->b_p_lw = empty_option;
11488#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011489 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011490
11491 /*
11492 * Don't copy the options set by ex_help(), use the saved values,
11493 * when going from a help buffer to a non-help buffer.
11494 * Don't touch these at all when BCO_NOHELP is used and going from
11495 * or to a help buffer.
11496 */
11497 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011498 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011499 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011500#ifdef FEAT_VARTABS
11501 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11502 tabstop_set(p_vts, &buf->b_p_vts_array);
11503 else
11504 buf->b_p_vts_array = NULL;
11505#endif
11506 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011507 else
11508 {
11509 buf->b_p_isk = vim_strsave(p_isk);
11510 did_isk = TRUE;
11511 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011512#ifdef FEAT_VARTABS
11513 buf->b_p_vts = vim_strsave(p_vts);
11514 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11515 tabstop_set(p_vts, &buf->b_p_vts_array);
11516 else
11517 buf->b_p_vts_array = NULL;
11518#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011519 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011520 if (buf->b_p_bt[0] == 'h')
11521 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011522 buf->b_p_ma = p_ma;
11523 }
11524 }
11525
11526 /*
11527 * When the options should be copied (ignoring BCO_ALWAYS), set the
11528 * flag that indicates that the options have been initialized.
11529 */
11530 if (should_copy)
11531 buf->b_p_initialized = TRUE;
11532 }
11533
11534 check_buf_options(buf); /* make sure we don't have NULLs */
11535 if (did_isk)
11536 (void)buf_init_chartab(buf, FALSE);
11537}
11538
11539/*
11540 * Reset the 'modifiable' option and its default value.
11541 */
11542 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011543reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011544{
11545 int opt_idx;
11546
11547 curbuf->b_p_ma = FALSE;
11548 p_ma = FALSE;
11549 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011550 if (opt_idx >= 0)
11551 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011552}
11553
11554/*
11555 * Set the global value for 'iminsert' to the local value.
11556 */
11557 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011558set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011559{
11560 p_iminsert = curbuf->b_p_iminsert;
11561}
11562
11563/*
11564 * Set the global value for 'imsearch' to the local value.
11565 */
11566 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011567set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011568{
11569 p_imsearch = curbuf->b_p_imsearch;
11570}
11571
11572#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11573static int expand_option_idx = -1;
11574static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11575static int expand_option_flags = 0;
11576
11577 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011578set_context_in_set_cmd(
11579 expand_T *xp,
11580 char_u *arg,
11581 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011582{
11583 int nextchar;
11584 long_u flags = 0; /* init for GCC */
11585 int opt_idx = 0; /* init for GCC */
11586 char_u *p;
11587 char_u *s;
11588 int is_term_option = FALSE;
11589 int key;
11590
11591 expand_option_flags = opt_flags;
11592
11593 xp->xp_context = EXPAND_SETTINGS;
11594 if (*arg == NUL)
11595 {
11596 xp->xp_pattern = arg;
11597 return;
11598 }
11599 p = arg + STRLEN(arg) - 1;
11600 if (*p == ' ' && *(p - 1) != '\\')
11601 {
11602 xp->xp_pattern = p + 1;
11603 return;
11604 }
11605 while (p > arg)
11606 {
11607 s = p;
11608 /* count number of backslashes before ' ' or ',' */
11609 if (*p == ' ' || *p == ',')
11610 {
11611 while (s > arg && *(s - 1) == '\\')
11612 --s;
11613 }
11614 /* break at a space with an even number of backslashes */
11615 if (*p == ' ' && ((p - s) & 1) == 0)
11616 {
11617 ++p;
11618 break;
11619 }
11620 --p;
11621 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011622 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623 {
11624 xp->xp_context = EXPAND_BOOL_SETTINGS;
11625 p += 2;
11626 }
11627 if (STRNCMP(p, "inv", 3) == 0)
11628 {
11629 xp->xp_context = EXPAND_BOOL_SETTINGS;
11630 p += 3;
11631 }
11632 xp->xp_pattern = arg = p;
11633 if (*arg == '<')
11634 {
11635 while (*p != '>')
11636 if (*p++ == NUL) /* expand terminal option name */
11637 return;
11638 key = get_special_key_code(arg + 1);
11639 if (key == 0) /* unknown name */
11640 {
11641 xp->xp_context = EXPAND_NOTHING;
11642 return;
11643 }
11644 nextchar = *++p;
11645 is_term_option = TRUE;
11646 expand_option_name[2] = KEY2TERMCAP0(key);
11647 expand_option_name[3] = KEY2TERMCAP1(key);
11648 }
11649 else
11650 {
11651 if (p[0] == 't' && p[1] == '_')
11652 {
11653 p += 2;
11654 if (*p != NUL)
11655 ++p;
11656 if (*p == NUL)
11657 return; /* expand option name */
11658 nextchar = *++p;
11659 is_term_option = TRUE;
11660 expand_option_name[2] = p[-2];
11661 expand_option_name[3] = p[-1];
11662 }
11663 else
11664 {
11665 /* Allow * wildcard */
11666 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11667 p++;
11668 if (*p == NUL)
11669 return;
11670 nextchar = *p;
11671 *p = NUL;
11672 opt_idx = findoption(arg);
11673 *p = nextchar;
11674 if (opt_idx == -1 || options[opt_idx].var == NULL)
11675 {
11676 xp->xp_context = EXPAND_NOTHING;
11677 return;
11678 }
11679 flags = options[opt_idx].flags;
11680 if (flags & P_BOOL)
11681 {
11682 xp->xp_context = EXPAND_NOTHING;
11683 return;
11684 }
11685 }
11686 }
11687 /* handle "-=" and "+=" */
11688 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11689 {
11690 ++p;
11691 nextchar = '=';
11692 }
11693 if ((nextchar != '=' && nextchar != ':')
11694 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11695 {
11696 xp->xp_context = EXPAND_UNSUCCESSFUL;
11697 return;
11698 }
11699 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11700 {
11701 xp->xp_context = EXPAND_OLD_SETTING;
11702 if (is_term_option)
11703 expand_option_idx = -1;
11704 else
11705 expand_option_idx = opt_idx;
11706 xp->xp_pattern = p + 1;
11707 return;
11708 }
11709 xp->xp_context = EXPAND_NOTHING;
11710 if (is_term_option || (flags & P_NUM))
11711 return;
11712
11713 xp->xp_pattern = p + 1;
11714
11715 if (flags & P_EXPAND)
11716 {
11717 p = options[opt_idx].var;
11718 if (p == (char_u *)&p_bdir
11719 || p == (char_u *)&p_dir
11720 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011721 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011722 || p == (char_u *)&p_rtp
11723#ifdef FEAT_SEARCHPATH
11724 || p == (char_u *)&p_cdpath
11725#endif
11726#ifdef FEAT_SESSION
11727 || p == (char_u *)&p_vdir
11728#endif
11729 )
11730 {
11731 xp->xp_context = EXPAND_DIRECTORIES;
11732 if (p == (char_u *)&p_path
11733#ifdef FEAT_SEARCHPATH
11734 || p == (char_u *)&p_cdpath
11735#endif
11736 )
11737 xp->xp_backslash = XP_BS_THREE;
11738 else
11739 xp->xp_backslash = XP_BS_ONE;
11740 }
11741 else
11742 {
11743 xp->xp_context = EXPAND_FILES;
11744 /* for 'tags' need three backslashes for a space */
11745 if (p == (char_u *)&p_tags)
11746 xp->xp_backslash = XP_BS_THREE;
11747 else
11748 xp->xp_backslash = XP_BS_ONE;
11749 }
11750 }
11751
11752 /* For an option that is a list of file names, find the start of the
11753 * last file name. */
11754 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11755 {
11756 /* count number of backslashes before ' ' or ',' */
11757 if (*p == ' ' || *p == ',')
11758 {
11759 s = p;
11760 while (s > xp->xp_pattern && *(s - 1) == '\\')
11761 --s;
11762 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11763 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11764 {
11765 xp->xp_pattern = p + 1;
11766 break;
11767 }
11768 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011769
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011770#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011771 /* for 'spellsuggest' start at "file:" */
11772 if (options[opt_idx].var == (char_u *)&p_sps
11773 && STRNCMP(p, "file:", 5) == 0)
11774 {
11775 xp->xp_pattern = p + 5;
11776 break;
11777 }
11778#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011779 }
11780
11781 return;
11782}
11783
11784 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011785ExpandSettings(
11786 expand_T *xp,
11787 regmatch_T *regmatch,
11788 int *num_file,
11789 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011790{
11791 int num_normal = 0; /* Nr of matching non-term-code settings */
11792 int num_term = 0; /* Nr of matching terminal code settings */
11793 int opt_idx;
11794 int match;
11795 int count = 0;
11796 char_u *str;
11797 int loop;
11798 int is_term_opt;
11799 char_u name_buf[MAX_KEY_NAME_LEN];
11800 static char *(names[]) = {"all", "termcap"};
11801 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11802
11803 /* do this loop twice:
11804 * loop == 0: count the number of matching options
11805 * loop == 1: copy the matching options into allocated memory
11806 */
11807 for (loop = 0; loop <= 1; ++loop)
11808 {
11809 regmatch->rm_ic = ic;
11810 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11811 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011812 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11813 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011814 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11815 {
11816 if (loop == 0)
11817 num_normal++;
11818 else
11819 (*file)[count++] = vim_strsave((char_u *)names[match]);
11820 }
11821 }
11822 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11823 opt_idx++)
11824 {
11825 if (options[opt_idx].var == NULL)
11826 continue;
11827 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11828 && !(options[opt_idx].flags & P_BOOL))
11829 continue;
11830 is_term_opt = istermoption(&options[opt_idx]);
11831 if (is_term_opt && num_normal > 0)
11832 continue;
11833 match = FALSE;
11834 if (vim_regexec(regmatch, str, (colnr_T)0)
11835 || (options[opt_idx].shortname != NULL
11836 && vim_regexec(regmatch,
11837 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11838 match = TRUE;
11839 else if (is_term_opt)
11840 {
11841 name_buf[0] = '<';
11842 name_buf[1] = 't';
11843 name_buf[2] = '_';
11844 name_buf[3] = str[2];
11845 name_buf[4] = str[3];
11846 name_buf[5] = '>';
11847 name_buf[6] = NUL;
11848 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11849 {
11850 match = TRUE;
11851 str = name_buf;
11852 }
11853 }
11854 if (match)
11855 {
11856 if (loop == 0)
11857 {
11858 if (is_term_opt)
11859 num_term++;
11860 else
11861 num_normal++;
11862 }
11863 else
11864 (*file)[count++] = vim_strsave(str);
11865 }
11866 }
11867 /*
11868 * Check terminal key codes, these are not in the option table
11869 */
11870 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11871 {
11872 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11873 {
11874 if (!isprint(str[0]) || !isprint(str[1]))
11875 continue;
11876
11877 name_buf[0] = 't';
11878 name_buf[1] = '_';
11879 name_buf[2] = str[0];
11880 name_buf[3] = str[1];
11881 name_buf[4] = NUL;
11882
11883 match = FALSE;
11884 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11885 match = TRUE;
11886 else
11887 {
11888 name_buf[0] = '<';
11889 name_buf[1] = 't';
11890 name_buf[2] = '_';
11891 name_buf[3] = str[0];
11892 name_buf[4] = str[1];
11893 name_buf[5] = '>';
11894 name_buf[6] = NUL;
11895
11896 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11897 match = TRUE;
11898 }
11899 if (match)
11900 {
11901 if (loop == 0)
11902 num_term++;
11903 else
11904 (*file)[count++] = vim_strsave(name_buf);
11905 }
11906 }
11907
11908 /*
11909 * Check special key names.
11910 */
11911 regmatch->rm_ic = TRUE; /* ignore case here */
11912 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11913 {
11914 name_buf[0] = '<';
11915 STRCPY(name_buf + 1, str);
11916 STRCAT(name_buf, ">");
11917
11918 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11919 {
11920 if (loop == 0)
11921 num_term++;
11922 else
11923 (*file)[count++] = vim_strsave(name_buf);
11924 }
11925 }
11926 }
11927 if (loop == 0)
11928 {
11929 if (num_normal > 0)
11930 *num_file = num_normal;
11931 else if (num_term > 0)
11932 *num_file = num_term;
11933 else
11934 return OK;
11935 *file = (char_u **)alloc((unsigned)(*num_file * sizeof(char_u *)));
11936 if (*file == NULL)
11937 {
11938 *file = (char_u **)"";
11939 return FAIL;
11940 }
11941 }
11942 }
11943 return OK;
11944}
11945
11946 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011947ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011948{
11949 char_u *var = NULL; /* init for GCC */
11950 char_u *buf;
11951
11952 *num_file = 0;
11953 *file = (char_u **)alloc((unsigned)sizeof(char_u *));
11954 if (*file == NULL)
11955 return FAIL;
11956
11957 /*
11958 * For a terminal key code expand_option_idx is < 0.
11959 */
11960 if (expand_option_idx < 0)
11961 {
11962 var = find_termcode(expand_option_name + 2);
11963 if (var == NULL)
11964 expand_option_idx = findoption(expand_option_name);
11965 }
11966
11967 if (expand_option_idx >= 0)
11968 {
11969 /* put string of option value in NameBuff */
11970 option_value2string(&options[expand_option_idx], expand_option_flags);
11971 var = NameBuff;
11972 }
11973 else if (var == NULL)
11974 var = (char_u *)"";
11975
11976 /* A backslash is required before some characters. This is the reverse of
11977 * what happens in do_set(). */
11978 buf = vim_strsave_escaped(var, escape_chars);
11979
11980 if (buf == NULL)
11981 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011982 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011983 return FAIL;
11984 }
11985
11986#ifdef BACKSLASH_IN_FILENAME
11987 /* For MS-Windows et al. we don't double backslashes at the start and
11988 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011989 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011990 if (var[0] == '\\' && var[1] == '\\'
11991 && expand_option_idx >= 0
11992 && (options[expand_option_idx].flags & P_EXPAND)
11993 && vim_isfilec(var[2])
11994 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011995 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996#endif
11997
11998 *file[0] = buf;
11999 *num_file = 1;
12000 return OK;
12001}
12002#endif
12003
12004/*
12005 * Get the value for the numeric or string option *opp in a nice format into
12006 * NameBuff[]. Must not be called with a hidden option!
12007 */
12008 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012009option_value2string(
12010 struct vimoption *opp,
12011 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012012{
12013 char_u *varp;
12014
12015 varp = get_varp_scope(opp, opt_flags);
12016
12017 if (opp->flags & P_NUM)
12018 {
12019 long wc = 0;
12020
12021 if (wc_use_keyname(varp, &wc))
12022 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12023 else if (wc != 0)
12024 STRCPY(NameBuff, transchar((int)wc));
12025 else
12026 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12027 }
12028 else /* P_STRING */
12029 {
12030 varp = *(char_u **)(varp);
12031 if (varp == NULL) /* just in case */
12032 NameBuff[0] = NUL;
12033#ifdef FEAT_CRYPT
12034 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012035 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036 STRCPY(NameBuff, "*****");
12037#endif
12038 else if (opp->flags & P_EXPAND)
12039 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12040 /* Translate 'pastetoggle' into special key names */
12041 else if ((char_u **)opp->var == &p_pt)
12042 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12043 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012044 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045 }
12046}
12047
12048/*
12049 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12050 * printed as a keyname.
12051 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12052 */
12053 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012054wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055{
12056 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12057 {
12058 *wcp = *(long *)varp;
12059 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12060 return TRUE;
12061 }
12062 return FALSE;
12063}
12064
Bram Moolenaar01615492015-02-03 13:00:38 +010012065#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012066/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012067 * Any character has an equivalent 'langmap' character. This is used for
12068 * keyboards that have a special language mode that sends characters above
12069 * 128 (although other characters can be translated too). The "to" field is a
12070 * Vim command character. This avoids having to switch the keyboard back to
12071 * ASCII mode when leaving Insert mode.
12072 *
12073 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12074 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012075 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12076 * same as langmap_mapchar[] for characters >= 256.
12077 *
12078 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012079 */
12080typedef struct
12081{
12082 int from;
12083 int to;
12084} langmap_entry_T;
12085
12086static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012087
12088/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012089 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12090 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012091 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012092 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012093langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012094{
12095 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012096 int a = 0;
12097 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012098
12099 /* Do a binary search for an existing entry. */
12100 while (a != b)
12101 {
12102 int i = (a + b) / 2;
12103 int d = entries[i].from - from;
12104
12105 if (d == 0)
12106 {
12107 entries[i].to = to;
12108 return;
12109 }
12110 if (d < 0)
12111 a = i + 1;
12112 else
12113 b = i;
12114 }
12115
12116 if (ga_grow(&langmap_mapga, 1) != OK)
12117 return; /* out of memory */
12118
12119 /* insert new entry at position "a" */
12120 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12121 mch_memmove(entries + 1, entries,
12122 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12123 ++langmap_mapga.ga_len;
12124 entries[0].from = from;
12125 entries[0].to = to;
12126}
12127
12128/*
12129 * Apply 'langmap' to multi-byte character "c" and return the result.
12130 */
12131 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012132langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012133{
12134 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12135 int a = 0;
12136 int b = langmap_mapga.ga_len;
12137
12138 while (a != b)
12139 {
12140 int i = (a + b) / 2;
12141 int d = entries[i].from - c;
12142
12143 if (d == 0)
12144 return entries[i].to; /* found matching entry */
12145 if (d < 0)
12146 a = i + 1;
12147 else
12148 b = i;
12149 }
12150 return c; /* no entry found, return "c" unmodified */
12151}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152
12153 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012154langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012155{
12156 int i;
12157
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012158 for (i = 0; i < 256; i++)
12159 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012160 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161}
12162
12163/*
12164 * Called when langmap option is set; the language map can be
12165 * changed at any time!
12166 */
12167 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012168langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012169{
12170 char_u *p;
12171 char_u *p2;
12172 int from, to;
12173
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012174 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012175 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012176
12177 for (p = p_langmap; p[0] != NUL; )
12178 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012179 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012180 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012181 {
12182 if (p2[0] == '\\' && p2[1] != NUL)
12183 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012184 }
12185 if (p2[0] == ';')
12186 ++p2; /* abcd;ABCD form, p2 points to A */
12187 else
12188 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12189 while (p[0])
12190 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012191 if (p[0] == ',')
12192 {
12193 ++p;
12194 break;
12195 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012196 if (p[0] == '\\' && p[1] != NUL)
12197 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012198 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012199 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012200 if (p2 == NULL)
12201 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012202 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012203 if (p[0] != ',')
12204 {
12205 if (p[0] == '\\')
12206 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012207 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012208 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209 }
12210 else
12211 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012212 if (p2[0] != ',')
12213 {
12214 if (p2[0] == '\\')
12215 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012216 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012217 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012218 }
12219 if (to == NUL)
12220 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012221 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012222 transchar(from));
12223 return;
12224 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012225
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012226 if (from >= 256)
12227 langmap_set_entry(from, to);
12228 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012229 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012230
12231 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012232 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012233 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012234 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012235 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236 if (*p == ';')
12237 {
12238 p = p2;
12239 if (p[0] != NUL)
12240 {
12241 if (p[0] != ',')
12242 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012243 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012244 return;
12245 }
12246 ++p;
12247 }
12248 break;
12249 }
12250 }
12251 }
12252 }
12253}
12254#endif
12255
12256/*
12257 * Return TRUE if format option 'x' is in effect.
12258 * Take care of no formatting when 'paste' is set.
12259 */
12260 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012261has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012262{
12263 if (p_paste)
12264 return FALSE;
12265 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12266}
12267
12268/*
12269 * Return TRUE if "x" is present in 'shortmess' option, or
12270 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12271 */
12272 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012273shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012274{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012275 return p_shm != NULL &&
12276 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012277 || (vim_strchr(p_shm, 'a') != NULL
12278 && vim_strchr((char_u *)SHM_A, x) != NULL));
12279}
12280
12281/*
12282 * paste_option_changed() - Called after p_paste was set or reset.
12283 */
12284 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012285paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012286{
12287 static int old_p_paste = FALSE;
12288 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012289 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012290#ifdef FEAT_CMDL_INFO
12291 static int save_ru = 0;
12292#endif
12293#ifdef FEAT_RIGHTLEFT
12294 static int save_ri = 0;
12295 static int save_hkmap = 0;
12296#endif
12297 buf_T *buf;
12298
12299 if (p_paste)
12300 {
12301 /*
12302 * Paste switched from off to on.
12303 * Save the current values, so they can be restored later.
12304 */
12305 if (!old_p_paste)
12306 {
12307 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012308 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012309 {
12310 buf->b_p_tw_nopaste = buf->b_p_tw;
12311 buf->b_p_wm_nopaste = buf->b_p_wm;
12312 buf->b_p_sts_nopaste = buf->b_p_sts;
12313 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012314 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012315#ifdef FEAT_VARTABS
12316 if (buf->b_p_vsts_nopaste)
12317 vim_free(buf->b_p_vsts_nopaste);
12318 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12319 ? vim_strsave(buf->b_p_vsts) : NULL;
12320#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012321 }
12322
12323 /* save global options */
12324 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012325 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012326#ifdef FEAT_CMDL_INFO
12327 save_ru = p_ru;
12328#endif
12329#ifdef FEAT_RIGHTLEFT
12330 save_ri = p_ri;
12331 save_hkmap = p_hkmap;
12332#endif
12333 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012334 p_ai_nopaste = p_ai;
12335 p_et_nopaste = p_et;
12336 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012337 p_tw_nopaste = p_tw;
12338 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012339#ifdef FEAT_VARTABS
12340 if (p_vsts_nopaste)
12341 vim_free(p_vsts_nopaste);
12342 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12343#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012344 }
12345
12346 /*
12347 * Always set the option values, also when 'paste' is set when it is
12348 * already on.
12349 */
12350 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012351 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012352 {
12353 buf->b_p_tw = 0; /* textwidth is 0 */
12354 buf->b_p_wm = 0; /* wrapmargin is 0 */
12355 buf->b_p_sts = 0; /* softtabstop is 0 */
12356 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012357 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012358#ifdef FEAT_VARTABS
12359 if (buf->b_p_vsts)
12360 free_string_option(buf->b_p_vsts);
12361 buf->b_p_vsts = empty_option;
12362 if (buf->b_p_vsts_array)
12363 vim_free(buf->b_p_vsts_array);
12364 buf->b_p_vsts_array = 0;
12365#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012366 }
12367
12368 /* set global options */
12369 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012370 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012371#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012372 if (p_ru)
12373 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012374 p_ru = 0; /* no ruler */
12375#endif
12376#ifdef FEAT_RIGHTLEFT
12377 p_ri = 0; /* no reverse insert */
12378 p_hkmap = 0; /* no Hebrew keyboard */
12379#endif
12380 /* set global values for local buffer options */
12381 p_tw = 0;
12382 p_wm = 0;
12383 p_sts = 0;
12384 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012385#ifdef FEAT_VARTABS
12386 if (p_vsts)
12387 free_string_option(p_vsts);
12388 p_vsts = empty_option;
12389#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012390 }
12391
12392 /*
12393 * Paste switched from on to off: Restore saved values.
12394 */
12395 else if (old_p_paste)
12396 {
12397 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012398 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012399 {
12400 buf->b_p_tw = buf->b_p_tw_nopaste;
12401 buf->b_p_wm = buf->b_p_wm_nopaste;
12402 buf->b_p_sts = buf->b_p_sts_nopaste;
12403 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012404 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012405#ifdef FEAT_VARTABS
12406 if (buf->b_p_vsts)
12407 free_string_option(buf->b_p_vsts);
12408 buf->b_p_vsts = buf->b_p_vsts_nopaste
12409 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12410 if (buf->b_p_vsts_array)
12411 vim_free(buf->b_p_vsts_array);
12412 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12413 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12414 else
12415 buf->b_p_vsts_array = 0;
12416#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012417 }
12418
12419 /* restore global options */
12420 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012421 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012422#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012423 if (p_ru != save_ru)
12424 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012425 p_ru = save_ru;
12426#endif
12427#ifdef FEAT_RIGHTLEFT
12428 p_ri = save_ri;
12429 p_hkmap = save_hkmap;
12430#endif
12431 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012432 p_ai = p_ai_nopaste;
12433 p_et = p_et_nopaste;
12434 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012435 p_tw = p_tw_nopaste;
12436 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012437#ifdef FEAT_VARTABS
12438 if (p_vsts)
12439 free_string_option(p_vsts);
12440 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12441#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012442 }
12443
12444 old_p_paste = p_paste;
12445}
12446
12447/*
12448 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12449 *
12450 * Reset 'compatible' and set the values for options that didn't get set yet
12451 * to the Vim defaults.
12452 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012453 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012454 */
12455 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012456vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012457{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012458 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012459 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012460 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012461
12462 if (!option_was_set((char_u *)"cp"))
12463 {
12464 p_cp = FALSE;
12465 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12466 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12467 set_option_default(opt_idx, OPT_FREE, FALSE);
12468 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012469 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012470 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012471
12472 if (fname != NULL)
12473 {
12474 p = vim_getenv(envname, &dofree);
12475 if (p == NULL)
12476 {
12477 /* Set $MYVIMRC to the first vimrc file found. */
12478 p = FullName_save(fname, FALSE);
12479 if (p != NULL)
12480 {
12481 vim_setenv(envname, p);
12482 vim_free(p);
12483 }
12484 }
12485 else if (dofree)
12486 vim_free(p);
12487 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012488}
12489
12490/*
12491 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12492 */
12493 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012494change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012495{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012496 int opt_idx;
12497
Bram Moolenaar071d4272004-06-13 20:20:40 +000012498 if (p_cp != on)
12499 {
12500 p_cp = on;
12501 compatible_set();
12502 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012503 opt_idx = findoption((char_u *)"cp");
12504 if (opt_idx >= 0)
12505 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012506}
12507
12508/*
12509 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012510 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012511 */
12512 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012513option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012514{
12515 int idx;
12516
12517 idx = findoption(name);
12518 if (idx < 0) /* unknown option */
12519 return FALSE;
12520 if (options[idx].flags & P_WAS_SET)
12521 return TRUE;
12522 return FALSE;
12523}
12524
12525/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012526 * Reset the flag indicating option "name" was set.
12527 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012528 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012529reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012530{
12531 int idx = findoption(name);
12532
12533 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012534 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012535 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012536 return OK;
12537 }
12538 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012539}
12540
12541/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012542 * compatible_set() - Called when 'compatible' has been set or unset.
12543 *
12544 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12545 * flag) to a Vi compatible value.
12546 * When 'compatible' is unset: Set all options that have a different default
12547 * for Vim (without the P_VI_DEF flag) to that default.
12548 */
12549 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012550compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012551{
12552 int opt_idx;
12553
12554 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12555 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12556 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12557 set_option_default(opt_idx, OPT_FREE, p_cp);
12558 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012559 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012560}
12561
12562#ifdef FEAT_LINEBREAK
12563
12564# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
12565 /* Borland C++ screws up loop optimisation here (negri) */
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012566 #pragma option -O-l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012567# endif
12568
12569/*
12570 * fill_breakat_flags() -- called when 'breakat' changes value.
12571 */
12572 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012573fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012574{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012575 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012576 int i;
12577
12578 for (i = 0; i < 256; i++)
12579 breakat_flags[i] = FALSE;
12580
12581 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012582 for (p = p_breakat; *p; p++)
12583 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012584}
12585
12586# if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
Bram Moolenaar8f999f12005-01-25 22:12:55 +000012587 #pragma option -O.l
Bram Moolenaar071d4272004-06-13 20:20:40 +000012588# endif
12589
12590#endif
12591
12592/*
12593 * Check an option that can be a range of string values.
12594 *
12595 * Return OK for correct value, FAIL otherwise.
12596 * Empty is always OK.
12597 */
12598 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012599check_opt_strings(
12600 char_u *val,
12601 char **values,
12602 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012603{
12604 return opt_strings_flags(val, values, NULL, list);
12605}
12606
12607/*
12608 * Handle an option that can be a range of string values.
12609 * Set a flag in "*flagp" for each string present.
12610 *
12611 * Return OK for correct value, FAIL otherwise.
12612 * Empty is always OK.
12613 */
12614 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012615opt_strings_flags(
12616 char_u *val, /* new value */
12617 char **values, /* array of valid string values */
12618 unsigned *flagp,
12619 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012620{
12621 int i;
12622 int len;
12623 unsigned new_flags = 0;
12624
12625 while (*val)
12626 {
12627 for (i = 0; ; ++i)
12628 {
12629 if (values[i] == NULL) /* val not found in values[] */
12630 return FAIL;
12631
12632 len = (int)STRLEN(values[i]);
12633 if (STRNCMP(values[i], val, len) == 0
12634 && ((list && val[len] == ',') || val[len] == NUL))
12635 {
12636 val += len + (val[len] == ',');
12637 new_flags |= (1 << i);
12638 break; /* check next item in val list */
12639 }
12640 }
12641 }
12642 if (flagp != NULL)
12643 *flagp = new_flags;
12644
12645 return OK;
12646}
12647
12648/*
12649 * Read the 'wildmode' option, fill wim_flags[].
12650 */
12651 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012652check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012653{
12654 char_u new_wim_flags[4];
12655 char_u *p;
12656 int i;
12657 int idx = 0;
12658
12659 for (i = 0; i < 4; ++i)
12660 new_wim_flags[i] = 0;
12661
12662 for (p = p_wim; *p; ++p)
12663 {
12664 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12665 ;
12666 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12667 return FAIL;
12668 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12669 new_wim_flags[idx] |= WIM_LONGEST;
12670 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12671 new_wim_flags[idx] |= WIM_FULL;
12672 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12673 new_wim_flags[idx] |= WIM_LIST;
12674 else
12675 return FAIL;
12676 p += i;
12677 if (*p == NUL)
12678 break;
12679 if (*p == ',')
12680 {
12681 if (idx == 3)
12682 return FAIL;
12683 ++idx;
12684 }
12685 }
12686
12687 /* fill remaining entries with last flag */
12688 while (idx < 3)
12689 {
12690 new_wim_flags[idx + 1] = new_wim_flags[idx];
12691 ++idx;
12692 }
12693
12694 /* only when there are no errors, wim_flags[] is changed */
12695 for (i = 0; i < 4; ++i)
12696 wim_flags[i] = new_wim_flags[i];
12697 return OK;
12698}
12699
12700/*
12701 * Check if backspacing over something is allowed.
12702 */
12703 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012704can_bs(
12705 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012706{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012707#ifdef FEAT_JOB_CHANNEL
12708 if (what == BS_START && bt_prompt(curbuf))
12709 return FALSE;
12710#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012711 switch (*p_bs)
12712 {
12713 case '2': return TRUE;
12714 case '1': return (what != BS_START);
12715 case '0': return FALSE;
12716 }
12717 return vim_strchr(p_bs, what) != NULL;
12718}
12719
12720/*
12721 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12722 * the file must be considered changed when the value is different.
12723 */
12724 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012725save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012726{
12727 buf->b_start_ffc = *buf->b_p_ff;
12728 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012729 buf->b_start_bomb = buf->b_p_bomb;
12730
Bram Moolenaar071d4272004-06-13 20:20:40 +000012731 /* Only use free/alloc when necessary, they take time. */
12732 if (buf->b_start_fenc == NULL
12733 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12734 {
12735 vim_free(buf->b_start_fenc);
12736 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12737 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012738}
12739
12740/*
12741 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12742 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012743 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12744 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012745 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012746 * When "ignore_empty" is true don't consider a new, empty buffer to be
12747 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012748 */
12749 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012750file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012751{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012752 /* In a buffer that was never loaded the options are not valid. */
12753 if (buf->b_flags & BF_NEVERLOADED)
12754 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012755 if (ignore_empty
12756 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012757 && buf->b_ml.ml_line_count == 1
12758 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12759 return FALSE;
12760 if (buf->b_start_ffc != *buf->b_p_ff)
12761 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012762 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012763 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012764 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12765 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012766 if (buf->b_start_fenc == NULL)
12767 return (*buf->b_p_fenc != NUL);
12768 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012769}
12770
12771/*
12772 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12773 */
12774 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012775check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012776{
12777 return check_opt_strings(p, p_ff_values, FALSE);
12778}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012779
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012780#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012781
12782/*
12783 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012784 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012785 */
12786 int
12787tabstop_set(char_u *var, int **array)
12788{
12789 int valcount = 1;
12790 int t;
12791 char_u *cp;
12792
Bram Moolenaar64f41072018-10-15 22:51:50 +020012793 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012794 {
12795 *array = NULL;
12796 return TRUE;
12797 }
12798
Bram Moolenaar64f41072018-10-15 22:51:50 +020012799 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012800 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020012801 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012802 {
12803 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012804
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012805 if (strtol((char *)cp, (char **)&end, 10) <= 0)
12806 {
12807 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012808 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012809 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012810 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012811 return FALSE;
12812 }
12813 }
12814
12815 if (VIM_ISDIGIT(*cp))
12816 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012817 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012818 {
12819 ++valcount;
12820 continue;
12821 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012822 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012823 return FALSE;
12824 }
12825
Bram Moolenaar64f41072018-10-15 22:51:50 +020012826 *array = (int *)alloc((unsigned) ((valcount + 1) * sizeof(int)));
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010012827 if (*array == NULL)
12828 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012829 (*array)[0] = valcount;
12830
12831 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012832 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012833 {
12834 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020012835 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012836 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020012837 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012838 ++cp;
12839 }
12840
12841 return TRUE;
12842}
12843
12844/*
12845 * Calculate the number of screen spaces a tab will occupy.
12846 * If "vts" is set then the tab widths are taken from that array,
12847 * otherwise the value of ts is used.
12848 */
12849 int
12850tabstop_padding(colnr_T col, int ts_arg, int *vts)
12851{
12852 int ts = ts_arg == 0 ? 8 : ts_arg;
12853 int tabcount;
12854 colnr_T tabcol = 0;
12855 int t;
12856 int padding = 0;
12857
12858 if (vts == NULL || vts[0] == 0)
12859 return ts - (col % ts);
12860
12861 tabcount = vts[0];
12862
12863 for (t = 1; t <= tabcount; ++t)
12864 {
12865 tabcol += vts[t];
12866 if (tabcol > col)
12867 {
12868 padding = (int)(tabcol - col);
12869 break;
12870 }
12871 }
12872 if (t > tabcount)
12873 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
12874
12875 return padding;
12876}
12877
12878/*
12879 * Find the size of the tab that covers a particular column.
12880 */
12881 int
12882tabstop_at(colnr_T col, int ts, int *vts)
12883{
12884 int tabcount;
12885 colnr_T tabcol = 0;
12886 int t;
12887 int tab_size = 0;
12888
12889 if (vts == 0 || vts[0] == 0)
12890 return ts;
12891
12892 tabcount = vts[0];
12893 for (t = 1; t <= tabcount; ++t)
12894 {
12895 tabcol += vts[t];
12896 if (tabcol > col)
12897 {
12898 tab_size = vts[t];
12899 break;
12900 }
12901 }
12902 if (t > tabcount)
12903 tab_size = vts[tabcount];
12904
12905 return tab_size;
12906}
12907
12908/*
12909 * Find the column on which a tab starts.
12910 */
12911 colnr_T
12912tabstop_start(colnr_T col, int ts, int *vts)
12913{
12914 int tabcount;
12915 colnr_T tabcol = 0;
12916 int t;
12917 int excess;
12918
Bram Moolenaar0119a592018-06-24 23:53:28 +020012919 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012920 return (col / ts) * ts;
12921
12922 tabcount = vts[0];
12923 for (t = 1; t <= tabcount; ++t)
12924 {
12925 tabcol += vts[t];
12926 if (tabcol > col)
12927 return tabcol - vts[t];
12928 }
12929
12930 excess = tabcol % vts[tabcount];
12931 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
12932}
12933
12934/*
12935 * Find the number of tabs and spaces necessary to get from one column
12936 * to another.
12937 */
12938 void
12939tabstop_fromto(
12940 colnr_T start_col,
12941 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012942 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012943 int *vts,
12944 int *ntabs,
12945 int *nspcs)
12946{
12947 int spaces = end_col - start_col;
12948 colnr_T tabcol = 0;
12949 int padding = 0;
12950 int tabcount;
12951 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012952 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012953
Bram Moolenaar0119a592018-06-24 23:53:28 +020012954 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012955 {
12956 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012957 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020012958
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020012959 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012960 if (spaces >= initspc)
12961 {
12962 spaces -= initspc;
12963 tabs++;
12964 }
12965 tabs += spaces / ts;
12966 spaces -= (spaces / ts) * ts;
12967
12968 *ntabs = tabs;
12969 *nspcs = spaces;
12970 return;
12971 }
12972
12973 /* Find the padding needed to reach the next tabstop. */
12974 tabcount = vts[0];
12975 for (t = 1; t <= tabcount; ++t)
12976 {
12977 tabcol += vts[t];
12978 if (tabcol > start_col)
12979 {
12980 padding = (int)(tabcol - start_col);
12981 break;
12982 }
12983 }
12984 if (t > tabcount)
12985 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
12986
12987 /* If the space needed is less than the padding no tabs can be used. */
12988 if (spaces < padding)
12989 {
12990 *ntabs = 0;
12991 *nspcs = spaces;
12992 return;
12993 }
12994
12995 *ntabs = 1;
12996 spaces -= padding;
12997
12998 /* At least one tab has been used. See if any more will fit. */
12999 while (spaces != 0 && ++t <= tabcount)
13000 {
13001 padding = vts[t];
13002 if (spaces < padding)
13003 {
13004 *nspcs = spaces;
13005 return;
13006 }
13007 ++*ntabs;
13008 spaces -= padding;
13009 }
13010
13011 *ntabs += spaces / vts[tabcount];
13012 *nspcs = spaces % vts[tabcount];
13013}
13014
13015/*
13016 * See if two tabstop arrays contain the same values.
13017 */
13018 int
13019tabstop_eq(int *ts1, int *ts2)
13020{
13021 int t;
13022
13023 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13024 return FALSE;
13025 if (ts1 == ts2)
13026 return TRUE;
13027 if (ts1[0] != ts2[0])
13028 return FALSE;
13029
13030 for (t = 1; t <= ts1[0]; ++t)
13031 if (ts1[t] != ts2[t])
13032 return FALSE;
13033
13034 return TRUE;
13035}
13036
Bram Moolenaar113e1072019-01-20 15:30:40 +010013037#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013038/*
13039 * Copy a tabstop array, allocating space for the new array.
13040 */
13041 int *
13042tabstop_copy(int *oldts)
13043{
13044 int *newts;
13045 int t;
13046
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013047 if (oldts == NULL)
13048 return NULL;
13049 newts = (int *)alloc((unsigned)((oldts[0] + 1) * sizeof(int)));
13050 if (newts != NULL)
13051 for (t = 0; t <= oldts[0]; ++t)
13052 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013053 return newts;
13054}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013055#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013056
13057/*
13058 * Return a count of the number of tabstops.
13059 */
13060 int
13061tabstop_count(int *ts)
13062{
13063 return ts != NULL ? ts[0] : 0;
13064}
13065
13066/*
13067 * Return the first tabstop, or 8 if there are no tabstops defined.
13068 */
13069 int
13070tabstop_first(int *ts)
13071{
13072 return ts != NULL ? ts[1] : 8;
13073}
13074
13075#endif
13076
Bram Moolenaar14f24742012-08-08 18:01:05 +020013077/*
13078 * Return the effective shiftwidth value for current buffer, using the
13079 * 'tabstop' value when 'shiftwidth' is zero.
13080 */
13081 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013082get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013083{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013084 return get_sw_value_col(buf, 0);
13085}
13086
13087/*
13088 * Idem, using the first non-black in the current line.
13089 */
13090 long
13091get_sw_value_indent(buf_T *buf)
13092{
13093 pos_T pos = curwin->w_cursor;
13094
13095 pos.col = getwhitecols_curline();
13096 return get_sw_value_pos(buf, &pos);
13097}
13098
13099/*
13100 * Idem, using "pos".
13101 */
13102 long
13103get_sw_value_pos(buf_T *buf, pos_T *pos)
13104{
13105 pos_T save_cursor = curwin->w_cursor;
13106 long sw_value;
13107
13108 curwin->w_cursor = *pos;
13109 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13110 curwin->w_cursor = save_cursor;
13111 return sw_value;
13112}
13113
13114/*
13115 * Idem, using virtual column "col".
13116 */
13117 long
13118get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13119{
13120 return buf->b_p_sw ? buf->b_p_sw :
13121 #ifdef FEAT_VARTABS
13122 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13123 #else
13124 buf->b_p_ts;
13125 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013126}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013127
13128/*
13129 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013130 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013131 */
13132 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013133get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013134{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013135 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013136}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013137
13138/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013139 * Return the effective 'scrolloff' value for the current window, using the
13140 * global value when appropriate.
13141 */
13142 long
13143get_scrolloff_value(void)
13144{
13145 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13146}
13147
13148/*
13149 * Return the effective 'sidescrolloff' value for the current window, using the
13150 * global value when appropriate.
13151 */
13152 long
13153get_sidescrolloff_value(void)
13154{
13155 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13156}
13157
13158/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013159 * Check matchpairs option for "*initc".
13160 * If there is a match set "*initc" to the matching character and "*findc" to
13161 * the opposite character. Set "*backwards" to the direction.
13162 * When "switchit" is TRUE swap the direction.
13163 */
13164 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013165find_mps_values(
13166 int *initc,
13167 int *findc,
13168 int *backwards,
13169 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013170{
13171 char_u *ptr;
13172
13173 ptr = curbuf->b_p_mps;
13174 while (*ptr != NUL)
13175 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013176 if (has_mbyte)
13177 {
13178 char_u *prev;
13179
13180 if (mb_ptr2char(ptr) == *initc)
13181 {
13182 if (switchit)
13183 {
13184 *findc = *initc;
13185 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13186 *backwards = TRUE;
13187 }
13188 else
13189 {
13190 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13191 *backwards = FALSE;
13192 }
13193 return;
13194 }
13195 prev = ptr;
13196 ptr += mb_ptr2len(ptr) + 1;
13197 if (mb_ptr2char(ptr) == *initc)
13198 {
13199 if (switchit)
13200 {
13201 *findc = *initc;
13202 *initc = mb_ptr2char(prev);
13203 *backwards = FALSE;
13204 }
13205 else
13206 {
13207 *findc = mb_ptr2char(prev);
13208 *backwards = TRUE;
13209 }
13210 return;
13211 }
13212 ptr += mb_ptr2len(ptr);
13213 }
13214 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013215 {
13216 if (*ptr == *initc)
13217 {
13218 if (switchit)
13219 {
13220 *backwards = TRUE;
13221 *findc = *initc;
13222 *initc = ptr[2];
13223 }
13224 else
13225 {
13226 *backwards = FALSE;
13227 *findc = ptr[2];
13228 }
13229 return;
13230 }
13231 ptr += 2;
13232 if (*ptr == *initc)
13233 {
13234 if (switchit)
13235 {
13236 *backwards = FALSE;
13237 *findc = *initc;
13238 *initc = ptr[-2];
13239 }
13240 else
13241 {
13242 *backwards = TRUE;
13243 *findc = ptr[-2];
13244 }
13245 return;
13246 }
13247 ++ptr;
13248 }
13249 if (*ptr == ',')
13250 ++ptr;
13251 }
13252}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013253
13254#if defined(FEAT_LINEBREAK) || defined(PROTO)
13255/*
13256 * This is called when 'breakindentopt' is changed and when a window is
13257 * initialized.
13258 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013259 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013260briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013261{
13262 char_u *p;
13263 int bri_shift = 0;
13264 long bri_min = 20;
13265 int bri_sbr = FALSE;
13266
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013267 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013268 while (*p != NUL)
13269 {
13270 if (STRNCMP(p, "shift:", 6) == 0
13271 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13272 {
13273 p += 6;
13274 bri_shift = getdigits(&p);
13275 }
13276 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13277 {
13278 p += 4;
13279 bri_min = getdigits(&p);
13280 }
13281 else if (STRNCMP(p, "sbr", 3) == 0)
13282 {
13283 p += 3;
13284 bri_sbr = TRUE;
13285 }
13286 if (*p != ',' && *p != NUL)
13287 return FAIL;
13288 if (*p == ',')
13289 ++p;
13290 }
13291
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013292 wp->w_p_brishift = bri_shift;
13293 wp->w_p_brimin = bri_min;
13294 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013295
13296 return OK;
13297}
13298#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013299
13300/*
13301 * Get the local or global value of 'backupcopy'.
13302 */
13303 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013304get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013305{
13306 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13307}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013308
13309#if defined(FEAT_SIGNS) || defined(PROTO)
13310/*
13311 * Return TRUE when window "wp" has a column to draw signs in.
13312 */
13313 int
13314signcolumn_on(win_T *wp)
13315{
13316 if (*wp->w_p_scl == 'n')
13317 return FALSE;
13318 if (*wp->w_p_scl == 'y')
13319 return TRUE;
13320 return (wp->w_buffer->b_signlist != NULL
13321# ifdef FEAT_NETBEANS_INTG
13322 || wp->w_buffer->b_has_sign_column
13323# endif
13324 );
13325}
13326#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013327
13328#if defined(FEAT_EVAL) || defined(PROTO)
13329/*
13330 * Get window or buffer local options.
13331 */
13332 dict_T *
13333get_winbuf_options(int bufopt)
13334{
13335 dict_T *d;
13336 int opt_idx;
13337
13338 d = dict_alloc();
13339 if (d == NULL)
13340 return NULL;
13341
13342 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13343 {
13344 struct vimoption *opt = &options[opt_idx];
13345
13346 if ((bufopt && (opt->indir & PV_BUF))
13347 || (!bufopt && (opt->indir & PV_WIN)))
13348 {
13349 char_u *varp = get_varp(opt);
13350
13351 if (varp != NULL)
13352 {
13353 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013354 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013355 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013356 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013357 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013358 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013359 }
13360 }
13361 }
13362
13363 return d;
13364}
13365#endif