blob: 19c89f7c2cac0d7947560927ccbe0a35a1de4069 [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
Bram Moolenaare2c453d2019-08-21 14:37:09 +020086#define PV_CPT OPT_BUF(BV_CPT)
87#define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
88#define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
Bram Moolenaarac3150d2019-07-28 16:36:39 +020089#define PV_CSL OPT_BUF(BV_CSL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000090#ifdef FEAT_COMPL_FUNC
91# define PV_CFU OPT_BUF(BV_CFU)
92#endif
93#ifdef FEAT_FIND_ID
94# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
95# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
96#endif
97#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +020098#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000099#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
100#define PV_ET OPT_BUF(BV_ET)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100101#define PV_FENC OPT_BUF(BV_FENC)
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000102#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
103# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
104#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100105#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000106#ifdef FEAT_EVAL
107# define PV_FEX OPT_BUF(BV_FEX)
108#endif
109#define PV_FF OPT_BUF(BV_FF)
110#define PV_FLP OPT_BUF(BV_FLP)
111#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100112#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000113#define PV_IMI OPT_BUF(BV_IMI)
114#define PV_IMS OPT_BUF(BV_IMS)
115#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
116# define PV_INDE OPT_BUF(BV_INDE)
117# define PV_INDK OPT_BUF(BV_INDK)
118#endif
119#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
120# define PV_INEX OPT_BUF(BV_INEX)
121#endif
122#define PV_INF OPT_BUF(BV_INF)
123#define PV_ISK OPT_BUF(BV_ISK)
124#ifdef FEAT_CRYPT
125# define PV_KEY OPT_BUF(BV_KEY)
126#endif
127#ifdef FEAT_KEYMAP
128# define PV_KMAP OPT_BUF(BV_KMAP)
129#endif
130#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
131#ifdef FEAT_LISP
132# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100133# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000134#endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100135#define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000136#define PV_MA OPT_BUF(BV_MA)
137#define PV_ML OPT_BUF(BV_ML)
138#define PV_MOD OPT_BUF(BV_MOD)
139#define PV_MPS OPT_BUF(BV_MPS)
140#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000141#ifdef FEAT_COMPL_FUNC
142# define PV_OFU OPT_BUF(BV_OFU)
143#endif
144#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
145#define PV_PI OPT_BUF(BV_PI)
146#ifdef FEAT_TEXTOBJ
147# define PV_QE OPT_BUF(BV_QE)
148#endif
149#define PV_RO OPT_BUF(BV_RO)
150#ifdef FEAT_SMARTINDENT
151# define PV_SI OPT_BUF(BV_SI)
152#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100153#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000154#ifdef FEAT_SYN_HL
155# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000156# define PV_SYN OPT_BUF(BV_SYN)
157#endif
158#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000159# define PV_SPC OPT_BUF(BV_SPC)
160# define PV_SPF OPT_BUF(BV_SPF)
161# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000162#endif
163#define PV_STS OPT_BUF(BV_STS)
164#ifdef FEAT_SEARCHPATH
165# define PV_SUA OPT_BUF(BV_SUA)
166#endif
167#define PV_SW OPT_BUF(BV_SW)
168#define PV_SWF OPT_BUF(BV_SWF)
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200169#ifdef FEAT_EVAL
170# define PV_TFU OPT_BUF(BV_TFU)
171#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000172#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100173#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000174#define PV_TS OPT_BUF(BV_TS)
175#define PV_TW OPT_BUF(BV_TW)
176#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200177#ifdef FEAT_PERSISTENT_UNDO
178# define PV_UDF OPT_BUF(BV_UDF)
179#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000180#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200181#ifdef FEAT_VARTABS
182# define PV_VSTS OPT_BUF(BV_VSTS)
183# define PV_VTS OPT_BUF(BV_VTS)
184#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000185
186/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000187 * Definition of the PV_ values for window-local options.
188 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000189 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190#define PV_LIST OPT_WIN(WV_LIST)
191#ifdef FEAT_ARABIC
192# define PV_ARAB OPT_WIN(WV_ARAB)
193#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200194#ifdef FEAT_LINEBREAK
195# define PV_BRI OPT_WIN(WV_BRI)
196# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
197#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200198# define PV_WCR OPT_WIN(WV_WCR)
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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000302static char_u *p_cpt;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000303#ifdef FEAT_COMPL_FUNC
304static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000305static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200307#ifdef FEAT_EVAL
308static char_u *p_tfu;
309#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200311static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000312static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static char_u *p_ff;
315static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000316static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318static long p_iminsert;
319static long p_imsearch;
320#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
321static char_u *p_inex;
322#endif
323#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
324static char_u *p_inde;
325static char_u *p_indk;
326#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000327#if defined(FEAT_EVAL)
328static char_u *p_fex;
329#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000330static int p_inf;
331static char_u *p_isk;
332#ifdef FEAT_CRYPT
333static char_u *p_key;
334#endif
335#ifdef FEAT_LISP
336static int p_lisp;
337#endif
338static int p_ml;
339static int p_ma;
340static int p_mod;
341static char_u *p_mps;
342static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000343static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000344#ifdef FEAT_TEXTOBJ
345static char_u *p_qe;
346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000347static int p_ro;
348#ifdef FEAT_SMARTINDENT
349static int p_si;
350#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static long p_sts;
353#if defined(FEAT_SEARCHPATH)
354static char_u *p_sua;
355#endif
356static long p_sw;
357static int p_swf;
358#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000359static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000361#endif
362#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000363static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000364static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000365static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000366#endif
367static long p_ts;
368static long p_tw;
369static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200370#ifdef FEAT_PERSISTENT_UNDO
371static int p_udf;
372#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200374#ifdef FEAT_VARTABS
375static char_u *p_vsts;
376static char_u *p_vts;
377#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000378#ifdef FEAT_KEYMAP
379static char_u *p_keymap;
380#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200381#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200382static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000384
385/* Saved values for when 'bin' is set. */
386static int p_et_nobin;
387static int p_ml_nobin;
388static long p_tw_nobin;
389static long p_wm_nobin;
390
391/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200392static int p_ai_nopaste;
393static int p_et_nopaste;
394static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000395static long p_tw_nopaste;
396static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200397#ifdef FEAT_VARTABS
398static char_u *p_vsts_nopaste;
399#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000400
401struct vimoption
402{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200403 char *fullname; // full option name
404 char *shortname; // permissible abbreviation
405 long_u flags; // see below
406 char_u *var; // global option: pointer to variable;
407 // window-local option: VAR_WIN;
408 // buffer-local option: global value
409 idopt_T indir; // global option: PV_NONE;
410 // local option: indirect option index
411 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000412#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200413 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaar558ca4a2019-04-04 18:15:38 +0200414# define SCTX_INIT , {0, 0, 0, 1}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000415#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200416# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000417#endif
418};
419
420#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
421#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
422
423/*
424 * Flags
425 */
426#define P_BOOL 0x01 /* the option is boolean */
427#define P_NUM 0x02 /* the option is numeric */
428#define P_STRING 0x04 /* the option is a string */
429#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000430 must use free_string_option() when
431 assigning new value. Not set if default is
432 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000433#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
434 never be used for local or hidden options! */
435#define P_NODEFAULT 0x40 /* don't set to default value */
436#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
437 use vim_free() when assigning new value */
438#define P_WAS_SET 0x100 /* option has been set/reset */
439#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
440#define P_VI_DEF 0x400 /* Use Vi default for Vim */
441#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
442
443 /* when option changed, what to display: */
444#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100445#define P_RWIN 0x2000 /* redraw current window and recompute text */
446#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000447#define P_RALL 0x6000 /* redraw all windows */
448#define P_RCLR 0x7000 /* clear and redraw all */
449
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200450#define P_COMMA 0x8000 /* comma separated list */
451#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
452 * commas */
453#define P_NODUP 0x20000L /* don't allow duplicate strings */
454#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000455
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200456#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
457#define P_GETTEXT 0x100000L /* expand default value with _() */
458#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
459#define P_NFNAME 0x400000L /* only normal file name chars allowed */
460#define P_INSECURE 0x800000L /* option was set from a modeline */
461#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100462 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200463#define P_NO_ML 0x2000000L /* not allowed in modeline */
464#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200465 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100466#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100467#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar110289e2019-05-23 15:38:06 +0200468#define P_MLE 0x20000000L /* under control of 'modelineexpr' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000469
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000470#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
471
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000472/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
473 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100474#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000475# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000476#else
477# define ISP_LATIN1 (char_u *)"@,161-255"
478#endif
479
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200480# 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 +0000481
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100482/* Default python version for pyx* commands */
483#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
484# define DEFAULT_PYTHON_VER 0
485#elif defined(FEAT_PYTHON3)
486# define DEFAULT_PYTHON_VER 3
487#elif defined(FEAT_PYTHON)
488# define DEFAULT_PYTHON_VER 2
489#else
490# define DEFAULT_PYTHON_VER 0
491#endif
492
Bram Moolenaarce655742019-01-31 14:12:57 +0100493// used for 'cinkeys' and 'indentkeys'
494#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
495
Bram Moolenaar071d4272004-06-13 20:20:40 +0000496/*
497 * options[] is initialized here.
498 * The order of the options MUST be alphabetic for ":set all" and findoption().
499 * All option names MUST start with a lowercase letter (for findoption()).
500 * Exception: "t_" options are at the end.
501 * The options with a NULL variable are 'hidden': a set command for them is
502 * ignored and they are not printed.
503 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100504static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200506 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000507#ifdef FEAT_RIGHTLEFT
508 (char_u *)&p_aleph, PV_NONE,
509#else
510 (char_u *)NULL, PV_NONE,
511#endif
512 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100513#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000514 (char_u *)128L,
515#else
516 (char_u *)224L,
517#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200518 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000519 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200520#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000521 (char_u *)&p_antialias, PV_NONE,
522 {(char_u *)FALSE, (char_u *)FALSE}
523#else
524 (char_u *)NULL, PV_NONE,
525 {(char_u *)FALSE, (char_u *)FALSE}
526#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200527 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200528 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000529#ifdef FEAT_ARABIC
530 (char_u *)VAR_WIN, PV_ARAB,
531#else
532 (char_u *)NULL, PV_NONE,
533#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200534 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000535 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
536#ifdef FEAT_ARABIC
537 (char_u *)&p_arshape, PV_NONE,
538#else
539 (char_u *)NULL, PV_NONE,
540#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200541 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000542 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
543#ifdef FEAT_RIGHTLEFT
544 (char_u *)&p_ari, PV_NONE,
545#else
546 (char_u *)NULL, PV_NONE,
547#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200548 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000549 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200551 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 (char_u *)&p_ambw, PV_NONE,
554 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200555 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100557#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100559 {(char_u *)FALSE, (char_u *)0L}
560#else
561 (char_u *)NULL, PV_NONE,
562 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000563#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200564 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000565 {"autoindent", "ai", P_BOOL|P_VI_DEF,
566 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200567 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autoprint", "ap", P_BOOL|P_VI_DEF,
569 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200570 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000572 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200573 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autowrite", "aw", P_BOOL|P_VI_DEF,
575 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autowriteall","awa", P_BOOL|P_VI_DEF,
578 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200579 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
581 (char_u *)&p_bg, PV_NONE,
582 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100583#if (defined(MSWIN)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000584 (char_u *)"dark",
585#else
586 (char_u *)"light",
587#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200588 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200589 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200591 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
593 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200594 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200595 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200596 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597#ifdef UNIX
598 {(char_u *)"yes", (char_u *)"auto"}
599#else
600 {(char_u *)"auto", (char_u *)"auto"}
601#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200602 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200603 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
604 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000605 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200606 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000607 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608 (char_u *)&p_bex, PV_NONE,
609 {
610#ifdef VMS
611 (char_u *)"_",
612#else
613 (char_u *)"~",
614#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200615 (char_u *)0L} SCTX_INIT},
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200616 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000617#ifdef FEAT_WILDIGN
618 (char_u *)&p_bsk, PV_NONE,
619 {(char_u *)"", (char_u *)0L}
620#else
621 (char_u *)NULL, PV_NONE,
622 {(char_u *)0L, (char_u *)0L}
623#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200624 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000625 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100626#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000627 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100628 {(char_u *)600L, (char_u *)0L}
629#else
630 (char_u *)NULL, PV_NONE,
631 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000632#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200633 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100634 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100635#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100636 (char_u *)&p_beval, PV_NONE,
637 {(char_u *)FALSE, (char_u *)0L}
638#else
639 (char_u *)NULL, PV_NONE,
640 {(char_u *)0L, (char_u *)0L}
641#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200642 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100643 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100644#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100645 (char_u *)&p_bevalterm, PV_NONE,
646 {(char_u *)FALSE, (char_u *)0L}
647#else
648 (char_u *)NULL, PV_NONE,
649 {(char_u *)0L, (char_u *)0L}
650#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200651 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200652 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100653#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
654 (char_u *)&p_bexpr, PV_BEXPR,
655 {(char_u *)"", (char_u *)0L}
656#else
657 (char_u *)NULL, PV_NONE,
658 {(char_u *)0L, (char_u *)0L}
659#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200660 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000661 {"beautify", "bf", P_BOOL|P_VI_DEF,
662 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200663 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200664 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
665 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200666 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000667 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
668 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200669 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200672 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200675 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
677#ifdef FEAT_LINEBREAK
678 (char_u *)&p_breakat, PV_NONE,
679 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
680#else
681 (char_u *)NULL, PV_NONE,
682 {(char_u *)0L, (char_u *)0L}
683#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200684 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200685 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
686#ifdef FEAT_LINEBREAK
687 (char_u *)VAR_WIN, PV_BRI,
688 {(char_u *)FALSE, (char_u *)0L}
689#else
690 (char_u *)NULL, PV_NONE,
691 {(char_u *)0L, (char_u *)0L}
692#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200693 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200694 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
695 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200696#ifdef FEAT_LINEBREAK
697 (char_u *)VAR_WIN, PV_BRIOPT,
698 {(char_u *)"", (char_u *)NULL}
699#else
700 (char_u *)NULL, PV_NONE,
701 {(char_u *)"", (char_u *)NULL}
702#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200703 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000704 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
705#ifdef FEAT_BROWSE
706 (char_u *)&p_bsdir, PV_NONE,
707 {(char_u *)"last", (char_u *)0L}
708#else
709 (char_u *)NULL, PV_NONE,
710 {(char_u *)0L, (char_u *)0L}
711#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200712 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000713 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 (char_u *)&p_bh, PV_BH,
715 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200716 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
718 (char_u *)&p_bl, PV_BL,
719 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200720 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000721 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 (char_u *)&p_bt, PV_BT,
723 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200724 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200725 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000726 (char_u *)&p_cmp, PV_NONE,
727 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200728 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200729 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000730#ifdef FEAT_SEARCHPATH
731 (char_u *)&p_cdpath, PV_NONE,
732 {(char_u *)",,", (char_u *)0L}
733#else
734 (char_u *)NULL, PV_NONE,
735 {(char_u *)0L, (char_u *)0L}
736#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200737 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000738 {"cedit", NULL, P_STRING,
739#ifdef FEAT_CMDWIN
740 (char_u *)&p_cedit, PV_NONE,
741 {(char_u *)"", (char_u *)CTRL_F_STR}
742#else
743 (char_u *)NULL, PV_NONE,
744 {(char_u *)0L, (char_u *)0L}
745#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200746 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000747 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100748#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000749 (char_u *)&p_ccv, PV_NONE,
750 {(char_u *)"", (char_u *)0L}
751#else
752 (char_u *)NULL, PV_NONE,
753 {(char_u *)0L, (char_u *)0L}
754#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200755 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000756 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
757#ifdef FEAT_CINDENT
758 (char_u *)&p_cin, PV_CIN,
759#else
760 (char_u *)NULL, PV_NONE,
761#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200762 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200763 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000764#ifdef FEAT_CINDENT
765 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100766 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767#else
768 (char_u *)NULL, PV_NONE,
769 {(char_u *)0L, (char_u *)0L}
770#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200771 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200772 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000773#ifdef FEAT_CINDENT
774 (char_u *)&p_cino, PV_CINO,
775#else
776 (char_u *)NULL, PV_NONE,
777#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200778 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200779 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000780#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
781 (char_u *)&p_cinw, PV_CINW,
782 {(char_u *)"if,else,while,do,for,switch",
783 (char_u *)0L}
784#else
785 (char_u *)NULL, PV_NONE,
786 {(char_u *)0L, (char_u *)0L}
787#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200788 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200789 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000790#ifdef FEAT_CLIPBOARD
791 (char_u *)&p_cb, PV_NONE,
792# ifdef FEAT_XCLIPBOARD
793 {(char_u *)"autoselect,exclude:cons\\|linux",
794 (char_u *)0L}
795# else
796 {(char_u *)"", (char_u *)0L}
797# endif
798#else
799 (char_u *)NULL, PV_NONE,
800 {(char_u *)"", (char_u *)0L}
801#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200802 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000803 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
804 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200805 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
807#ifdef FEAT_CMDWIN
808 (char_u *)&p_cwh, PV_NONE,
809#else
810 (char_u *)NULL, PV_NONE,
811#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200812 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200813 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200814#ifdef FEAT_SYN_HL
815 (char_u *)VAR_WIN, PV_CC,
816#else
817 (char_u *)NULL, PV_NONE,
818#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200819 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000820 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
821 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200822 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200823 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
824 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000825#ifdef FEAT_COMMENTS
826 (char_u *)&p_com, PV_COM,
827 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
828 (char_u *)0L}
829#else
830 (char_u *)NULL, PV_NONE,
831 {(char_u *)0L, (char_u *)0L}
832#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200833 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200834 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000835#ifdef FEAT_FOLDING
836 (char_u *)&p_cms, PV_CMS,
837 {(char_u *)"/*%s*/", (char_u *)0L}
838#else
839 (char_u *)NULL, PV_NONE,
840 {(char_u *)0L, (char_u *)0L}
841#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200842 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000843 /* P_PRI_MKRC isn't needed here, optval_default()
844 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000845 {"compatible", "cp", P_BOOL|P_RALL,
846 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200847 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200848 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000849 (char_u *)&p_cpt, PV_CPT,
850 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200851 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200852 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200853#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200854 (char_u *)VAR_WIN, PV_COCU,
855 {(char_u *)"", (char_u *)NULL}
856#else
857 (char_u *)NULL, PV_NONE,
858 {(char_u *)NULL, (char_u *)0L}
859#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200860 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200861 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
862#ifdef FEAT_CONCEAL
863 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200864#else
865 (char_u *)NULL, PV_NONE,
866#endif
867 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200868 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000869 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
870#ifdef FEAT_COMPL_FUNC
871 (char_u *)&p_cfu, PV_CFU,
872 {(char_u *)"", (char_u *)0L}
873#else
874 (char_u *)NULL, PV_NONE,
875 {(char_u *)0L, (char_u *)0L}
876#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200877 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200878 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000879 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000880 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200881 SCTX_INIT},
Bram Moolenaar62a0cb42019-08-18 16:35:23 +0200882 {"completepopup", "cpp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar36e4d982019-08-20 21:12:16 +0200883#if defined(FEAT_TEXT_PROP) && defined(FEAT_QUICKFIX)
Bram Moolenaar62a0cb42019-08-18 16:35:23 +0200884 (char_u *)&p_cpp, PV_NONE,
885 {(char_u *)"", (char_u *)0L}
886#else
887 (char_u *)NULL, PV_NONE,
888 {(char_u *)NULL, (char_u *)0L}
889#endif
890 SCTX_INIT},
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200891 {"completeslash", "csl", P_STRING|P_VI_DEF|P_VIM,
Bram Moolenaare2c453d2019-08-21 14:37:09 +0200892#if defined(BACKSLASH_IN_FILENAME)
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200893 (char_u *)&p_csl, PV_CSL,
894 {(char_u *)"", (char_u *)0L}
895#else
896 (char_u *)NULL, PV_NONE,
897 {(char_u *)0L, (char_u *)0L}
898#endif
899 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000900 {"confirm", "cf", P_BOOL|P_VI_DEF,
901#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
902 (char_u *)&p_confirm, PV_NONE,
903#else
904 (char_u *)NULL, PV_NONE,
905#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200906 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000907 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200909 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000910 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
911 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200912 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000913 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
914 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000915 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200916 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200917 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200918#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200919 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100920 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200921#else
922 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200923 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200924#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200925 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000926 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
927#ifdef FEAT_CSCOPE
928 (char_u *)&p_cspc, PV_NONE,
929#else
930 (char_u *)NULL, PV_NONE,
931#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200932 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000933 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
934#ifdef FEAT_CSCOPE
935 (char_u *)&p_csprg, PV_NONE,
936 {(char_u *)"cscope", (char_u *)0L}
937#else
938 (char_u *)NULL, PV_NONE,
939 {(char_u *)0L, (char_u *)0L}
940#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200941 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200942 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000943#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
944 (char_u *)&p_csqf, PV_NONE,
945 {(char_u *)"", (char_u *)0L}
946#else
947 (char_u *)NULL, PV_NONE,
948 {(char_u *)0L, (char_u *)0L}
949#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200950 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200951 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
952#ifdef FEAT_CSCOPE
953 (char_u *)&p_csre, 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 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
959#ifdef FEAT_CSCOPE
960 (char_u *)&p_cst, 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 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
966#ifdef FEAT_CSCOPE
967 (char_u *)&p_csto, 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 Moolenaar071d4272004-06-13 20:20:40 +0000972 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
973#ifdef FEAT_CSCOPE
974 (char_u *)&p_csverbose, PV_NONE,
975#else
976 (char_u *)NULL, PV_NONE,
977#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200978 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200979 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200980 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200981 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100982 {"cursorcolumn", "cuc", 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_CUC,
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 Moolenaara2477fd2016-12-03 15:13:20 +0100989 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000990#ifdef FEAT_SYN_HL
991 (char_u *)VAR_WIN, PV_CUL,
992#else
993 (char_u *)NULL, PV_NONE,
994#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200995 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000996 {"debug", NULL, P_STRING|P_VI_DEF,
997 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200998 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200999 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001000#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001001 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001002 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003#else
1004 (char_u *)NULL, PV_NONE,
1005 {(char_u *)NULL, (char_u *)0L}
1006#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001007 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001010 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001011 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001012 (char_u *)&p_dict, PV_DICT,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001013 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001014 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1015#ifdef FEAT_DIFF
1016 (char_u *)VAR_WIN, PV_DIFF,
1017#else
1018 (char_u *)NULL, PV_NONE,
1019#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001020 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001021 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1023 (char_u *)&p_dex, PV_NONE,
1024 {(char_u *)"", (char_u *)0L}
1025#else
1026 (char_u *)NULL, PV_NONE,
1027 {(char_u *)0L, (char_u *)0L}
1028#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001029 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001030 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1031 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001032#ifdef FEAT_DIFF
1033 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001034 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001035#else
1036 (char_u *)NULL, PV_NONE,
1037 {(char_u *)"", (char_u *)NULL}
1038#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001039 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1041#ifdef FEAT_DIGRAPHS
1042 (char_u *)&p_dg, PV_NONE,
1043#else
1044 (char_u *)NULL, PV_NONE,
1045#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001046 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001047 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1048 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001050 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001051 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001052 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001053 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 (char_u *)&p_ead, PV_NONE,
1056 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001057 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001058 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1059 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001060 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001061 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001062 (char_u *)&p_emoji, PV_NONE,
1063 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001064 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001065 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 (char_u *)&p_enc, PV_NONE,
1067 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001068 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001069 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1070 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001071 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001072 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1073 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001074 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001075 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001076 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001077 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001078 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1079 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001080 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1082#ifdef FEAT_QUICKFIX
1083 (char_u *)&p_ef, PV_NONE,
1084 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1085#else
1086 (char_u *)NULL, PV_NONE,
1087 {(char_u *)NULL, (char_u *)0L}
1088#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001089 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001090 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001092 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001093 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094#else
1095 (char_u *)NULL, PV_NONE,
1096 {(char_u *)NULL, (char_u *)0L}
1097#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001098 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 {"esckeys", "ek", P_BOOL|P_VIM,
1100 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001101 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001102 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001103 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001104 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001105 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1106 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001107 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001108 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1109 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001110 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001111 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1112 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 (char_u *)&p_fenc, PV_FENC,
1114 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001115 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001116 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001117 (char_u *)&p_fencs, PV_NONE,
1118 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001119 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001120 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1121 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001123 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001124 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001126 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001127 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001128 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1129 (char_u *)&p_fic, PV_NONE,
1130 {
1131#ifdef CASE_INSENSITIVE_FILENAME
1132 (char_u *)TRUE,
1133#else
1134 (char_u *)FALSE,
1135#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001136 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001137 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001138 (char_u *)&p_ft, PV_FT,
1139 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001140 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001141 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001142 (char_u *)&p_fcs, PV_NONE,
1143 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001144 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001145 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1146 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001147 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001149 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001150 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001151 {"flash", "fl", P_BOOL|P_VI_DEF,
1152 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001153 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001154 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001155#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001157 {(char_u *)"", (char_u *)0L}
1158#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 (char_u *)NULL, PV_NONE,
1160 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001161#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001162 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001163 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1164#ifdef FEAT_FOLDING
1165 (char_u *)VAR_WIN, PV_FDC,
1166 {(char_u *)FALSE, (char_u *)0L}
1167#else
1168 (char_u *)NULL, PV_NONE,
1169 {(char_u *)NULL, (char_u *)0L}
1170#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001171 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001172 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1173#ifdef FEAT_FOLDING
1174 (char_u *)VAR_WIN, PV_FEN,
1175 {(char_u *)TRUE, (char_u *)0L}
1176#else
1177 (char_u *)NULL, PV_NONE,
1178 {(char_u *)NULL, (char_u *)0L}
1179#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001180 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001181 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001182#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1183 (char_u *)VAR_WIN, PV_FDE,
1184 {(char_u *)"0", (char_u *)NULL}
1185#else
1186 (char_u *)NULL, PV_NONE,
1187 {(char_u *)NULL, (char_u *)0L}
1188#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001189 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001190 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001191#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001192 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001193 {(char_u *)"#", (char_u *)NULL}
1194#else
1195 (char_u *)NULL, PV_NONE,
1196 {(char_u *)NULL, (char_u *)0L}
1197#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001198 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001199 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001200#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001201 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001202 {(char_u *)0L, (char_u *)0L}
1203#else
1204 (char_u *)NULL, PV_NONE,
1205 {(char_u *)NULL, (char_u *)0L}
1206#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001207 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001208 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001209#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001210 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001211 {(char_u *)-1L, (char_u *)0L}
1212#else
1213 (char_u *)NULL, PV_NONE,
1214 {(char_u *)NULL, (char_u *)0L}
1215#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001216 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001217 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001218 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001219#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001220 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001221 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001222#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001223 (char_u *)NULL, PV_NONE,
1224 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001226 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001227 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1228#ifdef FEAT_FOLDING
1229 (char_u *)VAR_WIN, PV_FDM,
1230 {(char_u *)"manual", (char_u *)NULL}
1231#else
1232 (char_u *)NULL, PV_NONE,
1233 {(char_u *)NULL, (char_u *)0L}
1234#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001235 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001236 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1237#ifdef FEAT_FOLDING
1238 (char_u *)VAR_WIN, PV_FML,
1239 {(char_u *)1L, (char_u *)0L}
1240#else
1241 (char_u *)NULL, PV_NONE,
1242 {(char_u *)NULL, (char_u *)0L}
1243#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001244 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001245 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1246#ifdef FEAT_FOLDING
1247 (char_u *)VAR_WIN, PV_FDN,
1248 {(char_u *)20L, (char_u *)0L}
1249#else
1250 (char_u *)NULL, PV_NONE,
1251 {(char_u *)NULL, (char_u *)0L}
1252#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001253 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001254 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1255#ifdef FEAT_FOLDING
1256 (char_u *)&p_fdo, PV_NONE,
1257 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1258 (char_u *)0L}
1259#else
1260 (char_u *)NULL, PV_NONE,
1261 {(char_u *)NULL, (char_u *)0L}
1262#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001263 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001264 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001265#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1266 (char_u *)VAR_WIN, PV_FDT,
1267 {(char_u *)"foldtext()", (char_u *)NULL}
1268#else
1269 (char_u *)NULL, PV_NONE,
1270 {(char_u *)NULL, (char_u *)0L}
1271#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001272 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001273 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001274#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001275 (char_u *)&p_fex, PV_FEX,
1276 {(char_u *)"", (char_u *)0L}
1277#else
1278 (char_u *)NULL, PV_NONE,
1279 {(char_u *)0L, (char_u *)0L}
1280#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001281 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001282 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1283 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001284 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001285 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001286 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1287 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001288 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001289 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001291 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001292 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001293 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1294#ifdef HAVE_FSYNC
1295 (char_u *)&p_fs, PV_NONE,
1296 {(char_u *)TRUE, (char_u *)0L}
1297#else
1298 (char_u *)NULL, PV_NONE,
1299 {(char_u *)FALSE, (char_u *)0L}
1300#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001301 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1303 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001304 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001305 {"graphic", "gr", P_BOOL|P_VI_DEF,
1306 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001307 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001308 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309#ifdef FEAT_QUICKFIX
1310 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001311 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001312#else
1313 (char_u *)NULL, PV_NONE,
1314 {(char_u *)NULL, (char_u *)0L}
1315#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001316 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1318#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001319 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001321# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001322 /* may be changed to "grep -n" in os_win32.c */
1323 (char_u *)"findstr /n",
1324# else
1325# ifdef UNIX
1326 /* Add an extra file name so that grep will always
1327 * insert a file name in the match line. */
1328 (char_u *)"grep -n $* /dev/null",
1329# else
1330# ifdef VMS
1331 (char_u *)"SEARCH/NUMBERS ",
1332# else
1333 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001334# endif
1335# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001336# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001337 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001338#else
1339 (char_u *)NULL, PV_NONE,
1340 {(char_u *)NULL, (char_u *)0L}
1341#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001342 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001343 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344#ifdef CURSOR_SHAPE
1345 (char_u *)&p_guicursor, PV_NONE,
1346 {
1347# ifdef FEAT_GUI
1348 (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 +01001349# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001350 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1351# endif
1352 (char_u *)0L}
1353#else
1354 (char_u *)NULL, PV_NONE,
1355 {(char_u *)NULL, (char_u *)0L}
1356#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001357 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001358 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001359#ifdef FEAT_GUI
1360 (char_u *)&p_guifont, PV_NONE,
1361 {(char_u *)"", (char_u *)0L}
1362#else
1363 (char_u *)NULL, PV_NONE,
1364 {(char_u *)NULL, (char_u *)0L}
1365#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001366 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001367 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1369 (char_u *)&p_guifontset, PV_NONE,
1370 {(char_u *)"", (char_u *)0L}
1371#else
1372 (char_u *)NULL, PV_NONE,
1373 {(char_u *)NULL, (char_u *)0L}
1374#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001375 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001376 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001377#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001378 (char_u *)&p_guifontwide, PV_NONE,
1379 {(char_u *)"", (char_u *)0L}
1380#else
1381 (char_u *)NULL, PV_NONE,
1382 {(char_u *)NULL, (char_u *)0L}
1383#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001384 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001386#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001387 (char_u *)&p_ghr, PV_NONE,
1388#else
1389 (char_u *)NULL, PV_NONE,
1390#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001391 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001392 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001393#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001394 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001395# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001396 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001397# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001398 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001399# endif
1400#else
1401 (char_u *)NULL, PV_NONE,
1402 {(char_u *)NULL, (char_u *)0L}
1403#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001404 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405 {"guipty", NULL, P_BOOL|P_VI_DEF,
1406#if defined(FEAT_GUI)
1407 (char_u *)&p_guipty, PV_NONE,
1408#else
1409 (char_u *)NULL, PV_NONE,
1410#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001411 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001412 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001413#if defined(FEAT_GUI_TABLINE)
1414 (char_u *)&p_gtl, PV_NONE,
1415 {(char_u *)"", (char_u *)0L}
1416#else
1417 (char_u *)NULL, PV_NONE,
1418 {(char_u *)NULL, (char_u *)0L}
1419#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001420 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001421 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001422#if defined(FEAT_GUI_TABLINE)
1423 (char_u *)&p_gtt, PV_NONE,
1424 {(char_u *)"", (char_u *)0L}
1425#else
1426 (char_u *)NULL, PV_NONE,
1427 {(char_u *)NULL, (char_u *)0L}
1428#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001429 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001430 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1431 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001432 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001433 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1434 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001435 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001436 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001439 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001440 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441#ifdef FEAT_MULTI_LANG
1442 (char_u *)&p_hlg, PV_NONE,
1443 {(char_u *)"", (char_u *)0L}
1444#else
1445 (char_u *)NULL, PV_NONE,
1446 {(char_u *)0L, (char_u *)0L}
1447#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001448 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449 {"hidden", "hid", P_BOOL|P_VI_DEF,
1450 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001451 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001452 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001453 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001454 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001455 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001456 {"history", "hi", P_NUM|P_VIM,
1457 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001458 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001459 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1460#ifdef FEAT_RIGHTLEFT
1461 (char_u *)&p_hkmap, PV_NONE,
1462#else
1463 (char_u *)NULL, PV_NONE,
1464#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001465 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001466 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1467#ifdef FEAT_RIGHTLEFT
1468 (char_u *)&p_hkmapp, PV_NONE,
1469#else
1470 (char_u *)NULL, PV_NONE,
1471#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001472 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001473 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1474 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001475 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001476 {"icon", NULL, P_BOOL|P_VI_DEF,
1477#ifdef FEAT_TITLE
1478 (char_u *)&p_icon, PV_NONE,
1479#else
1480 (char_u *)NULL, PV_NONE,
1481#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001482 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001483 {"iconstring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484#ifdef FEAT_TITLE
1485 (char_u *)&p_iconstring, PV_NONE,
1486#else
1487 (char_u *)NULL, PV_NONE,
1488#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001489 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001490 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1491 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001492 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001493 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001494#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001495 (char_u *)&p_imaf, PV_NONE,
1496 {(char_u *)"", (char_u *)NULL}
1497# else
1498 (char_u *)NULL, PV_NONE,
1499 {(char_u *)NULL, (char_u *)0L}
1500# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001501 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001502 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001503#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001504 (char_u *)&p_imak, PV_NONE,
1505#else
1506 (char_u *)NULL, PV_NONE,
1507#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001508 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001511 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001514#ifdef __sgi
1515 {(char_u *)TRUE, (char_u *)0L}
1516#else
1517 {(char_u *)FALSE, (char_u *)0L}
1518#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001519 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"iminsert", "imi", P_NUM|P_VI_DEF,
1521 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001523 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001524 {"imsearch", "ims", P_NUM|P_VI_DEF,
1525 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001526 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001527 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001528 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001529#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001530 (char_u *)&p_imsf, PV_NONE,
1531 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001532#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001533 (char_u *)NULL, PV_NONE,
1534 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001535#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001536 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001537 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1538#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1539 (char_u *)&p_imst, PV_NONE,
1540 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1541#else
1542 (char_u *)NULL, PV_NONE,
1543 {(char_u *)0L, (char_u *)0L}
1544#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001545 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001546 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1547#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001548 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001549 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1550#else
1551 (char_u *)NULL, PV_NONE,
1552 {(char_u *)0L, (char_u *)0L}
1553#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001554 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001555 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001556#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1557 (char_u *)&p_inex, PV_INEX,
1558 {(char_u *)"", (char_u *)0L}
1559#else
1560 (char_u *)NULL, PV_NONE,
1561 {(char_u *)0L, (char_u *)0L}
1562#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001563 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1565 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001566 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001567 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001568#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1569 (char_u *)&p_inde, PV_INDE,
1570 {(char_u *)"", (char_u *)0L}
1571#else
1572 (char_u *)NULL, PV_NONE,
1573 {(char_u *)0L, (char_u *)0L}
1574#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001575 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001576 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001577#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1578 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001579 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001580#else
1581 (char_u *)NULL, PV_NONE,
1582 {(char_u *)0L, (char_u *)0L}
1583#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001584 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585 {"infercase", "inf", P_BOOL|P_VI_DEF,
1586 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001587 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1589 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001590 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001591 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1592 (char_u *)&p_isf, PV_NONE,
1593 {
1594#ifdef BACKSLASH_IN_FILENAME
1595 /* Excluded are: & and ^ are special in cmd.exe
1596 * ( and ) are used in text separating fnames */
1597 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1598#else
1599# ifdef AMIGA
1600 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1601# else
1602# ifdef VMS
1603 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1604# else /* UNIX et al. */
1605# ifdef EBCDIC
1606 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1607# else
1608 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1609# endif
1610# endif
1611# endif
1612#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001613 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001614 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1615 (char_u *)&p_isi, PV_NONE,
1616 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001617#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001618 (char_u *)"@,48-57,_,128-167,224-235",
1619#else
1620# ifdef EBCDIC
1621 /* TODO: EBCDIC Check this! @ == isalpha()*/
1622 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1623 "112-120,128,140-142,156,158,172,"
1624 "174,186,191,203-207,219-225,235-239,"
1625 "251-254",
1626# else
1627 (char_u *)"@,48-57,_,192-255",
1628# endif
1629#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001630 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001631 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1632 (char_u *)&p_isk, PV_ISK,
1633 {
1634#ifdef EBCDIC
1635 (char_u *)"@,240-249,_",
1636 /* TODO: EBCDIC Check this! @ == isalpha()*/
1637 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1638 "112-120,128,140-142,156,158,172,"
1639 "174,186,191,203-207,219-225,235-239,"
1640 "251-254",
1641#else
1642 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001643# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001644 (char_u *)"@,48-57,_,128-167,224-235"
1645# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001646 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001647# endif
1648#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001649 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001650 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1651 (char_u *)&p_isp, PV_NONE,
1652 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001653#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001654 (char_u *)"@,~-255",
1655#else
1656# ifdef EBCDIC
1657 /* all chars above 63 are printable */
1658 (char_u *)"63-255",
1659# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001660 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001661# endif
1662#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001663 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001664 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1665 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001666 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1668#ifdef FEAT_CRYPT
1669 (char_u *)&p_key, PV_KEY,
1670 {(char_u *)"", (char_u *)0L}
1671#else
1672 (char_u *)NULL, PV_NONE,
1673 {(char_u *)0L, (char_u *)0L}
1674#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001675 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001676 {"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 +00001677#ifdef FEAT_KEYMAP
1678 (char_u *)&p_keymap, PV_KMAP,
1679 {(char_u *)"", (char_u *)0L}
1680#else
1681 (char_u *)NULL, PV_NONE,
1682 {(char_u *)"", (char_u *)0L}
1683#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001684 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001685 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001687 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001688 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001689 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001690 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001691#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001692 (char_u *)":help",
1693#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001694# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001695 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001696# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001697# ifdef USEMAN_S
1698 (char_u *)"man -s",
1699# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001701# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001702# endif
1703#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001704 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001705 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001706#ifdef FEAT_LANGMAP
1707 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001708 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001709#else
1710 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001711 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001712#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001713 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001714 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001715#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1716 (char_u *)&p_lm, PV_NONE,
1717#else
1718 (char_u *)NULL, PV_NONE,
1719#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001720 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001721 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1722#ifdef FEAT_LANGMAP
1723 (char_u *)&p_lnr, PV_NONE,
1724#else
1725 (char_u *)NULL, PV_NONE,
1726#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001727 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001728 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1729#ifdef FEAT_LANGMAP
1730 (char_u *)&p_lrm, PV_NONE,
1731#else
1732 (char_u *)NULL, PV_NONE,
1733#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001734 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001737 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001738 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1739 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001740 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001741 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1742#ifdef FEAT_LINEBREAK
1743 (char_u *)VAR_WIN, PV_LBR,
1744#else
1745 (char_u *)NULL, PV_NONE,
1746#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001747 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001748 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1749 (char_u *)&Rows, PV_NONE,
1750 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001751#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001752 (char_u *)25L,
1753#else
1754 (char_u *)24L,
1755#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001756 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001757 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1758#ifdef FEAT_GUI
1759 (char_u *)&p_linespace, PV_NONE,
1760#else
1761 (char_u *)NULL, PV_NONE,
1762#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001763#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001764 {(char_u *)1L, (char_u *)0L}
1765#else
1766 {(char_u *)0L, (char_u *)0L}
1767#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001768 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001769 {"lisp", NULL, P_BOOL|P_VI_DEF,
1770#ifdef FEAT_LISP
1771 (char_u *)&p_lisp, PV_LISP,
1772#else
1773 (char_u *)NULL, PV_NONE,
1774#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001775 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001776 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001778 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001779 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1780#else
1781 (char_u *)NULL, PV_NONE,
1782 {(char_u *)"", (char_u *)0L}
1783#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001784 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1786 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001787 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001788 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001789 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001790 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001791 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1792 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001793 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001794 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001795#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001796 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001797 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001798#else
1799 (char_u *)NULL, PV_NONE,
1800 {(char_u *)"", (char_u *)0L}
1801#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001802 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001803 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001804#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001805 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001806 {(char_u *)TRUE, (char_u *)0L}
1807#else
1808 (char_u *)NULL, PV_NONE,
1809 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001810#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001811 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812 {"magic", NULL, P_BOOL|P_VI_DEF,
1813 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001814 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001815 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001816#ifdef FEAT_QUICKFIX
1817 (char_u *)&p_mef, PV_NONE,
1818 {(char_u *)"", (char_u *)0L}
1819#else
1820 (char_u *)NULL, PV_NONE,
1821 {(char_u *)NULL, (char_u *)0L}
1822#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001823 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001824 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001825 (char_u *)&p_menc, PV_MENC,
1826 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001827 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001828 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1829#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001830 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001831# ifdef VMS
1832 {(char_u *)"MMS", (char_u *)0L}
1833# else
1834 {(char_u *)"make", (char_u *)0L}
1835# endif
1836#else
1837 (char_u *)NULL, PV_NONE,
1838 {(char_u *)NULL, (char_u *)0L}
1839#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001840 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001841 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001842 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001843 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001844 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001845 {"matchtime", "mat", P_NUM|P_VI_DEF,
1846 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001847 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001848 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001849 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001850 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001851 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1852#ifdef FEAT_EVAL
1853 (char_u *)&p_mfd, PV_NONE,
1854#else
1855 (char_u *)NULL, PV_NONE,
1856#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001857 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001858 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1859 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001860 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001861 {"maxmem", "mm", P_NUM|P_VI_DEF,
1862 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001863 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001864 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001865 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1866 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001867 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001868 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1869 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001870 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001871 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001872 {"menuitems", "mis", P_NUM|P_VI_DEF,
1873#ifdef FEAT_MENU
1874 (char_u *)&p_mis, PV_NONE,
1875#else
1876 (char_u *)NULL, PV_NONE,
1877#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001878 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 {"mesg", NULL, P_BOOL|P_VI_DEF,
1880 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001881 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001882 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001883#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001884 (char_u *)&p_msm, PV_NONE,
1885 {(char_u *)"460000,2000,500", (char_u *)0L}
1886#else
1887 (char_u *)NULL, PV_NONE,
1888 {(char_u *)0L, (char_u *)0L}
1889#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001890 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001891 {"modeline", "ml", P_BOOL|P_VIM,
1892 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001893 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar7e800c62019-05-23 17:08:49 +02001894 {"modelineexpr", "mle", P_BOOL|P_VI_DEF|P_SECURE,
Bram Moolenaar110289e2019-05-23 15:38:06 +02001895 (char_u *)&p_mle, PV_NONE,
1896 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {"modelines", "mls", P_NUM|P_VI_DEF,
1898 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001899 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001900 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1901 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001902 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001903 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1904 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001905 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001906 {"more", NULL, P_BOOL|P_VIM,
1907 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001908 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001909 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1910 (char_u *)&p_mouse, PV_NONE,
1911 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001912#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001913 (char_u *)"a",
1914#else
1915 (char_u *)"",
1916#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001917 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001918 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1919#ifdef FEAT_GUI
1920 (char_u *)&p_mousef, PV_NONE,
1921#else
1922 (char_u *)NULL, PV_NONE,
1923#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001924 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001925 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1926#ifdef FEAT_GUI
1927 (char_u *)&p_mh, PV_NONE,
1928#else
1929 (char_u *)NULL, PV_NONE,
1930#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001931 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001932 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1933 (char_u *)&p_mousem, PV_NONE,
1934 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001935#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001936 (char_u *)"popup",
1937#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001938# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001939 (char_u *)"popup_setpos",
1940# else
1941 (char_u *)"extend",
1942# endif
1943#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001944 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001945 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001946#ifdef FEAT_MOUSESHAPE
1947 (char_u *)&p_mouseshape, PV_NONE,
1948 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1949#else
1950 (char_u *)NULL, PV_NONE,
1951 {(char_u *)NULL, (char_u *)0L}
1952#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001953 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1955 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001956 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001957 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1958#if defined(DYNAMIC_MZSCHEME)
1959 (char_u *)&p_mzschemedll, PV_NONE,
1960 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1961#else
1962 (char_u *)NULL, PV_NONE,
1963 {(char_u *)"", (char_u *)0L}
1964#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001965 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001966 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1967#if defined(DYNAMIC_MZSCHEME)
1968 (char_u *)&p_mzschemegcdll, PV_NONE,
1969 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1970#else
1971 (char_u *)NULL, PV_NONE,
1972 {(char_u *)"", (char_u *)0L}
1973#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001974 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001975 {"mzquantum", "mzq", P_NUM,
1976#ifdef FEAT_MZSCHEME
1977 (char_u *)&p_mzq, PV_NONE,
1978#else
1979 (char_u *)NULL, PV_NONE,
1980#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001981 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001982 {"novice", NULL, P_BOOL|P_VI_DEF,
1983 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001984 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001985 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001986 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001987 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001988 SCTX_INIT},
Bram Moolenaar44826212019-08-22 21:23:20 +02001989 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001990 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001991 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001992 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1993#ifdef FEAT_LINEBREAK
1994 (char_u *)VAR_WIN, PV_NUW,
1995#else
1996 (char_u *)NULL, PV_NONE,
1997#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001998 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001999 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002000#ifdef FEAT_COMPL_FUNC
2001 (char_u *)&p_ofu, PV_OFU,
2002 {(char_u *)"", (char_u *)0L}
2003#else
2004 (char_u *)NULL, PV_NONE,
2005 {(char_u *)0L, (char_u *)0L}
2006#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002007 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002008 {"open", NULL, P_BOOL|P_VI_DEF,
2009 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002010 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002011 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002012#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002013 (char_u *)&p_odev, PV_NONE,
2014#else
2015 (char_u *)NULL, PV_NONE,
2016#endif
2017 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002018 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002019 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2020 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002021 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002022 {"optimize", "opt", P_BOOL|P_VI_DEF,
2023 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002024 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002026 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002027 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002028 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2029 |P_SECURE,
2030 (char_u *)&p_pp, PV_NONE,
2031 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002032 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 {"paragraphs", "para", P_STRING|P_VI_DEF,
2034 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002035 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002036 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002037 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002038 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002039 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002040 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2041 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002042 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002043 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2044#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2045 (char_u *)&p_pex, PV_NONE,
2046 {(char_u *)"", (char_u *)0L}
2047#else
2048 (char_u *)NULL, PV_NONE,
2049 {(char_u *)0L, (char_u *)0L}
2050#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002051 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002052 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002053 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002054 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002055 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002056 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002057 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002058#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002059 (char_u *)".,,",
2060#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002062#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002063 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002064 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002065#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002066 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002067 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002068#else
2069 (char_u *)NULL, PV_NONE,
2070 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002071#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002072 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002073 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2074 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002075 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002076 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002077#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002078 (char_u *)&p_pvh, PV_NONE,
2079#else
2080 (char_u *)NULL, PV_NONE,
2081#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002082 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar79648732019-07-18 21:43:07 +02002083 {"previewpopup", "pvp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2084#ifdef FEAT_TEXT_PROP
2085 (char_u *)&p_pvp, PV_NONE,
2086 {(char_u *)"", (char_u *)0L}
2087#else
2088 (char_u *)NULL, PV_NONE,
2089 {(char_u *)NULL, (char_u *)0L}
2090#endif
2091 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002092 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002093#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002094 (char_u *)VAR_WIN, PV_PVW,
2095#else
2096 (char_u *)NULL, PV_NONE,
2097#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002098 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002099 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100#ifdef FEAT_PRINTER
2101 (char_u *)&p_pdev, PV_NONE,
2102 {(char_u *)"", (char_u *)0L}
2103#else
2104 (char_u *)NULL, PV_NONE,
2105 {(char_u *)NULL, (char_u *)0L}
2106#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002107 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108 {"printencoding", "penc", P_STRING|P_VI_DEF,
2109#ifdef FEAT_POSTSCRIPT
2110 (char_u *)&p_penc, PV_NONE,
2111 {(char_u *)"", (char_u *)0L}
2112#else
2113 (char_u *)NULL, PV_NONE,
2114 {(char_u *)NULL, (char_u *)0L}
2115#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002116 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002117 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002118#ifdef FEAT_POSTSCRIPT
2119 (char_u *)&p_pexpr, PV_NONE,
2120 {(char_u *)"", (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 {"printfont", "pfn", P_STRING|P_VI_DEF,
2127#ifdef FEAT_PRINTER
2128 (char_u *)&p_pfn, PV_NONE,
2129 {
2130# ifdef MSWIN
2131 (char_u *)"Courier_New:h10",
2132# else
2133 (char_u *)"courier",
2134# endif
2135 (char_u *)0L}
2136#else
2137 (char_u *)NULL, PV_NONE,
2138 {(char_u *)NULL, (char_u *)0L}
2139#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002140 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2142#ifdef FEAT_PRINTER
2143 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002144 /* untranslated to avoid problems when 'encoding'
2145 * is changed */
2146 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002147#else
2148 (char_u *)NULL, PV_NONE,
2149 {(char_u *)NULL, (char_u *)0L}
2150#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002151 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002152 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002153#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002154 (char_u *)&p_pmcs, PV_NONE,
2155 {(char_u *)"", (char_u *)0L}
2156#else
2157 (char_u *)NULL, PV_NONE,
2158 {(char_u *)NULL, (char_u *)0L}
2159#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002160 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002161 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002162#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002163 (char_u *)&p_pmfn, PV_NONE,
2164 {(char_u *)"", (char_u *)0L}
2165#else
2166 (char_u *)NULL, PV_NONE,
2167 {(char_u *)NULL, (char_u *)0L}
2168#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002169 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002170 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002171#ifdef FEAT_PRINTER
2172 (char_u *)&p_popt, PV_NONE,
2173 {(char_u *)"", (char_u *)0L}
2174#else
2175 (char_u *)NULL, PV_NONE,
2176 {(char_u *)NULL, (char_u *)0L}
2177#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002178 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002180 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002181 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002182 {"pumheight", "ph", P_NUM|P_VI_DEF,
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002183 (char_u *)&p_ph, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002184 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002185 {"pumwidth", "pw", P_NUM|P_VI_DEF,
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002186 (char_u *)&p_pw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002187 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002188 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002189#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002190 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002191 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002192#else
2193 (char_u *)NULL, PV_NONE,
2194 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002195#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002196 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002197 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2198#if defined(FEAT_PYTHON3)
2199 (char_u *)&p_py3home, PV_NONE,
2200 {(char_u *)"", (char_u *)0L}
2201#else
2202 (char_u *)NULL, PV_NONE,
2203 {(char_u *)NULL, (char_u *)0L}
2204#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002205 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002206 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002207#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002208 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002209 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002210#else
2211 (char_u *)NULL, PV_NONE,
2212 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002213#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002214 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002215 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2216#if defined(FEAT_PYTHON)
2217 (char_u *)&p_pyhome, PV_NONE,
2218 {(char_u *)"", (char_u *)0L}
2219#else
2220 (char_u *)NULL, PV_NONE,
2221 {(char_u *)NULL, (char_u *)0L}
2222#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002223 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002224 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2225#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2226 (char_u *)&p_pyx, PV_NONE,
2227#else
2228 (char_u *)NULL, PV_NONE,
2229#endif
2230 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002231 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002232 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2233#ifdef FEAT_TEXTOBJ
2234 (char_u *)&p_qe, PV_QE,
2235 {(char_u *)"\\", (char_u *)0L}
2236#else
2237 (char_u *)NULL, PV_NONE,
2238 {(char_u *)NULL, (char_u *)0L}
2239#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002240 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002241 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2242 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002243 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002244 {"redraw", NULL, P_BOOL|P_VI_DEF,
2245 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002246 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002247 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2248#ifdef FEAT_RELTIME
2249 (char_u *)&p_rdt, PV_NONE,
2250#else
2251 (char_u *)NULL, PV_NONE,
2252#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002253 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002254 {"regexpengine", "re", P_NUM|P_VI_DEF,
2255 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002256 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar44826212019-08-22 21:23:20 +02002257 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaar64486672010-05-16 15:46:46 +02002258 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002259 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002260 {"remap", NULL, P_BOOL|P_VI_DEF,
2261 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002262 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002263 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002264#ifdef FEAT_RENDER_OPTIONS
2265 (char_u *)&p_rop, PV_NONE,
2266 {(char_u *)"", (char_u *)0L}
2267#else
2268 (char_u *)NULL, PV_NONE,
2269 {(char_u *)NULL, (char_u *)0L}
2270#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002271 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002272 {"report", NULL, P_NUM|P_VI_DEF,
2273 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002274 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002275 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002276#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002277 (char_u *)&p_rs, PV_NONE,
2278#else
2279 (char_u *)NULL, PV_NONE,
2280#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002281 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2283#ifdef FEAT_RIGHTLEFT
2284 (char_u *)&p_ri, PV_NONE,
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 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2290#ifdef FEAT_RIGHTLEFT
2291 (char_u *)VAR_WIN, PV_RL,
2292#else
2293 (char_u *)NULL, PV_NONE,
2294#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002295 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2297#ifdef FEAT_RIGHTLEFT
2298 (char_u *)VAR_WIN, PV_RLC,
2299 {(char_u *)"search", (char_u *)NULL}
2300#else
2301 (char_u *)NULL, PV_NONE,
2302 {(char_u *)NULL, (char_u *)0L}
2303#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002304 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002305 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002306#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002307 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002308 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002309#else
2310 (char_u *)NULL, PV_NONE,
2311 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002312#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002313 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002314 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2315#ifdef FEAT_CMDL_INFO
2316 (char_u *)&p_ru, PV_NONE,
2317#else
2318 (char_u *)NULL, PV_NONE,
2319#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002320 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002321 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322#ifdef FEAT_STL_OPT
2323 (char_u *)&p_ruf, PV_NONE,
2324#else
2325 (char_u *)NULL, PV_NONE,
2326#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002327 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002328 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2329 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002331 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002332 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002333 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2334 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002335 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002336 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002338 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002339 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2340 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002341 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002342 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002343 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002344 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002345 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 (char_u *)&p_sbo, PV_NONE,
2347 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002348 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"sections", "sect", P_STRING|P_VI_DEF,
2350 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002351 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002352 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2354 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002355 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002359 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002360 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002362 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002363 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364#ifdef FEAT_SESSION
2365 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002366 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002367 (char_u *)0L}
2368#else
2369 (char_u *)NULL, PV_NONE,
2370 {(char_u *)0L, (char_u *)0L}
2371#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002372 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002373 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2374 (char_u *)&p_sh, PV_NONE,
2375 {
2376#ifdef VMS
2377 (char_u *)"-",
2378#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002379# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002381# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002382 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002383# endif
2384#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002385 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002386 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2387 (char_u *)&p_shcf, PV_NONE,
2388 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002389#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 (char_u *)"/c",
2391#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002392 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002394 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002395 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2396#ifdef FEAT_QUICKFIX
2397 (char_u *)&p_sp, PV_NONE,
2398 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002399#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401#else
2402 (char_u *)">",
2403#endif
2404 (char_u *)0L}
2405#else
2406 (char_u *)NULL, PV_NONE,
2407 {(char_u *)0L, (char_u *)0L}
2408#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002409 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002410 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2411 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002412 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002413 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2414 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002415 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002416 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2417#ifdef BACKSLASH_IN_FILENAME
2418 (char_u *)&p_ssl, PV_NONE,
2419#else
2420 (char_u *)NULL, PV_NONE,
2421#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002422 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002423 {"shelltemp", "stmp", P_BOOL,
2424 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002425 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002426 {"shelltype", "st", P_NUM|P_VI_DEF,
2427#ifdef AMIGA
2428 (char_u *)&p_st, PV_NONE,
2429#else
2430 (char_u *)NULL, PV_NONE,
2431#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002432 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2434 (char_u *)&p_sxq, PV_NONE,
2435 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002436#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002437 (char_u *)"\"",
2438#else
2439 (char_u *)"",
2440#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002441 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002442 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2443 (char_u *)&p_sxe, PV_NONE,
2444 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002445#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002446 (char_u *)"\"&|<>()@^",
2447#else
2448 (char_u *)"",
2449#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002450 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002451 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2452 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002453 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002454 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2455 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002456 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002457 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2458 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02002459 {(char_u *)"S", (char_u *)"filnxtToOS"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002460 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002463 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2465#ifdef FEAT_LINEBREAK
2466 (char_u *)&p_sbr, PV_NONE,
2467#else
2468 (char_u *)NULL, PV_NONE,
2469#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002470 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"showcmd", "sc", P_BOOL|P_VIM,
2472#ifdef FEAT_CMDL_INFO
2473 (char_u *)&p_sc, PV_NONE,
2474#else
2475 (char_u *)NULL, PV_NONE,
2476#endif
2477 {(char_u *)FALSE,
2478#ifdef UNIX
2479 (char_u *)FALSE
2480#else
2481 (char_u *)TRUE
2482#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002483 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002484 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2485 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002486 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002487 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2488 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002489 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002490 {"showmode", "smd", P_BOOL|P_VIM,
2491 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002492 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002493 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002494 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002495 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002496 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2497 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002498 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002499 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002500 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002501 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002502 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RCLR,
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002503#ifdef FEAT_SIGNS
2504 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002505 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002506#else
2507 (char_u *)NULL, PV_NONE,
2508 {(char_u *)NULL, (char_u *)0L}
2509#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002510 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002511 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2512 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002513 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002514 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2515 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002516 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002517 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2518#ifdef FEAT_SMARTINDENT
2519 (char_u *)&p_si, PV_SI,
2520#else
2521 (char_u *)NULL, PV_NONE,
2522#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002523 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2525 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002526 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002527 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2528 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002529 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002530 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2531 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002532 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002533 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002534#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002535 (char_u *)VAR_WIN, PV_SPELL,
2536#else
2537 (char_u *)NULL, PV_NONE,
2538#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002539 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002540 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002541#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002542 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002543 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002544#else
2545 (char_u *)NULL, PV_NONE,
2546 {(char_u *)0L, (char_u *)0L}
2547#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002548 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002549 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2550 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002551#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002552 (char_u *)&p_spf, PV_SPF,
2553 {(char_u *)"", (char_u *)0L}
2554#else
2555 (char_u *)NULL, PV_NONE,
2556 {(char_u *)0L, (char_u *)0L}
2557#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002558 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002559 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2560 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002561#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002562 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002563 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002564#else
2565 (char_u *)NULL, PV_NONE,
2566 {(char_u *)0L, (char_u *)0L}
2567#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002568 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002569 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002570#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002571 (char_u *)&p_sps, PV_NONE,
2572 {(char_u *)"best", (char_u *)0L}
2573#else
2574 (char_u *)NULL, PV_NONE,
2575 {(char_u *)0L, (char_u *)0L}
2576#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002577 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002578 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002579 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002580 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002581 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002582 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002583 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002584 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2585 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002586 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002587 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002589 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590#else
2591 (char_u *)NULL, PV_NONE,
2592#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002593 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002594 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595 (char_u *)&p_su, PV_NONE,
2596 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002597 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002598 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002599#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002600 (char_u *)&p_sua, PV_SUA,
2601 {(char_u *)"", (char_u *)0L}
2602#else
2603 (char_u *)NULL, PV_NONE,
2604 {(char_u *)0L, (char_u *)0L}
2605#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002606 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2608 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002609 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002610 {"swapsync", "sws", P_STRING|P_VI_DEF,
2611 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002612 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002613 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002615 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002616 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2617#ifdef FEAT_SYN_HL
2618 (char_u *)&p_smc, PV_SMC,
2619 {(char_u *)3000L, (char_u *)0L}
2620#else
2621 (char_u *)NULL, PV_NONE,
2622 {(char_u *)0L, (char_u *)0L}
2623#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002624 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002625 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002626#ifdef FEAT_SYN_HL
2627 (char_u *)&p_syn, PV_SYN,
2628 {(char_u *)"", (char_u *)0L}
2629#else
2630 (char_u *)NULL, PV_NONE,
2631 {(char_u *)0L, (char_u *)0L}
2632#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002633 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002634 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL|P_MLE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002635#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002636 (char_u *)&p_tal, PV_NONE,
2637#else
2638 (char_u *)NULL, PV_NONE,
2639#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002640 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002641 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002642 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002643 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002644 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2645 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002646 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002647 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2648 (char_u *)&p_tbs, PV_NONE,
2649#ifdef VMS /* binary searching doesn't appear to work on VMS */
2650 {(char_u *)0L, (char_u *)0L}
2651#else
2652 {(char_u *)TRUE, (char_u *)0L}
2653#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002654 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002655 {"tagcase", "tc", P_STRING|P_VIM,
2656 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002657 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002658 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2659#ifdef FEAT_EVAL
2660 (char_u *)&p_tfu, PV_TFU,
2661 {(char_u *)"", (char_u *)0L}
2662#else
2663 (char_u *)NULL, PV_NONE,
2664 {(char_u *)0L, (char_u *)0L}
2665#endif
2666 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002667 {"taglength", "tl", P_NUM|P_VI_DEF,
2668 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002669 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002670 {"tagrelative", "tr", P_BOOL|P_VIM,
2671 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002672 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002673 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002674 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {
2676#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2677 (char_u *)"./tags,./TAGS,tags,TAGS",
2678#else
2679 (char_u *)"./tags,tags",
2680#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002681 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2683 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002684 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002685 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002686#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002687 (char_u *)&p_tcldll, PV_NONE,
2688 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002689#else
2690 (char_u *)NULL, PV_NONE,
2691 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002692#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002693 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002694 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2695 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002696 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002697 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2698#ifdef FEAT_ARABIC
2699 (char_u *)&p_tbidi, PV_NONE,
2700#else
2701 (char_u *)NULL, PV_NONE,
2702#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002703 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 (char_u *)&p_tenc, PV_NONE,
2706 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002707 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002708 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2709#ifdef FEAT_TERMGUICOLORS
2710 (char_u *)&p_tgc, PV_NONE,
2711 {(char_u *)FALSE, (char_u *)FALSE}
2712#else
2713 (char_u*)NULL, PV_NONE,
2714 {(char_u *)FALSE, (char_u *)FALSE}
2715#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002716 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002717 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2718#ifdef FEAT_TERMINAL
2719 (char_u *)VAR_WIN, PV_TWK,
2720 {(char_u *)"", (char_u *)NULL}
2721#else
2722 (char_u *)NULL, PV_NONE,
2723 {(char_u *)NULL, (char_u *)0L}
2724#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002725 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002726 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2727#ifdef FEAT_TERMINAL
2728 (char_u *)&p_twsl, PV_TWSL,
2729 {(char_u *)10000L, (char_u *)10000L}
2730#else
2731 (char_u *)NULL, PV_NONE,
2732 {(char_u *)NULL, (char_u *)0L}
2733#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002734 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002735 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2736#ifdef FEAT_TERMINAL
2737 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002738 {(char_u *)"", (char_u *)NULL}
2739#else
2740 (char_u *)NULL, PV_NONE,
2741 {(char_u *)NULL, (char_u *)0L}
2742#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002743 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002744 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002745#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002746 (char_u *)&p_twt, PV_NONE,
2747 {(char_u *)"", (char_u *)NULL}
2748#else
2749 (char_u *)NULL, PV_NONE,
2750 {(char_u *)NULL, (char_u *)0L}
2751#endif
2752 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002753 {"terse", NULL, P_BOOL|P_VI_DEF,
2754 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002755 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002756 {"textauto", "ta", P_BOOL|P_VIM,
2757 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002758 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002759 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2761 (char_u *)&p_tx, PV_TX,
2762 {
2763#ifdef USE_CRNL
2764 (char_u *)TRUE,
2765#else
2766 (char_u *)FALSE,
2767#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002768 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002769 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002770 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002771 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002772 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002773 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002774 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002775 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2776 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002777 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 {"timeout", "to", P_BOOL|P_VI_DEF,
2779 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002780 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002781 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2782 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002783 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002784 {"title", NULL, P_BOOL|P_VI_DEF,
2785#ifdef FEAT_TITLE
2786 (char_u *)&p_title, PV_NONE,
2787#else
2788 (char_u *)NULL, PV_NONE,
2789#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002790 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002791 {"titlelen", NULL, P_NUM|P_VI_DEF,
2792#ifdef FEAT_TITLE
2793 (char_u *)&p_titlelen, PV_NONE,
2794#else
2795 (char_u *)NULL, PV_NONE,
2796#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002797 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002798 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799#ifdef FEAT_TITLE
2800 (char_u *)&p_titleold, PV_NONE,
2801 {(char_u *)N_("Thanks for flying Vim"),
2802 (char_u *)0L}
2803#else
2804 (char_u *)NULL, PV_NONE,
2805 {(char_u *)0L, (char_u *)0L}
2806#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002807 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002808 {"titlestring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002809#ifdef FEAT_TITLE
2810 (char_u *)&p_titlestring, PV_NONE,
2811#else
2812 (char_u *)NULL, PV_NONE,
2813#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002814 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002815 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002816#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002818 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002819#else
2820 (char_u *)NULL, PV_NONE,
2821 {(char_u *)0L, (char_u *)0L}
2822#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002823 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002824 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002825#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002826 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002827 {(char_u *)"small", (char_u *)0L}
2828#else
2829 (char_u *)NULL, PV_NONE,
2830 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002831#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002832 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002833 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2834 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002835 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002836 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2837 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002838 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2840 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002841 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2843 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002844 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002845 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2846#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2847 (char_u *)&p_ttym, PV_NONE,
2848#else
2849 (char_u *)NULL, PV_NONE,
2850#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002851 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002852 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2853 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002854 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002855 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2856 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002857 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002858 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2859 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002860#ifdef FEAT_PERSISTENT_UNDO
2861 (char_u *)&p_udir, PV_NONE,
2862 {(char_u *)".", (char_u *)0L}
2863#else
2864 (char_u *)NULL, PV_NONE,
2865 {(char_u *)0L, (char_u *)0L}
2866#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002867 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002868 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2869#ifdef FEAT_PERSISTENT_UNDO
2870 (char_u *)&p_udf, PV_UDF,
2871#else
2872 (char_u *)NULL, PV_NONE,
2873#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002874 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002875 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002876 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002877 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002878#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002879 (char_u *)1000L,
2880#else
2881 (char_u *)100L,
2882#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002883 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002884 {"undoreload", "ur", P_NUM|P_VI_DEF,
2885 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002886 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 {"updatecount", "uc", P_NUM|P_VI_DEF,
2888 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002889 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 {"updatetime", "ut", P_NUM|P_VI_DEF,
2891 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002892 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002893 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2894#ifdef FEAT_VARTABS
2895 (char_u *)&p_vsts, PV_VSTS,
2896 {(char_u *)"", (char_u *)0L}
2897#else
2898 (char_u *)NULL, PV_NONE,
2899 {(char_u *)"", (char_u *)NULL}
2900#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002901 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002902 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2903#ifdef FEAT_VARTABS
2904 (char_u *)&p_vts, PV_VTS,
2905 {(char_u *)"", (char_u *)0L}
2906#else
2907 (char_u *)NULL, PV_NONE,
2908 {(char_u *)"", (char_u *)NULL}
2909#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002910 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002911 {"verbose", "vbs", P_NUM|P_VI_DEF,
2912 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002913 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002914 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2915 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002916 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002917 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2918#ifdef FEAT_SESSION
2919 (char_u *)&p_vdir, PV_NONE,
2920 {(char_u *)DFLT_VDIR, (char_u *)0L}
2921#else
2922 (char_u *)NULL, PV_NONE,
2923 {(char_u *)0L, (char_u *)0L}
2924#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002925 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002926 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002927#ifdef FEAT_SESSION
2928 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002929 {(char_u *)"folds,options,cursor,curdir",
2930 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002931#else
2932 (char_u *)NULL, PV_NONE,
2933 {(char_u *)0L, (char_u *)0L}
2934#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002935 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002936 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002937#ifdef FEAT_VIMINFO
2938 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002939#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002940 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002941#else
2942# ifdef AMIGA
2943 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002944 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002946 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002947# endif
2948#endif
2949#else
2950 (char_u *)NULL, PV_NONE,
2951 {(char_u *)0L, (char_u *)0L}
2952#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002953 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002954 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2955 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002956#ifdef FEAT_VIMINFO
2957 (char_u *)&p_viminfofile, PV_NONE,
2958 {(char_u *)"", (char_u *)0L}
2959#else
2960 (char_u *)NULL, PV_NONE,
2961 {(char_u *)0L, (char_u *)0L}
2962#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002963 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002964 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2965 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002966 (char_u *)&p_ve, PV_NONE,
2967 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002968 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002969 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2970 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002971 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002972 {"w300", 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 {"w1200", 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 {"w9600", NULL, P_NUM|P_VI_DEF,
2979 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002980 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002981 {"warn", NULL, P_BOOL|P_VI_DEF,
2982 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002983 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002984 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2985 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002986 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002987 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002988 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002989 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002990 {"wildchar", "wc", P_NUM|P_VIM,
2991 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002992 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002993 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01002994 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002996 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002997 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998#ifdef FEAT_WILDIGN
2999 (char_u *)&p_wig, PV_NONE,
3000#else
3001 (char_u *)NULL, PV_NONE,
3002#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003003 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003004 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3005 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003006 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003007 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3008#ifdef FEAT_WILDMENU
3009 (char_u *)&p_wmnu, PV_NONE,
3010#else
3011 (char_u *)NULL, PV_NONE,
3012#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003013 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003014 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003016 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003017 {"wildoptions", "wop", P_STRING|P_VI_DEF,
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003018 (char_u *)&p_wop, PV_NONE,
3019 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003020 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003021 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3022#ifdef FEAT_WAK
3023 (char_u *)&p_wak, PV_NONE,
3024 {(char_u *)"menu", (char_u *)0L}
3025#else
3026 (char_u *)NULL, PV_NONE,
3027 {(char_u *)NULL, (char_u *)0L}
3028#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003029 SCTX_INIT},
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003030 {"wincolor", "wcr", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
3031 (char_u *)VAR_WIN, PV_WCR,
3032 {(char_u *)"", (char_u *)NULL}
3033 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003034 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003035 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003036 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003038 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003039 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003040 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003041 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003042 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003043 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003044 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003045 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003047 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003048 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003051 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003052 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003053#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003054 (char_u *)&p_winptydll, PV_NONE, {
3055# ifdef _WIN64
3056 (char_u *)"winpty64.dll",
3057# else
3058 (char_u *)"winpty32.dll",
3059# endif
3060 (char_u *)0L}
3061#else
3062 (char_u *)NULL, PV_NONE,
3063 {(char_u *)0L, (char_u *)0L}
3064#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003065 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003067 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003068 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003069 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3070 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003071 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003072 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3073 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003074 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3076 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003077 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003078 {"write", NULL, P_BOOL|P_VI_DEF,
3079 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003080 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003081 {"writeany", "wa", P_BOOL|P_VI_DEF,
3082 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003083 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003084 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3085 (char_u *)&p_wb, PV_NONE,
3086 {
3087#ifdef FEAT_WRITEBACKUP
3088 (char_u *)TRUE,
3089#else
3090 (char_u *)FALSE,
3091#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003092 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003093 {"writedelay", "wd", P_NUM|P_VI_DEF,
3094 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003095 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003096
3097/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003098#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003099 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003100 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101
3102 p_term("t_AB", T_CAB)
3103 p_term("t_AF", T_CAF)
3104 p_term("t_AL", T_CAL)
3105 p_term("t_al", T_AL)
3106 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003107 p_term("t_BE", T_BE)
3108 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 p_term("t_cd", T_CD)
3110 p_term("t_ce", T_CE)
3111 p_term("t_cl", T_CL)
3112 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003113 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003114 p_term("t_Co", T_CCO)
3115 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003116 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003118 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003119 p_term("t_da", T_DA)
3120 p_term("t_db", T_DB)
3121 p_term("t_DL", T_CDL)
3122 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003123 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003124 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003126 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 p_term("t_IE", T_CIE)
3128 p_term("t_IS", T_CIS)
3129 p_term("t_ke", T_KE)
3130 p_term("t_ks", T_KS)
3131 p_term("t_le", T_LE)
3132 p_term("t_mb", T_MB)
3133 p_term("t_md", T_MD)
3134 p_term("t_me", T_ME)
3135 p_term("t_mr", T_MR)
3136 p_term("t_ms", T_MS)
3137 p_term("t_nd", T_ND)
3138 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003139 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003140 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003141 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003142 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003143 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003144 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003145 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003146 p_term("t_RV", T_CRV)
3147 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003148 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003149 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003150 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003151 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003152 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003153 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003155 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003156 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003157 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003158 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003159 p_term("t_te", T_TE)
3160 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003161 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003162 p_term("t_ts", T_TS)
3163 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_ue", T_UE)
3165 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003166 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 p_term("t_vb", T_VB)
3168 p_term("t_ve", T_VE)
3169 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003170 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003171 p_term("t_vs", T_VS)
3172 p_term("t_WP", T_CWP)
3173 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003174 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 p_term("t_xs", T_XS)
3176 p_term("t_ZH", T_CZH)
3177 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003178 p_term("t_8f", T_8F)
3179 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180
3181/* terminal key codes are not in here */
3182
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003183 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003184 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003185};
3186
3187#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3188
Bram Moolenaar071d4272004-06-13 20:20:40 +00003189static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003190static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003191static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003192static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003193#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003194static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003195#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003196static char *(p_wop_values[]) = {"tagfile", NULL};
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 Moolenaar4d784b22019-05-25 19:51:39 +02003210static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", 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 Moolenaar576a4a62019-08-18 15:25:17 +02003221static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL};
Bram Moolenaare2c453d2019-08-21 14:37:09 +02003222#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +02003223static char *(p_csl_values[]) = {"slash", "backslash", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003224#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003225#ifdef FEAT_SIGNS
Bram Moolenaar394c5d82019-06-17 21:48:05 +02003226static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003227#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003228#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003229static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003230#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003231
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003232static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003233static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003234static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003235static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003236static char_u *option_expand(int opt_idx, char_u *val);
3237static void didset_options(void);
3238static void didset_options2(void);
3239static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003240#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003241static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003242#else
3243# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3244#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003245static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003246static 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);
3247static char *set_chars_option(char_u **varp);
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02003248#ifdef FEAT_STL_OPT
3249static char *check_stl_option(char_u *s);
3250#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003251#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003252static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003253#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003254#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003255static char *did_set_spell_option(int is_spellfile);
3256static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003257#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003258#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003259static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003260#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003261static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3262static char *set_num_option(int opt_idx, char_u *varp, long value, char *errbuf, size_t errbuflen, int opt_flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static void check_redraw(long_u flags);
3264static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003265static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003266static void showoptions(int all, int opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003267static int optval_default(struct vimoption *, char_u *varp, int compatible);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003268static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003269static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003270static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3271static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3272static int istermoption(struct vimoption *);
3273static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3274static char_u *get_varp(struct vimoption *);
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02003275static void check_win_options(win_T *win);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static void option_value2string(struct vimoption *, int opt_flags);
3277static void check_winopt(winopt_T *wop);
3278static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003279#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static void langmap_init(void);
3281static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003282#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static void paste_option_changed(void);
3284static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003286static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003288static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3289static int check_opt_strings(char_u *val, char **values, int);
3290static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003291#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003292static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294
3295/*
3296 * Initialize the options, first part.
3297 *
3298 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003299 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300 */
3301 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003302set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003303{
3304 char_u *p;
3305 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003306 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307
3308#ifdef FEAT_LANGMAP
3309 langmap_init();
3310#endif
3311
3312 /* Be Vi compatible by default */
3313 p_cp = TRUE;
3314
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003315 /* Use POSIX compatibility when $VIM_POSIX is set. */
3316 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003317 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003318 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003319 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003320 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003321
Bram Moolenaar071d4272004-06-13 20:20:40 +00003322 /*
3323 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003324 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003325 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003326 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003327#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003328 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003329 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003330#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003331 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003332 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003333
3334#ifdef FEAT_WILDIGN
3335 /*
3336 * Set the default for 'backupskip' to include environment variables for
3337 * temp files.
3338 */
3339 {
3340# ifdef UNIX
3341 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3342# else
3343 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3344# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003345 int len;
3346 garray_T ga;
3347 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003348
3349 ga_init2(&ga, 1, 100);
3350 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3351 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003352 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003353# ifdef UNIX
3354 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003355# ifdef MACOS_X
3356 p = (char_u *)"/private/tmp";
3357# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003359# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360 else
3361# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003362 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003363 if (p != NULL && *p != NUL)
3364 {
3365 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003366 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003367 if (ga_grow(&ga, len) == OK)
3368 {
3369 if (ga.ga_len > 0)
3370 STRCAT(ga.ga_data, ",");
3371 STRCAT(ga.ga_data, p);
3372 add_pathsep(ga.ga_data);
3373 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003374 ga.ga_len += len;
3375 }
3376 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003377 if (mustfree)
3378 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003379 }
3380 if (ga.ga_data != NULL)
3381 {
3382 set_string_default("bsk", ga.ga_data);
3383 vim_free(ga.ga_data);
3384 }
3385 }
3386#endif
3387
3388 /*
3389 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3390 */
3391 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003392 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003393 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003394#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3395 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3396#endif
3397 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003399 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003400 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003401#else
3402# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003403 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003404 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003405# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003406 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407# endif
3408#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003410 opt_idx = findoption((char_u *)"maxmem");
3411 if (opt_idx >= 0)
3412 {
3413#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003414 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3415 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003416#endif
3417 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3418 }
3419 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420 }
3421
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422#ifdef FEAT_SEARCHPATH
3423 {
3424 char_u *cdpath;
3425 char_u *buf;
3426 int i;
3427 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003428 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003429
3430 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003431 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003432 if (cdpath != NULL)
3433 {
Bram Moolenaar964b3742019-05-24 18:54:09 +02003434 buf = alloc((STRLEN(cdpath) << 1) + 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435 if (buf != NULL)
3436 {
3437 buf[0] = ','; /* start with ",", current dir first */
3438 j = 1;
3439 for (i = 0; cdpath[i] != NUL; ++i)
3440 {
3441 if (vim_ispathlistsep(cdpath[i]))
3442 buf[j++] = ',';
3443 else
3444 {
3445 if (cdpath[i] == ' ' || cdpath[i] == ',')
3446 buf[j++] = '\\';
3447 buf[j++] = cdpath[i];
3448 }
3449 }
3450 buf[j] = NUL;
3451 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003452 if (opt_idx >= 0)
3453 {
3454 options[opt_idx].def_val[VI_DEFAULT] = buf;
3455 options[opt_idx].flags |= P_DEF_ALLOCED;
3456 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003457 else
3458 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003459 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003460 if (mustfree)
3461 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003462 }
3463 }
3464#endif
3465
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003466#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003467 /* Set print encoding on platforms that don't default to latin1 */
3468 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003469# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003470 (char_u *)"cp1252"
3471# else
3472# ifdef VMS
3473 (char_u *)"dec-mcs"
3474# else
3475# ifdef EBCDIC
3476 (char_u *)"ebcdic-uk"
3477# else
3478# ifdef MAC
3479 (char_u *)"mac-roman"
3480# else /* HPUX */
3481 (char_u *)"hp-roman8"
3482# endif
3483# endif
3484# endif
3485# endif
3486 );
3487#endif
3488
3489#ifdef FEAT_POSTSCRIPT
3490 /* 'printexpr' must be allocated to be able to evaluate it. */
3491 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003492# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003493 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003494# else
3495# ifdef VMS
3496 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3497
3498# else
3499 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3500# endif
3501# endif
3502 );
3503#endif
3504
3505 /*
3506 * Set all the options (except the terminal options) to their default
3507 * value. Also set the global value for local options.
3508 */
3509 set_options_default(0);
3510
Bram Moolenaar07268702018-03-01 21:57:32 +01003511#ifdef CLEAN_RUNTIMEPATH
3512 if (clean_arg)
3513 {
3514 opt_idx = findoption((char_u *)"runtimepath");
3515 if (opt_idx >= 0)
3516 {
3517 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3518 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3519 }
3520 opt_idx = findoption((char_u *)"packpath");
3521 if (opt_idx >= 0)
3522 {
3523 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3524 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3525 }
3526 }
3527#endif
3528
Bram Moolenaar071d4272004-06-13 20:20:40 +00003529#ifdef FEAT_GUI
3530 if (found_reverse_arg)
3531 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3532#endif
3533
3534 curbuf->b_p_initialized = TRUE;
3535 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003536 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003537 check_buf_options(curbuf);
3538 check_win_options(curwin);
3539 check_options();
3540
3541 /* Must be before option_expand(), because that one needs vim_isIDc() */
3542 didset_options();
3543
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003544#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003545 /* Use the current chartab for the generic chartab. This is not in
3546 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003547 init_spell_chartab();
3548#endif
3549
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550 /*
3551 * Expand environment variables and things like "~" for the defaults.
3552 * If option_expand() returns non-NULL the variable is expanded. This can
3553 * only happen for non-indirect options.
3554 * Also set the default to the expanded value, so ":set" does not list
3555 * them.
3556 * Don't set the P_ALLOCED flag, because we don't want to free the
3557 * default.
3558 */
3559 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3560 {
3561 if ((options[opt_idx].flags & P_GETTEXT)
3562 && options[opt_idx].var != NULL)
3563 p = (char_u *)_(*(char **)options[opt_idx].var);
3564 else
3565 p = option_expand(opt_idx, NULL);
3566 if (p != NULL && (p = vim_strsave(p)) != NULL)
3567 {
3568 *(char_u **)options[opt_idx].var = p;
3569 /* VIMEXP
3570 * Defaults for all expanded options are currently the same for Vi
3571 * and Vim. When this changes, add some code here! Also need to
3572 * split P_DEF_ALLOCED in two.
3573 */
3574 if (options[opt_idx].flags & P_DEF_ALLOCED)
3575 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3576 options[opt_idx].def_val[VI_DEFAULT] = p;
3577 options[opt_idx].flags |= P_DEF_ALLOCED;
3578 }
3579 }
3580
Bram Moolenaar071d4272004-06-13 20:20:40 +00003581 save_file_ff(curbuf); /* Buffer is unchanged */
3582
Bram Moolenaar071d4272004-06-13 20:20:40 +00003583#if defined(FEAT_ARABIC)
3584 /* Detect use of mlterm.
3585 * Mlterm is a terminal emulator akin to xterm that has some special
3586 * abilities (bidi namely).
3587 * NOTE: mlterm's author is being asked to 'set' a variable
3588 * instead of an environment variable due to inheritance.
3589 */
3590 if (mch_getenv((char_u *)"MLTERM") != NULL)
3591 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3592#endif
3593
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003594 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003595
Bram Moolenaar4f974752019-02-17 17:44:42 +01003596# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597 /*
3598 * If $LANG isn't set, try to get a good value for it. This makes the
3599 * right language be used automatically. Don't do this for English.
3600 */
3601 if (mch_getenv((char_u *)"LANG") == NULL)
3602 {
3603 char buf[20];
3604
3605 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3606 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3607 * only the first two. */
3608 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3609 (LPTSTR)buf, 20);
3610 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3611 {
3612 /* There are a few exceptions (probably more) */
3613 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3614 STRCPY(buf, "zh_TW");
3615 else if (STRNICMP(buf, "chs", 3) == 0
3616 || STRNICMP(buf, "zhc", 3) == 0)
3617 STRCPY(buf, "zh_CN");
3618 else if (STRNICMP(buf, "jp", 2) == 0)
3619 STRCPY(buf, "ja");
3620 else
3621 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003622 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003623 }
3624 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003625# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003626# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003627 /* Moved to os_mac_conv.c to avoid dependency problems. */
3628 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003629# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003630# endif
3631
3632 /* enc_locale() will try to find the encoding of the current locale. */
3633 p = enc_locale();
3634 if (p != NULL)
3635 {
3636 char_u *save_enc;
3637
3638 /* Try setting 'encoding' and check if the value is valid.
3639 * If not, go back to the default "latin1". */
3640 save_enc = p_enc;
3641 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003642 if (STRCMP(p_enc, "gb18030") == 0)
3643 {
3644 /* We don't support "gb18030", but "cp936" is a good substitute
3645 * for practical purposes, thus use that. It's not an alias to
3646 * still support conversion between gb18030 and utf-8. */
3647 p_enc = vim_strsave((char_u *)"cp936");
3648 vim_free(p);
3649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003650 if (mb_init() == NULL)
3651 {
3652 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003653 if (opt_idx >= 0)
3654 {
3655 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3656 options[opt_idx].flags |= P_DEF_ALLOCED;
3657 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003658
Bram Moolenaard0573012017-10-28 21:11:06 +02003659#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003660 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003661 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003662 /* Adjust the default for 'isprint' and 'iskeyword' to match
3663 * latin1. Also set the defaults for when 'nocompatible' is
3664 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003665 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003666 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003667 set_string_option_direct((char_u *)"isk", -1,
3668 ISK_LATIN1, OPT_FREE, SID_NONE);
3669 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003670 if (opt_idx >= 0)
3671 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003672 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003673 if (opt_idx >= 0)
3674 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003675 (void)init_chartab();
3676 }
3677#endif
3678
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003679#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003680 /* Win32 console: When GetACP() returns a different value from
3681 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003682 if (
3683# ifdef VIMDLL
3684 (!gui.in_use && !gui.starting) &&
3685# endif
3686 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687 {
3688 char buf[50];
3689
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003690 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3691 * Use an alternative value. */
3692 if (GetConsoleCP() == 0)
3693 sprintf(buf, "cp%ld", (long)GetACP());
3694 else
3695 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 p_tenc = vim_strsave((char_u *)buf);
3697 if (p_tenc != NULL)
3698 {
3699 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003700 if (opt_idx >= 0)
3701 {
3702 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3703 options[opt_idx].flags |= P_DEF_ALLOCED;
3704 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003705 convert_setup(&input_conv, p_tenc, p_enc);
3706 convert_setup(&output_conv, p_enc, p_tenc);
3707 }
3708 else
3709 p_tenc = empty_option;
3710 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003711#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003712#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003713 /* $HOME may have characters in active code page. */
3714 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003715#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003716 }
3717 else
3718 {
3719 vim_free(p_enc);
3720 p_enc = save_enc;
3721 }
3722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003723
3724#ifdef FEAT_MULTI_LANG
3725 /* Set the default for 'helplang'. */
3726 set_helplang_default(get_mess_lang());
3727#endif
3728}
3729
3730/*
3731 * Set an option to its default value.
3732 * This does not take care of side effects!
3733 */
3734 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003735set_option_default(
3736 int opt_idx,
3737 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3738 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003739{
3740 char_u *varp; /* pointer to variable for current option */
3741 int dvi; /* index in def_val[] */
3742 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003743 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003744 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3745
3746 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3747 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003748 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003749 {
3750 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3751 if (flags & P_STRING)
3752 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003753 /* Use set_string_option_direct() for local options to handle
3754 * freeing and allocating the value. */
3755 if (options[opt_idx].indir != PV_NONE)
3756 set_string_option_direct(NULL, opt_idx,
3757 options[opt_idx].def_val[dvi], opt_flags, 0);
3758 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003759 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003760 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3761 free_string_option(*(char_u **)(varp));
3762 *(char_u **)varp = options[opt_idx].def_val[dvi];
3763 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003764 }
3765 }
3766 else if (flags & P_NUM)
3767 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003768 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003769 win_comp_scroll(curwin);
3770 else
3771 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003772 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3773
3774 if ((long *)varp == &curwin->w_p_so
3775 || (long *)varp == &curwin->w_p_siso)
3776 // 'scrolloff' and 'sidescrolloff' local values have a
3777 // different default value than the global default.
3778 *(long *)varp = -1;
3779 else
3780 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003781 /* May also set global value for local option. */
3782 if (both)
3783 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003784 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003785 }
3786 }
3787 else /* P_BOOL */
3788 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003789 /* the cast to long is required for Manx C, long_i is needed for
3790 * MSVC */
3791 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003792#ifdef UNIX
3793 /* 'modeline' defaults to off for root */
3794 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3795 *(int *)varp = FALSE;
3796#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 /* May also set global value for local option. */
3798 if (both)
3799 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3800 *(int *)varp;
3801 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003802
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003803 /* The default value is not insecure. */
3804 flagsp = insecure_flag(opt_idx, opt_flags);
3805 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003806 }
3807
3808#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003809 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810#endif
3811}
3812
3813/*
3814 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003815 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003816 */
3817 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003818set_options_default(
3819 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003820{
3821 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003823 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824
3825 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003826 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003827 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003828 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003829# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003830 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003831 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003832# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003833 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003834 set_option_default(i, opt_flags, p_cp);
3835
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003837 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003839#ifdef FEAT_CINDENT
3840 parse_cino(curbuf);
3841#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842}
3843
3844/*
3845 * Set the Vi-default value of a string option.
3846 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003847 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003848 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003849 static void
3850set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851{
3852 char_u *p;
3853 int opt_idx;
3854
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003855 if (escape && vim_strchr(val, ' ') != NULL)
3856 p = vim_strsave_escaped(val, (char_u *)" ");
3857 else
3858 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003859 if (p != NULL) /* we don't want a NULL */
3860 {
3861 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003862 if (opt_idx >= 0)
3863 {
3864 if (options[opt_idx].flags & P_DEF_ALLOCED)
3865 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3866 options[opt_idx].def_val[VI_DEFAULT] = p;
3867 options[opt_idx].flags |= P_DEF_ALLOCED;
3868 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869 }
3870}
3871
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003872 void
3873set_string_default(char *name, char_u *val)
3874{
3875 set_string_default_esc(name, val, FALSE);
3876}
3877
Bram Moolenaar071d4272004-06-13 20:20:40 +00003878/*
3879 * Set the Vi-default value of a number option.
3880 * Used for 'lines' and 'columns'.
3881 */
3882 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003883set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003884{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003885 int opt_idx;
3886
3887 opt_idx = findoption((char_u *)name);
3888 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003889 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003890}
3891
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003892/*
3893 * Set all window-local and buffer-local options to the Vim default.
3894 * local-global options will use the global value.
Bram Moolenaar46451042019-08-24 15:50:46 +02003895 * When "do_buffer" is FALSE don't set buffer-local options.
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003896 */
3897 void
Bram Moolenaar46451042019-08-24 15:50:46 +02003898set_local_options_default(win_T *wp, int do_buffer)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003899{
3900 win_T *save_curwin = curwin;
3901 int i;
3902
3903 curwin = wp;
3904 curbuf = curwin->w_buffer;
3905 block_autocmds();
3906
3907 for (i = 0; !istermoption(&options[i]); i++)
3908 {
3909 struct vimoption *p = &(options[i]);
3910 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3911
3912 if (p->indir != PV_NONE
Bram Moolenaar46451042019-08-24 15:50:46 +02003913 && (do_buffer || (p->indir & PV_BUF) == 0)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003914 && !(options[i].flags & P_NODEFAULT)
3915 && !optval_default(p, varp, FALSE))
3916 set_option_default(i, OPT_LOCAL, FALSE);
3917 }
3918
3919 unblock_autocmds();
3920 curwin = save_curwin;
3921 curbuf = curwin->w_buffer;
3922}
3923
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003924#if defined(EXITFREE) || defined(PROTO)
3925/*
3926 * Free all options.
3927 */
3928 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003929free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003930{
3931 int i;
3932
3933 for (i = 0; !istermoption(&options[i]); i++)
3934 {
3935 if (options[i].indir == PV_NONE)
3936 {
3937 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003938 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003939 free_string_option(*(char_u **)options[i].var);
3940 if (options[i].flags & P_DEF_ALLOCED)
3941 free_string_option(options[i].def_val[VI_DEFAULT]);
3942 }
3943 else if (options[i].var != VAR_WIN
3944 && (options[i].flags & P_STRING))
3945 /* buffer-local option: free global value */
3946 free_string_option(*(char_u **)options[i].var);
3947 }
3948}
3949#endif
3950
3951
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952/*
3953 * Initialize the options, part two: After getting Rows and Columns and
3954 * setting 'term'.
3955 */
3956 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003957set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003958{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003959 int idx;
3960
Bram Moolenaar071d4272004-06-13 20:20:40 +00003961 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003962 * 'scroll' defaults to half the window height. The stored default is zero,
3963 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003964 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003965 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003966 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003967 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003968 comp_col();
3969
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003970 /*
3971 * 'window' is only for backwards compatibility with Vi.
3972 * Default is Rows - 1.
3973 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003974 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003975 p_window = Rows - 1;
3976 set_number_default("window", Rows - 1);
3977
Bram Moolenaarf740b292006-02-16 22:11:02 +00003978 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003979#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003980 /*
3981 * If 'background' wasn't set by the user, try guessing the value,
3982 * depending on the terminal name. Only need to check for terminals
3983 * with a dark background, that can handle color.
3984 */
3985 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003986 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3987 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003988 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003989 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003990 /* don't mark it as set, when starting the GUI it may be
3991 * changed again */
3992 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003993 }
3994#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003995
3996#ifdef CURSOR_SHAPE
3997 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3998#endif
3999#ifdef FEAT_MOUSESHAPE
4000 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4001#endif
4002#ifdef FEAT_PRINTER
4003 (void)parse_printoptions(); /* parse 'printoptions' default value */
4004#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004005}
4006
4007/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004008 * Return "dark" or "light" depending on the kind of terminal.
4009 * This is just guessing! Recognized are:
4010 * "linux" Linux console
4011 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004012 * "cygwin.*" Cygwin shell
4013 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004014 * We also check the COLORFGBG environment variable, which is set by
4015 * rxvt and derivatives. This variable contains either two or three
4016 * values separated by semicolons; we want the last value in either
4017 * case. If this value is 0-6 or 8, our background is dark.
4018 */
4019 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004020term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004021{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004022#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004023 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004024 return (char_u *)"dark";
4025#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004026 char_u *p;
4027
Bram Moolenaarf740b292006-02-16 22:11:02 +00004028 if (STRCMP(T_NAME, "linux") == 0
4029 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004030 || STRNCMP(T_NAME, "cygwin", 6) == 0
4031 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004032 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4033 && (p = vim_strrchr(p, ';')) != NULL
4034 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4035 && p[2] == NUL))
4036 return (char_u *)"dark";
4037 return (char_u *)"light";
4038#endif
4039}
4040
4041/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004042 * Initialize the options, part three: After reading the .vimrc
4043 */
4044 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004045set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004047#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048/*
4049 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4050 * This is done after other initializations, where 'shell' might have been
4051 * set, but only if they have not been set before.
4052 */
4053 char_u *p;
4054 int idx_srr;
4055 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004056# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057 int idx_sp;
4058 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004059# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004060
4061 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004062 if (idx_srr < 0)
4063 do_srr = FALSE;
4064 else
4065 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004066# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004067 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004068 if (idx_sp < 0)
4069 do_sp = FALSE;
4070 else
4071 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004072# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004073 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 if (p != NULL)
4075 {
4076 /*
4077 * Default for p_sp is "| tee", for p_srr is ">".
4078 * For known shells it is changed here to include stderr.
4079 */
4080 if ( fnamecmp(p, "csh") == 0
4081 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004082# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 || fnamecmp(p, "csh.exe") == 0
4084 || fnamecmp(p, "tcsh.exe") == 0
4085# endif
4086 )
4087 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004088# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004089 if (do_sp)
4090 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004091# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004095# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4097 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004098# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004099 if (do_srr)
4100 {
4101 p_srr = (char_u *)">&";
4102 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4103 }
4104 }
4105 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004106 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 if ( fnamecmp(p, "sh") == 0
4108 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004109 || fnamecmp(p, "mksh") == 0
4110 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004112 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004114 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004115# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116 || fnamecmp(p, "cmd") == 0
4117 || fnamecmp(p, "sh.exe") == 0
4118 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004119 || fnamecmp(p, "mksh.exe") == 0
4120 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004122 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 || fnamecmp(p, "bash.exe") == 0
4124 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004126 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004128# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 if (do_sp)
4130 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004131# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004133# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004135# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4137 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004138# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004139 if (do_srr)
4140 {
4141 p_srr = (char_u *)">%s 2>&1";
4142 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4143 }
4144 }
4145 vim_free(p);
4146 }
4147#endif
4148
Bram Moolenaar4f974752019-02-17 17:44:42 +01004149#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004151 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4152 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004153 * This is done after other initializations, where 'shell' might have been
4154 * set, but only if they have not been set before. Default for p_shcf is
4155 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004156 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004158 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004159 {
4160 int idx3;
4161
4162 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004163 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164 {
4165 p_shcf = (char_u *)"-c";
4166 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4167 }
4168
Bram Moolenaar071d4272004-06-13 20:20:40 +00004169 /* Somehow Win32 requires the quotes around the redirection too */
4170 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004171 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004172 {
4173 p_sxq = (char_u *)"\"";
4174 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4175 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004176 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004177 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4178 {
4179 int idx3;
4180
4181 /*
4182 * cmd.exe on Windows will strip the first and last double quote given
4183 * on the command line, e.g. most of the time things like:
4184 * cmd /c "my path/to/echo" "my args to echo"
4185 * become:
4186 * my path/to/echo" "my args to echo
4187 * when executed.
4188 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004189 * To avoid this, set shellxquote to surround the command in
4190 * parenthesis. This appears to make most commands work, without
4191 * breaking commands that worked previously, such as
4192 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004193 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004194 idx3 = findoption((char_u *)"sxq");
4195 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4196 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004197 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004198 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4199 }
4200
Bram Moolenaara64ba222012-02-12 23:23:31 +01004201 idx3 = findoption((char_u *)"shcf");
4202 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4203 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004204 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004205 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4206 }
4207 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004208#endif
4209
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004210 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004211 {
4212 int idx_ffs = findoption((char_u *)"ffs");
4213
4214 /* Apply the first entry of 'fileformats' to the initial buffer. */
4215 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4216 set_fileformat(default_fileformat(), OPT_LOCAL);
4217 }
4218
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219#ifdef FEAT_TITLE
4220 set_title_defaults();
4221#endif
4222}
4223
4224#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4225/*
4226 * When 'helplang' is still at its default value, set it to "lang".
4227 * Only the first two characters of "lang" are used.
4228 */
4229 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004230set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004231{
4232 int idx;
4233
4234 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4235 return;
4236 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004237 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004238 {
4239 if (options[idx].flags & P_ALLOCED)
4240 free_string_option(p_hlg);
4241 p_hlg = vim_strsave(lang);
4242 if (p_hlg == NULL)
4243 p_hlg = empty_option;
4244 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004245 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004246 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004247 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4248 {
4249 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4250 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4251 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004252 // any C like setting, such as C.UTF-8, becomes "en"
4253 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4254 {
4255 p_hlg[0] = 'e';
4256 p_hlg[1] = 'n';
4257 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004258 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260 options[idx].flags |= P_ALLOCED;
4261 }
4262}
4263#endif
4264
4265#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004266 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004267gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268{
4269 if (gui_get_lightness(gui.back_pixel) < 127)
4270 return (char_u *)"dark";
4271 return (char_u *)"light";
4272}
4273
4274/*
4275 * Option initializations that can only be done after opening the GUI window.
4276 */
4277 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004278init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279{
4280 /* Set the 'background' option according to the lightness of the
4281 * background color, unless the user has set it already. */
4282 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4283 {
4284 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4285 highlight_changed();
4286 }
4287}
4288#endif
4289
4290#ifdef FEAT_TITLE
4291/*
4292 * 'title' and 'icon' only default to true if they have not been set or reset
4293 * in .vimrc and we can read the old value.
4294 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4295 * they can be reset. This reduces startup time when using X on a remote
4296 * machine.
4297 */
4298 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004299set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004300{
4301 int idx1;
4302 long val;
4303
4304 /*
4305 * If GUI is (going to be) used, we can always set the window title and
4306 * icon name. Saves a bit of time, because the X11 display server does
4307 * not need to be contacted.
4308 */
4309 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004310 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311 {
4312#ifdef FEAT_GUI
4313 if (gui.starting || gui.in_use)
4314 val = TRUE;
4315 else
4316#endif
4317 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004318 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004319 p_title = val;
4320 }
4321 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004322 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004323 {
4324#ifdef FEAT_GUI
4325 if (gui.starting || gui.in_use)
4326 val = TRUE;
4327 else
4328#endif
4329 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004330 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004331 p_icon = val;
4332 }
4333}
4334#endif
4335
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004336#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02004337/*
4338 * Trigger the OptionSet autocommand.
4339 * "opt_idx" is the index of the option being set.
4340 * "opt_flags" can be OPT_LOCAL etc.
4341 * "oldval" the old value
4342 * "oldval_l" the old local value (only non-NULL if global and local value
4343 * are set)
4344 * "oldval_g" the old global value (only non-NULL if global and local value
4345 * are set)
4346 * "newval" the new value
4347 */
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004348 static void
4349trigger_optionsset_string(
4350 int opt_idx,
4351 int opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02004352 char_u *oldval,
4353 char_u *oldval_l,
4354 char_u *oldval_g,
4355 char_u *newval)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004356{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004357 // Don't do this recursively.
4358 if (oldval != NULL && newval != NULL
4359 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004360 {
4361 char_u buf_type[7];
4362
4363 sprintf((char *)buf_type, "%s",
4364 (opt_flags & OPT_LOCAL) ? "local" : "global");
4365 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4366 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4367 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02004368 if (opt_flags & OPT_LOCAL)
4369 {
4370 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
4371 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4372 }
4373 if (opt_flags & OPT_GLOBAL)
4374 {
4375 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
4376 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
4377 }
4378 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4379 {
4380 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
4381 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
4382 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
4383 }
4384 if (opt_flags & OPT_MODELINE)
4385 {
4386 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
4387 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4388 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004389 apply_autocmds(EVENT_OPTIONSET,
4390 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4391 reset_v_option_vars();
4392 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004393}
4394#endif
4395
Bram Moolenaar071d4272004-06-13 20:20:40 +00004396/*
4397 * Parse 'arg' for option settings.
4398 *
4399 * 'arg' may be IObuff, but only when no errors can be present and option
4400 * does not need to be expanded with option_expand().
4401 * "opt_flags":
4402 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004403 * OPT_GLOBAL for ":setglobal"
4404 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004405 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004406 * OPT_WINONLY to only set window-local options
4407 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004408 *
4409 * returns FAIL if an error is detected, OK otherwise
4410 */
4411 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004412do_set(
4413 char_u *arg, /* option string (may be written to!) */
4414 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004415{
4416 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004417 char *errmsg;
4418 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004419 char_u *startarg;
4420 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4421 int nextchar; /* next non-white char after option name */
4422 int afterchar; /* character just after option name */
4423 int len;
4424 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004425 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004426 int key;
4427 long_u flags; /* flags for current option */
4428 char_u *varp = NULL; /* pointer to variable for current option */
4429 int did_show = FALSE; /* already showed one value */
4430 int adding; /* "opt+=arg" */
4431 int prepending; /* "opt^=arg" */
4432 int removing; /* "opt-=arg" */
4433 int cp_val = 0;
4434 char_u key_name[2];
4435
4436 if (*arg == NUL)
4437 {
4438 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004439 did_show = TRUE;
4440 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004441 }
4442
4443 while (*arg != NUL) /* loop to process all options */
4444 {
4445 errmsg = NULL;
4446 startarg = arg; /* remember for error message */
4447
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004448 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4449 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004450 {
4451 /*
4452 * ":set all" show all options.
4453 * ":set all&" set all options to their default value.
4454 */
4455 arg += 3;
4456 if (*arg == '&')
4457 {
4458 ++arg;
4459 /* Only for :set command set global value of local options. */
4460 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004461 didset_options();
4462 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004463 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004464 }
4465 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004466 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004467 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004468 did_show = TRUE;
4469 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004470 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004471 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004472 {
4473 showoptions(2, opt_flags);
4474 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004475 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004476 arg += 7;
4477 }
4478 else
4479 {
4480 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004481 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004482 {
4483 prefix = 0;
4484 arg += 2;
4485 }
4486 else if (STRNCMP(arg, "inv", 3) == 0)
4487 {
4488 prefix = 2;
4489 arg += 3;
4490 }
4491
4492 /* find end of name */
4493 key = 0;
4494 if (*arg == '<')
4495 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004496 opt_idx = -1;
4497 /* look out for <t_>;> */
4498 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4499 len = 5;
4500 else
4501 {
4502 len = 1;
4503 while (arg[len] != NUL && arg[len] != '>')
4504 ++len;
4505 }
4506 if (arg[len] != '>')
4507 {
4508 errmsg = e_invarg;
4509 goto skip;
4510 }
4511 arg[len] = NUL; /* put NUL after name */
4512 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4513 opt_idx = findoption(arg + 1);
4514 arg[len++] = '>'; /* restore '>' */
4515 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004516 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004517 }
4518 else
4519 {
4520 len = 0;
4521 /*
4522 * The two characters after "t_" may not be alphanumeric.
4523 */
4524 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4525 len = 4;
4526 else
4527 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4528 ++len;
4529 nextchar = arg[len];
4530 arg[len] = NUL; /* put NUL after name */
4531 opt_idx = findoption(arg);
4532 arg[len] = nextchar; /* restore nextchar */
4533 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004534 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004535 }
4536
4537 /* remember character after option name */
4538 afterchar = arg[len];
4539
4540 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004541 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004542 ++len;
4543
4544 adding = FALSE;
4545 prepending = FALSE;
4546 removing = FALSE;
4547 if (arg[len] != NUL && arg[len + 1] == '=')
4548 {
4549 if (arg[len] == '+')
4550 {
4551 adding = TRUE; /* "+=" */
4552 ++len;
4553 }
4554 else if (arg[len] == '^')
4555 {
4556 prepending = TRUE; /* "^=" */
4557 ++len;
4558 }
4559 else if (arg[len] == '-')
4560 {
4561 removing = TRUE; /* "-=" */
4562 ++len;
4563 }
4564 }
4565 nextchar = arg[len];
4566
4567 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4568 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004569 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004570 goto skip;
4571 }
4572
4573 if (opt_idx >= 0)
4574 {
4575 if (options[opt_idx].var == NULL) /* hidden option: skip */
4576 {
4577 /* Only give an error message when requesting the value of
4578 * a hidden option, ignore setting it. */
4579 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4580 && (!(options[opt_idx].flags & P_BOOL)
4581 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004582 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004583 goto skip;
4584 }
4585
4586 flags = options[opt_idx].flags;
4587 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4588 }
4589 else
4590 {
4591 flags = P_STRING;
4592 if (key < 0)
4593 {
4594 key_name[0] = KEY2TERMCAP0(key);
4595 key_name[1] = KEY2TERMCAP1(key);
4596 }
4597 else
4598 {
4599 key_name[0] = KS_KEY;
4600 key_name[1] = (key & 0xff);
4601 }
4602 }
4603
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004604 /* Skip all options that are not window-local (used when showing
4605 * an already loaded buffer in a window). */
4606 if ((opt_flags & OPT_WINONLY)
4607 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4608 goto skip;
4609
Bram Moolenaara3227e22006-03-08 21:32:40 +00004610 /* Skip all options that are window-local (used for :vimgrep). */
4611 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4612 && options[opt_idx].var == VAR_WIN)
4613 goto skip;
4614
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004615 /* Disallow changing some options from modelines. */
4616 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004617 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004618 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004619 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004620 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004621 goto skip;
4622 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004623 if ((flags & P_MLE) && !p_mle)
4624 {
4625 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4626 goto skip;
4627 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004628#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004629 /* In diff mode some options are overruled. This avoids that
4630 * 'foldmethod' becomes "marker" instead of "diff" and that
4631 * "wrap" gets set. */
4632 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004633 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004634 && (
4635#ifdef FEAT_FOLDING
4636 options[opt_idx].indir == PV_FDM ||
4637#endif
4638 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004639 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004640#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004641 }
4642
4643#ifdef HAVE_SANDBOX
4644 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004645 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004646 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004647 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004648 goto skip;
4649 }
4650#endif
4651
4652 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4653 {
4654 arg += len;
4655 cp_val = p_cp;
4656 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4657 {
4658 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4659 {
4660 cp_val = FALSE;
4661 arg += 3;
4662 }
4663 else /* "opt&vi": set to Vi default */
4664 {
4665 cp_val = TRUE;
4666 arg += 2;
4667 }
4668 }
4669 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004670 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004671 {
4672 errmsg = e_trailing;
4673 goto skip;
4674 }
4675 }
4676
4677 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004678 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4679 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004680 */
4681 if (nextchar == '?'
4682 || (prefix == 1
4683 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4684 && !(flags & P_BOOL)))
4685 {
4686 /*
4687 * print value
4688 */
4689 if (did_show)
4690 msg_putchar('\n'); /* cursor below last one */
4691 else
4692 {
4693 gotocmdline(TRUE); /* cursor at status line */
4694 did_show = TRUE; /* remember that we did a line */
4695 }
4696 if (opt_idx >= 0)
4697 {
4698 showoneopt(&options[opt_idx], opt_flags);
4699#ifdef FEAT_EVAL
4700 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004701 {
4702 /* Mention where the option was last set. */
4703 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004704 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004705 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004706 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004707 (int)options[opt_idx].indir & PV_MASK]);
4708 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004709 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004710 (int)options[opt_idx].indir & PV_MASK]);
4711 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004712#endif
4713 }
4714 else
4715 {
4716 char_u *p;
4717
4718 p = find_termcode(key_name);
4719 if (p == NULL)
4720 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004721 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004722 goto skip;
4723 }
4724 else
4725 (void)show_one_termcode(key_name, p, TRUE);
4726 }
4727 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004728 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004729 errmsg = e_trailing;
4730 }
4731 else
4732 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004733 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004734 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004735
Bram Moolenaar071d4272004-06-13 20:20:40 +00004736 if (flags & P_BOOL) /* boolean */
4737 {
4738 if (nextchar == '=' || nextchar == ':')
4739 {
4740 errmsg = e_invarg;
4741 goto skip;
4742 }
4743
4744 /*
4745 * ":set opt!": invert
4746 * ":set opt&": reset to default value
4747 * ":set opt<": reset to global value
4748 */
4749 if (nextchar == '!')
4750 value = *(int *)(varp) ^ 1;
4751 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004752 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004753 ((flags & P_VI_DEF) || cp_val)
4754 ? VI_DEFAULT : VIM_DEFAULT];
4755 else if (nextchar == '<')
4756 {
4757 /* For 'autoread' -1 means to use global value. */
4758 if ((int *)varp == &curbuf->b_p_ar
4759 && opt_flags == OPT_LOCAL)
4760 value = -1;
4761 else
4762 value = *(int *)get_varp_scope(&(options[opt_idx]),
4763 OPT_GLOBAL);
4764 }
4765 else
4766 {
4767 /*
4768 * ":set invopt": invert
4769 * ":set opt" or ":set noopt": set or reset
4770 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004771 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004772 {
4773 errmsg = e_trailing;
4774 goto skip;
4775 }
4776 if (prefix == 2) /* inv */
4777 value = *(int *)(varp) ^ 1;
4778 else
4779 value = prefix;
4780 }
4781
4782 errmsg = set_bool_option(opt_idx, varp, (int)value,
4783 opt_flags);
4784 }
4785 else /* numeric or string */
4786 {
4787 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4788 || prefix != 1)
4789 {
4790 errmsg = e_invarg;
4791 goto skip;
4792 }
4793
4794 if (flags & P_NUM) /* numeric */
4795 {
4796 /*
4797 * Different ways to set a number option:
4798 * & set to default value
4799 * < set to global value
4800 * <xx> accept special key codes for 'wildchar'
4801 * c accept any non-digit for 'wildchar'
4802 * [-]0-9 set number
4803 * other error
4804 */
4805 ++arg;
4806 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004807 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004808 ((flags & P_VI_DEF) || cp_val)
4809 ? VI_DEFAULT : VIM_DEFAULT];
4810 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004811 {
4812 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4813 * use the global value. */
4814 if ((long *)varp == &curbuf->b_p_ul
4815 && opt_flags == OPT_LOCAL)
4816 value = NO_LOCAL_UNDOLEVEL;
4817 else
4818 value = *(long *)get_varp_scope(
4819 &(options[opt_idx]), OPT_GLOBAL);
4820 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004821 else if (((long *)varp == &p_wc
4822 || (long *)varp == &p_wcm)
4823 && (*arg == '<'
4824 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004825 || (*arg != NUL
4826 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004827 && !VIM_ISDIGIT(*arg))))
4828 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004829 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004830 if (value == 0 && (long *)varp != &p_wcm)
4831 {
4832 errmsg = e_invarg;
4833 goto skip;
4834 }
4835 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004836 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4837 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004838 /* Allow negative (for 'undolevels'), octal and
4839 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004840 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004841 &value, NULL, 0, TRUE);
Bram Moolenaar06e2c812019-06-12 19:05:48 +02004842 if (i == 0 || (arg[i] != NUL
4843 && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004844 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004845 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004846 goto skip;
4847 }
4848 }
4849 else
4850 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004851 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004852 goto skip;
4853 }
4854
4855 if (adding)
4856 value = *(long *)varp + value;
4857 if (prepending)
4858 value = *(long *)varp * value;
4859 if (removing)
4860 value = *(long *)varp - value;
4861 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004862 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004863 }
4864 else if (opt_idx >= 0) /* string */
4865 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004866 char_u *save_arg = NULL;
4867 char_u *s = NULL;
4868 char_u *oldval = NULL; /* previous value if *varp */
4869 char_u *newval;
4870 char_u *origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004871 char_u *origval_l = NULL;
4872 char_u *origval_g = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004873#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004874 char_u *saved_origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004875 char_u *saved_origval_l = NULL;
4876 char_u *saved_origval_g = NULL;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004877 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004878#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004879 unsigned newlen;
4880 int comma;
4881 int bs;
4882 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004883 was allocated */
4884
4885 /* When using ":set opt=val" for a global option
4886 * with a local value the local value will be
4887 * reset, use the global value here. */
4888 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004889 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004890 varp = options[opt_idx].var;
4891
4892 /* The old value is kept until we are sure that the
4893 * new value is valid. */
4894 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004895
Bram Moolenaard7c96872019-06-15 17:12:48 +02004896 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4897 {
4898 origval_l = *(char_u **)get_varp_scope(
4899 &(options[opt_idx]), OPT_LOCAL);
4900 origval_g = *(char_u **)get_varp_scope(
4901 &(options[opt_idx]), OPT_GLOBAL);
4902
4903 // A global-local string option might have an empty
4904 // option as value to indicate that the global
4905 // value should be used.
4906 if (((int)options[opt_idx].indir & PV_BOTH)
4907 && origval_l == empty_option)
4908 origval_l = origval_g;
4909 }
4910
4911 // When setting the local value of a global
4912 // option, the old value may be the global value.
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004913 if (((int)options[opt_idx].indir & PV_BOTH)
4914 && (opt_flags & OPT_LOCAL))
4915 origval = *(char_u **)get_varp(
4916 &options[opt_idx]);
4917 else
4918 origval = oldval;
4919
Bram Moolenaar071d4272004-06-13 20:20:40 +00004920 if (nextchar == '&') /* set to default val */
4921 {
4922 newval = options[opt_idx].def_val[
4923 ((flags & P_VI_DEF) || cp_val)
4924 ? VI_DEFAULT : VIM_DEFAULT];
4925 if ((char_u **)varp == &p_bg)
4926 {
4927 /* guess the value of 'background' */
4928#ifdef FEAT_GUI
4929 if (gui.in_use)
4930 newval = gui_bg_default();
4931 else
4932#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004933 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004934 }
4935
4936 /* expand environment variables and ~ (since the
4937 * default value was already expanded, only
4938 * required when an environment variable was set
4939 * later */
4940 if (newval == NULL)
4941 newval = empty_option;
4942 else
4943 {
4944 s = option_expand(opt_idx, newval);
4945 if (s == NULL)
4946 s = newval;
4947 newval = vim_strsave(s);
4948 }
4949 new_value_alloced = TRUE;
4950 }
4951 else if (nextchar == '<') /* set to global val */
4952 {
4953 newval = vim_strsave(*(char_u **)get_varp_scope(
4954 &(options[opt_idx]), OPT_GLOBAL));
4955 new_value_alloced = TRUE;
4956 }
4957 else
4958 {
4959 ++arg; /* jump to after the '=' or ':' */
4960
4961 /*
4962 * Set 'keywordprg' to ":help" if an empty
4963 * value was passed to :set by the user.
4964 * Misuse errbuf[] for the resulting string.
4965 */
4966 if (varp == (char_u *)&p_kp
4967 && (*arg == NUL || *arg == ' '))
4968 {
4969 STRCPY(errbuf, ":help");
4970 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004971 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004972 }
4973 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004974 * Convert 'backspace' number to string, for
4975 * adding, prepending and removing string.
4976 */
4977 else if (varp == (char_u *)&p_bs
4978 && VIM_ISDIGIT(**(char_u **)varp))
4979 {
4980 i = getdigits((char_u **)varp);
4981 switch (i)
4982 {
4983 case 0:
4984 *(char_u **)varp = empty_option;
4985 break;
4986 case 1:
4987 *(char_u **)varp = vim_strsave(
4988 (char_u *)"indent,eol");
4989 break;
4990 case 2:
4991 *(char_u **)varp = vim_strsave(
4992 (char_u *)"indent,eol,start");
4993 break;
4994 }
4995 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004996 if (origval == oldval)
4997 origval = *(char_u **)varp;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004998 if (origval_l == oldval)
4999 origval_l = *(char_u **)varp;
5000 if (origval_g == oldval)
5001 origval_g = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01005002 oldval = *(char_u **)varp;
5003 }
5004 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005005 * Convert 'whichwrap' number to string, for
5006 * backwards compatibility with Vim 3.0.
5007 * Misuse errbuf[] for the resulting string.
5008 */
5009 else if (varp == (char_u *)&p_ww
5010 && VIM_ISDIGIT(*arg))
5011 {
5012 *errbuf = NUL;
5013 i = getdigits(&arg);
5014 if (i & 1)
5015 STRCAT(errbuf, "b,");
5016 if (i & 2)
5017 STRCAT(errbuf, "s,");
5018 if (i & 4)
5019 STRCAT(errbuf, "h,l,");
5020 if (i & 8)
5021 STRCAT(errbuf, "<,>,");
5022 if (i & 16)
5023 STRCAT(errbuf, "[,],");
5024 if (*errbuf != NUL) /* remove trailing , */
5025 errbuf[STRLEN(errbuf) - 1] = NUL;
5026 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005027 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005028 }
5029 /*
5030 * Remove '>' before 'dir' and 'bdir', for
5031 * backwards compatibility with version 3.0
5032 */
5033 else if ( *arg == '>'
5034 && (varp == (char_u *)&p_dir
5035 || varp == (char_u *)&p_bdir))
5036 {
5037 ++arg;
5038 }
5039
Bram Moolenaar071d4272004-06-13 20:20:40 +00005040 /*
5041 * Copy the new string into allocated memory.
5042 * Can't use set_string_option_direct(), because
5043 * we need to remove the backslashes.
5044 */
5045 /* get a bit too much */
5046 newlen = (unsigned)STRLEN(arg) + 1;
5047 if (adding || prepending || removing)
5048 newlen += (unsigned)STRLEN(origval) + 1;
5049 newval = alloc(newlen);
5050 if (newval == NULL) /* out of mem, don't change */
5051 break;
5052 s = newval;
5053
5054 /*
5055 * Copy the string, skip over escaped chars.
5056 * For MS-DOS and WIN32 backslashes before normal
5057 * file name characters are not removed, and keep
5058 * backslash at start, for "\\machine\path", but
5059 * do remove it for "\\\\machine\\path".
5060 * The reverse is found in ExpandOldSetting().
5061 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005062 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005063 {
5064 if (*arg == '\\' && arg[1] != NUL
5065#ifdef BACKSLASH_IN_FILENAME
5066 && !((flags & P_EXPAND)
5067 && vim_isfilec(arg[1])
5068 && (arg[1] != '\\'
5069 || (s == newval
5070 && arg[2] != '\\')))
5071#endif
5072 )
5073 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005074 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005075 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005076 {
5077 /* copy multibyte char */
5078 mch_memmove(s, arg, (size_t)i);
5079 arg += i;
5080 s += i;
5081 }
5082 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005083 *s++ = *arg++;
5084 }
5085 *s = NUL;
5086
5087 /*
5088 * Expand environment variables and ~.
5089 * Don't do it when adding without inserting a
5090 * comma.
5091 */
5092 if (!(adding || prepending || removing)
5093 || (flags & P_COMMA))
5094 {
5095 s = option_expand(opt_idx, newval);
5096 if (s != NULL)
5097 {
5098 vim_free(newval);
5099 newlen = (unsigned)STRLEN(s) + 1;
5100 if (adding || prepending || removing)
5101 newlen += (unsigned)STRLEN(origval) + 1;
5102 newval = alloc(newlen);
5103 if (newval == NULL)
5104 break;
5105 STRCPY(newval, s);
5106 }
5107 }
5108
5109 /* locate newval[] in origval[] when removing it
5110 * and when adding to avoid duplicates */
5111 i = 0; /* init for GCC */
5112 if (removing || (flags & P_NODUP))
5113 {
5114 i = (int)STRLEN(newval);
5115 bs = 0;
5116 for (s = origval; *s; ++s)
5117 {
5118 if ((!(flags & P_COMMA)
5119 || s == origval
5120 || (s[-1] == ',' && !(bs & 1)))
5121 && STRNCMP(s, newval, i) == 0
5122 && (!(flags & P_COMMA)
5123 || s[i] == ','
5124 || s[i] == NUL))
5125 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005126 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005127 * even number of backslashes or a single
5128 * backslash preceded by a comma before it
5129 * is recognized as a separator */
5130 if ((s > origval + 1
5131 && s[-1] == '\\'
5132 && s[-2] != ',')
5133 || (s == origval + 1
5134 && s[-1] == '\\'))
5135
Bram Moolenaar071d4272004-06-13 20:20:40 +00005136 ++bs;
5137 else
5138 bs = 0;
5139 }
5140
5141 /* do not add if already there */
5142 if ((adding || prepending) && *s)
5143 {
5144 prepending = FALSE;
5145 adding = FALSE;
5146 STRCPY(newval, origval);
5147 }
5148 }
5149
5150 /* concatenate the two strings; add a ',' if
5151 * needed */
5152 if (adding || prepending)
5153 {
5154 comma = ((flags & P_COMMA) && *origval != NUL
5155 && *newval != NUL);
5156 if (adding)
5157 {
5158 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005159 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005160 if (comma && i > 1
5161 && (flags & P_ONECOMMA) == P_ONECOMMA
5162 && origval[i - 1] == ','
5163 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005164 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005165 mch_memmove(newval + i + comma, newval,
5166 STRLEN(newval) + 1);
5167 mch_memmove(newval, origval, (size_t)i);
5168 }
5169 else
5170 {
5171 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005172 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005173 }
5174 if (comma)
5175 newval[i] = ',';
5176 }
5177
5178 /* Remove newval[] from origval[]. (Note: "i" has
5179 * been set above and is used here). */
5180 if (removing)
5181 {
5182 STRCPY(newval, origval);
5183 if (*s)
5184 {
5185 /* may need to remove a comma */
5186 if (flags & P_COMMA)
5187 {
5188 if (s == origval)
5189 {
5190 /* include comma after string */
5191 if (s[i] == ',')
5192 ++i;
5193 }
5194 else
5195 {
5196 /* include comma before string */
5197 --s;
5198 ++i;
5199 }
5200 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005201 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005202 }
5203 }
5204
5205 if (flags & P_FLAGLIST)
5206 {
5207 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005208 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005209 {
5210 /* if options have P_FLAGLIST and
5211 * P_ONECOMMA such as 'whichwrap' */
5212 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005213 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005214 if (*s != ',' && *(s + 1) == ','
5215 && vim_strchr(s + 2, *s) != NULL)
5216 {
5217 /* Remove the duplicated value and
5218 * the next comma. */
5219 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005220 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005221 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005222 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005223 else
5224 {
5225 if ((!(flags & P_COMMA) || *s != ',')
5226 && vim_strchr(s + 1, *s) != NULL)
5227 {
5228 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005229 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005230 }
5231 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005232 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005233 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005234 }
5235
5236 if (save_arg != NULL) /* number for 'whichwrap' */
5237 arg = save_arg;
5238 new_value_alloced = TRUE;
5239 }
5240
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005241 /*
5242 * Set the new value.
5243 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005244 *(char_u **)(varp) = newval;
5245
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005246#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005247 if (!starting
5248# ifdef FEAT_CRYPT
5249 && options[opt_idx].indir != PV_KEY
5250# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005251 && origval != NULL && newval != NULL)
5252 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005253 /* origval may be freed by
5254 * did_set_string_option(), make a copy. */
5255 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005256 /* newval (and varp) may become invalid if the
5257 * buffer is closed by autocommands. */
5258 saved_newval = vim_strsave(newval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005259 if (origval_l != NULL)
5260 saved_origval_l = vim_strsave(origval_l);
5261 if (origval_g != NULL)
5262 saved_origval_g = vim_strsave(origval_g);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005263 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005264#endif
5265
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005266 {
5267 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005268 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005269
5270 // When an option is set in the sandbox, from a
5271 // modeline or in secure mode, then deal with side
5272 // effects in secure mode. Also when the value was
5273 // set with the P_INSECURE flag and is not
5274 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005275 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005276#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005277 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005278#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005279 || (!value_is_replaced && (*p & P_INSECURE)))
5280 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005281
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005282 // Handle side effects, and set the global value
5283 // for ":set" on local options. Note: when setting
5284 // 'syntax' or 'filetype' autocommands may be
5285 // triggered that can cause havoc.
5286 errmsg = did_set_string_option(
5287 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005288 new_value_alloced, oldval, errbuf,
5289 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005290
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005291 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005292 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005293
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005294#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005295 if (errmsg == NULL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02005296 trigger_optionsset_string(
5297 opt_idx, opt_flags, saved_origval,
5298 saved_origval_l, saved_origval_g,
5299 saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005300 vim_free(saved_origval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005301 vim_free(saved_origval_l);
5302 vim_free(saved_origval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005303 vim_free(saved_newval);
5304#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005305 /* If error detected, print the error message. */
5306 if (errmsg != NULL)
5307 goto skip;
5308 }
5309 else /* key code option */
5310 {
5311 char_u *p;
5312
5313 if (nextchar == '&')
5314 {
5315 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005316 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005317 }
5318 else
5319 {
5320 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005321 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005322 if (*p == '\\' && p[1] != NUL)
5323 ++p;
5324 nextchar = *p;
5325 *p = NUL;
5326 add_termcode(key_name, arg, FALSE);
5327 *p = nextchar;
5328 }
5329 if (full_screen)
5330 ttest(FALSE);
5331 redraw_all_later(CLEAR);
5332 }
5333 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005334
Bram Moolenaar071d4272004-06-13 20:20:40 +00005335 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005336 did_set_option(
5337 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005338 }
5339
5340skip:
5341 /*
5342 * Advance to next argument.
5343 * - skip until a blank found, taking care of backslashes
5344 * - skip blanks
5345 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5346 */
5347 for (i = 0; i < 2 ; ++i)
5348 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005349 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005350 if (*arg++ == '\\' && *arg != NUL)
5351 ++arg;
5352 arg = skipwhite(arg);
5353 if (*arg != '=')
5354 break;
5355 }
5356 }
5357
5358 if (errmsg != NULL)
5359 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005360 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005361 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005362 if (i + (arg - startarg) < IOSIZE)
5363 {
5364 /* append the argument with the error */
5365 STRCAT(IObuff, ": ");
5366 mch_memmove(IObuff + i, startarg, (arg - startarg));
5367 IObuff[i + (arg - startarg)] = NUL;
5368 }
5369 /* make sure all characters are printable */
5370 trans_characters(IObuff, IOSIZE);
5371
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005372 ++no_wait_return; // wait_return done later
5373 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005374 --no_wait_return;
5375
5376 return FAIL;
5377 }
5378
5379 arg = skipwhite(arg);
5380 }
5381
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005382theend:
5383 if (silent_mode && did_show)
5384 {
5385 /* After displaying option values in silent mode. */
5386 silent_mode = FALSE;
5387 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5388 msg_putchar('\n');
5389 cursor_on(); /* msg_start() switches it off */
5390 out_flush();
5391 silent_mode = TRUE;
5392 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5393 }
5394
Bram Moolenaar071d4272004-06-13 20:20:40 +00005395 return OK;
5396}
5397
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005398/*
5399 * Call this when an option has been given a new value through a user command.
5400 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5401 */
5402 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005403did_set_option(
5404 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005405 int opt_flags, // possibly with OPT_MODELINE
5406 int new_value, // value was replaced completely
5407 int value_checked) // value was checked to be safe, no need to set the
5408 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005409{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005410 long_u *p;
5411
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005412 options[opt_idx].flags |= P_WAS_SET;
5413
5414 /* When an option is set in the sandbox, from a modeline or in secure mode
5415 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005416 * flag. */
5417 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005418 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005419#ifdef HAVE_SANDBOX
5420 || sandbox != 0
5421#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005422 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005423 *p = *p | P_INSECURE;
5424 else if (new_value)
5425 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005426}
5427
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005428 static char *
5429illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005430{
5431 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005432 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005434 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005435 return errbuf;
5436}
5437
5438/*
5439 * Convert a key name or string into a key value.
5440 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005441 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005442 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005443 int
5444string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005445{
5446 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005447 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005448 if (*arg == '^')
5449 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005450 if (multi_byte)
5451 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005452 return *arg;
5453}
5454
5455#ifdef FEAT_CMDWIN
5456/*
5457 * Check value of 'cedit' and set cedit_key.
5458 * Returns NULL if value is OK, error message otherwise.
5459 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005460 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005461check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005462{
5463 int n;
5464
5465 if (*p_cedit == NUL)
5466 cedit_key = -1;
5467 else
5468 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005469 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005470 if (vim_isprintc(n))
5471 return e_invarg;
5472 cedit_key = n;
5473 }
5474 return NULL;
5475}
5476#endif
5477
5478#ifdef FEAT_TITLE
5479/*
5480 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5481 * maketitle() to create and display it.
5482 * When switching the title or icon off, call mch_restore_title() to get
5483 * the old value back.
5484 */
5485 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005486did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005487{
5488 if (starting != NO_SCREEN
5489#ifdef FEAT_GUI
5490 && !gui.starting
5491#endif
5492 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005493 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005494}
5495#endif
5496
5497/*
5498 * set_options_bin - called when 'bin' changes value.
5499 */
5500 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005501set_options_bin(
5502 int oldval,
5503 int newval,
5504 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005505{
5506 /*
5507 * The option values that are changed when 'bin' changes are
5508 * copied when 'bin is set and restored when 'bin' is reset.
5509 */
5510 if (newval)
5511 {
5512 if (!oldval) /* switched on */
5513 {
5514 if (!(opt_flags & OPT_GLOBAL))
5515 {
5516 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5517 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5518 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5519 curbuf->b_p_et_nobin = curbuf->b_p_et;
5520 }
5521 if (!(opt_flags & OPT_LOCAL))
5522 {
5523 p_tw_nobin = p_tw;
5524 p_wm_nobin = p_wm;
5525 p_ml_nobin = p_ml;
5526 p_et_nobin = p_et;
5527 }
5528 }
5529
5530 if (!(opt_flags & OPT_GLOBAL))
5531 {
5532 curbuf->b_p_tw = 0; /* no automatic line wrap */
5533 curbuf->b_p_wm = 0; /* no automatic line wrap */
5534 curbuf->b_p_ml = 0; /* no modelines */
5535 curbuf->b_p_et = 0; /* no expandtab */
5536 }
5537 if (!(opt_flags & OPT_LOCAL))
5538 {
5539 p_tw = 0;
5540 p_wm = 0;
5541 p_ml = FALSE;
5542 p_et = FALSE;
5543 p_bin = TRUE; /* needed when called for the "-b" argument */
5544 }
5545 }
5546 else if (oldval) /* switched off */
5547 {
5548 if (!(opt_flags & OPT_GLOBAL))
5549 {
5550 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5551 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5552 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5553 curbuf->b_p_et = curbuf->b_p_et_nobin;
5554 }
5555 if (!(opt_flags & OPT_LOCAL))
5556 {
5557 p_tw = p_tw_nobin;
5558 p_wm = p_wm_nobin;
5559 p_ml = p_ml_nobin;
5560 p_et = p_et_nobin;
5561 }
5562 }
5563}
5564
Bram Moolenaar071d4272004-06-13 20:20:40 +00005565/*
5566 * Expand environment variables for some string options.
5567 * These string options cannot be indirect!
5568 * If "val" is NULL expand the current value of the option.
5569 * Return pointer to NameBuff, or NULL when not expanded.
5570 */
5571 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005572option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005573{
5574 /* if option doesn't need expansion nothing to do */
5575 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5576 return NULL;
5577
5578 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5579 * expand_env() would truncate the string. */
5580 if (val != NULL && STRLEN(val) > MAXPATHL)
5581 return NULL;
5582
5583 if (val == NULL)
5584 val = *(char_u **)options[opt_idx].var;
5585
5586 /*
5587 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5588 * Escape spaces when expanding 'tags', they are used to separate file
5589 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005590 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005591 */
5592 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005593 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005594#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005595 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5596#endif
5597 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005598 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5599 return NULL;
5600
5601 return NameBuff;
5602}
5603
5604/*
5605 * After setting various option values: recompute variables that depend on
5606 * option values.
5607 */
5608 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005609didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005610{
5611 /* initialize the table for 'iskeyword' et.al. */
5612 (void)init_chartab();
5613
5614 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5615 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005616 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617#ifdef FEAT_SESSION
5618 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5619 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5620#endif
5621#ifdef FEAT_FOLDING
5622 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5623#endif
5624 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005625 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005626 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005627#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5628 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5629#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005630#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005631 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005632 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005633 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005634 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005635#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005636#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005637 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5638#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005639#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005640 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5641#endif
5642#ifdef FEAT_CMDWIN
5643 /* set cedit_key */
5644 (void)check_cedit();
5645#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005646#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005647 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005648#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005649#ifdef FEAT_LINEBREAK
5650 /* initialize the table for 'breakat'. */
5651 fill_breakat_flags();
5652#endif
5653
5654}
5655
5656/*
5657 * More side effects of setting options.
5658 */
5659 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005660didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005661{
5662 /* Initialize the highlight_attr[] table. */
5663 (void)highlight_changed();
5664
5665 /* Parse default for 'wildmode' */
5666 check_opt_wim();
5667
5668 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005669 /* Parse default for 'fillchars'. */
5670 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005671
5672#ifdef FEAT_CLIPBOARD
5673 /* Parse default for 'clipboard' */
5674 (void)check_clipboard_option();
5675#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005676#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005677 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005678 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005679 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005680 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5681#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005682}
5683
5684/*
5685 * Check for string options that are NULL (normally only termcap options).
5686 */
5687 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005688check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005689{
5690 int opt_idx;
5691
5692 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5693 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5694 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5695}
5696
5697/*
5698 * Check string options in a buffer for NULL value.
5699 */
5700 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005701check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005702{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005703 check_string_option(&buf->b_p_bh);
5704 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005706 check_string_option(&buf->b_p_ff);
5707#ifdef FEAT_FIND_ID
5708 check_string_option(&buf->b_p_def);
5709 check_string_option(&buf->b_p_inc);
5710# ifdef FEAT_EVAL
5711 check_string_option(&buf->b_p_inex);
5712# endif
5713#endif
5714#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5715 check_string_option(&buf->b_p_inde);
5716 check_string_option(&buf->b_p_indk);
5717#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005718#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5719 check_string_option(&buf->b_p_bexpr);
5720#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005721#if defined(FEAT_CRYPT)
5722 check_string_option(&buf->b_p_cm);
5723#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005724 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005725#if defined(FEAT_EVAL)
5726 check_string_option(&buf->b_p_fex);
5727#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005728#ifdef FEAT_CRYPT
5729 check_string_option(&buf->b_p_key);
5730#endif
5731 check_string_option(&buf->b_p_kp);
5732 check_string_option(&buf->b_p_mps);
5733 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005734 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005735 check_string_option(&buf->b_p_isk);
5736#ifdef FEAT_COMMENTS
5737 check_string_option(&buf->b_p_com);
5738#endif
5739#ifdef FEAT_FOLDING
5740 check_string_option(&buf->b_p_cms);
5741#endif
5742 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005743#ifdef FEAT_TEXTOBJ
5744 check_string_option(&buf->b_p_qe);
5745#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005746#ifdef FEAT_SYN_HL
5747 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005748 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005749#endif
5750#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005751 check_string_option(&buf->b_s.b_p_spc);
5752 check_string_option(&buf->b_s.b_p_spf);
5753 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754#endif
5755#ifdef FEAT_SEARCHPATH
5756 check_string_option(&buf->b_p_sua);
5757#endif
5758#ifdef FEAT_CINDENT
5759 check_string_option(&buf->b_p_cink);
5760 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005761 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005762#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005763 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5765 check_string_option(&buf->b_p_cinw);
5766#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005767 check_string_option(&buf->b_p_cpt);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005768#ifdef FEAT_COMPL_FUNC
5769 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005770 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005771#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005772#ifdef FEAT_EVAL
5773 check_string_option(&buf->b_p_tfu);
5774#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005775#ifdef FEAT_KEYMAP
5776 check_string_option(&buf->b_p_keymap);
5777#endif
5778#ifdef FEAT_QUICKFIX
5779 check_string_option(&buf->b_p_gp);
5780 check_string_option(&buf->b_p_mp);
5781 check_string_option(&buf->b_p_efm);
5782#endif
5783 check_string_option(&buf->b_p_ep);
5784 check_string_option(&buf->b_p_path);
5785 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005786 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005787 check_string_option(&buf->b_p_dict);
5788 check_string_option(&buf->b_p_tsr);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005789#ifdef FEAT_LISP
5790 check_string_option(&buf->b_p_lw);
5791#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005792 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005793 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005794#ifdef FEAT_VARTABS
5795 check_string_option(&buf->b_p_vsts);
5796 check_string_option(&buf->b_p_vts);
5797#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005798}
5799
5800/*
5801 * Free the string allocated for an option.
5802 * Checks for the string being empty_option. This may happen if we're out of
5803 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5804 * check_options().
5805 * Does NOT check for P_ALLOCED flag!
5806 */
5807 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005808free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005809{
5810 if (p != empty_option)
5811 vim_free(p);
5812}
5813
5814 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005815clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005816{
5817 if (*pp != empty_option)
5818 vim_free(*pp);
5819 *pp = empty_option;
5820}
5821
5822 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005823check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005824{
5825 if (*pp == NULL)
5826 *pp = empty_option;
5827}
5828
5829/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005830 * Return the option index found by a pointer into term_strings[].
5831 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005832 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005833 int
5834get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005835{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005836 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837
5838 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5839 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005840 return opt_idx;
5841 return -1; // cannot happen: didn't find it!
5842}
5843
5844/*
5845 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5846 * Return the option index or -1 if not found.
5847 */
5848 int
5849set_term_option_alloced(char_u **p)
5850{
5851 int opt_idx = get_term_opt_idx(p);
5852
5853 if (opt_idx >= 0)
5854 options[opt_idx].flags |= P_ALLOCED;
5855 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856}
5857
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005858#if defined(FEAT_EVAL) || defined(PROTO)
5859/*
5860 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5861 * Return FALSE when it wasn't.
5862 * Return -1 for an unknown option.
5863 */
5864 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005865was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005866{
5867 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005868 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005869
5870 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005871 {
5872 flagp = insecure_flag(idx, opt_flags);
5873 return (*flagp & P_INSECURE) != 0;
5874 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005875 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005876 return -1;
5877}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005878
5879/*
5880 * Get a pointer to the flags used for the P_INSECURE flag of option
5881 * "opt_idx". For some local options a local flags field is used.
5882 */
5883 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005884insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005885{
5886 if (opt_flags & OPT_LOCAL)
5887 switch ((int)options[opt_idx].indir)
5888 {
5889#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005890 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005891#endif
5892#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005893# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005894 case PV_FDE: return &curwin->w_p_fde_flags;
5895 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005896# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005897# ifdef FEAT_BEVAL
5898 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5899# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005900# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005901 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005902# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005903 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005904# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005905 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005906# endif
5907#endif
5908 }
5909
5910 /* Nothing special, return global flags field. */
5911 return &options[opt_idx].flags;
5912}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005913#endif
5914
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005915#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005916/*
5917 * Redraw the window title and/or tab page text later.
5918 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005919static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005920{
5921 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005922 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005923}
5924#endif
5925
Bram Moolenaar071d4272004-06-13 20:20:40 +00005926/*
5927 * Set a string option to a new value (without checking the effect).
5928 * The string is copied into allocated memory.
5929 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005930 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5931 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5932 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005933 */
5934 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005935set_string_option_direct(
5936 char_u *name,
5937 int opt_idx,
5938 char_u *val,
5939 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5940 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005941{
5942 char_u *s;
5943 char_u **varp;
5944 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005945 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946
Bram Moolenaar89d40322006-08-29 15:30:07 +00005947 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005948 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005949 idx = findoption(name);
5950 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005951 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005952 semsg(_(e_intern2), "set_string_option_direct()");
5953 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005954 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005955 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956 }
5957
Bram Moolenaar89d40322006-08-29 15:30:07 +00005958 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005959 return;
5960
5961 s = vim_strsave(val);
5962 if (s != NULL)
5963 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005964 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005966 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005967 free_string_option(*varp);
5968 *varp = s;
5969
5970 /* For buffer/window local option may also set the global value. */
5971 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005972 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005973
Bram Moolenaar89d40322006-08-29 15:30:07 +00005974 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975
5976 /* When setting both values of a global option with a local value,
5977 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005978 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005979 {
5980 free_string_option(*varp);
5981 *varp = empty_option;
5982 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005983# ifdef FEAT_EVAL
5984 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005985 {
5986 sctx_T script_ctx;
5987
5988 if (set_sid == 0)
5989 script_ctx = current_sctx;
5990 else
5991 {
5992 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005993 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005994 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005995 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005996 }
5997 set_option_sctx_idx(idx, opt_flags, script_ctx);
5998 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005999# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006000 }
6001}
6002
6003/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02006004 * Like set_string_option_direct(), but for a window-local option in "wp".
6005 * Blocks autocommands to avoid the old curwin becoming invalid.
6006 */
6007 void
6008set_string_option_direct_in_win(
6009 win_T *wp,
6010 char_u *name,
6011 int opt_idx,
6012 char_u *val,
6013 int opt_flags,
6014 int set_sid)
6015{
6016 win_T *save_curwin = curwin;
6017
6018 block_autocmds();
6019 curwin = wp;
6020 curbuf = curwin->w_buffer;
6021 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6022 curwin = save_curwin;
6023 curbuf = curwin->w_buffer;
6024 unblock_autocmds();
6025}
6026
6027/*
6028 * Like set_string_option_direct(), but for a buffer-local option in "buf".
6029 * Blocks autocommands to avoid the old curbuf becoming invalid.
6030 */
6031 void
6032set_string_option_direct_in_buf(
6033 buf_T *buf,
6034 char_u *name,
6035 int opt_idx,
6036 char_u *val,
6037 int opt_flags,
6038 int set_sid)
6039{
6040 buf_T *save_curbuf = curbuf;
6041
6042 block_autocmds();
6043 curbuf = buf;
6044 curwin->w_buffer = curbuf;
6045 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6046 curbuf = save_curbuf;
6047 curwin->w_buffer = curbuf;
6048 unblock_autocmds();
6049}
6050
6051/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006052 * Set global value for string option when it's a local option.
6053 */
6054 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006055set_string_option_global(
6056 int opt_idx, /* option index */
6057 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058{
6059 char_u **p, *s;
6060
6061 /* the global value is always allocated */
6062 if (options[opt_idx].var == VAR_WIN)
6063 p = (char_u **)GLOBAL_WO(varp);
6064 else
6065 p = (char_u **)options[opt_idx].var;
6066 if (options[opt_idx].indir != PV_NONE
6067 && p != varp
6068 && (s = vim_strsave(*varp)) != NULL)
6069 {
6070 free_string_option(*p);
6071 *p = s;
6072 }
6073}
6074
6075/*
6076 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006077 *
6078 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006079 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006080 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006081set_string_option(
6082 int opt_idx,
6083 char_u *value,
6084 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006085{
6086 char_u *s;
6087 char_u **varp;
6088 char_u *oldval;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006089#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006090 char_u *oldval_l = NULL;
6091 char_u *oldval_g = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006092 char_u *saved_oldval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02006093 char_u *saved_oldval_l = NULL;
6094 char_u *saved_oldval_g = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006095 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006096#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006097 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006098 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006099
6100 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006101 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006102
6103 s = vim_strsave(value);
6104 if (s != NULL)
6105 {
6106 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6107 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006108 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006109 ? OPT_GLOBAL : OPT_LOCAL)
6110 : opt_flags);
6111 oldval = *varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006112#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006113 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6114 {
6115 oldval_l = *(char_u **)get_varp_scope(&(options[opt_idx]),
6116 OPT_LOCAL);
6117 oldval_g = *(char_u **)get_varp_scope(&(options[opt_idx]),
6118 OPT_GLOBAL);
6119 }
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006120#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006121 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006122
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006123#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006124 if (!starting
6125# ifdef FEAT_CRYPT
6126 && options[opt_idx].indir != PV_KEY
6127# endif
6128 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006129 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02006130 if (oldval_l != NULL)
6131 saved_oldval_l = vim_strsave(oldval_l);
6132 if (oldval_g != NULL)
6133 saved_oldval_g = vim_strsave(oldval_g);
Bram Moolenaar53744302015-07-17 17:38:22 +02006134 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006135 saved_newval = vim_strsave(s);
6136 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006137#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006138 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006139 opt_flags, &value_checked)) == NULL)
6140 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006141
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006142#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006143 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006144 if (r == NULL)
6145 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02006146 saved_oldval, saved_oldval_l,
6147 saved_oldval_g, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006148 vim_free(saved_oldval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02006149 vim_free(saved_oldval_l);
6150 vim_free(saved_oldval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006151 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006152#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006153 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006154 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006155}
6156
6157/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006158 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6159 * characters or characters in "allowed".
6160 */
6161 static int
6162valid_name(char_u *val, char *allowed)
6163{
6164 char_u *s;
6165
6166 for (s = val; *s != NUL; ++s)
6167 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6168 return FALSE;
6169 return TRUE;
6170}
6171
6172/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006173 * Return TRUE if "val" is a valid 'filetype' name.
6174 * Also used for 'syntax' and 'keymap'.
6175 */
6176 static int
6177valid_filetype(char_u *val)
6178{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006179 return valid_name(val, ".-_");
6180}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006181
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006182#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006183/*
6184 * Return TRUE if "val" is a valid 'spellang' value.
6185 */
6186 int
6187valid_spellang(char_u *val)
6188{
Bram Moolenaar9a061cb2019-05-05 16:55:03 +02006189 return valid_name(val, ".-_,@");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006190}
6191
6192/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006193 * Return TRUE if "val" is a valid 'spellfile' value.
6194 */
6195 static int
6196valid_spellfile(char_u *val)
6197{
6198 char_u *s;
6199
6200 for (s = val; *s != NUL; ++s)
6201 if (!vim_isfilec(*s) && *s != ',')
6202 return FALSE;
6203 return TRUE;
6204}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006205#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006206
6207/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006208 * Handle string options that need some action to perform when changed.
6209 * Returns NULL for success, or an error message for an error.
6210 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006211 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006212did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006213 int opt_idx, // index in options[] table
6214 char_u **varp, // pointer to the option variable
6215 int new_value_alloced, // new value was allocated
6216 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006217 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006218 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6219 int *value_checked) // value was checked to be save, no
6220 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006221{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006222 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006223 char_u *s, *p;
6224 int did_chartab = FALSE;
6225 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006226 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006227#ifdef FEAT_GUI
6228 /* set when changing an option that only requires a redraw in the GUI */
6229 int redraw_gui_only = FALSE;
6230#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006231 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006232#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6233 int did_swaptcap = FALSE;
6234#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006235
6236 /* Get the global option to compare with, otherwise we would have to check
6237 * two values for all local options. */
6238 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6239
6240 /* Disallow changing some options from secure mode */
6241 if ((secure
6242#ifdef HAVE_SANDBOX
6243 || sandbox != 0
6244#endif
6245 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006246 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006247
Bram Moolenaar916a8182018-11-25 02:18:29 +01006248 // Check for a "normal" directory or file name in some options. Disallow a
6249 // path separator (slash and/or backslash), wildcards and characters that
6250 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006251 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006252 && vim_strpbrk(*varp, (char_u *)(secure
6253 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006254 || ((options[opt_idx].flags & P_NDNAME)
6255 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006256 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006257
Bram Moolenaar071d4272004-06-13 20:20:40 +00006258 /* 'term' */
6259 else if (varp == &T_NAME)
6260 {
6261 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006262 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006263#ifdef FEAT_GUI
6264 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006265 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006267 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006268#endif
6269 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006270 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006271 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006272 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006273 /* Screen colors may have changed. */
6274 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006275
6276 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6277 * P_ALLOCED flag on 'term'. */
6278 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006279 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006280 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006281 }
6282
6283 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006284 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006285 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006286 char_u *bkc = p_bkc;
6287 unsigned int *flags = &bkc_flags;
6288
6289 if (opt_flags & OPT_LOCAL)
6290 {
6291 bkc = curbuf->b_p_bkc;
6292 flags = &curbuf->b_bkc_flags;
6293 }
6294
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006295 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6296 /* make the local value empty: use the global value */
6297 *flags = 0;
6298 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006299 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006300 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6301 errmsg = e_invarg;
6302 if ((((int)*flags & BKC_AUTO) != 0)
6303 + (((int)*flags & BKC_YES) != 0)
6304 + (((int)*flags & BKC_NO) != 0) != 1)
6305 {
6306 /* Must have exactly one of "auto", "yes" and "no". */
6307 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6308 errmsg = e_invarg;
6309 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310 }
6311 }
6312
6313 /* 'backupext' and 'patchmode' */
6314 else if (varp == &p_bex || varp == &p_pm)
6315 {
6316 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6317 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006318 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006319 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006320#ifdef FEAT_LINEBREAK
6321 /* 'breakindentopt' */
6322 else if (varp == &curwin->w_p_briopt)
6323 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006324 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006325 errmsg = e_invarg;
6326 }
6327#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006328
6329 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006330 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006332 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006333 */
6334 else if ( varp == &p_isi
6335 || varp == &(curbuf->b_p_isk)
6336 || varp == &p_isp
6337 || varp == &p_isf)
6338 {
6339 if (init_chartab() == FAIL)
6340 {
6341 did_chartab = TRUE; /* need to restore it below */
6342 errmsg = e_invarg; /* error in value */
6343 }
6344 }
6345
6346 /* 'helpfile' */
6347 else if (varp == &p_hf)
6348 {
6349 /* May compute new values for $VIM and $VIMRUNTIME */
6350 if (didset_vim)
6351 {
6352 vim_setenv((char_u *)"VIM", (char_u *)"");
6353 didset_vim = FALSE;
6354 }
6355 if (didset_vimruntime)
6356 {
6357 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6358 didset_vimruntime = FALSE;
6359 }
6360 }
6361
Bram Moolenaar1a384422010-07-14 19:53:30 +02006362#ifdef FEAT_SYN_HL
6363 /* 'colorcolumn' */
6364 else if (varp == &curwin->w_p_cc)
6365 errmsg = check_colorcolumn(curwin);
6366#endif
6367
Bram Moolenaar071d4272004-06-13 20:20:40 +00006368#ifdef FEAT_MULTI_LANG
6369 /* 'helplang' */
6370 else if (varp == &p_hlg)
6371 {
6372 /* Check for "", "ab", "ab,cd", etc. */
6373 for (s = p_hlg; *s != NUL; s += 3)
6374 {
6375 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6376 {
6377 errmsg = e_invarg;
6378 break;
6379 }
6380 if (s[2] == NUL)
6381 break;
6382 }
6383 }
6384#endif
6385
6386 /* 'highlight' */
6387 else if (varp == &p_hl)
6388 {
6389 if (highlight_changed() == FAIL)
6390 errmsg = e_invarg; /* invalid flags */
6391 }
6392
6393 /* 'nrformats' */
6394 else if (gvarp == &p_nf)
6395 {
6396 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6397 errmsg = e_invarg;
6398 }
6399
6400#ifdef FEAT_SESSION
6401 /* 'sessionoptions' */
6402 else if (varp == &p_ssop)
6403 {
6404 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6405 errmsg = e_invarg;
6406 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6407 {
6408 /* Don't allow both "sesdir" and "curdir". */
6409 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6410 errmsg = e_invarg;
6411 }
6412 }
6413 /* 'viewoptions' */
6414 else if (varp == &p_vop)
6415 {
6416 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6417 errmsg = e_invarg;
6418 }
6419#endif
6420
6421 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006422 else if (varp == &p_sbo)
6423 {
6424 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6425 errmsg = e_invarg;
6426 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006427
6428 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006429 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006430 {
6431 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6432 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006433 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006434 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006435 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006436 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006437 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006438
6439 /* 'background' */
6440 else if (varp == &p_bg)
6441 {
6442 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6443 {
6444#ifdef FEAT_EVAL
6445 int dark = (*p_bg == 'd');
6446#endif
6447
6448 init_highlight(FALSE, FALSE);
6449
6450#ifdef FEAT_EVAL
6451 if (dark != (*p_bg == 'd')
6452 && get_var_value((char_u *)"g:colors_name") != NULL)
6453 {
6454 /* The color scheme must have set 'background' back to another
6455 * value, that's not what we want here. Disable the color
6456 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006457 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006458 free_string_option(p_bg);
6459 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6460 check_string_option(&p_bg);
6461 init_highlight(FALSE, FALSE);
6462 }
6463#endif
6464 }
6465 else
6466 errmsg = e_invarg;
6467 }
6468
6469 /* 'wildmode' */
6470 else if (varp == &p_wim)
6471 {
6472 if (check_opt_wim() == FAIL)
6473 errmsg = e_invarg;
6474 }
6475
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006476 /* 'wildoptions' */
6477 else if (varp == &p_wop)
6478 {
6479 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6480 errmsg = e_invarg;
6481 }
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006482
Bram Moolenaar071d4272004-06-13 20:20:40 +00006483#ifdef FEAT_WAK
6484 /* 'winaltkeys' */
6485 else if (varp == &p_wak)
6486 {
6487 if (*p_wak == NUL
6488 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6489 errmsg = e_invarg;
6490# ifdef FEAT_MENU
6491# ifdef FEAT_GUI_MOTIF
6492 else if (gui.in_use)
6493 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6494# else
6495# ifdef FEAT_GUI_GTK
6496 else if (gui.in_use)
6497 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6498# endif
6499# endif
6500# endif
6501 }
6502#endif
6503
Bram Moolenaar071d4272004-06-13 20:20:40 +00006504 /* 'eventignore' */
6505 else if (varp == &p_ei)
6506 {
6507 if (check_ei() == FAIL)
6508 errmsg = e_invarg;
6509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006510
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006511 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6512 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6513 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006514 {
6515 if (gvarp == &p_fenc)
6516 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006517 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 errmsg = e_modifiable;
6519 else if (vim_strchr(*varp, ',') != NULL)
6520 /* No comma allowed in 'fileencoding'; catches confusing it
6521 * with 'fileencodings'. */
6522 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006523 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006524 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006525#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006526 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006527 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006528#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006529 /* Add 'fileencoding' to the swap file. */
6530 ml_setflags(curbuf);
6531 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006532 }
6533 if (errmsg == NULL)
6534 {
6535 /* canonize the value, so that STRCMP() can be used on it */
6536 p = enc_canonize(*varp);
6537 if (p != NULL)
6538 {
6539 vim_free(*varp);
6540 *varp = p;
6541 }
6542 if (varp == &p_enc)
6543 {
6544 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006545#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006546 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006547#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006548 }
6549 }
6550
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006551#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006552 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6553 {
6554 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6555 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006556 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006558#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006559
6560 if (errmsg == NULL)
6561 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006562#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006563 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6564 * (with another encoding). */
6565 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6566 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006567#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006568
6569 /* When 'termencoding' is not empty and 'encoding' changes or when
6570 * 'termencoding' changes, need to setup for keyboard input and
6571 * display output conversion. */
6572 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6573 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006574 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6575 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6576 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006577 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006578 p_tenc, p_enc);
6579 errmsg = e_invarg;
6580 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006581 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006582
Bram Moolenaar4f974752019-02-17 17:44:42 +01006583#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006584 /* $HOME may have characters in active code page. */
6585 if (varp == &p_enc)
6586 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006587#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006588 }
6589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006590
6591#if defined(FEAT_POSTSCRIPT)
6592 else if (varp == &p_penc)
6593 {
6594 /* Canonize printencoding if VIM standard one */
6595 p = enc_canonize(p_penc);
6596 if (p != NULL)
6597 {
6598 vim_free(p_penc);
6599 p_penc = p;
6600 }
6601 else
6602 {
6603 /* Ensure lower case and '-' for '_' */
6604 for (s = p_penc; *s != NUL; s++)
6605 {
6606 if (*s == '_')
6607 *s = '-';
6608 else
6609 *s = TOLOWER_ASC(*s);
6610 }
6611 }
6612 }
6613#endif
6614
Bram Moolenaar9372a112005-12-06 19:59:18 +00006615#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006616 else if (varp == &p_imak)
6617 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006618 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006619 errmsg = e_invarg;
6620 }
6621#endif
6622
6623#ifdef FEAT_KEYMAP
6624 else if (varp == &curbuf->b_p_keymap)
6625 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006626 if (!valid_filetype(*varp))
6627 errmsg = e_invarg;
6628 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006629 {
6630 int secure_save = secure;
6631
6632 // Reset the secure flag, since the value of 'keymap' has
6633 // been checked to be safe.
6634 secure = 0;
6635
6636 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006637 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006638
Bram Moolenaar916a8182018-11-25 02:18:29 +01006639 secure = secure_save;
6640
6641 // Since we check the value, there is no need to set P_INSECURE,
6642 // even when the value comes from a modeline.
6643 *value_checked = TRUE;
6644 }
6645
Bram Moolenaarfab06232009-03-04 03:13:35 +00006646 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006647 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006648 if (*curbuf->b_p_keymap != NUL)
6649 {
6650 /* Installed a new keymap, switch on using it. */
6651 curbuf->b_p_iminsert = B_IMODE_LMAP;
6652 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6653 curbuf->b_p_imsearch = B_IMODE_LMAP;
6654 }
6655 else
6656 {
6657 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6658 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6659 curbuf->b_p_iminsert = B_IMODE_NONE;
6660 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6661 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6662 }
6663 if ((opt_flags & OPT_LOCAL) == 0)
6664 {
6665 set_iminsert_global();
6666 set_imsearch_global();
6667 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006668 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006669 }
6670 }
6671#endif
6672
6673 /* 'fileformat' */
6674 else if (gvarp == &p_ff)
6675 {
6676 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6677 errmsg = e_modifiable;
6678 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6679 errmsg = e_invarg;
6680 else
6681 {
6682 /* may also change 'textmode' */
6683 if (get_fileformat(curbuf) == EOL_DOS)
6684 curbuf->b_p_tx = TRUE;
6685 else
6686 curbuf->b_p_tx = FALSE;
6687#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006688 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006689#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006690 /* update flag in swap file */
6691 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006692 /* Redraw needed when switching to/from "mac": a CR in the text
6693 * will be displayed differently. */
6694 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6695 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006696 }
6697 }
6698
6699 /* 'fileformats' */
6700 else if (varp == &p_ffs)
6701 {
6702 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6703 errmsg = e_invarg;
6704 else
6705 {
6706 /* also change 'textauto' */
6707 if (*p_ffs == NUL)
6708 p_ta = FALSE;
6709 else
6710 p_ta = TRUE;
6711 }
6712 }
6713
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006714#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006715 /* 'cryptkey' */
6716 else if (gvarp == &p_key)
6717 {
Bram Moolenaard7663c22019-08-06 21:59:57 +02006718 // Make sure the ":set" command doesn't show the new value in the
6719 // history.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006720 remove_key_from_history();
Bram Moolenaard7663c22019-08-06 21:59:57 +02006721
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006722 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6723 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006724 ml_set_crypt_key(curbuf, oldval,
6725 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006726 }
6727
6728 else if (gvarp == &p_cm)
6729 {
6730 if (opt_flags & OPT_LOCAL)
6731 p = curbuf->b_p_cm;
6732 else
6733 p = p_cm;
6734 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6735 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006736 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006737 errmsg = e_invarg;
6738 else
6739 {
6740 /* When setting the global value to empty, make it "zip". */
6741 if (*p_cm == NUL)
6742 {
6743 if (new_value_alloced)
6744 free_string_option(p_cm);
6745 p_cm = vim_strsave((char_u *)"zip");
6746 new_value_alloced = TRUE;
6747 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006748 /* When using ":set cm=name" the local value is going to be empty.
6749 * Do that here, otherwise the crypt functions will still use the
6750 * local value. */
6751 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6752 {
6753 free_string_option(curbuf->b_p_cm);
6754 curbuf->b_p_cm = empty_option;
6755 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006756
6757 /* Need to update the swapfile when the effective method changed.
6758 * Set "s" to the effective old value, "p" to the effective new
6759 * method and compare. */
6760 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6761 s = p_cm; /* was previously using the global value */
6762 else
6763 s = oldval;
6764 if (*curbuf->b_p_cm == NUL)
6765 p = p_cm; /* is now using the global value */
6766 else
6767 p = curbuf->b_p_cm;
6768 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006769 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006770
6771 /* If the global value changes need to update the swapfile for all
6772 * buffers using that value. */
6773 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6774 {
6775 buf_T *buf;
6776
Bram Moolenaar29323592016-07-24 22:04:11 +02006777 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006778 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006779 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006780 }
6781 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006782 }
6783#endif
6784
6785 /* 'matchpairs' */
6786 else if (gvarp == &p_mps)
6787 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006788 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006789 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006790 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006791 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006792 int x2 = -1;
6793 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006794
6795 if (*p != NUL)
6796 p += mb_ptr2len(p);
6797 if (*p != NUL)
6798 x2 = *p++;
6799 if (*p != NUL)
6800 {
6801 x3 = mb_ptr2char(p);
6802 p += mb_ptr2len(p);
6803 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006804 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006805 {
6806 errmsg = e_invarg;
6807 break;
6808 }
6809 if (*p == NUL)
6810 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006811 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006812 }
6813 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006814 {
6815 /* Check for "x:y,x:y" */
6816 for (p = *varp; *p != NUL; p += 4)
6817 {
6818 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6819 {
6820 errmsg = e_invarg;
6821 break;
6822 }
6823 if (p[3] == NUL)
6824 break;
6825 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006826 }
6827 }
6828
6829#ifdef FEAT_COMMENTS
6830 /* 'comments' */
6831 else if (gvarp == &p_com)
6832 {
6833 for (s = *varp; *s; )
6834 {
6835 while (*s && *s != ':')
6836 {
6837 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6838 && !VIM_ISDIGIT(*s) && *s != '-')
6839 {
6840 errmsg = illegal_char(errbuf, *s);
6841 break;
6842 }
6843 ++s;
6844 }
6845 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006846 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006848 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006849 if (errmsg != NULL)
6850 break;
6851 while (*s && *s != ',')
6852 {
6853 if (*s == '\\' && s[1] != NUL)
6854 ++s;
6855 ++s;
6856 }
6857 s = skip_to_option_part(s);
6858 }
6859 }
6860#endif
6861
6862 /* 'listchars' */
6863 else if (varp == &p_lcs)
6864 {
6865 errmsg = set_chars_option(varp);
6866 }
6867
Bram Moolenaar071d4272004-06-13 20:20:40 +00006868 /* 'fillchars' */
6869 else if (varp == &p_fcs)
6870 {
6871 errmsg = set_chars_option(varp);
6872 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006873
6874#ifdef FEAT_CMDWIN
6875 /* 'cedit' */
6876 else if (varp == &p_cedit)
6877 {
6878 errmsg = check_cedit();
6879 }
6880#endif
6881
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006882 /* 'verbosefile' */
6883 else if (varp == &p_vfile)
6884 {
6885 verbose_stop();
6886 if (*p_vfile != NUL && verbose_open() == FAIL)
6887 errmsg = e_invarg;
6888 }
6889
Bram Moolenaar071d4272004-06-13 20:20:40 +00006890#ifdef FEAT_VIMINFO
6891 /* 'viminfo' */
6892 else if (varp == &p_viminfo)
6893 {
6894 for (s = p_viminfo; *s;)
6895 {
6896 /* Check it's a valid character */
6897 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6898 {
6899 errmsg = illegal_char(errbuf, *s);
6900 break;
6901 }
6902 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006903 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006904 else if (*s == 'r') /* skip until next ',' */
6905 {
6906 while (*++s && *s != ',')
6907 ;
6908 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006909 else if (*s == '%')
6910 {
6911 /* optional number */
6912 while (vim_isdigit(*++s))
6913 ;
6914 }
6915 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006916 ++s; /* no extra chars */
6917 else /* must have a number */
6918 {
6919 while (vim_isdigit(*++s))
6920 ;
6921
6922 if (!VIM_ISDIGIT(*(s - 1)))
6923 {
6924 if (errbuf != NULL)
6925 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006926 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006927 transchar_byte(*(s - 1)));
6928 errmsg = errbuf;
6929 }
6930 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006931 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006932 break;
6933 }
6934 }
6935 if (*s == ',')
6936 ++s;
6937 else if (*s)
6938 {
6939 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006940 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006941 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006942 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006943 break;
6944 }
6945 }
6946 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006947 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006948 }
6949#endif /* FEAT_VIMINFO */
6950
6951 /* terminal options */
6952 else if (istermoption(&options[opt_idx]) && full_screen)
6953 {
6954 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6955 if (varp == &T_CCO)
6956 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006957 int colors = atoi((char *)T_CCO);
6958
6959 /* Only reinitialize colors if t_Co value has really changed to
6960 * avoid expensive reload of colorscheme if t_Co is set to the
6961 * same value multiple times. */
6962 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006963 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006964 t_colors = colors;
6965 if (t_colors <= 1)
6966 {
6967 if (new_value_alloced)
6968 vim_free(T_CCO);
6969 T_CCO = empty_option;
6970 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006971#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6972 if (is_term_win32())
6973 {
6974 swap_tcap();
6975 did_swaptcap = TRUE;
6976 }
6977#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006978 /* We now have a different color setup, initialize it again. */
6979 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006980 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006981 }
6982 ttest(FALSE);
6983 if (varp == &T_ME)
6984 {
6985 out_str(T_ME);
6986 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006987#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006988 /* Since t_me has been set, this probably means that the user
6989 * wants to use this as default colors. Need to reset default
6990 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006991# ifdef VIMDLL
6992 if (!gui.in_use && !gui.starting)
6993# endif
6994 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006995#endif
6996 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006997 if (varp == &T_BE && termcap_active)
6998 {
6999 if (*T_BE == NUL)
7000 /* When clearing t_BE we assume the user no longer wants
7001 * bracketed paste, thus disable it by writing t_BD. */
7002 out_str(T_BD);
7003 else
7004 out_str(T_BE);
7005 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007006 }
7007
7008#ifdef FEAT_LINEBREAK
7009 /* 'showbreak' */
7010 else if (varp == &p_sbr)
7011 {
7012 for (s = p_sbr; *s; )
7013 {
7014 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007015 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01007016 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007017 }
7018 }
7019#endif
7020
7021#ifdef FEAT_GUI
7022 /* 'guifont' */
7023 else if (varp == &p_guifont)
7024 {
7025 if (gui.in_use)
7026 {
7027 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00007028# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029 /*
7030 * Put up a font dialog and let the user select a new value.
7031 * If this is cancelled go back to the old value but don't
7032 * give an error message.
7033 */
7034 if (STRCMP(p, "*") == 0)
7035 {
7036 p = gui_mch_font_dialog(oldval);
7037
7038 if (new_value_alloced)
7039 free_string_option(p_guifont);
7040
7041 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
7042 new_value_alloced = TRUE;
7043 }
7044# endif
7045 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
7046 {
7047# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
7048 if (STRCMP(p_guifont, "*") == 0)
7049 {
7050 /* Dialog was cancelled: Keep the old value without giving
7051 * an error message. */
7052 if (new_value_alloced)
7053 free_string_option(p_guifont);
7054 p_guifont = vim_strsave(oldval);
7055 new_value_alloced = TRUE;
7056 }
7057 else
7058# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007059 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007060 }
7061 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007062 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007063 }
7064# ifdef FEAT_XFONTSET
7065 else if (varp == &p_guifontset)
7066 {
7067 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007068 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007069 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007070 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007071 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007072 }
7073# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007074 else if (varp == &p_guifontwide)
7075 {
7076 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007077 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007079 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007080 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007081 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007082#endif
7083
7084#ifdef CURSOR_SHAPE
7085 /* 'guicursor' */
7086 else if (varp == &p_guicursor)
7087 errmsg = parse_shape_opt(SHAPE_CURSOR);
7088#endif
7089
7090#ifdef FEAT_MOUSESHAPE
7091 /* 'mouseshape' */
7092 else if (varp == &p_mouseshape)
7093 {
7094 errmsg = parse_shape_opt(SHAPE_MOUSE);
7095 update_mouseshape(-1);
7096 }
7097#endif
7098
7099#ifdef FEAT_PRINTER
7100 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007101 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007102# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007103 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007104 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007105# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007106#endif
7107
7108#ifdef FEAT_LANGMAP
7109 /* 'langmap' */
7110 else if (varp == &p_langmap)
7111 langmap_set();
7112#endif
7113
7114#ifdef FEAT_LINEBREAK
7115 /* 'breakat' */
7116 else if (varp == &p_breakat)
7117 fill_breakat_flags();
7118#endif
7119
7120#ifdef FEAT_TITLE
7121 /* 'titlestring' and 'iconstring' */
7122 else if (varp == &p_titlestring || varp == &p_iconstring)
7123 {
7124# ifdef FEAT_STL_OPT
7125 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7126
7127 /* NULL => statusline syntax */
7128 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7129 stl_syntax |= flagval;
7130 else
7131 stl_syntax &= ~flagval;
7132# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007133 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007134 }
7135#endif
7136
7137#ifdef FEAT_GUI
7138 /* 'guioptions' */
7139 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007140 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007141 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007142 redraw_gui_only = TRUE;
7143 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007144#endif
7145
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007146#if defined(FEAT_GUI_TABLINE)
7147 /* 'guitablabel' */
7148 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007149 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007150 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007151 redraw_gui_only = TRUE;
7152 }
7153 /* 'guitabtooltip' */
7154 else if (varp == &p_gtt)
7155 {
7156 redraw_gui_only = TRUE;
7157 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007158#endif
7159
Bram Moolenaar071d4272004-06-13 20:20:40 +00007160#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7161 /* 'ttymouse' */
7162 else if (varp == &p_ttym)
7163 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007164 /* Switch the mouse off before changing the escape sequences used for
7165 * that. */
7166 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007167 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7168 errmsg = e_invarg;
7169 else
7170 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007171 if (termcap_active)
7172 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007173 }
7174#endif
7175
Bram Moolenaar071d4272004-06-13 20:20:40 +00007176 /* 'selection' */
7177 else if (varp == &p_sel)
7178 {
7179 if (*p_sel == NUL
7180 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7181 errmsg = e_invarg;
7182 }
7183
7184 /* 'selectmode' */
7185 else if (varp == &p_slm)
7186 {
7187 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7188 errmsg = e_invarg;
7189 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007190
7191#ifdef FEAT_BROWSE
7192 /* 'browsedir' */
7193 else if (varp == &p_bsdir)
7194 {
7195 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7196 && !mch_isdir(p_bsdir))
7197 errmsg = e_invarg;
7198 }
7199#endif
7200
Bram Moolenaar071d4272004-06-13 20:20:40 +00007201 /* 'keymodel' */
7202 else if (varp == &p_km)
7203 {
7204 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7205 errmsg = e_invarg;
7206 else
7207 {
7208 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7209 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7210 }
7211 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007212
7213 /* 'mousemodel' */
7214 else if (varp == &p_mousem)
7215 {
7216 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7217 errmsg = e_invarg;
7218#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7219 else if (*p_mousem != *oldval)
7220 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7221 * to create or delete the popup menus. */
7222 gui_motif_update_mousemodel(root_menu);
7223#endif
7224 }
7225
7226 /* 'switchbuf' */
7227 else if (varp == &p_swb)
7228 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007229 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007230 errmsg = e_invarg;
7231 }
7232
7233 /* 'debug' */
7234 else if (varp == &p_debug)
7235 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007236 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007237 errmsg = e_invarg;
7238 }
7239
7240 /* 'display' */
7241 else if (varp == &p_dy)
7242 {
7243 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7244 errmsg = e_invarg;
7245 else
7246 (void)init_chartab();
7247
7248 }
7249
Bram Moolenaar071d4272004-06-13 20:20:40 +00007250 /* 'eadirection' */
7251 else if (varp == &p_ead)
7252 {
7253 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7254 errmsg = e_invarg;
7255 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007256
7257#ifdef FEAT_CLIPBOARD
7258 /* 'clipboard' */
7259 else if (varp == &p_cb)
7260 errmsg = check_clipboard_option();
7261#endif
7262
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007263#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007264 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7265 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007266 else if (varp == &(curwin->w_s->b_p_spl)
7267 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007268 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007269 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7270
7271 if ((is_spellfile && !valid_spellfile(*varp))
7272 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007273 errmsg = e_invarg;
7274 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007275 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007276 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007277 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007278 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007279 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007280 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007281 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007282 /* 'spellsuggest' */
7283 else if (varp == &p_sps)
7284 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007285 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007286 errmsg = e_invarg;
7287 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007288 /* 'mkspellmem' */
7289 else if (varp == &p_msm)
7290 {
7291 if (spell_check_msm() != OK)
7292 errmsg = e_invarg;
7293 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007294#endif
7295
Bram Moolenaar071d4272004-06-13 20:20:40 +00007296 /* When 'bufhidden' is set, check for valid value. */
7297 else if (gvarp == &p_bh)
7298 {
7299 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7300 errmsg = e_invarg;
7301 }
7302
7303 /* When 'buftype' is set, check for valid value. */
7304 else if (gvarp == &p_bt)
7305 {
7306 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7307 errmsg = e_invarg;
7308 else
7309 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310 if (curwin->w_status_height)
7311 {
7312 curwin->w_redr_status = TRUE;
7313 redraw_later(VALID);
7314 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007315 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007316#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007317 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007318#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007319 }
7320 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007321
7322#ifdef FEAT_STL_OPT
7323 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007324 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007325 {
7326 int wid;
7327
7328 if (varp == &p_ruf) /* reset ru_wid first */
7329 ru_wid = 0;
7330 s = *varp;
7331 if (varp == &p_ruf && *s == '%')
7332 {
7333 /* set ru_wid if 'ruf' starts with "%99(" */
7334 if (*++s == '-') /* ignore a '-' */
7335 s++;
7336 wid = getdigits(&s);
7337 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7338 ru_wid = wid;
7339 else
7340 errmsg = check_stl_option(p_ruf);
7341 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007342 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007343 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007345 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007346 comp_col();
7347 }
7348#endif
7349
Bram Moolenaar071d4272004-06-13 20:20:40 +00007350 /* check if it is a valid value for 'complete' -- Acevedo */
7351 else if (gvarp == &p_cpt)
7352 {
7353 for (s = *varp; *s;)
7354 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007355 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007356 s++;
7357 if (!*s)
7358 break;
7359 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7360 {
7361 errmsg = illegal_char(errbuf, *s);
7362 break;
7363 }
7364 if (*++s != NUL && *s != ',' && *s != ' ')
7365 {
7366 if (s[-1] == 'k' || s[-1] == 's')
7367 {
7368 /* skip optional filename after 'k' and 's' */
7369 while (*s && *s != ',' && *s != ' ')
7370 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007371 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007372 ++s;
7373 ++s;
7374 }
7375 }
7376 else
7377 {
7378 if (errbuf != NULL)
7379 {
7380 sprintf((char *)errbuf,
7381 _("E535: Illegal character after <%c>"),
7382 *--s);
7383 errmsg = errbuf;
7384 }
7385 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007386 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007387 break;
7388 }
7389 }
7390 }
7391 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007392
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007393 // 'completeopt'
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007394 else if (varp == &p_cot)
7395 {
7396 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7397 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007398 else
7399 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007400 }
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007401
Bram Moolenaare2c453d2019-08-21 14:37:09 +02007402#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007403 // 'completeslash'
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007404 else if (gvarp == &p_csl)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007405 {
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007406 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
7407 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007408 errmsg = e_invarg;
7409 }
Bram Moolenaare2c453d2019-08-21 14:37:09 +02007410#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007411
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007412#ifdef FEAT_SIGNS
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007413 // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007414 else if (varp == &curwin->w_p_scl)
7415 {
7416 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7417 errmsg = e_invarg;
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007418 // When changing the 'signcolumn' to or from 'number', recompute the
7419 // width of the number column if 'number' or 'relativenumber' is set.
7420 if (((*oldval == 'n' && *(oldval + 1) == 'u')
7421 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
7422 && (curwin->w_p_nu || curwin->w_p_rnu))
7423 curwin->w_nrwidth_line_count = 0;
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007424 }
7425#endif
7426
Bram Moolenaar071d4272004-06-13 20:20:40 +00007427
Bram Moolenaar4f974752019-02-17 17:44:42 +01007428#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007429 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007430 else if (varp == &p_toolbar)
7431 {
7432 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7433 &toolbar_flags, TRUE) != OK)
7434 errmsg = e_invarg;
7435 else
7436 {
7437 out_flush();
7438 gui_mch_show_toolbar((toolbar_flags &
7439 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7440 }
7441 }
7442#endif
7443
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007444#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007445 /* 'toolbariconsize': GTK+ 2 only */
7446 else if (varp == &p_tbis)
7447 {
7448 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7449 errmsg = e_invarg;
7450 else
7451 {
7452 out_flush();
7453 gui_mch_show_toolbar((toolbar_flags &
7454 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7455 }
7456 }
7457#endif
7458
7459 /* 'pastetoggle': translate key codes like in a mapping */
7460 else if (varp == &p_pt)
7461 {
7462 if (*p_pt)
7463 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007464 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007465 if (p != NULL)
7466 {
7467 if (new_value_alloced)
7468 free_string_option(p_pt);
7469 p_pt = p;
7470 new_value_alloced = TRUE;
7471 }
7472 }
7473 }
7474
7475 /* 'backspace' */
7476 else if (varp == &p_bs)
7477 {
7478 if (VIM_ISDIGIT(*p_bs))
7479 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007480 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007481 errmsg = e_invarg;
7482 }
7483 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7484 errmsg = e_invarg;
7485 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007486 else if (varp == &p_bo)
7487 {
7488 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7489 errmsg = e_invarg;
7490 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007491
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007492 /* 'tagcase' */
7493 else if (gvarp == &p_tc)
7494 {
7495 unsigned int *flags;
7496
7497 if (opt_flags & OPT_LOCAL)
7498 {
7499 p = curbuf->b_p_tc;
7500 flags = &curbuf->b_tc_flags;
7501 }
7502 else
7503 {
7504 p = p_tc;
7505 flags = &tc_flags;
7506 }
7507
7508 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7509 /* make the local value empty: use the global value */
7510 *flags = 0;
7511 else if (*p == NUL
7512 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7513 errmsg = e_invarg;
7514 }
7515
Bram Moolenaar071d4272004-06-13 20:20:40 +00007516 /* 'casemap' */
7517 else if (varp == &p_cmp)
7518 {
7519 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7520 errmsg = e_invarg;
7521 }
7522
7523#ifdef FEAT_DIFF
7524 /* 'diffopt' */
7525 else if (varp == &p_dip)
7526 {
7527 if (diffopt_changed() == FAIL)
7528 errmsg = e_invarg;
7529 }
7530#endif
7531
7532#ifdef FEAT_FOLDING
7533 /* 'foldmethod' */
7534 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7535 {
7536 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7537 || *curwin->w_p_fdm == NUL)
7538 errmsg = e_invarg;
7539 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007540 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007541 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007542 if (foldmethodIsDiff(curwin))
7543 newFoldLevel();
7544 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007545 }
7546# ifdef FEAT_EVAL
7547 /* 'foldexpr' */
7548 else if (varp == &curwin->w_p_fde)
7549 {
7550 if (foldmethodIsExpr(curwin))
7551 foldUpdateAll(curwin);
7552 }
7553# endif
7554 /* 'foldmarker' */
7555 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7556 {
7557 p = vim_strchr(*varp, ',');
7558 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007559 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007560 else if (p == *varp || p[1] == NUL)
7561 errmsg = e_invarg;
7562 else if (foldmethodIsMarker(curwin))
7563 foldUpdateAll(curwin);
7564 }
7565 /* 'commentstring' */
7566 else if (gvarp == &p_cms)
7567 {
7568 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007569 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570 }
7571 /* 'foldopen' */
7572 else if (varp == &p_fdo)
7573 {
7574 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7575 errmsg = e_invarg;
7576 }
7577 /* 'foldclose' */
7578 else if (varp == &p_fcl)
7579 {
7580 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7581 errmsg = e_invarg;
7582 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007583 /* 'foldignore' */
7584 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7585 {
7586 if (foldmethodIsIndent(curwin))
7587 foldUpdateAll(curwin);
7588 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007589#endif
7590
Bram Moolenaar071d4272004-06-13 20:20:40 +00007591 /* 'virtualedit' */
7592 else if (varp == &p_ve)
7593 {
7594 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7595 errmsg = e_invarg;
7596 else if (STRCMP(p_ve, oldval) != 0)
7597 {
7598 /* Recompute cursor position in case the new 've' setting
7599 * changes something. */
7600 validate_virtcol();
7601 coladvance(curwin->w_virtcol);
7602 }
7603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007604
7605#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7606 else if (varp == &p_csqf)
7607 {
7608 if (p_csqf != NULL)
7609 {
7610 p = p_csqf;
7611 while (*p != NUL)
7612 {
7613 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7614 || p[1] == NUL
7615 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7616 || (p[2] != NUL && p[2] != ','))
7617 {
7618 errmsg = e_invarg;
7619 break;
7620 }
7621 else if (p[2] == NUL)
7622 break;
7623 else
7624 p += 3;
7625 }
7626 }
7627 }
7628#endif
7629
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007630#ifdef FEAT_CINDENT
7631 /* 'cinoptions' */
7632 else if (gvarp == &p_cino)
7633 {
7634 /* TODO: recognize errors */
7635 parse_cino(curbuf);
7636 }
7637#endif
7638
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007639#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007640 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007641 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007642 {
7643 if (!gui_mch_set_rendering_options(p_rop))
7644 errmsg = e_invarg;
7645 }
7646#endif
7647
Bram Moolenaard0b51382016-11-04 15:23:45 +01007648 else if (gvarp == &p_ft)
7649 {
7650 if (!valid_filetype(*varp))
7651 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007652 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007653 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007654 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007655
7656 // Since we check the value, there is no need to set P_INSECURE,
7657 // even when the value comes from a modeline.
7658 *value_checked = TRUE;
7659 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007660 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007661
7662#ifdef FEAT_SYN_HL
7663 else if (gvarp == &p_syn)
7664 {
7665 if (!valid_filetype(*varp))
7666 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007667 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007668 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007669 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007670
7671 // Since we check the value, there is no need to set P_INSECURE,
7672 // even when the value comes from a modeline.
7673 *value_checked = TRUE;
7674 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007675 }
7676#endif
7677
Bram Moolenaar825680f2017-07-22 17:04:02 +02007678#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007679 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007680 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007681 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007682 if (*curwin->w_p_twk != NUL
7683 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007684 errmsg = e_invarg;
7685 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007686 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007687 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007688 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007689 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007690 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007691 p = skipdigits(curwin->w_p_tws);
7692 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007693 || (*p != 'x' && *p != '*')
7694 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007695 errmsg = e_invarg;
7696 }
7697 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007698# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007699 // 'termwintype'
7700 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007701 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007702 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007703 errmsg = e_invarg;
7704 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007705# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007706#endif
7707
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007708#ifdef FEAT_VARTABS
7709 /* 'varsofttabstop' */
7710 else if (varp == &(curbuf->b_p_vsts))
7711 {
7712 char_u *cp;
7713
7714 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7715 {
7716 if (curbuf->b_p_vsts_array)
7717 {
7718 vim_free(curbuf->b_p_vsts_array);
7719 curbuf->b_p_vsts_array = 0;
7720 }
7721 }
7722 else
7723 {
7724 for (cp = *varp; *cp; ++cp)
7725 {
7726 if (vim_isdigit(*cp))
7727 continue;
7728 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7729 continue;
7730 errmsg = e_invarg;
7731 break;
7732 }
7733 if (errmsg == NULL)
7734 {
7735 int *oldarray = curbuf->b_p_vsts_array;
7736 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7737 {
7738 if (oldarray)
7739 vim_free(oldarray);
7740 }
7741 else
7742 errmsg = e_invarg;
7743 }
7744 }
7745 }
7746
7747 /* 'vartabstop' */
7748 else if (varp == &(curbuf->b_p_vts))
7749 {
7750 char_u *cp;
7751
7752 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7753 {
7754 if (curbuf->b_p_vts_array)
7755 {
7756 vim_free(curbuf->b_p_vts_array);
7757 curbuf->b_p_vts_array = NULL;
7758 }
7759 }
7760 else
7761 {
7762 for (cp = *varp; *cp; ++cp)
7763 {
7764 if (vim_isdigit(*cp))
7765 continue;
7766 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7767 continue;
7768 errmsg = e_invarg;
7769 break;
7770 }
7771 if (errmsg == NULL)
7772 {
7773 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007774
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007775 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7776 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007777 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007778#ifdef FEAT_FOLDING
7779 if (foldmethodIsIndent(curwin))
7780 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007781#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007782 }
7783 else
7784 errmsg = e_invarg;
7785 }
7786 }
7787 }
7788#endif
7789
Bram Moolenaar79648732019-07-18 21:43:07 +02007790#ifdef FEAT_TEXT_PROP
7791 // 'previewpopup'
7792 else if (varp == &p_pvp)
7793 {
7794 if (parse_previewpopup(NULL) == FAIL)
7795 errmsg = e_invarg;
7796 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007797# ifdef FEAT_QUICKFIX
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02007798 // 'completepopup'
7799 else if (varp == &p_cpp)
7800 {
7801 if (parse_completepopup(NULL) == FAIL)
7802 errmsg = e_invarg;
7803 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007804# endif
Bram Moolenaar79648732019-07-18 21:43:07 +02007805#endif
7806
Bram Moolenaar071d4272004-06-13 20:20:40 +00007807 /* Options that are a list of flags. */
7808 else
7809 {
7810 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007811 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007812 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007813 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007814 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007815 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007817 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007818 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007819#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007820 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007821 p = (char_u *)COCU_ALL;
7822#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007823 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007824 {
7825#ifdef FEAT_MOUSE
7826 p = (char_u *)MOUSE_ALL;
7827#else
7828 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007829 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007830#endif
7831 }
7832#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007833 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007834 p = (char_u *)GO_ALL;
7835#endif
7836 if (p != NULL)
7837 {
7838 for (s = *varp; *s; ++s)
7839 if (vim_strchr(p, *s) == NULL)
7840 {
7841 errmsg = illegal_char(errbuf, *s);
7842 break;
7843 }
7844 }
7845 }
7846
7847 /*
7848 * If error detected, restore the previous value.
7849 */
7850 if (errmsg != NULL)
7851 {
7852 if (new_value_alloced)
7853 free_string_option(*varp);
7854 *varp = oldval;
7855 /*
7856 * When resetting some values, need to act on it.
7857 */
7858 if (did_chartab)
7859 (void)init_chartab();
7860 if (varp == &p_hl)
7861 (void)highlight_changed();
7862 }
7863 else
7864 {
7865#ifdef FEAT_EVAL
7866 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007867 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007868#endif
7869 /*
7870 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007871 * Use "free_oldval", because recursiveness may change the flags under
7872 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007874 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007875 free_string_option(oldval);
7876 if (new_value_alloced)
7877 options[opt_idx].flags |= P_ALLOCED;
7878 else
7879 options[opt_idx].flags &= ~P_ALLOCED;
7880
7881 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007882 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007883 {
7884 /* global option with local value set to use global value; free
7885 * the local value and make it empty */
7886 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7887 free_string_option(*(char_u **)p);
7888 *(char_u **)p = empty_option;
7889 }
7890
7891 /* May set global value for local option. */
7892 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7893 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007894
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007895 /*
7896 * Trigger the autocommand only after setting the flags.
7897 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007898#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007899 /* When 'syntax' is set, load the syntax of that name */
7900 if (varp == &(curbuf->b_p_syn))
7901 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007902 static int syn_recursive = 0;
7903
7904 ++syn_recursive;
7905 // Only pass TRUE for "force" when the value changed or not used
7906 // recursively, to avoid endless recurrence.
7907 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7908 value_changed || syn_recursive == 1, curbuf);
Bram Moolenaarc7f1e402019-08-03 13:29:46 +02007909 curbuf->b_flags |= BF_SYN_SET;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007910 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007911 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007912#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007913 else if (varp == &(curbuf->b_p_ft))
7914 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007915 /* 'filetype' is set, trigger the FileType autocommand.
7916 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007917 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007918 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007919 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007920 static int ft_recursive = 0;
7921 int secure_save = secure;
7922
7923 // Reset the secure flag, since the value of 'filetype' has
7924 // been checked to be safe.
7925 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007926
7927 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007928 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007929 // Only pass TRUE for "force" when the value changed or not
7930 // used recursively, to avoid endless recurrence.
7931 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7932 value_changed || ft_recursive == 1, curbuf);
7933 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007934 /* Just in case the old "curbuf" is now invalid. */
7935 if (varp != &(curbuf->b_p_ft))
7936 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007937
7938 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007939 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007940 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007941#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007942 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007943 {
7944 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007945 char_u *q = curwin->w_s->b_p_spl;
7946
7947 /* Skip the first name if it is "cjk". */
7948 if (STRNCMP(q, "cjk,", 4) == 0)
7949 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007950
7951 /*
7952 * Source the spell/LANG.vim in 'runtimepath'.
7953 * They could set 'spellcapcheck' depending on the language.
7954 * Use the first name in 'spelllang' up to '_region' or
7955 * '.encoding'.
7956 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007957 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007958 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007959 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007960 if (p > q)
7961 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007962 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7963 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007964 source_runtime(fname, DIP_ALL);
7965 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007966 }
7967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007968 }
7969
7970#ifdef FEAT_MOUSE
7971 if (varp == &p_mouse)
7972 {
7973# ifdef FEAT_MOUSE_TTY
7974 if (*p_mouse == NUL)
7975 mch_setmouse(FALSE); /* switch mouse off */
7976 else
7977# endif
7978 setmouse(); /* in case 'mouse' changed */
7979 }
7980#endif
7981
Bram Moolenaar913077c2012-03-28 19:59:04 +02007982 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007983 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007984 curwin->w_set_curswant = TRUE;
7985
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007986#ifdef FEAT_GUI
7987 /* check redraw when it's not a GUI option or the GUI is active. */
7988 if (!redraw_gui_only || gui.in_use)
7989#endif
7990 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007991
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007992#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7993 if (did_swaptcap)
7994 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007995 set_termname((char_u *)"win32");
7996 init_highlight(TRUE, FALSE);
7997 }
7998#endif
7999
Bram Moolenaar071d4272004-06-13 20:20:40 +00008000 return errmsg;
8001}
8002
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01008003#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008004/*
8005 * Simple int comparison function for use with qsort()
8006 */
8007 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008008int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008009{
8010 return *(const int *)a - *(const int *)b;
8011}
8012
8013/*
8014 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
8015 * Returns error message, NULL if it's OK.
8016 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008017 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008018check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008019{
8020 char_u *s;
8021 int col;
8022 int count = 0;
8023 int color_cols[256];
8024 int i;
8025 int j = 0;
8026
Bram Moolenaar50f834d2011-09-21 13:40:17 +02008027 if (wp->w_buffer == NULL)
8028 return NULL; /* buffer was closed */
8029
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008030 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008031 {
8032 if (*s == '-' || *s == '+')
8033 {
8034 /* -N and +N: add to 'textwidth' */
8035 col = (*s == '-') ? -1 : 1;
8036 ++s;
8037 if (!VIM_ISDIGIT(*s))
8038 return e_invarg;
8039 col = col * getdigits(&s);
8040 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008041 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008042 col += wp->w_buffer->b_p_tw;
8043 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008044 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02008045 }
8046 else if (VIM_ISDIGIT(*s))
8047 col = getdigits(&s);
8048 else
8049 return e_invarg;
8050 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008051skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02008052 if (*s == NUL)
8053 break;
8054 if (*s != ',')
8055 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008056 if (*++s == NUL)
8057 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008058 }
8059
8060 vim_free(wp->w_p_cc_cols);
8061 if (count == 0)
8062 wp->w_p_cc_cols = NULL;
8063 else
8064 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008065 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008066 if (wp->w_p_cc_cols != NULL)
8067 {
8068 /* sort the columns for faster usage on screen redraw inside
8069 * win_line() */
8070 qsort(color_cols, count, sizeof(int), int_cmp);
8071
8072 for (i = 0; i < count; ++i)
8073 /* skip duplicates */
8074 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8075 wp->w_p_cc_cols[j++] = color_cols[i];
8076 wp->w_p_cc_cols[j] = -1; /* end marker */
8077 }
8078 }
8079
8080 return NULL; /* no error */
8081}
8082#endif
8083
Bram Moolenaar071d4272004-06-13 20:20:40 +00008084/*
8085 * Handle setting 'listchars' or 'fillchars'.
8086 * Returns error message, NULL if it's OK.
8087 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008088 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008089set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008090{
8091 int round, i, len, entries;
8092 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008093 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008094 struct charstab
8095 {
8096 int *cp;
8097 char *name;
8098 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008099 static struct charstab filltab[] =
8100 {
8101 {&fill_stl, "stl"},
8102 {&fill_stlnc, "stlnc"},
8103 {&fill_vert, "vert"},
8104 {&fill_fold, "fold"},
8105 {&fill_diff, "diff"},
8106 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008107 static struct charstab lcstab[] =
8108 {
8109 {&lcs_eol, "eol"},
8110 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008111 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008112 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008113 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114 {&lcs_tab2, "tab"},
8115 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008116#ifdef FEAT_CONCEAL
8117 {&lcs_conceal, "conceal"},
8118#else
8119 {NULL, "conceal"},
8120#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008121 };
8122 struct charstab *tab;
8123
Bram Moolenaar071d4272004-06-13 20:20:40 +00008124 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008125 {
8126 tab = lcstab;
8127 entries = sizeof(lcstab) / sizeof(struct charstab);
8128 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008129 else
8130 {
8131 tab = filltab;
8132 entries = sizeof(filltab) / sizeof(struct charstab);
8133 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008134
8135 /* first round: check for valid value, second round: assign values */
8136 for (round = 0; round <= 1; ++round)
8137 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008138 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008139 {
8140 /* After checking that the value is valid: set defaults: space for
8141 * 'fillchars', NUL for 'listchars' */
8142 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008143 if (tab[i].cp != NULL)
8144 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008145
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008147 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008148 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008149 lcs_tab3 = NUL;
8150 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151 else
8152 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008153 }
8154 p = *varp;
8155 while (*p)
8156 {
8157 for (i = 0; i < entries; ++i)
8158 {
8159 len = (int)STRLEN(tab[i].name);
8160 if (STRNCMP(p, tab[i].name, len) == 0
8161 && p[len] == ':'
8162 && p[len + 1] != NUL)
8163 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008164 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008166 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008167 if (mb_char2cells(c1) > 1)
8168 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 if (tab[i].cp == &lcs_tab2)
8170 {
8171 if (*s == NUL)
8172 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008174 if (mb_char2cells(c2) > 1)
8175 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008176 if (!(*s == ',' || *s == NUL))
8177 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008178 c3 = mb_ptr2char_adv(&s);
8179 if (mb_char2cells(c3) > 1)
8180 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008181 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008182 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008183
Bram Moolenaar071d4272004-06-13 20:20:40 +00008184 if (*s == ',' || *s == NUL)
8185 {
8186 if (round)
8187 {
8188 if (tab[i].cp == &lcs_tab2)
8189 {
8190 lcs_tab1 = c1;
8191 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008192 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008194 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195 *(tab[i].cp) = c1;
8196
8197 }
8198 p = s;
8199 break;
8200 }
8201 }
8202 }
8203
8204 if (i == entries)
8205 return e_invarg;
8206 if (*p == ',')
8207 ++p;
8208 }
8209 }
8210
8211 return NULL; /* no error */
8212}
8213
8214#ifdef FEAT_STL_OPT
8215/*
8216 * Check validity of options with the 'statusline' format.
8217 * Return error message or NULL.
8218 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02008219 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008220check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008221{
8222 int itemcnt = 0;
8223 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008224 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225
8226 while (*s && itemcnt < STL_MAX_ITEM)
8227 {
8228 /* Check for valid keys after % sequences */
8229 while (*s && *s != '%')
8230 s++;
8231 if (!*s)
8232 break;
8233 s++;
8234 if (*s != '%' && *s != ')')
8235 ++itemcnt;
8236 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8237 {
8238 s++;
8239 continue;
8240 }
8241 if (*s == ')')
8242 {
8243 s++;
8244 if (--groupdepth < 0)
8245 break;
8246 continue;
8247 }
8248 if (*s == '-')
8249 s++;
8250 while (VIM_ISDIGIT(*s))
8251 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008252 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008253 continue;
8254 if (*s == '.')
8255 {
8256 s++;
8257 while (*s && VIM_ISDIGIT(*s))
8258 s++;
8259 }
8260 if (*s == '(')
8261 {
8262 groupdepth++;
8263 continue;
8264 }
8265 if (vim_strchr(STL_ALL, *s) == NULL)
8266 {
8267 return illegal_char(errbuf, *s);
8268 }
8269 if (*s == '{')
8270 {
8271 s++;
8272 while (*s != '}' && *s)
8273 s++;
8274 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008275 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008276 }
8277 }
8278 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008279 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008280 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008281 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008282 return NULL;
8283}
8284#endif
8285
8286#ifdef FEAT_CLIPBOARD
8287/*
8288 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008289 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008290 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008291 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008292check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008293{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008294 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008295 int new_autoselect_star = FALSE;
8296 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008298 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008299 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008300 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008301 char_u *p;
8302
8303 for (p = p_cb; *p != NUL; )
8304 {
8305 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8306 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008307 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008308 p += 7;
8309 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008310 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008311 && (p[11] == ',' || p[11] == NUL))
8312 {
8313 new_unnamed |= CLIP_UNNAMED_PLUS;
8314 p += 11;
8315 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008317 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008318 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008319 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 p += 10;
8321 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008322 else if (STRNCMP(p, "autoselectplus", 14) == 0
8323 && (p[14] == ',' || p[14] == NUL))
8324 {
8325 new_autoselect_plus = TRUE;
8326 p += 14;
8327 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008328 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008329 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008330 {
8331 new_autoselectml = TRUE;
8332 p += 12;
8333 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008334 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8335 {
8336 new_html = TRUE;
8337 p += 4;
8338 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008339 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8340 {
8341 p += 8;
8342 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8343 if (new_exclude_prog == NULL)
8344 errmsg = e_invarg;
8345 break;
8346 }
8347 else
8348 {
8349 errmsg = e_invarg;
8350 break;
8351 }
8352 if (*p == ',')
8353 ++p;
8354 }
8355 if (errmsg == NULL)
8356 {
8357 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008358 clip_autoselect_star = new_autoselect_star;
8359 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008361 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008362 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008364#ifdef FEAT_GUI_GTK
8365 if (gui.in_use)
8366 {
8367 gui_gtk_set_selection_targets();
8368 gui_gtk_set_dnd_targets();
8369 }
8370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008371 }
8372 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008373 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374
8375 return errmsg;
8376}
8377#endif
8378
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008379#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008380/*
8381 * Handle side effects of setting 'spell'.
8382 * Return an error message or NULL for success.
8383 */
8384 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008385did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008386{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008387 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008388 win_T *wp;
8389 int l;
8390
8391 if (is_spellfile)
8392 {
8393 l = (int)STRLEN(curwin->w_s->b_p_spf);
8394 if (l > 0 && (l < 4
8395 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8396 errmsg = e_invarg;
8397 }
8398
8399 if (errmsg == NULL)
8400 {
8401 FOR_ALL_WINDOWS(wp)
8402 if (wp->w_buffer == curbuf && wp->w_p_spell)
8403 {
8404 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008405 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008406 }
8407 }
8408 return errmsg;
8409}
8410
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008411/*
8412 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8413 * Return error message when failed, NULL when OK.
8414 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008415 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008416compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008417{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008418 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008419 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008420
Bram Moolenaar860cae12010-06-05 23:22:07 +02008421 if (*synblock->b_p_spc == NUL)
8422 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008423 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008424 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008425 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008426 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008427 if (re != NULL)
8428 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008429 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008430 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008431 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008432 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008433 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008434 return e_invarg;
8435 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008436 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008437 }
8438
Bram Moolenaar473de612013-06-08 18:19:48 +02008439 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008440 return NULL;
8441}
8442#endif
8443
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008444#if defined(FEAT_EVAL) || defined(PROTO)
8445/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008446 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008447 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008448 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008449 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008450set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008451{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008452 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8453 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008454 sctx_T new_script_ctx = script_ctx;
8455
8456 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008457
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008458 /* Remember where the option was set. For local options need to do that
8459 * in the buffer or window structure. */
8460 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008461 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008462 if (both || (opt_flags & OPT_LOCAL))
8463 {
8464 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008465 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008466 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008467 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008468 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008469}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008470
8471/*
8472 * Set the script_ctx for a termcap option.
8473 * "name" must be the two character code, e.g. "RV".
8474 * When "name" is NULL use "opt_idx".
8475 */
8476 void
8477set_term_option_sctx_idx(char *name, int opt_idx)
8478{
8479 char_u buf[5];
8480 int idx;
8481
8482 if (name == NULL)
8483 idx = opt_idx;
8484 else
8485 {
8486 buf[0] = 't';
8487 buf[1] = '_';
8488 buf[2] = name[0];
8489 buf[3] = name[1];
8490 buf[4] = 0;
8491 idx = findoption(buf);
8492 }
8493 if (idx >= 0)
8494 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8495}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008496#endif
8497
Bram Moolenaar071d4272004-06-13 20:20:40 +00008498/*
8499 * Set the value of a boolean option, and take care of side effects.
8500 * Returns NULL for success, or an error message for an error.
8501 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008502 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008503set_bool_option(
8504 int opt_idx, /* index in options[] table */
8505 char_u *varp, /* pointer to the option variable */
8506 int value, /* new value */
8507 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008508{
8509 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008510#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008511 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008512#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008513
Bram Moolenaar071d4272004-06-13 20:20:40 +00008514 /* Disallow changing some options from secure mode */
8515 if ((secure
8516#ifdef HAVE_SANDBOX
8517 || sandbox != 0
8518#endif
8519 ) && (options[opt_idx].flags & P_SECURE))
8520 return e_secure;
8521
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008522#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008523 // Save the global value before changing anything. This is needed as for
8524 // a global-only option setting the "local value" in fact sets the global
8525 // value (since there is only one value).
8526 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8527 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8528 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008529#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008530
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531 *(int *)varp = value; /* set the new value */
8532#ifdef FEAT_EVAL
8533 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008534 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008535#endif
8536
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008537#ifdef FEAT_GUI
8538 need_mouse_correct = TRUE;
8539#endif
8540
Bram Moolenaar071d4272004-06-13 20:20:40 +00008541 /* May set global value for local option. */
8542 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8543 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8544
8545 /*
8546 * Handle side effects of changing a bool option.
8547 */
8548
8549 /* 'compatible' */
8550 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008551 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008552
Bram Moolenaar920694c2016-08-21 17:45:02 +02008553#ifdef FEAT_LANGMAP
8554 if ((int *)varp == &p_lrm)
8555 /* 'langremap' -> !'langnoremap' */
8556 p_lnr = !p_lrm;
8557 else if ((int *)varp == &p_lnr)
8558 /* 'langnoremap' -> !'langremap' */
8559 p_lrm = !p_lnr;
8560#endif
8561
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008562#ifdef FEAT_SYN_HL
8563 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8564 reset_cursorline();
8565#endif
8566
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008567#ifdef FEAT_PERSISTENT_UNDO
8568 /* 'undofile' */
8569 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8570 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008571 /* Only take action when the option was set. When reset we do not
8572 * delete the undo file, the option may be set again without making
8573 * any changes in between. */
8574 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008575 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008576 char_u hash[UNDO_HASH_SIZE];
8577 buf_T *save_curbuf = curbuf;
8578
Bram Moolenaar29323592016-07-24 22:04:11 +02008579 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008580 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008581 /* When 'undofile' is set globally: for every buffer, otherwise
8582 * only for the current buffer: Try to read in the undofile,
8583 * if one exists, the buffer wasn't changed and the buffer was
8584 * loaded */
8585 if ((curbuf == save_curbuf
8586 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8587 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8588 {
8589 u_compute_hash(hash);
8590 u_read_undo(NULL, hash, curbuf->b_fname);
8591 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008592 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008593 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008594 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008595 }
8596#endif
8597
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598 else if ((int *)varp == &curbuf->b_p_ro)
8599 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008600 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008601 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8602 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008603
8604 /* when 'readonly' is set may give W10 again */
8605 if (curbuf->b_p_ro)
8606 curbuf->b_did_warn = FALSE;
8607
Bram Moolenaar071d4272004-06-13 20:20:40 +00008608#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008609 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008610#endif
8611 }
8612
Bram Moolenaar9c449722010-07-20 18:44:27 +02008613#ifdef FEAT_GUI
8614 else if ((int *)varp == &p_mh)
8615 {
8616 if (!p_mh)
8617 gui_mch_mousehide(FALSE);
8618 }
8619#endif
8620
Bram Moolenaara539df02010-08-01 14:35:05 +02008621 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008623 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008624# ifdef FEAT_TERMINAL
8625 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008626 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8627 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008628 {
8629 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008630 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008631 }
8632# endif
8633# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008634 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008635# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008636 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008637#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008638 /* when 'endofline' is changed, redraw the window title */
8639 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008640 {
8641 redraw_titles();
8642 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008643 /* when 'fixeol' is changed, redraw the window title */
8644 else if ((int *)varp == &curbuf->b_p_fixeol)
8645 {
8646 redraw_titles();
8647 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008648 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008649 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008650 {
8651 redraw_titles();
8652 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008653#endif
8654
8655 /* when 'bin' is set also set some other options */
8656 else if ((int *)varp == &curbuf->b_p_bin)
8657 {
8658 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8659#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008660 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008661#endif
8662 }
8663
Bram Moolenaar071d4272004-06-13 20:20:40 +00008664 /* when 'buflisted' changes, trigger autocommands */
8665 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8666 {
8667 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8668 NULL, NULL, TRUE, curbuf);
8669 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008670
8671 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8672 else if ((int *)varp == &curbuf->b_p_swf)
8673 {
8674 if (curbuf->b_p_swf && p_uc)
8675 ml_open_file(curbuf); /* create the swap file */
8676 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008677 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8678 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008679 mf_close_file(curbuf, TRUE); /* remove the swap file */
8680 }
8681
8682 /* when 'terse' is set change 'shortmess' */
8683 else if ((int *)varp == &p_terse)
8684 {
8685 char_u *p;
8686
8687 p = vim_strchr(p_shm, SHM_SEARCH);
8688
8689 /* insert 's' in p_shm */
8690 if (p_terse && p == NULL)
8691 {
8692 STRCPY(IObuff, p_shm);
8693 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008694 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008695 }
8696 /* remove 's' from p_shm */
8697 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008698 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008699 }
8700
8701 /* when 'paste' is set or reset also change other options */
8702 else if ((int *)varp == &p_paste)
8703 {
8704 paste_option_changed();
8705 }
8706
8707 /* when 'insertmode' is set from an autocommand need to do work here */
8708 else if ((int *)varp == &p_im)
8709 {
8710 if (p_im)
8711 {
8712 if ((State & INSERT) == 0)
8713 need_start_insertmode = TRUE;
8714 stop_insert_mode = FALSE;
8715 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008716 /* only reset if it was set previously */
8717 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008718 {
8719 need_start_insertmode = FALSE;
8720 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008721 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008722 clear_cmdline = TRUE; /* remove "(insert)" */
8723 restart_edit = 0;
8724 }
8725 }
8726
8727 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8728 else if ((int *)varp == &p_ic && p_hls)
8729 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008730 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008731 }
8732
8733#ifdef FEAT_SEARCH_EXTRA
8734 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8735 else if ((int *)varp == &p_hls)
8736 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008737 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008738 }
8739#endif
8740
Bram Moolenaar071d4272004-06-13 20:20:40 +00008741 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8742 * at the end of normal_cmd() */
8743 else if ((int *)varp == &curwin->w_p_scb)
8744 {
8745 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008746 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008747 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008748 curwin->w_scbind_pos = curwin->w_topline;
8749 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008750 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008751
Bram Moolenaar4033c552017-09-16 20:54:51 +02008752#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008753 /* There can be only one window with 'previewwindow' set. */
8754 else if ((int *)varp == &curwin->w_p_pvw)
8755 {
8756 if (curwin->w_p_pvw)
8757 {
8758 win_T *win;
8759
Bram Moolenaar29323592016-07-24 22:04:11 +02008760 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008761 if (win->w_p_pvw && win != curwin)
8762 {
8763 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008764 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008765 }
8766 }
8767 }
8768#endif
8769
8770 /* when 'textmode' is set or reset also change 'fileformat' */
8771 else if ((int *)varp == &curbuf->b_p_tx)
8772 {
8773 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8774 }
8775
8776 /* when 'textauto' is set or reset also change 'fileformats' */
8777 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008778 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008779 set_string_option_direct((char_u *)"ffs", -1,
8780 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008781 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008782 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008783
8784 /*
8785 * When 'lisp' option changes include/exclude '-' in
8786 * keyword characters.
8787 */
8788#ifdef FEAT_LISP
8789 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8790 {
8791 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8792 }
8793#endif
8794
8795#ifdef FEAT_TITLE
8796 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008797 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008799 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008800 }
8801#endif
8802
8803 else if ((int *)varp == &curbuf->b_changed)
8804 {
8805 if (!value)
8806 save_file_ff(curbuf); /* Buffer is unchanged */
8807#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008808 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008810 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008811 }
8812
8813#ifdef BACKSLASH_IN_FILENAME
8814 else if ((int *)varp == &p_ssl)
8815 {
8816 if (p_ssl)
8817 {
8818 psepc = '/';
8819 psepcN = '\\';
8820 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008821 }
8822 else
8823 {
8824 psepc = '\\';
8825 psepcN = '/';
8826 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827 }
8828
8829 /* need to adjust the file name arguments and buffer names. */
8830 buflist_slash_adjust();
8831 alist_slash_adjust();
8832# ifdef FEAT_EVAL
8833 scriptnames_slash_adjust();
8834# endif
8835 }
8836#endif
8837
8838 /* If 'wrap' is set, set w_leftcol to zero. */
8839 else if ((int *)varp == &curwin->w_p_wrap)
8840 {
8841 if (curwin->w_p_wrap)
8842 curwin->w_leftcol = 0;
8843 }
8844
Bram Moolenaar071d4272004-06-13 20:20:40 +00008845 else if ((int *)varp == &p_ea)
8846 {
8847 if (p_ea && !old_value)
8848 win_equal(curwin, FALSE, 0);
8849 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008850
8851 else if ((int *)varp == &p_wiv)
8852 {
8853 /*
8854 * When 'weirdinvert' changed, set/reset 't_xs'.
8855 * Then set 'weirdinvert' according to value of 't_xs'.
8856 */
8857 if (p_wiv && !old_value)
8858 T_XS = (char_u *)"y";
8859 else if (!p_wiv && old_value)
8860 T_XS = empty_option;
8861 p_wiv = (*T_XS != NUL);
8862 }
8863
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008864#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 else if ((int *)varp == &p_beval)
8866 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008867 if (!balloonEvalForTerm)
8868 {
8869 if (p_beval && !old_value)
8870 gui_mch_enable_beval_area(balloonEval);
8871 else if (!p_beval && old_value)
8872 gui_mch_disable_beval_area(balloonEval);
8873 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008874 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008875#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008876#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008877 else if ((int *)varp == &p_bevalterm)
8878 {
8879 mch_bevalterm_changed();
8880 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008881#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008882
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008883#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008884 else if ((int *)varp == &p_acd)
8885 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008886 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008887 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008888 }
8889#endif
8890
8891#ifdef FEAT_DIFF
8892 /* 'diff' */
8893 else if ((int *)varp == &curwin->w_p_diff)
8894 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008895 /* May add or remove the buffer from the list of diff buffers. */
8896 diff_buf_adjust(curwin);
8897# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 if (foldmethodIsDiff(curwin))
8899 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008900# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008901 }
8902#endif
8903
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008904#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008905 /* 'imdisable' */
8906 else if ((int *)varp == &p_imdisable)
8907 {
8908 /* Only de-activate it here, it will be enabled when changing mode. */
8909 if (p_imdisable)
8910 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008911 else if (State & INSERT)
8912 /* When the option is set from an autocommand, it may need to take
8913 * effect right away. */
8914 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008915 }
8916#endif
8917
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008918#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008919 /* 'spell' */
8920 else if ((int *)varp == &curwin->w_p_spell)
8921 {
8922 if (curwin->w_p_spell)
8923 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008924 char *errmsg = did_set_spelllang(curwin);
8925
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008926 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008927 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008928 }
8929 }
8930#endif
8931
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932#ifdef FEAT_ARABIC
8933 if ((int *)varp == &curwin->w_p_arab)
8934 {
8935 if (curwin->w_p_arab)
8936 {
8937 /*
8938 * 'arabic' is set, handle various sub-settings.
8939 */
8940 if (!p_tbidi)
8941 {
8942 /* set rightleft mode */
8943 if (!curwin->w_p_rl)
8944 {
8945 curwin->w_p_rl = TRUE;
8946 changed_window_setting();
8947 }
8948
8949 /* Enable Arabic shaping (major part of what Arabic requires) */
8950 if (!p_arshape)
8951 {
8952 p_arshape = TRUE;
8953 redraw_later_clear();
8954 }
8955 }
8956
8957 /* Arabic requires a utf-8 encoding, inform the user if its not
8958 * set. */
8959 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008960 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008961 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8962
Bram Moolenaar8820b482017-03-16 17:23:31 +01008963 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008964 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008965#ifdef FEAT_EVAL
8966 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8967#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008968 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008969
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970 /* set 'delcombine' */
8971 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008972
8973# ifdef FEAT_KEYMAP
8974 /* Force-set the necessary keymap for arabic */
8975 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8976 OPT_LOCAL);
8977# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008978 }
8979 else
8980 {
8981 /*
8982 * 'arabic' is reset, handle various sub-settings.
8983 */
8984 if (!p_tbidi)
8985 {
8986 /* reset rightleft mode */
8987 if (curwin->w_p_rl)
8988 {
8989 curwin->w_p_rl = FALSE;
8990 changed_window_setting();
8991 }
8992
8993 /* 'arabicshape' isn't reset, it is a global option and
8994 * another window may still need it "on". */
8995 }
8996
8997 /* 'delcombine' isn't reset, it is a global option and another
8998 * window may still want it "on". */
8999
9000# ifdef FEAT_KEYMAP
9001 /* Revert to the default keymap */
9002 curbuf->b_p_iminsert = B_IMODE_NONE;
9003 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
9004# endif
9005 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00009006 }
9007
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00009008#endif
9009
Bram Moolenaar44826212019-08-22 21:23:20 +02009010#if defined(FEAT_SIGNS) && defined(FEAT_GUI)
9011 else if (((int *)varp == &curwin->w_p_nu
9012 || (int *)varp == &curwin->w_p_rnu)
9013 && gui.in_use
9014 && (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) == 'u')
9015 && curbuf->b_signlist != NULL)
9016 {
9017 // If the 'number' or 'relativenumber' options are modified and
9018 // 'signcolumn' is set to 'number', then clear the screen for a full
9019 // refresh. Otherwise the sign icons are not displayed properly in the
9020 // number column. If the 'number' option is set and only the
9021 // 'relativenumber' option is toggled, then don't refresh the screen
9022 // (optimization).
9023 if (!(curwin->w_p_nu && ((int *)varp == &curwin->w_p_rnu)))
9024 redraw_all_later(CLEAR);
9025 }
9026#endif
9027
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009028#ifdef FEAT_TERMGUICOLORS
9029 /* 'termguicolors' */
9030 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009031 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009032# ifdef FEAT_VTP
9033 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02009034 if (
9035# ifdef VIMDLL
9036 !gui.in_use && !gui.starting &&
9037# endif
9038 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009039 {
9040 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01009041 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009042 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009043 if (is_term_win32())
9044 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009045# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009046# ifdef FEAT_GUI
9047 if (!gui.in_use && !gui.starting)
9048# endif
9049 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009050# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009051 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009052 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009053 {
9054 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009055 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009056 init_highlight(TRUE, FALSE);
9057 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009058# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009059 }
9060#endif
9061
Bram Moolenaar071d4272004-06-13 20:20:40 +00009062 /*
9063 * End of handling side effects for bool options.
9064 */
9065
Bram Moolenaar53744302015-07-17 17:38:22 +02009066 /* after handling side effects, call autocommand */
9067
Bram Moolenaar071d4272004-06-13 20:20:40 +00009068 options[opt_idx].flags |= P_WAS_SET;
9069
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009070#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009071 // Don't do this while starting up or recursively.
9072 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009073 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009074 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009075
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009076 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009077 vim_snprintf((char *)buf_old_global, 2, "%d",
9078 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009079 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009080 vim_snprintf((char *)buf_type, 7, "%s",
9081 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009082 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9083 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9084 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009085 if (opt_flags & OPT_LOCAL)
9086 {
9087 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9088 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9089 }
9090 if (opt_flags & OPT_GLOBAL)
9091 {
9092 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9093 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9094 }
9095 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9096 {
9097 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9098 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9099 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9100 }
9101 if (opt_flags & OPT_MODELINE)
9102 {
9103 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9104 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9105 }
9106 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9107 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009108 reset_v_option_vars();
9109 }
9110#endif
9111
Bram Moolenaar071d4272004-06-13 20:20:40 +00009112 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009113 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009114 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009115 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009116 check_redraw(options[opt_idx].flags);
9117
9118 return NULL;
9119}
9120
9121/*
9122 * Set the value of a number option, and take care of side effects.
9123 * Returns NULL for success, or an error message for an error.
9124 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009125 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009126set_num_option(
9127 int opt_idx, /* index in options[] table */
9128 char_u *varp, /* pointer to the option variable */
9129 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009130 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009131 size_t errbuflen, /* length of "errbuf" */
9132 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009133 OPT_MODELINE */
9134{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009135 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009136 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009137#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009138 long old_global_value = 0; // only used when setting a local and
9139 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009140#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009141 long old_Rows = Rows; // remember old Rows
9142 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00009143 long *pp = (long *)varp;
9144
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009145 /* Disallow changing some options from secure mode. */
9146 if ((secure
9147#ifdef HAVE_SANDBOX
9148 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009150 ) && (options[opt_idx].flags & P_SECURE))
9151 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009152
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009153#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009154 // Save the global value before changing anything. This is needed as for
9155 // a global-only option setting the "local value" infact sets the global
9156 // value (since there is only one value).
9157 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009158 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
9159 OPT_GLOBAL);
9160#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009161
Bram Moolenaar071d4272004-06-13 20:20:40 +00009162 *pp = value;
9163#ifdef FEAT_EVAL
9164 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009165 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009166#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009167#ifdef FEAT_GUI
9168 need_mouse_correct = TRUE;
9169#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009170
Bram Moolenaar14f24742012-08-08 18:01:05 +02009171 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009172 {
9173 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009174#ifdef FEAT_VARTABS
9175 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9176 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9177 ? tabstop_first(curbuf->b_p_vts_array)
9178 : curbuf->b_p_ts;
9179#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009180 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009181#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009182 }
9183
9184 /*
9185 * Number options that need some action when changed
9186 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009187 if (pp == &p_wh || pp == &p_hh)
9188 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009189 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009190 if (p_wh < 1)
9191 {
9192 errmsg = e_positive;
9193 p_wh = 1;
9194 }
9195 if (p_wmh > p_wh)
9196 {
9197 errmsg = e_winheight;
9198 p_wh = p_wmh;
9199 }
9200 if (p_hh < 0)
9201 {
9202 errmsg = e_positive;
9203 p_hh = 0;
9204 }
9205
9206 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009207 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009208 {
9209 if (pp == &p_wh && curwin->w_height < p_wh)
9210 win_setheight((int)p_wh);
9211 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9212 win_setheight((int)p_hh);
9213 }
9214 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009215 else if (pp == &p_wmh)
9216 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009217 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009218 if (p_wmh < 0)
9219 {
9220 errmsg = e_positive;
9221 p_wmh = 0;
9222 }
9223 if (p_wmh > p_wh)
9224 {
9225 errmsg = e_winheight;
9226 p_wmh = p_wh;
9227 }
9228 win_setminheight();
9229 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009230 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009232 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009233 if (p_wiw < 1)
9234 {
9235 errmsg = e_positive;
9236 p_wiw = 1;
9237 }
9238 if (p_wmw > p_wiw)
9239 {
9240 errmsg = e_winwidth;
9241 p_wiw = p_wmw;
9242 }
9243
9244 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009245 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009246 win_setwidth((int)p_wiw);
9247 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009248 else if (pp == &p_wmw)
9249 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009250 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009251 if (p_wmw < 0)
9252 {
9253 errmsg = e_positive;
9254 p_wmw = 0;
9255 }
9256 if (p_wmw > p_wiw)
9257 {
9258 errmsg = e_winwidth;
9259 p_wmw = p_wiw;
9260 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009261 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009262 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009263
Bram Moolenaar071d4272004-06-13 20:20:40 +00009264 /* (re)set last window status line */
9265 else if (pp == &p_ls)
9266 {
9267 last_status(FALSE);
9268 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009269
9270 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009271 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009272 {
9273 shell_new_rows(); /* recompute window positions and heights */
9274 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009275
9276#ifdef FEAT_GUI
9277 else if (pp == &p_linespace)
9278 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009279 /* Recompute gui.char_height and resize the Vim window to keep the
9280 * same number of lines. */
9281 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009282 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009283 }
9284#endif
9285
9286#ifdef FEAT_FOLDING
9287 /* 'foldlevel' */
9288 else if (pp == &curwin->w_p_fdl)
9289 {
9290 if (curwin->w_p_fdl < 0)
9291 curwin->w_p_fdl = 0;
9292 newFoldLevel();
9293 }
9294
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009295 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009296 else if (pp == &curwin->w_p_fml)
9297 {
9298 foldUpdateAll(curwin);
9299 }
9300
9301 /* 'foldnestmax' */
9302 else if (pp == &curwin->w_p_fdn)
9303 {
9304 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9305 foldUpdateAll(curwin);
9306 }
9307
9308 /* 'foldcolumn' */
9309 else if (pp == &curwin->w_p_fdc)
9310 {
9311 if (curwin->w_p_fdc < 0)
9312 {
9313 errmsg = e_positive;
9314 curwin->w_p_fdc = 0;
9315 }
9316 else if (curwin->w_p_fdc > 12)
9317 {
9318 errmsg = e_invarg;
9319 curwin->w_p_fdc = 12;
9320 }
9321 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009322#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009323
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009324#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009325 /* 'shiftwidth' or 'tabstop' */
9326 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9327 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009328# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009329 if (foldmethodIsIndent(curwin))
9330 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009331# endif
9332# ifdef FEAT_CINDENT
9333 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9334 * parse 'cinoptions'. */
9335 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9336 parse_cino(curbuf);
9337# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009339#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009340
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009341 /* 'maxcombine' */
9342 else if (pp == &p_mco)
9343 {
9344 if (p_mco > MAX_MCO)
9345 p_mco = MAX_MCO;
9346 else if (p_mco < 0)
9347 p_mco = 0;
9348 screenclear(); /* will re-allocate the screen */
9349 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009350
Bram Moolenaar071d4272004-06-13 20:20:40 +00009351 else if (pp == &curbuf->b_p_iminsert)
9352 {
9353 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9354 {
9355 errmsg = e_invarg;
9356 curbuf->b_p_iminsert = B_IMODE_NONE;
9357 }
9358 p_iminsert = curbuf->b_p_iminsert;
9359 if (termcap_active) /* don't do this in the alternate screen */
9360 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009361#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009362 /* Show/unshow value of 'keymap' in status lines. */
9363 status_redraw_curbuf();
9364#endif
9365 }
9366
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009367#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9368 /* 'imstyle' */
9369 else if (pp == &p_imst)
9370 {
9371 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9372 errmsg = e_invarg;
9373 }
9374#endif
9375
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009376 else if (pp == &p_window)
9377 {
9378 if (p_window < 1)
9379 p_window = 1;
9380 else if (p_window >= Rows)
9381 p_window = Rows - 1;
9382 }
9383
Bram Moolenaar071d4272004-06-13 20:20:40 +00009384 else if (pp == &curbuf->b_p_imsearch)
9385 {
9386 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9387 {
9388 errmsg = e_invarg;
9389 curbuf->b_p_imsearch = B_IMODE_NONE;
9390 }
9391 p_imsearch = curbuf->b_p_imsearch;
9392 }
9393
9394#ifdef FEAT_TITLE
9395 /* if 'titlelen' has changed, redraw the title */
9396 else if (pp == &p_titlelen)
9397 {
9398 if (p_titlelen < 0)
9399 {
9400 errmsg = e_positive;
9401 p_titlelen = 85;
9402 }
9403 if (starting != NO_SCREEN && old_value != p_titlelen)
9404 need_maketitle = TRUE;
9405 }
9406#endif
9407
9408 /* if p_ch changed value, change the command line height */
9409 else if (pp == &p_ch)
9410 {
9411 if (p_ch < 1)
9412 {
9413 errmsg = e_positive;
9414 p_ch = 1;
9415 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009416 if (p_ch > Rows - min_rows() + 1)
9417 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418
9419 /* Only compute the new window layout when startup has been
9420 * completed. Otherwise the frame sizes may be wrong. */
9421 if (p_ch != old_value && full_screen
9422#ifdef FEAT_GUI
9423 && !gui.starting
9424#endif
9425 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009426 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009427 }
9428
9429 /* when 'updatecount' changes from zero to non-zero, open swap files */
9430 else if (pp == &p_uc)
9431 {
9432 if (p_uc < 0)
9433 {
9434 errmsg = e_positive;
9435 p_uc = 100;
9436 }
9437 if (p_uc && !old_value)
9438 ml_open_files();
9439 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009440#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009441 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009442 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009443 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009444 {
9445 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009446 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009447 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009448 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009449 {
9450 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009451 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009452 }
9453 }
9454#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009455#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009456 else if (pp == &p_mzq)
9457 mzvim_reset_timer();
9458#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009459
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009460#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9461 /* 'pyxversion' */
9462 else if (pp == &p_pyx)
9463 {
9464 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9465 errmsg = e_invarg;
9466 }
9467#endif
9468
Bram Moolenaar071d4272004-06-13 20:20:40 +00009469 /* sync undo before 'undolevels' changes */
9470 else if (pp == &p_ul)
9471 {
9472 /* use the old value, otherwise u_sync() may not work properly */
9473 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009474 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009475 p_ul = value;
9476 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009477 else if (pp == &curbuf->b_p_ul)
9478 {
9479 /* use the old value, otherwise u_sync() may not work properly */
9480 curbuf->b_p_ul = old_value;
9481 u_sync(TRUE);
9482 curbuf->b_p_ul = value;
9483 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009484
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009485#ifdef FEAT_LINEBREAK
9486 /* 'numberwidth' must be positive */
9487 else if (pp == &curwin->w_p_nuw)
9488 {
9489 if (curwin->w_p_nuw < 1)
9490 {
9491 errmsg = e_positive;
9492 curwin->w_p_nuw = 1;
9493 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009494 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009495 {
9496 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009497 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009498 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009499 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009500 }
9501#endif
9502
Bram Moolenaar1a384422010-07-14 19:53:30 +02009503 else if (pp == &curbuf->b_p_tw)
9504 {
9505 if (curbuf->b_p_tw < 0)
9506 {
9507 errmsg = e_positive;
9508 curbuf->b_p_tw = 0;
9509 }
9510#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009511 {
9512 win_T *wp;
9513 tabpage_T *tp;
9514
9515 FOR_ALL_TAB_WINDOWS(tp, wp)
9516 check_colorcolumn(wp);
9517 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009518#endif
9519 }
9520
Bram Moolenaar071d4272004-06-13 20:20:40 +00009521 /*
9522 * Check the bounds for numeric options here
9523 */
9524 if (Rows < min_rows() && full_screen)
9525 {
9526 if (errbuf != NULL)
9527 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009528 vim_snprintf((char *)errbuf, errbuflen,
9529 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009530 errmsg = errbuf;
9531 }
9532 Rows = min_rows();
9533 }
9534 if (Columns < MIN_COLUMNS && full_screen)
9535 {
9536 if (errbuf != NULL)
9537 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009538 vim_snprintf((char *)errbuf, errbuflen,
9539 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009540 errmsg = errbuf;
9541 }
9542 Columns = MIN_COLUMNS;
9543 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009544 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009545
Bram Moolenaar071d4272004-06-13 20:20:40 +00009546 /*
9547 * If the screen (shell) height has been changed, assume it is the
9548 * physical screenheight.
9549 */
9550 if (old_Rows != Rows || old_Columns != Columns)
9551 {
9552 /* Changing the screen size is not allowed while updating the screen. */
9553 if (updating_screen)
9554 *pp = old_value;
9555 else if (full_screen
9556#ifdef FEAT_GUI
9557 && !gui.starting
9558#endif
9559 )
9560 set_shellsize((int)Columns, (int)Rows, TRUE);
9561 else
9562 {
9563 /* Postpone the resizing; check the size and cmdline position for
9564 * messages. */
9565 check_shellsize();
9566 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9567 cmdline_row = Rows - p_ch;
9568 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009569 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009570 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009571 }
9572
Bram Moolenaar071d4272004-06-13 20:20:40 +00009573 if (curbuf->b_p_ts <= 0)
9574 {
9575 errmsg = e_positive;
9576 curbuf->b_p_ts = 8;
9577 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009578 if (p_tm < 0)
9579 {
9580 errmsg = e_positive;
9581 p_tm = 0;
9582 }
9583 if ((curwin->w_p_scr <= 0
9584 || (curwin->w_p_scr > curwin->w_height
9585 && curwin->w_height > 0))
9586 && full_screen)
9587 {
9588 if (pp == &(curwin->w_p_scr))
9589 {
9590 if (curwin->w_p_scr != 0)
9591 errmsg = e_scroll;
9592 win_comp_scroll(curwin);
9593 }
9594 /* If 'scroll' became invalid because of a side effect silently adjust
9595 * it. */
9596 else if (curwin->w_p_scr <= 0)
9597 curwin->w_p_scr = 1;
9598 else /* curwin->w_p_scr > curwin->w_height */
9599 curwin->w_p_scr = curwin->w_height;
9600 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009601 if (p_hi < 0)
9602 {
9603 errmsg = e_positive;
9604 p_hi = 0;
9605 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009606 else if (p_hi > 10000)
9607 {
9608 errmsg = e_invarg;
9609 p_hi = 10000;
9610 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009611 if (p_re < 0 || p_re > 2)
9612 {
9613 errmsg = e_invarg;
9614 p_re = 0;
9615 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009616 if (p_report < 0)
9617 {
9618 errmsg = e_positive;
9619 p_report = 1;
9620 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009621 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009622 {
9623 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9624 p_sj = Rows / 2;
9625 else
9626 {
9627 errmsg = e_scroll;
9628 p_sj = 1;
9629 }
9630 }
9631 if (p_so < 0 && full_screen)
9632 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009633 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009634 p_so = 0;
9635 }
9636 if (p_siso < 0 && full_screen)
9637 {
9638 errmsg = e_positive;
9639 p_siso = 0;
9640 }
9641#ifdef FEAT_CMDWIN
9642 if (p_cwh < 1)
9643 {
9644 errmsg = e_positive;
9645 p_cwh = 1;
9646 }
9647#endif
9648 if (p_ut < 0)
9649 {
9650 errmsg = e_positive;
9651 p_ut = 2000;
9652 }
9653 if (p_ss < 0)
9654 {
9655 errmsg = e_positive;
9656 p_ss = 0;
9657 }
9658
9659 /* May set global value for local option. */
9660 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9661 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9662
9663 options[opt_idx].flags |= P_WAS_SET;
9664
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009665#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009666 // Don't do this while starting up, failure or recursively.
9667 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009668 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009669 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009670 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009671 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009672 vim_snprintf((char *)buf_new, 10, "%ld", value);
9673 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009674 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9675 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9676 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009677 if (opt_flags & OPT_LOCAL)
9678 {
9679 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9680 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9681 }
9682 if (opt_flags & OPT_GLOBAL)
9683 {
9684 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9685 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9686 }
9687 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9688 {
9689 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9690 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9691 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9692 }
9693 if (opt_flags & OPT_MODELINE)
9694 {
9695 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9696 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9697 }
9698 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9699 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009700 reset_v_option_vars();
9701 }
9702#endif
9703
Bram Moolenaar071d4272004-06-13 20:20:40 +00009704 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009705 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009706 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009707 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009708 check_redraw(options[opt_idx].flags);
9709
9710 return errmsg;
9711}
9712
9713/*
9714 * Called after an option changed: check if something needs to be redrawn.
9715 */
9716 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009717check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009718{
9719 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009720 int doclear = (flags & P_RCLR) == P_RCLR;
9721 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009722
Bram Moolenaar071d4272004-06-13 20:20:40 +00009723 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9724 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009725
9726 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9727 changed_window_setting();
9728 if (flags & P_RBUF)
9729 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009730 if (flags & P_RWINONLY)
9731 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009732 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009733 redraw_all_later(CLEAR);
9734 else if (all)
9735 redraw_all_later(NOT_VALID);
9736}
9737
9738/*
9739 * Find index for option 'arg'.
9740 * Return -1 if not found.
9741 */
9742 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009743findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009744{
9745 int opt_idx;
9746 char *s, *p;
9747 static short quick_tab[27] = {0, 0}; /* quick access table */
9748 int is_term_opt;
9749
9750 /*
9751 * For first call: Initialize the quick-access table.
9752 * It contains the index for the first option that starts with a certain
9753 * letter. There are 26 letters, plus the first "t_" option.
9754 */
9755 if (quick_tab[1] == 0)
9756 {
9757 p = options[0].fullname;
9758 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9759 {
9760 if (s[0] != p[0])
9761 {
9762 if (s[0] == 't' && s[1] == '_')
9763 quick_tab[26] = opt_idx;
9764 else
9765 quick_tab[CharOrdLow(s[0])] = opt_idx;
9766 }
9767 p = s;
9768 }
9769 }
9770
9771 /*
9772 * Check for name starting with an illegal character.
9773 */
9774#ifdef EBCDIC
9775 if (!islower(arg[0]))
9776#else
9777 if (arg[0] < 'a' || arg[0] > 'z')
9778#endif
9779 return -1;
9780
9781 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9782 if (is_term_opt)
9783 opt_idx = quick_tab[26];
9784 else
9785 opt_idx = quick_tab[CharOrdLow(arg[0])];
9786 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9787 {
9788 if (STRCMP(arg, s) == 0) /* match full name */
9789 break;
9790 }
9791 if (s == NULL && !is_term_opt)
9792 {
9793 opt_idx = quick_tab[CharOrdLow(arg[0])];
9794 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9795 {
9796 s = options[opt_idx].shortname;
9797 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9798 break;
9799 s = NULL;
9800 }
9801 }
9802 if (s == NULL)
9803 opt_idx = -1;
9804 return opt_idx;
9805}
9806
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009807#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009808/*
9809 * Get the value for an option.
9810 *
9811 * Returns:
9812 * Number or Toggle option: 1, *numval gets value.
9813 * String option: 0, *stringval gets allocated string.
9814 * Hidden Number or Toggle option: -1.
9815 * hidden String option: -2.
9816 * unknown option: -3.
9817 */
9818 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009819get_option_value(
9820 char_u *name,
9821 long *numval,
9822 char_u **stringval, /* NULL when only checking existence */
9823 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009824{
9825 int opt_idx;
9826 char_u *varp;
9827
9828 opt_idx = findoption(name);
9829 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009830 {
9831 int key;
9832
9833 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009834 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009835 {
9836 char_u key_name[2];
9837 char_u *p;
9838
9839 if (key < 0)
9840 {
9841 key_name[0] = KEY2TERMCAP0(key);
9842 key_name[1] = KEY2TERMCAP1(key);
9843 }
9844 else
9845 {
9846 key_name[0] = KS_KEY;
9847 key_name[1] = (key & 0xff);
9848 }
9849 p = find_termcode(key_name);
9850 if (p != NULL)
9851 {
9852 if (stringval != NULL)
9853 *stringval = vim_strsave(p);
9854 return 0;
9855 }
9856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009857 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009858 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009859
9860 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9861
9862 if (options[opt_idx].flags & P_STRING)
9863 {
9864 if (varp == NULL) /* hidden option */
9865 return -2;
9866 if (stringval != NULL)
9867 {
9868#ifdef FEAT_CRYPT
9869 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009870 if ((char_u **)varp == &curbuf->b_p_key
9871 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009872 *stringval = vim_strsave((char_u *)"*****");
9873 else
9874#endif
9875 *stringval = vim_strsave(*(char_u **)(varp));
9876 }
9877 return 0;
9878 }
9879
9880 if (varp == NULL) /* hidden option */
9881 return -1;
9882 if (options[opt_idx].flags & P_NUM)
9883 *numval = *(long *)varp;
9884 else
9885 {
9886 /* Special case: 'modified' is b_changed, but we also want to consider
9887 * it set when 'ff' or 'fenc' changed. */
9888 if ((int *)varp == &curbuf->b_changed)
9889 *numval = curbufIsChanged();
9890 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009891 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009892 }
9893 return 1;
9894}
9895#endif
9896
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009897#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009898/*
9899 * Returns the option attributes and its value. Unlike the above function it
9900 * will return either global value or local value of the option depending on
9901 * what was requested, but it will never return global value if it was
9902 * requested to return local one and vice versa. Neither it will return
9903 * buffer-local value if it was requested to return window-local one.
9904 *
9905 * Pretends that option is absent if it is not present in the requested scope
9906 * (i.e. has no global, window-local or buffer-local value depending on
9907 * opt_type). Uses
9908 *
9909 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009910 * 0 hidden or unknown option, also option that does not have requested
9911 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009912 * see SOPT_* in vim.h for other flags
9913 *
9914 * Possible opt_type values: see SREQ_* in vim.h
9915 */
9916 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009917get_option_value_strict(
9918 char_u *name,
9919 long *numval,
9920 char_u **stringval, /* NULL when only obtaining attributes */
9921 int opt_type,
9922 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009923{
9924 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009925 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009926 struct vimoption *p;
9927 int r = 0;
9928
9929 opt_idx = findoption(name);
9930 if (opt_idx < 0)
9931 return 0;
9932
9933 p = &(options[opt_idx]);
9934
9935 /* Hidden option */
9936 if (p->var == NULL)
9937 return 0;
9938
9939 if (p->flags & P_BOOL)
9940 r |= SOPT_BOOL;
9941 else if (p->flags & P_NUM)
9942 r |= SOPT_NUM;
9943 else if (p->flags & P_STRING)
9944 r |= SOPT_STRING;
9945
9946 if (p->indir == PV_NONE)
9947 {
9948 if (opt_type == SREQ_GLOBAL)
9949 r |= SOPT_GLOBAL;
9950 else
9951 return 0; /* Did not request global-only option */
9952 }
9953 else
9954 {
9955 if (p->indir & PV_BOTH)
9956 r |= SOPT_GLOBAL;
9957 else if (opt_type == SREQ_GLOBAL)
9958 return 0; /* Requested global option */
9959
9960 if (p->indir & PV_WIN)
9961 {
9962 if (opt_type == SREQ_BUF)
9963 return 0; /* Did not request window-local option */
9964 else
9965 r |= SOPT_WIN;
9966 }
9967 else if (p->indir & PV_BUF)
9968 {
9969 if (opt_type == SREQ_WIN)
9970 return 0; /* Did not request buffer-local option */
9971 else
9972 r |= SOPT_BUF;
9973 }
9974 }
9975
9976 if (stringval == NULL)
9977 return r;
9978
9979 if (opt_type == SREQ_GLOBAL)
9980 varp = p->var;
9981 else
9982 {
9983 if (opt_type == SREQ_BUF)
9984 {
9985 /* Special case: 'modified' is b_changed, but we also want to
9986 * consider it set when 'ff' or 'fenc' changed. */
9987 if (p->indir == PV_MOD)
9988 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009989 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009990 varp = NULL;
9991 }
9992#ifdef FEAT_CRYPT
9993 else if (p->indir == PV_KEY)
9994 {
9995 /* never return the value of the crypt key */
9996 *stringval = NULL;
9997 varp = NULL;
9998 }
9999#endif
10000 else
10001 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010002 buf_T *save_curbuf = curbuf;
10003
10004 // only getting a pointer, no need to use aucmd_prepbuf()
10005 curbuf = (buf_T *)from;
10006 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010007 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +020010008 curbuf = save_curbuf;
10009 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010010 }
10011 }
10012 else if (opt_type == SREQ_WIN)
10013 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010014 win_T *save_curwin = curwin;
10015
10016 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010017 curbuf = curwin->w_buffer;
10018 varp = get_varp(p);
10019 curwin = save_curwin;
10020 curbuf = curwin->w_buffer;
10021 }
10022 if (varp == p->var)
10023 return (r | SOPT_UNSET);
10024 }
10025
10026 if (varp != NULL)
10027 {
10028 if (p->flags & P_STRING)
10029 *stringval = vim_strsave(*(char_u **)(varp));
10030 else if (p->flags & P_NUM)
10031 *numval = *(long *) varp;
10032 else
10033 *numval = *(int *)varp;
10034 }
10035
10036 return r;
10037}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010038
10039/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010040 * Iterate over options. First argument is a pointer to a pointer to a
10041 * structure inside options[] array, second is option type like in the above
10042 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010043 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010044 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010045 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010046 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010047 * first argument to NULL.
10048 *
10049 * Returns full option name for current option on each call.
10050 */
10051 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010052option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010053{
10054 struct vimoption *ret = NULL;
10055 do
10056 {
10057 if (*option == NULL)
10058 *option = (void *) options;
10059 else if (((struct vimoption *) (*option))->fullname == NULL)
10060 {
10061 *option = NULL;
10062 return NULL;
10063 }
10064 else
10065 *option = (void *) (((struct vimoption *) (*option)) + 1);
10066
10067 ret = ((struct vimoption *) (*option));
10068
10069 /* Hidden option */
10070 if (ret->var == NULL)
10071 {
10072 ret = NULL;
10073 continue;
10074 }
10075
10076 switch (opt_type)
10077 {
10078 case SREQ_GLOBAL:
10079 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
10080 ret = NULL;
10081 break;
10082 case SREQ_BUF:
10083 if (!(ret->indir & PV_BUF))
10084 ret = NULL;
10085 break;
10086 case SREQ_WIN:
10087 if (!(ret->indir & PV_WIN))
10088 ret = NULL;
10089 break;
10090 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +010010091 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010092 return NULL;
10093 }
10094 }
10095 while (ret == NULL);
10096
10097 return (char_u *)ret->fullname;
10098}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010099#endif
10100
Bram Moolenaar071d4272004-06-13 20:20:40 +000010101/*
10102 * Set the value of option "name".
10103 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010104 *
10105 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010106 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010107 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010108set_option_value(
10109 char_u *name,
10110 long number,
10111 char_u *string,
10112 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010113{
10114 int opt_idx;
10115 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010116 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010117
10118 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010119 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010120 {
10121 int key;
10122
10123 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010124 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010125 {
10126 char_u key_name[2];
10127
10128 if (key < 0)
10129 {
10130 key_name[0] = KEY2TERMCAP0(key);
10131 key_name[1] = KEY2TERMCAP1(key);
10132 }
10133 else
10134 {
10135 key_name[0] = KS_KEY;
10136 key_name[1] = (key & 0xff);
10137 }
10138 add_termcode(key_name, string, FALSE);
10139 if (full_screen)
10140 ttest(FALSE);
10141 redraw_all_later(CLEAR);
10142 return NULL;
10143 }
10144
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010145 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +010010146 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010147 else
10148 {
10149 flags = options[opt_idx].flags;
10150#ifdef HAVE_SANDBOX
10151 /* Disallow changing some options in the sandbox */
10152 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010153 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010154 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010155 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010156 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010157#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010158 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010159 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010160 else
10161 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010162 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010163 if (varp != NULL) /* hidden option is not changed */
10164 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010165 if (number == 0 && string != NULL)
10166 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010167 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010168
10169 /* Either we are given a string or we are setting option
10170 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010171 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010172 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010173 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010174 {
10175 /* There's another character after zeros or the string
10176 * is empty. In both cases, we are trying to set a
10177 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010178 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010179 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010180 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010181
10182 }
10183 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010184 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010185 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010186 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010187 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010188 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010189 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010190 }
10191 }
10192 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010193 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010194}
10195
10196/*
10197 * Get the terminal code for a terminal option.
10198 * Returns NULL when not found.
10199 */
10200 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010201get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010202{
10203 int opt_idx;
10204 char_u *varp;
10205
10206 if (tname[0] != 't' || tname[1] != '_' ||
10207 tname[2] == NUL || tname[3] == NUL)
10208 return NULL;
10209 if ((opt_idx = findoption(tname)) >= 0)
10210 {
10211 varp = get_varp(&(options[opt_idx]));
10212 if (varp != NULL)
10213 varp = *(char_u **)(varp);
10214 return varp;
10215 }
10216 return find_termcode(tname + 2);
10217}
10218
10219 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010220get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010221{
10222 int i;
10223
10224 i = findoption((char_u *)"hl");
10225 if (i >= 0)
10226 return options[i].def_val[VI_DEFAULT];
10227 return (char_u *)NULL;
10228}
10229
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010230 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010231get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010232{
10233 int i;
10234
10235 i = findoption((char_u *)"enc");
10236 if (i >= 0)
10237 return options[i].def_val[VI_DEFAULT];
10238 return (char_u *)NULL;
10239}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010240
Bram Moolenaar071d4272004-06-13 20:20:40 +000010241/*
10242 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010243 * When "has_lt" is true there is a '<' before "*arg_arg".
10244 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010245 */
10246 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010247find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010249 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010250 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010251 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252
10253 /*
10254 * Don't use get_special_key_code() for t_xx, we don't want it to call
10255 * add_termcap_entry().
10256 */
10257 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10258 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010259 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010260 {
10261 --arg; /* put arg at the '<' */
10262 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010263 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010264 if (modifiers) /* can't handle modifiers here */
10265 key = 0;
10266 }
10267 return key;
10268}
10269
10270/*
10271 * if 'all' == 0: show changed options
10272 * if 'all' == 1: show all normal options
10273 * if 'all' == 2: show all terminal options
10274 */
10275 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010276showoptions(
10277 int all,
10278 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279{
10280 struct vimoption *p;
10281 int col;
10282 int isterm;
10283 char_u *varp;
10284 struct vimoption **items;
10285 int item_count;
10286 int run;
10287 int row, rows;
10288 int cols;
10289 int i;
10290 int len;
10291
10292#define INC 20
10293#define GAP 3
10294
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010295 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010296 if (items == NULL)
10297 return;
10298
10299 /* Highlight title */
10300 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010301 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010303 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010304 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010305 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010307 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010308
10309 /*
10310 * do the loop two times:
10311 * 1. display the short items
10312 * 2. display the long items (only strings and numbers)
10313 */
10314 for (run = 1; run <= 2 && !got_int; ++run)
10315 {
10316 /*
10317 * collect the items in items[]
10318 */
10319 item_count = 0;
10320 for (p = &options[0]; p->fullname != NULL; p++)
10321 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010322 // apply :filter /pat/
10323 if (message_filtered((char_u *) p->fullname))
10324 continue;
10325
Bram Moolenaar071d4272004-06-13 20:20:40 +000010326 varp = NULL;
10327 isterm = istermoption(p);
10328 if (opt_flags != 0)
10329 {
10330 if (p->indir != PV_NONE && !isterm)
10331 varp = get_varp_scope(p, opt_flags);
10332 }
10333 else
10334 varp = get_varp(p);
10335 if (varp != NULL
10336 && ((all == 2 && isterm)
10337 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010338 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010339 {
10340 if (p->flags & P_BOOL)
10341 len = 1; /* a toggle option fits always */
10342 else
10343 {
10344 option_value2string(p, opt_flags);
10345 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10346 }
10347 if ((len <= INC - GAP && run == 1) ||
10348 (len > INC - GAP && run == 2))
10349 items[item_count++] = p;
10350 }
10351 }
10352
10353 /*
10354 * display the items
10355 */
10356 if (run == 1)
10357 {
10358 cols = (Columns + GAP - 3) / INC;
10359 if (cols == 0)
10360 cols = 1;
10361 rows = (item_count + cols - 1) / cols;
10362 }
10363 else /* run == 2 */
10364 rows = item_count;
10365 for (row = 0; row < rows && !got_int; ++row)
10366 {
10367 msg_putchar('\n'); /* go to next line */
10368 if (got_int) /* 'q' typed in more */
10369 break;
10370 col = 0;
10371 for (i = row; i < item_count; i += rows)
10372 {
10373 msg_col = col; /* make columns */
10374 showoneopt(items[i], opt_flags);
10375 col += INC;
10376 }
10377 out_flush();
10378 ui_breakcheck();
10379 }
10380 }
10381 vim_free(items);
10382}
10383
10384/*
10385 * Return TRUE if option "p" has its default value.
10386 */
10387 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010388optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389{
10390 int dvi;
10391
10392 if (varp == NULL)
10393 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010394 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010396 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010397 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010398 /* the cast to long is required for Manx C, long_i is
10399 * needed for MSVC */
10400 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010401 /* P_STRING */
10402 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10403}
10404
10405/*
10406 * showoneopt: show the value of one option
10407 * must not be called with a hidden option!
10408 */
10409 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010410showoneopt(
10411 struct vimoption *p,
10412 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010413{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010414 char_u *varp;
10415 int save_silent = silent_mode;
10416
10417 silent_mode = FALSE;
10418 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010419
10420 varp = get_varp_scope(p, opt_flags);
10421
10422 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10423 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10424 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010425 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010427 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010428 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010429 msg_puts(" ");
10430 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010431 if (!(p->flags & P_BOOL))
10432 {
10433 msg_putchar('=');
10434 /* put value string in NameBuff */
10435 option_value2string(p, opt_flags);
10436 msg_outtrans(NameBuff);
10437 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010438
10439 silent_mode = save_silent;
10440 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010441}
10442
10443/*
10444 * Write modified options as ":set" commands to a file.
10445 *
10446 * There are three values for "opt_flags":
10447 * OPT_GLOBAL: Write global option values and fresh values of
10448 * buffer-local options (used for start of a session
10449 * file).
10450 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10451 * curwin (used for a vimrc file).
10452 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10453 * and local values for window-local options of
10454 * curwin. Local values are also written when at the
10455 * default value, because a modeline or autocommand
10456 * may have set them when doing ":edit file" and the
10457 * user has set them back at the default or fresh
10458 * value.
10459 * When "local_only" is TRUE, don't write fresh
10460 * values, only local values (for ":mkview").
10461 * (fresh value = value used for a new buffer or window for a local option).
10462 *
10463 * Return FAIL on error, OK otherwise.
10464 */
10465 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010466makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010467{
10468 struct vimoption *p;
10469 char_u *varp; /* currently used value */
10470 char_u *varp_fresh; /* local value */
10471 char_u *varp_local = NULL; /* fresh value */
10472 char *cmd;
10473 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010474 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010475
10476 /*
10477 * The options that don't have a default (terminal name, columns, lines)
10478 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010479 * Do the loop over "options[]" twice: once for options with the
10480 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010481 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010482 for (pri = 1; pri >= 0; --pri)
10483 {
10484 for (p = &options[0]; !istermoption(p); p++)
10485 if (!(p->flags & P_NO_MKRC)
10486 && !istermoption(p)
10487 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010488 {
10489 /* skip global option when only doing locals */
10490 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10491 continue;
10492
10493 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10494 * file, they are always buffer-specific. */
10495 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10496 continue;
10497
10498 /* Global values are only written when not at the default value. */
10499 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010500 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501 continue;
10502
10503 round = 2;
10504 if (p->indir != PV_NONE)
10505 {
10506 if (p->var == VAR_WIN)
10507 {
10508 /* skip window-local option when only doing globals */
10509 if (!(opt_flags & OPT_LOCAL))
10510 continue;
10511 /* When fresh value of window-local option is not at the
10512 * default, need to write it too. */
10513 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10514 {
10515 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010516 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010517 {
10518 round = 1;
10519 varp_local = varp;
10520 varp = varp_fresh;
10521 }
10522 }
10523 }
10524 }
10525
10526 /* Round 1: fresh value for window-local options.
10527 * Round 2: other values */
10528 for ( ; round <= 2; varp = varp_local, ++round)
10529 {
10530 if (round == 1 || (opt_flags & OPT_GLOBAL))
10531 cmd = "set";
10532 else
10533 cmd = "setlocal";
10534
10535 if (p->flags & P_BOOL)
10536 {
10537 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10538 return FAIL;
10539 }
10540 else if (p->flags & P_NUM)
10541 {
10542 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10543 return FAIL;
10544 }
10545 else /* P_STRING */
10546 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010547 int do_endif = FALSE;
10548
Bram Moolenaar071d4272004-06-13 20:20:40 +000010549 /* Don't set 'syntax' and 'filetype' again if the value is
10550 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010551 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010552#if defined(FEAT_SYN_HL)
10553 p->indir == PV_SYN ||
10554#endif
10555 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010556 {
10557 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10558 *(char_u **)(varp)) < 0
10559 || put_eol(fd) < 0)
10560 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010561 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010562 }
10563 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010564 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010565 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010566 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010567 {
10568 if (put_line(fd, "endif") == FAIL)
10569 return FAIL;
10570 }
10571 }
10572 }
10573 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010574 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575 return OK;
10576}
10577
10578#if defined(FEAT_FOLDING) || defined(PROTO)
10579/*
10580 * Generate set commands for the local fold options only. Used when
10581 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10582 */
10583 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010584makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010586 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010588 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010589 == FAIL
10590# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010591 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010593 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010594 == FAIL
10595 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10596 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10597 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10598 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10599 )
10600 return FAIL;
10601
10602 return OK;
10603}
10604#endif
10605
10606 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010607put_setstring(
10608 FILE *fd,
10609 char *cmd,
10610 char *name,
10611 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010612 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613{
10614 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010615 char_u *buf = NULL;
10616 char_u *part = NULL;
10617 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618
10619 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10620 return FAIL;
10621 if (*valuep != NULL)
10622 {
10623 /* Output 'pastetoggle' as key names. For other
10624 * options some characters have to be escaped with
10625 * CTRL-V or backslash */
10626 if (valuep == &p_pt)
10627 {
10628 s = *valuep;
10629 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010630 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010631 return FAIL;
10632 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010633 // expand the option value, replace $HOME by ~
10634 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010635 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010636 int size = (int)STRLEN(*valuep) + 1;
10637
10638 // replace home directory in the whole option value into "buf"
10639 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010640 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010641 goto fail;
10642 home_replace(NULL, *valuep, buf, size, FALSE);
10643
10644 // If the option value is longer than MAXPATHL, we need to append
10645 // earch comma separated part of the option separately, so that it
10646 // can be expanded when read back.
10647 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10648 && vim_strchr(*valuep, ',') != NULL)
10649 {
10650 part = alloc(size);
10651 if (part == NULL)
10652 goto fail;
10653
10654 // write line break to clear the option, e.g. ':set rtp='
10655 if (put_eol(fd) == FAIL)
10656 goto fail;
10657
10658 p = buf;
10659 while (*p != NUL)
10660 {
10661 // for each comma separated option part, append value to
10662 // the option, :set rtp+=value
10663 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10664 goto fail;
10665 (void)copy_option_part(&p, part, size, ",");
10666 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10667 goto fail;
10668 }
10669 vim_free(buf);
10670 vim_free(part);
10671 return OK;
10672 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010673 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010674 {
10675 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010676 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010677 }
10678 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679 }
10680 else if (put_escstr(fd, *valuep, 2) == FAIL)
10681 return FAIL;
10682 }
10683 if (put_eol(fd) < 0)
10684 return FAIL;
10685 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010686fail:
10687 vim_free(buf);
10688 vim_free(part);
10689 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010690}
10691
10692 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010693put_setnum(
10694 FILE *fd,
10695 char *cmd,
10696 char *name,
10697 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010698{
10699 long wc;
10700
10701 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10702 return FAIL;
10703 if (wc_use_keyname((char_u *)valuep, &wc))
10704 {
10705 /* print 'wildchar' and 'wildcharm' as a key name */
10706 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10707 return FAIL;
10708 }
10709 else if (fprintf(fd, "%ld", *valuep) < 0)
10710 return FAIL;
10711 if (put_eol(fd) < 0)
10712 return FAIL;
10713 return OK;
10714}
10715
10716 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010717put_setbool(
10718 FILE *fd,
10719 char *cmd,
10720 char *name,
10721 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010722{
Bram Moolenaar893de922007-10-02 18:40:57 +000010723 if (value < 0) /* global/local option using global value */
10724 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010725 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10726 || put_eol(fd) < 0)
10727 return FAIL;
10728 return OK;
10729}
10730
10731/*
10732 * Clear all the terminal options.
10733 * If the option has been allocated, free the memory.
10734 * Terminal options are never hidden or indirect.
10735 */
10736 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010737clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010738{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739 /*
10740 * Reset a few things before clearing the old options. This may cause
10741 * outputting a few things that the terminal doesn't understand, but the
10742 * screen will be cleared later, so this is OK.
10743 */
10744#ifdef FEAT_MOUSE_TTY
10745 mch_setmouse(FALSE); /* switch mouse off */
10746#endif
10747#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010748 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010749#endif
10750#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10751 /* When starting the GUI close the display opened for the clipboard.
10752 * After restoring the title, because that will need the display. */
10753 if (gui.starting)
10754 clear_xterm_clip();
10755#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010756 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010758 free_termoptions();
10759}
10760
10761 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010762free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010763{
10764 struct vimoption *p;
10765
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010766 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767 if (istermoption(p))
10768 {
10769 if (p->flags & P_ALLOCED)
10770 free_string_option(*(char_u **)(p->var));
10771 if (p->flags & P_DEF_ALLOCED)
10772 free_string_option(p->def_val[VI_DEFAULT]);
10773 *(char_u **)(p->var) = empty_option;
10774 p->def_val[VI_DEFAULT] = empty_option;
10775 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010776#ifdef FEAT_EVAL
10777 // remember where the option was cleared
10778 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10779#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780 }
10781 clear_termcodes();
10782}
10783
10784/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010785 * Free the string for one term option, if it was allocated.
10786 * Set the string to empty_option and clear allocated flag.
10787 * "var" points to the option value.
10788 */
10789 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010790free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010791{
10792 struct vimoption *p;
10793
10794 for (p = &options[0]; p->fullname != NULL; p++)
10795 if (p->var == var)
10796 {
10797 if (p->flags & P_ALLOCED)
10798 free_string_option(*(char_u **)(p->var));
10799 *(char_u **)(p->var) = empty_option;
10800 p->flags &= ~P_ALLOCED;
10801 break;
10802 }
10803}
10804
10805/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806 * Set the terminal option defaults to the current value.
10807 * Used after setting the terminal name.
10808 */
10809 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010810set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010811{
10812 struct vimoption *p;
10813
10814 for (p = &options[0]; p->fullname != NULL; p++)
10815 {
10816 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10817 {
10818 if (p->flags & P_DEF_ALLOCED)
10819 {
10820 free_string_option(p->def_val[VI_DEFAULT]);
10821 p->flags &= ~P_DEF_ALLOCED;
10822 }
10823 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10824 if (p->flags & P_ALLOCED)
10825 {
10826 p->flags |= P_DEF_ALLOCED;
10827 p->flags &= ~P_ALLOCED; /* don't free the value now */
10828 }
10829 }
10830 }
10831}
10832
10833/*
10834 * return TRUE if 'p' starts with 't_'
10835 */
10836 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010837istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838{
10839 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10840}
10841
10842/*
10843 * Compute columns for ruler and shown command. 'sc_col' is also used to
10844 * decide what the maximum length of a message on the status line can be.
10845 * If there is a status line for the last window, 'sc_col' is independent
10846 * of 'ru_col'.
10847 */
10848
10849#define COL_RULER 17 /* columns needed by standard ruler */
10850
10851 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010852comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010853{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010854#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010855 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010856
10857 sc_col = 0;
10858 ru_col = 0;
10859 if (p_ru)
10860 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010861# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010863# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010865# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866 /* no last status line, adjust sc_col */
10867 if (!last_has_status)
10868 sc_col = ru_col;
10869 }
10870 if (p_sc)
10871 {
10872 sc_col += SHOWCMD_COLS;
10873 if (!p_ru || last_has_status) /* no need for separating space */
10874 ++sc_col;
10875 }
10876 sc_col = Columns - sc_col;
10877 ru_col = Columns - ru_col;
10878 if (sc_col <= 0) /* screen too narrow, will become a mess */
10879 sc_col = 1;
10880 if (ru_col <= 0)
10881 ru_col = 1;
10882#else
10883 sc_col = Columns;
10884 ru_col = Columns;
10885#endif
Bram Moolenaar37f4cbd2019-08-23 20:58:45 +020010886#ifdef FEAT_EVAL
10887 set_vim_var_nr(VV_ECHOSPACE, sc_col - 1);
10888#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010889}
10890
Bram Moolenaar113e1072019-01-20 15:30:40 +010010891#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010893 * Unset local option value, similar to ":set opt<".
10894 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010895 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010896unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010897{
10898 struct vimoption *p;
10899 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010900 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010901
10902 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010903 if (opt_idx < 0)
10904 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010905 p = &(options[opt_idx]);
10906
10907 switch ((int)p->indir)
10908 {
10909 /* global option with local value: use local value if it's been set */
10910 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010911 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010912 break;
10913 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010914 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010915 break;
10916 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010917 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010918 break;
10919 case PV_AR:
10920 buf->b_p_ar = -1;
10921 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010922 case PV_BKC:
10923 clear_string_option(&buf->b_p_bkc);
10924 buf->b_bkc_flags = 0;
10925 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010926 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010927 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010928 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010929 case PV_TC:
10930 clear_string_option(&buf->b_p_tc);
10931 buf->b_tc_flags = 0;
10932 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010933 case PV_SISO:
10934 curwin->w_p_siso = -1;
10935 break;
10936 case PV_SO:
10937 curwin->w_p_so = -1;
10938 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010939#ifdef FEAT_FIND_ID
10940 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010941 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010942 break;
10943 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010944 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010945 break;
10946#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010947 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010948 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010949 break;
10950 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010951 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010952 break;
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010953 case PV_FP:
10954 clear_string_option(&buf->b_p_fp);
10955 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010956#ifdef FEAT_QUICKFIX
10957 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010958 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010959 break;
10960 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010961 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010962 break;
10963 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010964 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010965 break;
10966#endif
10967#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10968 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010969 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010970 break;
10971#endif
10972#if defined(FEAT_CRYPT)
10973 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010974 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010975 break;
10976#endif
10977#ifdef FEAT_STL_OPT
10978 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010979 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010980 break;
10981#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010982 case PV_UL:
10983 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10984 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010985#ifdef FEAT_LISP
10986 case PV_LW:
10987 clear_string_option(&buf->b_p_lw);
10988 break;
10989#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010990 case PV_MENC:
10991 clear_string_option(&buf->b_p_menc);
10992 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010993 }
10994}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010995#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010996
10997/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010998 * Get pointer to option variable, depending on local or global scope.
10999 */
11000 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011001get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011002{
11003 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
11004 {
11005 if (p->var == VAR_WIN)
11006 return (char_u *)GLOBAL_WO(get_varp(p));
11007 return p->var;
11008 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011009 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011010 {
11011 switch ((int)p->indir)
11012 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011013 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011014#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011015 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
11016 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
11017 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011018#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011019 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
11020 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
11021 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011022 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011023 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011024 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010011025 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
11026 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011027#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011028 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
11029 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011030#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011031 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
11032 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011033#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11034 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
11035#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011036#if defined(FEAT_CRYPT)
11037 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
11038#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011039#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011040 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011041#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011042 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011043#ifdef FEAT_LISP
11044 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
11045#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011046 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011047 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011048 }
11049 return NULL; /* "cannot happen" */
11050 }
11051 return get_varp(p);
11052}
11053
11054/*
11055 * Get pointer to option variable.
11056 */
11057 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011058get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011059{
11060 /* hidden option, always return NULL */
11061 if (p->var == NULL)
11062 return NULL;
11063
11064 switch ((int)p->indir)
11065 {
11066 case PV_NONE: return p->var;
11067
11068 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011069 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011070 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011071 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011072 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011073 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011075 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000011076 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011077 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011078 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011079 case PV_TC: return *curbuf->b_p_tc != NUL
11080 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011081 case PV_BKC: return *curbuf->b_p_bkc != NUL
11082 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010011083 case PV_SISO: return curwin->w_p_siso >= 0
11084 ? (char_u *)&(curwin->w_p_siso) : p->var;
11085 case PV_SO: return curwin->w_p_so >= 0
11086 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011087#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011088 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011090 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 ? (char_u *)&(curbuf->b_p_inc) : p->var;
11092#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011093 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011094 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011095 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011097 case PV_FP: return *curbuf->b_p_fp != NUL
11098 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011100 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011101 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011102 case PV_GP: return *curbuf->b_p_gp != NUL
11103 ? (char_u *)&(curbuf->b_p_gp) : p->var;
11104 case PV_MP: return *curbuf->b_p_mp != NUL
11105 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011106#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011107#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11108 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
11109 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
11110#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011111#if defined(FEAT_CRYPT)
11112 case PV_CM: return *curbuf->b_p_cm != NUL
11113 ? (char_u *)&(curbuf->b_p_cm) : p->var;
11114#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011115#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011116 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011117 ? (char_u *)&(curwin->w_p_stl) : p->var;
11118#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011119 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
11120 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011121#ifdef FEAT_LISP
11122 case PV_LW: return *curbuf->b_p_lw != NUL
11123 ? (char_u *)&(curbuf->b_p_lw) : p->var;
11124#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011125 case PV_MENC: return *curbuf->b_p_menc != NUL
11126 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011127#ifdef FEAT_ARABIC
11128 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
11129#endif
11130 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011131#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011132 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
11133#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011134#ifdef FEAT_SYN_HL
11135 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
11136 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011137 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011138#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011139#ifdef FEAT_DIFF
11140 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
11141#endif
11142#ifdef FEAT_FOLDING
11143 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
11144 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
11145 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
11146 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
11147 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
11148 case PV_FML: return (char_u *)&(curwin->w_p_fml);
11149 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
11150# ifdef FEAT_EVAL
11151 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11152 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11153# endif
11154 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11155#endif
11156 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011157 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011158#ifdef FEAT_LINEBREAK
11159 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011161 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011162 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011163#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11165#endif
11166#ifdef FEAT_RIGHTLEFT
11167 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11168 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11169#endif
11170 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11171 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11172#ifdef FEAT_LINEBREAK
11173 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011174 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11175 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011176#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011177 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011178 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011179 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011180#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011181 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11182 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11183#endif
11184#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011185 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11186 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11187 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011188#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011189
11190 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11191 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011192 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011193 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11194 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011195 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11196 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11197#ifdef FEAT_CINDENT
11198 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11199 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11200 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11201#endif
11202#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11203 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11204#endif
11205#ifdef FEAT_COMMENTS
11206 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11207#endif
11208#ifdef FEAT_FOLDING
11209 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011211 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaare2c453d2019-08-21 14:37:09 +020011212#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011213 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011214#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011215#ifdef FEAT_COMPL_FUNC
11216 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011217 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011218#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011219#ifdef FEAT_EVAL
11220 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11221#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011222 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011223 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011224 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011226 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011227 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011228 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011229 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011230 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11231 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11232 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11233 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11234#ifdef FEAT_FIND_ID
11235# ifdef FEAT_EVAL
11236 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11237# endif
11238#endif
11239#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11240 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11241 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11242#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011243#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011244 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11245#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011246#ifdef FEAT_CRYPT
11247 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11248#endif
11249#ifdef FEAT_LISP
11250 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11251#endif
11252 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11253 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11254 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11255 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11256 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011257 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011258#ifdef FEAT_TEXTOBJ
11259 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011261 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11262#ifdef FEAT_SMARTINDENT
11263 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11264#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011265 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011266 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11267#ifdef FEAT_SEARCHPATH
11268 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11269#endif
11270 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11271#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011272 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011273 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11274#endif
11275#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011276 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11277 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11278 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011279#endif
11280 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11281 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11282 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11283 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011284#ifdef FEAT_PERSISTENT_UNDO
11285 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11286#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011287 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11288#ifdef FEAT_KEYMAP
11289 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11290#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011291#ifdef FEAT_SIGNS
11292 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11293#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011294#ifdef FEAT_VARTABS
11295 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11296 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11297#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011298 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011299 }
11300 /* always return a valid pointer to avoid a crash! */
11301 return (char_u *)&(curbuf->b_p_wm);
11302}
11303
11304/*
11305 * Get the value of 'equalprg', either the buffer-local one or the global one.
11306 */
11307 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011308get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011309{
11310 if (*curbuf->b_p_ep == NUL)
11311 return p_ep;
11312 return curbuf->b_p_ep;
11313}
11314
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315/*
11316 * Copy options from one window to another.
11317 * Used when splitting a window.
11318 */
11319 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011320win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011321{
11322 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11323 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011324#if defined(FEAT_LINEBREAK)
11325 briopt_check(wp_to);
11326#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011327}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011328
11329/*
11330 * Copy the options from one winopt_T to another.
11331 * Doesn't free the old option values in "to", use clear_winopt() for that.
11332 * The 'scroll' option is not copied, because it depends on the window height.
11333 * The 'previewwindow' option is reset, there can be only one preview window.
11334 */
11335 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011336copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011337{
11338#ifdef FEAT_ARABIC
11339 to->wo_arab = from->wo_arab;
11340#endif
11341 to->wo_list = from->wo_list;
11342 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011343 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011344#ifdef FEAT_LINEBREAK
11345 to->wo_nuw = from->wo_nuw;
11346#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011347#ifdef FEAT_RIGHTLEFT
11348 to->wo_rl = from->wo_rl;
11349 to->wo_rlc = vim_strsave(from->wo_rlc);
11350#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011351#ifdef FEAT_STL_OPT
11352 to->wo_stl = vim_strsave(from->wo_stl);
11353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011354 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011355#ifdef FEAT_DIFF
11356 to->wo_wrap_save = from->wo_wrap_save;
11357#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011358#ifdef FEAT_LINEBREAK
11359 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011360 to->wo_bri = from->wo_bri;
11361 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011362#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011363 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011364 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011365 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011366 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011367 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011368#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011369 to->wo_spell = from->wo_spell;
11370#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011371#ifdef FEAT_SYN_HL
11372 to->wo_cuc = from->wo_cuc;
11373 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011374 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376#ifdef FEAT_DIFF
11377 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011378 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011379#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011380#ifdef FEAT_CONCEAL
11381 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011382 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011383#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011384#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011385 to->wo_twk = vim_strsave(from->wo_twk);
11386 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011387#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388#ifdef FEAT_FOLDING
11389 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011390 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011392 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011393 to->wo_fdi = vim_strsave(from->wo_fdi);
11394 to->wo_fml = from->wo_fml;
11395 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011396 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011397 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011398 to->wo_fdm_save = from->wo_diff_saved
11399 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011400 to->wo_fdn = from->wo_fdn;
11401# ifdef FEAT_EVAL
11402 to->wo_fde = vim_strsave(from->wo_fde);
11403 to->wo_fdt = vim_strsave(from->wo_fdt);
11404# endif
11405 to->wo_fmr = vim_strsave(from->wo_fmr);
11406#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011407#ifdef FEAT_SIGNS
11408 to->wo_scl = vim_strsave(from->wo_scl);
11409#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410 check_winopt(to); /* don't want NULL pointers */
11411}
11412
11413/*
11414 * Check string options in a window for a NULL value.
11415 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020011416 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011417check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011418{
11419 check_winopt(&win->w_onebuf_opt);
11420 check_winopt(&win->w_allbuf_opt);
11421}
11422
11423/*
11424 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11425 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011426 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011427check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428{
11429#ifdef FEAT_FOLDING
11430 check_string_option(&wop->wo_fdi);
11431 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011432 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011433# ifdef FEAT_EVAL
11434 check_string_option(&wop->wo_fde);
11435 check_string_option(&wop->wo_fdt);
11436# endif
11437 check_string_option(&wop->wo_fmr);
11438#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011439#ifdef FEAT_SIGNS
11440 check_string_option(&wop->wo_scl);
11441#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011442#ifdef FEAT_RIGHTLEFT
11443 check_string_option(&wop->wo_rlc);
11444#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011445#ifdef FEAT_STL_OPT
11446 check_string_option(&wop->wo_stl);
11447#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011448#ifdef FEAT_SYN_HL
11449 check_string_option(&wop->wo_cc);
11450#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011451#ifdef FEAT_CONCEAL
11452 check_string_option(&wop->wo_cocu);
11453#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011454#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011455 check_string_option(&wop->wo_twk);
11456 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011457#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011458#ifdef FEAT_LINEBREAK
11459 check_string_option(&wop->wo_briopt);
11460#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011461 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011462}
11463
11464/*
11465 * Free the allocated memory inside a winopt_T.
11466 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011467 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011468clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011469{
11470#ifdef FEAT_FOLDING
11471 clear_string_option(&wop->wo_fdi);
11472 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011473 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011474# ifdef FEAT_EVAL
11475 clear_string_option(&wop->wo_fde);
11476 clear_string_option(&wop->wo_fdt);
11477# endif
11478 clear_string_option(&wop->wo_fmr);
11479#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011480#ifdef FEAT_SIGNS
11481 clear_string_option(&wop->wo_scl);
11482#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011483#ifdef FEAT_LINEBREAK
11484 clear_string_option(&wop->wo_briopt);
11485#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011486 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011487#ifdef FEAT_RIGHTLEFT
11488 clear_string_option(&wop->wo_rlc);
11489#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011490#ifdef FEAT_STL_OPT
11491 clear_string_option(&wop->wo_stl);
11492#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011493#ifdef FEAT_SYN_HL
11494 clear_string_option(&wop->wo_cc);
11495#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011496#ifdef FEAT_CONCEAL
11497 clear_string_option(&wop->wo_cocu);
11498#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011499#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011500 clear_string_option(&wop->wo_twk);
11501 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011502#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011503}
11504
11505/*
11506 * Copy global option values to local options for one buffer.
11507 * Used when creating a new buffer and sometimes when entering a buffer.
11508 * flags:
11509 * BCO_ENTER We will enter the buf buffer.
11510 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11511 * appropriate.
11512 * BCO_NOHELP Don't copy the values to a help buffer.
11513 */
11514 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011515buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011516{
11517 int should_copy = TRUE;
11518 char_u *save_p_isk = NULL; /* init for GCC */
11519 int dont_do_help;
11520 int did_isk = FALSE;
11521
11522 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011523 * Skip this when the option defaults have not been set yet. Happens when
11524 * main() allocates the first buffer.
11525 */
11526 if (p_cpo != NULL)
11527 {
11528 /*
11529 * Always copy when entering and 'cpo' contains 'S'.
11530 * Don't copy when already initialized.
11531 * Don't copy when 'cpo' contains 's' and not entering.
11532 * 'S' BCO_ENTER initialized 's' should_copy
11533 * yes yes X X TRUE
11534 * yes no yes X FALSE
11535 * no X yes X FALSE
11536 * X no no yes FALSE
11537 * X no no no TRUE
11538 * no yes no X TRUE
11539 */
11540 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11541 && (buf->b_p_initialized
11542 || (!(flags & BCO_ENTER)
11543 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11544 should_copy = FALSE;
11545
11546 if (should_copy || (flags & BCO_ALWAYS))
11547 {
11548 /* Don't copy the options specific to a help buffer when
11549 * BCO_NOHELP is given or the options were initialized already
11550 * (jumping back to a help file with CTRL-T or CTRL-O) */
11551 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11552 || buf->b_p_initialized;
11553 if (dont_do_help) /* don't free b_p_isk */
11554 {
11555 save_p_isk = buf->b_p_isk;
11556 buf->b_p_isk = NULL;
11557 }
11558 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011559 * Always free the allocated strings. If not already initialized,
11560 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011561 */
11562 if (!buf->b_p_initialized)
11563 {
11564 free_buf_options(buf, TRUE);
11565 buf->b_p_ro = FALSE; /* don't copy readonly */
11566 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011567 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011568 switch (*p_ffs)
11569 {
11570 case 'm':
11571 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11572 case 'd':
11573 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11574 case 'u':
11575 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11576 default:
11577 buf->b_p_ff = vim_strsave(p_ff);
11578 }
11579 if (buf->b_p_ff != NULL)
11580 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011581 buf->b_p_bh = empty_option;
11582 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011583 }
11584 else
11585 free_buf_options(buf, FALSE);
11586
11587 buf->b_p_ai = p_ai;
11588 buf->b_p_ai_nopaste = p_ai_nopaste;
11589 buf->b_p_sw = p_sw;
11590 buf->b_p_tw = p_tw;
11591 buf->b_p_tw_nopaste = p_tw_nopaste;
11592 buf->b_p_tw_nobin = p_tw_nobin;
11593 buf->b_p_wm = p_wm;
11594 buf->b_p_wm_nopaste = p_wm_nopaste;
11595 buf->b_p_wm_nobin = p_wm_nobin;
11596 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011597 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011598 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011599 buf->b_p_et = p_et;
11600 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011601 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011602 buf->b_p_ml = p_ml;
11603 buf->b_p_ml_nobin = p_ml_nobin;
11604 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011605 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011606 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaare2c453d2019-08-21 14:37:09 +020011607#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011608 buf->b_p_csl = vim_strsave(p_csl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011609#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011610#ifdef FEAT_COMPL_FUNC
11611 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011612 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011613#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011614#ifdef FEAT_EVAL
11615 buf->b_p_tfu = vim_strsave(p_tfu);
11616#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011617 buf->b_p_sts = p_sts;
11618 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011619#ifdef FEAT_VARTABS
11620 buf->b_p_vsts = vim_strsave(p_vsts);
11621 if (p_vsts && p_vsts != empty_option)
11622 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11623 else
11624 buf->b_p_vsts_array = 0;
11625 buf->b_p_vsts_nopaste = p_vsts_nopaste
11626 ? vim_strsave(p_vsts_nopaste) : NULL;
11627#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011628 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011629#ifdef FEAT_COMMENTS
11630 buf->b_p_com = vim_strsave(p_com);
11631#endif
11632#ifdef FEAT_FOLDING
11633 buf->b_p_cms = vim_strsave(p_cms);
11634#endif
11635 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011636 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011637 buf->b_p_nf = vim_strsave(p_nf);
11638 buf->b_p_mps = vim_strsave(p_mps);
11639#ifdef FEAT_SMARTINDENT
11640 buf->b_p_si = p_si;
11641#endif
11642 buf->b_p_ci = p_ci;
11643#ifdef FEAT_CINDENT
11644 buf->b_p_cin = p_cin;
11645 buf->b_p_cink = vim_strsave(p_cink);
11646 buf->b_p_cino = vim_strsave(p_cino);
11647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011648 /* Don't copy 'filetype', it must be detected */
11649 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011650 buf->b_p_pi = p_pi;
11651#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11652 buf->b_p_cinw = vim_strsave(p_cinw);
11653#endif
11654#ifdef FEAT_LISP
11655 buf->b_p_lisp = p_lisp;
11656#endif
11657#ifdef FEAT_SYN_HL
11658 /* Don't copy 'syntax', it must be set */
11659 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011660 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011661 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011662#endif
11663#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011664 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011665 (void)compile_cap_prog(&buf->b_s);
11666 buf->b_s.b_p_spf = vim_strsave(p_spf);
11667 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011668#endif
11669#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11670 buf->b_p_inde = vim_strsave(p_inde);
11671 buf->b_p_indk = vim_strsave(p_indk);
11672#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011673 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011674#if defined(FEAT_EVAL)
11675 buf->b_p_fex = vim_strsave(p_fex);
11676#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011677#ifdef FEAT_CRYPT
11678 buf->b_p_key = vim_strsave(p_key);
11679#endif
11680#ifdef FEAT_SEARCHPATH
11681 buf->b_p_sua = vim_strsave(p_sua);
11682#endif
11683#ifdef FEAT_KEYMAP
11684 buf->b_p_keymap = vim_strsave(p_keymap);
11685 buf->b_kmap_state |= KEYMAP_INIT;
11686#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011687#ifdef FEAT_TERMINAL
11688 buf->b_p_twsl = p_twsl;
11689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011690 /* This isn't really an option, but copying the langmap and IME
11691 * state from the current buffer is better than resetting it. */
11692 buf->b_p_iminsert = p_iminsert;
11693 buf->b_p_imsearch = p_imsearch;
11694
11695 /* options that are normally global but also have a local value
11696 * are not copied, start using the global value */
11697 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011698 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011699 buf->b_p_bkc = empty_option;
11700 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011701#ifdef FEAT_QUICKFIX
11702 buf->b_p_gp = empty_option;
11703 buf->b_p_mp = empty_option;
11704 buf->b_p_efm = empty_option;
11705#endif
11706 buf->b_p_ep = empty_option;
11707 buf->b_p_kp = empty_option;
11708 buf->b_p_path = empty_option;
11709 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011710 buf->b_p_tc = empty_option;
11711 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011712#ifdef FEAT_FIND_ID
11713 buf->b_p_def = empty_option;
11714 buf->b_p_inc = empty_option;
11715# ifdef FEAT_EVAL
11716 buf->b_p_inex = vim_strsave(p_inex);
11717# endif
11718#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011719 buf->b_p_dict = empty_option;
11720 buf->b_p_tsr = empty_option;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011721#ifdef FEAT_TEXTOBJ
11722 buf->b_p_qe = vim_strsave(p_qe);
11723#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011724#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11725 buf->b_p_bexpr = empty_option;
11726#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011727#if defined(FEAT_CRYPT)
11728 buf->b_p_cm = empty_option;
11729#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011730#ifdef FEAT_PERSISTENT_UNDO
11731 buf->b_p_udf = p_udf;
11732#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011733#ifdef FEAT_LISP
11734 buf->b_p_lw = empty_option;
11735#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011736 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011737
11738 /*
11739 * Don't copy the options set by ex_help(), use the saved values,
11740 * when going from a help buffer to a non-help buffer.
11741 * Don't touch these at all when BCO_NOHELP is used and going from
11742 * or to a help buffer.
11743 */
11744 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011745 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011746 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011747#ifdef FEAT_VARTABS
11748 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11749 tabstop_set(p_vts, &buf->b_p_vts_array);
11750 else
11751 buf->b_p_vts_array = NULL;
11752#endif
11753 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011754 else
11755 {
11756 buf->b_p_isk = vim_strsave(p_isk);
11757 did_isk = TRUE;
11758 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011759#ifdef FEAT_VARTABS
11760 buf->b_p_vts = vim_strsave(p_vts);
11761 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11762 tabstop_set(p_vts, &buf->b_p_vts_array);
11763 else
11764 buf->b_p_vts_array = NULL;
11765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011766 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767 if (buf->b_p_bt[0] == 'h')
11768 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011769 buf->b_p_ma = p_ma;
11770 }
11771 }
11772
11773 /*
11774 * When the options should be copied (ignoring BCO_ALWAYS), set the
11775 * flag that indicates that the options have been initialized.
11776 */
11777 if (should_copy)
11778 buf->b_p_initialized = TRUE;
11779 }
11780
11781 check_buf_options(buf); /* make sure we don't have NULLs */
11782 if (did_isk)
11783 (void)buf_init_chartab(buf, FALSE);
11784}
11785
11786/*
11787 * Reset the 'modifiable' option and its default value.
11788 */
11789 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011790reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011791{
11792 int opt_idx;
11793
11794 curbuf->b_p_ma = FALSE;
11795 p_ma = FALSE;
11796 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011797 if (opt_idx >= 0)
11798 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799}
11800
11801/*
11802 * Set the global value for 'iminsert' to the local value.
11803 */
11804 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011805set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011806{
11807 p_iminsert = curbuf->b_p_iminsert;
11808}
11809
11810/*
11811 * Set the global value for 'imsearch' to the local value.
11812 */
11813 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011814set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011815{
11816 p_imsearch = curbuf->b_p_imsearch;
11817}
11818
Bram Moolenaar071d4272004-06-13 20:20:40 +000011819static int expand_option_idx = -1;
11820static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11821static int expand_option_flags = 0;
11822
11823 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011824set_context_in_set_cmd(
11825 expand_T *xp,
11826 char_u *arg,
11827 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011828{
11829 int nextchar;
11830 long_u flags = 0; /* init for GCC */
11831 int opt_idx = 0; /* init for GCC */
11832 char_u *p;
11833 char_u *s;
11834 int is_term_option = FALSE;
11835 int key;
11836
11837 expand_option_flags = opt_flags;
11838
11839 xp->xp_context = EXPAND_SETTINGS;
11840 if (*arg == NUL)
11841 {
11842 xp->xp_pattern = arg;
11843 return;
11844 }
11845 p = arg + STRLEN(arg) - 1;
11846 if (*p == ' ' && *(p - 1) != '\\')
11847 {
11848 xp->xp_pattern = p + 1;
11849 return;
11850 }
11851 while (p > arg)
11852 {
11853 s = p;
11854 /* count number of backslashes before ' ' or ',' */
11855 if (*p == ' ' || *p == ',')
11856 {
11857 while (s > arg && *(s - 1) == '\\')
11858 --s;
11859 }
11860 /* break at a space with an even number of backslashes */
11861 if (*p == ' ' && ((p - s) & 1) == 0)
11862 {
11863 ++p;
11864 break;
11865 }
11866 --p;
11867 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011868 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011869 {
11870 xp->xp_context = EXPAND_BOOL_SETTINGS;
11871 p += 2;
11872 }
11873 if (STRNCMP(p, "inv", 3) == 0)
11874 {
11875 xp->xp_context = EXPAND_BOOL_SETTINGS;
11876 p += 3;
11877 }
11878 xp->xp_pattern = arg = p;
11879 if (*arg == '<')
11880 {
11881 while (*p != '>')
11882 if (*p++ == NUL) /* expand terminal option name */
11883 return;
11884 key = get_special_key_code(arg + 1);
11885 if (key == 0) /* unknown name */
11886 {
11887 xp->xp_context = EXPAND_NOTHING;
11888 return;
11889 }
11890 nextchar = *++p;
11891 is_term_option = TRUE;
11892 expand_option_name[2] = KEY2TERMCAP0(key);
11893 expand_option_name[3] = KEY2TERMCAP1(key);
11894 }
11895 else
11896 {
11897 if (p[0] == 't' && p[1] == '_')
11898 {
11899 p += 2;
11900 if (*p != NUL)
11901 ++p;
11902 if (*p == NUL)
11903 return; /* expand option name */
11904 nextchar = *++p;
11905 is_term_option = TRUE;
11906 expand_option_name[2] = p[-2];
11907 expand_option_name[3] = p[-1];
11908 }
11909 else
11910 {
11911 /* Allow * wildcard */
11912 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11913 p++;
11914 if (*p == NUL)
11915 return;
11916 nextchar = *p;
11917 *p = NUL;
11918 opt_idx = findoption(arg);
11919 *p = nextchar;
11920 if (opt_idx == -1 || options[opt_idx].var == NULL)
11921 {
11922 xp->xp_context = EXPAND_NOTHING;
11923 return;
11924 }
11925 flags = options[opt_idx].flags;
11926 if (flags & P_BOOL)
11927 {
11928 xp->xp_context = EXPAND_NOTHING;
11929 return;
11930 }
11931 }
11932 }
11933 /* handle "-=" and "+=" */
11934 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11935 {
11936 ++p;
11937 nextchar = '=';
11938 }
11939 if ((nextchar != '=' && nextchar != ':')
11940 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11941 {
11942 xp->xp_context = EXPAND_UNSUCCESSFUL;
11943 return;
11944 }
11945 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11946 {
11947 xp->xp_context = EXPAND_OLD_SETTING;
11948 if (is_term_option)
11949 expand_option_idx = -1;
11950 else
11951 expand_option_idx = opt_idx;
11952 xp->xp_pattern = p + 1;
11953 return;
11954 }
11955 xp->xp_context = EXPAND_NOTHING;
11956 if (is_term_option || (flags & P_NUM))
11957 return;
11958
11959 xp->xp_pattern = p + 1;
11960
11961 if (flags & P_EXPAND)
11962 {
11963 p = options[opt_idx].var;
11964 if (p == (char_u *)&p_bdir
11965 || p == (char_u *)&p_dir
11966 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011967 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011968 || p == (char_u *)&p_rtp
11969#ifdef FEAT_SEARCHPATH
11970 || p == (char_u *)&p_cdpath
11971#endif
11972#ifdef FEAT_SESSION
11973 || p == (char_u *)&p_vdir
11974#endif
11975 )
11976 {
11977 xp->xp_context = EXPAND_DIRECTORIES;
11978 if (p == (char_u *)&p_path
11979#ifdef FEAT_SEARCHPATH
11980 || p == (char_u *)&p_cdpath
11981#endif
11982 )
11983 xp->xp_backslash = XP_BS_THREE;
11984 else
11985 xp->xp_backslash = XP_BS_ONE;
11986 }
11987 else
11988 {
11989 xp->xp_context = EXPAND_FILES;
11990 /* for 'tags' need three backslashes for a space */
11991 if (p == (char_u *)&p_tags)
11992 xp->xp_backslash = XP_BS_THREE;
11993 else
11994 xp->xp_backslash = XP_BS_ONE;
11995 }
11996 }
11997
11998 /* For an option that is a list of file names, find the start of the
11999 * last file name. */
12000 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
12001 {
12002 /* count number of backslashes before ' ' or ',' */
12003 if (*p == ' ' || *p == ',')
12004 {
12005 s = p;
12006 while (s > xp->xp_pattern && *(s - 1) == '\\')
12007 --s;
12008 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
12009 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
12010 {
12011 xp->xp_pattern = p + 1;
12012 break;
12013 }
12014 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012015
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000012016#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012017 /* for 'spellsuggest' start at "file:" */
12018 if (options[opt_idx].var == (char_u *)&p_sps
12019 && STRNCMP(p, "file:", 5) == 0)
12020 {
12021 xp->xp_pattern = p + 5;
12022 break;
12023 }
12024#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012025 }
12026
12027 return;
12028}
12029
12030 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012031ExpandSettings(
12032 expand_T *xp,
12033 regmatch_T *regmatch,
12034 int *num_file,
12035 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012036{
12037 int num_normal = 0; /* Nr of matching non-term-code settings */
12038 int num_term = 0; /* Nr of matching terminal code settings */
12039 int opt_idx;
12040 int match;
12041 int count = 0;
12042 char_u *str;
12043 int loop;
12044 int is_term_opt;
12045 char_u name_buf[MAX_KEY_NAME_LEN];
12046 static char *(names[]) = {"all", "termcap"};
12047 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
12048
12049 /* do this loop twice:
12050 * loop == 0: count the number of matching options
12051 * loop == 1: copy the matching options into allocated memory
12052 */
12053 for (loop = 0; loop <= 1; ++loop)
12054 {
12055 regmatch->rm_ic = ic;
12056 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
12057 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000012058 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
12059 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012060 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
12061 {
12062 if (loop == 0)
12063 num_normal++;
12064 else
12065 (*file)[count++] = vim_strsave((char_u *)names[match]);
12066 }
12067 }
12068 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
12069 opt_idx++)
12070 {
12071 if (options[opt_idx].var == NULL)
12072 continue;
12073 if (xp->xp_context == EXPAND_BOOL_SETTINGS
12074 && !(options[opt_idx].flags & P_BOOL))
12075 continue;
12076 is_term_opt = istermoption(&options[opt_idx]);
12077 if (is_term_opt && num_normal > 0)
12078 continue;
12079 match = FALSE;
12080 if (vim_regexec(regmatch, str, (colnr_T)0)
12081 || (options[opt_idx].shortname != NULL
12082 && vim_regexec(regmatch,
12083 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
12084 match = TRUE;
12085 else if (is_term_opt)
12086 {
12087 name_buf[0] = '<';
12088 name_buf[1] = 't';
12089 name_buf[2] = '_';
12090 name_buf[3] = str[2];
12091 name_buf[4] = str[3];
12092 name_buf[5] = '>';
12093 name_buf[6] = NUL;
12094 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12095 {
12096 match = TRUE;
12097 str = name_buf;
12098 }
12099 }
12100 if (match)
12101 {
12102 if (loop == 0)
12103 {
12104 if (is_term_opt)
12105 num_term++;
12106 else
12107 num_normal++;
12108 }
12109 else
12110 (*file)[count++] = vim_strsave(str);
12111 }
12112 }
12113 /*
12114 * Check terminal key codes, these are not in the option table
12115 */
12116 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
12117 {
12118 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
12119 {
12120 if (!isprint(str[0]) || !isprint(str[1]))
12121 continue;
12122
12123 name_buf[0] = 't';
12124 name_buf[1] = '_';
12125 name_buf[2] = str[0];
12126 name_buf[3] = str[1];
12127 name_buf[4] = NUL;
12128
12129 match = FALSE;
12130 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12131 match = TRUE;
12132 else
12133 {
12134 name_buf[0] = '<';
12135 name_buf[1] = 't';
12136 name_buf[2] = '_';
12137 name_buf[3] = str[0];
12138 name_buf[4] = str[1];
12139 name_buf[5] = '>';
12140 name_buf[6] = NUL;
12141
12142 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12143 match = TRUE;
12144 }
12145 if (match)
12146 {
12147 if (loop == 0)
12148 num_term++;
12149 else
12150 (*file)[count++] = vim_strsave(name_buf);
12151 }
12152 }
12153
12154 /*
12155 * Check special key names.
12156 */
12157 regmatch->rm_ic = TRUE; /* ignore case here */
12158 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12159 {
12160 name_buf[0] = '<';
12161 STRCPY(name_buf + 1, str);
12162 STRCAT(name_buf, ">");
12163
12164 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12165 {
12166 if (loop == 0)
12167 num_term++;
12168 else
12169 (*file)[count++] = vim_strsave(name_buf);
12170 }
12171 }
12172 }
12173 if (loop == 0)
12174 {
12175 if (num_normal > 0)
12176 *num_file = num_normal;
12177 else if (num_term > 0)
12178 *num_file = num_term;
12179 else
12180 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012181 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012182 if (*file == NULL)
12183 {
12184 *file = (char_u **)"";
12185 return FAIL;
12186 }
12187 }
12188 }
12189 return OK;
12190}
12191
12192 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012193ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012194{
12195 char_u *var = NULL; /* init for GCC */
12196 char_u *buf;
12197
12198 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012199 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012200 if (*file == NULL)
12201 return FAIL;
12202
12203 /*
12204 * For a terminal key code expand_option_idx is < 0.
12205 */
12206 if (expand_option_idx < 0)
12207 {
12208 var = find_termcode(expand_option_name + 2);
12209 if (var == NULL)
12210 expand_option_idx = findoption(expand_option_name);
12211 }
12212
12213 if (expand_option_idx >= 0)
12214 {
12215 /* put string of option value in NameBuff */
12216 option_value2string(&options[expand_option_idx], expand_option_flags);
12217 var = NameBuff;
12218 }
12219 else if (var == NULL)
12220 var = (char_u *)"";
12221
12222 /* A backslash is required before some characters. This is the reverse of
12223 * what happens in do_set(). */
12224 buf = vim_strsave_escaped(var, escape_chars);
12225
12226 if (buf == NULL)
12227 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012228 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012229 return FAIL;
12230 }
12231
12232#ifdef BACKSLASH_IN_FILENAME
12233 /* For MS-Windows et al. we don't double backslashes at the start and
12234 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012235 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012236 if (var[0] == '\\' && var[1] == '\\'
12237 && expand_option_idx >= 0
12238 && (options[expand_option_idx].flags & P_EXPAND)
12239 && vim_isfilec(var[2])
12240 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012241 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012242#endif
12243
12244 *file[0] = buf;
12245 *num_file = 1;
12246 return OK;
12247}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012248
12249/*
12250 * Get the value for the numeric or string option *opp in a nice format into
12251 * NameBuff[]. Must not be called with a hidden option!
12252 */
12253 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012254option_value2string(
12255 struct vimoption *opp,
12256 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012257{
12258 char_u *varp;
12259
12260 varp = get_varp_scope(opp, opt_flags);
12261
12262 if (opp->flags & P_NUM)
12263 {
12264 long wc = 0;
12265
12266 if (wc_use_keyname(varp, &wc))
12267 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12268 else if (wc != 0)
12269 STRCPY(NameBuff, transchar((int)wc));
12270 else
12271 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12272 }
12273 else /* P_STRING */
12274 {
12275 varp = *(char_u **)(varp);
12276 if (varp == NULL) /* just in case */
12277 NameBuff[0] = NUL;
12278#ifdef FEAT_CRYPT
12279 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012280 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012281 STRCPY(NameBuff, "*****");
12282#endif
12283 else if (opp->flags & P_EXPAND)
12284 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12285 /* Translate 'pastetoggle' into special key names */
12286 else if ((char_u **)opp->var == &p_pt)
12287 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12288 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012289 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012290 }
12291}
12292
12293/*
12294 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12295 * printed as a keyname.
12296 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12297 */
12298 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012299wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012300{
12301 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12302 {
12303 *wcp = *(long *)varp;
12304 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12305 return TRUE;
12306 }
12307 return FALSE;
12308}
12309
Bram Moolenaar01615492015-02-03 13:00:38 +010012310#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012311/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012312 * Any character has an equivalent 'langmap' character. This is used for
12313 * keyboards that have a special language mode that sends characters above
12314 * 128 (although other characters can be translated too). The "to" field is a
12315 * Vim command character. This avoids having to switch the keyboard back to
12316 * ASCII mode when leaving Insert mode.
12317 *
12318 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12319 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012320 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12321 * same as langmap_mapchar[] for characters >= 256.
12322 *
12323 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012324 */
12325typedef struct
12326{
12327 int from;
12328 int to;
12329} langmap_entry_T;
12330
12331static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012332
12333/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012334 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12335 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012336 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012337 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012338langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012339{
12340 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012341 int a = 0;
12342 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012343
12344 /* Do a binary search for an existing entry. */
12345 while (a != b)
12346 {
12347 int i = (a + b) / 2;
12348 int d = entries[i].from - from;
12349
12350 if (d == 0)
12351 {
12352 entries[i].to = to;
12353 return;
12354 }
12355 if (d < 0)
12356 a = i + 1;
12357 else
12358 b = i;
12359 }
12360
12361 if (ga_grow(&langmap_mapga, 1) != OK)
12362 return; /* out of memory */
12363
12364 /* insert new entry at position "a" */
12365 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12366 mch_memmove(entries + 1, entries,
12367 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12368 ++langmap_mapga.ga_len;
12369 entries[0].from = from;
12370 entries[0].to = to;
12371}
12372
12373/*
12374 * Apply 'langmap' to multi-byte character "c" and return the result.
12375 */
12376 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012377langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012378{
12379 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12380 int a = 0;
12381 int b = langmap_mapga.ga_len;
12382
12383 while (a != b)
12384 {
12385 int i = (a + b) / 2;
12386 int d = entries[i].from - c;
12387
12388 if (d == 0)
12389 return entries[i].to; /* found matching entry */
12390 if (d < 0)
12391 a = i + 1;
12392 else
12393 b = i;
12394 }
12395 return c; /* no entry found, return "c" unmodified */
12396}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012397
12398 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012399langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012400{
12401 int i;
12402
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012403 for (i = 0; i < 256; i++)
12404 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012405 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012406}
12407
12408/*
12409 * Called when langmap option is set; the language map can be
12410 * changed at any time!
12411 */
12412 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012413langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012414{
12415 char_u *p;
12416 char_u *p2;
12417 int from, to;
12418
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012419 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012420 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012421
12422 for (p = p_langmap; p[0] != NUL; )
12423 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012424 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012425 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012426 {
12427 if (p2[0] == '\\' && p2[1] != NUL)
12428 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012429 }
12430 if (p2[0] == ';')
12431 ++p2; /* abcd;ABCD form, p2 points to A */
12432 else
12433 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12434 while (p[0])
12435 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012436 if (p[0] == ',')
12437 {
12438 ++p;
12439 break;
12440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012441 if (p[0] == '\\' && p[1] != NUL)
12442 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012443 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012444 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012445 if (p2 == NULL)
12446 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012447 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012448 if (p[0] != ',')
12449 {
12450 if (p[0] == '\\')
12451 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012452 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012453 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012454 }
12455 else
12456 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012457 if (p2[0] != ',')
12458 {
12459 if (p2[0] == '\\')
12460 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012461 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012462 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012463 }
12464 if (to == NUL)
12465 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012466 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012467 transchar(from));
12468 return;
12469 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012470
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012471 if (from >= 256)
12472 langmap_set_entry(from, to);
12473 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012474 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012475
12476 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012477 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012478 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012479 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012480 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012481 if (*p == ';')
12482 {
12483 p = p2;
12484 if (p[0] != NUL)
12485 {
12486 if (p[0] != ',')
12487 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012488 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012489 return;
12490 }
12491 ++p;
12492 }
12493 break;
12494 }
12495 }
12496 }
12497 }
12498}
12499#endif
12500
12501/*
12502 * Return TRUE if format option 'x' is in effect.
12503 * Take care of no formatting when 'paste' is set.
12504 */
12505 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012506has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507{
12508 if (p_paste)
12509 return FALSE;
12510 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12511}
12512
12513/*
12514 * Return TRUE if "x" is present in 'shortmess' option, or
12515 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12516 */
12517 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012518shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012519{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012520 return p_shm != NULL &&
12521 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012522 || (vim_strchr(p_shm, 'a') != NULL
12523 && vim_strchr((char_u *)SHM_A, x) != NULL));
12524}
12525
12526/*
12527 * paste_option_changed() - Called after p_paste was set or reset.
12528 */
12529 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012530paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012531{
12532 static int old_p_paste = FALSE;
12533 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012534 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012535#ifdef FEAT_CMDL_INFO
12536 static int save_ru = 0;
12537#endif
12538#ifdef FEAT_RIGHTLEFT
12539 static int save_ri = 0;
12540 static int save_hkmap = 0;
12541#endif
12542 buf_T *buf;
12543
12544 if (p_paste)
12545 {
12546 /*
12547 * Paste switched from off to on.
12548 * Save the current values, so they can be restored later.
12549 */
12550 if (!old_p_paste)
12551 {
12552 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012553 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012554 {
12555 buf->b_p_tw_nopaste = buf->b_p_tw;
12556 buf->b_p_wm_nopaste = buf->b_p_wm;
12557 buf->b_p_sts_nopaste = buf->b_p_sts;
12558 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012559 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012560#ifdef FEAT_VARTABS
12561 if (buf->b_p_vsts_nopaste)
12562 vim_free(buf->b_p_vsts_nopaste);
12563 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12564 ? vim_strsave(buf->b_p_vsts) : NULL;
12565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012566 }
12567
12568 /* save global options */
12569 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012570 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012571#ifdef FEAT_CMDL_INFO
12572 save_ru = p_ru;
12573#endif
12574#ifdef FEAT_RIGHTLEFT
12575 save_ri = p_ri;
12576 save_hkmap = p_hkmap;
12577#endif
12578 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012579 p_ai_nopaste = p_ai;
12580 p_et_nopaste = p_et;
12581 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012582 p_tw_nopaste = p_tw;
12583 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012584#ifdef FEAT_VARTABS
12585 if (p_vsts_nopaste)
12586 vim_free(p_vsts_nopaste);
12587 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12588#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012589 }
12590
12591 /*
12592 * Always set the option values, also when 'paste' is set when it is
12593 * already on.
12594 */
12595 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012596 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012597 {
12598 buf->b_p_tw = 0; /* textwidth is 0 */
12599 buf->b_p_wm = 0; /* wrapmargin is 0 */
12600 buf->b_p_sts = 0; /* softtabstop is 0 */
12601 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012602 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012603#ifdef FEAT_VARTABS
12604 if (buf->b_p_vsts)
12605 free_string_option(buf->b_p_vsts);
12606 buf->b_p_vsts = empty_option;
12607 if (buf->b_p_vsts_array)
12608 vim_free(buf->b_p_vsts_array);
12609 buf->b_p_vsts_array = 0;
12610#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012611 }
12612
12613 /* set global options */
12614 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012615 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012616#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012617 if (p_ru)
12618 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012619 p_ru = 0; /* no ruler */
12620#endif
12621#ifdef FEAT_RIGHTLEFT
12622 p_ri = 0; /* no reverse insert */
12623 p_hkmap = 0; /* no Hebrew keyboard */
12624#endif
12625 /* set global values for local buffer options */
12626 p_tw = 0;
12627 p_wm = 0;
12628 p_sts = 0;
12629 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012630#ifdef FEAT_VARTABS
12631 if (p_vsts)
12632 free_string_option(p_vsts);
12633 p_vsts = empty_option;
12634#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012635 }
12636
12637 /*
12638 * Paste switched from on to off: Restore saved values.
12639 */
12640 else if (old_p_paste)
12641 {
12642 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012643 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012644 {
12645 buf->b_p_tw = buf->b_p_tw_nopaste;
12646 buf->b_p_wm = buf->b_p_wm_nopaste;
12647 buf->b_p_sts = buf->b_p_sts_nopaste;
12648 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012649 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012650#ifdef FEAT_VARTABS
12651 if (buf->b_p_vsts)
12652 free_string_option(buf->b_p_vsts);
12653 buf->b_p_vsts = buf->b_p_vsts_nopaste
12654 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12655 if (buf->b_p_vsts_array)
12656 vim_free(buf->b_p_vsts_array);
12657 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12658 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12659 else
12660 buf->b_p_vsts_array = 0;
12661#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012662 }
12663
12664 /* restore global options */
12665 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012666 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012667#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012668 if (p_ru != save_ru)
12669 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012670 p_ru = save_ru;
12671#endif
12672#ifdef FEAT_RIGHTLEFT
12673 p_ri = save_ri;
12674 p_hkmap = save_hkmap;
12675#endif
12676 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012677 p_ai = p_ai_nopaste;
12678 p_et = p_et_nopaste;
12679 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012680 p_tw = p_tw_nopaste;
12681 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012682#ifdef FEAT_VARTABS
12683 if (p_vsts)
12684 free_string_option(p_vsts);
12685 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12686#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012687 }
12688
12689 old_p_paste = p_paste;
12690}
12691
12692/*
12693 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12694 *
12695 * Reset 'compatible' and set the values for options that didn't get set yet
12696 * to the Vim defaults.
12697 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012698 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012699 */
12700 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012701vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012702{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012703 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012704 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012705 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012706
12707 if (!option_was_set((char_u *)"cp"))
12708 {
12709 p_cp = FALSE;
12710 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12711 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12712 set_option_default(opt_idx, OPT_FREE, FALSE);
12713 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012714 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012715 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012716
12717 if (fname != NULL)
12718 {
12719 p = vim_getenv(envname, &dofree);
12720 if (p == NULL)
12721 {
12722 /* Set $MYVIMRC to the first vimrc file found. */
12723 p = FullName_save(fname, FALSE);
12724 if (p != NULL)
12725 {
12726 vim_setenv(envname, p);
12727 vim_free(p);
12728 }
12729 }
12730 else if (dofree)
12731 vim_free(p);
12732 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012733}
12734
12735/*
12736 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12737 */
12738 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012739change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012740{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012741 int opt_idx;
12742
Bram Moolenaar071d4272004-06-13 20:20:40 +000012743 if (p_cp != on)
12744 {
12745 p_cp = on;
12746 compatible_set();
12747 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012748 opt_idx = findoption((char_u *)"cp");
12749 if (opt_idx >= 0)
12750 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012751}
12752
12753/*
12754 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012755 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012756 */
12757 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012758option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012759{
12760 int idx;
12761
12762 idx = findoption(name);
12763 if (idx < 0) /* unknown option */
12764 return FALSE;
12765 if (options[idx].flags & P_WAS_SET)
12766 return TRUE;
12767 return FALSE;
12768}
12769
12770/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012771 * Reset the flag indicating option "name" was set.
12772 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012773 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012774reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012775{
12776 int idx = findoption(name);
12777
12778 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012779 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012780 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012781 return OK;
12782 }
12783 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012784}
12785
12786/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012787 * compatible_set() - Called when 'compatible' has been set or unset.
12788 *
12789 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12790 * flag) to a Vi compatible value.
12791 * When 'compatible' is unset: Set all options that have a different default
12792 * for Vim (without the P_VI_DEF flag) to that default.
12793 */
12794 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012795compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012796{
12797 int opt_idx;
12798
12799 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12800 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12801 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12802 set_option_default(opt_idx, OPT_FREE, p_cp);
12803 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012804 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012805}
12806
12807#ifdef FEAT_LINEBREAK
12808
Bram Moolenaar071d4272004-06-13 20:20:40 +000012809/*
12810 * fill_breakat_flags() -- called when 'breakat' changes value.
12811 */
12812 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012813fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012814{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012815 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012816 int i;
12817
12818 for (i = 0; i < 256; i++)
12819 breakat_flags[i] = FALSE;
12820
12821 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012822 for (p = p_breakat; *p; p++)
12823 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012824}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012825#endif
12826
12827/*
12828 * Check an option that can be a range of string values.
12829 *
12830 * Return OK for correct value, FAIL otherwise.
12831 * Empty is always OK.
12832 */
12833 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012834check_opt_strings(
12835 char_u *val,
12836 char **values,
12837 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012838{
12839 return opt_strings_flags(val, values, NULL, list);
12840}
12841
12842/*
12843 * Handle an option that can be a range of string values.
12844 * Set a flag in "*flagp" for each string present.
12845 *
12846 * Return OK for correct value, FAIL otherwise.
12847 * Empty is always OK.
12848 */
12849 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012850opt_strings_flags(
12851 char_u *val, /* new value */
12852 char **values, /* array of valid string values */
12853 unsigned *flagp,
12854 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012855{
12856 int i;
12857 int len;
12858 unsigned new_flags = 0;
12859
12860 while (*val)
12861 {
12862 for (i = 0; ; ++i)
12863 {
12864 if (values[i] == NULL) /* val not found in values[] */
12865 return FAIL;
12866
12867 len = (int)STRLEN(values[i]);
12868 if (STRNCMP(values[i], val, len) == 0
12869 && ((list && val[len] == ',') || val[len] == NUL))
12870 {
12871 val += len + (val[len] == ',');
12872 new_flags |= (1 << i);
12873 break; /* check next item in val list */
12874 }
12875 }
12876 }
12877 if (flagp != NULL)
12878 *flagp = new_flags;
12879
12880 return OK;
12881}
12882
12883/*
12884 * Read the 'wildmode' option, fill wim_flags[].
12885 */
12886 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012887check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012888{
12889 char_u new_wim_flags[4];
12890 char_u *p;
12891 int i;
12892 int idx = 0;
12893
12894 for (i = 0; i < 4; ++i)
12895 new_wim_flags[i] = 0;
12896
12897 for (p = p_wim; *p; ++p)
12898 {
12899 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12900 ;
12901 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12902 return FAIL;
12903 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12904 new_wim_flags[idx] |= WIM_LONGEST;
12905 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12906 new_wim_flags[idx] |= WIM_FULL;
12907 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12908 new_wim_flags[idx] |= WIM_LIST;
12909 else
12910 return FAIL;
12911 p += i;
12912 if (*p == NUL)
12913 break;
12914 if (*p == ',')
12915 {
12916 if (idx == 3)
12917 return FAIL;
12918 ++idx;
12919 }
12920 }
12921
12922 /* fill remaining entries with last flag */
12923 while (idx < 3)
12924 {
12925 new_wim_flags[idx + 1] = new_wim_flags[idx];
12926 ++idx;
12927 }
12928
12929 /* only when there are no errors, wim_flags[] is changed */
12930 for (i = 0; i < 4; ++i)
12931 wim_flags[i] = new_wim_flags[i];
12932 return OK;
12933}
12934
12935/*
12936 * Check if backspacing over something is allowed.
12937 */
12938 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012939can_bs(
12940 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012941{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012942#ifdef FEAT_JOB_CHANNEL
12943 if (what == BS_START && bt_prompt(curbuf))
12944 return FALSE;
12945#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012946 switch (*p_bs)
12947 {
12948 case '2': return TRUE;
12949 case '1': return (what != BS_START);
12950 case '0': return FALSE;
12951 }
12952 return vim_strchr(p_bs, what) != NULL;
12953}
12954
12955/*
12956 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12957 * the file must be considered changed when the value is different.
12958 */
12959 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012960save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012961{
12962 buf->b_start_ffc = *buf->b_p_ff;
12963 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012964 buf->b_start_bomb = buf->b_p_bomb;
12965
Bram Moolenaar071d4272004-06-13 20:20:40 +000012966 /* Only use free/alloc when necessary, they take time. */
12967 if (buf->b_start_fenc == NULL
12968 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12969 {
12970 vim_free(buf->b_start_fenc);
12971 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12972 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012973}
12974
12975/*
12976 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12977 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012978 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12979 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012980 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012981 * When "ignore_empty" is true don't consider a new, empty buffer to be
12982 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012983 */
12984 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012985file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012986{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012987 /* In a buffer that was never loaded the options are not valid. */
12988 if (buf->b_flags & BF_NEVERLOADED)
12989 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012990 if (ignore_empty
12991 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012992 && buf->b_ml.ml_line_count == 1
12993 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12994 return FALSE;
12995 if (buf->b_start_ffc != *buf->b_p_ff)
12996 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012997 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012998 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012999 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
13000 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000013001 if (buf->b_start_fenc == NULL)
13002 return (*buf->b_p_fenc != NUL);
13003 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000013004}
13005
13006/*
13007 * return OK if "p" is a valid fileformat name, FAIL otherwise.
13008 */
13009 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013010check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013011{
13012 return check_opt_strings(p, p_ff_values, FALSE);
13013}
Bram Moolenaar14f24742012-08-08 18:01:05 +020013014
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013015#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013016
13017/*
13018 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013019 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013020 */
13021 int
13022tabstop_set(char_u *var, int **array)
13023{
13024 int valcount = 1;
13025 int t;
13026 char_u *cp;
13027
Bram Moolenaar64f41072018-10-15 22:51:50 +020013028 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013029 {
13030 *array = NULL;
13031 return TRUE;
13032 }
13033
Bram Moolenaar64f41072018-10-15 22:51:50 +020013034 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013035 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020013036 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013037 {
13038 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013039
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013040 if (strtol((char *)cp, (char **)&end, 10) <= 0)
13041 {
13042 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013043 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013044 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013045 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013046 return FALSE;
13047 }
13048 }
13049
13050 if (VIM_ISDIGIT(*cp))
13051 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013052 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013053 {
13054 ++valcount;
13055 continue;
13056 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013057 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013058 return FALSE;
13059 }
13060
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013061 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013062 if (*array == NULL)
13063 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013064 (*array)[0] = valcount;
13065
13066 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013067 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013068 {
13069 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020013070 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013071 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013072 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013073 ++cp;
13074 }
13075
13076 return TRUE;
13077}
13078
13079/*
13080 * Calculate the number of screen spaces a tab will occupy.
13081 * If "vts" is set then the tab widths are taken from that array,
13082 * otherwise the value of ts is used.
13083 */
13084 int
13085tabstop_padding(colnr_T col, int ts_arg, int *vts)
13086{
13087 int ts = ts_arg == 0 ? 8 : ts_arg;
13088 int tabcount;
13089 colnr_T tabcol = 0;
13090 int t;
13091 int padding = 0;
13092
13093 if (vts == NULL || vts[0] == 0)
13094 return ts - (col % ts);
13095
13096 tabcount = vts[0];
13097
13098 for (t = 1; t <= tabcount; ++t)
13099 {
13100 tabcol += vts[t];
13101 if (tabcol > col)
13102 {
13103 padding = (int)(tabcol - col);
13104 break;
13105 }
13106 }
13107 if (t > tabcount)
13108 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
13109
13110 return padding;
13111}
13112
13113/*
13114 * Find the size of the tab that covers a particular column.
13115 */
13116 int
13117tabstop_at(colnr_T col, int ts, int *vts)
13118{
13119 int tabcount;
13120 colnr_T tabcol = 0;
13121 int t;
13122 int tab_size = 0;
13123
13124 if (vts == 0 || vts[0] == 0)
13125 return ts;
13126
13127 tabcount = vts[0];
13128 for (t = 1; t <= tabcount; ++t)
13129 {
13130 tabcol += vts[t];
13131 if (tabcol > col)
13132 {
13133 tab_size = vts[t];
13134 break;
13135 }
13136 }
13137 if (t > tabcount)
13138 tab_size = vts[tabcount];
13139
13140 return tab_size;
13141}
13142
13143/*
13144 * Find the column on which a tab starts.
13145 */
13146 colnr_T
13147tabstop_start(colnr_T col, int ts, int *vts)
13148{
13149 int tabcount;
13150 colnr_T tabcol = 0;
13151 int t;
13152 int excess;
13153
Bram Moolenaar0119a592018-06-24 23:53:28 +020013154 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013155 return (col / ts) * ts;
13156
13157 tabcount = vts[0];
13158 for (t = 1; t <= tabcount; ++t)
13159 {
13160 tabcol += vts[t];
13161 if (tabcol > col)
13162 return tabcol - vts[t];
13163 }
13164
13165 excess = tabcol % vts[tabcount];
13166 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13167}
13168
13169/*
13170 * Find the number of tabs and spaces necessary to get from one column
13171 * to another.
13172 */
13173 void
13174tabstop_fromto(
13175 colnr_T start_col,
13176 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013177 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013178 int *vts,
13179 int *ntabs,
13180 int *nspcs)
13181{
13182 int spaces = end_col - start_col;
13183 colnr_T tabcol = 0;
13184 int padding = 0;
13185 int tabcount;
13186 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013187 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013188
Bram Moolenaar0119a592018-06-24 23:53:28 +020013189 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013190 {
13191 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013192 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013193
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013194 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013195 if (spaces >= initspc)
13196 {
13197 spaces -= initspc;
13198 tabs++;
13199 }
13200 tabs += spaces / ts;
13201 spaces -= (spaces / ts) * ts;
13202
13203 *ntabs = tabs;
13204 *nspcs = spaces;
13205 return;
13206 }
13207
13208 /* Find the padding needed to reach the next tabstop. */
13209 tabcount = vts[0];
13210 for (t = 1; t <= tabcount; ++t)
13211 {
13212 tabcol += vts[t];
13213 if (tabcol > start_col)
13214 {
13215 padding = (int)(tabcol - start_col);
13216 break;
13217 }
13218 }
13219 if (t > tabcount)
13220 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13221
13222 /* If the space needed is less than the padding no tabs can be used. */
13223 if (spaces < padding)
13224 {
13225 *ntabs = 0;
13226 *nspcs = spaces;
13227 return;
13228 }
13229
13230 *ntabs = 1;
13231 spaces -= padding;
13232
13233 /* At least one tab has been used. See if any more will fit. */
13234 while (spaces != 0 && ++t <= tabcount)
13235 {
13236 padding = vts[t];
13237 if (spaces < padding)
13238 {
13239 *nspcs = spaces;
13240 return;
13241 }
13242 ++*ntabs;
13243 spaces -= padding;
13244 }
13245
13246 *ntabs += spaces / vts[tabcount];
13247 *nspcs = spaces % vts[tabcount];
13248}
13249
13250/*
13251 * See if two tabstop arrays contain the same values.
13252 */
13253 int
13254tabstop_eq(int *ts1, int *ts2)
13255{
13256 int t;
13257
13258 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13259 return FALSE;
13260 if (ts1 == ts2)
13261 return TRUE;
13262 if (ts1[0] != ts2[0])
13263 return FALSE;
13264
13265 for (t = 1; t <= ts1[0]; ++t)
13266 if (ts1[t] != ts2[t])
13267 return FALSE;
13268
13269 return TRUE;
13270}
13271
Bram Moolenaar113e1072019-01-20 15:30:40 +010013272#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013273/*
13274 * Copy a tabstop array, allocating space for the new array.
13275 */
13276 int *
13277tabstop_copy(int *oldts)
13278{
13279 int *newts;
13280 int t;
13281
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013282 if (oldts == NULL)
13283 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013284 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013285 if (newts != NULL)
13286 for (t = 0; t <= oldts[0]; ++t)
13287 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013288 return newts;
13289}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013290#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013291
13292/*
13293 * Return a count of the number of tabstops.
13294 */
13295 int
13296tabstop_count(int *ts)
13297{
13298 return ts != NULL ? ts[0] : 0;
13299}
13300
13301/*
13302 * Return the first tabstop, or 8 if there are no tabstops defined.
13303 */
13304 int
13305tabstop_first(int *ts)
13306{
13307 return ts != NULL ? ts[1] : 8;
13308}
13309
13310#endif
13311
Bram Moolenaar14f24742012-08-08 18:01:05 +020013312/*
13313 * Return the effective shiftwidth value for current buffer, using the
13314 * 'tabstop' value when 'shiftwidth' is zero.
13315 */
13316 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013317get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013318{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013319 return get_sw_value_col(buf, 0);
13320}
13321
13322/*
Bram Moolenaarf9514162018-11-22 03:08:29 +010013323 * Idem, using "pos".
13324 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020013325 static long
Bram Moolenaarf9514162018-11-22 03:08:29 +010013326get_sw_value_pos(buf_T *buf, pos_T *pos)
13327{
13328 pos_T save_cursor = curwin->w_cursor;
13329 long sw_value;
13330
13331 curwin->w_cursor = *pos;
13332 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13333 curwin->w_cursor = save_cursor;
13334 return sw_value;
13335}
13336
13337/*
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020013338 * Idem, using the first non-black in the current line.
13339 */
13340 long
13341get_sw_value_indent(buf_T *buf)
13342{
13343 pos_T pos = curwin->w_cursor;
13344
13345 pos.col = getwhitecols_curline();
13346 return get_sw_value_pos(buf, &pos);
13347}
13348
13349/*
Bram Moolenaarf9514162018-11-22 03:08:29 +010013350 * Idem, using virtual column "col".
13351 */
13352 long
13353get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13354{
13355 return buf->b_p_sw ? buf->b_p_sw :
13356 #ifdef FEAT_VARTABS
13357 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13358 #else
13359 buf->b_p_ts;
13360 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013361}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013362
13363/*
13364 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013365 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013366 */
13367 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013368get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013369{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013370 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013371}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013372
13373/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013374 * Return the effective 'scrolloff' value for the current window, using the
13375 * global value when appropriate.
13376 */
13377 long
13378get_scrolloff_value(void)
13379{
13380 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13381}
13382
13383/*
13384 * Return the effective 'sidescrolloff' value for the current window, using the
13385 * global value when appropriate.
13386 */
13387 long
13388get_sidescrolloff_value(void)
13389{
13390 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13391}
13392
13393/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013394 * Check matchpairs option for "*initc".
13395 * If there is a match set "*initc" to the matching character and "*findc" to
13396 * the opposite character. Set "*backwards" to the direction.
13397 * When "switchit" is TRUE swap the direction.
13398 */
13399 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013400find_mps_values(
13401 int *initc,
13402 int *findc,
13403 int *backwards,
13404 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013405{
13406 char_u *ptr;
13407
13408 ptr = curbuf->b_p_mps;
13409 while (*ptr != NUL)
13410 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013411 if (has_mbyte)
13412 {
13413 char_u *prev;
13414
13415 if (mb_ptr2char(ptr) == *initc)
13416 {
13417 if (switchit)
13418 {
13419 *findc = *initc;
13420 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13421 *backwards = TRUE;
13422 }
13423 else
13424 {
13425 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13426 *backwards = FALSE;
13427 }
13428 return;
13429 }
13430 prev = ptr;
13431 ptr += mb_ptr2len(ptr) + 1;
13432 if (mb_ptr2char(ptr) == *initc)
13433 {
13434 if (switchit)
13435 {
13436 *findc = *initc;
13437 *initc = mb_ptr2char(prev);
13438 *backwards = FALSE;
13439 }
13440 else
13441 {
13442 *findc = mb_ptr2char(prev);
13443 *backwards = TRUE;
13444 }
13445 return;
13446 }
13447 ptr += mb_ptr2len(ptr);
13448 }
13449 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013450 {
13451 if (*ptr == *initc)
13452 {
13453 if (switchit)
13454 {
13455 *backwards = TRUE;
13456 *findc = *initc;
13457 *initc = ptr[2];
13458 }
13459 else
13460 {
13461 *backwards = FALSE;
13462 *findc = ptr[2];
13463 }
13464 return;
13465 }
13466 ptr += 2;
13467 if (*ptr == *initc)
13468 {
13469 if (switchit)
13470 {
13471 *backwards = FALSE;
13472 *findc = *initc;
13473 *initc = ptr[-2];
13474 }
13475 else
13476 {
13477 *backwards = TRUE;
13478 *findc = ptr[-2];
13479 }
13480 return;
13481 }
13482 ++ptr;
13483 }
13484 if (*ptr == ',')
13485 ++ptr;
13486 }
13487}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013488
13489#if defined(FEAT_LINEBREAK) || defined(PROTO)
13490/*
13491 * This is called when 'breakindentopt' is changed and when a window is
13492 * initialized.
13493 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013494 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013495briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013496{
13497 char_u *p;
13498 int bri_shift = 0;
13499 long bri_min = 20;
13500 int bri_sbr = FALSE;
13501
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013502 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013503 while (*p != NUL)
13504 {
13505 if (STRNCMP(p, "shift:", 6) == 0
13506 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13507 {
13508 p += 6;
13509 bri_shift = getdigits(&p);
13510 }
13511 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13512 {
13513 p += 4;
13514 bri_min = getdigits(&p);
13515 }
13516 else if (STRNCMP(p, "sbr", 3) == 0)
13517 {
13518 p += 3;
13519 bri_sbr = TRUE;
13520 }
13521 if (*p != ',' && *p != NUL)
13522 return FAIL;
13523 if (*p == ',')
13524 ++p;
13525 }
13526
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013527 wp->w_p_brishift = bri_shift;
13528 wp->w_p_brimin = bri_min;
13529 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013530
13531 return OK;
13532}
13533#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013534
13535/*
13536 * Get the local or global value of 'backupcopy'.
13537 */
13538 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013539get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013540{
13541 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13542}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013543
13544#if defined(FEAT_SIGNS) || defined(PROTO)
13545/*
13546 * Return TRUE when window "wp" has a column to draw signs in.
13547 */
13548 int
13549signcolumn_on(win_T *wp)
13550{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020013551 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
13552 // column (if present). Otherwise signs are to be displayed in the sign
13553 // column.
13554 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
13555 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
13556
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013557 if (*wp->w_p_scl == 'n')
13558 return FALSE;
13559 if (*wp->w_p_scl == 'y')
13560 return TRUE;
13561 return (wp->w_buffer->b_signlist != NULL
13562# ifdef FEAT_NETBEANS_INTG
13563 || wp->w_buffer->b_has_sign_column
13564# endif
13565 );
13566}
13567#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013568
13569#if defined(FEAT_EVAL) || defined(PROTO)
13570/*
13571 * Get window or buffer local options.
13572 */
13573 dict_T *
13574get_winbuf_options(int bufopt)
13575{
13576 dict_T *d;
13577 int opt_idx;
13578
13579 d = dict_alloc();
13580 if (d == NULL)
13581 return NULL;
13582
13583 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13584 {
13585 struct vimoption *opt = &options[opt_idx];
13586
13587 if ((bufopt && (opt->indir & PV_BUF))
13588 || (!bufopt && (opt->indir & PV_WIN)))
13589 {
13590 char_u *varp = get_varp(opt);
13591
13592 if (varp != NULL)
13593 {
13594 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013595 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013596 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013597 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013598 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013599 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013600 }
13601 }
13602 }
13603
13604 return d;
13605}
13606#endif