blob: 6d3a059cca66aa724f456c1a4d01123f3ebc721d [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.
3895 */
3896 void
3897set_local_options_default(win_T *wp)
3898{
3899 win_T *save_curwin = curwin;
3900 int i;
3901
3902 curwin = wp;
3903 curbuf = curwin->w_buffer;
3904 block_autocmds();
3905
3906 for (i = 0; !istermoption(&options[i]); i++)
3907 {
3908 struct vimoption *p = &(options[i]);
3909 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3910
3911 if (p->indir != PV_NONE
3912 && !(options[i].flags & P_NODEFAULT)
3913 && !optval_default(p, varp, FALSE))
3914 set_option_default(i, OPT_LOCAL, FALSE);
3915 }
3916
3917 unblock_autocmds();
3918 curwin = save_curwin;
3919 curbuf = curwin->w_buffer;
3920}
3921
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003922#if defined(EXITFREE) || defined(PROTO)
3923/*
3924 * Free all options.
3925 */
3926 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003927free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003928{
3929 int i;
3930
3931 for (i = 0; !istermoption(&options[i]); i++)
3932 {
3933 if (options[i].indir == PV_NONE)
3934 {
3935 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003936 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003937 free_string_option(*(char_u **)options[i].var);
3938 if (options[i].flags & P_DEF_ALLOCED)
3939 free_string_option(options[i].def_val[VI_DEFAULT]);
3940 }
3941 else if (options[i].var != VAR_WIN
3942 && (options[i].flags & P_STRING))
3943 /* buffer-local option: free global value */
3944 free_string_option(*(char_u **)options[i].var);
3945 }
3946}
3947#endif
3948
3949
Bram Moolenaar071d4272004-06-13 20:20:40 +00003950/*
3951 * Initialize the options, part two: After getting Rows and Columns and
3952 * setting 'term'.
3953 */
3954 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003955set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003956{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003957 int idx;
3958
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003960 * 'scroll' defaults to half the window height. The stored default is zero,
3961 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003962 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003963 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003964 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003965 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 comp_col();
3967
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003968 /*
3969 * 'window' is only for backwards compatibility with Vi.
3970 * Default is Rows - 1.
3971 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003972 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003973 p_window = Rows - 1;
3974 set_number_default("window", Rows - 1);
3975
Bram Moolenaarf740b292006-02-16 22:11:02 +00003976 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003977#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003978 /*
3979 * If 'background' wasn't set by the user, try guessing the value,
3980 * depending on the terminal name. Only need to check for terminals
3981 * with a dark background, that can handle color.
3982 */
3983 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003984 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3985 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003986 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003987 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003988 /* don't mark it as set, when starting the GUI it may be
3989 * changed again */
3990 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003991 }
3992#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003993
3994#ifdef CURSOR_SHAPE
3995 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3996#endif
3997#ifdef FEAT_MOUSESHAPE
3998 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3999#endif
4000#ifdef FEAT_PRINTER
4001 (void)parse_printoptions(); /* parse 'printoptions' default value */
4002#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004003}
4004
4005/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004006 * Return "dark" or "light" depending on the kind of terminal.
4007 * This is just guessing! Recognized are:
4008 * "linux" Linux console
4009 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004010 * "cygwin.*" Cygwin shell
4011 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004012 * We also check the COLORFGBG environment variable, which is set by
4013 * rxvt and derivatives. This variable contains either two or three
4014 * values separated by semicolons; we want the last value in either
4015 * case. If this value is 0-6 or 8, our background is dark.
4016 */
4017 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004018term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004019{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004020#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004021 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004022 return (char_u *)"dark";
4023#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004024 char_u *p;
4025
Bram Moolenaarf740b292006-02-16 22:11:02 +00004026 if (STRCMP(T_NAME, "linux") == 0
4027 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004028 || STRNCMP(T_NAME, "cygwin", 6) == 0
4029 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004030 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4031 && (p = vim_strrchr(p, ';')) != NULL
4032 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4033 && p[2] == NUL))
4034 return (char_u *)"dark";
4035 return (char_u *)"light";
4036#endif
4037}
4038
4039/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004040 * Initialize the options, part three: After reading the .vimrc
4041 */
4042 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004043set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004045#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004046/*
4047 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4048 * This is done after other initializations, where 'shell' might have been
4049 * set, but only if they have not been set before.
4050 */
4051 char_u *p;
4052 int idx_srr;
4053 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004054# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004055 int idx_sp;
4056 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004057# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058
4059 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004060 if (idx_srr < 0)
4061 do_srr = FALSE;
4062 else
4063 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004064# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004066 if (idx_sp < 0)
4067 do_sp = FALSE;
4068 else
4069 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004071 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004072 if (p != NULL)
4073 {
4074 /*
4075 * Default for p_sp is "| tee", for p_srr is ">".
4076 * For known shells it is changed here to include stderr.
4077 */
4078 if ( fnamecmp(p, "csh") == 0
4079 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004080# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004081 || fnamecmp(p, "csh.exe") == 0
4082 || fnamecmp(p, "tcsh.exe") == 0
4083# endif
4084 )
4085 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 if (do_sp)
4088 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004089# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004091# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004092 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004093# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4095 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004096# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004097 if (do_srr)
4098 {
4099 p_srr = (char_u *)">&";
4100 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4101 }
4102 }
4103 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004104 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 if ( fnamecmp(p, "sh") == 0
4106 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004107 || fnamecmp(p, "mksh") == 0
4108 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004110 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004111 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004112 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004113# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 || fnamecmp(p, "cmd") == 0
4115 || fnamecmp(p, "sh.exe") == 0
4116 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004117 || fnamecmp(p, "mksh.exe") == 0
4118 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004119 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004120 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004121 || fnamecmp(p, "bash.exe") == 0
4122 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004124 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004126# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 if (do_sp)
4128 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004129# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004131# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004133# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4135 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004136# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004137 if (do_srr)
4138 {
4139 p_srr = (char_u *)">%s 2>&1";
4140 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4141 }
4142 }
4143 vim_free(p);
4144 }
4145#endif
4146
Bram Moolenaar4f974752019-02-17 17:44:42 +01004147#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004149 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4150 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004151 * This is done after other initializations, where 'shell' might have been
4152 * set, but only if they have not been set before. Default for p_shcf is
4153 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004154 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004156 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004157 {
4158 int idx3;
4159
4160 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004161 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004162 {
4163 p_shcf = (char_u *)"-c";
4164 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4165 }
4166
Bram Moolenaar071d4272004-06-13 20:20:40 +00004167 /* Somehow Win32 requires the quotes around the redirection too */
4168 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004169 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004170 {
4171 p_sxq = (char_u *)"\"";
4172 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4173 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004175 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4176 {
4177 int idx3;
4178
4179 /*
4180 * cmd.exe on Windows will strip the first and last double quote given
4181 * on the command line, e.g. most of the time things like:
4182 * cmd /c "my path/to/echo" "my args to echo"
4183 * become:
4184 * my path/to/echo" "my args to echo
4185 * when executed.
4186 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004187 * To avoid this, set shellxquote to surround the command in
4188 * parenthesis. This appears to make most commands work, without
4189 * breaking commands that worked previously, such as
4190 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004191 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004192 idx3 = findoption((char_u *)"sxq");
4193 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4194 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004195 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004196 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4197 }
4198
Bram Moolenaara64ba222012-02-12 23:23:31 +01004199 idx3 = findoption((char_u *)"shcf");
4200 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4201 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004202 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004203 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4204 }
4205 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004206#endif
4207
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004208 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004209 {
4210 int idx_ffs = findoption((char_u *)"ffs");
4211
4212 /* Apply the first entry of 'fileformats' to the initial buffer. */
4213 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4214 set_fileformat(default_fileformat(), OPT_LOCAL);
4215 }
4216
Bram Moolenaar071d4272004-06-13 20:20:40 +00004217#ifdef FEAT_TITLE
4218 set_title_defaults();
4219#endif
4220}
4221
4222#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4223/*
4224 * When 'helplang' is still at its default value, set it to "lang".
4225 * Only the first two characters of "lang" are used.
4226 */
4227 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004228set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229{
4230 int idx;
4231
4232 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4233 return;
4234 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004235 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004236 {
4237 if (options[idx].flags & P_ALLOCED)
4238 free_string_option(p_hlg);
4239 p_hlg = vim_strsave(lang);
4240 if (p_hlg == NULL)
4241 p_hlg = empty_option;
4242 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004243 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004244 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004245 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4246 {
4247 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4248 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4249 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004250 // any C like setting, such as C.UTF-8, becomes "en"
4251 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4252 {
4253 p_hlg[0] = 'e';
4254 p_hlg[1] = 'n';
4255 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004256 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004257 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004258 options[idx].flags |= P_ALLOCED;
4259 }
4260}
4261#endif
4262
4263#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004264 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004265gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004266{
4267 if (gui_get_lightness(gui.back_pixel) < 127)
4268 return (char_u *)"dark";
4269 return (char_u *)"light";
4270}
4271
4272/*
4273 * Option initializations that can only be done after opening the GUI window.
4274 */
4275 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004276init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004277{
4278 /* Set the 'background' option according to the lightness of the
4279 * background color, unless the user has set it already. */
4280 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4281 {
4282 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4283 highlight_changed();
4284 }
4285}
4286#endif
4287
4288#ifdef FEAT_TITLE
4289/*
4290 * 'title' and 'icon' only default to true if they have not been set or reset
4291 * in .vimrc and we can read the old value.
4292 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4293 * they can be reset. This reduces startup time when using X on a remote
4294 * machine.
4295 */
4296 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004297set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004298{
4299 int idx1;
4300 long val;
4301
4302 /*
4303 * If GUI is (going to be) used, we can always set the window title and
4304 * icon name. Saves a bit of time, because the X11 display server does
4305 * not need to be contacted.
4306 */
4307 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004308 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004309 {
4310#ifdef FEAT_GUI
4311 if (gui.starting || gui.in_use)
4312 val = TRUE;
4313 else
4314#endif
4315 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004316 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004317 p_title = val;
4318 }
4319 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004320 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004321 {
4322#ifdef FEAT_GUI
4323 if (gui.starting || gui.in_use)
4324 val = TRUE;
4325 else
4326#endif
4327 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004328 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004329 p_icon = val;
4330 }
4331}
4332#endif
4333
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004334#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02004335/*
4336 * Trigger the OptionSet autocommand.
4337 * "opt_idx" is the index of the option being set.
4338 * "opt_flags" can be OPT_LOCAL etc.
4339 * "oldval" the old value
4340 * "oldval_l" the old local value (only non-NULL if global and local value
4341 * are set)
4342 * "oldval_g" the old global value (only non-NULL if global and local value
4343 * are set)
4344 * "newval" the new value
4345 */
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004346 static void
4347trigger_optionsset_string(
4348 int opt_idx,
4349 int opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02004350 char_u *oldval,
4351 char_u *oldval_l,
4352 char_u *oldval_g,
4353 char_u *newval)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004354{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004355 // Don't do this recursively.
4356 if (oldval != NULL && newval != NULL
4357 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004358 {
4359 char_u buf_type[7];
4360
4361 sprintf((char *)buf_type, "%s",
4362 (opt_flags & OPT_LOCAL) ? "local" : "global");
4363 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4364 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4365 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02004366 if (opt_flags & OPT_LOCAL)
4367 {
4368 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
4369 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4370 }
4371 if (opt_flags & OPT_GLOBAL)
4372 {
4373 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
4374 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
4375 }
4376 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4377 {
4378 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
4379 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
4380 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
4381 }
4382 if (opt_flags & OPT_MODELINE)
4383 {
4384 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
4385 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4386 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004387 apply_autocmds(EVENT_OPTIONSET,
4388 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4389 reset_v_option_vars();
4390 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004391}
4392#endif
4393
Bram Moolenaar071d4272004-06-13 20:20:40 +00004394/*
4395 * Parse 'arg' for option settings.
4396 *
4397 * 'arg' may be IObuff, but only when no errors can be present and option
4398 * does not need to be expanded with option_expand().
4399 * "opt_flags":
4400 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004401 * OPT_GLOBAL for ":setglobal"
4402 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004403 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004404 * OPT_WINONLY to only set window-local options
4405 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004406 *
4407 * returns FAIL if an error is detected, OK otherwise
4408 */
4409 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004410do_set(
4411 char_u *arg, /* option string (may be written to!) */
4412 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004413{
4414 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004415 char *errmsg;
4416 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004417 char_u *startarg;
4418 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4419 int nextchar; /* next non-white char after option name */
4420 int afterchar; /* character just after option name */
4421 int len;
4422 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004423 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004424 int key;
4425 long_u flags; /* flags for current option */
4426 char_u *varp = NULL; /* pointer to variable for current option */
4427 int did_show = FALSE; /* already showed one value */
4428 int adding; /* "opt+=arg" */
4429 int prepending; /* "opt^=arg" */
4430 int removing; /* "opt-=arg" */
4431 int cp_val = 0;
4432 char_u key_name[2];
4433
4434 if (*arg == NUL)
4435 {
4436 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004437 did_show = TRUE;
4438 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004439 }
4440
4441 while (*arg != NUL) /* loop to process all options */
4442 {
4443 errmsg = NULL;
4444 startarg = arg; /* remember for error message */
4445
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004446 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4447 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004448 {
4449 /*
4450 * ":set all" show all options.
4451 * ":set all&" set all options to their default value.
4452 */
4453 arg += 3;
4454 if (*arg == '&')
4455 {
4456 ++arg;
4457 /* Only for :set command set global value of local options. */
4458 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004459 didset_options();
4460 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004461 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004462 }
4463 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004464 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004465 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004466 did_show = TRUE;
4467 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004468 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004469 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004470 {
4471 showoptions(2, opt_flags);
4472 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004473 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004474 arg += 7;
4475 }
4476 else
4477 {
4478 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004479 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004480 {
4481 prefix = 0;
4482 arg += 2;
4483 }
4484 else if (STRNCMP(arg, "inv", 3) == 0)
4485 {
4486 prefix = 2;
4487 arg += 3;
4488 }
4489
4490 /* find end of name */
4491 key = 0;
4492 if (*arg == '<')
4493 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004494 opt_idx = -1;
4495 /* look out for <t_>;> */
4496 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4497 len = 5;
4498 else
4499 {
4500 len = 1;
4501 while (arg[len] != NUL && arg[len] != '>')
4502 ++len;
4503 }
4504 if (arg[len] != '>')
4505 {
4506 errmsg = e_invarg;
4507 goto skip;
4508 }
4509 arg[len] = NUL; /* put NUL after name */
4510 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4511 opt_idx = findoption(arg + 1);
4512 arg[len++] = '>'; /* restore '>' */
4513 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004514 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004515 }
4516 else
4517 {
4518 len = 0;
4519 /*
4520 * The two characters after "t_" may not be alphanumeric.
4521 */
4522 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4523 len = 4;
4524 else
4525 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4526 ++len;
4527 nextchar = arg[len];
4528 arg[len] = NUL; /* put NUL after name */
4529 opt_idx = findoption(arg);
4530 arg[len] = nextchar; /* restore nextchar */
4531 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004532 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004533 }
4534
4535 /* remember character after option name */
4536 afterchar = arg[len];
4537
4538 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004539 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004540 ++len;
4541
4542 adding = FALSE;
4543 prepending = FALSE;
4544 removing = FALSE;
4545 if (arg[len] != NUL && arg[len + 1] == '=')
4546 {
4547 if (arg[len] == '+')
4548 {
4549 adding = TRUE; /* "+=" */
4550 ++len;
4551 }
4552 else if (arg[len] == '^')
4553 {
4554 prepending = TRUE; /* "^=" */
4555 ++len;
4556 }
4557 else if (arg[len] == '-')
4558 {
4559 removing = TRUE; /* "-=" */
4560 ++len;
4561 }
4562 }
4563 nextchar = arg[len];
4564
4565 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4566 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004567 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004568 goto skip;
4569 }
4570
4571 if (opt_idx >= 0)
4572 {
4573 if (options[opt_idx].var == NULL) /* hidden option: skip */
4574 {
4575 /* Only give an error message when requesting the value of
4576 * a hidden option, ignore setting it. */
4577 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4578 && (!(options[opt_idx].flags & P_BOOL)
4579 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004580 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 goto skip;
4582 }
4583
4584 flags = options[opt_idx].flags;
4585 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4586 }
4587 else
4588 {
4589 flags = P_STRING;
4590 if (key < 0)
4591 {
4592 key_name[0] = KEY2TERMCAP0(key);
4593 key_name[1] = KEY2TERMCAP1(key);
4594 }
4595 else
4596 {
4597 key_name[0] = KS_KEY;
4598 key_name[1] = (key & 0xff);
4599 }
4600 }
4601
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004602 /* Skip all options that are not window-local (used when showing
4603 * an already loaded buffer in a window). */
4604 if ((opt_flags & OPT_WINONLY)
4605 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4606 goto skip;
4607
Bram Moolenaara3227e22006-03-08 21:32:40 +00004608 /* Skip all options that are window-local (used for :vimgrep). */
4609 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4610 && options[opt_idx].var == VAR_WIN)
4611 goto skip;
4612
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004613 /* Disallow changing some options from modelines. */
4614 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004615 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004616 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004617 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004618 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004619 goto skip;
4620 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004621 if ((flags & P_MLE) && !p_mle)
4622 {
4623 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4624 goto skip;
4625 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004626#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004627 /* In diff mode some options are overruled. This avoids that
4628 * 'foldmethod' becomes "marker" instead of "diff" and that
4629 * "wrap" gets set. */
4630 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004631 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004632 && (
4633#ifdef FEAT_FOLDING
4634 options[opt_idx].indir == PV_FDM ||
4635#endif
4636 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004637 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004638#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004639 }
4640
4641#ifdef HAVE_SANDBOX
4642 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004643 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004644 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004645 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004646 goto skip;
4647 }
4648#endif
4649
4650 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4651 {
4652 arg += len;
4653 cp_val = p_cp;
4654 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4655 {
4656 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4657 {
4658 cp_val = FALSE;
4659 arg += 3;
4660 }
4661 else /* "opt&vi": set to Vi default */
4662 {
4663 cp_val = TRUE;
4664 arg += 2;
4665 }
4666 }
4667 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004668 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004669 {
4670 errmsg = e_trailing;
4671 goto skip;
4672 }
4673 }
4674
4675 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004676 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4677 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004678 */
4679 if (nextchar == '?'
4680 || (prefix == 1
4681 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4682 && !(flags & P_BOOL)))
4683 {
4684 /*
4685 * print value
4686 */
4687 if (did_show)
4688 msg_putchar('\n'); /* cursor below last one */
4689 else
4690 {
4691 gotocmdline(TRUE); /* cursor at status line */
4692 did_show = TRUE; /* remember that we did a line */
4693 }
4694 if (opt_idx >= 0)
4695 {
4696 showoneopt(&options[opt_idx], opt_flags);
4697#ifdef FEAT_EVAL
4698 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004699 {
4700 /* Mention where the option was last set. */
4701 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004702 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004703 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004704 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004705 (int)options[opt_idx].indir & PV_MASK]);
4706 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004707 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004708 (int)options[opt_idx].indir & PV_MASK]);
4709 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004710#endif
4711 }
4712 else
4713 {
4714 char_u *p;
4715
4716 p = find_termcode(key_name);
4717 if (p == NULL)
4718 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004719 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004720 goto skip;
4721 }
4722 else
4723 (void)show_one_termcode(key_name, p, TRUE);
4724 }
4725 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004726 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004727 errmsg = e_trailing;
4728 }
4729 else
4730 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004731 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004732 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004733
Bram Moolenaar071d4272004-06-13 20:20:40 +00004734 if (flags & P_BOOL) /* boolean */
4735 {
4736 if (nextchar == '=' || nextchar == ':')
4737 {
4738 errmsg = e_invarg;
4739 goto skip;
4740 }
4741
4742 /*
4743 * ":set opt!": invert
4744 * ":set opt&": reset to default value
4745 * ":set opt<": reset to global value
4746 */
4747 if (nextchar == '!')
4748 value = *(int *)(varp) ^ 1;
4749 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004750 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004751 ((flags & P_VI_DEF) || cp_val)
4752 ? VI_DEFAULT : VIM_DEFAULT];
4753 else if (nextchar == '<')
4754 {
4755 /* For 'autoread' -1 means to use global value. */
4756 if ((int *)varp == &curbuf->b_p_ar
4757 && opt_flags == OPT_LOCAL)
4758 value = -1;
4759 else
4760 value = *(int *)get_varp_scope(&(options[opt_idx]),
4761 OPT_GLOBAL);
4762 }
4763 else
4764 {
4765 /*
4766 * ":set invopt": invert
4767 * ":set opt" or ":set noopt": set or reset
4768 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004769 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004770 {
4771 errmsg = e_trailing;
4772 goto skip;
4773 }
4774 if (prefix == 2) /* inv */
4775 value = *(int *)(varp) ^ 1;
4776 else
4777 value = prefix;
4778 }
4779
4780 errmsg = set_bool_option(opt_idx, varp, (int)value,
4781 opt_flags);
4782 }
4783 else /* numeric or string */
4784 {
4785 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4786 || prefix != 1)
4787 {
4788 errmsg = e_invarg;
4789 goto skip;
4790 }
4791
4792 if (flags & P_NUM) /* numeric */
4793 {
4794 /*
4795 * Different ways to set a number option:
4796 * & set to default value
4797 * < set to global value
4798 * <xx> accept special key codes for 'wildchar'
4799 * c accept any non-digit for 'wildchar'
4800 * [-]0-9 set number
4801 * other error
4802 */
4803 ++arg;
4804 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004805 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004806 ((flags & P_VI_DEF) || cp_val)
4807 ? VI_DEFAULT : VIM_DEFAULT];
4808 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004809 {
4810 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4811 * use the global value. */
4812 if ((long *)varp == &curbuf->b_p_ul
4813 && opt_flags == OPT_LOCAL)
4814 value = NO_LOCAL_UNDOLEVEL;
4815 else
4816 value = *(long *)get_varp_scope(
4817 &(options[opt_idx]), OPT_GLOBAL);
4818 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004819 else if (((long *)varp == &p_wc
4820 || (long *)varp == &p_wcm)
4821 && (*arg == '<'
4822 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004823 || (*arg != NUL
4824 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004825 && !VIM_ISDIGIT(*arg))))
4826 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004827 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004828 if (value == 0 && (long *)varp != &p_wcm)
4829 {
4830 errmsg = e_invarg;
4831 goto skip;
4832 }
4833 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004834 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4835 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004836 /* Allow negative (for 'undolevels'), octal and
4837 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004838 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004839 &value, NULL, 0, TRUE);
Bram Moolenaar06e2c812019-06-12 19:05:48 +02004840 if (i == 0 || (arg[i] != NUL
4841 && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004842 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004843 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004844 goto skip;
4845 }
4846 }
4847 else
4848 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004849 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004850 goto skip;
4851 }
4852
4853 if (adding)
4854 value = *(long *)varp + value;
4855 if (prepending)
4856 value = *(long *)varp * value;
4857 if (removing)
4858 value = *(long *)varp - value;
4859 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004860 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004861 }
4862 else if (opt_idx >= 0) /* string */
4863 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004864 char_u *save_arg = NULL;
4865 char_u *s = NULL;
4866 char_u *oldval = NULL; /* previous value if *varp */
4867 char_u *newval;
4868 char_u *origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004869 char_u *origval_l = NULL;
4870 char_u *origval_g = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004871#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004872 char_u *saved_origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004873 char_u *saved_origval_l = NULL;
4874 char_u *saved_origval_g = NULL;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004875 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004876#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004877 unsigned newlen;
4878 int comma;
4879 int bs;
4880 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004881 was allocated */
4882
4883 /* When using ":set opt=val" for a global option
4884 * with a local value the local value will be
4885 * reset, use the global value here. */
4886 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004887 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004888 varp = options[opt_idx].var;
4889
4890 /* The old value is kept until we are sure that the
4891 * new value is valid. */
4892 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004893
Bram Moolenaard7c96872019-06-15 17:12:48 +02004894 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4895 {
4896 origval_l = *(char_u **)get_varp_scope(
4897 &(options[opt_idx]), OPT_LOCAL);
4898 origval_g = *(char_u **)get_varp_scope(
4899 &(options[opt_idx]), OPT_GLOBAL);
4900
4901 // A global-local string option might have an empty
4902 // option as value to indicate that the global
4903 // value should be used.
4904 if (((int)options[opt_idx].indir & PV_BOTH)
4905 && origval_l == empty_option)
4906 origval_l = origval_g;
4907 }
4908
4909 // When setting the local value of a global
4910 // option, the old value may be the global value.
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004911 if (((int)options[opt_idx].indir & PV_BOTH)
4912 && (opt_flags & OPT_LOCAL))
4913 origval = *(char_u **)get_varp(
4914 &options[opt_idx]);
4915 else
4916 origval = oldval;
4917
Bram Moolenaar071d4272004-06-13 20:20:40 +00004918 if (nextchar == '&') /* set to default val */
4919 {
4920 newval = options[opt_idx].def_val[
4921 ((flags & P_VI_DEF) || cp_val)
4922 ? VI_DEFAULT : VIM_DEFAULT];
4923 if ((char_u **)varp == &p_bg)
4924 {
4925 /* guess the value of 'background' */
4926#ifdef FEAT_GUI
4927 if (gui.in_use)
4928 newval = gui_bg_default();
4929 else
4930#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004931 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004932 }
4933
4934 /* expand environment variables and ~ (since the
4935 * default value was already expanded, only
4936 * required when an environment variable was set
4937 * later */
4938 if (newval == NULL)
4939 newval = empty_option;
4940 else
4941 {
4942 s = option_expand(opt_idx, newval);
4943 if (s == NULL)
4944 s = newval;
4945 newval = vim_strsave(s);
4946 }
4947 new_value_alloced = TRUE;
4948 }
4949 else if (nextchar == '<') /* set to global val */
4950 {
4951 newval = vim_strsave(*(char_u **)get_varp_scope(
4952 &(options[opt_idx]), OPT_GLOBAL));
4953 new_value_alloced = TRUE;
4954 }
4955 else
4956 {
4957 ++arg; /* jump to after the '=' or ':' */
4958
4959 /*
4960 * Set 'keywordprg' to ":help" if an empty
4961 * value was passed to :set by the user.
4962 * Misuse errbuf[] for the resulting string.
4963 */
4964 if (varp == (char_u *)&p_kp
4965 && (*arg == NUL || *arg == ' '))
4966 {
4967 STRCPY(errbuf, ":help");
4968 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004969 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004970 }
4971 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004972 * Convert 'backspace' number to string, for
4973 * adding, prepending and removing string.
4974 */
4975 else if (varp == (char_u *)&p_bs
4976 && VIM_ISDIGIT(**(char_u **)varp))
4977 {
4978 i = getdigits((char_u **)varp);
4979 switch (i)
4980 {
4981 case 0:
4982 *(char_u **)varp = empty_option;
4983 break;
4984 case 1:
4985 *(char_u **)varp = vim_strsave(
4986 (char_u *)"indent,eol");
4987 break;
4988 case 2:
4989 *(char_u **)varp = vim_strsave(
4990 (char_u *)"indent,eol,start");
4991 break;
4992 }
4993 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004994 if (origval == oldval)
4995 origval = *(char_u **)varp;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004996 if (origval_l == oldval)
4997 origval_l = *(char_u **)varp;
4998 if (origval_g == oldval)
4999 origval_g = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01005000 oldval = *(char_u **)varp;
5001 }
5002 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005003 * Convert 'whichwrap' number to string, for
5004 * backwards compatibility with Vim 3.0.
5005 * Misuse errbuf[] for the resulting string.
5006 */
5007 else if (varp == (char_u *)&p_ww
5008 && VIM_ISDIGIT(*arg))
5009 {
5010 *errbuf = NUL;
5011 i = getdigits(&arg);
5012 if (i & 1)
5013 STRCAT(errbuf, "b,");
5014 if (i & 2)
5015 STRCAT(errbuf, "s,");
5016 if (i & 4)
5017 STRCAT(errbuf, "h,l,");
5018 if (i & 8)
5019 STRCAT(errbuf, "<,>,");
5020 if (i & 16)
5021 STRCAT(errbuf, "[,],");
5022 if (*errbuf != NUL) /* remove trailing , */
5023 errbuf[STRLEN(errbuf) - 1] = NUL;
5024 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005025 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005026 }
5027 /*
5028 * Remove '>' before 'dir' and 'bdir', for
5029 * backwards compatibility with version 3.0
5030 */
5031 else if ( *arg == '>'
5032 && (varp == (char_u *)&p_dir
5033 || varp == (char_u *)&p_bdir))
5034 {
5035 ++arg;
5036 }
5037
Bram Moolenaar071d4272004-06-13 20:20:40 +00005038 /*
5039 * Copy the new string into allocated memory.
5040 * Can't use set_string_option_direct(), because
5041 * we need to remove the backslashes.
5042 */
5043 /* get a bit too much */
5044 newlen = (unsigned)STRLEN(arg) + 1;
5045 if (adding || prepending || removing)
5046 newlen += (unsigned)STRLEN(origval) + 1;
5047 newval = alloc(newlen);
5048 if (newval == NULL) /* out of mem, don't change */
5049 break;
5050 s = newval;
5051
5052 /*
5053 * Copy the string, skip over escaped chars.
5054 * For MS-DOS and WIN32 backslashes before normal
5055 * file name characters are not removed, and keep
5056 * backslash at start, for "\\machine\path", but
5057 * do remove it for "\\\\machine\\path".
5058 * The reverse is found in ExpandOldSetting().
5059 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005060 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005061 {
5062 if (*arg == '\\' && arg[1] != NUL
5063#ifdef BACKSLASH_IN_FILENAME
5064 && !((flags & P_EXPAND)
5065 && vim_isfilec(arg[1])
5066 && (arg[1] != '\\'
5067 || (s == newval
5068 && arg[2] != '\\')))
5069#endif
5070 )
5071 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005072 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005073 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005074 {
5075 /* copy multibyte char */
5076 mch_memmove(s, arg, (size_t)i);
5077 arg += i;
5078 s += i;
5079 }
5080 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005081 *s++ = *arg++;
5082 }
5083 *s = NUL;
5084
5085 /*
5086 * Expand environment variables and ~.
5087 * Don't do it when adding without inserting a
5088 * comma.
5089 */
5090 if (!(adding || prepending || removing)
5091 || (flags & P_COMMA))
5092 {
5093 s = option_expand(opt_idx, newval);
5094 if (s != NULL)
5095 {
5096 vim_free(newval);
5097 newlen = (unsigned)STRLEN(s) + 1;
5098 if (adding || prepending || removing)
5099 newlen += (unsigned)STRLEN(origval) + 1;
5100 newval = alloc(newlen);
5101 if (newval == NULL)
5102 break;
5103 STRCPY(newval, s);
5104 }
5105 }
5106
5107 /* locate newval[] in origval[] when removing it
5108 * and when adding to avoid duplicates */
5109 i = 0; /* init for GCC */
5110 if (removing || (flags & P_NODUP))
5111 {
5112 i = (int)STRLEN(newval);
5113 bs = 0;
5114 for (s = origval; *s; ++s)
5115 {
5116 if ((!(flags & P_COMMA)
5117 || s == origval
5118 || (s[-1] == ',' && !(bs & 1)))
5119 && STRNCMP(s, newval, i) == 0
5120 && (!(flags & P_COMMA)
5121 || s[i] == ','
5122 || s[i] == NUL))
5123 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005124 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005125 * even number of backslashes or a single
5126 * backslash preceded by a comma before it
5127 * is recognized as a separator */
5128 if ((s > origval + 1
5129 && s[-1] == '\\'
5130 && s[-2] != ',')
5131 || (s == origval + 1
5132 && s[-1] == '\\'))
5133
Bram Moolenaar071d4272004-06-13 20:20:40 +00005134 ++bs;
5135 else
5136 bs = 0;
5137 }
5138
5139 /* do not add if already there */
5140 if ((adding || prepending) && *s)
5141 {
5142 prepending = FALSE;
5143 adding = FALSE;
5144 STRCPY(newval, origval);
5145 }
5146 }
5147
5148 /* concatenate the two strings; add a ',' if
5149 * needed */
5150 if (adding || prepending)
5151 {
5152 comma = ((flags & P_COMMA) && *origval != NUL
5153 && *newval != NUL);
5154 if (adding)
5155 {
5156 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005157 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005158 if (comma && i > 1
5159 && (flags & P_ONECOMMA) == P_ONECOMMA
5160 && origval[i - 1] == ','
5161 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005162 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005163 mch_memmove(newval + i + comma, newval,
5164 STRLEN(newval) + 1);
5165 mch_memmove(newval, origval, (size_t)i);
5166 }
5167 else
5168 {
5169 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005170 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005171 }
5172 if (comma)
5173 newval[i] = ',';
5174 }
5175
5176 /* Remove newval[] from origval[]. (Note: "i" has
5177 * been set above and is used here). */
5178 if (removing)
5179 {
5180 STRCPY(newval, origval);
5181 if (*s)
5182 {
5183 /* may need to remove a comma */
5184 if (flags & P_COMMA)
5185 {
5186 if (s == origval)
5187 {
5188 /* include comma after string */
5189 if (s[i] == ',')
5190 ++i;
5191 }
5192 else
5193 {
5194 /* include comma before string */
5195 --s;
5196 ++i;
5197 }
5198 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005199 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005200 }
5201 }
5202
5203 if (flags & P_FLAGLIST)
5204 {
5205 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005206 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005207 {
5208 /* if options have P_FLAGLIST and
5209 * P_ONECOMMA such as 'whichwrap' */
5210 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005211 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005212 if (*s != ',' && *(s + 1) == ','
5213 && vim_strchr(s + 2, *s) != NULL)
5214 {
5215 /* Remove the duplicated value and
5216 * the next comma. */
5217 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005218 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005219 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005220 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005221 else
5222 {
5223 if ((!(flags & P_COMMA) || *s != ',')
5224 && vim_strchr(s + 1, *s) != NULL)
5225 {
5226 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005227 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005228 }
5229 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005230 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005231 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005232 }
5233
5234 if (save_arg != NULL) /* number for 'whichwrap' */
5235 arg = save_arg;
5236 new_value_alloced = TRUE;
5237 }
5238
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005239 /*
5240 * Set the new value.
5241 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005242 *(char_u **)(varp) = newval;
5243
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005244#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005245 if (!starting
5246# ifdef FEAT_CRYPT
5247 && options[opt_idx].indir != PV_KEY
5248# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005249 && origval != NULL && newval != NULL)
5250 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005251 /* origval may be freed by
5252 * did_set_string_option(), make a copy. */
5253 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005254 /* newval (and varp) may become invalid if the
5255 * buffer is closed by autocommands. */
5256 saved_newval = vim_strsave(newval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005257 if (origval_l != NULL)
5258 saved_origval_l = vim_strsave(origval_l);
5259 if (origval_g != NULL)
5260 saved_origval_g = vim_strsave(origval_g);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005261 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005262#endif
5263
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005264 {
5265 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005266 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005267
5268 // When an option is set in the sandbox, from a
5269 // modeline or in secure mode, then deal with side
5270 // effects in secure mode. Also when the value was
5271 // set with the P_INSECURE flag and is not
5272 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005273 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005274#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005275 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005276#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005277 || (!value_is_replaced && (*p & P_INSECURE)))
5278 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005279
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005280 // Handle side effects, and set the global value
5281 // for ":set" on local options. Note: when setting
5282 // 'syntax' or 'filetype' autocommands may be
5283 // triggered that can cause havoc.
5284 errmsg = did_set_string_option(
5285 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005286 new_value_alloced, oldval, errbuf,
5287 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005288
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005289 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005290 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005291
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005292#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005293 if (errmsg == NULL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02005294 trigger_optionsset_string(
5295 opt_idx, opt_flags, saved_origval,
5296 saved_origval_l, saved_origval_g,
5297 saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005298 vim_free(saved_origval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005299 vim_free(saved_origval_l);
5300 vim_free(saved_origval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005301 vim_free(saved_newval);
5302#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005303 /* If error detected, print the error message. */
5304 if (errmsg != NULL)
5305 goto skip;
5306 }
5307 else /* key code option */
5308 {
5309 char_u *p;
5310
5311 if (nextchar == '&')
5312 {
5313 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005314 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005315 }
5316 else
5317 {
5318 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005319 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005320 if (*p == '\\' && p[1] != NUL)
5321 ++p;
5322 nextchar = *p;
5323 *p = NUL;
5324 add_termcode(key_name, arg, FALSE);
5325 *p = nextchar;
5326 }
5327 if (full_screen)
5328 ttest(FALSE);
5329 redraw_all_later(CLEAR);
5330 }
5331 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005332
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005334 did_set_option(
5335 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005336 }
5337
5338skip:
5339 /*
5340 * Advance to next argument.
5341 * - skip until a blank found, taking care of backslashes
5342 * - skip blanks
5343 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5344 */
5345 for (i = 0; i < 2 ; ++i)
5346 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005347 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005348 if (*arg++ == '\\' && *arg != NUL)
5349 ++arg;
5350 arg = skipwhite(arg);
5351 if (*arg != '=')
5352 break;
5353 }
5354 }
5355
5356 if (errmsg != NULL)
5357 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005358 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005359 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005360 if (i + (arg - startarg) < IOSIZE)
5361 {
5362 /* append the argument with the error */
5363 STRCAT(IObuff, ": ");
5364 mch_memmove(IObuff + i, startarg, (arg - startarg));
5365 IObuff[i + (arg - startarg)] = NUL;
5366 }
5367 /* make sure all characters are printable */
5368 trans_characters(IObuff, IOSIZE);
5369
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005370 ++no_wait_return; // wait_return done later
5371 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005372 --no_wait_return;
5373
5374 return FAIL;
5375 }
5376
5377 arg = skipwhite(arg);
5378 }
5379
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005380theend:
5381 if (silent_mode && did_show)
5382 {
5383 /* After displaying option values in silent mode. */
5384 silent_mode = FALSE;
5385 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5386 msg_putchar('\n');
5387 cursor_on(); /* msg_start() switches it off */
5388 out_flush();
5389 silent_mode = TRUE;
5390 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5391 }
5392
Bram Moolenaar071d4272004-06-13 20:20:40 +00005393 return OK;
5394}
5395
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005396/*
5397 * Call this when an option has been given a new value through a user command.
5398 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5399 */
5400 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005401did_set_option(
5402 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005403 int opt_flags, // possibly with OPT_MODELINE
5404 int new_value, // value was replaced completely
5405 int value_checked) // value was checked to be safe, no need to set the
5406 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005407{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005408 long_u *p;
5409
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005410 options[opt_idx].flags |= P_WAS_SET;
5411
5412 /* When an option is set in the sandbox, from a modeline or in secure mode
5413 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005414 * flag. */
5415 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005416 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005417#ifdef HAVE_SANDBOX
5418 || sandbox != 0
5419#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005420 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005421 *p = *p | P_INSECURE;
5422 else if (new_value)
5423 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005424}
5425
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005426 static char *
5427illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005428{
5429 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005430 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005431 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005432 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433 return errbuf;
5434}
5435
5436/*
5437 * Convert a key name or string into a key value.
5438 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005439 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005440 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005441 int
5442string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005443{
5444 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005445 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446 if (*arg == '^')
5447 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005448 if (multi_byte)
5449 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005450 return *arg;
5451}
5452
5453#ifdef FEAT_CMDWIN
5454/*
5455 * Check value of 'cedit' and set cedit_key.
5456 * Returns NULL if value is OK, error message otherwise.
5457 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005458 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005459check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005460{
5461 int n;
5462
5463 if (*p_cedit == NUL)
5464 cedit_key = -1;
5465 else
5466 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005467 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005468 if (vim_isprintc(n))
5469 return e_invarg;
5470 cedit_key = n;
5471 }
5472 return NULL;
5473}
5474#endif
5475
5476#ifdef FEAT_TITLE
5477/*
5478 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5479 * maketitle() to create and display it.
5480 * When switching the title or icon off, call mch_restore_title() to get
5481 * the old value back.
5482 */
5483 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005484did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005485{
5486 if (starting != NO_SCREEN
5487#ifdef FEAT_GUI
5488 && !gui.starting
5489#endif
5490 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005491 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005492}
5493#endif
5494
5495/*
5496 * set_options_bin - called when 'bin' changes value.
5497 */
5498 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005499set_options_bin(
5500 int oldval,
5501 int newval,
5502 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005503{
5504 /*
5505 * The option values that are changed when 'bin' changes are
5506 * copied when 'bin is set and restored when 'bin' is reset.
5507 */
5508 if (newval)
5509 {
5510 if (!oldval) /* switched on */
5511 {
5512 if (!(opt_flags & OPT_GLOBAL))
5513 {
5514 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5515 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5516 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5517 curbuf->b_p_et_nobin = curbuf->b_p_et;
5518 }
5519 if (!(opt_flags & OPT_LOCAL))
5520 {
5521 p_tw_nobin = p_tw;
5522 p_wm_nobin = p_wm;
5523 p_ml_nobin = p_ml;
5524 p_et_nobin = p_et;
5525 }
5526 }
5527
5528 if (!(opt_flags & OPT_GLOBAL))
5529 {
5530 curbuf->b_p_tw = 0; /* no automatic line wrap */
5531 curbuf->b_p_wm = 0; /* no automatic line wrap */
5532 curbuf->b_p_ml = 0; /* no modelines */
5533 curbuf->b_p_et = 0; /* no expandtab */
5534 }
5535 if (!(opt_flags & OPT_LOCAL))
5536 {
5537 p_tw = 0;
5538 p_wm = 0;
5539 p_ml = FALSE;
5540 p_et = FALSE;
5541 p_bin = TRUE; /* needed when called for the "-b" argument */
5542 }
5543 }
5544 else if (oldval) /* switched off */
5545 {
5546 if (!(opt_flags & OPT_GLOBAL))
5547 {
5548 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5549 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5550 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5551 curbuf->b_p_et = curbuf->b_p_et_nobin;
5552 }
5553 if (!(opt_flags & OPT_LOCAL))
5554 {
5555 p_tw = p_tw_nobin;
5556 p_wm = p_wm_nobin;
5557 p_ml = p_ml_nobin;
5558 p_et = p_et_nobin;
5559 }
5560 }
5561}
5562
Bram Moolenaar071d4272004-06-13 20:20:40 +00005563/*
5564 * Expand environment variables for some string options.
5565 * These string options cannot be indirect!
5566 * If "val" is NULL expand the current value of the option.
5567 * Return pointer to NameBuff, or NULL when not expanded.
5568 */
5569 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005570option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005571{
5572 /* if option doesn't need expansion nothing to do */
5573 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5574 return NULL;
5575
5576 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5577 * expand_env() would truncate the string. */
5578 if (val != NULL && STRLEN(val) > MAXPATHL)
5579 return NULL;
5580
5581 if (val == NULL)
5582 val = *(char_u **)options[opt_idx].var;
5583
5584 /*
5585 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5586 * Escape spaces when expanding 'tags', they are used to separate file
5587 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005588 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589 */
5590 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005591 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005592#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005593 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5594#endif
5595 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005596 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5597 return NULL;
5598
5599 return NameBuff;
5600}
5601
5602/*
5603 * After setting various option values: recompute variables that depend on
5604 * option values.
5605 */
5606 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005607didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005608{
5609 /* initialize the table for 'iskeyword' et.al. */
5610 (void)init_chartab();
5611
5612 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5613 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005614 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005615#ifdef FEAT_SESSION
5616 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5617 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5618#endif
5619#ifdef FEAT_FOLDING
5620 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5621#endif
5622 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005623 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005624 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005625#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5626 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5627#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005628#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005629 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005630 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005631 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005632 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005633#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005634#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005635 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5636#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005637#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005638 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5639#endif
5640#ifdef FEAT_CMDWIN
5641 /* set cedit_key */
5642 (void)check_cedit();
5643#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005644#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005645 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005646#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005647#ifdef FEAT_LINEBREAK
5648 /* initialize the table for 'breakat'. */
5649 fill_breakat_flags();
5650#endif
5651
5652}
5653
5654/*
5655 * More side effects of setting options.
5656 */
5657 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005658didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005659{
5660 /* Initialize the highlight_attr[] table. */
5661 (void)highlight_changed();
5662
5663 /* Parse default for 'wildmode' */
5664 check_opt_wim();
5665
5666 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005667 /* Parse default for 'fillchars'. */
5668 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005669
5670#ifdef FEAT_CLIPBOARD
5671 /* Parse default for 'clipboard' */
5672 (void)check_clipboard_option();
5673#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005674#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005675 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005676 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005677 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005678 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5679#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680}
5681
5682/*
5683 * Check for string options that are NULL (normally only termcap options).
5684 */
5685 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005686check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005687{
5688 int opt_idx;
5689
5690 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5691 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5692 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5693}
5694
5695/*
5696 * Check string options in a buffer for NULL value.
5697 */
5698 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005699check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005700{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005701 check_string_option(&buf->b_p_bh);
5702 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005703 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704 check_string_option(&buf->b_p_ff);
5705#ifdef FEAT_FIND_ID
5706 check_string_option(&buf->b_p_def);
5707 check_string_option(&buf->b_p_inc);
5708# ifdef FEAT_EVAL
5709 check_string_option(&buf->b_p_inex);
5710# endif
5711#endif
5712#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5713 check_string_option(&buf->b_p_inde);
5714 check_string_option(&buf->b_p_indk);
5715#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005716#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5717 check_string_option(&buf->b_p_bexpr);
5718#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005719#if defined(FEAT_CRYPT)
5720 check_string_option(&buf->b_p_cm);
5721#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005722 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005723#if defined(FEAT_EVAL)
5724 check_string_option(&buf->b_p_fex);
5725#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726#ifdef FEAT_CRYPT
5727 check_string_option(&buf->b_p_key);
5728#endif
5729 check_string_option(&buf->b_p_kp);
5730 check_string_option(&buf->b_p_mps);
5731 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005732 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005733 check_string_option(&buf->b_p_isk);
5734#ifdef FEAT_COMMENTS
5735 check_string_option(&buf->b_p_com);
5736#endif
5737#ifdef FEAT_FOLDING
5738 check_string_option(&buf->b_p_cms);
5739#endif
5740 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005741#ifdef FEAT_TEXTOBJ
5742 check_string_option(&buf->b_p_qe);
5743#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005744#ifdef FEAT_SYN_HL
5745 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005746 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005747#endif
5748#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005749 check_string_option(&buf->b_s.b_p_spc);
5750 check_string_option(&buf->b_s.b_p_spf);
5751 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005752#endif
5753#ifdef FEAT_SEARCHPATH
5754 check_string_option(&buf->b_p_sua);
5755#endif
5756#ifdef FEAT_CINDENT
5757 check_string_option(&buf->b_p_cink);
5758 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005759 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005761 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005762#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5763 check_string_option(&buf->b_p_cinw);
5764#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765 check_string_option(&buf->b_p_cpt);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005766#ifdef FEAT_COMPL_FUNC
5767 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005768 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005769#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005770#ifdef FEAT_EVAL
5771 check_string_option(&buf->b_p_tfu);
5772#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005773#ifdef FEAT_KEYMAP
5774 check_string_option(&buf->b_p_keymap);
5775#endif
5776#ifdef FEAT_QUICKFIX
5777 check_string_option(&buf->b_p_gp);
5778 check_string_option(&buf->b_p_mp);
5779 check_string_option(&buf->b_p_efm);
5780#endif
5781 check_string_option(&buf->b_p_ep);
5782 check_string_option(&buf->b_p_path);
5783 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005784 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005785 check_string_option(&buf->b_p_dict);
5786 check_string_option(&buf->b_p_tsr);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005787#ifdef FEAT_LISP
5788 check_string_option(&buf->b_p_lw);
5789#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005790 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005791 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005792#ifdef FEAT_VARTABS
5793 check_string_option(&buf->b_p_vsts);
5794 check_string_option(&buf->b_p_vts);
5795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005796}
5797
5798/*
5799 * Free the string allocated for an option.
5800 * Checks for the string being empty_option. This may happen if we're out of
5801 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5802 * check_options().
5803 * Does NOT check for P_ALLOCED flag!
5804 */
5805 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005806free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005807{
5808 if (p != empty_option)
5809 vim_free(p);
5810}
5811
5812 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005813clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005814{
5815 if (*pp != empty_option)
5816 vim_free(*pp);
5817 *pp = empty_option;
5818}
5819
5820 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005821check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005822{
5823 if (*pp == NULL)
5824 *pp = empty_option;
5825}
5826
5827/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005828 * Return the option index found by a pointer into term_strings[].
5829 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005830 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005831 int
5832get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005833{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005834 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005835
5836 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5837 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005838 return opt_idx;
5839 return -1; // cannot happen: didn't find it!
5840}
5841
5842/*
5843 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5844 * Return the option index or -1 if not found.
5845 */
5846 int
5847set_term_option_alloced(char_u **p)
5848{
5849 int opt_idx = get_term_opt_idx(p);
5850
5851 if (opt_idx >= 0)
5852 options[opt_idx].flags |= P_ALLOCED;
5853 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005854}
5855
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005856#if defined(FEAT_EVAL) || defined(PROTO)
5857/*
5858 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5859 * Return FALSE when it wasn't.
5860 * Return -1 for an unknown option.
5861 */
5862 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005863was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005864{
5865 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005866 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005867
5868 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005869 {
5870 flagp = insecure_flag(idx, opt_flags);
5871 return (*flagp & P_INSECURE) != 0;
5872 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005873 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005874 return -1;
5875}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005876
5877/*
5878 * Get a pointer to the flags used for the P_INSECURE flag of option
5879 * "opt_idx". For some local options a local flags field is used.
5880 */
5881 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005882insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005883{
5884 if (opt_flags & OPT_LOCAL)
5885 switch ((int)options[opt_idx].indir)
5886 {
5887#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005888 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005889#endif
5890#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005891# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005892 case PV_FDE: return &curwin->w_p_fde_flags;
5893 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005894# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005895# ifdef FEAT_BEVAL
5896 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5897# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005898# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005899 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005900# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005901 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005902# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005903 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005904# endif
5905#endif
5906 }
5907
5908 /* Nothing special, return global flags field. */
5909 return &options[opt_idx].flags;
5910}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005911#endif
5912
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005913#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005914/*
5915 * Redraw the window title and/or tab page text later.
5916 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005917static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005918{
5919 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005920 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005921}
5922#endif
5923
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924/*
5925 * Set a string option to a new value (without checking the effect).
5926 * The string is copied into allocated memory.
5927 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005928 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5929 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5930 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005931 */
5932 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005933set_string_option_direct(
5934 char_u *name,
5935 int opt_idx,
5936 char_u *val,
5937 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5938 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005939{
5940 char_u *s;
5941 char_u **varp;
5942 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005943 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005944
Bram Moolenaar89d40322006-08-29 15:30:07 +00005945 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005946 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005947 idx = findoption(name);
5948 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005949 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005950 semsg(_(e_intern2), "set_string_option_direct()");
5951 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005952 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005953 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005954 }
5955
Bram Moolenaar89d40322006-08-29 15:30:07 +00005956 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005957 return;
5958
5959 s = vim_strsave(val);
5960 if (s != NULL)
5961 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005962 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005963 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005964 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005965 free_string_option(*varp);
5966 *varp = s;
5967
5968 /* For buffer/window local option may also set the global value. */
5969 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005970 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005971
Bram Moolenaar89d40322006-08-29 15:30:07 +00005972 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005973
5974 /* When setting both values of a global option with a local value,
5975 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005976 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977 {
5978 free_string_option(*varp);
5979 *varp = empty_option;
5980 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005981# ifdef FEAT_EVAL
5982 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005983 {
5984 sctx_T script_ctx;
5985
5986 if (set_sid == 0)
5987 script_ctx = current_sctx;
5988 else
5989 {
5990 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005991 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005992 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005993 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005994 }
5995 set_option_sctx_idx(idx, opt_flags, script_ctx);
5996 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005997# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005998 }
5999}
6000
6001/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02006002 * Like set_string_option_direct(), but for a window-local option in "wp".
6003 * Blocks autocommands to avoid the old curwin becoming invalid.
6004 */
6005 void
6006set_string_option_direct_in_win(
6007 win_T *wp,
6008 char_u *name,
6009 int opt_idx,
6010 char_u *val,
6011 int opt_flags,
6012 int set_sid)
6013{
6014 win_T *save_curwin = curwin;
6015
6016 block_autocmds();
6017 curwin = wp;
6018 curbuf = curwin->w_buffer;
6019 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6020 curwin = save_curwin;
6021 curbuf = curwin->w_buffer;
6022 unblock_autocmds();
6023}
6024
6025/*
6026 * Like set_string_option_direct(), but for a buffer-local option in "buf".
6027 * Blocks autocommands to avoid the old curbuf becoming invalid.
6028 */
6029 void
6030set_string_option_direct_in_buf(
6031 buf_T *buf,
6032 char_u *name,
6033 int opt_idx,
6034 char_u *val,
6035 int opt_flags,
6036 int set_sid)
6037{
6038 buf_T *save_curbuf = curbuf;
6039
6040 block_autocmds();
6041 curbuf = buf;
6042 curwin->w_buffer = curbuf;
6043 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6044 curbuf = save_curbuf;
6045 curwin->w_buffer = curbuf;
6046 unblock_autocmds();
6047}
6048
6049/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006050 * Set global value for string option when it's a local option.
6051 */
6052 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006053set_string_option_global(
6054 int opt_idx, /* option index */
6055 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006056{
6057 char_u **p, *s;
6058
6059 /* the global value is always allocated */
6060 if (options[opt_idx].var == VAR_WIN)
6061 p = (char_u **)GLOBAL_WO(varp);
6062 else
6063 p = (char_u **)options[opt_idx].var;
6064 if (options[opt_idx].indir != PV_NONE
6065 && p != varp
6066 && (s = vim_strsave(*varp)) != NULL)
6067 {
6068 free_string_option(*p);
6069 *p = s;
6070 }
6071}
6072
6073/*
6074 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006075 *
6076 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006077 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006078 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006079set_string_option(
6080 int opt_idx,
6081 char_u *value,
6082 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006083{
6084 char_u *s;
6085 char_u **varp;
6086 char_u *oldval;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006087#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006088 char_u *oldval_l = NULL;
6089 char_u *oldval_g = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006090 char_u *saved_oldval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02006091 char_u *saved_oldval_l = NULL;
6092 char_u *saved_oldval_g = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006093 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006094#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006095 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006096 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006097
6098 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006099 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006100
6101 s = vim_strsave(value);
6102 if (s != NULL)
6103 {
6104 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6105 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006106 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006107 ? OPT_GLOBAL : OPT_LOCAL)
6108 : opt_flags);
6109 oldval = *varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006110#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006111 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6112 {
6113 oldval_l = *(char_u **)get_varp_scope(&(options[opt_idx]),
6114 OPT_LOCAL);
6115 oldval_g = *(char_u **)get_varp_scope(&(options[opt_idx]),
6116 OPT_GLOBAL);
6117 }
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006118#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006119 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006120
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006121#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006122 if (!starting
6123# ifdef FEAT_CRYPT
6124 && options[opt_idx].indir != PV_KEY
6125# endif
6126 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006127 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02006128 if (oldval_l != NULL)
6129 saved_oldval_l = vim_strsave(oldval_l);
6130 if (oldval_g != NULL)
6131 saved_oldval_g = vim_strsave(oldval_g);
Bram Moolenaar53744302015-07-17 17:38:22 +02006132 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006133 saved_newval = vim_strsave(s);
6134 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006135#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006136 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006137 opt_flags, &value_checked)) == NULL)
6138 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006139
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006140#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006141 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006142 if (r == NULL)
6143 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02006144 saved_oldval, saved_oldval_l,
6145 saved_oldval_g, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006146 vim_free(saved_oldval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02006147 vim_free(saved_oldval_l);
6148 vim_free(saved_oldval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006149 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006150#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006151 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006152 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006153}
6154
6155/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006156 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6157 * characters or characters in "allowed".
6158 */
6159 static int
6160valid_name(char_u *val, char *allowed)
6161{
6162 char_u *s;
6163
6164 for (s = val; *s != NUL; ++s)
6165 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6166 return FALSE;
6167 return TRUE;
6168}
6169
6170/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006171 * Return TRUE if "val" is a valid 'filetype' name.
6172 * Also used for 'syntax' and 'keymap'.
6173 */
6174 static int
6175valid_filetype(char_u *val)
6176{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006177 return valid_name(val, ".-_");
6178}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006179
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006180#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006181/*
6182 * Return TRUE if "val" is a valid 'spellang' value.
6183 */
6184 int
6185valid_spellang(char_u *val)
6186{
Bram Moolenaar9a061cb2019-05-05 16:55:03 +02006187 return valid_name(val, ".-_,@");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006188}
6189
6190/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006191 * Return TRUE if "val" is a valid 'spellfile' value.
6192 */
6193 static int
6194valid_spellfile(char_u *val)
6195{
6196 char_u *s;
6197
6198 for (s = val; *s != NUL; ++s)
6199 if (!vim_isfilec(*s) && *s != ',')
6200 return FALSE;
6201 return TRUE;
6202}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006203#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006204
6205/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006206 * Handle string options that need some action to perform when changed.
6207 * Returns NULL for success, or an error message for an error.
6208 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006209 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006210did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006211 int opt_idx, // index in options[] table
6212 char_u **varp, // pointer to the option variable
6213 int new_value_alloced, // new value was allocated
6214 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006215 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006216 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6217 int *value_checked) // value was checked to be save, no
6218 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006219{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006220 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006221 char_u *s, *p;
6222 int did_chartab = FALSE;
6223 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006224 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006225#ifdef FEAT_GUI
6226 /* set when changing an option that only requires a redraw in the GUI */
6227 int redraw_gui_only = FALSE;
6228#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006229 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006230#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6231 int did_swaptcap = FALSE;
6232#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006233
6234 /* Get the global option to compare with, otherwise we would have to check
6235 * two values for all local options. */
6236 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6237
6238 /* Disallow changing some options from secure mode */
6239 if ((secure
6240#ifdef HAVE_SANDBOX
6241 || sandbox != 0
6242#endif
6243 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006244 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006245
Bram Moolenaar916a8182018-11-25 02:18:29 +01006246 // Check for a "normal" directory or file name in some options. Disallow a
6247 // path separator (slash and/or backslash), wildcards and characters that
6248 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006249 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006250 && vim_strpbrk(*varp, (char_u *)(secure
6251 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006252 || ((options[opt_idx].flags & P_NDNAME)
6253 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006254 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006255
Bram Moolenaar071d4272004-06-13 20:20:40 +00006256 /* 'term' */
6257 else if (varp == &T_NAME)
6258 {
6259 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006260 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006261#ifdef FEAT_GUI
6262 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006263 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006264 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006265 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266#endif
6267 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006268 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006269 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006270 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006271 /* Screen colors may have changed. */
6272 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006273
6274 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6275 * P_ALLOCED flag on 'term'. */
6276 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006277 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006278 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006279 }
6280
6281 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006282 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006283 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006284 char_u *bkc = p_bkc;
6285 unsigned int *flags = &bkc_flags;
6286
6287 if (opt_flags & OPT_LOCAL)
6288 {
6289 bkc = curbuf->b_p_bkc;
6290 flags = &curbuf->b_bkc_flags;
6291 }
6292
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006293 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6294 /* make the local value empty: use the global value */
6295 *flags = 0;
6296 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006297 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006298 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6299 errmsg = e_invarg;
6300 if ((((int)*flags & BKC_AUTO) != 0)
6301 + (((int)*flags & BKC_YES) != 0)
6302 + (((int)*flags & BKC_NO) != 0) != 1)
6303 {
6304 /* Must have exactly one of "auto", "yes" and "no". */
6305 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6306 errmsg = e_invarg;
6307 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006308 }
6309 }
6310
6311 /* 'backupext' and 'patchmode' */
6312 else if (varp == &p_bex || varp == &p_pm)
6313 {
6314 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6315 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006316 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006317 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006318#ifdef FEAT_LINEBREAK
6319 /* 'breakindentopt' */
6320 else if (varp == &curwin->w_p_briopt)
6321 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006322 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006323 errmsg = e_invarg;
6324 }
6325#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006326
6327 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006328 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006329 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006330 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331 */
6332 else if ( varp == &p_isi
6333 || varp == &(curbuf->b_p_isk)
6334 || varp == &p_isp
6335 || varp == &p_isf)
6336 {
6337 if (init_chartab() == FAIL)
6338 {
6339 did_chartab = TRUE; /* need to restore it below */
6340 errmsg = e_invarg; /* error in value */
6341 }
6342 }
6343
6344 /* 'helpfile' */
6345 else if (varp == &p_hf)
6346 {
6347 /* May compute new values for $VIM and $VIMRUNTIME */
6348 if (didset_vim)
6349 {
6350 vim_setenv((char_u *)"VIM", (char_u *)"");
6351 didset_vim = FALSE;
6352 }
6353 if (didset_vimruntime)
6354 {
6355 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6356 didset_vimruntime = FALSE;
6357 }
6358 }
6359
Bram Moolenaar1a384422010-07-14 19:53:30 +02006360#ifdef FEAT_SYN_HL
6361 /* 'colorcolumn' */
6362 else if (varp == &curwin->w_p_cc)
6363 errmsg = check_colorcolumn(curwin);
6364#endif
6365
Bram Moolenaar071d4272004-06-13 20:20:40 +00006366#ifdef FEAT_MULTI_LANG
6367 /* 'helplang' */
6368 else if (varp == &p_hlg)
6369 {
6370 /* Check for "", "ab", "ab,cd", etc. */
6371 for (s = p_hlg; *s != NUL; s += 3)
6372 {
6373 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6374 {
6375 errmsg = e_invarg;
6376 break;
6377 }
6378 if (s[2] == NUL)
6379 break;
6380 }
6381 }
6382#endif
6383
6384 /* 'highlight' */
6385 else if (varp == &p_hl)
6386 {
6387 if (highlight_changed() == FAIL)
6388 errmsg = e_invarg; /* invalid flags */
6389 }
6390
6391 /* 'nrformats' */
6392 else if (gvarp == &p_nf)
6393 {
6394 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6395 errmsg = e_invarg;
6396 }
6397
6398#ifdef FEAT_SESSION
6399 /* 'sessionoptions' */
6400 else if (varp == &p_ssop)
6401 {
6402 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6403 errmsg = e_invarg;
6404 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6405 {
6406 /* Don't allow both "sesdir" and "curdir". */
6407 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6408 errmsg = e_invarg;
6409 }
6410 }
6411 /* 'viewoptions' */
6412 else if (varp == &p_vop)
6413 {
6414 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6415 errmsg = e_invarg;
6416 }
6417#endif
6418
6419 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006420 else if (varp == &p_sbo)
6421 {
6422 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6423 errmsg = e_invarg;
6424 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006425
6426 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006427 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006428 {
6429 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6430 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006431 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006432 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006433 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006434 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006435 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006436
6437 /* 'background' */
6438 else if (varp == &p_bg)
6439 {
6440 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6441 {
6442#ifdef FEAT_EVAL
6443 int dark = (*p_bg == 'd');
6444#endif
6445
6446 init_highlight(FALSE, FALSE);
6447
6448#ifdef FEAT_EVAL
6449 if (dark != (*p_bg == 'd')
6450 && get_var_value((char_u *)"g:colors_name") != NULL)
6451 {
6452 /* The color scheme must have set 'background' back to another
6453 * value, that's not what we want here. Disable the color
6454 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006455 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006456 free_string_option(p_bg);
6457 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6458 check_string_option(&p_bg);
6459 init_highlight(FALSE, FALSE);
6460 }
6461#endif
6462 }
6463 else
6464 errmsg = e_invarg;
6465 }
6466
6467 /* 'wildmode' */
6468 else if (varp == &p_wim)
6469 {
6470 if (check_opt_wim() == FAIL)
6471 errmsg = e_invarg;
6472 }
6473
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006474 /* 'wildoptions' */
6475 else if (varp == &p_wop)
6476 {
6477 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6478 errmsg = e_invarg;
6479 }
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006480
Bram Moolenaar071d4272004-06-13 20:20:40 +00006481#ifdef FEAT_WAK
6482 /* 'winaltkeys' */
6483 else if (varp == &p_wak)
6484 {
6485 if (*p_wak == NUL
6486 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6487 errmsg = e_invarg;
6488# ifdef FEAT_MENU
6489# ifdef FEAT_GUI_MOTIF
6490 else if (gui.in_use)
6491 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6492# else
6493# ifdef FEAT_GUI_GTK
6494 else if (gui.in_use)
6495 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6496# endif
6497# endif
6498# endif
6499 }
6500#endif
6501
Bram Moolenaar071d4272004-06-13 20:20:40 +00006502 /* 'eventignore' */
6503 else if (varp == &p_ei)
6504 {
6505 if (check_ei() == FAIL)
6506 errmsg = e_invarg;
6507 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006508
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006509 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6510 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6511 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006512 {
6513 if (gvarp == &p_fenc)
6514 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006515 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006516 errmsg = e_modifiable;
6517 else if (vim_strchr(*varp, ',') != NULL)
6518 /* No comma allowed in 'fileencoding'; catches confusing it
6519 * with 'fileencodings'. */
6520 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006521 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006522 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006523#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006524 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006525 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006526#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006527 /* Add 'fileencoding' to the swap file. */
6528 ml_setflags(curbuf);
6529 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006530 }
6531 if (errmsg == NULL)
6532 {
6533 /* canonize the value, so that STRCMP() can be used on it */
6534 p = enc_canonize(*varp);
6535 if (p != NULL)
6536 {
6537 vim_free(*varp);
6538 *varp = p;
6539 }
6540 if (varp == &p_enc)
6541 {
6542 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006543#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006544 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006545#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006546 }
6547 }
6548
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006549#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006550 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6551 {
6552 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6553 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006554 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006555 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006556#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006557
6558 if (errmsg == NULL)
6559 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006560#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006561 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6562 * (with another encoding). */
6563 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6564 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006565#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006566
6567 /* When 'termencoding' is not empty and 'encoding' changes or when
6568 * 'termencoding' changes, need to setup for keyboard input and
6569 * display output conversion. */
6570 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6571 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006572 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6573 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6574 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006575 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006576 p_tenc, p_enc);
6577 errmsg = e_invarg;
6578 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006579 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006580
Bram Moolenaar4f974752019-02-17 17:44:42 +01006581#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006582 /* $HOME may have characters in active code page. */
6583 if (varp == &p_enc)
6584 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006585#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006586 }
6587 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006588
6589#if defined(FEAT_POSTSCRIPT)
6590 else if (varp == &p_penc)
6591 {
6592 /* Canonize printencoding if VIM standard one */
6593 p = enc_canonize(p_penc);
6594 if (p != NULL)
6595 {
6596 vim_free(p_penc);
6597 p_penc = p;
6598 }
6599 else
6600 {
6601 /* Ensure lower case and '-' for '_' */
6602 for (s = p_penc; *s != NUL; s++)
6603 {
6604 if (*s == '_')
6605 *s = '-';
6606 else
6607 *s = TOLOWER_ASC(*s);
6608 }
6609 }
6610 }
6611#endif
6612
Bram Moolenaar9372a112005-12-06 19:59:18 +00006613#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006614 else if (varp == &p_imak)
6615 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006616 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006617 errmsg = e_invarg;
6618 }
6619#endif
6620
6621#ifdef FEAT_KEYMAP
6622 else if (varp == &curbuf->b_p_keymap)
6623 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006624 if (!valid_filetype(*varp))
6625 errmsg = e_invarg;
6626 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006627 {
6628 int secure_save = secure;
6629
6630 // Reset the secure flag, since the value of 'keymap' has
6631 // been checked to be safe.
6632 secure = 0;
6633
6634 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006635 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006636
Bram Moolenaar916a8182018-11-25 02:18:29 +01006637 secure = secure_save;
6638
6639 // Since we check the value, there is no need to set P_INSECURE,
6640 // even when the value comes from a modeline.
6641 *value_checked = TRUE;
6642 }
6643
Bram Moolenaarfab06232009-03-04 03:13:35 +00006644 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006645 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006646 if (*curbuf->b_p_keymap != NUL)
6647 {
6648 /* Installed a new keymap, switch on using it. */
6649 curbuf->b_p_iminsert = B_IMODE_LMAP;
6650 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6651 curbuf->b_p_imsearch = B_IMODE_LMAP;
6652 }
6653 else
6654 {
6655 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6656 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6657 curbuf->b_p_iminsert = B_IMODE_NONE;
6658 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6659 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6660 }
6661 if ((opt_flags & OPT_LOCAL) == 0)
6662 {
6663 set_iminsert_global();
6664 set_imsearch_global();
6665 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006666 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006667 }
6668 }
6669#endif
6670
6671 /* 'fileformat' */
6672 else if (gvarp == &p_ff)
6673 {
6674 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6675 errmsg = e_modifiable;
6676 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6677 errmsg = e_invarg;
6678 else
6679 {
6680 /* may also change 'textmode' */
6681 if (get_fileformat(curbuf) == EOL_DOS)
6682 curbuf->b_p_tx = TRUE;
6683 else
6684 curbuf->b_p_tx = FALSE;
6685#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006686 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006687#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006688 /* update flag in swap file */
6689 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006690 /* Redraw needed when switching to/from "mac": a CR in the text
6691 * will be displayed differently. */
6692 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6693 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006694 }
6695 }
6696
6697 /* 'fileformats' */
6698 else if (varp == &p_ffs)
6699 {
6700 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6701 errmsg = e_invarg;
6702 else
6703 {
6704 /* also change 'textauto' */
6705 if (*p_ffs == NUL)
6706 p_ta = FALSE;
6707 else
6708 p_ta = TRUE;
6709 }
6710 }
6711
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006712#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006713 /* 'cryptkey' */
6714 else if (gvarp == &p_key)
6715 {
Bram Moolenaard7663c22019-08-06 21:59:57 +02006716 // Make sure the ":set" command doesn't show the new value in the
6717 // history.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006718 remove_key_from_history();
Bram Moolenaard7663c22019-08-06 21:59:57 +02006719
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006720 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6721 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006722 ml_set_crypt_key(curbuf, oldval,
6723 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006724 }
6725
6726 else if (gvarp == &p_cm)
6727 {
6728 if (opt_flags & OPT_LOCAL)
6729 p = curbuf->b_p_cm;
6730 else
6731 p = p_cm;
6732 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6733 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006734 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006735 errmsg = e_invarg;
6736 else
6737 {
6738 /* When setting the global value to empty, make it "zip". */
6739 if (*p_cm == NUL)
6740 {
6741 if (new_value_alloced)
6742 free_string_option(p_cm);
6743 p_cm = vim_strsave((char_u *)"zip");
6744 new_value_alloced = TRUE;
6745 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006746 /* When using ":set cm=name" the local value is going to be empty.
6747 * Do that here, otherwise the crypt functions will still use the
6748 * local value. */
6749 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6750 {
6751 free_string_option(curbuf->b_p_cm);
6752 curbuf->b_p_cm = empty_option;
6753 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006754
6755 /* Need to update the swapfile when the effective method changed.
6756 * Set "s" to the effective old value, "p" to the effective new
6757 * method and compare. */
6758 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6759 s = p_cm; /* was previously using the global value */
6760 else
6761 s = oldval;
6762 if (*curbuf->b_p_cm == NUL)
6763 p = p_cm; /* is now using the global value */
6764 else
6765 p = curbuf->b_p_cm;
6766 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006767 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006768
6769 /* If the global value changes need to update the swapfile for all
6770 * buffers using that value. */
6771 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6772 {
6773 buf_T *buf;
6774
Bram Moolenaar29323592016-07-24 22:04:11 +02006775 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006776 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006777 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006778 }
6779 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006780 }
6781#endif
6782
6783 /* 'matchpairs' */
6784 else if (gvarp == &p_mps)
6785 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006786 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006787 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006788 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006789 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006790 int x2 = -1;
6791 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006792
6793 if (*p != NUL)
6794 p += mb_ptr2len(p);
6795 if (*p != NUL)
6796 x2 = *p++;
6797 if (*p != NUL)
6798 {
6799 x3 = mb_ptr2char(p);
6800 p += mb_ptr2len(p);
6801 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006802 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006803 {
6804 errmsg = e_invarg;
6805 break;
6806 }
6807 if (*p == NUL)
6808 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006809 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006810 }
6811 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006812 {
6813 /* Check for "x:y,x:y" */
6814 for (p = *varp; *p != NUL; p += 4)
6815 {
6816 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6817 {
6818 errmsg = e_invarg;
6819 break;
6820 }
6821 if (p[3] == NUL)
6822 break;
6823 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006824 }
6825 }
6826
6827#ifdef FEAT_COMMENTS
6828 /* 'comments' */
6829 else if (gvarp == &p_com)
6830 {
6831 for (s = *varp; *s; )
6832 {
6833 while (*s && *s != ':')
6834 {
6835 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6836 && !VIM_ISDIGIT(*s) && *s != '-')
6837 {
6838 errmsg = illegal_char(errbuf, *s);
6839 break;
6840 }
6841 ++s;
6842 }
6843 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006844 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006845 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006846 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006847 if (errmsg != NULL)
6848 break;
6849 while (*s && *s != ',')
6850 {
6851 if (*s == '\\' && s[1] != NUL)
6852 ++s;
6853 ++s;
6854 }
6855 s = skip_to_option_part(s);
6856 }
6857 }
6858#endif
6859
6860 /* 'listchars' */
6861 else if (varp == &p_lcs)
6862 {
6863 errmsg = set_chars_option(varp);
6864 }
6865
Bram Moolenaar071d4272004-06-13 20:20:40 +00006866 /* 'fillchars' */
6867 else if (varp == &p_fcs)
6868 {
6869 errmsg = set_chars_option(varp);
6870 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006871
6872#ifdef FEAT_CMDWIN
6873 /* 'cedit' */
6874 else if (varp == &p_cedit)
6875 {
6876 errmsg = check_cedit();
6877 }
6878#endif
6879
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006880 /* 'verbosefile' */
6881 else if (varp == &p_vfile)
6882 {
6883 verbose_stop();
6884 if (*p_vfile != NUL && verbose_open() == FAIL)
6885 errmsg = e_invarg;
6886 }
6887
Bram Moolenaar071d4272004-06-13 20:20:40 +00006888#ifdef FEAT_VIMINFO
6889 /* 'viminfo' */
6890 else if (varp == &p_viminfo)
6891 {
6892 for (s = p_viminfo; *s;)
6893 {
6894 /* Check it's a valid character */
6895 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6896 {
6897 errmsg = illegal_char(errbuf, *s);
6898 break;
6899 }
6900 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006901 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006902 else if (*s == 'r') /* skip until next ',' */
6903 {
6904 while (*++s && *s != ',')
6905 ;
6906 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006907 else if (*s == '%')
6908 {
6909 /* optional number */
6910 while (vim_isdigit(*++s))
6911 ;
6912 }
6913 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006914 ++s; /* no extra chars */
6915 else /* must have a number */
6916 {
6917 while (vim_isdigit(*++s))
6918 ;
6919
6920 if (!VIM_ISDIGIT(*(s - 1)))
6921 {
6922 if (errbuf != NULL)
6923 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006924 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006925 transchar_byte(*(s - 1)));
6926 errmsg = errbuf;
6927 }
6928 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006929 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006930 break;
6931 }
6932 }
6933 if (*s == ',')
6934 ++s;
6935 else if (*s)
6936 {
6937 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006938 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006939 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006940 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006941 break;
6942 }
6943 }
6944 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006945 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 }
6947#endif /* FEAT_VIMINFO */
6948
6949 /* terminal options */
6950 else if (istermoption(&options[opt_idx]) && full_screen)
6951 {
6952 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6953 if (varp == &T_CCO)
6954 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006955 int colors = atoi((char *)T_CCO);
6956
6957 /* Only reinitialize colors if t_Co value has really changed to
6958 * avoid expensive reload of colorscheme if t_Co is set to the
6959 * same value multiple times. */
6960 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006962 t_colors = colors;
6963 if (t_colors <= 1)
6964 {
6965 if (new_value_alloced)
6966 vim_free(T_CCO);
6967 T_CCO = empty_option;
6968 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006969#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6970 if (is_term_win32())
6971 {
6972 swap_tcap();
6973 did_swaptcap = TRUE;
6974 }
6975#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006976 /* We now have a different color setup, initialize it again. */
6977 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006978 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006979 }
6980 ttest(FALSE);
6981 if (varp == &T_ME)
6982 {
6983 out_str(T_ME);
6984 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006985#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006986 /* Since t_me has been set, this probably means that the user
6987 * wants to use this as default colors. Need to reset default
6988 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006989# ifdef VIMDLL
6990 if (!gui.in_use && !gui.starting)
6991# endif
6992 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993#endif
6994 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006995 if (varp == &T_BE && termcap_active)
6996 {
6997 if (*T_BE == NUL)
6998 /* When clearing t_BE we assume the user no longer wants
6999 * bracketed paste, thus disable it by writing t_BD. */
7000 out_str(T_BD);
7001 else
7002 out_str(T_BE);
7003 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007004 }
7005
7006#ifdef FEAT_LINEBREAK
7007 /* 'showbreak' */
7008 else if (varp == &p_sbr)
7009 {
7010 for (s = p_sbr; *s; )
7011 {
7012 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007013 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01007014 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015 }
7016 }
7017#endif
7018
7019#ifdef FEAT_GUI
7020 /* 'guifont' */
7021 else if (varp == &p_guifont)
7022 {
7023 if (gui.in_use)
7024 {
7025 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00007026# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007027 /*
7028 * Put up a font dialog and let the user select a new value.
7029 * If this is cancelled go back to the old value but don't
7030 * give an error message.
7031 */
7032 if (STRCMP(p, "*") == 0)
7033 {
7034 p = gui_mch_font_dialog(oldval);
7035
7036 if (new_value_alloced)
7037 free_string_option(p_guifont);
7038
7039 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
7040 new_value_alloced = TRUE;
7041 }
7042# endif
7043 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
7044 {
7045# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
7046 if (STRCMP(p_guifont, "*") == 0)
7047 {
7048 /* Dialog was cancelled: Keep the old value without giving
7049 * an error message. */
7050 if (new_value_alloced)
7051 free_string_option(p_guifont);
7052 p_guifont = vim_strsave(oldval);
7053 new_value_alloced = TRUE;
7054 }
7055 else
7056# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007057 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007058 }
7059 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007060 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007061 }
7062# ifdef FEAT_XFONTSET
7063 else if (varp == &p_guifontset)
7064 {
7065 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007066 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007068 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007069 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007070 }
7071# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007072 else if (varp == &p_guifontwide)
7073 {
7074 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007075 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007076 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007077 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007078 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007079 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007080#endif
7081
7082#ifdef CURSOR_SHAPE
7083 /* 'guicursor' */
7084 else if (varp == &p_guicursor)
7085 errmsg = parse_shape_opt(SHAPE_CURSOR);
7086#endif
7087
7088#ifdef FEAT_MOUSESHAPE
7089 /* 'mouseshape' */
7090 else if (varp == &p_mouseshape)
7091 {
7092 errmsg = parse_shape_opt(SHAPE_MOUSE);
7093 update_mouseshape(-1);
7094 }
7095#endif
7096
7097#ifdef FEAT_PRINTER
7098 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007099 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007100# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007101 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007102 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007103# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007104#endif
7105
7106#ifdef FEAT_LANGMAP
7107 /* 'langmap' */
7108 else if (varp == &p_langmap)
7109 langmap_set();
7110#endif
7111
7112#ifdef FEAT_LINEBREAK
7113 /* 'breakat' */
7114 else if (varp == &p_breakat)
7115 fill_breakat_flags();
7116#endif
7117
7118#ifdef FEAT_TITLE
7119 /* 'titlestring' and 'iconstring' */
7120 else if (varp == &p_titlestring || varp == &p_iconstring)
7121 {
7122# ifdef FEAT_STL_OPT
7123 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7124
7125 /* NULL => statusline syntax */
7126 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7127 stl_syntax |= flagval;
7128 else
7129 stl_syntax &= ~flagval;
7130# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007131 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007132 }
7133#endif
7134
7135#ifdef FEAT_GUI
7136 /* 'guioptions' */
7137 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007138 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007139 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007140 redraw_gui_only = TRUE;
7141 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007142#endif
7143
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007144#if defined(FEAT_GUI_TABLINE)
7145 /* 'guitablabel' */
7146 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007147 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007148 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007149 redraw_gui_only = TRUE;
7150 }
7151 /* 'guitabtooltip' */
7152 else if (varp == &p_gtt)
7153 {
7154 redraw_gui_only = TRUE;
7155 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007156#endif
7157
Bram Moolenaar071d4272004-06-13 20:20:40 +00007158#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7159 /* 'ttymouse' */
7160 else if (varp == &p_ttym)
7161 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007162 /* Switch the mouse off before changing the escape sequences used for
7163 * that. */
7164 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007165 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7166 errmsg = e_invarg;
7167 else
7168 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007169 if (termcap_active)
7170 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007171 }
7172#endif
7173
Bram Moolenaar071d4272004-06-13 20:20:40 +00007174 /* 'selection' */
7175 else if (varp == &p_sel)
7176 {
7177 if (*p_sel == NUL
7178 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7179 errmsg = e_invarg;
7180 }
7181
7182 /* 'selectmode' */
7183 else if (varp == &p_slm)
7184 {
7185 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7186 errmsg = e_invarg;
7187 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007188
7189#ifdef FEAT_BROWSE
7190 /* 'browsedir' */
7191 else if (varp == &p_bsdir)
7192 {
7193 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7194 && !mch_isdir(p_bsdir))
7195 errmsg = e_invarg;
7196 }
7197#endif
7198
Bram Moolenaar071d4272004-06-13 20:20:40 +00007199 /* 'keymodel' */
7200 else if (varp == &p_km)
7201 {
7202 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7203 errmsg = e_invarg;
7204 else
7205 {
7206 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7207 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7208 }
7209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007210
7211 /* 'mousemodel' */
7212 else if (varp == &p_mousem)
7213 {
7214 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7215 errmsg = e_invarg;
7216#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7217 else if (*p_mousem != *oldval)
7218 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7219 * to create or delete the popup menus. */
7220 gui_motif_update_mousemodel(root_menu);
7221#endif
7222 }
7223
7224 /* 'switchbuf' */
7225 else if (varp == &p_swb)
7226 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007227 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007228 errmsg = e_invarg;
7229 }
7230
7231 /* 'debug' */
7232 else if (varp == &p_debug)
7233 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007234 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007235 errmsg = e_invarg;
7236 }
7237
7238 /* 'display' */
7239 else if (varp == &p_dy)
7240 {
7241 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7242 errmsg = e_invarg;
7243 else
7244 (void)init_chartab();
7245
7246 }
7247
Bram Moolenaar071d4272004-06-13 20:20:40 +00007248 /* 'eadirection' */
7249 else if (varp == &p_ead)
7250 {
7251 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7252 errmsg = e_invarg;
7253 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007254
7255#ifdef FEAT_CLIPBOARD
7256 /* 'clipboard' */
7257 else if (varp == &p_cb)
7258 errmsg = check_clipboard_option();
7259#endif
7260
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007261#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007262 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7263 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007264 else if (varp == &(curwin->w_s->b_p_spl)
7265 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007266 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007267 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7268
7269 if ((is_spellfile && !valid_spellfile(*varp))
7270 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007271 errmsg = e_invarg;
7272 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007273 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007274 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007275 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007276 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007277 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007278 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007279 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007280 /* 'spellsuggest' */
7281 else if (varp == &p_sps)
7282 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007283 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007284 errmsg = e_invarg;
7285 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007286 /* 'mkspellmem' */
7287 else if (varp == &p_msm)
7288 {
7289 if (spell_check_msm() != OK)
7290 errmsg = e_invarg;
7291 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007292#endif
7293
Bram Moolenaar071d4272004-06-13 20:20:40 +00007294 /* When 'bufhidden' is set, check for valid value. */
7295 else if (gvarp == &p_bh)
7296 {
7297 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7298 errmsg = e_invarg;
7299 }
7300
7301 /* When 'buftype' is set, check for valid value. */
7302 else if (gvarp == &p_bt)
7303 {
7304 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7305 errmsg = e_invarg;
7306 else
7307 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007308 if (curwin->w_status_height)
7309 {
7310 curwin->w_redr_status = TRUE;
7311 redraw_later(VALID);
7312 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007313 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007314#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007315 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007316#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317 }
7318 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007319
7320#ifdef FEAT_STL_OPT
7321 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007322 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007323 {
7324 int wid;
7325
7326 if (varp == &p_ruf) /* reset ru_wid first */
7327 ru_wid = 0;
7328 s = *varp;
7329 if (varp == &p_ruf && *s == '%')
7330 {
7331 /* set ru_wid if 'ruf' starts with "%99(" */
7332 if (*++s == '-') /* ignore a '-' */
7333 s++;
7334 wid = getdigits(&s);
7335 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7336 ru_wid = wid;
7337 else
7338 errmsg = check_stl_option(p_ruf);
7339 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007340 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007341 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007342 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007343 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007344 comp_col();
7345 }
7346#endif
7347
Bram Moolenaar071d4272004-06-13 20:20:40 +00007348 /* check if it is a valid value for 'complete' -- Acevedo */
7349 else if (gvarp == &p_cpt)
7350 {
7351 for (s = *varp; *s;)
7352 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007353 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007354 s++;
7355 if (!*s)
7356 break;
7357 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7358 {
7359 errmsg = illegal_char(errbuf, *s);
7360 break;
7361 }
7362 if (*++s != NUL && *s != ',' && *s != ' ')
7363 {
7364 if (s[-1] == 'k' || s[-1] == 's')
7365 {
7366 /* skip optional filename after 'k' and 's' */
7367 while (*s && *s != ',' && *s != ' ')
7368 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007369 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007370 ++s;
7371 ++s;
7372 }
7373 }
7374 else
7375 {
7376 if (errbuf != NULL)
7377 {
7378 sprintf((char *)errbuf,
7379 _("E535: Illegal character after <%c>"),
7380 *--s);
7381 errmsg = errbuf;
7382 }
7383 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007384 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007385 break;
7386 }
7387 }
7388 }
7389 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007390
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007391 // 'completeopt'
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007392 else if (varp == &p_cot)
7393 {
7394 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7395 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007396 else
7397 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007398 }
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007399
Bram Moolenaare2c453d2019-08-21 14:37:09 +02007400#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007401 // 'completeslash'
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007402 else if (gvarp == &p_csl)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007403 {
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007404 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
7405 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007406 errmsg = e_invarg;
7407 }
Bram Moolenaare2c453d2019-08-21 14:37:09 +02007408#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007409
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007410#ifdef FEAT_SIGNS
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007411 // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007412 else if (varp == &curwin->w_p_scl)
7413 {
7414 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7415 errmsg = e_invarg;
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007416 // When changing the 'signcolumn' to or from 'number', recompute the
7417 // width of the number column if 'number' or 'relativenumber' is set.
7418 if (((*oldval == 'n' && *(oldval + 1) == 'u')
7419 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
7420 && (curwin->w_p_nu || curwin->w_p_rnu))
7421 curwin->w_nrwidth_line_count = 0;
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007422 }
7423#endif
7424
Bram Moolenaar071d4272004-06-13 20:20:40 +00007425
Bram Moolenaar4f974752019-02-17 17:44:42 +01007426#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007427 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007428 else if (varp == &p_toolbar)
7429 {
7430 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7431 &toolbar_flags, TRUE) != OK)
7432 errmsg = e_invarg;
7433 else
7434 {
7435 out_flush();
7436 gui_mch_show_toolbar((toolbar_flags &
7437 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7438 }
7439 }
7440#endif
7441
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007442#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007443 /* 'toolbariconsize': GTK+ 2 only */
7444 else if (varp == &p_tbis)
7445 {
7446 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7447 errmsg = e_invarg;
7448 else
7449 {
7450 out_flush();
7451 gui_mch_show_toolbar((toolbar_flags &
7452 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7453 }
7454 }
7455#endif
7456
7457 /* 'pastetoggle': translate key codes like in a mapping */
7458 else if (varp == &p_pt)
7459 {
7460 if (*p_pt)
7461 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007462 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463 if (p != NULL)
7464 {
7465 if (new_value_alloced)
7466 free_string_option(p_pt);
7467 p_pt = p;
7468 new_value_alloced = TRUE;
7469 }
7470 }
7471 }
7472
7473 /* 'backspace' */
7474 else if (varp == &p_bs)
7475 {
7476 if (VIM_ISDIGIT(*p_bs))
7477 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007478 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007479 errmsg = e_invarg;
7480 }
7481 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7482 errmsg = e_invarg;
7483 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007484 else if (varp == &p_bo)
7485 {
7486 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7487 errmsg = e_invarg;
7488 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007489
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007490 /* 'tagcase' */
7491 else if (gvarp == &p_tc)
7492 {
7493 unsigned int *flags;
7494
7495 if (opt_flags & OPT_LOCAL)
7496 {
7497 p = curbuf->b_p_tc;
7498 flags = &curbuf->b_tc_flags;
7499 }
7500 else
7501 {
7502 p = p_tc;
7503 flags = &tc_flags;
7504 }
7505
7506 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7507 /* make the local value empty: use the global value */
7508 *flags = 0;
7509 else if (*p == NUL
7510 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7511 errmsg = e_invarg;
7512 }
7513
Bram Moolenaar071d4272004-06-13 20:20:40 +00007514 /* 'casemap' */
7515 else if (varp == &p_cmp)
7516 {
7517 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7518 errmsg = e_invarg;
7519 }
7520
7521#ifdef FEAT_DIFF
7522 /* 'diffopt' */
7523 else if (varp == &p_dip)
7524 {
7525 if (diffopt_changed() == FAIL)
7526 errmsg = e_invarg;
7527 }
7528#endif
7529
7530#ifdef FEAT_FOLDING
7531 /* 'foldmethod' */
7532 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7533 {
7534 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7535 || *curwin->w_p_fdm == NUL)
7536 errmsg = e_invarg;
7537 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007538 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007539 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007540 if (foldmethodIsDiff(curwin))
7541 newFoldLevel();
7542 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007543 }
7544# ifdef FEAT_EVAL
7545 /* 'foldexpr' */
7546 else if (varp == &curwin->w_p_fde)
7547 {
7548 if (foldmethodIsExpr(curwin))
7549 foldUpdateAll(curwin);
7550 }
7551# endif
7552 /* 'foldmarker' */
7553 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7554 {
7555 p = vim_strchr(*varp, ',');
7556 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007557 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007558 else if (p == *varp || p[1] == NUL)
7559 errmsg = e_invarg;
7560 else if (foldmethodIsMarker(curwin))
7561 foldUpdateAll(curwin);
7562 }
7563 /* 'commentstring' */
7564 else if (gvarp == &p_cms)
7565 {
7566 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007567 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007568 }
7569 /* 'foldopen' */
7570 else if (varp == &p_fdo)
7571 {
7572 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7573 errmsg = e_invarg;
7574 }
7575 /* 'foldclose' */
7576 else if (varp == &p_fcl)
7577 {
7578 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7579 errmsg = e_invarg;
7580 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007581 /* 'foldignore' */
7582 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7583 {
7584 if (foldmethodIsIndent(curwin))
7585 foldUpdateAll(curwin);
7586 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007587#endif
7588
Bram Moolenaar071d4272004-06-13 20:20:40 +00007589 /* 'virtualedit' */
7590 else if (varp == &p_ve)
7591 {
7592 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7593 errmsg = e_invarg;
7594 else if (STRCMP(p_ve, oldval) != 0)
7595 {
7596 /* Recompute cursor position in case the new 've' setting
7597 * changes something. */
7598 validate_virtcol();
7599 coladvance(curwin->w_virtcol);
7600 }
7601 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007602
7603#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7604 else if (varp == &p_csqf)
7605 {
7606 if (p_csqf != NULL)
7607 {
7608 p = p_csqf;
7609 while (*p != NUL)
7610 {
7611 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7612 || p[1] == NUL
7613 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7614 || (p[2] != NUL && p[2] != ','))
7615 {
7616 errmsg = e_invarg;
7617 break;
7618 }
7619 else if (p[2] == NUL)
7620 break;
7621 else
7622 p += 3;
7623 }
7624 }
7625 }
7626#endif
7627
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007628#ifdef FEAT_CINDENT
7629 /* 'cinoptions' */
7630 else if (gvarp == &p_cino)
7631 {
7632 /* TODO: recognize errors */
7633 parse_cino(curbuf);
7634 }
7635#endif
7636
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007637#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007638 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007639 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007640 {
7641 if (!gui_mch_set_rendering_options(p_rop))
7642 errmsg = e_invarg;
7643 }
7644#endif
7645
Bram Moolenaard0b51382016-11-04 15:23:45 +01007646 else if (gvarp == &p_ft)
7647 {
7648 if (!valid_filetype(*varp))
7649 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007650 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007651 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007652 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007653
7654 // Since we check the value, there is no need to set P_INSECURE,
7655 // even when the value comes from a modeline.
7656 *value_checked = TRUE;
7657 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007658 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007659
7660#ifdef FEAT_SYN_HL
7661 else if (gvarp == &p_syn)
7662 {
7663 if (!valid_filetype(*varp))
7664 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007665 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007666 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007667 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007668
7669 // Since we check the value, there is no need to set P_INSECURE,
7670 // even when the value comes from a modeline.
7671 *value_checked = TRUE;
7672 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007673 }
7674#endif
7675
Bram Moolenaar825680f2017-07-22 17:04:02 +02007676#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007677 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007678 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007679 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007680 if (*curwin->w_p_twk != NUL
7681 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007682 errmsg = e_invarg;
7683 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007684 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007685 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007686 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007687 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007688 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007689 p = skipdigits(curwin->w_p_tws);
7690 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007691 || (*p != 'x' && *p != '*')
7692 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007693 errmsg = e_invarg;
7694 }
7695 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007696# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007697 // 'termwintype'
7698 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007699 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007700 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007701 errmsg = e_invarg;
7702 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007703# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007704#endif
7705
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007706#ifdef FEAT_VARTABS
7707 /* 'varsofttabstop' */
7708 else if (varp == &(curbuf->b_p_vsts))
7709 {
7710 char_u *cp;
7711
7712 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7713 {
7714 if (curbuf->b_p_vsts_array)
7715 {
7716 vim_free(curbuf->b_p_vsts_array);
7717 curbuf->b_p_vsts_array = 0;
7718 }
7719 }
7720 else
7721 {
7722 for (cp = *varp; *cp; ++cp)
7723 {
7724 if (vim_isdigit(*cp))
7725 continue;
7726 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7727 continue;
7728 errmsg = e_invarg;
7729 break;
7730 }
7731 if (errmsg == NULL)
7732 {
7733 int *oldarray = curbuf->b_p_vsts_array;
7734 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7735 {
7736 if (oldarray)
7737 vim_free(oldarray);
7738 }
7739 else
7740 errmsg = e_invarg;
7741 }
7742 }
7743 }
7744
7745 /* 'vartabstop' */
7746 else if (varp == &(curbuf->b_p_vts))
7747 {
7748 char_u *cp;
7749
7750 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7751 {
7752 if (curbuf->b_p_vts_array)
7753 {
7754 vim_free(curbuf->b_p_vts_array);
7755 curbuf->b_p_vts_array = NULL;
7756 }
7757 }
7758 else
7759 {
7760 for (cp = *varp; *cp; ++cp)
7761 {
7762 if (vim_isdigit(*cp))
7763 continue;
7764 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7765 continue;
7766 errmsg = e_invarg;
7767 break;
7768 }
7769 if (errmsg == NULL)
7770 {
7771 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007772
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007773 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7774 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007775 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007776#ifdef FEAT_FOLDING
7777 if (foldmethodIsIndent(curwin))
7778 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007779#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007780 }
7781 else
7782 errmsg = e_invarg;
7783 }
7784 }
7785 }
7786#endif
7787
Bram Moolenaar79648732019-07-18 21:43:07 +02007788#ifdef FEAT_TEXT_PROP
7789 // 'previewpopup'
7790 else if (varp == &p_pvp)
7791 {
7792 if (parse_previewpopup(NULL) == FAIL)
7793 errmsg = e_invarg;
7794 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007795# ifdef FEAT_QUICKFIX
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02007796 // 'completepopup'
7797 else if (varp == &p_cpp)
7798 {
7799 if (parse_completepopup(NULL) == FAIL)
7800 errmsg = e_invarg;
7801 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007802# endif
Bram Moolenaar79648732019-07-18 21:43:07 +02007803#endif
7804
Bram Moolenaar071d4272004-06-13 20:20:40 +00007805 /* Options that are a list of flags. */
7806 else
7807 {
7808 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007809 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007811 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007812 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007813 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007814 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007815 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007817#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007818 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007819 p = (char_u *)COCU_ALL;
7820#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007821 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007822 {
7823#ifdef FEAT_MOUSE
7824 p = (char_u *)MOUSE_ALL;
7825#else
7826 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007827 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007828#endif
7829 }
7830#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007831 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007832 p = (char_u *)GO_ALL;
7833#endif
7834 if (p != NULL)
7835 {
7836 for (s = *varp; *s; ++s)
7837 if (vim_strchr(p, *s) == NULL)
7838 {
7839 errmsg = illegal_char(errbuf, *s);
7840 break;
7841 }
7842 }
7843 }
7844
7845 /*
7846 * If error detected, restore the previous value.
7847 */
7848 if (errmsg != NULL)
7849 {
7850 if (new_value_alloced)
7851 free_string_option(*varp);
7852 *varp = oldval;
7853 /*
7854 * When resetting some values, need to act on it.
7855 */
7856 if (did_chartab)
7857 (void)init_chartab();
7858 if (varp == &p_hl)
7859 (void)highlight_changed();
7860 }
7861 else
7862 {
7863#ifdef FEAT_EVAL
7864 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007865 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007866#endif
7867 /*
7868 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007869 * Use "free_oldval", because recursiveness may change the flags under
7870 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007871 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007872 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007873 free_string_option(oldval);
7874 if (new_value_alloced)
7875 options[opt_idx].flags |= P_ALLOCED;
7876 else
7877 options[opt_idx].flags &= ~P_ALLOCED;
7878
7879 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007880 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007881 {
7882 /* global option with local value set to use global value; free
7883 * the local value and make it empty */
7884 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7885 free_string_option(*(char_u **)p);
7886 *(char_u **)p = empty_option;
7887 }
7888
7889 /* May set global value for local option. */
7890 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7891 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007892
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007893 /*
7894 * Trigger the autocommand only after setting the flags.
7895 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007896#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007897 /* When 'syntax' is set, load the syntax of that name */
7898 if (varp == &(curbuf->b_p_syn))
7899 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007900 static int syn_recursive = 0;
7901
7902 ++syn_recursive;
7903 // Only pass TRUE for "force" when the value changed or not used
7904 // recursively, to avoid endless recurrence.
7905 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7906 value_changed || syn_recursive == 1, curbuf);
Bram Moolenaarc7f1e402019-08-03 13:29:46 +02007907 curbuf->b_flags |= BF_SYN_SET;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007908 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007909 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007910#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007911 else if (varp == &(curbuf->b_p_ft))
7912 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007913 /* 'filetype' is set, trigger the FileType autocommand.
7914 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007915 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007916 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007917 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007918 static int ft_recursive = 0;
7919 int secure_save = secure;
7920
7921 // Reset the secure flag, since the value of 'filetype' has
7922 // been checked to be safe.
7923 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007924
7925 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007926 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007927 // Only pass TRUE for "force" when the value changed or not
7928 // used recursively, to avoid endless recurrence.
7929 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7930 value_changed || ft_recursive == 1, curbuf);
7931 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007932 /* Just in case the old "curbuf" is now invalid. */
7933 if (varp != &(curbuf->b_p_ft))
7934 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007935
7936 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007937 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007938 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007939#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007940 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007941 {
7942 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007943 char_u *q = curwin->w_s->b_p_spl;
7944
7945 /* Skip the first name if it is "cjk". */
7946 if (STRNCMP(q, "cjk,", 4) == 0)
7947 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007948
7949 /*
7950 * Source the spell/LANG.vim in 'runtimepath'.
7951 * They could set 'spellcapcheck' depending on the language.
7952 * Use the first name in 'spelllang' up to '_region' or
7953 * '.encoding'.
7954 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007955 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007956 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007957 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007958 if (p > q)
7959 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007960 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7961 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007962 source_runtime(fname, DIP_ALL);
7963 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007964 }
7965#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 }
7967
7968#ifdef FEAT_MOUSE
7969 if (varp == &p_mouse)
7970 {
7971# ifdef FEAT_MOUSE_TTY
7972 if (*p_mouse == NUL)
7973 mch_setmouse(FALSE); /* switch mouse off */
7974 else
7975# endif
7976 setmouse(); /* in case 'mouse' changed */
7977 }
7978#endif
7979
Bram Moolenaar913077c2012-03-28 19:59:04 +02007980 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007981 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007982 curwin->w_set_curswant = TRUE;
7983
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007984#ifdef FEAT_GUI
7985 /* check redraw when it's not a GUI option or the GUI is active. */
7986 if (!redraw_gui_only || gui.in_use)
7987#endif
7988 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007989
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007990#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7991 if (did_swaptcap)
7992 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007993 set_termname((char_u *)"win32");
7994 init_highlight(TRUE, FALSE);
7995 }
7996#endif
7997
Bram Moolenaar071d4272004-06-13 20:20:40 +00007998 return errmsg;
7999}
8000
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01008001#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008002/*
8003 * Simple int comparison function for use with qsort()
8004 */
8005 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008006int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008007{
8008 return *(const int *)a - *(const int *)b;
8009}
8010
8011/*
8012 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
8013 * Returns error message, NULL if it's OK.
8014 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008015 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008016check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008017{
8018 char_u *s;
8019 int col;
8020 int count = 0;
8021 int color_cols[256];
8022 int i;
8023 int j = 0;
8024
Bram Moolenaar50f834d2011-09-21 13:40:17 +02008025 if (wp->w_buffer == NULL)
8026 return NULL; /* buffer was closed */
8027
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008028 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008029 {
8030 if (*s == '-' || *s == '+')
8031 {
8032 /* -N and +N: add to 'textwidth' */
8033 col = (*s == '-') ? -1 : 1;
8034 ++s;
8035 if (!VIM_ISDIGIT(*s))
8036 return e_invarg;
8037 col = col * getdigits(&s);
8038 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008039 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008040 col += wp->w_buffer->b_p_tw;
8041 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008042 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02008043 }
8044 else if (VIM_ISDIGIT(*s))
8045 col = getdigits(&s);
8046 else
8047 return e_invarg;
8048 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008049skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02008050 if (*s == NUL)
8051 break;
8052 if (*s != ',')
8053 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008054 if (*++s == NUL)
8055 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008056 }
8057
8058 vim_free(wp->w_p_cc_cols);
8059 if (count == 0)
8060 wp->w_p_cc_cols = NULL;
8061 else
8062 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008063 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008064 if (wp->w_p_cc_cols != NULL)
8065 {
8066 /* sort the columns for faster usage on screen redraw inside
8067 * win_line() */
8068 qsort(color_cols, count, sizeof(int), int_cmp);
8069
8070 for (i = 0; i < count; ++i)
8071 /* skip duplicates */
8072 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8073 wp->w_p_cc_cols[j++] = color_cols[i];
8074 wp->w_p_cc_cols[j] = -1; /* end marker */
8075 }
8076 }
8077
8078 return NULL; /* no error */
8079}
8080#endif
8081
Bram Moolenaar071d4272004-06-13 20:20:40 +00008082/*
8083 * Handle setting 'listchars' or 'fillchars'.
8084 * Returns error message, NULL if it's OK.
8085 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008086 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008087set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008088{
8089 int round, i, len, entries;
8090 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008091 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008092 struct charstab
8093 {
8094 int *cp;
8095 char *name;
8096 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008097 static struct charstab filltab[] =
8098 {
8099 {&fill_stl, "stl"},
8100 {&fill_stlnc, "stlnc"},
8101 {&fill_vert, "vert"},
8102 {&fill_fold, "fold"},
8103 {&fill_diff, "diff"},
8104 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008105 static struct charstab lcstab[] =
8106 {
8107 {&lcs_eol, "eol"},
8108 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008109 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008110 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008111 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008112 {&lcs_tab2, "tab"},
8113 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008114#ifdef FEAT_CONCEAL
8115 {&lcs_conceal, "conceal"},
8116#else
8117 {NULL, "conceal"},
8118#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008119 };
8120 struct charstab *tab;
8121
Bram Moolenaar071d4272004-06-13 20:20:40 +00008122 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008123 {
8124 tab = lcstab;
8125 entries = sizeof(lcstab) / sizeof(struct charstab);
8126 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008127 else
8128 {
8129 tab = filltab;
8130 entries = sizeof(filltab) / sizeof(struct charstab);
8131 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008132
8133 /* first round: check for valid value, second round: assign values */
8134 for (round = 0; round <= 1; ++round)
8135 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008136 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008137 {
8138 /* After checking that the value is valid: set defaults: space for
8139 * 'fillchars', NUL for 'listchars' */
8140 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008141 if (tab[i].cp != NULL)
8142 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008143
Bram Moolenaar071d4272004-06-13 20:20:40 +00008144 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008145 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008147 lcs_tab3 = NUL;
8148 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149 else
8150 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151 }
8152 p = *varp;
8153 while (*p)
8154 {
8155 for (i = 0; i < entries; ++i)
8156 {
8157 len = (int)STRLEN(tab[i].name);
8158 if (STRNCMP(p, tab[i].name, len) == 0
8159 && p[len] == ':'
8160 && p[len + 1] != NUL)
8161 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008162 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008163 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008164 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008165 if (mb_char2cells(c1) > 1)
8166 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008167 if (tab[i].cp == &lcs_tab2)
8168 {
8169 if (*s == NUL)
8170 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008171 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008172 if (mb_char2cells(c2) > 1)
8173 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008174 if (!(*s == ',' || *s == NUL))
8175 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008176 c3 = mb_ptr2char_adv(&s);
8177 if (mb_char2cells(c3) > 1)
8178 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008179 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008180 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008181
Bram Moolenaar071d4272004-06-13 20:20:40 +00008182 if (*s == ',' || *s == NUL)
8183 {
8184 if (round)
8185 {
8186 if (tab[i].cp == &lcs_tab2)
8187 {
8188 lcs_tab1 = c1;
8189 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008190 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008191 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008192 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008193 *(tab[i].cp) = c1;
8194
8195 }
8196 p = s;
8197 break;
8198 }
8199 }
8200 }
8201
8202 if (i == entries)
8203 return e_invarg;
8204 if (*p == ',')
8205 ++p;
8206 }
8207 }
8208
8209 return NULL; /* no error */
8210}
8211
8212#ifdef FEAT_STL_OPT
8213/*
8214 * Check validity of options with the 'statusline' format.
8215 * Return error message or NULL.
8216 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02008217 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008218check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008219{
8220 int itemcnt = 0;
8221 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008222 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008223
8224 while (*s && itemcnt < STL_MAX_ITEM)
8225 {
8226 /* Check for valid keys after % sequences */
8227 while (*s && *s != '%')
8228 s++;
8229 if (!*s)
8230 break;
8231 s++;
8232 if (*s != '%' && *s != ')')
8233 ++itemcnt;
8234 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8235 {
8236 s++;
8237 continue;
8238 }
8239 if (*s == ')')
8240 {
8241 s++;
8242 if (--groupdepth < 0)
8243 break;
8244 continue;
8245 }
8246 if (*s == '-')
8247 s++;
8248 while (VIM_ISDIGIT(*s))
8249 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008250 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251 continue;
8252 if (*s == '.')
8253 {
8254 s++;
8255 while (*s && VIM_ISDIGIT(*s))
8256 s++;
8257 }
8258 if (*s == '(')
8259 {
8260 groupdepth++;
8261 continue;
8262 }
8263 if (vim_strchr(STL_ALL, *s) == NULL)
8264 {
8265 return illegal_char(errbuf, *s);
8266 }
8267 if (*s == '{')
8268 {
8269 s++;
8270 while (*s != '}' && *s)
8271 s++;
8272 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008273 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008274 }
8275 }
8276 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008277 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008278 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008279 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008280 return NULL;
8281}
8282#endif
8283
8284#ifdef FEAT_CLIPBOARD
8285/*
8286 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008287 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008288 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008289 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008290check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008291{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008292 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008293 int new_autoselect_star = FALSE;
8294 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008295 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008296 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008298 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008299 char_u *p;
8300
8301 for (p = p_cb; *p != NUL; )
8302 {
8303 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8304 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008305 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008306 p += 7;
8307 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008308 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008309 && (p[11] == ',' || p[11] == NUL))
8310 {
8311 new_unnamed |= CLIP_UNNAMED_PLUS;
8312 p += 11;
8313 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008314 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008315 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008316 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008317 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008318 p += 10;
8319 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008320 else if (STRNCMP(p, "autoselectplus", 14) == 0
8321 && (p[14] == ',' || p[14] == NUL))
8322 {
8323 new_autoselect_plus = TRUE;
8324 p += 14;
8325 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008327 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008328 {
8329 new_autoselectml = TRUE;
8330 p += 12;
8331 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008332 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8333 {
8334 new_html = TRUE;
8335 p += 4;
8336 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8338 {
8339 p += 8;
8340 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8341 if (new_exclude_prog == NULL)
8342 errmsg = e_invarg;
8343 break;
8344 }
8345 else
8346 {
8347 errmsg = e_invarg;
8348 break;
8349 }
8350 if (*p == ',')
8351 ++p;
8352 }
8353 if (errmsg == NULL)
8354 {
8355 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008356 clip_autoselect_star = new_autoselect_star;
8357 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008358 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008359 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008360 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008361 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008362#ifdef FEAT_GUI_GTK
8363 if (gui.in_use)
8364 {
8365 gui_gtk_set_selection_targets();
8366 gui_gtk_set_dnd_targets();
8367 }
8368#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008369 }
8370 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008371 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372
8373 return errmsg;
8374}
8375#endif
8376
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008377#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008378/*
8379 * Handle side effects of setting 'spell'.
8380 * Return an error message or NULL for success.
8381 */
8382 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008383did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008384{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008385 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008386 win_T *wp;
8387 int l;
8388
8389 if (is_spellfile)
8390 {
8391 l = (int)STRLEN(curwin->w_s->b_p_spf);
8392 if (l > 0 && (l < 4
8393 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8394 errmsg = e_invarg;
8395 }
8396
8397 if (errmsg == NULL)
8398 {
8399 FOR_ALL_WINDOWS(wp)
8400 if (wp->w_buffer == curbuf && wp->w_p_spell)
8401 {
8402 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008403 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008404 }
8405 }
8406 return errmsg;
8407}
8408
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008409/*
8410 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8411 * Return error message when failed, NULL when OK.
8412 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008413 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008414compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008415{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008416 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008417 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008418
Bram Moolenaar860cae12010-06-05 23:22:07 +02008419 if (*synblock->b_p_spc == NUL)
8420 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008421 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008422 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008423 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008424 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008425 if (re != NULL)
8426 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008427 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008428 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008429 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008430 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008431 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008432 return e_invarg;
8433 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008434 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008435 }
8436
Bram Moolenaar473de612013-06-08 18:19:48 +02008437 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008438 return NULL;
8439}
8440#endif
8441
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008442#if defined(FEAT_EVAL) || defined(PROTO)
8443/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008444 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008445 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008446 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008447 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008448set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008449{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008450 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8451 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008452 sctx_T new_script_ctx = script_ctx;
8453
8454 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008455
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008456 /* Remember where the option was set. For local options need to do that
8457 * in the buffer or window structure. */
8458 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008459 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008460 if (both || (opt_flags & OPT_LOCAL))
8461 {
8462 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008463 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008464 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008465 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008466 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008467}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008468
8469/*
8470 * Set the script_ctx for a termcap option.
8471 * "name" must be the two character code, e.g. "RV".
8472 * When "name" is NULL use "opt_idx".
8473 */
8474 void
8475set_term_option_sctx_idx(char *name, int opt_idx)
8476{
8477 char_u buf[5];
8478 int idx;
8479
8480 if (name == NULL)
8481 idx = opt_idx;
8482 else
8483 {
8484 buf[0] = 't';
8485 buf[1] = '_';
8486 buf[2] = name[0];
8487 buf[3] = name[1];
8488 buf[4] = 0;
8489 idx = findoption(buf);
8490 }
8491 if (idx >= 0)
8492 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8493}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008494#endif
8495
Bram Moolenaar071d4272004-06-13 20:20:40 +00008496/*
8497 * Set the value of a boolean option, and take care of side effects.
8498 * Returns NULL for success, or an error message for an error.
8499 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008500 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008501set_bool_option(
8502 int opt_idx, /* index in options[] table */
8503 char_u *varp, /* pointer to the option variable */
8504 int value, /* new value */
8505 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008506{
8507 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008508#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008509 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008510#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008511
Bram Moolenaar071d4272004-06-13 20:20:40 +00008512 /* Disallow changing some options from secure mode */
8513 if ((secure
8514#ifdef HAVE_SANDBOX
8515 || sandbox != 0
8516#endif
8517 ) && (options[opt_idx].flags & P_SECURE))
8518 return e_secure;
8519
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008520#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008521 // Save the global value before changing anything. This is needed as for
8522 // a global-only option setting the "local value" in fact sets the global
8523 // value (since there is only one value).
8524 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8525 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8526 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008527#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008528
Bram Moolenaar071d4272004-06-13 20:20:40 +00008529 *(int *)varp = value; /* set the new value */
8530#ifdef FEAT_EVAL
8531 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008532 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008533#endif
8534
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008535#ifdef FEAT_GUI
8536 need_mouse_correct = TRUE;
8537#endif
8538
Bram Moolenaar071d4272004-06-13 20:20:40 +00008539 /* May set global value for local option. */
8540 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8541 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8542
8543 /*
8544 * Handle side effects of changing a bool option.
8545 */
8546
8547 /* 'compatible' */
8548 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008549 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008550
Bram Moolenaar920694c2016-08-21 17:45:02 +02008551#ifdef FEAT_LANGMAP
8552 if ((int *)varp == &p_lrm)
8553 /* 'langremap' -> !'langnoremap' */
8554 p_lnr = !p_lrm;
8555 else if ((int *)varp == &p_lnr)
8556 /* 'langnoremap' -> !'langremap' */
8557 p_lrm = !p_lnr;
8558#endif
8559
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008560#ifdef FEAT_SYN_HL
8561 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8562 reset_cursorline();
8563#endif
8564
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008565#ifdef FEAT_PERSISTENT_UNDO
8566 /* 'undofile' */
8567 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8568 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008569 /* Only take action when the option was set. When reset we do not
8570 * delete the undo file, the option may be set again without making
8571 * any changes in between. */
8572 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008573 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008574 char_u hash[UNDO_HASH_SIZE];
8575 buf_T *save_curbuf = curbuf;
8576
Bram Moolenaar29323592016-07-24 22:04:11 +02008577 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008578 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008579 /* When 'undofile' is set globally: for every buffer, otherwise
8580 * only for the current buffer: Try to read in the undofile,
8581 * if one exists, the buffer wasn't changed and the buffer was
8582 * loaded */
8583 if ((curbuf == save_curbuf
8584 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8585 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8586 {
8587 u_compute_hash(hash);
8588 u_read_undo(NULL, hash, curbuf->b_fname);
8589 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008590 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008591 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008592 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008593 }
8594#endif
8595
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596 else if ((int *)varp == &curbuf->b_p_ro)
8597 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008598 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008599 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8600 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008601
8602 /* when 'readonly' is set may give W10 again */
8603 if (curbuf->b_p_ro)
8604 curbuf->b_did_warn = FALSE;
8605
Bram Moolenaar071d4272004-06-13 20:20:40 +00008606#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008607 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008608#endif
8609 }
8610
Bram Moolenaar9c449722010-07-20 18:44:27 +02008611#ifdef FEAT_GUI
8612 else if ((int *)varp == &p_mh)
8613 {
8614 if (!p_mh)
8615 gui_mch_mousehide(FALSE);
8616 }
8617#endif
8618
Bram Moolenaara539df02010-08-01 14:35:05 +02008619 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008620 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008621 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008622# ifdef FEAT_TERMINAL
8623 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008624 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8625 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008626 {
8627 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008628 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008629 }
8630# endif
8631# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008632 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008633# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008634 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008635#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008636 /* when 'endofline' is changed, redraw the window title */
8637 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008638 {
8639 redraw_titles();
8640 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008641 /* when 'fixeol' is changed, redraw the window title */
8642 else if ((int *)varp == &curbuf->b_p_fixeol)
8643 {
8644 redraw_titles();
8645 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008646 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008647 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008648 {
8649 redraw_titles();
8650 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008651#endif
8652
8653 /* when 'bin' is set also set some other options */
8654 else if ((int *)varp == &curbuf->b_p_bin)
8655 {
8656 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8657#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008658 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659#endif
8660 }
8661
Bram Moolenaar071d4272004-06-13 20:20:40 +00008662 /* when 'buflisted' changes, trigger autocommands */
8663 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8664 {
8665 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8666 NULL, NULL, TRUE, curbuf);
8667 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668
8669 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8670 else if ((int *)varp == &curbuf->b_p_swf)
8671 {
8672 if (curbuf->b_p_swf && p_uc)
8673 ml_open_file(curbuf); /* create the swap file */
8674 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008675 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8676 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008677 mf_close_file(curbuf, TRUE); /* remove the swap file */
8678 }
8679
8680 /* when 'terse' is set change 'shortmess' */
8681 else if ((int *)varp == &p_terse)
8682 {
8683 char_u *p;
8684
8685 p = vim_strchr(p_shm, SHM_SEARCH);
8686
8687 /* insert 's' in p_shm */
8688 if (p_terse && p == NULL)
8689 {
8690 STRCPY(IObuff, p_shm);
8691 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008692 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008693 }
8694 /* remove 's' from p_shm */
8695 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008696 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697 }
8698
8699 /* when 'paste' is set or reset also change other options */
8700 else if ((int *)varp == &p_paste)
8701 {
8702 paste_option_changed();
8703 }
8704
8705 /* when 'insertmode' is set from an autocommand need to do work here */
8706 else if ((int *)varp == &p_im)
8707 {
8708 if (p_im)
8709 {
8710 if ((State & INSERT) == 0)
8711 need_start_insertmode = TRUE;
8712 stop_insert_mode = FALSE;
8713 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008714 /* only reset if it was set previously */
8715 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008716 {
8717 need_start_insertmode = FALSE;
8718 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008719 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008720 clear_cmdline = TRUE; /* remove "(insert)" */
8721 restart_edit = 0;
8722 }
8723 }
8724
8725 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8726 else if ((int *)varp == &p_ic && p_hls)
8727 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008728 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008729 }
8730
8731#ifdef FEAT_SEARCH_EXTRA
8732 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8733 else if ((int *)varp == &p_hls)
8734 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008735 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008736 }
8737#endif
8738
Bram Moolenaar071d4272004-06-13 20:20:40 +00008739 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8740 * at the end of normal_cmd() */
8741 else if ((int *)varp == &curwin->w_p_scb)
8742 {
8743 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008744 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008745 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008746 curwin->w_scbind_pos = curwin->w_topline;
8747 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008748 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008749
Bram Moolenaar4033c552017-09-16 20:54:51 +02008750#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008751 /* There can be only one window with 'previewwindow' set. */
8752 else if ((int *)varp == &curwin->w_p_pvw)
8753 {
8754 if (curwin->w_p_pvw)
8755 {
8756 win_T *win;
8757
Bram Moolenaar29323592016-07-24 22:04:11 +02008758 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008759 if (win->w_p_pvw && win != curwin)
8760 {
8761 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008762 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008763 }
8764 }
8765 }
8766#endif
8767
8768 /* when 'textmode' is set or reset also change 'fileformat' */
8769 else if ((int *)varp == &curbuf->b_p_tx)
8770 {
8771 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8772 }
8773
8774 /* when 'textauto' is set or reset also change 'fileformats' */
8775 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008776 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008777 set_string_option_direct((char_u *)"ffs", -1,
8778 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008779 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008780 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008781
8782 /*
8783 * When 'lisp' option changes include/exclude '-' in
8784 * keyword characters.
8785 */
8786#ifdef FEAT_LISP
8787 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8788 {
8789 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8790 }
8791#endif
8792
8793#ifdef FEAT_TITLE
8794 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008795 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008796 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008797 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008798 }
8799#endif
8800
8801 else if ((int *)varp == &curbuf->b_changed)
8802 {
8803 if (!value)
8804 save_file_ff(curbuf); /* Buffer is unchanged */
8805#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008806 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008807#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008808 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 }
8810
8811#ifdef BACKSLASH_IN_FILENAME
8812 else if ((int *)varp == &p_ssl)
8813 {
8814 if (p_ssl)
8815 {
8816 psepc = '/';
8817 psepcN = '\\';
8818 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008819 }
8820 else
8821 {
8822 psepc = '\\';
8823 psepcN = '/';
8824 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008825 }
8826
8827 /* need to adjust the file name arguments and buffer names. */
8828 buflist_slash_adjust();
8829 alist_slash_adjust();
8830# ifdef FEAT_EVAL
8831 scriptnames_slash_adjust();
8832# endif
8833 }
8834#endif
8835
8836 /* If 'wrap' is set, set w_leftcol to zero. */
8837 else if ((int *)varp == &curwin->w_p_wrap)
8838 {
8839 if (curwin->w_p_wrap)
8840 curwin->w_leftcol = 0;
8841 }
8842
Bram Moolenaar071d4272004-06-13 20:20:40 +00008843 else if ((int *)varp == &p_ea)
8844 {
8845 if (p_ea && !old_value)
8846 win_equal(curwin, FALSE, 0);
8847 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008848
8849 else if ((int *)varp == &p_wiv)
8850 {
8851 /*
8852 * When 'weirdinvert' changed, set/reset 't_xs'.
8853 * Then set 'weirdinvert' according to value of 't_xs'.
8854 */
8855 if (p_wiv && !old_value)
8856 T_XS = (char_u *)"y";
8857 else if (!p_wiv && old_value)
8858 T_XS = empty_option;
8859 p_wiv = (*T_XS != NUL);
8860 }
8861
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008862#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008863 else if ((int *)varp == &p_beval)
8864 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008865 if (!balloonEvalForTerm)
8866 {
8867 if (p_beval && !old_value)
8868 gui_mch_enable_beval_area(balloonEval);
8869 else if (!p_beval && old_value)
8870 gui_mch_disable_beval_area(balloonEval);
8871 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008873#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008874#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008875 else if ((int *)varp == &p_bevalterm)
8876 {
8877 mch_bevalterm_changed();
8878 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008879#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008881#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008882 else if ((int *)varp == &p_acd)
8883 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008884 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008885 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008886 }
8887#endif
8888
8889#ifdef FEAT_DIFF
8890 /* 'diff' */
8891 else if ((int *)varp == &curwin->w_p_diff)
8892 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008893 /* May add or remove the buffer from the list of diff buffers. */
8894 diff_buf_adjust(curwin);
8895# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008896 if (foldmethodIsDiff(curwin))
8897 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008898# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008899 }
8900#endif
8901
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008902#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008903 /* 'imdisable' */
8904 else if ((int *)varp == &p_imdisable)
8905 {
8906 /* Only de-activate it here, it will be enabled when changing mode. */
8907 if (p_imdisable)
8908 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008909 else if (State & INSERT)
8910 /* When the option is set from an autocommand, it may need to take
8911 * effect right away. */
8912 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008913 }
8914#endif
8915
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008916#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008917 /* 'spell' */
8918 else if ((int *)varp == &curwin->w_p_spell)
8919 {
8920 if (curwin->w_p_spell)
8921 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008922 char *errmsg = did_set_spelllang(curwin);
8923
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008924 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008925 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008926 }
8927 }
8928#endif
8929
Bram Moolenaar071d4272004-06-13 20:20:40 +00008930#ifdef FEAT_ARABIC
8931 if ((int *)varp == &curwin->w_p_arab)
8932 {
8933 if (curwin->w_p_arab)
8934 {
8935 /*
8936 * 'arabic' is set, handle various sub-settings.
8937 */
8938 if (!p_tbidi)
8939 {
8940 /* set rightleft mode */
8941 if (!curwin->w_p_rl)
8942 {
8943 curwin->w_p_rl = TRUE;
8944 changed_window_setting();
8945 }
8946
8947 /* Enable Arabic shaping (major part of what Arabic requires) */
8948 if (!p_arshape)
8949 {
8950 p_arshape = TRUE;
8951 redraw_later_clear();
8952 }
8953 }
8954
8955 /* Arabic requires a utf-8 encoding, inform the user if its not
8956 * set. */
8957 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008958 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008959 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8960
Bram Moolenaar8820b482017-03-16 17:23:31 +01008961 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008962 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008963#ifdef FEAT_EVAL
8964 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8965#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008967
Bram Moolenaar071d4272004-06-13 20:20:40 +00008968 /* set 'delcombine' */
8969 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008970
8971# ifdef FEAT_KEYMAP
8972 /* Force-set the necessary keymap for arabic */
8973 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8974 OPT_LOCAL);
8975# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976 }
8977 else
8978 {
8979 /*
8980 * 'arabic' is reset, handle various sub-settings.
8981 */
8982 if (!p_tbidi)
8983 {
8984 /* reset rightleft mode */
8985 if (curwin->w_p_rl)
8986 {
8987 curwin->w_p_rl = FALSE;
8988 changed_window_setting();
8989 }
8990
8991 /* 'arabicshape' isn't reset, it is a global option and
8992 * another window may still need it "on". */
8993 }
8994
8995 /* 'delcombine' isn't reset, it is a global option and another
8996 * window may still want it "on". */
8997
8998# ifdef FEAT_KEYMAP
8999 /* Revert to the default keymap */
9000 curbuf->b_p_iminsert = B_IMODE_NONE;
9001 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
9002# endif
9003 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00009004 }
9005
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00009006#endif
9007
Bram Moolenaar44826212019-08-22 21:23:20 +02009008#if defined(FEAT_SIGNS) && defined(FEAT_GUI)
9009 else if (((int *)varp == &curwin->w_p_nu
9010 || (int *)varp == &curwin->w_p_rnu)
9011 && gui.in_use
9012 && (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) == 'u')
9013 && curbuf->b_signlist != NULL)
9014 {
9015 // If the 'number' or 'relativenumber' options are modified and
9016 // 'signcolumn' is set to 'number', then clear the screen for a full
9017 // refresh. Otherwise the sign icons are not displayed properly in the
9018 // number column. If the 'number' option is set and only the
9019 // 'relativenumber' option is toggled, then don't refresh the screen
9020 // (optimization).
9021 if (!(curwin->w_p_nu && ((int *)varp == &curwin->w_p_rnu)))
9022 redraw_all_later(CLEAR);
9023 }
9024#endif
9025
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009026#ifdef FEAT_TERMGUICOLORS
9027 /* 'termguicolors' */
9028 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009029 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009030# ifdef FEAT_VTP
9031 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02009032 if (
9033# ifdef VIMDLL
9034 !gui.in_use && !gui.starting &&
9035# endif
9036 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009037 {
9038 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01009039 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009040 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009041 if (is_term_win32())
9042 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009043# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009044# ifdef FEAT_GUI
9045 if (!gui.in_use && !gui.starting)
9046# endif
9047 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009048# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009049 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009050 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009051 {
9052 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009053 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009054 init_highlight(TRUE, FALSE);
9055 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009056# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009057 }
9058#endif
9059
Bram Moolenaar071d4272004-06-13 20:20:40 +00009060 /*
9061 * End of handling side effects for bool options.
9062 */
9063
Bram Moolenaar53744302015-07-17 17:38:22 +02009064 /* after handling side effects, call autocommand */
9065
Bram Moolenaar071d4272004-06-13 20:20:40 +00009066 options[opt_idx].flags |= P_WAS_SET;
9067
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009068#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009069 // Don't do this while starting up or recursively.
9070 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009071 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009072 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009073
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009074 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009075 vim_snprintf((char *)buf_old_global, 2, "%d",
9076 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009077 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009078 vim_snprintf((char *)buf_type, 7, "%s",
9079 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009080 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9081 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9082 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009083 if (opt_flags & OPT_LOCAL)
9084 {
9085 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9086 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9087 }
9088 if (opt_flags & OPT_GLOBAL)
9089 {
9090 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9091 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9092 }
9093 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9094 {
9095 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9096 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9097 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9098 }
9099 if (opt_flags & OPT_MODELINE)
9100 {
9101 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9102 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9103 }
9104 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9105 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009106 reset_v_option_vars();
9107 }
9108#endif
9109
Bram Moolenaar071d4272004-06-13 20:20:40 +00009110 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009111 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009112 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009113 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009114 check_redraw(options[opt_idx].flags);
9115
9116 return NULL;
9117}
9118
9119/*
9120 * Set the value of a number option, and take care of side effects.
9121 * Returns NULL for success, or an error message for an error.
9122 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009123 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009124set_num_option(
9125 int opt_idx, /* index in options[] table */
9126 char_u *varp, /* pointer to the option variable */
9127 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009128 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009129 size_t errbuflen, /* length of "errbuf" */
9130 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009131 OPT_MODELINE */
9132{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009133 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009134 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009135#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009136 long old_global_value = 0; // only used when setting a local and
9137 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009138#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009139 long old_Rows = Rows; // remember old Rows
9140 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00009141 long *pp = (long *)varp;
9142
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009143 /* Disallow changing some options from secure mode. */
9144 if ((secure
9145#ifdef HAVE_SANDBOX
9146 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009147#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009148 ) && (options[opt_idx].flags & P_SECURE))
9149 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009150
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009151#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009152 // Save the global value before changing anything. This is needed as for
9153 // a global-only option setting the "local value" infact sets the global
9154 // value (since there is only one value).
9155 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009156 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
9157 OPT_GLOBAL);
9158#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009159
Bram Moolenaar071d4272004-06-13 20:20:40 +00009160 *pp = value;
9161#ifdef FEAT_EVAL
9162 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009163 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009164#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009165#ifdef FEAT_GUI
9166 need_mouse_correct = TRUE;
9167#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009168
Bram Moolenaar14f24742012-08-08 18:01:05 +02009169 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009170 {
9171 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009172#ifdef FEAT_VARTABS
9173 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9174 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9175 ? tabstop_first(curbuf->b_p_vts_array)
9176 : curbuf->b_p_ts;
9177#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009178 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009179#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009180 }
9181
9182 /*
9183 * Number options that need some action when changed
9184 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009185 if (pp == &p_wh || pp == &p_hh)
9186 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009187 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009188 if (p_wh < 1)
9189 {
9190 errmsg = e_positive;
9191 p_wh = 1;
9192 }
9193 if (p_wmh > p_wh)
9194 {
9195 errmsg = e_winheight;
9196 p_wh = p_wmh;
9197 }
9198 if (p_hh < 0)
9199 {
9200 errmsg = e_positive;
9201 p_hh = 0;
9202 }
9203
9204 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009205 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206 {
9207 if (pp == &p_wh && curwin->w_height < p_wh)
9208 win_setheight((int)p_wh);
9209 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9210 win_setheight((int)p_hh);
9211 }
9212 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213 else if (pp == &p_wmh)
9214 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009215 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009216 if (p_wmh < 0)
9217 {
9218 errmsg = e_positive;
9219 p_wmh = 0;
9220 }
9221 if (p_wmh > p_wh)
9222 {
9223 errmsg = e_winheight;
9224 p_wmh = p_wh;
9225 }
9226 win_setminheight();
9227 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009228 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009229 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009230 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231 if (p_wiw < 1)
9232 {
9233 errmsg = e_positive;
9234 p_wiw = 1;
9235 }
9236 if (p_wmw > p_wiw)
9237 {
9238 errmsg = e_winwidth;
9239 p_wiw = p_wmw;
9240 }
9241
9242 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009243 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009244 win_setwidth((int)p_wiw);
9245 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009246 else if (pp == &p_wmw)
9247 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009248 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009249 if (p_wmw < 0)
9250 {
9251 errmsg = e_positive;
9252 p_wmw = 0;
9253 }
9254 if (p_wmw > p_wiw)
9255 {
9256 errmsg = e_winwidth;
9257 p_wmw = p_wiw;
9258 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009259 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009260 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009261
Bram Moolenaar071d4272004-06-13 20:20:40 +00009262 /* (re)set last window status line */
9263 else if (pp == &p_ls)
9264 {
9265 last_status(FALSE);
9266 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009267
9268 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009269 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009270 {
9271 shell_new_rows(); /* recompute window positions and heights */
9272 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009273
9274#ifdef FEAT_GUI
9275 else if (pp == &p_linespace)
9276 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009277 /* Recompute gui.char_height and resize the Vim window to keep the
9278 * same number of lines. */
9279 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009280 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009281 }
9282#endif
9283
9284#ifdef FEAT_FOLDING
9285 /* 'foldlevel' */
9286 else if (pp == &curwin->w_p_fdl)
9287 {
9288 if (curwin->w_p_fdl < 0)
9289 curwin->w_p_fdl = 0;
9290 newFoldLevel();
9291 }
9292
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009293 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009294 else if (pp == &curwin->w_p_fml)
9295 {
9296 foldUpdateAll(curwin);
9297 }
9298
9299 /* 'foldnestmax' */
9300 else if (pp == &curwin->w_p_fdn)
9301 {
9302 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9303 foldUpdateAll(curwin);
9304 }
9305
9306 /* 'foldcolumn' */
9307 else if (pp == &curwin->w_p_fdc)
9308 {
9309 if (curwin->w_p_fdc < 0)
9310 {
9311 errmsg = e_positive;
9312 curwin->w_p_fdc = 0;
9313 }
9314 else if (curwin->w_p_fdc > 12)
9315 {
9316 errmsg = e_invarg;
9317 curwin->w_p_fdc = 12;
9318 }
9319 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009320#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009321
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009322#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009323 /* 'shiftwidth' or 'tabstop' */
9324 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9325 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009326# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009327 if (foldmethodIsIndent(curwin))
9328 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009329# endif
9330# ifdef FEAT_CINDENT
9331 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9332 * parse 'cinoptions'. */
9333 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9334 parse_cino(curbuf);
9335# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009336 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009337#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009338
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009339 /* 'maxcombine' */
9340 else if (pp == &p_mco)
9341 {
9342 if (p_mco > MAX_MCO)
9343 p_mco = MAX_MCO;
9344 else if (p_mco < 0)
9345 p_mco = 0;
9346 screenclear(); /* will re-allocate the screen */
9347 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009348
Bram Moolenaar071d4272004-06-13 20:20:40 +00009349 else if (pp == &curbuf->b_p_iminsert)
9350 {
9351 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9352 {
9353 errmsg = e_invarg;
9354 curbuf->b_p_iminsert = B_IMODE_NONE;
9355 }
9356 p_iminsert = curbuf->b_p_iminsert;
9357 if (termcap_active) /* don't do this in the alternate screen */
9358 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009359#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009360 /* Show/unshow value of 'keymap' in status lines. */
9361 status_redraw_curbuf();
9362#endif
9363 }
9364
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009365#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9366 /* 'imstyle' */
9367 else if (pp == &p_imst)
9368 {
9369 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9370 errmsg = e_invarg;
9371 }
9372#endif
9373
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009374 else if (pp == &p_window)
9375 {
9376 if (p_window < 1)
9377 p_window = 1;
9378 else if (p_window >= Rows)
9379 p_window = Rows - 1;
9380 }
9381
Bram Moolenaar071d4272004-06-13 20:20:40 +00009382 else if (pp == &curbuf->b_p_imsearch)
9383 {
9384 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9385 {
9386 errmsg = e_invarg;
9387 curbuf->b_p_imsearch = B_IMODE_NONE;
9388 }
9389 p_imsearch = curbuf->b_p_imsearch;
9390 }
9391
9392#ifdef FEAT_TITLE
9393 /* if 'titlelen' has changed, redraw the title */
9394 else if (pp == &p_titlelen)
9395 {
9396 if (p_titlelen < 0)
9397 {
9398 errmsg = e_positive;
9399 p_titlelen = 85;
9400 }
9401 if (starting != NO_SCREEN && old_value != p_titlelen)
9402 need_maketitle = TRUE;
9403 }
9404#endif
9405
9406 /* if p_ch changed value, change the command line height */
9407 else if (pp == &p_ch)
9408 {
9409 if (p_ch < 1)
9410 {
9411 errmsg = e_positive;
9412 p_ch = 1;
9413 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009414 if (p_ch > Rows - min_rows() + 1)
9415 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009416
9417 /* Only compute the new window layout when startup has been
9418 * completed. Otherwise the frame sizes may be wrong. */
9419 if (p_ch != old_value && full_screen
9420#ifdef FEAT_GUI
9421 && !gui.starting
9422#endif
9423 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009424 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009425 }
9426
9427 /* when 'updatecount' changes from zero to non-zero, open swap files */
9428 else if (pp == &p_uc)
9429 {
9430 if (p_uc < 0)
9431 {
9432 errmsg = e_positive;
9433 p_uc = 100;
9434 }
9435 if (p_uc && !old_value)
9436 ml_open_files();
9437 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009438#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009439 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009440 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009441 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009442 {
9443 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009444 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009445 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009446 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009447 {
9448 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009449 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009450 }
9451 }
9452#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009453#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009454 else if (pp == &p_mzq)
9455 mzvim_reset_timer();
9456#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009457
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009458#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9459 /* 'pyxversion' */
9460 else if (pp == &p_pyx)
9461 {
9462 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9463 errmsg = e_invarg;
9464 }
9465#endif
9466
Bram Moolenaar071d4272004-06-13 20:20:40 +00009467 /* sync undo before 'undolevels' changes */
9468 else if (pp == &p_ul)
9469 {
9470 /* use the old value, otherwise u_sync() may not work properly */
9471 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009472 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009473 p_ul = value;
9474 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009475 else if (pp == &curbuf->b_p_ul)
9476 {
9477 /* use the old value, otherwise u_sync() may not work properly */
9478 curbuf->b_p_ul = old_value;
9479 u_sync(TRUE);
9480 curbuf->b_p_ul = value;
9481 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009482
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009483#ifdef FEAT_LINEBREAK
9484 /* 'numberwidth' must be positive */
9485 else if (pp == &curwin->w_p_nuw)
9486 {
9487 if (curwin->w_p_nuw < 1)
9488 {
9489 errmsg = e_positive;
9490 curwin->w_p_nuw = 1;
9491 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009492 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009493 {
9494 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009495 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009496 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009497 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009498 }
9499#endif
9500
Bram Moolenaar1a384422010-07-14 19:53:30 +02009501 else if (pp == &curbuf->b_p_tw)
9502 {
9503 if (curbuf->b_p_tw < 0)
9504 {
9505 errmsg = e_positive;
9506 curbuf->b_p_tw = 0;
9507 }
9508#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009509 {
9510 win_T *wp;
9511 tabpage_T *tp;
9512
9513 FOR_ALL_TAB_WINDOWS(tp, wp)
9514 check_colorcolumn(wp);
9515 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009516#endif
9517 }
9518
Bram Moolenaar071d4272004-06-13 20:20:40 +00009519 /*
9520 * Check the bounds for numeric options here
9521 */
9522 if (Rows < min_rows() && full_screen)
9523 {
9524 if (errbuf != NULL)
9525 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009526 vim_snprintf((char *)errbuf, errbuflen,
9527 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009528 errmsg = errbuf;
9529 }
9530 Rows = min_rows();
9531 }
9532 if (Columns < MIN_COLUMNS && full_screen)
9533 {
9534 if (errbuf != NULL)
9535 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009536 vim_snprintf((char *)errbuf, errbuflen,
9537 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009538 errmsg = errbuf;
9539 }
9540 Columns = MIN_COLUMNS;
9541 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009542 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009543
Bram Moolenaar071d4272004-06-13 20:20:40 +00009544 /*
9545 * If the screen (shell) height has been changed, assume it is the
9546 * physical screenheight.
9547 */
9548 if (old_Rows != Rows || old_Columns != Columns)
9549 {
9550 /* Changing the screen size is not allowed while updating the screen. */
9551 if (updating_screen)
9552 *pp = old_value;
9553 else if (full_screen
9554#ifdef FEAT_GUI
9555 && !gui.starting
9556#endif
9557 )
9558 set_shellsize((int)Columns, (int)Rows, TRUE);
9559 else
9560 {
9561 /* Postpone the resizing; check the size and cmdline position for
9562 * messages. */
9563 check_shellsize();
9564 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9565 cmdline_row = Rows - p_ch;
9566 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009567 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009568 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009569 }
9570
Bram Moolenaar071d4272004-06-13 20:20:40 +00009571 if (curbuf->b_p_ts <= 0)
9572 {
9573 errmsg = e_positive;
9574 curbuf->b_p_ts = 8;
9575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009576 if (p_tm < 0)
9577 {
9578 errmsg = e_positive;
9579 p_tm = 0;
9580 }
9581 if ((curwin->w_p_scr <= 0
9582 || (curwin->w_p_scr > curwin->w_height
9583 && curwin->w_height > 0))
9584 && full_screen)
9585 {
9586 if (pp == &(curwin->w_p_scr))
9587 {
9588 if (curwin->w_p_scr != 0)
9589 errmsg = e_scroll;
9590 win_comp_scroll(curwin);
9591 }
9592 /* If 'scroll' became invalid because of a side effect silently adjust
9593 * it. */
9594 else if (curwin->w_p_scr <= 0)
9595 curwin->w_p_scr = 1;
9596 else /* curwin->w_p_scr > curwin->w_height */
9597 curwin->w_p_scr = curwin->w_height;
9598 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009599 if (p_hi < 0)
9600 {
9601 errmsg = e_positive;
9602 p_hi = 0;
9603 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009604 else if (p_hi > 10000)
9605 {
9606 errmsg = e_invarg;
9607 p_hi = 10000;
9608 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009609 if (p_re < 0 || p_re > 2)
9610 {
9611 errmsg = e_invarg;
9612 p_re = 0;
9613 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009614 if (p_report < 0)
9615 {
9616 errmsg = e_positive;
9617 p_report = 1;
9618 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009619 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009620 {
9621 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9622 p_sj = Rows / 2;
9623 else
9624 {
9625 errmsg = e_scroll;
9626 p_sj = 1;
9627 }
9628 }
9629 if (p_so < 0 && full_screen)
9630 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009631 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009632 p_so = 0;
9633 }
9634 if (p_siso < 0 && full_screen)
9635 {
9636 errmsg = e_positive;
9637 p_siso = 0;
9638 }
9639#ifdef FEAT_CMDWIN
9640 if (p_cwh < 1)
9641 {
9642 errmsg = e_positive;
9643 p_cwh = 1;
9644 }
9645#endif
9646 if (p_ut < 0)
9647 {
9648 errmsg = e_positive;
9649 p_ut = 2000;
9650 }
9651 if (p_ss < 0)
9652 {
9653 errmsg = e_positive;
9654 p_ss = 0;
9655 }
9656
9657 /* May set global value for local option. */
9658 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9659 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9660
9661 options[opt_idx].flags |= P_WAS_SET;
9662
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009663#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009664 // Don't do this while starting up, failure or recursively.
9665 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009666 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009667 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009668 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009669 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009670 vim_snprintf((char *)buf_new, 10, "%ld", value);
9671 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009672 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9673 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9674 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009675 if (opt_flags & OPT_LOCAL)
9676 {
9677 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9678 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9679 }
9680 if (opt_flags & OPT_GLOBAL)
9681 {
9682 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9683 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9684 }
9685 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9686 {
9687 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9688 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9689 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9690 }
9691 if (opt_flags & OPT_MODELINE)
9692 {
9693 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9694 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9695 }
9696 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9697 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009698 reset_v_option_vars();
9699 }
9700#endif
9701
Bram Moolenaar071d4272004-06-13 20:20:40 +00009702 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009703 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009704 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009705 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009706 check_redraw(options[opt_idx].flags);
9707
9708 return errmsg;
9709}
9710
9711/*
9712 * Called after an option changed: check if something needs to be redrawn.
9713 */
9714 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009715check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009716{
9717 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009718 int doclear = (flags & P_RCLR) == P_RCLR;
9719 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009720
Bram Moolenaar071d4272004-06-13 20:20:40 +00009721 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9722 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009723
9724 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9725 changed_window_setting();
9726 if (flags & P_RBUF)
9727 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009728 if (flags & P_RWINONLY)
9729 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009730 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009731 redraw_all_later(CLEAR);
9732 else if (all)
9733 redraw_all_later(NOT_VALID);
9734}
9735
9736/*
9737 * Find index for option 'arg'.
9738 * Return -1 if not found.
9739 */
9740 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009741findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009742{
9743 int opt_idx;
9744 char *s, *p;
9745 static short quick_tab[27] = {0, 0}; /* quick access table */
9746 int is_term_opt;
9747
9748 /*
9749 * For first call: Initialize the quick-access table.
9750 * It contains the index for the first option that starts with a certain
9751 * letter. There are 26 letters, plus the first "t_" option.
9752 */
9753 if (quick_tab[1] == 0)
9754 {
9755 p = options[0].fullname;
9756 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9757 {
9758 if (s[0] != p[0])
9759 {
9760 if (s[0] == 't' && s[1] == '_')
9761 quick_tab[26] = opt_idx;
9762 else
9763 quick_tab[CharOrdLow(s[0])] = opt_idx;
9764 }
9765 p = s;
9766 }
9767 }
9768
9769 /*
9770 * Check for name starting with an illegal character.
9771 */
9772#ifdef EBCDIC
9773 if (!islower(arg[0]))
9774#else
9775 if (arg[0] < 'a' || arg[0] > 'z')
9776#endif
9777 return -1;
9778
9779 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9780 if (is_term_opt)
9781 opt_idx = quick_tab[26];
9782 else
9783 opt_idx = quick_tab[CharOrdLow(arg[0])];
9784 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9785 {
9786 if (STRCMP(arg, s) == 0) /* match full name */
9787 break;
9788 }
9789 if (s == NULL && !is_term_opt)
9790 {
9791 opt_idx = quick_tab[CharOrdLow(arg[0])];
9792 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9793 {
9794 s = options[opt_idx].shortname;
9795 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9796 break;
9797 s = NULL;
9798 }
9799 }
9800 if (s == NULL)
9801 opt_idx = -1;
9802 return opt_idx;
9803}
9804
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009805#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009806/*
9807 * Get the value for an option.
9808 *
9809 * Returns:
9810 * Number or Toggle option: 1, *numval gets value.
9811 * String option: 0, *stringval gets allocated string.
9812 * Hidden Number or Toggle option: -1.
9813 * hidden String option: -2.
9814 * unknown option: -3.
9815 */
9816 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009817get_option_value(
9818 char_u *name,
9819 long *numval,
9820 char_u **stringval, /* NULL when only checking existence */
9821 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009822{
9823 int opt_idx;
9824 char_u *varp;
9825
9826 opt_idx = findoption(name);
9827 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009828 {
9829 int key;
9830
9831 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009832 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009833 {
9834 char_u key_name[2];
9835 char_u *p;
9836
9837 if (key < 0)
9838 {
9839 key_name[0] = KEY2TERMCAP0(key);
9840 key_name[1] = KEY2TERMCAP1(key);
9841 }
9842 else
9843 {
9844 key_name[0] = KS_KEY;
9845 key_name[1] = (key & 0xff);
9846 }
9847 p = find_termcode(key_name);
9848 if (p != NULL)
9849 {
9850 if (stringval != NULL)
9851 *stringval = vim_strsave(p);
9852 return 0;
9853 }
9854 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009855 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009857
9858 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9859
9860 if (options[opt_idx].flags & P_STRING)
9861 {
9862 if (varp == NULL) /* hidden option */
9863 return -2;
9864 if (stringval != NULL)
9865 {
9866#ifdef FEAT_CRYPT
9867 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009868 if ((char_u **)varp == &curbuf->b_p_key
9869 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009870 *stringval = vim_strsave((char_u *)"*****");
9871 else
9872#endif
9873 *stringval = vim_strsave(*(char_u **)(varp));
9874 }
9875 return 0;
9876 }
9877
9878 if (varp == NULL) /* hidden option */
9879 return -1;
9880 if (options[opt_idx].flags & P_NUM)
9881 *numval = *(long *)varp;
9882 else
9883 {
9884 /* Special case: 'modified' is b_changed, but we also want to consider
9885 * it set when 'ff' or 'fenc' changed. */
9886 if ((int *)varp == &curbuf->b_changed)
9887 *numval = curbufIsChanged();
9888 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009889 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009890 }
9891 return 1;
9892}
9893#endif
9894
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009895#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009896/*
9897 * Returns the option attributes and its value. Unlike the above function it
9898 * will return either global value or local value of the option depending on
9899 * what was requested, but it will never return global value if it was
9900 * requested to return local one and vice versa. Neither it will return
9901 * buffer-local value if it was requested to return window-local one.
9902 *
9903 * Pretends that option is absent if it is not present in the requested scope
9904 * (i.e. has no global, window-local or buffer-local value depending on
9905 * opt_type). Uses
9906 *
9907 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009908 * 0 hidden or unknown option, also option that does not have requested
9909 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009910 * see SOPT_* in vim.h for other flags
9911 *
9912 * Possible opt_type values: see SREQ_* in vim.h
9913 */
9914 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009915get_option_value_strict(
9916 char_u *name,
9917 long *numval,
9918 char_u **stringval, /* NULL when only obtaining attributes */
9919 int opt_type,
9920 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009921{
9922 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009923 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009924 struct vimoption *p;
9925 int r = 0;
9926
9927 opt_idx = findoption(name);
9928 if (opt_idx < 0)
9929 return 0;
9930
9931 p = &(options[opt_idx]);
9932
9933 /* Hidden option */
9934 if (p->var == NULL)
9935 return 0;
9936
9937 if (p->flags & P_BOOL)
9938 r |= SOPT_BOOL;
9939 else if (p->flags & P_NUM)
9940 r |= SOPT_NUM;
9941 else if (p->flags & P_STRING)
9942 r |= SOPT_STRING;
9943
9944 if (p->indir == PV_NONE)
9945 {
9946 if (opt_type == SREQ_GLOBAL)
9947 r |= SOPT_GLOBAL;
9948 else
9949 return 0; /* Did not request global-only option */
9950 }
9951 else
9952 {
9953 if (p->indir & PV_BOTH)
9954 r |= SOPT_GLOBAL;
9955 else if (opt_type == SREQ_GLOBAL)
9956 return 0; /* Requested global option */
9957
9958 if (p->indir & PV_WIN)
9959 {
9960 if (opt_type == SREQ_BUF)
9961 return 0; /* Did not request window-local option */
9962 else
9963 r |= SOPT_WIN;
9964 }
9965 else if (p->indir & PV_BUF)
9966 {
9967 if (opt_type == SREQ_WIN)
9968 return 0; /* Did not request buffer-local option */
9969 else
9970 r |= SOPT_BUF;
9971 }
9972 }
9973
9974 if (stringval == NULL)
9975 return r;
9976
9977 if (opt_type == SREQ_GLOBAL)
9978 varp = p->var;
9979 else
9980 {
9981 if (opt_type == SREQ_BUF)
9982 {
9983 /* Special case: 'modified' is b_changed, but we also want to
9984 * consider it set when 'ff' or 'fenc' changed. */
9985 if (p->indir == PV_MOD)
9986 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009987 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009988 varp = NULL;
9989 }
9990#ifdef FEAT_CRYPT
9991 else if (p->indir == PV_KEY)
9992 {
9993 /* never return the value of the crypt key */
9994 *stringval = NULL;
9995 varp = NULL;
9996 }
9997#endif
9998 else
9999 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010000 buf_T *save_curbuf = curbuf;
10001
10002 // only getting a pointer, no need to use aucmd_prepbuf()
10003 curbuf = (buf_T *)from;
10004 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010005 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +020010006 curbuf = save_curbuf;
10007 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010008 }
10009 }
10010 else if (opt_type == SREQ_WIN)
10011 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010012 win_T *save_curwin = curwin;
10013
10014 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010015 curbuf = curwin->w_buffer;
10016 varp = get_varp(p);
10017 curwin = save_curwin;
10018 curbuf = curwin->w_buffer;
10019 }
10020 if (varp == p->var)
10021 return (r | SOPT_UNSET);
10022 }
10023
10024 if (varp != NULL)
10025 {
10026 if (p->flags & P_STRING)
10027 *stringval = vim_strsave(*(char_u **)(varp));
10028 else if (p->flags & P_NUM)
10029 *numval = *(long *) varp;
10030 else
10031 *numval = *(int *)varp;
10032 }
10033
10034 return r;
10035}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010036
10037/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010038 * Iterate over options. First argument is a pointer to a pointer to a
10039 * structure inside options[] array, second is option type like in the above
10040 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010041 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010042 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010043 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010044 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010045 * first argument to NULL.
10046 *
10047 * Returns full option name for current option on each call.
10048 */
10049 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010050option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010051{
10052 struct vimoption *ret = NULL;
10053 do
10054 {
10055 if (*option == NULL)
10056 *option = (void *) options;
10057 else if (((struct vimoption *) (*option))->fullname == NULL)
10058 {
10059 *option = NULL;
10060 return NULL;
10061 }
10062 else
10063 *option = (void *) (((struct vimoption *) (*option)) + 1);
10064
10065 ret = ((struct vimoption *) (*option));
10066
10067 /* Hidden option */
10068 if (ret->var == NULL)
10069 {
10070 ret = NULL;
10071 continue;
10072 }
10073
10074 switch (opt_type)
10075 {
10076 case SREQ_GLOBAL:
10077 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
10078 ret = NULL;
10079 break;
10080 case SREQ_BUF:
10081 if (!(ret->indir & PV_BUF))
10082 ret = NULL;
10083 break;
10084 case SREQ_WIN:
10085 if (!(ret->indir & PV_WIN))
10086 ret = NULL;
10087 break;
10088 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +010010089 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010090 return NULL;
10091 }
10092 }
10093 while (ret == NULL);
10094
10095 return (char_u *)ret->fullname;
10096}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010097#endif
10098
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099/*
10100 * Set the value of option "name".
10101 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010102 *
10103 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010104 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010105 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010106set_option_value(
10107 char_u *name,
10108 long number,
10109 char_u *string,
10110 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010111{
10112 int opt_idx;
10113 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010114 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010115
10116 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010117 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010118 {
10119 int key;
10120
10121 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010122 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010123 {
10124 char_u key_name[2];
10125
10126 if (key < 0)
10127 {
10128 key_name[0] = KEY2TERMCAP0(key);
10129 key_name[1] = KEY2TERMCAP1(key);
10130 }
10131 else
10132 {
10133 key_name[0] = KS_KEY;
10134 key_name[1] = (key & 0xff);
10135 }
10136 add_termcode(key_name, string, FALSE);
10137 if (full_screen)
10138 ttest(FALSE);
10139 redraw_all_later(CLEAR);
10140 return NULL;
10141 }
10142
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010143 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +010010144 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010145 else
10146 {
10147 flags = options[opt_idx].flags;
10148#ifdef HAVE_SANDBOX
10149 /* Disallow changing some options in the sandbox */
10150 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010151 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010152 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010153 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010154 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010155#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010156 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010157 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010158 else
10159 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010160 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010161 if (varp != NULL) /* hidden option is not changed */
10162 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010163 if (number == 0 && string != NULL)
10164 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010165 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010166
10167 /* Either we are given a string or we are setting option
10168 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010169 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010170 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010171 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010172 {
10173 /* There's another character after zeros or the string
10174 * is empty. In both cases, we are trying to set a
10175 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010176 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010177 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010178 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010179
10180 }
10181 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010182 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010183 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010184 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010186 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010187 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010188 }
10189 }
10190 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010191 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010192}
10193
10194/*
10195 * Get the terminal code for a terminal option.
10196 * Returns NULL when not found.
10197 */
10198 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010199get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010200{
10201 int opt_idx;
10202 char_u *varp;
10203
10204 if (tname[0] != 't' || tname[1] != '_' ||
10205 tname[2] == NUL || tname[3] == NUL)
10206 return NULL;
10207 if ((opt_idx = findoption(tname)) >= 0)
10208 {
10209 varp = get_varp(&(options[opt_idx]));
10210 if (varp != NULL)
10211 varp = *(char_u **)(varp);
10212 return varp;
10213 }
10214 return find_termcode(tname + 2);
10215}
10216
10217 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010218get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010219{
10220 int i;
10221
10222 i = findoption((char_u *)"hl");
10223 if (i >= 0)
10224 return options[i].def_val[VI_DEFAULT];
10225 return (char_u *)NULL;
10226}
10227
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010228 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010229get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010230{
10231 int i;
10232
10233 i = findoption((char_u *)"enc");
10234 if (i >= 0)
10235 return options[i].def_val[VI_DEFAULT];
10236 return (char_u *)NULL;
10237}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010238
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239/*
10240 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010241 * When "has_lt" is true there is a '<' before "*arg_arg".
10242 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010243 */
10244 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010245find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010247 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010248 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010249 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010250
10251 /*
10252 * Don't use get_special_key_code() for t_xx, we don't want it to call
10253 * add_termcap_entry().
10254 */
10255 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10256 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010257 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010258 {
10259 --arg; /* put arg at the '<' */
10260 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010261 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010262 if (modifiers) /* can't handle modifiers here */
10263 key = 0;
10264 }
10265 return key;
10266}
10267
10268/*
10269 * if 'all' == 0: show changed options
10270 * if 'all' == 1: show all normal options
10271 * if 'all' == 2: show all terminal options
10272 */
10273 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010274showoptions(
10275 int all,
10276 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010277{
10278 struct vimoption *p;
10279 int col;
10280 int isterm;
10281 char_u *varp;
10282 struct vimoption **items;
10283 int item_count;
10284 int run;
10285 int row, rows;
10286 int cols;
10287 int i;
10288 int len;
10289
10290#define INC 20
10291#define GAP 3
10292
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010293 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010294 if (items == NULL)
10295 return;
10296
10297 /* Highlight title */
10298 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010299 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010300 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010301 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010303 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010304 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010305 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010306
10307 /*
10308 * do the loop two times:
10309 * 1. display the short items
10310 * 2. display the long items (only strings and numbers)
10311 */
10312 for (run = 1; run <= 2 && !got_int; ++run)
10313 {
10314 /*
10315 * collect the items in items[]
10316 */
10317 item_count = 0;
10318 for (p = &options[0]; p->fullname != NULL; p++)
10319 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010320 // apply :filter /pat/
10321 if (message_filtered((char_u *) p->fullname))
10322 continue;
10323
Bram Moolenaar071d4272004-06-13 20:20:40 +000010324 varp = NULL;
10325 isterm = istermoption(p);
10326 if (opt_flags != 0)
10327 {
10328 if (p->indir != PV_NONE && !isterm)
10329 varp = get_varp_scope(p, opt_flags);
10330 }
10331 else
10332 varp = get_varp(p);
10333 if (varp != NULL
10334 && ((all == 2 && isterm)
10335 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010336 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010337 {
10338 if (p->flags & P_BOOL)
10339 len = 1; /* a toggle option fits always */
10340 else
10341 {
10342 option_value2string(p, opt_flags);
10343 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10344 }
10345 if ((len <= INC - GAP && run == 1) ||
10346 (len > INC - GAP && run == 2))
10347 items[item_count++] = p;
10348 }
10349 }
10350
10351 /*
10352 * display the items
10353 */
10354 if (run == 1)
10355 {
10356 cols = (Columns + GAP - 3) / INC;
10357 if (cols == 0)
10358 cols = 1;
10359 rows = (item_count + cols - 1) / cols;
10360 }
10361 else /* run == 2 */
10362 rows = item_count;
10363 for (row = 0; row < rows && !got_int; ++row)
10364 {
10365 msg_putchar('\n'); /* go to next line */
10366 if (got_int) /* 'q' typed in more */
10367 break;
10368 col = 0;
10369 for (i = row; i < item_count; i += rows)
10370 {
10371 msg_col = col; /* make columns */
10372 showoneopt(items[i], opt_flags);
10373 col += INC;
10374 }
10375 out_flush();
10376 ui_breakcheck();
10377 }
10378 }
10379 vim_free(items);
10380}
10381
10382/*
10383 * Return TRUE if option "p" has its default value.
10384 */
10385 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010386optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010387{
10388 int dvi;
10389
10390 if (varp == NULL)
10391 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010392 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010393 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010394 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010395 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010396 /* the cast to long is required for Manx C, long_i is
10397 * needed for MSVC */
10398 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010399 /* P_STRING */
10400 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10401}
10402
10403/*
10404 * showoneopt: show the value of one option
10405 * must not be called with a hidden option!
10406 */
10407 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010408showoneopt(
10409 struct vimoption *p,
10410 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010411{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010412 char_u *varp;
10413 int save_silent = silent_mode;
10414
10415 silent_mode = FALSE;
10416 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010417
10418 varp = get_varp_scope(p, opt_flags);
10419
10420 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10421 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10422 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010423 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010424 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010425 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010426 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010427 msg_puts(" ");
10428 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429 if (!(p->flags & P_BOOL))
10430 {
10431 msg_putchar('=');
10432 /* put value string in NameBuff */
10433 option_value2string(p, opt_flags);
10434 msg_outtrans(NameBuff);
10435 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010436
10437 silent_mode = save_silent;
10438 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439}
10440
10441/*
10442 * Write modified options as ":set" commands to a file.
10443 *
10444 * There are three values for "opt_flags":
10445 * OPT_GLOBAL: Write global option values and fresh values of
10446 * buffer-local options (used for start of a session
10447 * file).
10448 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10449 * curwin (used for a vimrc file).
10450 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10451 * and local values for window-local options of
10452 * curwin. Local values are also written when at the
10453 * default value, because a modeline or autocommand
10454 * may have set them when doing ":edit file" and the
10455 * user has set them back at the default or fresh
10456 * value.
10457 * When "local_only" is TRUE, don't write fresh
10458 * values, only local values (for ":mkview").
10459 * (fresh value = value used for a new buffer or window for a local option).
10460 *
10461 * Return FAIL on error, OK otherwise.
10462 */
10463 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010464makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010465{
10466 struct vimoption *p;
10467 char_u *varp; /* currently used value */
10468 char_u *varp_fresh; /* local value */
10469 char_u *varp_local = NULL; /* fresh value */
10470 char *cmd;
10471 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010472 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010473
10474 /*
10475 * The options that don't have a default (terminal name, columns, lines)
10476 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010477 * Do the loop over "options[]" twice: once for options with the
10478 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010479 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010480 for (pri = 1; pri >= 0; --pri)
10481 {
10482 for (p = &options[0]; !istermoption(p); p++)
10483 if (!(p->flags & P_NO_MKRC)
10484 && !istermoption(p)
10485 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010486 {
10487 /* skip global option when only doing locals */
10488 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10489 continue;
10490
10491 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10492 * file, they are always buffer-specific. */
10493 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10494 continue;
10495
10496 /* Global values are only written when not at the default value. */
10497 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010498 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010499 continue;
10500
10501 round = 2;
10502 if (p->indir != PV_NONE)
10503 {
10504 if (p->var == VAR_WIN)
10505 {
10506 /* skip window-local option when only doing globals */
10507 if (!(opt_flags & OPT_LOCAL))
10508 continue;
10509 /* When fresh value of window-local option is not at the
10510 * default, need to write it too. */
10511 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10512 {
10513 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010514 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010515 {
10516 round = 1;
10517 varp_local = varp;
10518 varp = varp_fresh;
10519 }
10520 }
10521 }
10522 }
10523
10524 /* Round 1: fresh value for window-local options.
10525 * Round 2: other values */
10526 for ( ; round <= 2; varp = varp_local, ++round)
10527 {
10528 if (round == 1 || (opt_flags & OPT_GLOBAL))
10529 cmd = "set";
10530 else
10531 cmd = "setlocal";
10532
10533 if (p->flags & P_BOOL)
10534 {
10535 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10536 return FAIL;
10537 }
10538 else if (p->flags & P_NUM)
10539 {
10540 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10541 return FAIL;
10542 }
10543 else /* P_STRING */
10544 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010545 int do_endif = FALSE;
10546
Bram Moolenaar071d4272004-06-13 20:20:40 +000010547 /* Don't set 'syntax' and 'filetype' again if the value is
10548 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010549 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010550#if defined(FEAT_SYN_HL)
10551 p->indir == PV_SYN ||
10552#endif
10553 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010554 {
10555 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10556 *(char_u **)(varp)) < 0
10557 || put_eol(fd) < 0)
10558 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010559 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010560 }
10561 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010562 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010563 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010564 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010565 {
10566 if (put_line(fd, "endif") == FAIL)
10567 return FAIL;
10568 }
10569 }
10570 }
10571 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010572 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010573 return OK;
10574}
10575
10576#if defined(FEAT_FOLDING) || defined(PROTO)
10577/*
10578 * Generate set commands for the local fold options only. Used when
10579 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10580 */
10581 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010582makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010583{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010584 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010585# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010586 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010587 == FAIL
10588# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010589 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010590 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010591 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010592 == FAIL
10593 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10594 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10595 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10596 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10597 )
10598 return FAIL;
10599
10600 return OK;
10601}
10602#endif
10603
10604 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010605put_setstring(
10606 FILE *fd,
10607 char *cmd,
10608 char *name,
10609 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010610 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611{
10612 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010613 char_u *buf = NULL;
10614 char_u *part = NULL;
10615 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010616
10617 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10618 return FAIL;
10619 if (*valuep != NULL)
10620 {
10621 /* Output 'pastetoggle' as key names. For other
10622 * options some characters have to be escaped with
10623 * CTRL-V or backslash */
10624 if (valuep == &p_pt)
10625 {
10626 s = *valuep;
10627 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010628 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010629 return FAIL;
10630 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010631 // expand the option value, replace $HOME by ~
10632 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010633 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010634 int size = (int)STRLEN(*valuep) + 1;
10635
10636 // replace home directory in the whole option value into "buf"
10637 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010638 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010639 goto fail;
10640 home_replace(NULL, *valuep, buf, size, FALSE);
10641
10642 // If the option value is longer than MAXPATHL, we need to append
10643 // earch comma separated part of the option separately, so that it
10644 // can be expanded when read back.
10645 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10646 && vim_strchr(*valuep, ',') != NULL)
10647 {
10648 part = alloc(size);
10649 if (part == NULL)
10650 goto fail;
10651
10652 // write line break to clear the option, e.g. ':set rtp='
10653 if (put_eol(fd) == FAIL)
10654 goto fail;
10655
10656 p = buf;
10657 while (*p != NUL)
10658 {
10659 // for each comma separated option part, append value to
10660 // the option, :set rtp+=value
10661 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10662 goto fail;
10663 (void)copy_option_part(&p, part, size, ",");
10664 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10665 goto fail;
10666 }
10667 vim_free(buf);
10668 vim_free(part);
10669 return OK;
10670 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010671 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010672 {
10673 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010674 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010675 }
10676 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010677 }
10678 else if (put_escstr(fd, *valuep, 2) == FAIL)
10679 return FAIL;
10680 }
10681 if (put_eol(fd) < 0)
10682 return FAIL;
10683 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010684fail:
10685 vim_free(buf);
10686 vim_free(part);
10687 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688}
10689
10690 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010691put_setnum(
10692 FILE *fd,
10693 char *cmd,
10694 char *name,
10695 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010696{
10697 long wc;
10698
10699 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10700 return FAIL;
10701 if (wc_use_keyname((char_u *)valuep, &wc))
10702 {
10703 /* print 'wildchar' and 'wildcharm' as a key name */
10704 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10705 return FAIL;
10706 }
10707 else if (fprintf(fd, "%ld", *valuep) < 0)
10708 return FAIL;
10709 if (put_eol(fd) < 0)
10710 return FAIL;
10711 return OK;
10712}
10713
10714 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010715put_setbool(
10716 FILE *fd,
10717 char *cmd,
10718 char *name,
10719 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720{
Bram Moolenaar893de922007-10-02 18:40:57 +000010721 if (value < 0) /* global/local option using global value */
10722 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010723 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10724 || put_eol(fd) < 0)
10725 return FAIL;
10726 return OK;
10727}
10728
10729/*
10730 * Clear all the terminal options.
10731 * If the option has been allocated, free the memory.
10732 * Terminal options are never hidden or indirect.
10733 */
10734 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010735clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010736{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 /*
10738 * Reset a few things before clearing the old options. This may cause
10739 * outputting a few things that the terminal doesn't understand, but the
10740 * screen will be cleared later, so this is OK.
10741 */
10742#ifdef FEAT_MOUSE_TTY
10743 mch_setmouse(FALSE); /* switch mouse off */
10744#endif
10745#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010746 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010747#endif
10748#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10749 /* When starting the GUI close the display opened for the clipboard.
10750 * After restoring the title, because that will need the display. */
10751 if (gui.starting)
10752 clear_xterm_clip();
10753#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010754 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010756 free_termoptions();
10757}
10758
10759 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010760free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010761{
10762 struct vimoption *p;
10763
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010764 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010765 if (istermoption(p))
10766 {
10767 if (p->flags & P_ALLOCED)
10768 free_string_option(*(char_u **)(p->var));
10769 if (p->flags & P_DEF_ALLOCED)
10770 free_string_option(p->def_val[VI_DEFAULT]);
10771 *(char_u **)(p->var) = empty_option;
10772 p->def_val[VI_DEFAULT] = empty_option;
10773 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010774#ifdef FEAT_EVAL
10775 // remember where the option was cleared
10776 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10777#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010778 }
10779 clear_termcodes();
10780}
10781
10782/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010783 * Free the string for one term option, if it was allocated.
10784 * Set the string to empty_option and clear allocated flag.
10785 * "var" points to the option value.
10786 */
10787 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010788free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010789{
10790 struct vimoption *p;
10791
10792 for (p = &options[0]; p->fullname != NULL; p++)
10793 if (p->var == var)
10794 {
10795 if (p->flags & P_ALLOCED)
10796 free_string_option(*(char_u **)(p->var));
10797 *(char_u **)(p->var) = empty_option;
10798 p->flags &= ~P_ALLOCED;
10799 break;
10800 }
10801}
10802
10803/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010804 * Set the terminal option defaults to the current value.
10805 * Used after setting the terminal name.
10806 */
10807 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010808set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010809{
10810 struct vimoption *p;
10811
10812 for (p = &options[0]; p->fullname != NULL; p++)
10813 {
10814 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10815 {
10816 if (p->flags & P_DEF_ALLOCED)
10817 {
10818 free_string_option(p->def_val[VI_DEFAULT]);
10819 p->flags &= ~P_DEF_ALLOCED;
10820 }
10821 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10822 if (p->flags & P_ALLOCED)
10823 {
10824 p->flags |= P_DEF_ALLOCED;
10825 p->flags &= ~P_ALLOCED; /* don't free the value now */
10826 }
10827 }
10828 }
10829}
10830
10831/*
10832 * return TRUE if 'p' starts with 't_'
10833 */
10834 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010835istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010836{
10837 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10838}
10839
10840/*
10841 * Compute columns for ruler and shown command. 'sc_col' is also used to
10842 * decide what the maximum length of a message on the status line can be.
10843 * If there is a status line for the last window, 'sc_col' is independent
10844 * of 'ru_col'.
10845 */
10846
10847#define COL_RULER 17 /* columns needed by standard ruler */
10848
10849 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010850comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010852#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010853 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854
10855 sc_col = 0;
10856 ru_col = 0;
10857 if (p_ru)
10858 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010859# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010860 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010861# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010862 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010863# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864 /* no last status line, adjust sc_col */
10865 if (!last_has_status)
10866 sc_col = ru_col;
10867 }
10868 if (p_sc)
10869 {
10870 sc_col += SHOWCMD_COLS;
10871 if (!p_ru || last_has_status) /* no need for separating space */
10872 ++sc_col;
10873 }
10874 sc_col = Columns - sc_col;
10875 ru_col = Columns - ru_col;
10876 if (sc_col <= 0) /* screen too narrow, will become a mess */
10877 sc_col = 1;
10878 if (ru_col <= 0)
10879 ru_col = 1;
10880#else
10881 sc_col = Columns;
10882 ru_col = Columns;
10883#endif
10884}
10885
Bram Moolenaar113e1072019-01-20 15:30:40 +010010886#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010888 * Unset local option value, similar to ":set opt<".
10889 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010890 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010891unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010892{
10893 struct vimoption *p;
10894 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010895 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010896
10897 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010898 if (opt_idx < 0)
10899 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010900 p = &(options[opt_idx]);
10901
10902 switch ((int)p->indir)
10903 {
10904 /* global option with local value: use local value if it's been set */
10905 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010906 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010907 break;
10908 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010909 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010910 break;
10911 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010912 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010913 break;
10914 case PV_AR:
10915 buf->b_p_ar = -1;
10916 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010917 case PV_BKC:
10918 clear_string_option(&buf->b_p_bkc);
10919 buf->b_bkc_flags = 0;
10920 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010921 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010922 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010923 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010924 case PV_TC:
10925 clear_string_option(&buf->b_p_tc);
10926 buf->b_tc_flags = 0;
10927 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010928 case PV_SISO:
10929 curwin->w_p_siso = -1;
10930 break;
10931 case PV_SO:
10932 curwin->w_p_so = -1;
10933 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010934#ifdef FEAT_FIND_ID
10935 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010936 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010937 break;
10938 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010939 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010940 break;
10941#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010942 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010943 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010944 break;
10945 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010946 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010947 break;
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010948 case PV_FP:
10949 clear_string_option(&buf->b_p_fp);
10950 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010951#ifdef FEAT_QUICKFIX
10952 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010953 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010954 break;
10955 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010956 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010957 break;
10958 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010959 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010960 break;
10961#endif
10962#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10963 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010964 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010965 break;
10966#endif
10967#if defined(FEAT_CRYPT)
10968 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010969 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010970 break;
10971#endif
10972#ifdef FEAT_STL_OPT
10973 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010974 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010975 break;
10976#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010977 case PV_UL:
10978 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10979 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010980#ifdef FEAT_LISP
10981 case PV_LW:
10982 clear_string_option(&buf->b_p_lw);
10983 break;
10984#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010985 case PV_MENC:
10986 clear_string_option(&buf->b_p_menc);
10987 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010988 }
10989}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010990#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010991
10992/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010993 * Get pointer to option variable, depending on local or global scope.
10994 */
10995 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010996get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010997{
10998 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10999 {
11000 if (p->var == VAR_WIN)
11001 return (char_u *)GLOBAL_WO(get_varp(p));
11002 return p->var;
11003 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011004 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011005 {
11006 switch ((int)p->indir)
11007 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011008 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011009#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011010 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
11011 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
11012 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011013#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011014 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
11015 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
11016 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011017 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011018 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011019 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010011020 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
11021 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011022#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011023 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
11024 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011025#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011026 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
11027 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011028#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11029 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
11030#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011031#if defined(FEAT_CRYPT)
11032 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
11033#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011034#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011035 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011036#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011037 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011038#ifdef FEAT_LISP
11039 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
11040#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011041 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011042 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011043 }
11044 return NULL; /* "cannot happen" */
11045 }
11046 return get_varp(p);
11047}
11048
11049/*
11050 * Get pointer to option variable.
11051 */
11052 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011053get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054{
11055 /* hidden option, always return NULL */
11056 if (p->var == NULL)
11057 return NULL;
11058
11059 switch ((int)p->indir)
11060 {
11061 case PV_NONE: return p->var;
11062
11063 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011064 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011065 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011066 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011067 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011068 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011069 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011070 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000011071 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011072 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011074 case PV_TC: return *curbuf->b_p_tc != NUL
11075 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011076 case PV_BKC: return *curbuf->b_p_bkc != NUL
11077 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010011078 case PV_SISO: return curwin->w_p_siso >= 0
11079 ? (char_u *)&(curwin->w_p_siso) : p->var;
11080 case PV_SO: return curwin->w_p_so >= 0
11081 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011082#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011083 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011084 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011085 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011086 ? (char_u *)&(curbuf->b_p_inc) : p->var;
11087#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011088 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011089 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011090 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011092 case PV_FP: return *curbuf->b_p_fp != NUL
11093 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011094#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011095 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011097 case PV_GP: return *curbuf->b_p_gp != NUL
11098 ? (char_u *)&(curbuf->b_p_gp) : p->var;
11099 case PV_MP: return *curbuf->b_p_mp != NUL
11100 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011101#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011102#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11103 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
11104 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
11105#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011106#if defined(FEAT_CRYPT)
11107 case PV_CM: return *curbuf->b_p_cm != NUL
11108 ? (char_u *)&(curbuf->b_p_cm) : p->var;
11109#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011110#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011111 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011112 ? (char_u *)&(curwin->w_p_stl) : p->var;
11113#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011114 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
11115 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011116#ifdef FEAT_LISP
11117 case PV_LW: return *curbuf->b_p_lw != NUL
11118 ? (char_u *)&(curbuf->b_p_lw) : p->var;
11119#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011120 case PV_MENC: return *curbuf->b_p_menc != NUL
11121 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122#ifdef FEAT_ARABIC
11123 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
11124#endif
11125 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011126#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011127 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
11128#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011129#ifdef FEAT_SYN_HL
11130 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
11131 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011132 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011133#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011134#ifdef FEAT_DIFF
11135 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
11136#endif
11137#ifdef FEAT_FOLDING
11138 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
11139 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
11140 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
11141 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
11142 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
11143 case PV_FML: return (char_u *)&(curwin->w_p_fml);
11144 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
11145# ifdef FEAT_EVAL
11146 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11147 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11148# endif
11149 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11150#endif
11151 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011152 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011153#ifdef FEAT_LINEBREAK
11154 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11155#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011157 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011158#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011159 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11160#endif
11161#ifdef FEAT_RIGHTLEFT
11162 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11163 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11164#endif
11165 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11166 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11167#ifdef FEAT_LINEBREAK
11168 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011169 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11170 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011171#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011172 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011173 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011174 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011175#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011176 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11177 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11178#endif
11179#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011180 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11181 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11182 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011183#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011184
11185 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11186 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011187 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11189 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011190 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11191 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11192#ifdef FEAT_CINDENT
11193 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11194 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11195 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11196#endif
11197#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11198 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11199#endif
11200#ifdef FEAT_COMMENTS
11201 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11202#endif
11203#ifdef FEAT_FOLDING
11204 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11205#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaare2c453d2019-08-21 14:37:09 +020011207#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011208 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011209#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011210#ifdef FEAT_COMPL_FUNC
11211 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011212 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011213#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011214#ifdef FEAT_EVAL
11215 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11216#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011217 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011218 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011219 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011220 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011221 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011222 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011223 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011224 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11226 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11227 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11228 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11229#ifdef FEAT_FIND_ID
11230# ifdef FEAT_EVAL
11231 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11232# endif
11233#endif
11234#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11235 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11236 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11237#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011238#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011239 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11240#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011241#ifdef FEAT_CRYPT
11242 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11243#endif
11244#ifdef FEAT_LISP
11245 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11246#endif
11247 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11248 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11249 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11250 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11251 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011252 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011253#ifdef FEAT_TEXTOBJ
11254 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11255#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011256 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11257#ifdef FEAT_SMARTINDENT
11258 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11259#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011260 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011261 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11262#ifdef FEAT_SEARCHPATH
11263 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11264#endif
11265 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11266#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011267 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011268 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11269#endif
11270#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011271 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11272 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11273 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011274#endif
11275 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11276 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11277 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11278 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011279#ifdef FEAT_PERSISTENT_UNDO
11280 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11281#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011282 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11283#ifdef FEAT_KEYMAP
11284 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11285#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011286#ifdef FEAT_SIGNS
11287 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11288#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011289#ifdef FEAT_VARTABS
11290 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11291 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11292#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011293 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011294 }
11295 /* always return a valid pointer to avoid a crash! */
11296 return (char_u *)&(curbuf->b_p_wm);
11297}
11298
11299/*
11300 * Get the value of 'equalprg', either the buffer-local one or the global one.
11301 */
11302 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011303get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011304{
11305 if (*curbuf->b_p_ep == NUL)
11306 return p_ep;
11307 return curbuf->b_p_ep;
11308}
11309
Bram Moolenaar071d4272004-06-13 20:20:40 +000011310/*
11311 * Copy options from one window to another.
11312 * Used when splitting a window.
11313 */
11314 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011315win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316{
11317 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11318 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011319#if defined(FEAT_LINEBREAK)
11320 briopt_check(wp_to);
11321#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011322}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011323
11324/*
11325 * Copy the options from one winopt_T to another.
11326 * Doesn't free the old option values in "to", use clear_winopt() for that.
11327 * The 'scroll' option is not copied, because it depends on the window height.
11328 * The 'previewwindow' option is reset, there can be only one preview window.
11329 */
11330 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011331copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011332{
11333#ifdef FEAT_ARABIC
11334 to->wo_arab = from->wo_arab;
11335#endif
11336 to->wo_list = from->wo_list;
11337 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011338 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011339#ifdef FEAT_LINEBREAK
11340 to->wo_nuw = from->wo_nuw;
11341#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342#ifdef FEAT_RIGHTLEFT
11343 to->wo_rl = from->wo_rl;
11344 to->wo_rlc = vim_strsave(from->wo_rlc);
11345#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011346#ifdef FEAT_STL_OPT
11347 to->wo_stl = vim_strsave(from->wo_stl);
11348#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011349 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011350#ifdef FEAT_DIFF
11351 to->wo_wrap_save = from->wo_wrap_save;
11352#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353#ifdef FEAT_LINEBREAK
11354 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011355 to->wo_bri = from->wo_bri;
11356 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011357#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011358 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011359 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011360 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011361 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011362 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011363#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011364 to->wo_spell = from->wo_spell;
11365#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011366#ifdef FEAT_SYN_HL
11367 to->wo_cuc = from->wo_cuc;
11368 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011369 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011370#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011371#ifdef FEAT_DIFF
11372 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011373 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011374#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011375#ifdef FEAT_CONCEAL
11376 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011377 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011378#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011379#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011380 to->wo_twk = vim_strsave(from->wo_twk);
11381 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011382#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383#ifdef FEAT_FOLDING
11384 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011385 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011386 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011387 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011388 to->wo_fdi = vim_strsave(from->wo_fdi);
11389 to->wo_fml = from->wo_fml;
11390 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011391 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011392 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011393 to->wo_fdm_save = from->wo_diff_saved
11394 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011395 to->wo_fdn = from->wo_fdn;
11396# ifdef FEAT_EVAL
11397 to->wo_fde = vim_strsave(from->wo_fde);
11398 to->wo_fdt = vim_strsave(from->wo_fdt);
11399# endif
11400 to->wo_fmr = vim_strsave(from->wo_fmr);
11401#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011402#ifdef FEAT_SIGNS
11403 to->wo_scl = vim_strsave(from->wo_scl);
11404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011405 check_winopt(to); /* don't want NULL pointers */
11406}
11407
11408/*
11409 * Check string options in a window for a NULL value.
11410 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020011411 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011412check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011413{
11414 check_winopt(&win->w_onebuf_opt);
11415 check_winopt(&win->w_allbuf_opt);
11416}
11417
11418/*
11419 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11420 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011421 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011422check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011423{
11424#ifdef FEAT_FOLDING
11425 check_string_option(&wop->wo_fdi);
11426 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011427 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011428# ifdef FEAT_EVAL
11429 check_string_option(&wop->wo_fde);
11430 check_string_option(&wop->wo_fdt);
11431# endif
11432 check_string_option(&wop->wo_fmr);
11433#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011434#ifdef FEAT_SIGNS
11435 check_string_option(&wop->wo_scl);
11436#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011437#ifdef FEAT_RIGHTLEFT
11438 check_string_option(&wop->wo_rlc);
11439#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011440#ifdef FEAT_STL_OPT
11441 check_string_option(&wop->wo_stl);
11442#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011443#ifdef FEAT_SYN_HL
11444 check_string_option(&wop->wo_cc);
11445#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011446#ifdef FEAT_CONCEAL
11447 check_string_option(&wop->wo_cocu);
11448#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011449#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011450 check_string_option(&wop->wo_twk);
11451 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011452#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011453#ifdef FEAT_LINEBREAK
11454 check_string_option(&wop->wo_briopt);
11455#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011456 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011457}
11458
11459/*
11460 * Free the allocated memory inside a winopt_T.
11461 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011462 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011463clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011464{
11465#ifdef FEAT_FOLDING
11466 clear_string_option(&wop->wo_fdi);
11467 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011468 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011469# ifdef FEAT_EVAL
11470 clear_string_option(&wop->wo_fde);
11471 clear_string_option(&wop->wo_fdt);
11472# endif
11473 clear_string_option(&wop->wo_fmr);
11474#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011475#ifdef FEAT_SIGNS
11476 clear_string_option(&wop->wo_scl);
11477#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011478#ifdef FEAT_LINEBREAK
11479 clear_string_option(&wop->wo_briopt);
11480#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011481 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011482#ifdef FEAT_RIGHTLEFT
11483 clear_string_option(&wop->wo_rlc);
11484#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011485#ifdef FEAT_STL_OPT
11486 clear_string_option(&wop->wo_stl);
11487#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011488#ifdef FEAT_SYN_HL
11489 clear_string_option(&wop->wo_cc);
11490#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011491#ifdef FEAT_CONCEAL
11492 clear_string_option(&wop->wo_cocu);
11493#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011494#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011495 clear_string_option(&wop->wo_twk);
11496 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011497#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011498}
11499
11500/*
11501 * Copy global option values to local options for one buffer.
11502 * Used when creating a new buffer and sometimes when entering a buffer.
11503 * flags:
11504 * BCO_ENTER We will enter the buf buffer.
11505 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11506 * appropriate.
11507 * BCO_NOHELP Don't copy the values to a help buffer.
11508 */
11509 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011510buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011511{
11512 int should_copy = TRUE;
11513 char_u *save_p_isk = NULL; /* init for GCC */
11514 int dont_do_help;
11515 int did_isk = FALSE;
11516
11517 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011518 * Skip this when the option defaults have not been set yet. Happens when
11519 * main() allocates the first buffer.
11520 */
11521 if (p_cpo != NULL)
11522 {
11523 /*
11524 * Always copy when entering and 'cpo' contains 'S'.
11525 * Don't copy when already initialized.
11526 * Don't copy when 'cpo' contains 's' and not entering.
11527 * 'S' BCO_ENTER initialized 's' should_copy
11528 * yes yes X X TRUE
11529 * yes no yes X FALSE
11530 * no X yes X FALSE
11531 * X no no yes FALSE
11532 * X no no no TRUE
11533 * no yes no X TRUE
11534 */
11535 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11536 && (buf->b_p_initialized
11537 || (!(flags & BCO_ENTER)
11538 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11539 should_copy = FALSE;
11540
11541 if (should_copy || (flags & BCO_ALWAYS))
11542 {
11543 /* Don't copy the options specific to a help buffer when
11544 * BCO_NOHELP is given or the options were initialized already
11545 * (jumping back to a help file with CTRL-T or CTRL-O) */
11546 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11547 || buf->b_p_initialized;
11548 if (dont_do_help) /* don't free b_p_isk */
11549 {
11550 save_p_isk = buf->b_p_isk;
11551 buf->b_p_isk = NULL;
11552 }
11553 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011554 * Always free the allocated strings. If not already initialized,
11555 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011556 */
11557 if (!buf->b_p_initialized)
11558 {
11559 free_buf_options(buf, TRUE);
11560 buf->b_p_ro = FALSE; /* don't copy readonly */
11561 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011562 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011563 switch (*p_ffs)
11564 {
11565 case 'm':
11566 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11567 case 'd':
11568 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11569 case 'u':
11570 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11571 default:
11572 buf->b_p_ff = vim_strsave(p_ff);
11573 }
11574 if (buf->b_p_ff != NULL)
11575 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011576 buf->b_p_bh = empty_option;
11577 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011578 }
11579 else
11580 free_buf_options(buf, FALSE);
11581
11582 buf->b_p_ai = p_ai;
11583 buf->b_p_ai_nopaste = p_ai_nopaste;
11584 buf->b_p_sw = p_sw;
11585 buf->b_p_tw = p_tw;
11586 buf->b_p_tw_nopaste = p_tw_nopaste;
11587 buf->b_p_tw_nobin = p_tw_nobin;
11588 buf->b_p_wm = p_wm;
11589 buf->b_p_wm_nopaste = p_wm_nopaste;
11590 buf->b_p_wm_nobin = p_wm_nobin;
11591 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011592 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011593 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011594 buf->b_p_et = p_et;
11595 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011596 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011597 buf->b_p_ml = p_ml;
11598 buf->b_p_ml_nobin = p_ml_nobin;
11599 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011600 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011601 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaare2c453d2019-08-21 14:37:09 +020011602#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011603 buf->b_p_csl = vim_strsave(p_csl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011604#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011605#ifdef FEAT_COMPL_FUNC
11606 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011607 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011608#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011609#ifdef FEAT_EVAL
11610 buf->b_p_tfu = vim_strsave(p_tfu);
11611#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612 buf->b_p_sts = p_sts;
11613 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011614#ifdef FEAT_VARTABS
11615 buf->b_p_vsts = vim_strsave(p_vsts);
11616 if (p_vsts && p_vsts != empty_option)
11617 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11618 else
11619 buf->b_p_vsts_array = 0;
11620 buf->b_p_vsts_nopaste = p_vsts_nopaste
11621 ? vim_strsave(p_vsts_nopaste) : NULL;
11622#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011623 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011624#ifdef FEAT_COMMENTS
11625 buf->b_p_com = vim_strsave(p_com);
11626#endif
11627#ifdef FEAT_FOLDING
11628 buf->b_p_cms = vim_strsave(p_cms);
11629#endif
11630 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011631 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011632 buf->b_p_nf = vim_strsave(p_nf);
11633 buf->b_p_mps = vim_strsave(p_mps);
11634#ifdef FEAT_SMARTINDENT
11635 buf->b_p_si = p_si;
11636#endif
11637 buf->b_p_ci = p_ci;
11638#ifdef FEAT_CINDENT
11639 buf->b_p_cin = p_cin;
11640 buf->b_p_cink = vim_strsave(p_cink);
11641 buf->b_p_cino = vim_strsave(p_cino);
11642#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011643 /* Don't copy 'filetype', it must be detected */
11644 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011645 buf->b_p_pi = p_pi;
11646#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11647 buf->b_p_cinw = vim_strsave(p_cinw);
11648#endif
11649#ifdef FEAT_LISP
11650 buf->b_p_lisp = p_lisp;
11651#endif
11652#ifdef FEAT_SYN_HL
11653 /* Don't copy 'syntax', it must be set */
11654 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011655 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011656 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011657#endif
11658#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011659 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011660 (void)compile_cap_prog(&buf->b_s);
11661 buf->b_s.b_p_spf = vim_strsave(p_spf);
11662 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011663#endif
11664#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11665 buf->b_p_inde = vim_strsave(p_inde);
11666 buf->b_p_indk = vim_strsave(p_indk);
11667#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011668 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011669#if defined(FEAT_EVAL)
11670 buf->b_p_fex = vim_strsave(p_fex);
11671#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011672#ifdef FEAT_CRYPT
11673 buf->b_p_key = vim_strsave(p_key);
11674#endif
11675#ifdef FEAT_SEARCHPATH
11676 buf->b_p_sua = vim_strsave(p_sua);
11677#endif
11678#ifdef FEAT_KEYMAP
11679 buf->b_p_keymap = vim_strsave(p_keymap);
11680 buf->b_kmap_state |= KEYMAP_INIT;
11681#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011682#ifdef FEAT_TERMINAL
11683 buf->b_p_twsl = p_twsl;
11684#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011685 /* This isn't really an option, but copying the langmap and IME
11686 * state from the current buffer is better than resetting it. */
11687 buf->b_p_iminsert = p_iminsert;
11688 buf->b_p_imsearch = p_imsearch;
11689
11690 /* options that are normally global but also have a local value
11691 * are not copied, start using the global value */
11692 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011693 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011694 buf->b_p_bkc = empty_option;
11695 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011696#ifdef FEAT_QUICKFIX
11697 buf->b_p_gp = empty_option;
11698 buf->b_p_mp = empty_option;
11699 buf->b_p_efm = empty_option;
11700#endif
11701 buf->b_p_ep = empty_option;
11702 buf->b_p_kp = empty_option;
11703 buf->b_p_path = empty_option;
11704 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011705 buf->b_p_tc = empty_option;
11706 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011707#ifdef FEAT_FIND_ID
11708 buf->b_p_def = empty_option;
11709 buf->b_p_inc = empty_option;
11710# ifdef FEAT_EVAL
11711 buf->b_p_inex = vim_strsave(p_inex);
11712# endif
11713#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011714 buf->b_p_dict = empty_option;
11715 buf->b_p_tsr = empty_option;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011716#ifdef FEAT_TEXTOBJ
11717 buf->b_p_qe = vim_strsave(p_qe);
11718#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011719#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11720 buf->b_p_bexpr = empty_option;
11721#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011722#if defined(FEAT_CRYPT)
11723 buf->b_p_cm = empty_option;
11724#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011725#ifdef FEAT_PERSISTENT_UNDO
11726 buf->b_p_udf = p_udf;
11727#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011728#ifdef FEAT_LISP
11729 buf->b_p_lw = empty_option;
11730#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011731 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011732
11733 /*
11734 * Don't copy the options set by ex_help(), use the saved values,
11735 * when going from a help buffer to a non-help buffer.
11736 * Don't touch these at all when BCO_NOHELP is used and going from
11737 * or to a help buffer.
11738 */
11739 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011740 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011741 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011742#ifdef FEAT_VARTABS
11743 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11744 tabstop_set(p_vts, &buf->b_p_vts_array);
11745 else
11746 buf->b_p_vts_array = NULL;
11747#endif
11748 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011749 else
11750 {
11751 buf->b_p_isk = vim_strsave(p_isk);
11752 did_isk = TRUE;
11753 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011754#ifdef FEAT_VARTABS
11755 buf->b_p_vts = vim_strsave(p_vts);
11756 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11757 tabstop_set(p_vts, &buf->b_p_vts_array);
11758 else
11759 buf->b_p_vts_array = NULL;
11760#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011761 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011762 if (buf->b_p_bt[0] == 'h')
11763 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011764 buf->b_p_ma = p_ma;
11765 }
11766 }
11767
11768 /*
11769 * When the options should be copied (ignoring BCO_ALWAYS), set the
11770 * flag that indicates that the options have been initialized.
11771 */
11772 if (should_copy)
11773 buf->b_p_initialized = TRUE;
11774 }
11775
11776 check_buf_options(buf); /* make sure we don't have NULLs */
11777 if (did_isk)
11778 (void)buf_init_chartab(buf, FALSE);
11779}
11780
11781/*
11782 * Reset the 'modifiable' option and its default value.
11783 */
11784 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011785reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011786{
11787 int opt_idx;
11788
11789 curbuf->b_p_ma = FALSE;
11790 p_ma = FALSE;
11791 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011792 if (opt_idx >= 0)
11793 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011794}
11795
11796/*
11797 * Set the global value for 'iminsert' to the local value.
11798 */
11799 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011800set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011801{
11802 p_iminsert = curbuf->b_p_iminsert;
11803}
11804
11805/*
11806 * Set the global value for 'imsearch' to the local value.
11807 */
11808 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011809set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011810{
11811 p_imsearch = curbuf->b_p_imsearch;
11812}
11813
Bram Moolenaar071d4272004-06-13 20:20:40 +000011814static int expand_option_idx = -1;
11815static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11816static int expand_option_flags = 0;
11817
11818 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011819set_context_in_set_cmd(
11820 expand_T *xp,
11821 char_u *arg,
11822 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823{
11824 int nextchar;
11825 long_u flags = 0; /* init for GCC */
11826 int opt_idx = 0; /* init for GCC */
11827 char_u *p;
11828 char_u *s;
11829 int is_term_option = FALSE;
11830 int key;
11831
11832 expand_option_flags = opt_flags;
11833
11834 xp->xp_context = EXPAND_SETTINGS;
11835 if (*arg == NUL)
11836 {
11837 xp->xp_pattern = arg;
11838 return;
11839 }
11840 p = arg + STRLEN(arg) - 1;
11841 if (*p == ' ' && *(p - 1) != '\\')
11842 {
11843 xp->xp_pattern = p + 1;
11844 return;
11845 }
11846 while (p > arg)
11847 {
11848 s = p;
11849 /* count number of backslashes before ' ' or ',' */
11850 if (*p == ' ' || *p == ',')
11851 {
11852 while (s > arg && *(s - 1) == '\\')
11853 --s;
11854 }
11855 /* break at a space with an even number of backslashes */
11856 if (*p == ' ' && ((p - s) & 1) == 0)
11857 {
11858 ++p;
11859 break;
11860 }
11861 --p;
11862 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011863 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011864 {
11865 xp->xp_context = EXPAND_BOOL_SETTINGS;
11866 p += 2;
11867 }
11868 if (STRNCMP(p, "inv", 3) == 0)
11869 {
11870 xp->xp_context = EXPAND_BOOL_SETTINGS;
11871 p += 3;
11872 }
11873 xp->xp_pattern = arg = p;
11874 if (*arg == '<')
11875 {
11876 while (*p != '>')
11877 if (*p++ == NUL) /* expand terminal option name */
11878 return;
11879 key = get_special_key_code(arg + 1);
11880 if (key == 0) /* unknown name */
11881 {
11882 xp->xp_context = EXPAND_NOTHING;
11883 return;
11884 }
11885 nextchar = *++p;
11886 is_term_option = TRUE;
11887 expand_option_name[2] = KEY2TERMCAP0(key);
11888 expand_option_name[3] = KEY2TERMCAP1(key);
11889 }
11890 else
11891 {
11892 if (p[0] == 't' && p[1] == '_')
11893 {
11894 p += 2;
11895 if (*p != NUL)
11896 ++p;
11897 if (*p == NUL)
11898 return; /* expand option name */
11899 nextchar = *++p;
11900 is_term_option = TRUE;
11901 expand_option_name[2] = p[-2];
11902 expand_option_name[3] = p[-1];
11903 }
11904 else
11905 {
11906 /* Allow * wildcard */
11907 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11908 p++;
11909 if (*p == NUL)
11910 return;
11911 nextchar = *p;
11912 *p = NUL;
11913 opt_idx = findoption(arg);
11914 *p = nextchar;
11915 if (opt_idx == -1 || options[opt_idx].var == NULL)
11916 {
11917 xp->xp_context = EXPAND_NOTHING;
11918 return;
11919 }
11920 flags = options[opt_idx].flags;
11921 if (flags & P_BOOL)
11922 {
11923 xp->xp_context = EXPAND_NOTHING;
11924 return;
11925 }
11926 }
11927 }
11928 /* handle "-=" and "+=" */
11929 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11930 {
11931 ++p;
11932 nextchar = '=';
11933 }
11934 if ((nextchar != '=' && nextchar != ':')
11935 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11936 {
11937 xp->xp_context = EXPAND_UNSUCCESSFUL;
11938 return;
11939 }
11940 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11941 {
11942 xp->xp_context = EXPAND_OLD_SETTING;
11943 if (is_term_option)
11944 expand_option_idx = -1;
11945 else
11946 expand_option_idx = opt_idx;
11947 xp->xp_pattern = p + 1;
11948 return;
11949 }
11950 xp->xp_context = EXPAND_NOTHING;
11951 if (is_term_option || (flags & P_NUM))
11952 return;
11953
11954 xp->xp_pattern = p + 1;
11955
11956 if (flags & P_EXPAND)
11957 {
11958 p = options[opt_idx].var;
11959 if (p == (char_u *)&p_bdir
11960 || p == (char_u *)&p_dir
11961 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011962 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011963 || p == (char_u *)&p_rtp
11964#ifdef FEAT_SEARCHPATH
11965 || p == (char_u *)&p_cdpath
11966#endif
11967#ifdef FEAT_SESSION
11968 || p == (char_u *)&p_vdir
11969#endif
11970 )
11971 {
11972 xp->xp_context = EXPAND_DIRECTORIES;
11973 if (p == (char_u *)&p_path
11974#ifdef FEAT_SEARCHPATH
11975 || p == (char_u *)&p_cdpath
11976#endif
11977 )
11978 xp->xp_backslash = XP_BS_THREE;
11979 else
11980 xp->xp_backslash = XP_BS_ONE;
11981 }
11982 else
11983 {
11984 xp->xp_context = EXPAND_FILES;
11985 /* for 'tags' need three backslashes for a space */
11986 if (p == (char_u *)&p_tags)
11987 xp->xp_backslash = XP_BS_THREE;
11988 else
11989 xp->xp_backslash = XP_BS_ONE;
11990 }
11991 }
11992
11993 /* For an option that is a list of file names, find the start of the
11994 * last file name. */
11995 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11996 {
11997 /* count number of backslashes before ' ' or ',' */
11998 if (*p == ' ' || *p == ',')
11999 {
12000 s = p;
12001 while (s > xp->xp_pattern && *(s - 1) == '\\')
12002 --s;
12003 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
12004 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
12005 {
12006 xp->xp_pattern = p + 1;
12007 break;
12008 }
12009 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012010
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000012011#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012012 /* for 'spellsuggest' start at "file:" */
12013 if (options[opt_idx].var == (char_u *)&p_sps
12014 && STRNCMP(p, "file:", 5) == 0)
12015 {
12016 xp->xp_pattern = p + 5;
12017 break;
12018 }
12019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012020 }
12021
12022 return;
12023}
12024
12025 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012026ExpandSettings(
12027 expand_T *xp,
12028 regmatch_T *regmatch,
12029 int *num_file,
12030 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012031{
12032 int num_normal = 0; /* Nr of matching non-term-code settings */
12033 int num_term = 0; /* Nr of matching terminal code settings */
12034 int opt_idx;
12035 int match;
12036 int count = 0;
12037 char_u *str;
12038 int loop;
12039 int is_term_opt;
12040 char_u name_buf[MAX_KEY_NAME_LEN];
12041 static char *(names[]) = {"all", "termcap"};
12042 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
12043
12044 /* do this loop twice:
12045 * loop == 0: count the number of matching options
12046 * loop == 1: copy the matching options into allocated memory
12047 */
12048 for (loop = 0; loop <= 1; ++loop)
12049 {
12050 regmatch->rm_ic = ic;
12051 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
12052 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000012053 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
12054 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012055 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
12056 {
12057 if (loop == 0)
12058 num_normal++;
12059 else
12060 (*file)[count++] = vim_strsave((char_u *)names[match]);
12061 }
12062 }
12063 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
12064 opt_idx++)
12065 {
12066 if (options[opt_idx].var == NULL)
12067 continue;
12068 if (xp->xp_context == EXPAND_BOOL_SETTINGS
12069 && !(options[opt_idx].flags & P_BOOL))
12070 continue;
12071 is_term_opt = istermoption(&options[opt_idx]);
12072 if (is_term_opt && num_normal > 0)
12073 continue;
12074 match = FALSE;
12075 if (vim_regexec(regmatch, str, (colnr_T)0)
12076 || (options[opt_idx].shortname != NULL
12077 && vim_regexec(regmatch,
12078 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
12079 match = TRUE;
12080 else if (is_term_opt)
12081 {
12082 name_buf[0] = '<';
12083 name_buf[1] = 't';
12084 name_buf[2] = '_';
12085 name_buf[3] = str[2];
12086 name_buf[4] = str[3];
12087 name_buf[5] = '>';
12088 name_buf[6] = NUL;
12089 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12090 {
12091 match = TRUE;
12092 str = name_buf;
12093 }
12094 }
12095 if (match)
12096 {
12097 if (loop == 0)
12098 {
12099 if (is_term_opt)
12100 num_term++;
12101 else
12102 num_normal++;
12103 }
12104 else
12105 (*file)[count++] = vim_strsave(str);
12106 }
12107 }
12108 /*
12109 * Check terminal key codes, these are not in the option table
12110 */
12111 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
12112 {
12113 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
12114 {
12115 if (!isprint(str[0]) || !isprint(str[1]))
12116 continue;
12117
12118 name_buf[0] = 't';
12119 name_buf[1] = '_';
12120 name_buf[2] = str[0];
12121 name_buf[3] = str[1];
12122 name_buf[4] = NUL;
12123
12124 match = FALSE;
12125 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12126 match = TRUE;
12127 else
12128 {
12129 name_buf[0] = '<';
12130 name_buf[1] = 't';
12131 name_buf[2] = '_';
12132 name_buf[3] = str[0];
12133 name_buf[4] = str[1];
12134 name_buf[5] = '>';
12135 name_buf[6] = NUL;
12136
12137 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12138 match = TRUE;
12139 }
12140 if (match)
12141 {
12142 if (loop == 0)
12143 num_term++;
12144 else
12145 (*file)[count++] = vim_strsave(name_buf);
12146 }
12147 }
12148
12149 /*
12150 * Check special key names.
12151 */
12152 regmatch->rm_ic = TRUE; /* ignore case here */
12153 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12154 {
12155 name_buf[0] = '<';
12156 STRCPY(name_buf + 1, str);
12157 STRCAT(name_buf, ">");
12158
12159 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12160 {
12161 if (loop == 0)
12162 num_term++;
12163 else
12164 (*file)[count++] = vim_strsave(name_buf);
12165 }
12166 }
12167 }
12168 if (loop == 0)
12169 {
12170 if (num_normal > 0)
12171 *num_file = num_normal;
12172 else if (num_term > 0)
12173 *num_file = num_term;
12174 else
12175 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012176 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012177 if (*file == NULL)
12178 {
12179 *file = (char_u **)"";
12180 return FAIL;
12181 }
12182 }
12183 }
12184 return OK;
12185}
12186
12187 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012188ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012189{
12190 char_u *var = NULL; /* init for GCC */
12191 char_u *buf;
12192
12193 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012194 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012195 if (*file == NULL)
12196 return FAIL;
12197
12198 /*
12199 * For a terminal key code expand_option_idx is < 0.
12200 */
12201 if (expand_option_idx < 0)
12202 {
12203 var = find_termcode(expand_option_name + 2);
12204 if (var == NULL)
12205 expand_option_idx = findoption(expand_option_name);
12206 }
12207
12208 if (expand_option_idx >= 0)
12209 {
12210 /* put string of option value in NameBuff */
12211 option_value2string(&options[expand_option_idx], expand_option_flags);
12212 var = NameBuff;
12213 }
12214 else if (var == NULL)
12215 var = (char_u *)"";
12216
12217 /* A backslash is required before some characters. This is the reverse of
12218 * what happens in do_set(). */
12219 buf = vim_strsave_escaped(var, escape_chars);
12220
12221 if (buf == NULL)
12222 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012223 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012224 return FAIL;
12225 }
12226
12227#ifdef BACKSLASH_IN_FILENAME
12228 /* For MS-Windows et al. we don't double backslashes at the start and
12229 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012230 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012231 if (var[0] == '\\' && var[1] == '\\'
12232 && expand_option_idx >= 0
12233 && (options[expand_option_idx].flags & P_EXPAND)
12234 && vim_isfilec(var[2])
12235 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012236 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012237#endif
12238
12239 *file[0] = buf;
12240 *num_file = 1;
12241 return OK;
12242}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012243
12244/*
12245 * Get the value for the numeric or string option *opp in a nice format into
12246 * NameBuff[]. Must not be called with a hidden option!
12247 */
12248 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012249option_value2string(
12250 struct vimoption *opp,
12251 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012252{
12253 char_u *varp;
12254
12255 varp = get_varp_scope(opp, opt_flags);
12256
12257 if (opp->flags & P_NUM)
12258 {
12259 long wc = 0;
12260
12261 if (wc_use_keyname(varp, &wc))
12262 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12263 else if (wc != 0)
12264 STRCPY(NameBuff, transchar((int)wc));
12265 else
12266 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12267 }
12268 else /* P_STRING */
12269 {
12270 varp = *(char_u **)(varp);
12271 if (varp == NULL) /* just in case */
12272 NameBuff[0] = NUL;
12273#ifdef FEAT_CRYPT
12274 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012275 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012276 STRCPY(NameBuff, "*****");
12277#endif
12278 else if (opp->flags & P_EXPAND)
12279 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12280 /* Translate 'pastetoggle' into special key names */
12281 else if ((char_u **)opp->var == &p_pt)
12282 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12283 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012284 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012285 }
12286}
12287
12288/*
12289 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12290 * printed as a keyname.
12291 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12292 */
12293 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012294wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012295{
12296 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12297 {
12298 *wcp = *(long *)varp;
12299 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12300 return TRUE;
12301 }
12302 return FALSE;
12303}
12304
Bram Moolenaar01615492015-02-03 13:00:38 +010012305#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012306/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012307 * Any character has an equivalent 'langmap' character. This is used for
12308 * keyboards that have a special language mode that sends characters above
12309 * 128 (although other characters can be translated too). The "to" field is a
12310 * Vim command character. This avoids having to switch the keyboard back to
12311 * ASCII mode when leaving Insert mode.
12312 *
12313 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12314 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012315 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12316 * same as langmap_mapchar[] for characters >= 256.
12317 *
12318 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012319 */
12320typedef struct
12321{
12322 int from;
12323 int to;
12324} langmap_entry_T;
12325
12326static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012327
12328/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012329 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12330 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012331 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012332 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012333langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012334{
12335 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012336 int a = 0;
12337 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012338
12339 /* Do a binary search for an existing entry. */
12340 while (a != b)
12341 {
12342 int i = (a + b) / 2;
12343 int d = entries[i].from - from;
12344
12345 if (d == 0)
12346 {
12347 entries[i].to = to;
12348 return;
12349 }
12350 if (d < 0)
12351 a = i + 1;
12352 else
12353 b = i;
12354 }
12355
12356 if (ga_grow(&langmap_mapga, 1) != OK)
12357 return; /* out of memory */
12358
12359 /* insert new entry at position "a" */
12360 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12361 mch_memmove(entries + 1, entries,
12362 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12363 ++langmap_mapga.ga_len;
12364 entries[0].from = from;
12365 entries[0].to = to;
12366}
12367
12368/*
12369 * Apply 'langmap' to multi-byte character "c" and return the result.
12370 */
12371 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012372langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012373{
12374 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12375 int a = 0;
12376 int b = langmap_mapga.ga_len;
12377
12378 while (a != b)
12379 {
12380 int i = (a + b) / 2;
12381 int d = entries[i].from - c;
12382
12383 if (d == 0)
12384 return entries[i].to; /* found matching entry */
12385 if (d < 0)
12386 a = i + 1;
12387 else
12388 b = i;
12389 }
12390 return c; /* no entry found, return "c" unmodified */
12391}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012392
12393 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012394langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012395{
12396 int i;
12397
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012398 for (i = 0; i < 256; i++)
12399 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012400 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012401}
12402
12403/*
12404 * Called when langmap option is set; the language map can be
12405 * changed at any time!
12406 */
12407 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012408langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012409{
12410 char_u *p;
12411 char_u *p2;
12412 int from, to;
12413
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012414 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012415 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012416
12417 for (p = p_langmap; p[0] != NUL; )
12418 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012419 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012420 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012421 {
12422 if (p2[0] == '\\' && p2[1] != NUL)
12423 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012424 }
12425 if (p2[0] == ';')
12426 ++p2; /* abcd;ABCD form, p2 points to A */
12427 else
12428 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12429 while (p[0])
12430 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012431 if (p[0] == ',')
12432 {
12433 ++p;
12434 break;
12435 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012436 if (p[0] == '\\' && p[1] != NUL)
12437 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012438 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012439 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440 if (p2 == NULL)
12441 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012442 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012443 if (p[0] != ',')
12444 {
12445 if (p[0] == '\\')
12446 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012447 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012448 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012449 }
12450 else
12451 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012452 if (p2[0] != ',')
12453 {
12454 if (p2[0] == '\\')
12455 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012456 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012457 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012458 }
12459 if (to == NUL)
12460 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012461 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012462 transchar(from));
12463 return;
12464 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012465
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012466 if (from >= 256)
12467 langmap_set_entry(from, to);
12468 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012469 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012470
12471 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012472 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012473 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012474 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012475 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012476 if (*p == ';')
12477 {
12478 p = p2;
12479 if (p[0] != NUL)
12480 {
12481 if (p[0] != ',')
12482 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012483 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012484 return;
12485 }
12486 ++p;
12487 }
12488 break;
12489 }
12490 }
12491 }
12492 }
12493}
12494#endif
12495
12496/*
12497 * Return TRUE if format option 'x' is in effect.
12498 * Take care of no formatting when 'paste' is set.
12499 */
12500 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012501has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012502{
12503 if (p_paste)
12504 return FALSE;
12505 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12506}
12507
12508/*
12509 * Return TRUE if "x" is present in 'shortmess' option, or
12510 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12511 */
12512 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012513shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012514{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012515 return p_shm != NULL &&
12516 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012517 || (vim_strchr(p_shm, 'a') != NULL
12518 && vim_strchr((char_u *)SHM_A, x) != NULL));
12519}
12520
12521/*
12522 * paste_option_changed() - Called after p_paste was set or reset.
12523 */
12524 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012525paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012526{
12527 static int old_p_paste = FALSE;
12528 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012529 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012530#ifdef FEAT_CMDL_INFO
12531 static int save_ru = 0;
12532#endif
12533#ifdef FEAT_RIGHTLEFT
12534 static int save_ri = 0;
12535 static int save_hkmap = 0;
12536#endif
12537 buf_T *buf;
12538
12539 if (p_paste)
12540 {
12541 /*
12542 * Paste switched from off to on.
12543 * Save the current values, so they can be restored later.
12544 */
12545 if (!old_p_paste)
12546 {
12547 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012548 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012549 {
12550 buf->b_p_tw_nopaste = buf->b_p_tw;
12551 buf->b_p_wm_nopaste = buf->b_p_wm;
12552 buf->b_p_sts_nopaste = buf->b_p_sts;
12553 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012554 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012555#ifdef FEAT_VARTABS
12556 if (buf->b_p_vsts_nopaste)
12557 vim_free(buf->b_p_vsts_nopaste);
12558 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12559 ? vim_strsave(buf->b_p_vsts) : NULL;
12560#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012561 }
12562
12563 /* save global options */
12564 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012565 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012566#ifdef FEAT_CMDL_INFO
12567 save_ru = p_ru;
12568#endif
12569#ifdef FEAT_RIGHTLEFT
12570 save_ri = p_ri;
12571 save_hkmap = p_hkmap;
12572#endif
12573 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012574 p_ai_nopaste = p_ai;
12575 p_et_nopaste = p_et;
12576 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012577 p_tw_nopaste = p_tw;
12578 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012579#ifdef FEAT_VARTABS
12580 if (p_vsts_nopaste)
12581 vim_free(p_vsts_nopaste);
12582 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12583#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012584 }
12585
12586 /*
12587 * Always set the option values, also when 'paste' is set when it is
12588 * already on.
12589 */
12590 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012591 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012592 {
12593 buf->b_p_tw = 0; /* textwidth is 0 */
12594 buf->b_p_wm = 0; /* wrapmargin is 0 */
12595 buf->b_p_sts = 0; /* softtabstop is 0 */
12596 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012597 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012598#ifdef FEAT_VARTABS
12599 if (buf->b_p_vsts)
12600 free_string_option(buf->b_p_vsts);
12601 buf->b_p_vsts = empty_option;
12602 if (buf->b_p_vsts_array)
12603 vim_free(buf->b_p_vsts_array);
12604 buf->b_p_vsts_array = 0;
12605#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012606 }
12607
12608 /* set global options */
12609 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012610 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012611#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012612 if (p_ru)
12613 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012614 p_ru = 0; /* no ruler */
12615#endif
12616#ifdef FEAT_RIGHTLEFT
12617 p_ri = 0; /* no reverse insert */
12618 p_hkmap = 0; /* no Hebrew keyboard */
12619#endif
12620 /* set global values for local buffer options */
12621 p_tw = 0;
12622 p_wm = 0;
12623 p_sts = 0;
12624 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012625#ifdef FEAT_VARTABS
12626 if (p_vsts)
12627 free_string_option(p_vsts);
12628 p_vsts = empty_option;
12629#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012630 }
12631
12632 /*
12633 * Paste switched from on to off: Restore saved values.
12634 */
12635 else if (old_p_paste)
12636 {
12637 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012638 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012639 {
12640 buf->b_p_tw = buf->b_p_tw_nopaste;
12641 buf->b_p_wm = buf->b_p_wm_nopaste;
12642 buf->b_p_sts = buf->b_p_sts_nopaste;
12643 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012644 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012645#ifdef FEAT_VARTABS
12646 if (buf->b_p_vsts)
12647 free_string_option(buf->b_p_vsts);
12648 buf->b_p_vsts = buf->b_p_vsts_nopaste
12649 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12650 if (buf->b_p_vsts_array)
12651 vim_free(buf->b_p_vsts_array);
12652 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12653 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12654 else
12655 buf->b_p_vsts_array = 0;
12656#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012657 }
12658
12659 /* restore global options */
12660 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012661 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012662#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012663 if (p_ru != save_ru)
12664 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012665 p_ru = save_ru;
12666#endif
12667#ifdef FEAT_RIGHTLEFT
12668 p_ri = save_ri;
12669 p_hkmap = save_hkmap;
12670#endif
12671 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012672 p_ai = p_ai_nopaste;
12673 p_et = p_et_nopaste;
12674 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012675 p_tw = p_tw_nopaste;
12676 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012677#ifdef FEAT_VARTABS
12678 if (p_vsts)
12679 free_string_option(p_vsts);
12680 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12681#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012682 }
12683
12684 old_p_paste = p_paste;
12685}
12686
12687/*
12688 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12689 *
12690 * Reset 'compatible' and set the values for options that didn't get set yet
12691 * to the Vim defaults.
12692 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012693 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012694 */
12695 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012696vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012697{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012698 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012699 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012700 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012701
12702 if (!option_was_set((char_u *)"cp"))
12703 {
12704 p_cp = FALSE;
12705 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12706 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12707 set_option_default(opt_idx, OPT_FREE, FALSE);
12708 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012709 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012710 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012711
12712 if (fname != NULL)
12713 {
12714 p = vim_getenv(envname, &dofree);
12715 if (p == NULL)
12716 {
12717 /* Set $MYVIMRC to the first vimrc file found. */
12718 p = FullName_save(fname, FALSE);
12719 if (p != NULL)
12720 {
12721 vim_setenv(envname, p);
12722 vim_free(p);
12723 }
12724 }
12725 else if (dofree)
12726 vim_free(p);
12727 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012728}
12729
12730/*
12731 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12732 */
12733 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012734change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012735{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012736 int opt_idx;
12737
Bram Moolenaar071d4272004-06-13 20:20:40 +000012738 if (p_cp != on)
12739 {
12740 p_cp = on;
12741 compatible_set();
12742 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012743 opt_idx = findoption((char_u *)"cp");
12744 if (opt_idx >= 0)
12745 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012746}
12747
12748/*
12749 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012750 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012751 */
12752 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012753option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012754{
12755 int idx;
12756
12757 idx = findoption(name);
12758 if (idx < 0) /* unknown option */
12759 return FALSE;
12760 if (options[idx].flags & P_WAS_SET)
12761 return TRUE;
12762 return FALSE;
12763}
12764
12765/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012766 * Reset the flag indicating option "name" was set.
12767 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012768 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012769reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012770{
12771 int idx = findoption(name);
12772
12773 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012774 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012775 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012776 return OK;
12777 }
12778 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012779}
12780
12781/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012782 * compatible_set() - Called when 'compatible' has been set or unset.
12783 *
12784 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12785 * flag) to a Vi compatible value.
12786 * When 'compatible' is unset: Set all options that have a different default
12787 * for Vim (without the P_VI_DEF flag) to that default.
12788 */
12789 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012790compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012791{
12792 int opt_idx;
12793
12794 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12795 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12796 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12797 set_option_default(opt_idx, OPT_FREE, p_cp);
12798 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012799 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012800}
12801
12802#ifdef FEAT_LINEBREAK
12803
Bram Moolenaar071d4272004-06-13 20:20:40 +000012804/*
12805 * fill_breakat_flags() -- called when 'breakat' changes value.
12806 */
12807 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012808fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012809{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012810 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012811 int i;
12812
12813 for (i = 0; i < 256; i++)
12814 breakat_flags[i] = FALSE;
12815
12816 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012817 for (p = p_breakat; *p; p++)
12818 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012819}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012820#endif
12821
12822/*
12823 * Check an option that can be a range of string values.
12824 *
12825 * Return OK for correct value, FAIL otherwise.
12826 * Empty is always OK.
12827 */
12828 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012829check_opt_strings(
12830 char_u *val,
12831 char **values,
12832 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012833{
12834 return opt_strings_flags(val, values, NULL, list);
12835}
12836
12837/*
12838 * Handle an option that can be a range of string values.
12839 * Set a flag in "*flagp" for each string present.
12840 *
12841 * Return OK for correct value, FAIL otherwise.
12842 * Empty is always OK.
12843 */
12844 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012845opt_strings_flags(
12846 char_u *val, /* new value */
12847 char **values, /* array of valid string values */
12848 unsigned *flagp,
12849 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012850{
12851 int i;
12852 int len;
12853 unsigned new_flags = 0;
12854
12855 while (*val)
12856 {
12857 for (i = 0; ; ++i)
12858 {
12859 if (values[i] == NULL) /* val not found in values[] */
12860 return FAIL;
12861
12862 len = (int)STRLEN(values[i]);
12863 if (STRNCMP(values[i], val, len) == 0
12864 && ((list && val[len] == ',') || val[len] == NUL))
12865 {
12866 val += len + (val[len] == ',');
12867 new_flags |= (1 << i);
12868 break; /* check next item in val list */
12869 }
12870 }
12871 }
12872 if (flagp != NULL)
12873 *flagp = new_flags;
12874
12875 return OK;
12876}
12877
12878/*
12879 * Read the 'wildmode' option, fill wim_flags[].
12880 */
12881 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012882check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012883{
12884 char_u new_wim_flags[4];
12885 char_u *p;
12886 int i;
12887 int idx = 0;
12888
12889 for (i = 0; i < 4; ++i)
12890 new_wim_flags[i] = 0;
12891
12892 for (p = p_wim; *p; ++p)
12893 {
12894 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12895 ;
12896 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12897 return FAIL;
12898 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12899 new_wim_flags[idx] |= WIM_LONGEST;
12900 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12901 new_wim_flags[idx] |= WIM_FULL;
12902 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12903 new_wim_flags[idx] |= WIM_LIST;
12904 else
12905 return FAIL;
12906 p += i;
12907 if (*p == NUL)
12908 break;
12909 if (*p == ',')
12910 {
12911 if (idx == 3)
12912 return FAIL;
12913 ++idx;
12914 }
12915 }
12916
12917 /* fill remaining entries with last flag */
12918 while (idx < 3)
12919 {
12920 new_wim_flags[idx + 1] = new_wim_flags[idx];
12921 ++idx;
12922 }
12923
12924 /* only when there are no errors, wim_flags[] is changed */
12925 for (i = 0; i < 4; ++i)
12926 wim_flags[i] = new_wim_flags[i];
12927 return OK;
12928}
12929
12930/*
12931 * Check if backspacing over something is allowed.
12932 */
12933 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012934can_bs(
12935 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012936{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012937#ifdef FEAT_JOB_CHANNEL
12938 if (what == BS_START && bt_prompt(curbuf))
12939 return FALSE;
12940#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012941 switch (*p_bs)
12942 {
12943 case '2': return TRUE;
12944 case '1': return (what != BS_START);
12945 case '0': return FALSE;
12946 }
12947 return vim_strchr(p_bs, what) != NULL;
12948}
12949
12950/*
12951 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12952 * the file must be considered changed when the value is different.
12953 */
12954 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012955save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012956{
12957 buf->b_start_ffc = *buf->b_p_ff;
12958 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012959 buf->b_start_bomb = buf->b_p_bomb;
12960
Bram Moolenaar071d4272004-06-13 20:20:40 +000012961 /* Only use free/alloc when necessary, they take time. */
12962 if (buf->b_start_fenc == NULL
12963 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12964 {
12965 vim_free(buf->b_start_fenc);
12966 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12967 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012968}
12969
12970/*
12971 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12972 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012973 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12974 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012975 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012976 * When "ignore_empty" is true don't consider a new, empty buffer to be
12977 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012978 */
12979 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012980file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012981{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012982 /* In a buffer that was never loaded the options are not valid. */
12983 if (buf->b_flags & BF_NEVERLOADED)
12984 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012985 if (ignore_empty
12986 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012987 && buf->b_ml.ml_line_count == 1
12988 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12989 return FALSE;
12990 if (buf->b_start_ffc != *buf->b_p_ff)
12991 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012992 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012993 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012994 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12995 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012996 if (buf->b_start_fenc == NULL)
12997 return (*buf->b_p_fenc != NUL);
12998 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012999}
13000
13001/*
13002 * return OK if "p" is a valid fileformat name, FAIL otherwise.
13003 */
13004 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013005check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013006{
13007 return check_opt_strings(p, p_ff_values, FALSE);
13008}
Bram Moolenaar14f24742012-08-08 18:01:05 +020013009
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013010#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013011
13012/*
13013 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013014 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013015 */
13016 int
13017tabstop_set(char_u *var, int **array)
13018{
13019 int valcount = 1;
13020 int t;
13021 char_u *cp;
13022
Bram Moolenaar64f41072018-10-15 22:51:50 +020013023 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013024 {
13025 *array = NULL;
13026 return TRUE;
13027 }
13028
Bram Moolenaar64f41072018-10-15 22:51:50 +020013029 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013030 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020013031 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013032 {
13033 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013034
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013035 if (strtol((char *)cp, (char **)&end, 10) <= 0)
13036 {
13037 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013038 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013039 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013040 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013041 return FALSE;
13042 }
13043 }
13044
13045 if (VIM_ISDIGIT(*cp))
13046 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013047 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013048 {
13049 ++valcount;
13050 continue;
13051 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013052 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013053 return FALSE;
13054 }
13055
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013056 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013057 if (*array == NULL)
13058 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013059 (*array)[0] = valcount;
13060
13061 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013062 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013063 {
13064 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020013065 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013066 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013067 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013068 ++cp;
13069 }
13070
13071 return TRUE;
13072}
13073
13074/*
13075 * Calculate the number of screen spaces a tab will occupy.
13076 * If "vts" is set then the tab widths are taken from that array,
13077 * otherwise the value of ts is used.
13078 */
13079 int
13080tabstop_padding(colnr_T col, int ts_arg, int *vts)
13081{
13082 int ts = ts_arg == 0 ? 8 : ts_arg;
13083 int tabcount;
13084 colnr_T tabcol = 0;
13085 int t;
13086 int padding = 0;
13087
13088 if (vts == NULL || vts[0] == 0)
13089 return ts - (col % ts);
13090
13091 tabcount = vts[0];
13092
13093 for (t = 1; t <= tabcount; ++t)
13094 {
13095 tabcol += vts[t];
13096 if (tabcol > col)
13097 {
13098 padding = (int)(tabcol - col);
13099 break;
13100 }
13101 }
13102 if (t > tabcount)
13103 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
13104
13105 return padding;
13106}
13107
13108/*
13109 * Find the size of the tab that covers a particular column.
13110 */
13111 int
13112tabstop_at(colnr_T col, int ts, int *vts)
13113{
13114 int tabcount;
13115 colnr_T tabcol = 0;
13116 int t;
13117 int tab_size = 0;
13118
13119 if (vts == 0 || vts[0] == 0)
13120 return ts;
13121
13122 tabcount = vts[0];
13123 for (t = 1; t <= tabcount; ++t)
13124 {
13125 tabcol += vts[t];
13126 if (tabcol > col)
13127 {
13128 tab_size = vts[t];
13129 break;
13130 }
13131 }
13132 if (t > tabcount)
13133 tab_size = vts[tabcount];
13134
13135 return tab_size;
13136}
13137
13138/*
13139 * Find the column on which a tab starts.
13140 */
13141 colnr_T
13142tabstop_start(colnr_T col, int ts, int *vts)
13143{
13144 int tabcount;
13145 colnr_T tabcol = 0;
13146 int t;
13147 int excess;
13148
Bram Moolenaar0119a592018-06-24 23:53:28 +020013149 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013150 return (col / ts) * ts;
13151
13152 tabcount = vts[0];
13153 for (t = 1; t <= tabcount; ++t)
13154 {
13155 tabcol += vts[t];
13156 if (tabcol > col)
13157 return tabcol - vts[t];
13158 }
13159
13160 excess = tabcol % vts[tabcount];
13161 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13162}
13163
13164/*
13165 * Find the number of tabs and spaces necessary to get from one column
13166 * to another.
13167 */
13168 void
13169tabstop_fromto(
13170 colnr_T start_col,
13171 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013172 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013173 int *vts,
13174 int *ntabs,
13175 int *nspcs)
13176{
13177 int spaces = end_col - start_col;
13178 colnr_T tabcol = 0;
13179 int padding = 0;
13180 int tabcount;
13181 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013182 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013183
Bram Moolenaar0119a592018-06-24 23:53:28 +020013184 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013185 {
13186 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013187 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013188
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013189 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013190 if (spaces >= initspc)
13191 {
13192 spaces -= initspc;
13193 tabs++;
13194 }
13195 tabs += spaces / ts;
13196 spaces -= (spaces / ts) * ts;
13197
13198 *ntabs = tabs;
13199 *nspcs = spaces;
13200 return;
13201 }
13202
13203 /* Find the padding needed to reach the next tabstop. */
13204 tabcount = vts[0];
13205 for (t = 1; t <= tabcount; ++t)
13206 {
13207 tabcol += vts[t];
13208 if (tabcol > start_col)
13209 {
13210 padding = (int)(tabcol - start_col);
13211 break;
13212 }
13213 }
13214 if (t > tabcount)
13215 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13216
13217 /* If the space needed is less than the padding no tabs can be used. */
13218 if (spaces < padding)
13219 {
13220 *ntabs = 0;
13221 *nspcs = spaces;
13222 return;
13223 }
13224
13225 *ntabs = 1;
13226 spaces -= padding;
13227
13228 /* At least one tab has been used. See if any more will fit. */
13229 while (spaces != 0 && ++t <= tabcount)
13230 {
13231 padding = vts[t];
13232 if (spaces < padding)
13233 {
13234 *nspcs = spaces;
13235 return;
13236 }
13237 ++*ntabs;
13238 spaces -= padding;
13239 }
13240
13241 *ntabs += spaces / vts[tabcount];
13242 *nspcs = spaces % vts[tabcount];
13243}
13244
13245/*
13246 * See if two tabstop arrays contain the same values.
13247 */
13248 int
13249tabstop_eq(int *ts1, int *ts2)
13250{
13251 int t;
13252
13253 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13254 return FALSE;
13255 if (ts1 == ts2)
13256 return TRUE;
13257 if (ts1[0] != ts2[0])
13258 return FALSE;
13259
13260 for (t = 1; t <= ts1[0]; ++t)
13261 if (ts1[t] != ts2[t])
13262 return FALSE;
13263
13264 return TRUE;
13265}
13266
Bram Moolenaar113e1072019-01-20 15:30:40 +010013267#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013268/*
13269 * Copy a tabstop array, allocating space for the new array.
13270 */
13271 int *
13272tabstop_copy(int *oldts)
13273{
13274 int *newts;
13275 int t;
13276
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013277 if (oldts == NULL)
13278 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013279 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013280 if (newts != NULL)
13281 for (t = 0; t <= oldts[0]; ++t)
13282 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013283 return newts;
13284}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013285#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013286
13287/*
13288 * Return a count of the number of tabstops.
13289 */
13290 int
13291tabstop_count(int *ts)
13292{
13293 return ts != NULL ? ts[0] : 0;
13294}
13295
13296/*
13297 * Return the first tabstop, or 8 if there are no tabstops defined.
13298 */
13299 int
13300tabstop_first(int *ts)
13301{
13302 return ts != NULL ? ts[1] : 8;
13303}
13304
13305#endif
13306
Bram Moolenaar14f24742012-08-08 18:01:05 +020013307/*
13308 * Return the effective shiftwidth value for current buffer, using the
13309 * 'tabstop' value when 'shiftwidth' is zero.
13310 */
13311 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013312get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013313{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013314 return get_sw_value_col(buf, 0);
13315}
13316
13317/*
Bram Moolenaarf9514162018-11-22 03:08:29 +010013318 * Idem, using "pos".
13319 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020013320 static long
Bram Moolenaarf9514162018-11-22 03:08:29 +010013321get_sw_value_pos(buf_T *buf, pos_T *pos)
13322{
13323 pos_T save_cursor = curwin->w_cursor;
13324 long sw_value;
13325
13326 curwin->w_cursor = *pos;
13327 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13328 curwin->w_cursor = save_cursor;
13329 return sw_value;
13330}
13331
13332/*
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020013333 * Idem, using the first non-black in the current line.
13334 */
13335 long
13336get_sw_value_indent(buf_T *buf)
13337{
13338 pos_T pos = curwin->w_cursor;
13339
13340 pos.col = getwhitecols_curline();
13341 return get_sw_value_pos(buf, &pos);
13342}
13343
13344/*
Bram Moolenaarf9514162018-11-22 03:08:29 +010013345 * Idem, using virtual column "col".
13346 */
13347 long
13348get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13349{
13350 return buf->b_p_sw ? buf->b_p_sw :
13351 #ifdef FEAT_VARTABS
13352 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13353 #else
13354 buf->b_p_ts;
13355 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013356}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013357
13358/*
13359 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013360 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013361 */
13362 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013363get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013364{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013365 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013366}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013367
13368/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013369 * Return the effective 'scrolloff' value for the current window, using the
13370 * global value when appropriate.
13371 */
13372 long
13373get_scrolloff_value(void)
13374{
13375 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13376}
13377
13378/*
13379 * Return the effective 'sidescrolloff' value for the current window, using the
13380 * global value when appropriate.
13381 */
13382 long
13383get_sidescrolloff_value(void)
13384{
13385 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13386}
13387
13388/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013389 * Check matchpairs option for "*initc".
13390 * If there is a match set "*initc" to the matching character and "*findc" to
13391 * the opposite character. Set "*backwards" to the direction.
13392 * When "switchit" is TRUE swap the direction.
13393 */
13394 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013395find_mps_values(
13396 int *initc,
13397 int *findc,
13398 int *backwards,
13399 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013400{
13401 char_u *ptr;
13402
13403 ptr = curbuf->b_p_mps;
13404 while (*ptr != NUL)
13405 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013406 if (has_mbyte)
13407 {
13408 char_u *prev;
13409
13410 if (mb_ptr2char(ptr) == *initc)
13411 {
13412 if (switchit)
13413 {
13414 *findc = *initc;
13415 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13416 *backwards = TRUE;
13417 }
13418 else
13419 {
13420 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13421 *backwards = FALSE;
13422 }
13423 return;
13424 }
13425 prev = ptr;
13426 ptr += mb_ptr2len(ptr) + 1;
13427 if (mb_ptr2char(ptr) == *initc)
13428 {
13429 if (switchit)
13430 {
13431 *findc = *initc;
13432 *initc = mb_ptr2char(prev);
13433 *backwards = FALSE;
13434 }
13435 else
13436 {
13437 *findc = mb_ptr2char(prev);
13438 *backwards = TRUE;
13439 }
13440 return;
13441 }
13442 ptr += mb_ptr2len(ptr);
13443 }
13444 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013445 {
13446 if (*ptr == *initc)
13447 {
13448 if (switchit)
13449 {
13450 *backwards = TRUE;
13451 *findc = *initc;
13452 *initc = ptr[2];
13453 }
13454 else
13455 {
13456 *backwards = FALSE;
13457 *findc = ptr[2];
13458 }
13459 return;
13460 }
13461 ptr += 2;
13462 if (*ptr == *initc)
13463 {
13464 if (switchit)
13465 {
13466 *backwards = FALSE;
13467 *findc = *initc;
13468 *initc = ptr[-2];
13469 }
13470 else
13471 {
13472 *backwards = TRUE;
13473 *findc = ptr[-2];
13474 }
13475 return;
13476 }
13477 ++ptr;
13478 }
13479 if (*ptr == ',')
13480 ++ptr;
13481 }
13482}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013483
13484#if defined(FEAT_LINEBREAK) || defined(PROTO)
13485/*
13486 * This is called when 'breakindentopt' is changed and when a window is
13487 * initialized.
13488 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013489 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013490briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013491{
13492 char_u *p;
13493 int bri_shift = 0;
13494 long bri_min = 20;
13495 int bri_sbr = FALSE;
13496
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013497 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013498 while (*p != NUL)
13499 {
13500 if (STRNCMP(p, "shift:", 6) == 0
13501 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13502 {
13503 p += 6;
13504 bri_shift = getdigits(&p);
13505 }
13506 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13507 {
13508 p += 4;
13509 bri_min = getdigits(&p);
13510 }
13511 else if (STRNCMP(p, "sbr", 3) == 0)
13512 {
13513 p += 3;
13514 bri_sbr = TRUE;
13515 }
13516 if (*p != ',' && *p != NUL)
13517 return FAIL;
13518 if (*p == ',')
13519 ++p;
13520 }
13521
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013522 wp->w_p_brishift = bri_shift;
13523 wp->w_p_brimin = bri_min;
13524 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013525
13526 return OK;
13527}
13528#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013529
13530/*
13531 * Get the local or global value of 'backupcopy'.
13532 */
13533 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013534get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013535{
13536 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13537}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013538
13539#if defined(FEAT_SIGNS) || defined(PROTO)
13540/*
13541 * Return TRUE when window "wp" has a column to draw signs in.
13542 */
13543 int
13544signcolumn_on(win_T *wp)
13545{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020013546 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
13547 // column (if present). Otherwise signs are to be displayed in the sign
13548 // column.
13549 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
13550 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
13551
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013552 if (*wp->w_p_scl == 'n')
13553 return FALSE;
13554 if (*wp->w_p_scl == 'y')
13555 return TRUE;
13556 return (wp->w_buffer->b_signlist != NULL
13557# ifdef FEAT_NETBEANS_INTG
13558 || wp->w_buffer->b_has_sign_column
13559# endif
13560 );
13561}
13562#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013563
13564#if defined(FEAT_EVAL) || defined(PROTO)
13565/*
13566 * Get window or buffer local options.
13567 */
13568 dict_T *
13569get_winbuf_options(int bufopt)
13570{
13571 dict_T *d;
13572 int opt_idx;
13573
13574 d = dict_alloc();
13575 if (d == NULL)
13576 return NULL;
13577
13578 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13579 {
13580 struct vimoption *opt = &options[opt_idx];
13581
13582 if ((bufopt && (opt->indir & PV_BUF))
13583 || (!bufopt && (opt->indir & PV_WIN)))
13584 {
13585 char_u *varp = get_varp(opt);
13586
13587 if (varp != NULL)
13588 {
13589 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013590 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013591 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013592 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013593 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013594 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013595 }
13596 }
13597 }
13598
13599 return d;
13600}
13601#endif