blob: aabfc7f53ee4281d1e16816a20da209bfc05f30c [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);
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02003247#ifdef FEAT_STL_OPT
3248static char *check_stl_option(char_u *s);
3249#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003250#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003251static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003252#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003253#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003254static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003255#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003256static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3257static 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 +01003258static void check_redraw(long_u flags);
3259static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003260static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003261static void showoptions(int all, int opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003262static int optval_default(struct vimoption *, char_u *varp, int compatible);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003263static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003264static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003265static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3266static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3267static int istermoption(struct vimoption *);
3268static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3269static char_u *get_varp(struct vimoption *);
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02003270static void check_win_options(win_T *win);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003271static void option_value2string(struct vimoption *, int opt_flags);
3272static void check_winopt(winopt_T *wop);
3273static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static void paste_option_changed(void);
3275static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003276#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003277static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003278#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003279static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3280static int check_opt_strings(char_u *val, char **values, int);
3281static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003282#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003283static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003284#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003285
3286/*
3287 * Initialize the options, first part.
3288 *
3289 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003290 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003291 */
3292 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003293set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003294{
3295 char_u *p;
3296 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003297 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298
3299#ifdef FEAT_LANGMAP
3300 langmap_init();
3301#endif
3302
3303 /* Be Vi compatible by default */
3304 p_cp = TRUE;
3305
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003306 /* Use POSIX compatibility when $VIM_POSIX is set. */
3307 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003308 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003309 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003310 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003311 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003312
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313 /*
3314 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003315 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003317 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003318#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003319 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003320 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003321#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003322 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003323 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324
3325#ifdef FEAT_WILDIGN
3326 /*
3327 * Set the default for 'backupskip' to include environment variables for
3328 * temp files.
3329 */
3330 {
3331# ifdef UNIX
3332 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3333# else
3334 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3335# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003336 int len;
3337 garray_T ga;
3338 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003339
3340 ga_init2(&ga, 1, 100);
3341 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3342 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003343 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003344# ifdef UNIX
3345 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003346# ifdef MACOS_X
3347 p = (char_u *)"/private/tmp";
3348# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003349 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003350# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003351 else
3352# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003353 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003354 if (p != NULL && *p != NUL)
3355 {
3356 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003357 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003358 if (ga_grow(&ga, len) == OK)
3359 {
3360 if (ga.ga_len > 0)
3361 STRCAT(ga.ga_data, ",");
3362 STRCAT(ga.ga_data, p);
3363 add_pathsep(ga.ga_data);
3364 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365 ga.ga_len += len;
3366 }
3367 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003368 if (mustfree)
3369 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003370 }
3371 if (ga.ga_data != NULL)
3372 {
3373 set_string_default("bsk", ga.ga_data);
3374 vim_free(ga.ga_data);
3375 }
3376 }
3377#endif
3378
3379 /*
3380 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3381 */
3382 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003383 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003384 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003385#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3386 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3387#endif
3388 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003389#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003390 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003391 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392#else
3393# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003394 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003395 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003396# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003397 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003398# endif
3399#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003401 opt_idx = findoption((char_u *)"maxmem");
3402 if (opt_idx >= 0)
3403 {
3404#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003405 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3406 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003407#endif
3408 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3409 }
3410 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411 }
3412
Bram Moolenaar071d4272004-06-13 20:20:40 +00003413#ifdef FEAT_SEARCHPATH
3414 {
3415 char_u *cdpath;
3416 char_u *buf;
3417 int i;
3418 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003419 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420
3421 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003422 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003423 if (cdpath != NULL)
3424 {
Bram Moolenaar964b3742019-05-24 18:54:09 +02003425 buf = alloc((STRLEN(cdpath) << 1) + 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003426 if (buf != NULL)
3427 {
3428 buf[0] = ','; /* start with ",", current dir first */
3429 j = 1;
3430 for (i = 0; cdpath[i] != NUL; ++i)
3431 {
3432 if (vim_ispathlistsep(cdpath[i]))
3433 buf[j++] = ',';
3434 else
3435 {
3436 if (cdpath[i] == ' ' || cdpath[i] == ',')
3437 buf[j++] = '\\';
3438 buf[j++] = cdpath[i];
3439 }
3440 }
3441 buf[j] = NUL;
3442 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003443 if (opt_idx >= 0)
3444 {
3445 options[opt_idx].def_val[VI_DEFAULT] = buf;
3446 options[opt_idx].flags |= P_DEF_ALLOCED;
3447 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003448 else
3449 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003450 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003451 if (mustfree)
3452 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003453 }
3454 }
3455#endif
3456
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003457#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003458 /* Set print encoding on platforms that don't default to latin1 */
3459 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003460# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461 (char_u *)"cp1252"
3462# else
3463# ifdef VMS
3464 (char_u *)"dec-mcs"
3465# else
3466# ifdef EBCDIC
3467 (char_u *)"ebcdic-uk"
3468# else
3469# ifdef MAC
3470 (char_u *)"mac-roman"
3471# else /* HPUX */
3472 (char_u *)"hp-roman8"
3473# endif
3474# endif
3475# endif
3476# endif
3477 );
3478#endif
3479
3480#ifdef FEAT_POSTSCRIPT
3481 /* 'printexpr' must be allocated to be able to evaluate it. */
3482 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003483# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003484 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003485# else
3486# ifdef VMS
3487 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3488
3489# else
3490 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3491# endif
3492# endif
3493 );
3494#endif
3495
3496 /*
3497 * Set all the options (except the terminal options) to their default
3498 * value. Also set the global value for local options.
3499 */
3500 set_options_default(0);
3501
Bram Moolenaar07268702018-03-01 21:57:32 +01003502#ifdef CLEAN_RUNTIMEPATH
3503 if (clean_arg)
3504 {
3505 opt_idx = findoption((char_u *)"runtimepath");
3506 if (opt_idx >= 0)
3507 {
3508 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3509 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3510 }
3511 opt_idx = findoption((char_u *)"packpath");
3512 if (opt_idx >= 0)
3513 {
3514 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3515 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3516 }
3517 }
3518#endif
3519
Bram Moolenaar071d4272004-06-13 20:20:40 +00003520#ifdef FEAT_GUI
3521 if (found_reverse_arg)
3522 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3523#endif
3524
3525 curbuf->b_p_initialized = TRUE;
3526 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003527 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003528 check_buf_options(curbuf);
3529 check_win_options(curwin);
3530 check_options();
3531
3532 /* Must be before option_expand(), because that one needs vim_isIDc() */
3533 didset_options();
3534
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003535#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003536 /* Use the current chartab for the generic chartab. This is not in
3537 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003538 init_spell_chartab();
3539#endif
3540
Bram Moolenaar071d4272004-06-13 20:20:40 +00003541 /*
3542 * Expand environment variables and things like "~" for the defaults.
3543 * If option_expand() returns non-NULL the variable is expanded. This can
3544 * only happen for non-indirect options.
3545 * Also set the default to the expanded value, so ":set" does not list
3546 * them.
3547 * Don't set the P_ALLOCED flag, because we don't want to free the
3548 * default.
3549 */
3550 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3551 {
3552 if ((options[opt_idx].flags & P_GETTEXT)
3553 && options[opt_idx].var != NULL)
3554 p = (char_u *)_(*(char **)options[opt_idx].var);
3555 else
3556 p = option_expand(opt_idx, NULL);
3557 if (p != NULL && (p = vim_strsave(p)) != NULL)
3558 {
3559 *(char_u **)options[opt_idx].var = p;
3560 /* VIMEXP
3561 * Defaults for all expanded options are currently the same for Vi
3562 * and Vim. When this changes, add some code here! Also need to
3563 * split P_DEF_ALLOCED in two.
3564 */
3565 if (options[opt_idx].flags & P_DEF_ALLOCED)
3566 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3567 options[opt_idx].def_val[VI_DEFAULT] = p;
3568 options[opt_idx].flags |= P_DEF_ALLOCED;
3569 }
3570 }
3571
Bram Moolenaar071d4272004-06-13 20:20:40 +00003572 save_file_ff(curbuf); /* Buffer is unchanged */
3573
Bram Moolenaar071d4272004-06-13 20:20:40 +00003574#if defined(FEAT_ARABIC)
3575 /* Detect use of mlterm.
3576 * Mlterm is a terminal emulator akin to xterm that has some special
3577 * abilities (bidi namely).
3578 * NOTE: mlterm's author is being asked to 'set' a variable
3579 * instead of an environment variable due to inheritance.
3580 */
3581 if (mch_getenv((char_u *)"MLTERM") != NULL)
3582 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3583#endif
3584
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003585 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003586
Bram Moolenaar4f974752019-02-17 17:44:42 +01003587# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003588 /*
3589 * If $LANG isn't set, try to get a good value for it. This makes the
3590 * right language be used automatically. Don't do this for English.
3591 */
3592 if (mch_getenv((char_u *)"LANG") == NULL)
3593 {
3594 char buf[20];
3595
3596 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3597 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3598 * only the first two. */
3599 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3600 (LPTSTR)buf, 20);
3601 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3602 {
3603 /* There are a few exceptions (probably more) */
3604 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3605 STRCPY(buf, "zh_TW");
3606 else if (STRNICMP(buf, "chs", 3) == 0
3607 || STRNICMP(buf, "zhc", 3) == 0)
3608 STRCPY(buf, "zh_CN");
3609 else if (STRNICMP(buf, "jp", 2) == 0)
3610 STRCPY(buf, "ja");
3611 else
3612 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003613 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003614 }
3615 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003616# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003617# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003618 /* Moved to os_mac_conv.c to avoid dependency problems. */
3619 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003620# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003621# endif
3622
3623 /* enc_locale() will try to find the encoding of the current locale. */
3624 p = enc_locale();
3625 if (p != NULL)
3626 {
3627 char_u *save_enc;
3628
3629 /* Try setting 'encoding' and check if the value is valid.
3630 * If not, go back to the default "latin1". */
3631 save_enc = p_enc;
3632 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003633 if (STRCMP(p_enc, "gb18030") == 0)
3634 {
3635 /* We don't support "gb18030", but "cp936" is a good substitute
3636 * for practical purposes, thus use that. It's not an alias to
3637 * still support conversion between gb18030 and utf-8. */
3638 p_enc = vim_strsave((char_u *)"cp936");
3639 vim_free(p);
3640 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003641 if (mb_init() == NULL)
3642 {
3643 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003644 if (opt_idx >= 0)
3645 {
3646 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3647 options[opt_idx].flags |= P_DEF_ALLOCED;
3648 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003649
Bram Moolenaard0573012017-10-28 21:11:06 +02003650#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003651 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003652 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003653 /* Adjust the default for 'isprint' and 'iskeyword' to match
3654 * latin1. Also set the defaults for when 'nocompatible' is
3655 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003656 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003657 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003658 set_string_option_direct((char_u *)"isk", -1,
3659 ISK_LATIN1, OPT_FREE, SID_NONE);
3660 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003661 if (opt_idx >= 0)
3662 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003663 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003664 if (opt_idx >= 0)
3665 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003666 (void)init_chartab();
3667 }
3668#endif
3669
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003670#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671 /* Win32 console: When GetACP() returns a different value from
3672 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003673 if (
3674# ifdef VIMDLL
3675 (!gui.in_use && !gui.starting) &&
3676# endif
3677 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003678 {
3679 char buf[50];
3680
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003681 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3682 * Use an alternative value. */
3683 if (GetConsoleCP() == 0)
3684 sprintf(buf, "cp%ld", (long)GetACP());
3685 else
3686 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003687 p_tenc = vim_strsave((char_u *)buf);
3688 if (p_tenc != NULL)
3689 {
3690 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003691 if (opt_idx >= 0)
3692 {
3693 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3694 options[opt_idx].flags |= P_DEF_ALLOCED;
3695 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003696 convert_setup(&input_conv, p_tenc, p_enc);
3697 convert_setup(&output_conv, p_enc, p_tenc);
3698 }
3699 else
3700 p_tenc = empty_option;
3701 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003702#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003703#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003704 /* $HOME may have characters in active code page. */
3705 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003706#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707 }
3708 else
3709 {
3710 vim_free(p_enc);
3711 p_enc = save_enc;
3712 }
3713 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003714
3715#ifdef FEAT_MULTI_LANG
3716 /* Set the default for 'helplang'. */
3717 set_helplang_default(get_mess_lang());
3718#endif
3719}
3720
3721/*
3722 * Set an option to its default value.
3723 * This does not take care of side effects!
3724 */
3725 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003726set_option_default(
3727 int opt_idx,
3728 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3729 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003730{
3731 char_u *varp; /* pointer to variable for current option */
3732 int dvi; /* index in def_val[] */
3733 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003734 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003735 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3736
3737 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3738 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003739 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003740 {
3741 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3742 if (flags & P_STRING)
3743 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003744 /* Use set_string_option_direct() for local options to handle
3745 * freeing and allocating the value. */
3746 if (options[opt_idx].indir != PV_NONE)
3747 set_string_option_direct(NULL, opt_idx,
3748 options[opt_idx].def_val[dvi], opt_flags, 0);
3749 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003750 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003751 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3752 free_string_option(*(char_u **)(varp));
3753 *(char_u **)varp = options[opt_idx].def_val[dvi];
3754 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003755 }
3756 }
3757 else if (flags & P_NUM)
3758 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003759 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003760 win_comp_scroll(curwin);
3761 else
3762 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003763 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3764
3765 if ((long *)varp == &curwin->w_p_so
3766 || (long *)varp == &curwin->w_p_siso)
3767 // 'scrolloff' and 'sidescrolloff' local values have a
3768 // different default value than the global default.
3769 *(long *)varp = -1;
3770 else
3771 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 /* May also set global value for local option. */
3773 if (both)
3774 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003775 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003776 }
3777 }
3778 else /* P_BOOL */
3779 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003780 /* the cast to long is required for Manx C, long_i is needed for
3781 * MSVC */
3782 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003783#ifdef UNIX
3784 /* 'modeline' defaults to off for root */
3785 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3786 *(int *)varp = FALSE;
3787#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003788 /* May also set global value for local option. */
3789 if (both)
3790 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3791 *(int *)varp;
3792 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003793
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003794 /* The default value is not insecure. */
3795 flagsp = insecure_flag(opt_idx, opt_flags);
3796 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003797 }
3798
3799#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003800 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003801#endif
3802}
3803
3804/*
3805 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003806 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003807 */
3808 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003809set_options_default(
3810 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003811{
3812 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003813 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003814 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003815
3816 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003817 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003818 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003819 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003820# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003821 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003822 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003823# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003824 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003825 set_option_default(i, opt_flags, p_cp);
3826
Bram Moolenaar071d4272004-06-13 20:20:40 +00003827 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003828 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003830#ifdef FEAT_CINDENT
3831 parse_cino(curbuf);
3832#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833}
3834
3835/*
3836 * Set the Vi-default value of a string option.
3837 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003838 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003839 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003840 static void
3841set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003842{
3843 char_u *p;
3844 int opt_idx;
3845
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003846 if (escape && vim_strchr(val, ' ') != NULL)
3847 p = vim_strsave_escaped(val, (char_u *)" ");
3848 else
3849 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850 if (p != NULL) /* we don't want a NULL */
3851 {
3852 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003853 if (opt_idx >= 0)
3854 {
3855 if (options[opt_idx].flags & P_DEF_ALLOCED)
3856 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3857 options[opt_idx].def_val[VI_DEFAULT] = p;
3858 options[opt_idx].flags |= P_DEF_ALLOCED;
3859 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003860 }
3861}
3862
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003863 void
3864set_string_default(char *name, char_u *val)
3865{
3866 set_string_default_esc(name, val, FALSE);
3867}
3868
Bram Moolenaar071d4272004-06-13 20:20:40 +00003869/*
3870 * Set the Vi-default value of a number option.
3871 * Used for 'lines' and 'columns'.
3872 */
3873 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003874set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003875{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003876 int opt_idx;
3877
3878 opt_idx = findoption((char_u *)name);
3879 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003880 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003881}
3882
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003883/*
3884 * Set all window-local and buffer-local options to the Vim default.
3885 * local-global options will use the global value.
Bram Moolenaar46451042019-08-24 15:50:46 +02003886 * When "do_buffer" is FALSE don't set buffer-local options.
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003887 */
3888 void
Bram Moolenaar46451042019-08-24 15:50:46 +02003889set_local_options_default(win_T *wp, int do_buffer)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003890{
3891 win_T *save_curwin = curwin;
3892 int i;
3893
3894 curwin = wp;
3895 curbuf = curwin->w_buffer;
3896 block_autocmds();
3897
3898 for (i = 0; !istermoption(&options[i]); i++)
3899 {
3900 struct vimoption *p = &(options[i]);
3901 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3902
3903 if (p->indir != PV_NONE
Bram Moolenaar46451042019-08-24 15:50:46 +02003904 && (do_buffer || (p->indir & PV_BUF) == 0)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003905 && !(options[i].flags & P_NODEFAULT)
3906 && !optval_default(p, varp, FALSE))
3907 set_option_default(i, OPT_LOCAL, FALSE);
3908 }
3909
3910 unblock_autocmds();
3911 curwin = save_curwin;
3912 curbuf = curwin->w_buffer;
3913}
3914
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003915#if defined(EXITFREE) || defined(PROTO)
3916/*
3917 * Free all options.
3918 */
3919 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003920free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003921{
3922 int i;
3923
3924 for (i = 0; !istermoption(&options[i]); i++)
3925 {
3926 if (options[i].indir == PV_NONE)
3927 {
3928 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003929 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003930 free_string_option(*(char_u **)options[i].var);
3931 if (options[i].flags & P_DEF_ALLOCED)
3932 free_string_option(options[i].def_val[VI_DEFAULT]);
3933 }
3934 else if (options[i].var != VAR_WIN
3935 && (options[i].flags & P_STRING))
3936 /* buffer-local option: free global value */
3937 free_string_option(*(char_u **)options[i].var);
3938 }
3939}
3940#endif
3941
3942
Bram Moolenaar071d4272004-06-13 20:20:40 +00003943/*
3944 * Initialize the options, part two: After getting Rows and Columns and
3945 * setting 'term'.
3946 */
3947 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003948set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003949{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003950 int idx;
3951
Bram Moolenaar071d4272004-06-13 20:20:40 +00003952 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003953 * 'scroll' defaults to half the window height. The stored default is zero,
3954 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003955 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003956 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003957 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003958 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003959 comp_col();
3960
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003961 /*
3962 * 'window' is only for backwards compatibility with Vi.
3963 * Default is Rows - 1.
3964 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003965 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003966 p_window = Rows - 1;
3967 set_number_default("window", Rows - 1);
3968
Bram Moolenaarf740b292006-02-16 22:11:02 +00003969 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003970#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003971 /*
3972 * If 'background' wasn't set by the user, try guessing the value,
3973 * depending on the terminal name. Only need to check for terminals
3974 * with a dark background, that can handle color.
3975 */
3976 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003977 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3978 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003980 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003981 /* don't mark it as set, when starting the GUI it may be
3982 * changed again */
3983 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003984 }
3985#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003986
3987#ifdef CURSOR_SHAPE
3988 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
3989#endif
3990#ifdef FEAT_MOUSESHAPE
3991 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
3992#endif
3993#ifdef FEAT_PRINTER
3994 (void)parse_printoptions(); /* parse 'printoptions' default value */
3995#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003996}
3997
3998/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00003999 * Return "dark" or "light" depending on the kind of terminal.
4000 * This is just guessing! Recognized are:
4001 * "linux" Linux console
4002 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004003 * "cygwin.*" Cygwin shell
4004 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004005 * We also check the COLORFGBG environment variable, which is set by
4006 * rxvt and derivatives. This variable contains either two or three
4007 * values separated by semicolons; we want the last value in either
4008 * case. If this value is 0-6 or 8, our background is dark.
4009 */
4010 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004011term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004012{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004013#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004014 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004015 return (char_u *)"dark";
4016#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004017 char_u *p;
4018
Bram Moolenaarf740b292006-02-16 22:11:02 +00004019 if (STRCMP(T_NAME, "linux") == 0
4020 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004021 || STRNCMP(T_NAME, "cygwin", 6) == 0
4022 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004023 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4024 && (p = vim_strrchr(p, ';')) != NULL
4025 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4026 && p[2] == NUL))
4027 return (char_u *)"dark";
4028 return (char_u *)"light";
4029#endif
4030}
4031
4032/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004033 * Initialize the options, part three: After reading the .vimrc
4034 */
4035 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004036set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004037{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004038#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004039/*
4040 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4041 * This is done after other initializations, where 'shell' might have been
4042 * set, but only if they have not been set before.
4043 */
4044 char_u *p;
4045 int idx_srr;
4046 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004047# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048 int idx_sp;
4049 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004050# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004051
4052 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004053 if (idx_srr < 0)
4054 do_srr = FALSE;
4055 else
4056 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004057# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004058 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004059 if (idx_sp < 0)
4060 do_sp = FALSE;
4061 else
4062 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004063# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004064 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004065 if (p != NULL)
4066 {
4067 /*
4068 * Default for p_sp is "| tee", for p_srr is ">".
4069 * For known shells it is changed here to include stderr.
4070 */
4071 if ( fnamecmp(p, "csh") == 0
4072 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004073# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004074 || fnamecmp(p, "csh.exe") == 0
4075 || fnamecmp(p, "tcsh.exe") == 0
4076# endif
4077 )
4078 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004079# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004080 if (do_sp)
4081 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004082# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004083 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004084# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004086# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004087 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4088 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004089# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004090 if (do_srr)
4091 {
4092 p_srr = (char_u *)">&";
4093 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4094 }
4095 }
4096 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004097 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 if ( fnamecmp(p, "sh") == 0
4099 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004100 || fnamecmp(p, "mksh") == 0
4101 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004102 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004103 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004104 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004105 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004106# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 || fnamecmp(p, "cmd") == 0
4108 || fnamecmp(p, "sh.exe") == 0
4109 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004110 || fnamecmp(p, "mksh.exe") == 0
4111 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004112 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004113 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004114 || fnamecmp(p, "bash.exe") == 0
4115 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004116# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004117 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004119# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004120 if (do_sp)
4121 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004122# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004124# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004126# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4128 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004129# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004130 if (do_srr)
4131 {
4132 p_srr = (char_u *)">%s 2>&1";
4133 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4134 }
4135 }
4136 vim_free(p);
4137 }
4138#endif
4139
Bram Moolenaar4f974752019-02-17 17:44:42 +01004140#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004142 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4143 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004144 * This is done after other initializations, where 'shell' might have been
4145 * set, but only if they have not been set before. Default for p_shcf is
4146 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004147 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004148 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004149 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 {
4151 int idx3;
4152
4153 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004154 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 {
4156 p_shcf = (char_u *)"-c";
4157 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4158 }
4159
Bram Moolenaar071d4272004-06-13 20:20:40 +00004160 /* Somehow Win32 requires the quotes around the redirection too */
4161 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004162 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004163 {
4164 p_sxq = (char_u *)"\"";
4165 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4166 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004167 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004168 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4169 {
4170 int idx3;
4171
4172 /*
4173 * cmd.exe on Windows will strip the first and last double quote given
4174 * on the command line, e.g. most of the time things like:
4175 * cmd /c "my path/to/echo" "my args to echo"
4176 * become:
4177 * my path/to/echo" "my args to echo
4178 * when executed.
4179 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004180 * To avoid this, set shellxquote to surround the command in
4181 * parenthesis. This appears to make most commands work, without
4182 * breaking commands that worked previously, such as
4183 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004184 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004185 idx3 = findoption((char_u *)"sxq");
4186 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4187 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004188 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004189 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4190 }
4191
Bram Moolenaara64ba222012-02-12 23:23:31 +01004192 idx3 = findoption((char_u *)"shcf");
4193 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4194 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004195 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004196 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4197 }
4198 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004199#endif
4200
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004201 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004202 {
4203 int idx_ffs = findoption((char_u *)"ffs");
4204
4205 /* Apply the first entry of 'fileformats' to the initial buffer. */
4206 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4207 set_fileformat(default_fileformat(), OPT_LOCAL);
4208 }
4209
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210#ifdef FEAT_TITLE
4211 set_title_defaults();
4212#endif
4213}
4214
4215#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4216/*
4217 * When 'helplang' is still at its default value, set it to "lang".
4218 * Only the first two characters of "lang" are used.
4219 */
4220 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004221set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004222{
4223 int idx;
4224
4225 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4226 return;
4227 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004228 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004229 {
4230 if (options[idx].flags & P_ALLOCED)
4231 free_string_option(p_hlg);
4232 p_hlg = vim_strsave(lang);
4233 if (p_hlg == NULL)
4234 p_hlg = empty_option;
4235 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004236 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004237 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004238 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4239 {
4240 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4241 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4242 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004243 // any C like setting, such as C.UTF-8, becomes "en"
4244 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4245 {
4246 p_hlg[0] = 'e';
4247 p_hlg[1] = 'n';
4248 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004249 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004250 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004251 options[idx].flags |= P_ALLOCED;
4252 }
4253}
4254#endif
4255
4256#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004257 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004258gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004259{
4260 if (gui_get_lightness(gui.back_pixel) < 127)
4261 return (char_u *)"dark";
4262 return (char_u *)"light";
4263}
4264
4265/*
4266 * Option initializations that can only be done after opening the GUI window.
4267 */
4268 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004269init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270{
4271 /* Set the 'background' option according to the lightness of the
4272 * background color, unless the user has set it already. */
4273 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4274 {
4275 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4276 highlight_changed();
4277 }
4278}
4279#endif
4280
4281#ifdef FEAT_TITLE
4282/*
4283 * 'title' and 'icon' only default to true if they have not been set or reset
4284 * in .vimrc and we can read the old value.
4285 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4286 * they can be reset. This reduces startup time when using X on a remote
4287 * machine.
4288 */
4289 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004290set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004291{
4292 int idx1;
4293 long val;
4294
4295 /*
4296 * If GUI is (going to be) used, we can always set the window title and
4297 * icon name. Saves a bit of time, because the X11 display server does
4298 * not need to be contacted.
4299 */
4300 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004301 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004302 {
4303#ifdef FEAT_GUI
4304 if (gui.starting || gui.in_use)
4305 val = TRUE;
4306 else
4307#endif
4308 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004309 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004310 p_title = val;
4311 }
4312 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004313 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004314 {
4315#ifdef FEAT_GUI
4316 if (gui.starting || gui.in_use)
4317 val = TRUE;
4318 else
4319#endif
4320 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004321 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004322 p_icon = val;
4323 }
4324}
4325#endif
4326
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004327#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02004328/*
4329 * Trigger the OptionSet autocommand.
4330 * "opt_idx" is the index of the option being set.
4331 * "opt_flags" can be OPT_LOCAL etc.
4332 * "oldval" the old value
4333 * "oldval_l" the old local value (only non-NULL if global and local value
4334 * are set)
4335 * "oldval_g" the old global value (only non-NULL if global and local value
4336 * are set)
4337 * "newval" the new value
4338 */
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004339 static void
4340trigger_optionsset_string(
4341 int opt_idx,
4342 int opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02004343 char_u *oldval,
4344 char_u *oldval_l,
4345 char_u *oldval_g,
4346 char_u *newval)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004347{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004348 // Don't do this recursively.
4349 if (oldval != NULL && newval != NULL
4350 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004351 {
4352 char_u buf_type[7];
4353
4354 sprintf((char *)buf_type, "%s",
4355 (opt_flags & OPT_LOCAL) ? "local" : "global");
4356 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4357 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4358 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02004359 if (opt_flags & OPT_LOCAL)
4360 {
4361 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
4362 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4363 }
4364 if (opt_flags & OPT_GLOBAL)
4365 {
4366 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
4367 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
4368 }
4369 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4370 {
4371 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
4372 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
4373 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
4374 }
4375 if (opt_flags & OPT_MODELINE)
4376 {
4377 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
4378 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4379 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004380 apply_autocmds(EVENT_OPTIONSET,
4381 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4382 reset_v_option_vars();
4383 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004384}
4385#endif
4386
Bram Moolenaar071d4272004-06-13 20:20:40 +00004387/*
4388 * Parse 'arg' for option settings.
4389 *
4390 * 'arg' may be IObuff, but only when no errors can be present and option
4391 * does not need to be expanded with option_expand().
4392 * "opt_flags":
4393 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004394 * OPT_GLOBAL for ":setglobal"
4395 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004396 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004397 * OPT_WINONLY to only set window-local options
4398 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004399 *
4400 * returns FAIL if an error is detected, OK otherwise
4401 */
4402 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004403do_set(
4404 char_u *arg, /* option string (may be written to!) */
4405 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004406{
4407 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004408 char *errmsg;
4409 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410 char_u *startarg;
4411 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4412 int nextchar; /* next non-white char after option name */
4413 int afterchar; /* character just after option name */
4414 int len;
4415 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004416 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004417 int key;
4418 long_u flags; /* flags for current option */
4419 char_u *varp = NULL; /* pointer to variable for current option */
4420 int did_show = FALSE; /* already showed one value */
4421 int adding; /* "opt+=arg" */
4422 int prepending; /* "opt^=arg" */
4423 int removing; /* "opt-=arg" */
4424 int cp_val = 0;
4425 char_u key_name[2];
4426
4427 if (*arg == NUL)
4428 {
4429 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004430 did_show = TRUE;
4431 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004432 }
4433
4434 while (*arg != NUL) /* loop to process all options */
4435 {
4436 errmsg = NULL;
4437 startarg = arg; /* remember for error message */
4438
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004439 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4440 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004441 {
4442 /*
4443 * ":set all" show all options.
4444 * ":set all&" set all options to their default value.
4445 */
4446 arg += 3;
4447 if (*arg == '&')
4448 {
4449 ++arg;
4450 /* Only for :set command set global value of local options. */
4451 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004452 didset_options();
4453 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004454 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004455 }
4456 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004457 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004458 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004459 did_show = TRUE;
4460 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004461 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004462 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004463 {
4464 showoptions(2, opt_flags);
4465 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004466 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004467 arg += 7;
4468 }
4469 else
4470 {
4471 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004472 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004473 {
4474 prefix = 0;
4475 arg += 2;
4476 }
4477 else if (STRNCMP(arg, "inv", 3) == 0)
4478 {
4479 prefix = 2;
4480 arg += 3;
4481 }
4482
4483 /* find end of name */
4484 key = 0;
4485 if (*arg == '<')
4486 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004487 opt_idx = -1;
4488 /* look out for <t_>;> */
4489 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4490 len = 5;
4491 else
4492 {
4493 len = 1;
4494 while (arg[len] != NUL && arg[len] != '>')
4495 ++len;
4496 }
4497 if (arg[len] != '>')
4498 {
4499 errmsg = e_invarg;
4500 goto skip;
4501 }
4502 arg[len] = NUL; /* put NUL after name */
4503 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4504 opt_idx = findoption(arg + 1);
4505 arg[len++] = '>'; /* restore '>' */
4506 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004507 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004508 }
4509 else
4510 {
4511 len = 0;
4512 /*
4513 * The two characters after "t_" may not be alphanumeric.
4514 */
4515 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4516 len = 4;
4517 else
4518 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4519 ++len;
4520 nextchar = arg[len];
4521 arg[len] = NUL; /* put NUL after name */
4522 opt_idx = findoption(arg);
4523 arg[len] = nextchar; /* restore nextchar */
4524 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004525 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004526 }
4527
4528 /* remember character after option name */
4529 afterchar = arg[len];
4530
4531 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004532 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004533 ++len;
4534
4535 adding = FALSE;
4536 prepending = FALSE;
4537 removing = FALSE;
4538 if (arg[len] != NUL && arg[len + 1] == '=')
4539 {
4540 if (arg[len] == '+')
4541 {
4542 adding = TRUE; /* "+=" */
4543 ++len;
4544 }
4545 else if (arg[len] == '^')
4546 {
4547 prepending = TRUE; /* "^=" */
4548 ++len;
4549 }
4550 else if (arg[len] == '-')
4551 {
4552 removing = TRUE; /* "-=" */
4553 ++len;
4554 }
4555 }
4556 nextchar = arg[len];
4557
4558 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4559 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004560 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004561 goto skip;
4562 }
4563
4564 if (opt_idx >= 0)
4565 {
4566 if (options[opt_idx].var == NULL) /* hidden option: skip */
4567 {
4568 /* Only give an error message when requesting the value of
4569 * a hidden option, ignore setting it. */
4570 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4571 && (!(options[opt_idx].flags & P_BOOL)
4572 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004573 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004574 goto skip;
4575 }
4576
4577 flags = options[opt_idx].flags;
4578 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4579 }
4580 else
4581 {
4582 flags = P_STRING;
4583 if (key < 0)
4584 {
4585 key_name[0] = KEY2TERMCAP0(key);
4586 key_name[1] = KEY2TERMCAP1(key);
4587 }
4588 else
4589 {
4590 key_name[0] = KS_KEY;
4591 key_name[1] = (key & 0xff);
4592 }
4593 }
4594
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004595 /* Skip all options that are not window-local (used when showing
4596 * an already loaded buffer in a window). */
4597 if ((opt_flags & OPT_WINONLY)
4598 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4599 goto skip;
4600
Bram Moolenaara3227e22006-03-08 21:32:40 +00004601 /* Skip all options that are window-local (used for :vimgrep). */
4602 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4603 && options[opt_idx].var == VAR_WIN)
4604 goto skip;
4605
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004606 /* Disallow changing some options from modelines. */
4607 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004608 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004609 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004610 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004611 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004612 goto skip;
4613 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004614 if ((flags & P_MLE) && !p_mle)
4615 {
4616 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4617 goto skip;
4618 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004619#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004620 /* In diff mode some options are overruled. This avoids that
4621 * 'foldmethod' becomes "marker" instead of "diff" and that
4622 * "wrap" gets set. */
4623 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004624 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004625 && (
4626#ifdef FEAT_FOLDING
4627 options[opt_idx].indir == PV_FDM ||
4628#endif
4629 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004630 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004631#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004632 }
4633
4634#ifdef HAVE_SANDBOX
4635 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004636 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004637 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004638 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004639 goto skip;
4640 }
4641#endif
4642
4643 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4644 {
4645 arg += len;
4646 cp_val = p_cp;
4647 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4648 {
4649 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4650 {
4651 cp_val = FALSE;
4652 arg += 3;
4653 }
4654 else /* "opt&vi": set to Vi default */
4655 {
4656 cp_val = TRUE;
4657 arg += 2;
4658 }
4659 }
4660 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004661 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004662 {
4663 errmsg = e_trailing;
4664 goto skip;
4665 }
4666 }
4667
4668 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004669 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4670 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004671 */
4672 if (nextchar == '?'
4673 || (prefix == 1
4674 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4675 && !(flags & P_BOOL)))
4676 {
4677 /*
4678 * print value
4679 */
4680 if (did_show)
4681 msg_putchar('\n'); /* cursor below last one */
4682 else
4683 {
4684 gotocmdline(TRUE); /* cursor at status line */
4685 did_show = TRUE; /* remember that we did a line */
4686 }
4687 if (opt_idx >= 0)
4688 {
4689 showoneopt(&options[opt_idx], opt_flags);
4690#ifdef FEAT_EVAL
4691 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004692 {
4693 /* Mention where the option was last set. */
4694 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004695 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004696 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004697 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004698 (int)options[opt_idx].indir & PV_MASK]);
4699 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004700 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004701 (int)options[opt_idx].indir & PV_MASK]);
4702 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004703#endif
4704 }
4705 else
4706 {
4707 char_u *p;
4708
4709 p = find_termcode(key_name);
4710 if (p == NULL)
4711 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004712 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004713 goto skip;
4714 }
4715 else
4716 (void)show_one_termcode(key_name, p, TRUE);
4717 }
4718 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004719 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004720 errmsg = e_trailing;
4721 }
4722 else
4723 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004724 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004725 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004726
Bram Moolenaar071d4272004-06-13 20:20:40 +00004727 if (flags & P_BOOL) /* boolean */
4728 {
4729 if (nextchar == '=' || nextchar == ':')
4730 {
4731 errmsg = e_invarg;
4732 goto skip;
4733 }
4734
4735 /*
4736 * ":set opt!": invert
4737 * ":set opt&": reset to default value
4738 * ":set opt<": reset to global value
4739 */
4740 if (nextchar == '!')
4741 value = *(int *)(varp) ^ 1;
4742 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004743 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004744 ((flags & P_VI_DEF) || cp_val)
4745 ? VI_DEFAULT : VIM_DEFAULT];
4746 else if (nextchar == '<')
4747 {
4748 /* For 'autoread' -1 means to use global value. */
4749 if ((int *)varp == &curbuf->b_p_ar
4750 && opt_flags == OPT_LOCAL)
4751 value = -1;
4752 else
4753 value = *(int *)get_varp_scope(&(options[opt_idx]),
4754 OPT_GLOBAL);
4755 }
4756 else
4757 {
4758 /*
4759 * ":set invopt": invert
4760 * ":set opt" or ":set noopt": set or reset
4761 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004762 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004763 {
4764 errmsg = e_trailing;
4765 goto skip;
4766 }
4767 if (prefix == 2) /* inv */
4768 value = *(int *)(varp) ^ 1;
4769 else
4770 value = prefix;
4771 }
4772
4773 errmsg = set_bool_option(opt_idx, varp, (int)value,
4774 opt_flags);
4775 }
4776 else /* numeric or string */
4777 {
4778 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4779 || prefix != 1)
4780 {
4781 errmsg = e_invarg;
4782 goto skip;
4783 }
4784
4785 if (flags & P_NUM) /* numeric */
4786 {
4787 /*
4788 * Different ways to set a number option:
4789 * & set to default value
4790 * < set to global value
4791 * <xx> accept special key codes for 'wildchar'
4792 * c accept any non-digit for 'wildchar'
4793 * [-]0-9 set number
4794 * other error
4795 */
4796 ++arg;
4797 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004798 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004799 ((flags & P_VI_DEF) || cp_val)
4800 ? VI_DEFAULT : VIM_DEFAULT];
4801 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004802 {
4803 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4804 * use the global value. */
4805 if ((long *)varp == &curbuf->b_p_ul
4806 && opt_flags == OPT_LOCAL)
4807 value = NO_LOCAL_UNDOLEVEL;
4808 else
4809 value = *(long *)get_varp_scope(
4810 &(options[opt_idx]), OPT_GLOBAL);
4811 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004812 else if (((long *)varp == &p_wc
4813 || (long *)varp == &p_wcm)
4814 && (*arg == '<'
4815 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004816 || (*arg != NUL
4817 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004818 && !VIM_ISDIGIT(*arg))))
4819 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004820 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004821 if (value == 0 && (long *)varp != &p_wcm)
4822 {
4823 errmsg = e_invarg;
4824 goto skip;
4825 }
4826 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004827 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4828 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004829 /* Allow negative (for 'undolevels'), octal and
4830 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004831 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004832 &value, NULL, 0, TRUE);
Bram Moolenaar06e2c812019-06-12 19:05:48 +02004833 if (i == 0 || (arg[i] != NUL
4834 && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004835 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004836 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004837 goto skip;
4838 }
4839 }
4840 else
4841 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004842 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004843 goto skip;
4844 }
4845
4846 if (adding)
4847 value = *(long *)varp + value;
4848 if (prepending)
4849 value = *(long *)varp * value;
4850 if (removing)
4851 value = *(long *)varp - value;
4852 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004853 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004854 }
4855 else if (opt_idx >= 0) /* string */
4856 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004857 char_u *save_arg = NULL;
4858 char_u *s = NULL;
4859 char_u *oldval = NULL; /* previous value if *varp */
4860 char_u *newval;
4861 char_u *origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004862 char_u *origval_l = NULL;
4863 char_u *origval_g = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004864#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004865 char_u *saved_origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004866 char_u *saved_origval_l = NULL;
4867 char_u *saved_origval_g = NULL;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004868 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004869#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004870 unsigned newlen;
4871 int comma;
4872 int bs;
4873 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004874 was allocated */
4875
4876 /* When using ":set opt=val" for a global option
4877 * with a local value the local value will be
4878 * reset, use the global value here. */
4879 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004880 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004881 varp = options[opt_idx].var;
4882
4883 /* The old value is kept until we are sure that the
4884 * new value is valid. */
4885 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004886
Bram Moolenaard7c96872019-06-15 17:12:48 +02004887 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4888 {
4889 origval_l = *(char_u **)get_varp_scope(
4890 &(options[opt_idx]), OPT_LOCAL);
4891 origval_g = *(char_u **)get_varp_scope(
4892 &(options[opt_idx]), OPT_GLOBAL);
4893
4894 // A global-local string option might have an empty
4895 // option as value to indicate that the global
4896 // value should be used.
4897 if (((int)options[opt_idx].indir & PV_BOTH)
4898 && origval_l == empty_option)
4899 origval_l = origval_g;
4900 }
4901
4902 // When setting the local value of a global
4903 // option, the old value may be the global value.
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004904 if (((int)options[opt_idx].indir & PV_BOTH)
4905 && (opt_flags & OPT_LOCAL))
4906 origval = *(char_u **)get_varp(
4907 &options[opt_idx]);
4908 else
4909 origval = oldval;
4910
Bram Moolenaar071d4272004-06-13 20:20:40 +00004911 if (nextchar == '&') /* set to default val */
4912 {
4913 newval = options[opt_idx].def_val[
4914 ((flags & P_VI_DEF) || cp_val)
4915 ? VI_DEFAULT : VIM_DEFAULT];
4916 if ((char_u **)varp == &p_bg)
4917 {
4918 /* guess the value of 'background' */
4919#ifdef FEAT_GUI
4920 if (gui.in_use)
4921 newval = gui_bg_default();
4922 else
4923#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004924 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004925 }
4926
4927 /* expand environment variables and ~ (since the
4928 * default value was already expanded, only
4929 * required when an environment variable was set
4930 * later */
4931 if (newval == NULL)
4932 newval = empty_option;
4933 else
4934 {
4935 s = option_expand(opt_idx, newval);
4936 if (s == NULL)
4937 s = newval;
4938 newval = vim_strsave(s);
4939 }
4940 new_value_alloced = TRUE;
4941 }
4942 else if (nextchar == '<') /* set to global val */
4943 {
4944 newval = vim_strsave(*(char_u **)get_varp_scope(
4945 &(options[opt_idx]), OPT_GLOBAL));
4946 new_value_alloced = TRUE;
4947 }
4948 else
4949 {
4950 ++arg; /* jump to after the '=' or ':' */
4951
4952 /*
4953 * Set 'keywordprg' to ":help" if an empty
4954 * value was passed to :set by the user.
4955 * Misuse errbuf[] for the resulting string.
4956 */
4957 if (varp == (char_u *)&p_kp
4958 && (*arg == NUL || *arg == ' '))
4959 {
4960 STRCPY(errbuf, ":help");
4961 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004962 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004963 }
4964 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004965 * Convert 'backspace' number to string, for
4966 * adding, prepending and removing string.
4967 */
4968 else if (varp == (char_u *)&p_bs
4969 && VIM_ISDIGIT(**(char_u **)varp))
4970 {
4971 i = getdigits((char_u **)varp);
4972 switch (i)
4973 {
4974 case 0:
4975 *(char_u **)varp = empty_option;
4976 break;
4977 case 1:
4978 *(char_u **)varp = vim_strsave(
4979 (char_u *)"indent,eol");
4980 break;
4981 case 2:
4982 *(char_u **)varp = vim_strsave(
4983 (char_u *)"indent,eol,start");
4984 break;
4985 }
4986 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004987 if (origval == oldval)
4988 origval = *(char_u **)varp;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004989 if (origval_l == oldval)
4990 origval_l = *(char_u **)varp;
4991 if (origval_g == oldval)
4992 origval_g = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004993 oldval = *(char_u **)varp;
4994 }
4995 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004996 * Convert 'whichwrap' number to string, for
4997 * backwards compatibility with Vim 3.0.
4998 * Misuse errbuf[] for the resulting string.
4999 */
5000 else if (varp == (char_u *)&p_ww
5001 && VIM_ISDIGIT(*arg))
5002 {
5003 *errbuf = NUL;
5004 i = getdigits(&arg);
5005 if (i & 1)
5006 STRCAT(errbuf, "b,");
5007 if (i & 2)
5008 STRCAT(errbuf, "s,");
5009 if (i & 4)
5010 STRCAT(errbuf, "h,l,");
5011 if (i & 8)
5012 STRCAT(errbuf, "<,>,");
5013 if (i & 16)
5014 STRCAT(errbuf, "[,],");
5015 if (*errbuf != NUL) /* remove trailing , */
5016 errbuf[STRLEN(errbuf) - 1] = NUL;
5017 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005018 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005019 }
5020 /*
5021 * Remove '>' before 'dir' and 'bdir', for
5022 * backwards compatibility with version 3.0
5023 */
5024 else if ( *arg == '>'
5025 && (varp == (char_u *)&p_dir
5026 || varp == (char_u *)&p_bdir))
5027 {
5028 ++arg;
5029 }
5030
Bram Moolenaar071d4272004-06-13 20:20:40 +00005031 /*
5032 * Copy the new string into allocated memory.
5033 * Can't use set_string_option_direct(), because
5034 * we need to remove the backslashes.
5035 */
5036 /* get a bit too much */
5037 newlen = (unsigned)STRLEN(arg) + 1;
5038 if (adding || prepending || removing)
5039 newlen += (unsigned)STRLEN(origval) + 1;
5040 newval = alloc(newlen);
5041 if (newval == NULL) /* out of mem, don't change */
5042 break;
5043 s = newval;
5044
5045 /*
5046 * Copy the string, skip over escaped chars.
5047 * For MS-DOS and WIN32 backslashes before normal
5048 * file name characters are not removed, and keep
5049 * backslash at start, for "\\machine\path", but
5050 * do remove it for "\\\\machine\\path".
5051 * The reverse is found in ExpandOldSetting().
5052 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005053 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005054 {
5055 if (*arg == '\\' && arg[1] != NUL
5056#ifdef BACKSLASH_IN_FILENAME
5057 && !((flags & P_EXPAND)
5058 && vim_isfilec(arg[1])
5059 && (arg[1] != '\\'
5060 || (s == newval
5061 && arg[2] != '\\')))
5062#endif
5063 )
5064 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005065 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005066 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005067 {
5068 /* copy multibyte char */
5069 mch_memmove(s, arg, (size_t)i);
5070 arg += i;
5071 s += i;
5072 }
5073 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005074 *s++ = *arg++;
5075 }
5076 *s = NUL;
5077
5078 /*
5079 * Expand environment variables and ~.
5080 * Don't do it when adding without inserting a
5081 * comma.
5082 */
5083 if (!(adding || prepending || removing)
5084 || (flags & P_COMMA))
5085 {
5086 s = option_expand(opt_idx, newval);
5087 if (s != NULL)
5088 {
5089 vim_free(newval);
5090 newlen = (unsigned)STRLEN(s) + 1;
5091 if (adding || prepending || removing)
5092 newlen += (unsigned)STRLEN(origval) + 1;
5093 newval = alloc(newlen);
5094 if (newval == NULL)
5095 break;
5096 STRCPY(newval, s);
5097 }
5098 }
5099
5100 /* locate newval[] in origval[] when removing it
5101 * and when adding to avoid duplicates */
5102 i = 0; /* init for GCC */
5103 if (removing || (flags & P_NODUP))
5104 {
5105 i = (int)STRLEN(newval);
5106 bs = 0;
5107 for (s = origval; *s; ++s)
5108 {
5109 if ((!(flags & P_COMMA)
5110 || s == origval
5111 || (s[-1] == ',' && !(bs & 1)))
5112 && STRNCMP(s, newval, i) == 0
5113 && (!(flags & P_COMMA)
5114 || s[i] == ','
5115 || s[i] == NUL))
5116 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005117 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005118 * even number of backslashes or a single
5119 * backslash preceded by a comma before it
5120 * is recognized as a separator */
5121 if ((s > origval + 1
5122 && s[-1] == '\\'
5123 && s[-2] != ',')
5124 || (s == origval + 1
5125 && s[-1] == '\\'))
5126
Bram Moolenaar071d4272004-06-13 20:20:40 +00005127 ++bs;
5128 else
5129 bs = 0;
5130 }
5131
5132 /* do not add if already there */
5133 if ((adding || prepending) && *s)
5134 {
5135 prepending = FALSE;
5136 adding = FALSE;
5137 STRCPY(newval, origval);
5138 }
5139 }
5140
5141 /* concatenate the two strings; add a ',' if
5142 * needed */
5143 if (adding || prepending)
5144 {
5145 comma = ((flags & P_COMMA) && *origval != NUL
5146 && *newval != NUL);
5147 if (adding)
5148 {
5149 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005150 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005151 if (comma && i > 1
5152 && (flags & P_ONECOMMA) == P_ONECOMMA
5153 && origval[i - 1] == ','
5154 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005155 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005156 mch_memmove(newval + i + comma, newval,
5157 STRLEN(newval) + 1);
5158 mch_memmove(newval, origval, (size_t)i);
5159 }
5160 else
5161 {
5162 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005163 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005164 }
5165 if (comma)
5166 newval[i] = ',';
5167 }
5168
5169 /* Remove newval[] from origval[]. (Note: "i" has
5170 * been set above and is used here). */
5171 if (removing)
5172 {
5173 STRCPY(newval, origval);
5174 if (*s)
5175 {
5176 /* may need to remove a comma */
5177 if (flags & P_COMMA)
5178 {
5179 if (s == origval)
5180 {
5181 /* include comma after string */
5182 if (s[i] == ',')
5183 ++i;
5184 }
5185 else
5186 {
5187 /* include comma before string */
5188 --s;
5189 ++i;
5190 }
5191 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005192 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005193 }
5194 }
5195
5196 if (flags & P_FLAGLIST)
5197 {
5198 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005199 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005200 {
5201 /* if options have P_FLAGLIST and
5202 * P_ONECOMMA such as 'whichwrap' */
5203 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005204 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005205 if (*s != ',' && *(s + 1) == ','
5206 && vim_strchr(s + 2, *s) != NULL)
5207 {
5208 /* Remove the duplicated value and
5209 * the next comma. */
5210 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005211 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005212 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005213 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005214 else
5215 {
5216 if ((!(flags & P_COMMA) || *s != ',')
5217 && vim_strchr(s + 1, *s) != NULL)
5218 {
5219 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005220 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005221 }
5222 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005223 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005224 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005225 }
5226
5227 if (save_arg != NULL) /* number for 'whichwrap' */
5228 arg = save_arg;
5229 new_value_alloced = TRUE;
5230 }
5231
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005232 /*
5233 * Set the new value.
5234 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005235 *(char_u **)(varp) = newval;
5236
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005237#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005238 if (!starting
5239# ifdef FEAT_CRYPT
5240 && options[opt_idx].indir != PV_KEY
5241# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005242 && origval != NULL && newval != NULL)
5243 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005244 /* origval may be freed by
5245 * did_set_string_option(), make a copy. */
5246 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005247 /* newval (and varp) may become invalid if the
5248 * buffer is closed by autocommands. */
5249 saved_newval = vim_strsave(newval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005250 if (origval_l != NULL)
5251 saved_origval_l = vim_strsave(origval_l);
5252 if (origval_g != NULL)
5253 saved_origval_g = vim_strsave(origval_g);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005254 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005255#endif
5256
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005257 {
5258 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005259 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005260
5261 // When an option is set in the sandbox, from a
5262 // modeline or in secure mode, then deal with side
5263 // effects in secure mode. Also when the value was
5264 // set with the P_INSECURE flag and is not
5265 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005266 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005267#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005268 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005269#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005270 || (!value_is_replaced && (*p & P_INSECURE)))
5271 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005272
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005273 // Handle side effects, and set the global value
5274 // for ":set" on local options. Note: when setting
5275 // 'syntax' or 'filetype' autocommands may be
5276 // triggered that can cause havoc.
5277 errmsg = did_set_string_option(
5278 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005279 new_value_alloced, oldval, errbuf,
5280 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005281
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005282 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005283 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005284
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005285#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005286 if (errmsg == NULL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02005287 trigger_optionsset_string(
5288 opt_idx, opt_flags, saved_origval,
5289 saved_origval_l, saved_origval_g,
5290 saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005291 vim_free(saved_origval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005292 vim_free(saved_origval_l);
5293 vim_free(saved_origval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005294 vim_free(saved_newval);
5295#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005296 /* If error detected, print the error message. */
5297 if (errmsg != NULL)
5298 goto skip;
5299 }
5300 else /* key code option */
5301 {
5302 char_u *p;
5303
5304 if (nextchar == '&')
5305 {
5306 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005307 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005308 }
5309 else
5310 {
5311 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005312 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005313 if (*p == '\\' && p[1] != NUL)
5314 ++p;
5315 nextchar = *p;
5316 *p = NUL;
5317 add_termcode(key_name, arg, FALSE);
5318 *p = nextchar;
5319 }
5320 if (full_screen)
5321 ttest(FALSE);
5322 redraw_all_later(CLEAR);
5323 }
5324 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005325
Bram Moolenaar071d4272004-06-13 20:20:40 +00005326 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005327 did_set_option(
5328 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005329 }
5330
5331skip:
5332 /*
5333 * Advance to next argument.
5334 * - skip until a blank found, taking care of backslashes
5335 * - skip blanks
5336 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5337 */
5338 for (i = 0; i < 2 ; ++i)
5339 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005340 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005341 if (*arg++ == '\\' && *arg != NUL)
5342 ++arg;
5343 arg = skipwhite(arg);
5344 if (*arg != '=')
5345 break;
5346 }
5347 }
5348
5349 if (errmsg != NULL)
5350 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005351 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005352 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005353 if (i + (arg - startarg) < IOSIZE)
5354 {
5355 /* append the argument with the error */
5356 STRCAT(IObuff, ": ");
5357 mch_memmove(IObuff + i, startarg, (arg - startarg));
5358 IObuff[i + (arg - startarg)] = NUL;
5359 }
5360 /* make sure all characters are printable */
5361 trans_characters(IObuff, IOSIZE);
5362
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005363 ++no_wait_return; // wait_return done later
5364 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005365 --no_wait_return;
5366
5367 return FAIL;
5368 }
5369
5370 arg = skipwhite(arg);
5371 }
5372
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005373theend:
5374 if (silent_mode && did_show)
5375 {
5376 /* After displaying option values in silent mode. */
5377 silent_mode = FALSE;
5378 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5379 msg_putchar('\n');
5380 cursor_on(); /* msg_start() switches it off */
5381 out_flush();
5382 silent_mode = TRUE;
5383 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5384 }
5385
Bram Moolenaar071d4272004-06-13 20:20:40 +00005386 return OK;
5387}
5388
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005389/*
5390 * Call this when an option has been given a new value through a user command.
5391 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5392 */
5393 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005394did_set_option(
5395 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005396 int opt_flags, // possibly with OPT_MODELINE
5397 int new_value, // value was replaced completely
5398 int value_checked) // value was checked to be safe, no need to set the
5399 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005400{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005401 long_u *p;
5402
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005403 options[opt_idx].flags |= P_WAS_SET;
5404
5405 /* When an option is set in the sandbox, from a modeline or in secure mode
5406 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005407 * flag. */
5408 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005409 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005410#ifdef HAVE_SANDBOX
5411 || sandbox != 0
5412#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005413 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005414 *p = *p | P_INSECURE;
5415 else if (new_value)
5416 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005417}
5418
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005419 static char *
5420illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005421{
5422 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005423 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005424 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005425 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005426 return errbuf;
5427}
5428
5429/*
5430 * Convert a key name or string into a key value.
5431 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005432 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005433 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005434 int
5435string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005436{
5437 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005438 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005439 if (*arg == '^')
5440 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005441 if (multi_byte)
5442 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005443 return *arg;
5444}
5445
5446#ifdef FEAT_CMDWIN
5447/*
5448 * Check value of 'cedit' and set cedit_key.
5449 * Returns NULL if value is OK, error message otherwise.
5450 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005451 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005452check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005453{
5454 int n;
5455
5456 if (*p_cedit == NUL)
5457 cedit_key = -1;
5458 else
5459 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005460 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005461 if (vim_isprintc(n))
5462 return e_invarg;
5463 cedit_key = n;
5464 }
5465 return NULL;
5466}
5467#endif
5468
5469#ifdef FEAT_TITLE
5470/*
5471 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5472 * maketitle() to create and display it.
5473 * When switching the title or icon off, call mch_restore_title() to get
5474 * the old value back.
5475 */
5476 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005477did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005478{
5479 if (starting != NO_SCREEN
5480#ifdef FEAT_GUI
5481 && !gui.starting
5482#endif
5483 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005484 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005485}
5486#endif
5487
5488/*
5489 * set_options_bin - called when 'bin' changes value.
5490 */
5491 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005492set_options_bin(
5493 int oldval,
5494 int newval,
5495 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496{
5497 /*
5498 * The option values that are changed when 'bin' changes are
5499 * copied when 'bin is set and restored when 'bin' is reset.
5500 */
5501 if (newval)
5502 {
5503 if (!oldval) /* switched on */
5504 {
5505 if (!(opt_flags & OPT_GLOBAL))
5506 {
5507 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5508 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5509 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5510 curbuf->b_p_et_nobin = curbuf->b_p_et;
5511 }
5512 if (!(opt_flags & OPT_LOCAL))
5513 {
5514 p_tw_nobin = p_tw;
5515 p_wm_nobin = p_wm;
5516 p_ml_nobin = p_ml;
5517 p_et_nobin = p_et;
5518 }
5519 }
5520
5521 if (!(opt_flags & OPT_GLOBAL))
5522 {
5523 curbuf->b_p_tw = 0; /* no automatic line wrap */
5524 curbuf->b_p_wm = 0; /* no automatic line wrap */
5525 curbuf->b_p_ml = 0; /* no modelines */
5526 curbuf->b_p_et = 0; /* no expandtab */
5527 }
5528 if (!(opt_flags & OPT_LOCAL))
5529 {
5530 p_tw = 0;
5531 p_wm = 0;
5532 p_ml = FALSE;
5533 p_et = FALSE;
5534 p_bin = TRUE; /* needed when called for the "-b" argument */
5535 }
5536 }
5537 else if (oldval) /* switched off */
5538 {
5539 if (!(opt_flags & OPT_GLOBAL))
5540 {
5541 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5542 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5543 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5544 curbuf->b_p_et = curbuf->b_p_et_nobin;
5545 }
5546 if (!(opt_flags & OPT_LOCAL))
5547 {
5548 p_tw = p_tw_nobin;
5549 p_wm = p_wm_nobin;
5550 p_ml = p_ml_nobin;
5551 p_et = p_et_nobin;
5552 }
5553 }
5554}
5555
Bram Moolenaar071d4272004-06-13 20:20:40 +00005556/*
5557 * Expand environment variables for some string options.
5558 * These string options cannot be indirect!
5559 * If "val" is NULL expand the current value of the option.
5560 * Return pointer to NameBuff, or NULL when not expanded.
5561 */
5562 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005563option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005564{
5565 /* if option doesn't need expansion nothing to do */
5566 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5567 return NULL;
5568
5569 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5570 * expand_env() would truncate the string. */
5571 if (val != NULL && STRLEN(val) > MAXPATHL)
5572 return NULL;
5573
5574 if (val == NULL)
5575 val = *(char_u **)options[opt_idx].var;
5576
5577 /*
5578 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5579 * Escape spaces when expanding 'tags', they are used to separate file
5580 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005581 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005582 */
5583 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005584 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005585#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005586 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5587#endif
5588 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005589 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5590 return NULL;
5591
5592 return NameBuff;
5593}
5594
5595/*
5596 * After setting various option values: recompute variables that depend on
5597 * option values.
5598 */
5599 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005600didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005601{
5602 /* initialize the table for 'iskeyword' et.al. */
5603 (void)init_chartab();
5604
5605 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5606 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005607 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005608#ifdef FEAT_SESSION
5609 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5610 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5611#endif
5612#ifdef FEAT_FOLDING
5613 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5614#endif
5615 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005616 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005617 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005618#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5619 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5620#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005621#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005622 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005623 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005624 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005625 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005626#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005627#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005628 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5629#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005630#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005631 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5632#endif
5633#ifdef FEAT_CMDWIN
5634 /* set cedit_key */
5635 (void)check_cedit();
5636#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005637#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005638 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005639#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005640#ifdef FEAT_LINEBREAK
5641 /* initialize the table for 'breakat'. */
5642 fill_breakat_flags();
5643#endif
5644
5645}
5646
5647/*
5648 * More side effects of setting options.
5649 */
5650 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005651didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005652{
5653 /* Initialize the highlight_attr[] table. */
5654 (void)highlight_changed();
5655
5656 /* Parse default for 'wildmode' */
5657 check_opt_wim();
5658
5659 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005660 /* Parse default for 'fillchars'. */
5661 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005662
5663#ifdef FEAT_CLIPBOARD
5664 /* Parse default for 'clipboard' */
5665 (void)check_clipboard_option();
5666#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005667#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005668 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005669 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005670 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005671 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5672#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005673}
5674
5675/*
5676 * Check for string options that are NULL (normally only termcap options).
5677 */
5678 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005679check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680{
5681 int opt_idx;
5682
5683 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5684 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5685 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5686}
5687
5688/*
5689 * Check string options in a buffer for NULL value.
5690 */
5691 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005692check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005693{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694 check_string_option(&buf->b_p_bh);
5695 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005696 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005697 check_string_option(&buf->b_p_ff);
5698#ifdef FEAT_FIND_ID
5699 check_string_option(&buf->b_p_def);
5700 check_string_option(&buf->b_p_inc);
5701# ifdef FEAT_EVAL
5702 check_string_option(&buf->b_p_inex);
5703# endif
5704#endif
5705#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5706 check_string_option(&buf->b_p_inde);
5707 check_string_option(&buf->b_p_indk);
5708#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005709#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5710 check_string_option(&buf->b_p_bexpr);
5711#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005712#if defined(FEAT_CRYPT)
5713 check_string_option(&buf->b_p_cm);
5714#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005715 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005716#if defined(FEAT_EVAL)
5717 check_string_option(&buf->b_p_fex);
5718#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005719#ifdef FEAT_CRYPT
5720 check_string_option(&buf->b_p_key);
5721#endif
5722 check_string_option(&buf->b_p_kp);
5723 check_string_option(&buf->b_p_mps);
5724 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005725 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005726 check_string_option(&buf->b_p_isk);
5727#ifdef FEAT_COMMENTS
5728 check_string_option(&buf->b_p_com);
5729#endif
5730#ifdef FEAT_FOLDING
5731 check_string_option(&buf->b_p_cms);
5732#endif
5733 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005734#ifdef FEAT_TEXTOBJ
5735 check_string_option(&buf->b_p_qe);
5736#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737#ifdef FEAT_SYN_HL
5738 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005739 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005740#endif
5741#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005742 check_string_option(&buf->b_s.b_p_spc);
5743 check_string_option(&buf->b_s.b_p_spf);
5744 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005745#endif
5746#ifdef FEAT_SEARCHPATH
5747 check_string_option(&buf->b_p_sua);
5748#endif
5749#ifdef FEAT_CINDENT
5750 check_string_option(&buf->b_p_cink);
5751 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005752 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005753#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005754 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005755#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5756 check_string_option(&buf->b_p_cinw);
5757#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005758 check_string_option(&buf->b_p_cpt);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005759#ifdef FEAT_COMPL_FUNC
5760 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005761 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005762#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005763#ifdef FEAT_EVAL
5764 check_string_option(&buf->b_p_tfu);
5765#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005766#ifdef FEAT_KEYMAP
5767 check_string_option(&buf->b_p_keymap);
5768#endif
5769#ifdef FEAT_QUICKFIX
5770 check_string_option(&buf->b_p_gp);
5771 check_string_option(&buf->b_p_mp);
5772 check_string_option(&buf->b_p_efm);
5773#endif
5774 check_string_option(&buf->b_p_ep);
5775 check_string_option(&buf->b_p_path);
5776 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005777 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005778 check_string_option(&buf->b_p_dict);
5779 check_string_option(&buf->b_p_tsr);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005780#ifdef FEAT_LISP
5781 check_string_option(&buf->b_p_lw);
5782#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005783 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005784 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005785#ifdef FEAT_VARTABS
5786 check_string_option(&buf->b_p_vsts);
5787 check_string_option(&buf->b_p_vts);
5788#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005789}
5790
5791/*
5792 * Free the string allocated for an option.
5793 * Checks for the string being empty_option. This may happen if we're out of
5794 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5795 * check_options().
5796 * Does NOT check for P_ALLOCED flag!
5797 */
5798 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005799free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005800{
5801 if (p != empty_option)
5802 vim_free(p);
5803}
5804
5805 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005806clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005807{
5808 if (*pp != empty_option)
5809 vim_free(*pp);
5810 *pp = empty_option;
5811}
5812
5813 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005814check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005815{
5816 if (*pp == NULL)
5817 *pp = empty_option;
5818}
5819
5820/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005821 * Return the option index found by a pointer into term_strings[].
5822 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005823 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005824 int
5825get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005827 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005828
5829 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5830 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005831 return opt_idx;
5832 return -1; // cannot happen: didn't find it!
5833}
5834
5835/*
5836 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5837 * Return the option index or -1 if not found.
5838 */
5839 int
5840set_term_option_alloced(char_u **p)
5841{
5842 int opt_idx = get_term_opt_idx(p);
5843
5844 if (opt_idx >= 0)
5845 options[opt_idx].flags |= P_ALLOCED;
5846 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005847}
5848
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005849#if defined(FEAT_EVAL) || defined(PROTO)
5850/*
5851 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5852 * Return FALSE when it wasn't.
5853 * Return -1 for an unknown option.
5854 */
5855 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005856was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005857{
5858 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005859 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005860
5861 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005862 {
5863 flagp = insecure_flag(idx, opt_flags);
5864 return (*flagp & P_INSECURE) != 0;
5865 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005866 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005867 return -1;
5868}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005869
5870/*
5871 * Get a pointer to the flags used for the P_INSECURE flag of option
5872 * "opt_idx". For some local options a local flags field is used.
5873 */
5874 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005875insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005876{
5877 if (opt_flags & OPT_LOCAL)
5878 switch ((int)options[opt_idx].indir)
5879 {
5880#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005881 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005882#endif
5883#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005884# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005885 case PV_FDE: return &curwin->w_p_fde_flags;
5886 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005887# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005888# ifdef FEAT_BEVAL
5889 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5890# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005891# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005892 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005893# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005894 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005895# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005896 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005897# endif
5898#endif
5899 }
5900
5901 /* Nothing special, return global flags field. */
5902 return &options[opt_idx].flags;
5903}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005904#endif
5905
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005906#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005907/*
5908 * Redraw the window title and/or tab page text later.
5909 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005910static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005911{
5912 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005913 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005914}
5915#endif
5916
Bram Moolenaar071d4272004-06-13 20:20:40 +00005917/*
5918 * Set a string option to a new value (without checking the effect).
5919 * The string is copied into allocated memory.
5920 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005921 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5922 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5923 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005924 */
5925 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005926set_string_option_direct(
5927 char_u *name,
5928 int opt_idx,
5929 char_u *val,
5930 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5931 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005932{
5933 char_u *s;
5934 char_u **varp;
5935 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005936 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005937
Bram Moolenaar89d40322006-08-29 15:30:07 +00005938 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005939 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005940 idx = findoption(name);
5941 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005942 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005943 semsg(_(e_intern2), "set_string_option_direct()");
5944 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005945 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005947 }
5948
Bram Moolenaar89d40322006-08-29 15:30:07 +00005949 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950 return;
5951
5952 s = vim_strsave(val);
5953 if (s != NULL)
5954 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005955 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005957 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005958 free_string_option(*varp);
5959 *varp = s;
5960
5961 /* For buffer/window local option may also set the global value. */
5962 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005963 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005964
Bram Moolenaar89d40322006-08-29 15:30:07 +00005965 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005966
5967 /* When setting both values of a global option with a local value,
5968 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005969 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005970 {
5971 free_string_option(*varp);
5972 *varp = empty_option;
5973 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005974# ifdef FEAT_EVAL
5975 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005976 {
5977 sctx_T script_ctx;
5978
5979 if (set_sid == 0)
5980 script_ctx = current_sctx;
5981 else
5982 {
5983 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005984 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005985 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005986 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005987 }
5988 set_option_sctx_idx(idx, opt_flags, script_ctx);
5989 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005990# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 }
5992}
5993
5994/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02005995 * Like set_string_option_direct(), but for a window-local option in "wp".
5996 * Blocks autocommands to avoid the old curwin becoming invalid.
5997 */
5998 void
5999set_string_option_direct_in_win(
6000 win_T *wp,
6001 char_u *name,
6002 int opt_idx,
6003 char_u *val,
6004 int opt_flags,
6005 int set_sid)
6006{
6007 win_T *save_curwin = curwin;
6008
6009 block_autocmds();
6010 curwin = wp;
6011 curbuf = curwin->w_buffer;
6012 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6013 curwin = save_curwin;
6014 curbuf = curwin->w_buffer;
6015 unblock_autocmds();
6016}
6017
6018/*
6019 * Like set_string_option_direct(), but for a buffer-local option in "buf".
6020 * Blocks autocommands to avoid the old curbuf becoming invalid.
6021 */
6022 void
6023set_string_option_direct_in_buf(
6024 buf_T *buf,
6025 char_u *name,
6026 int opt_idx,
6027 char_u *val,
6028 int opt_flags,
6029 int set_sid)
6030{
6031 buf_T *save_curbuf = curbuf;
6032
6033 block_autocmds();
6034 curbuf = buf;
6035 curwin->w_buffer = curbuf;
6036 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6037 curbuf = save_curbuf;
6038 curwin->w_buffer = curbuf;
6039 unblock_autocmds();
6040}
6041
6042/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006043 * Set global value for string option when it's a local option.
6044 */
6045 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006046set_string_option_global(
6047 int opt_idx, /* option index */
6048 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006049{
6050 char_u **p, *s;
6051
6052 /* the global value is always allocated */
6053 if (options[opt_idx].var == VAR_WIN)
6054 p = (char_u **)GLOBAL_WO(varp);
6055 else
6056 p = (char_u **)options[opt_idx].var;
6057 if (options[opt_idx].indir != PV_NONE
6058 && p != varp
6059 && (s = vim_strsave(*varp)) != NULL)
6060 {
6061 free_string_option(*p);
6062 *p = s;
6063 }
6064}
6065
6066/*
6067 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006068 *
6069 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006070 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006071 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006072set_string_option(
6073 int opt_idx,
6074 char_u *value,
6075 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006076{
6077 char_u *s;
6078 char_u **varp;
6079 char_u *oldval;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006080#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006081 char_u *oldval_l = NULL;
6082 char_u *oldval_g = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006083 char_u *saved_oldval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02006084 char_u *saved_oldval_l = NULL;
6085 char_u *saved_oldval_g = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006086 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006087#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006088 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006089 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006090
6091 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006092 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006093
6094 s = vim_strsave(value);
6095 if (s != NULL)
6096 {
6097 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6098 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006099 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006100 ? OPT_GLOBAL : OPT_LOCAL)
6101 : opt_flags);
6102 oldval = *varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006103#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006104 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6105 {
6106 oldval_l = *(char_u **)get_varp_scope(&(options[opt_idx]),
6107 OPT_LOCAL);
6108 oldval_g = *(char_u **)get_varp_scope(&(options[opt_idx]),
6109 OPT_GLOBAL);
6110 }
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006112 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006113
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006114#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006115 if (!starting
6116# ifdef FEAT_CRYPT
6117 && options[opt_idx].indir != PV_KEY
6118# endif
6119 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006120 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02006121 if (oldval_l != NULL)
6122 saved_oldval_l = vim_strsave(oldval_l);
6123 if (oldval_g != NULL)
6124 saved_oldval_g = vim_strsave(oldval_g);
Bram Moolenaar53744302015-07-17 17:38:22 +02006125 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006126 saved_newval = vim_strsave(s);
6127 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006128#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006129 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006130 opt_flags, &value_checked)) == NULL)
6131 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006132
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006133#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006134 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006135 if (r == NULL)
6136 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02006137 saved_oldval, saved_oldval_l,
6138 saved_oldval_g, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006139 vim_free(saved_oldval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02006140 vim_free(saved_oldval_l);
6141 vim_free(saved_oldval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006142 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006144 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006145 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006146}
6147
6148/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006149 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6150 * characters or characters in "allowed".
6151 */
Bram Moolenaare677df82019-09-02 22:31:11 +02006152 int
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006153valid_name(char_u *val, char *allowed)
6154{
6155 char_u *s;
6156
6157 for (s = val; *s != NUL; ++s)
6158 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6159 return FALSE;
6160 return TRUE;
6161}
6162
6163/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006164 * Return TRUE if "val" is a valid 'filetype' name.
6165 * Also used for 'syntax' and 'keymap'.
6166 */
6167 static int
6168valid_filetype(char_u *val)
6169{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006170 return valid_name(val, ".-_");
6171}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006172
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006173/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006174 * Handle string options that need some action to perform when changed.
6175 * Returns NULL for success, or an error message for an error.
6176 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006177 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006178did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006179 int opt_idx, // index in options[] table
6180 char_u **varp, // pointer to the option variable
6181 int new_value_alloced, // new value was allocated
6182 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006183 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006184 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6185 int *value_checked) // value was checked to be save, no
6186 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006187{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006188 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006189 char_u *s, *p;
6190 int did_chartab = FALSE;
6191 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006192 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006193#ifdef FEAT_GUI
6194 /* set when changing an option that only requires a redraw in the GUI */
6195 int redraw_gui_only = FALSE;
6196#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006197 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006198#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6199 int did_swaptcap = FALSE;
6200#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006201
6202 /* Get the global option to compare with, otherwise we would have to check
6203 * two values for all local options. */
6204 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6205
6206 /* Disallow changing some options from secure mode */
6207 if ((secure
6208#ifdef HAVE_SANDBOX
6209 || sandbox != 0
6210#endif
6211 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006213
Bram Moolenaar916a8182018-11-25 02:18:29 +01006214 // Check for a "normal" directory or file name in some options. Disallow a
6215 // path separator (slash and/or backslash), wildcards and characters that
6216 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006217 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006218 && vim_strpbrk(*varp, (char_u *)(secure
6219 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006220 || ((options[opt_idx].flags & P_NDNAME)
6221 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006222 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006223
Bram Moolenaar071d4272004-06-13 20:20:40 +00006224 /* 'term' */
6225 else if (varp == &T_NAME)
6226 {
6227 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006228 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006229#ifdef FEAT_GUI
6230 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006231 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006232 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006233 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006234#endif
6235 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006236 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006237 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006238 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006239 /* Screen colors may have changed. */
6240 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006241
6242 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6243 * P_ALLOCED flag on 'term'. */
6244 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006245 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006246 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006247 }
6248
6249 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006250 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006251 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006252 char_u *bkc = p_bkc;
6253 unsigned int *flags = &bkc_flags;
6254
6255 if (opt_flags & OPT_LOCAL)
6256 {
6257 bkc = curbuf->b_p_bkc;
6258 flags = &curbuf->b_bkc_flags;
6259 }
6260
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006261 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6262 /* make the local value empty: use the global value */
6263 *flags = 0;
6264 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006265 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006266 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6267 errmsg = e_invarg;
6268 if ((((int)*flags & BKC_AUTO) != 0)
6269 + (((int)*flags & BKC_YES) != 0)
6270 + (((int)*flags & BKC_NO) != 0) != 1)
6271 {
6272 /* Must have exactly one of "auto", "yes" and "no". */
6273 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6274 errmsg = e_invarg;
6275 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276 }
6277 }
6278
6279 /* 'backupext' and 'patchmode' */
6280 else if (varp == &p_bex || varp == &p_pm)
6281 {
6282 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6283 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006284 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006285 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006286#ifdef FEAT_LINEBREAK
6287 /* 'breakindentopt' */
6288 else if (varp == &curwin->w_p_briopt)
6289 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006290 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006291 errmsg = e_invarg;
6292 }
6293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006294
6295 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006296 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006297 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006298 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006299 */
6300 else if ( varp == &p_isi
6301 || varp == &(curbuf->b_p_isk)
6302 || varp == &p_isp
6303 || varp == &p_isf)
6304 {
6305 if (init_chartab() == FAIL)
6306 {
6307 did_chartab = TRUE; /* need to restore it below */
6308 errmsg = e_invarg; /* error in value */
6309 }
6310 }
6311
6312 /* 'helpfile' */
6313 else if (varp == &p_hf)
6314 {
6315 /* May compute new values for $VIM and $VIMRUNTIME */
6316 if (didset_vim)
6317 {
6318 vim_setenv((char_u *)"VIM", (char_u *)"");
6319 didset_vim = FALSE;
6320 }
6321 if (didset_vimruntime)
6322 {
6323 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6324 didset_vimruntime = FALSE;
6325 }
6326 }
6327
Bram Moolenaar1a384422010-07-14 19:53:30 +02006328#ifdef FEAT_SYN_HL
6329 /* 'colorcolumn' */
6330 else if (varp == &curwin->w_p_cc)
6331 errmsg = check_colorcolumn(curwin);
6332#endif
6333
Bram Moolenaar071d4272004-06-13 20:20:40 +00006334#ifdef FEAT_MULTI_LANG
6335 /* 'helplang' */
6336 else if (varp == &p_hlg)
6337 {
6338 /* Check for "", "ab", "ab,cd", etc. */
6339 for (s = p_hlg; *s != NUL; s += 3)
6340 {
6341 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6342 {
6343 errmsg = e_invarg;
6344 break;
6345 }
6346 if (s[2] == NUL)
6347 break;
6348 }
6349 }
6350#endif
6351
6352 /* 'highlight' */
6353 else if (varp == &p_hl)
6354 {
6355 if (highlight_changed() == FAIL)
6356 errmsg = e_invarg; /* invalid flags */
6357 }
6358
6359 /* 'nrformats' */
6360 else if (gvarp == &p_nf)
6361 {
6362 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6363 errmsg = e_invarg;
6364 }
6365
6366#ifdef FEAT_SESSION
6367 /* 'sessionoptions' */
6368 else if (varp == &p_ssop)
6369 {
6370 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6371 errmsg = e_invarg;
6372 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6373 {
6374 /* Don't allow both "sesdir" and "curdir". */
6375 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6376 errmsg = e_invarg;
6377 }
6378 }
6379 /* 'viewoptions' */
6380 else if (varp == &p_vop)
6381 {
6382 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6383 errmsg = e_invarg;
6384 }
6385#endif
6386
6387 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006388 else if (varp == &p_sbo)
6389 {
6390 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6391 errmsg = e_invarg;
6392 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006393
6394 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006395 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006396 {
6397 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6398 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006399 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006400 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006401 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006402 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006403 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006404
6405 /* 'background' */
6406 else if (varp == &p_bg)
6407 {
6408 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6409 {
6410#ifdef FEAT_EVAL
6411 int dark = (*p_bg == 'd');
6412#endif
6413
6414 init_highlight(FALSE, FALSE);
6415
6416#ifdef FEAT_EVAL
6417 if (dark != (*p_bg == 'd')
6418 && get_var_value((char_u *)"g:colors_name") != NULL)
6419 {
6420 /* The color scheme must have set 'background' back to another
6421 * value, that's not what we want here. Disable the color
6422 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006423 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006424 free_string_option(p_bg);
6425 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6426 check_string_option(&p_bg);
6427 init_highlight(FALSE, FALSE);
6428 }
6429#endif
6430 }
6431 else
6432 errmsg = e_invarg;
6433 }
6434
6435 /* 'wildmode' */
6436 else if (varp == &p_wim)
6437 {
6438 if (check_opt_wim() == FAIL)
6439 errmsg = e_invarg;
6440 }
6441
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006442 /* 'wildoptions' */
6443 else if (varp == &p_wop)
6444 {
6445 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6446 errmsg = e_invarg;
6447 }
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006448
Bram Moolenaar071d4272004-06-13 20:20:40 +00006449#ifdef FEAT_WAK
6450 /* 'winaltkeys' */
6451 else if (varp == &p_wak)
6452 {
6453 if (*p_wak == NUL
6454 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6455 errmsg = e_invarg;
6456# ifdef FEAT_MENU
6457# ifdef FEAT_GUI_MOTIF
6458 else if (gui.in_use)
6459 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6460# else
6461# ifdef FEAT_GUI_GTK
6462 else if (gui.in_use)
6463 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6464# endif
6465# endif
6466# endif
6467 }
6468#endif
6469
Bram Moolenaar071d4272004-06-13 20:20:40 +00006470 /* 'eventignore' */
6471 else if (varp == &p_ei)
6472 {
6473 if (check_ei() == FAIL)
6474 errmsg = e_invarg;
6475 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006476
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006477 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6478 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6479 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480 {
6481 if (gvarp == &p_fenc)
6482 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006483 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006484 errmsg = e_modifiable;
6485 else if (vim_strchr(*varp, ',') != NULL)
6486 /* No comma allowed in 'fileencoding'; catches confusing it
6487 * with 'fileencodings'. */
6488 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006489 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006490 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006491#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006492 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006493 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006494#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006495 /* Add 'fileencoding' to the swap file. */
6496 ml_setflags(curbuf);
6497 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006498 }
6499 if (errmsg == NULL)
6500 {
6501 /* canonize the value, so that STRCMP() can be used on it */
6502 p = enc_canonize(*varp);
6503 if (p != NULL)
6504 {
6505 vim_free(*varp);
6506 *varp = p;
6507 }
6508 if (varp == &p_enc)
6509 {
6510 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006511#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006512 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006513#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006514 }
6515 }
6516
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006517#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6519 {
6520 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6521 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006522 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006523 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006524#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006525
6526 if (errmsg == NULL)
6527 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006528#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006529 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6530 * (with another encoding). */
6531 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6532 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534
6535 /* When 'termencoding' is not empty and 'encoding' changes or when
6536 * 'termencoding' changes, need to setup for keyboard input and
6537 * display output conversion. */
6538 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6539 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006540 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6541 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6542 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006543 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006544 p_tenc, p_enc);
6545 errmsg = e_invarg;
6546 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006547 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006548
Bram Moolenaar4f974752019-02-17 17:44:42 +01006549#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006550 /* $HOME may have characters in active code page. */
6551 if (varp == &p_enc)
6552 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006553#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554 }
6555 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006556
6557#if defined(FEAT_POSTSCRIPT)
6558 else if (varp == &p_penc)
6559 {
6560 /* Canonize printencoding if VIM standard one */
6561 p = enc_canonize(p_penc);
6562 if (p != NULL)
6563 {
6564 vim_free(p_penc);
6565 p_penc = p;
6566 }
6567 else
6568 {
6569 /* Ensure lower case and '-' for '_' */
6570 for (s = p_penc; *s != NUL; s++)
6571 {
6572 if (*s == '_')
6573 *s = '-';
6574 else
6575 *s = TOLOWER_ASC(*s);
6576 }
6577 }
6578 }
6579#endif
6580
Bram Moolenaar9372a112005-12-06 19:59:18 +00006581#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006582 else if (varp == &p_imak)
6583 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006584 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006585 errmsg = e_invarg;
6586 }
6587#endif
6588
6589#ifdef FEAT_KEYMAP
6590 else if (varp == &curbuf->b_p_keymap)
6591 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006592 if (!valid_filetype(*varp))
6593 errmsg = e_invarg;
6594 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006595 {
6596 int secure_save = secure;
6597
6598 // Reset the secure flag, since the value of 'keymap' has
6599 // been checked to be safe.
6600 secure = 0;
6601
6602 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006603 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006604
Bram Moolenaar916a8182018-11-25 02:18:29 +01006605 secure = secure_save;
6606
6607 // Since we check the value, there is no need to set P_INSECURE,
6608 // even when the value comes from a modeline.
6609 *value_checked = TRUE;
6610 }
6611
Bram Moolenaarfab06232009-03-04 03:13:35 +00006612 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006613 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006614 if (*curbuf->b_p_keymap != NUL)
6615 {
6616 /* Installed a new keymap, switch on using it. */
6617 curbuf->b_p_iminsert = B_IMODE_LMAP;
6618 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6619 curbuf->b_p_imsearch = B_IMODE_LMAP;
6620 }
6621 else
6622 {
6623 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6624 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6625 curbuf->b_p_iminsert = B_IMODE_NONE;
6626 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6627 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6628 }
6629 if ((opt_flags & OPT_LOCAL) == 0)
6630 {
6631 set_iminsert_global();
6632 set_imsearch_global();
6633 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006634 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006635 }
6636 }
6637#endif
6638
6639 /* 'fileformat' */
6640 else if (gvarp == &p_ff)
6641 {
6642 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6643 errmsg = e_modifiable;
6644 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6645 errmsg = e_invarg;
6646 else
6647 {
6648 /* may also change 'textmode' */
6649 if (get_fileformat(curbuf) == EOL_DOS)
6650 curbuf->b_p_tx = TRUE;
6651 else
6652 curbuf->b_p_tx = FALSE;
6653#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006654 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006655#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006656 /* update flag in swap file */
6657 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006658 /* Redraw needed when switching to/from "mac": a CR in the text
6659 * will be displayed differently. */
6660 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6661 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006662 }
6663 }
6664
6665 /* 'fileformats' */
6666 else if (varp == &p_ffs)
6667 {
6668 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6669 errmsg = e_invarg;
6670 else
6671 {
6672 /* also change 'textauto' */
6673 if (*p_ffs == NUL)
6674 p_ta = FALSE;
6675 else
6676 p_ta = TRUE;
6677 }
6678 }
6679
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006680#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006681 /* 'cryptkey' */
6682 else if (gvarp == &p_key)
6683 {
Bram Moolenaard7663c22019-08-06 21:59:57 +02006684 // Make sure the ":set" command doesn't show the new value in the
6685 // history.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006686 remove_key_from_history();
Bram Moolenaard7663c22019-08-06 21:59:57 +02006687
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006688 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6689 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006690 ml_set_crypt_key(curbuf, oldval,
6691 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006692 }
6693
6694 else if (gvarp == &p_cm)
6695 {
6696 if (opt_flags & OPT_LOCAL)
6697 p = curbuf->b_p_cm;
6698 else
6699 p = p_cm;
6700 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6701 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006702 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006703 errmsg = e_invarg;
6704 else
6705 {
6706 /* When setting the global value to empty, make it "zip". */
6707 if (*p_cm == NUL)
6708 {
6709 if (new_value_alloced)
6710 free_string_option(p_cm);
6711 p_cm = vim_strsave((char_u *)"zip");
6712 new_value_alloced = TRUE;
6713 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006714 /* When using ":set cm=name" the local value is going to be empty.
6715 * Do that here, otherwise the crypt functions will still use the
6716 * local value. */
6717 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6718 {
6719 free_string_option(curbuf->b_p_cm);
6720 curbuf->b_p_cm = empty_option;
6721 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006722
6723 /* Need to update the swapfile when the effective method changed.
6724 * Set "s" to the effective old value, "p" to the effective new
6725 * method and compare. */
6726 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6727 s = p_cm; /* was previously using the global value */
6728 else
6729 s = oldval;
6730 if (*curbuf->b_p_cm == NUL)
6731 p = p_cm; /* is now using the global value */
6732 else
6733 p = curbuf->b_p_cm;
6734 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006735 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006736
6737 /* If the global value changes need to update the swapfile for all
6738 * buffers using that value. */
6739 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6740 {
6741 buf_T *buf;
6742
Bram Moolenaar29323592016-07-24 22:04:11 +02006743 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006744 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006745 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006746 }
6747 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006748 }
6749#endif
6750
6751 /* 'matchpairs' */
6752 else if (gvarp == &p_mps)
6753 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006754 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006755 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006756 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006757 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006758 int x2 = -1;
6759 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006760
6761 if (*p != NUL)
6762 p += mb_ptr2len(p);
6763 if (*p != NUL)
6764 x2 = *p++;
6765 if (*p != NUL)
6766 {
6767 x3 = mb_ptr2char(p);
6768 p += mb_ptr2len(p);
6769 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006770 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006771 {
6772 errmsg = e_invarg;
6773 break;
6774 }
6775 if (*p == NUL)
6776 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006778 }
6779 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006780 {
6781 /* Check for "x:y,x:y" */
6782 for (p = *varp; *p != NUL; p += 4)
6783 {
6784 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6785 {
6786 errmsg = e_invarg;
6787 break;
6788 }
6789 if (p[3] == NUL)
6790 break;
6791 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006792 }
6793 }
6794
6795#ifdef FEAT_COMMENTS
6796 /* 'comments' */
6797 else if (gvarp == &p_com)
6798 {
6799 for (s = *varp; *s; )
6800 {
6801 while (*s && *s != ':')
6802 {
6803 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6804 && !VIM_ISDIGIT(*s) && *s != '-')
6805 {
6806 errmsg = illegal_char(errbuf, *s);
6807 break;
6808 }
6809 ++s;
6810 }
6811 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006812 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006813 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006814 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006815 if (errmsg != NULL)
6816 break;
6817 while (*s && *s != ',')
6818 {
6819 if (*s == '\\' && s[1] != NUL)
6820 ++s;
6821 ++s;
6822 }
6823 s = skip_to_option_part(s);
6824 }
6825 }
6826#endif
6827
6828 /* 'listchars' */
6829 else if (varp == &p_lcs)
6830 {
6831 errmsg = set_chars_option(varp);
6832 }
6833
Bram Moolenaar071d4272004-06-13 20:20:40 +00006834 /* 'fillchars' */
6835 else if (varp == &p_fcs)
6836 {
6837 errmsg = set_chars_option(varp);
6838 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006839
6840#ifdef FEAT_CMDWIN
6841 /* 'cedit' */
6842 else if (varp == &p_cedit)
6843 {
6844 errmsg = check_cedit();
6845 }
6846#endif
6847
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006848 /* 'verbosefile' */
6849 else if (varp == &p_vfile)
6850 {
6851 verbose_stop();
6852 if (*p_vfile != NUL && verbose_open() == FAIL)
6853 errmsg = e_invarg;
6854 }
6855
Bram Moolenaar071d4272004-06-13 20:20:40 +00006856#ifdef FEAT_VIMINFO
6857 /* 'viminfo' */
6858 else if (varp == &p_viminfo)
6859 {
6860 for (s = p_viminfo; *s;)
6861 {
6862 /* Check it's a valid character */
6863 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6864 {
6865 errmsg = illegal_char(errbuf, *s);
6866 break;
6867 }
6868 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006869 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006870 else if (*s == 'r') /* skip until next ',' */
6871 {
6872 while (*++s && *s != ',')
6873 ;
6874 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006875 else if (*s == '%')
6876 {
6877 /* optional number */
6878 while (vim_isdigit(*++s))
6879 ;
6880 }
6881 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006882 ++s; /* no extra chars */
6883 else /* must have a number */
6884 {
6885 while (vim_isdigit(*++s))
6886 ;
6887
6888 if (!VIM_ISDIGIT(*(s - 1)))
6889 {
6890 if (errbuf != NULL)
6891 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006892 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006893 transchar_byte(*(s - 1)));
6894 errmsg = errbuf;
6895 }
6896 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006897 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006898 break;
6899 }
6900 }
6901 if (*s == ',')
6902 ++s;
6903 else if (*s)
6904 {
6905 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006906 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006907 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006908 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006909 break;
6910 }
6911 }
6912 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006913 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006914 }
6915#endif /* FEAT_VIMINFO */
6916
6917 /* terminal options */
6918 else if (istermoption(&options[opt_idx]) && full_screen)
6919 {
6920 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6921 if (varp == &T_CCO)
6922 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006923 int colors = atoi((char *)T_CCO);
6924
6925 /* Only reinitialize colors if t_Co value has really changed to
6926 * avoid expensive reload of colorscheme if t_Co is set to the
6927 * same value multiple times. */
6928 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006929 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006930 t_colors = colors;
6931 if (t_colors <= 1)
6932 {
6933 if (new_value_alloced)
6934 vim_free(T_CCO);
6935 T_CCO = empty_option;
6936 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006937#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6938 if (is_term_win32())
6939 {
6940 swap_tcap();
6941 did_swaptcap = TRUE;
6942 }
6943#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006944 /* We now have a different color setup, initialize it again. */
6945 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006946 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006947 }
6948 ttest(FALSE);
6949 if (varp == &T_ME)
6950 {
6951 out_str(T_ME);
6952 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006953#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006954 /* Since t_me has been set, this probably means that the user
6955 * wants to use this as default colors. Need to reset default
6956 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006957# ifdef VIMDLL
6958 if (!gui.in_use && !gui.starting)
6959# endif
6960 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006961#endif
6962 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006963 if (varp == &T_BE && termcap_active)
6964 {
6965 if (*T_BE == NUL)
6966 /* When clearing t_BE we assume the user no longer wants
6967 * bracketed paste, thus disable it by writing t_BD. */
6968 out_str(T_BD);
6969 else
6970 out_str(T_BE);
6971 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006972 }
6973
6974#ifdef FEAT_LINEBREAK
6975 /* 'showbreak' */
6976 else if (varp == &p_sbr)
6977 {
6978 for (s = p_sbr; *s; )
6979 {
6980 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006981 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01006982 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006983 }
6984 }
6985#endif
6986
6987#ifdef FEAT_GUI
6988 /* 'guifont' */
6989 else if (varp == &p_guifont)
6990 {
6991 if (gui.in_use)
6992 {
6993 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00006994# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006995 /*
6996 * Put up a font dialog and let the user select a new value.
6997 * If this is cancelled go back to the old value but don't
6998 * give an error message.
6999 */
7000 if (STRCMP(p, "*") == 0)
7001 {
7002 p = gui_mch_font_dialog(oldval);
7003
7004 if (new_value_alloced)
7005 free_string_option(p_guifont);
7006
7007 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
7008 new_value_alloced = TRUE;
7009 }
7010# endif
7011 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
7012 {
7013# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
7014 if (STRCMP(p_guifont, "*") == 0)
7015 {
7016 /* Dialog was cancelled: Keep the old value without giving
7017 * an error message. */
7018 if (new_value_alloced)
7019 free_string_option(p_guifont);
7020 p_guifont = vim_strsave(oldval);
7021 new_value_alloced = TRUE;
7022 }
7023 else
7024# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007025 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007026 }
7027 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007028 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007029 }
7030# ifdef FEAT_XFONTSET
7031 else if (varp == &p_guifontset)
7032 {
7033 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007034 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007035 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007036 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007037 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007038 }
7039# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007040 else if (varp == &p_guifontwide)
7041 {
7042 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007043 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007044 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007045 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007046 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007047 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007048#endif
7049
7050#ifdef CURSOR_SHAPE
7051 /* 'guicursor' */
7052 else if (varp == &p_guicursor)
7053 errmsg = parse_shape_opt(SHAPE_CURSOR);
7054#endif
7055
7056#ifdef FEAT_MOUSESHAPE
7057 /* 'mouseshape' */
7058 else if (varp == &p_mouseshape)
7059 {
7060 errmsg = parse_shape_opt(SHAPE_MOUSE);
7061 update_mouseshape(-1);
7062 }
7063#endif
7064
7065#ifdef FEAT_PRINTER
7066 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007067 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007068# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007069 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007070 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007071# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007072#endif
7073
7074#ifdef FEAT_LANGMAP
7075 /* 'langmap' */
7076 else if (varp == &p_langmap)
7077 langmap_set();
7078#endif
7079
7080#ifdef FEAT_LINEBREAK
7081 /* 'breakat' */
7082 else if (varp == &p_breakat)
7083 fill_breakat_flags();
7084#endif
7085
7086#ifdef FEAT_TITLE
7087 /* 'titlestring' and 'iconstring' */
7088 else if (varp == &p_titlestring || varp == &p_iconstring)
7089 {
7090# ifdef FEAT_STL_OPT
7091 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7092
7093 /* NULL => statusline syntax */
7094 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7095 stl_syntax |= flagval;
7096 else
7097 stl_syntax &= ~flagval;
7098# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007099 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007100 }
7101#endif
7102
7103#ifdef FEAT_GUI
7104 /* 'guioptions' */
7105 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007106 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007107 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007108 redraw_gui_only = TRUE;
7109 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007110#endif
7111
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007112#if defined(FEAT_GUI_TABLINE)
7113 /* 'guitablabel' */
7114 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007115 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007116 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007117 redraw_gui_only = TRUE;
7118 }
7119 /* 'guitabtooltip' */
7120 else if (varp == &p_gtt)
7121 {
7122 redraw_gui_only = TRUE;
7123 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007124#endif
7125
Bram Moolenaar071d4272004-06-13 20:20:40 +00007126#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7127 /* 'ttymouse' */
7128 else if (varp == &p_ttym)
7129 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007130 /* Switch the mouse off before changing the escape sequences used for
7131 * that. */
7132 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7134 errmsg = e_invarg;
7135 else
7136 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007137 if (termcap_active)
7138 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007139 }
7140#endif
7141
Bram Moolenaar071d4272004-06-13 20:20:40 +00007142 /* 'selection' */
7143 else if (varp == &p_sel)
7144 {
7145 if (*p_sel == NUL
7146 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7147 errmsg = e_invarg;
7148 }
7149
7150 /* 'selectmode' */
7151 else if (varp == &p_slm)
7152 {
7153 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7154 errmsg = e_invarg;
7155 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007156
7157#ifdef FEAT_BROWSE
7158 /* 'browsedir' */
7159 else if (varp == &p_bsdir)
7160 {
7161 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7162 && !mch_isdir(p_bsdir))
7163 errmsg = e_invarg;
7164 }
7165#endif
7166
Bram Moolenaar071d4272004-06-13 20:20:40 +00007167 /* 'keymodel' */
7168 else if (varp == &p_km)
7169 {
7170 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7171 errmsg = e_invarg;
7172 else
7173 {
7174 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7175 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7176 }
7177 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007178
7179 /* 'mousemodel' */
7180 else if (varp == &p_mousem)
7181 {
7182 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7183 errmsg = e_invarg;
7184#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7185 else if (*p_mousem != *oldval)
7186 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7187 * to create or delete the popup menus. */
7188 gui_motif_update_mousemodel(root_menu);
7189#endif
7190 }
7191
7192 /* 'switchbuf' */
7193 else if (varp == &p_swb)
7194 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007195 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007196 errmsg = e_invarg;
7197 }
7198
7199 /* 'debug' */
7200 else if (varp == &p_debug)
7201 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007202 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007203 errmsg = e_invarg;
7204 }
7205
7206 /* 'display' */
7207 else if (varp == &p_dy)
7208 {
7209 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7210 errmsg = e_invarg;
7211 else
7212 (void)init_chartab();
7213
7214 }
7215
Bram Moolenaar071d4272004-06-13 20:20:40 +00007216 /* 'eadirection' */
7217 else if (varp == &p_ead)
7218 {
7219 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7220 errmsg = e_invarg;
7221 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007222
7223#ifdef FEAT_CLIPBOARD
7224 /* 'clipboard' */
7225 else if (varp == &p_cb)
7226 errmsg = check_clipboard_option();
7227#endif
7228
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007229#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007230 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7231 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007232 else if (varp == &(curwin->w_s->b_p_spl)
7233 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007234 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007235 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7236
7237 if ((is_spellfile && !valid_spellfile(*varp))
7238 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007239 errmsg = e_invarg;
7240 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007241 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007242 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007243 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007244 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007245 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007246 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007247 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007248 /* 'spellsuggest' */
7249 else if (varp == &p_sps)
7250 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007251 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007252 errmsg = e_invarg;
7253 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007254 /* 'mkspellmem' */
7255 else if (varp == &p_msm)
7256 {
7257 if (spell_check_msm() != OK)
7258 errmsg = e_invarg;
7259 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007260#endif
7261
Bram Moolenaar071d4272004-06-13 20:20:40 +00007262 /* When 'bufhidden' is set, check for valid value. */
7263 else if (gvarp == &p_bh)
7264 {
7265 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7266 errmsg = e_invarg;
7267 }
7268
7269 /* When 'buftype' is set, check for valid value. */
7270 else if (gvarp == &p_bt)
7271 {
7272 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7273 errmsg = e_invarg;
7274 else
7275 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007276 if (curwin->w_status_height)
7277 {
7278 curwin->w_redr_status = TRUE;
7279 redraw_later(VALID);
7280 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007281 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007282#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007283 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007284#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007285 }
7286 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007287
7288#ifdef FEAT_STL_OPT
7289 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007290 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007291 {
7292 int wid;
7293
7294 if (varp == &p_ruf) /* reset ru_wid first */
7295 ru_wid = 0;
7296 s = *varp;
7297 if (varp == &p_ruf && *s == '%')
7298 {
7299 /* set ru_wid if 'ruf' starts with "%99(" */
7300 if (*++s == '-') /* ignore a '-' */
7301 s++;
7302 wid = getdigits(&s);
7303 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7304 ru_wid = wid;
7305 else
7306 errmsg = check_stl_option(p_ruf);
7307 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007308 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007309 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007310 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007311 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007312 comp_col();
7313 }
7314#endif
7315
Bram Moolenaar071d4272004-06-13 20:20:40 +00007316 /* check if it is a valid value for 'complete' -- Acevedo */
7317 else if (gvarp == &p_cpt)
7318 {
7319 for (s = *varp; *s;)
7320 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007321 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007322 s++;
7323 if (!*s)
7324 break;
7325 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7326 {
7327 errmsg = illegal_char(errbuf, *s);
7328 break;
7329 }
7330 if (*++s != NUL && *s != ',' && *s != ' ')
7331 {
7332 if (s[-1] == 'k' || s[-1] == 's')
7333 {
7334 /* skip optional filename after 'k' and 's' */
7335 while (*s && *s != ',' && *s != ' ')
7336 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007337 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007338 ++s;
7339 ++s;
7340 }
7341 }
7342 else
7343 {
7344 if (errbuf != NULL)
7345 {
7346 sprintf((char *)errbuf,
7347 _("E535: Illegal character after <%c>"),
7348 *--s);
7349 errmsg = errbuf;
7350 }
7351 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007352 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007353 break;
7354 }
7355 }
7356 }
7357 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007358
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007359 // 'completeopt'
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007360 else if (varp == &p_cot)
7361 {
7362 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7363 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007364 else
7365 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007366 }
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007367
Bram Moolenaare2c453d2019-08-21 14:37:09 +02007368#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007369 // 'completeslash'
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007370 else if (gvarp == &p_csl)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007371 {
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007372 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
7373 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007374 errmsg = e_invarg;
7375 }
Bram Moolenaare2c453d2019-08-21 14:37:09 +02007376#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007377
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007378#ifdef FEAT_SIGNS
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007379 // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007380 else if (varp == &curwin->w_p_scl)
7381 {
7382 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7383 errmsg = e_invarg;
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007384 // When changing the 'signcolumn' to or from 'number', recompute the
7385 // width of the number column if 'number' or 'relativenumber' is set.
7386 if (((*oldval == 'n' && *(oldval + 1) == 'u')
7387 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
7388 && (curwin->w_p_nu || curwin->w_p_rnu))
7389 curwin->w_nrwidth_line_count = 0;
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007390 }
7391#endif
7392
Bram Moolenaar071d4272004-06-13 20:20:40 +00007393
Bram Moolenaar4f974752019-02-17 17:44:42 +01007394#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007395 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007396 else if (varp == &p_toolbar)
7397 {
7398 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7399 &toolbar_flags, TRUE) != OK)
7400 errmsg = e_invarg;
7401 else
7402 {
7403 out_flush();
7404 gui_mch_show_toolbar((toolbar_flags &
7405 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7406 }
7407 }
7408#endif
7409
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007410#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007411 /* 'toolbariconsize': GTK+ 2 only */
7412 else if (varp == &p_tbis)
7413 {
7414 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7415 errmsg = e_invarg;
7416 else
7417 {
7418 out_flush();
7419 gui_mch_show_toolbar((toolbar_flags &
7420 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7421 }
7422 }
7423#endif
7424
7425 /* 'pastetoggle': translate key codes like in a mapping */
7426 else if (varp == &p_pt)
7427 {
7428 if (*p_pt)
7429 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007430 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007431 if (p != NULL)
7432 {
7433 if (new_value_alloced)
7434 free_string_option(p_pt);
7435 p_pt = p;
7436 new_value_alloced = TRUE;
7437 }
7438 }
7439 }
7440
7441 /* 'backspace' */
7442 else if (varp == &p_bs)
7443 {
7444 if (VIM_ISDIGIT(*p_bs))
7445 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007446 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007447 errmsg = e_invarg;
7448 }
7449 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7450 errmsg = e_invarg;
7451 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007452 else if (varp == &p_bo)
7453 {
7454 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7455 errmsg = e_invarg;
7456 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007457
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007458 /* 'tagcase' */
7459 else if (gvarp == &p_tc)
7460 {
7461 unsigned int *flags;
7462
7463 if (opt_flags & OPT_LOCAL)
7464 {
7465 p = curbuf->b_p_tc;
7466 flags = &curbuf->b_tc_flags;
7467 }
7468 else
7469 {
7470 p = p_tc;
7471 flags = &tc_flags;
7472 }
7473
7474 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7475 /* make the local value empty: use the global value */
7476 *flags = 0;
7477 else if (*p == NUL
7478 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7479 errmsg = e_invarg;
7480 }
7481
Bram Moolenaar071d4272004-06-13 20:20:40 +00007482 /* 'casemap' */
7483 else if (varp == &p_cmp)
7484 {
7485 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7486 errmsg = e_invarg;
7487 }
7488
7489#ifdef FEAT_DIFF
7490 /* 'diffopt' */
7491 else if (varp == &p_dip)
7492 {
7493 if (diffopt_changed() == FAIL)
7494 errmsg = e_invarg;
7495 }
7496#endif
7497
7498#ifdef FEAT_FOLDING
7499 /* 'foldmethod' */
7500 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7501 {
7502 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7503 || *curwin->w_p_fdm == NUL)
7504 errmsg = e_invarg;
7505 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007506 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007507 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007508 if (foldmethodIsDiff(curwin))
7509 newFoldLevel();
7510 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007511 }
7512# ifdef FEAT_EVAL
7513 /* 'foldexpr' */
7514 else if (varp == &curwin->w_p_fde)
7515 {
7516 if (foldmethodIsExpr(curwin))
7517 foldUpdateAll(curwin);
7518 }
7519# endif
7520 /* 'foldmarker' */
7521 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7522 {
7523 p = vim_strchr(*varp, ',');
7524 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007525 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007526 else if (p == *varp || p[1] == NUL)
7527 errmsg = e_invarg;
7528 else if (foldmethodIsMarker(curwin))
7529 foldUpdateAll(curwin);
7530 }
7531 /* 'commentstring' */
7532 else if (gvarp == &p_cms)
7533 {
7534 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007535 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007536 }
7537 /* 'foldopen' */
7538 else if (varp == &p_fdo)
7539 {
7540 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7541 errmsg = e_invarg;
7542 }
7543 /* 'foldclose' */
7544 else if (varp == &p_fcl)
7545 {
7546 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7547 errmsg = e_invarg;
7548 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007549 /* 'foldignore' */
7550 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7551 {
7552 if (foldmethodIsIndent(curwin))
7553 foldUpdateAll(curwin);
7554 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007555#endif
7556
Bram Moolenaar071d4272004-06-13 20:20:40 +00007557 /* 'virtualedit' */
7558 else if (varp == &p_ve)
7559 {
7560 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7561 errmsg = e_invarg;
7562 else if (STRCMP(p_ve, oldval) != 0)
7563 {
7564 /* Recompute cursor position in case the new 've' setting
7565 * changes something. */
7566 validate_virtcol();
7567 coladvance(curwin->w_virtcol);
7568 }
7569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007570
7571#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7572 else if (varp == &p_csqf)
7573 {
7574 if (p_csqf != NULL)
7575 {
7576 p = p_csqf;
7577 while (*p != NUL)
7578 {
7579 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7580 || p[1] == NUL
7581 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7582 || (p[2] != NUL && p[2] != ','))
7583 {
7584 errmsg = e_invarg;
7585 break;
7586 }
7587 else if (p[2] == NUL)
7588 break;
7589 else
7590 p += 3;
7591 }
7592 }
7593 }
7594#endif
7595
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007596#ifdef FEAT_CINDENT
7597 /* 'cinoptions' */
7598 else if (gvarp == &p_cino)
7599 {
7600 /* TODO: recognize errors */
7601 parse_cino(curbuf);
7602 }
7603#endif
7604
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007605#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007606 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007607 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007608 {
7609 if (!gui_mch_set_rendering_options(p_rop))
7610 errmsg = e_invarg;
7611 }
7612#endif
7613
Bram Moolenaard0b51382016-11-04 15:23:45 +01007614 else if (gvarp == &p_ft)
7615 {
7616 if (!valid_filetype(*varp))
7617 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007618 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007619 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007620 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007621
7622 // Since we check the value, there is no need to set P_INSECURE,
7623 // even when the value comes from a modeline.
7624 *value_checked = TRUE;
7625 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007626 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007627
7628#ifdef FEAT_SYN_HL
7629 else if (gvarp == &p_syn)
7630 {
7631 if (!valid_filetype(*varp))
7632 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007633 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007634 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007635 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007636
7637 // Since we check the value, there is no need to set P_INSECURE,
7638 // even when the value comes from a modeline.
7639 *value_checked = TRUE;
7640 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007641 }
7642#endif
7643
Bram Moolenaar825680f2017-07-22 17:04:02 +02007644#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007645 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007646 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007647 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007648 if (*curwin->w_p_twk != NUL
7649 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007650 errmsg = e_invarg;
7651 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007652 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007653 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007654 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007655 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007656 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007657 p = skipdigits(curwin->w_p_tws);
7658 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007659 || (*p != 'x' && *p != '*')
7660 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007661 errmsg = e_invarg;
7662 }
7663 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007664# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007665 // 'termwintype'
7666 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007667 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007668 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007669 errmsg = e_invarg;
7670 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007671# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007672#endif
7673
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007674#ifdef FEAT_VARTABS
7675 /* 'varsofttabstop' */
7676 else if (varp == &(curbuf->b_p_vsts))
7677 {
7678 char_u *cp;
7679
7680 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7681 {
7682 if (curbuf->b_p_vsts_array)
7683 {
7684 vim_free(curbuf->b_p_vsts_array);
7685 curbuf->b_p_vsts_array = 0;
7686 }
7687 }
7688 else
7689 {
7690 for (cp = *varp; *cp; ++cp)
7691 {
7692 if (vim_isdigit(*cp))
7693 continue;
7694 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7695 continue;
7696 errmsg = e_invarg;
7697 break;
7698 }
7699 if (errmsg == NULL)
7700 {
7701 int *oldarray = curbuf->b_p_vsts_array;
7702 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7703 {
7704 if (oldarray)
7705 vim_free(oldarray);
7706 }
7707 else
7708 errmsg = e_invarg;
7709 }
7710 }
7711 }
7712
7713 /* 'vartabstop' */
7714 else if (varp == &(curbuf->b_p_vts))
7715 {
7716 char_u *cp;
7717
7718 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7719 {
7720 if (curbuf->b_p_vts_array)
7721 {
7722 vim_free(curbuf->b_p_vts_array);
7723 curbuf->b_p_vts_array = NULL;
7724 }
7725 }
7726 else
7727 {
7728 for (cp = *varp; *cp; ++cp)
7729 {
7730 if (vim_isdigit(*cp))
7731 continue;
7732 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7733 continue;
7734 errmsg = e_invarg;
7735 break;
7736 }
7737 if (errmsg == NULL)
7738 {
7739 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007740
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007741 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7742 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007743 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007744#ifdef FEAT_FOLDING
7745 if (foldmethodIsIndent(curwin))
7746 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007747#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007748 }
7749 else
7750 errmsg = e_invarg;
7751 }
7752 }
7753 }
7754#endif
7755
Bram Moolenaar79648732019-07-18 21:43:07 +02007756#ifdef FEAT_TEXT_PROP
7757 // 'previewpopup'
7758 else if (varp == &p_pvp)
7759 {
7760 if (parse_previewpopup(NULL) == FAIL)
7761 errmsg = e_invarg;
7762 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007763# ifdef FEAT_QUICKFIX
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02007764 // 'completepopup'
7765 else if (varp == &p_cpp)
7766 {
7767 if (parse_completepopup(NULL) == FAIL)
7768 errmsg = e_invarg;
7769 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007770# endif
Bram Moolenaar79648732019-07-18 21:43:07 +02007771#endif
7772
Bram Moolenaar071d4272004-06-13 20:20:40 +00007773 /* Options that are a list of flags. */
7774 else
7775 {
7776 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007777 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007778 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007779 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007780 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007781 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007782 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007783 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007784 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007785#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007786 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007787 p = (char_u *)COCU_ALL;
7788#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007789 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007790 {
7791#ifdef FEAT_MOUSE
7792 p = (char_u *)MOUSE_ALL;
7793#else
7794 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007795 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007796#endif
7797 }
7798#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007799 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 p = (char_u *)GO_ALL;
7801#endif
7802 if (p != NULL)
7803 {
7804 for (s = *varp; *s; ++s)
7805 if (vim_strchr(p, *s) == NULL)
7806 {
7807 errmsg = illegal_char(errbuf, *s);
7808 break;
7809 }
7810 }
7811 }
7812
7813 /*
7814 * If error detected, restore the previous value.
7815 */
7816 if (errmsg != NULL)
7817 {
7818 if (new_value_alloced)
7819 free_string_option(*varp);
7820 *varp = oldval;
7821 /*
7822 * When resetting some values, need to act on it.
7823 */
7824 if (did_chartab)
7825 (void)init_chartab();
7826 if (varp == &p_hl)
7827 (void)highlight_changed();
7828 }
7829 else
7830 {
7831#ifdef FEAT_EVAL
7832 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007833 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007834#endif
7835 /*
7836 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007837 * Use "free_oldval", because recursiveness may change the flags under
7838 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007839 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007840 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007841 free_string_option(oldval);
7842 if (new_value_alloced)
7843 options[opt_idx].flags |= P_ALLOCED;
7844 else
7845 options[opt_idx].flags &= ~P_ALLOCED;
7846
7847 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007848 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007849 {
7850 /* global option with local value set to use global value; free
7851 * the local value and make it empty */
7852 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7853 free_string_option(*(char_u **)p);
7854 *(char_u **)p = empty_option;
7855 }
7856
7857 /* May set global value for local option. */
7858 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7859 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007860
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007861 /*
7862 * Trigger the autocommand only after setting the flags.
7863 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007864#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007865 /* When 'syntax' is set, load the syntax of that name */
7866 if (varp == &(curbuf->b_p_syn))
7867 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007868 static int syn_recursive = 0;
7869
7870 ++syn_recursive;
7871 // Only pass TRUE for "force" when the value changed or not used
7872 // recursively, to avoid endless recurrence.
7873 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7874 value_changed || syn_recursive == 1, curbuf);
Bram Moolenaarc7f1e402019-08-03 13:29:46 +02007875 curbuf->b_flags |= BF_SYN_SET;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007876 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007877 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007878#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007879 else if (varp == &(curbuf->b_p_ft))
7880 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007881 /* 'filetype' is set, trigger the FileType autocommand.
7882 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007883 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007884 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007885 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007886 static int ft_recursive = 0;
7887 int secure_save = secure;
7888
7889 // Reset the secure flag, since the value of 'filetype' has
7890 // been checked to be safe.
7891 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007892
7893 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007894 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007895 // Only pass TRUE for "force" when the value changed or not
7896 // used recursively, to avoid endless recurrence.
7897 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7898 value_changed || ft_recursive == 1, curbuf);
7899 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007900 /* Just in case the old "curbuf" is now invalid. */
7901 if (varp != &(curbuf->b_p_ft))
7902 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007903
7904 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007905 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007906 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007907#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007908 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007909 {
7910 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007911 char_u *q = curwin->w_s->b_p_spl;
7912
7913 /* Skip the first name if it is "cjk". */
7914 if (STRNCMP(q, "cjk,", 4) == 0)
7915 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007916
7917 /*
7918 * Source the spell/LANG.vim in 'runtimepath'.
7919 * They could set 'spellcapcheck' depending on the language.
7920 * Use the first name in 'spelllang' up to '_region' or
7921 * '.encoding'.
7922 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007923 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007924 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007925 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007926 if (p > q)
7927 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007928 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7929 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007930 source_runtime(fname, DIP_ALL);
7931 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007932 }
7933#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007934 }
7935
7936#ifdef FEAT_MOUSE
7937 if (varp == &p_mouse)
7938 {
7939# ifdef FEAT_MOUSE_TTY
7940 if (*p_mouse == NUL)
7941 mch_setmouse(FALSE); /* switch mouse off */
7942 else
7943# endif
7944 setmouse(); /* in case 'mouse' changed */
7945 }
7946#endif
7947
Bram Moolenaar913077c2012-03-28 19:59:04 +02007948 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007949 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007950 curwin->w_set_curswant = TRUE;
7951
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007952#ifdef FEAT_GUI
7953 /* check redraw when it's not a GUI option or the GUI is active. */
7954 if (!redraw_gui_only || gui.in_use)
7955#endif
7956 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007957
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007958#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7959 if (did_swaptcap)
7960 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007961 set_termname((char_u *)"win32");
7962 init_highlight(TRUE, FALSE);
7963 }
7964#endif
7965
Bram Moolenaar071d4272004-06-13 20:20:40 +00007966 return errmsg;
7967}
7968
Bram Moolenaar071d4272004-06-13 20:20:40 +00007969#ifdef FEAT_STL_OPT
7970/*
7971 * Check validity of options with the 'statusline' format.
7972 * Return error message or NULL.
7973 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02007974 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007975check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007976{
7977 int itemcnt = 0;
7978 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007979 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00007980
7981 while (*s && itemcnt < STL_MAX_ITEM)
7982 {
7983 /* Check for valid keys after % sequences */
7984 while (*s && *s != '%')
7985 s++;
7986 if (!*s)
7987 break;
7988 s++;
7989 if (*s != '%' && *s != ')')
7990 ++itemcnt;
7991 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
7992 {
7993 s++;
7994 continue;
7995 }
7996 if (*s == ')')
7997 {
7998 s++;
7999 if (--groupdepth < 0)
8000 break;
8001 continue;
8002 }
8003 if (*s == '-')
8004 s++;
8005 while (VIM_ISDIGIT(*s))
8006 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008007 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008008 continue;
8009 if (*s == '.')
8010 {
8011 s++;
8012 while (*s && VIM_ISDIGIT(*s))
8013 s++;
8014 }
8015 if (*s == '(')
8016 {
8017 groupdepth++;
8018 continue;
8019 }
8020 if (vim_strchr(STL_ALL, *s) == NULL)
8021 {
8022 return illegal_char(errbuf, *s);
8023 }
8024 if (*s == '{')
8025 {
8026 s++;
8027 while (*s != '}' && *s)
8028 s++;
8029 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008030 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008031 }
8032 }
8033 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008034 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008036 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008037 return NULL;
8038}
8039#endif
8040
8041#ifdef FEAT_CLIPBOARD
8042/*
8043 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008044 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008045 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008046 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008047check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008048{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008049 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008050 int new_autoselect_star = FALSE;
8051 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008052 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008053 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008054 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008055 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008056 char_u *p;
8057
8058 for (p = p_cb; *p != NUL; )
8059 {
8060 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8061 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008062 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008063 p += 7;
8064 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008065 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008066 && (p[11] == ',' || p[11] == NUL))
8067 {
8068 new_unnamed |= CLIP_UNNAMED_PLUS;
8069 p += 11;
8070 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008071 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008072 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008073 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008074 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008075 p += 10;
8076 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008077 else if (STRNCMP(p, "autoselectplus", 14) == 0
8078 && (p[14] == ',' || p[14] == NUL))
8079 {
8080 new_autoselect_plus = TRUE;
8081 p += 14;
8082 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008083 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008084 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008085 {
8086 new_autoselectml = TRUE;
8087 p += 12;
8088 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008089 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8090 {
8091 new_html = TRUE;
8092 p += 4;
8093 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008094 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8095 {
8096 p += 8;
8097 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8098 if (new_exclude_prog == NULL)
8099 errmsg = e_invarg;
8100 break;
8101 }
8102 else
8103 {
8104 errmsg = e_invarg;
8105 break;
8106 }
8107 if (*p == ',')
8108 ++p;
8109 }
8110 if (errmsg == NULL)
8111 {
8112 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008113 clip_autoselect_star = new_autoselect_star;
8114 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008115 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008116 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008117 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008118 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008119#ifdef FEAT_GUI_GTK
8120 if (gui.in_use)
8121 {
8122 gui_gtk_set_selection_targets();
8123 gui_gtk_set_dnd_targets();
8124 }
8125#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008126 }
8127 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008128 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008129
8130 return errmsg;
8131}
8132#endif
8133
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008134#if defined(FEAT_EVAL) || defined(PROTO)
8135/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008136 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008137 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008138 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008139 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008140set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008141{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008142 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8143 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008144 sctx_T new_script_ctx = script_ctx;
8145
8146 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008147
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008148 /* Remember where the option was set. For local options need to do that
8149 * in the buffer or window structure. */
8150 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008151 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008152 if (both || (opt_flags & OPT_LOCAL))
8153 {
8154 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008155 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008156 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008157 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008158 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008159}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008160
8161/*
8162 * Set the script_ctx for a termcap option.
8163 * "name" must be the two character code, e.g. "RV".
8164 * When "name" is NULL use "opt_idx".
8165 */
8166 void
8167set_term_option_sctx_idx(char *name, int opt_idx)
8168{
8169 char_u buf[5];
8170 int idx;
8171
8172 if (name == NULL)
8173 idx = opt_idx;
8174 else
8175 {
8176 buf[0] = 't';
8177 buf[1] = '_';
8178 buf[2] = name[0];
8179 buf[3] = name[1];
8180 buf[4] = 0;
8181 idx = findoption(buf);
8182 }
8183 if (idx >= 0)
8184 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8185}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008186#endif
8187
Bram Moolenaar071d4272004-06-13 20:20:40 +00008188/*
8189 * Set the value of a boolean option, and take care of side effects.
8190 * Returns NULL for success, or an error message for an error.
8191 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008192 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008193set_bool_option(
8194 int opt_idx, /* index in options[] table */
8195 char_u *varp, /* pointer to the option variable */
8196 int value, /* new value */
8197 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008198{
8199 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008200#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008201 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008202#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008203
Bram Moolenaar071d4272004-06-13 20:20:40 +00008204 /* Disallow changing some options from secure mode */
8205 if ((secure
8206#ifdef HAVE_SANDBOX
8207 || sandbox != 0
8208#endif
8209 ) && (options[opt_idx].flags & P_SECURE))
8210 return e_secure;
8211
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008212#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008213 // Save the global value before changing anything. This is needed as for
8214 // a global-only option setting the "local value" in fact sets the global
8215 // value (since there is only one value).
8216 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8217 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8218 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008219#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008220
Bram Moolenaar071d4272004-06-13 20:20:40 +00008221 *(int *)varp = value; /* set the new value */
8222#ifdef FEAT_EVAL
8223 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008224 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008225#endif
8226
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008227#ifdef FEAT_GUI
8228 need_mouse_correct = TRUE;
8229#endif
8230
Bram Moolenaar071d4272004-06-13 20:20:40 +00008231 /* May set global value for local option. */
8232 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8233 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8234
8235 /*
8236 * Handle side effects of changing a bool option.
8237 */
8238
8239 /* 'compatible' */
8240 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008242
Bram Moolenaar920694c2016-08-21 17:45:02 +02008243#ifdef FEAT_LANGMAP
8244 if ((int *)varp == &p_lrm)
8245 /* 'langremap' -> !'langnoremap' */
8246 p_lnr = !p_lrm;
8247 else if ((int *)varp == &p_lnr)
8248 /* 'langnoremap' -> !'langremap' */
8249 p_lrm = !p_lnr;
8250#endif
8251
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008252#ifdef FEAT_SYN_HL
8253 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8254 reset_cursorline();
8255#endif
8256
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008257#ifdef FEAT_PERSISTENT_UNDO
8258 /* 'undofile' */
8259 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8260 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008261 /* Only take action when the option was set. When reset we do not
8262 * delete the undo file, the option may be set again without making
8263 * any changes in between. */
8264 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008265 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008266 char_u hash[UNDO_HASH_SIZE];
8267 buf_T *save_curbuf = curbuf;
8268
Bram Moolenaar29323592016-07-24 22:04:11 +02008269 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008270 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008271 /* When 'undofile' is set globally: for every buffer, otherwise
8272 * only for the current buffer: Try to read in the undofile,
8273 * if one exists, the buffer wasn't changed and the buffer was
8274 * loaded */
8275 if ((curbuf == save_curbuf
8276 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8277 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8278 {
8279 u_compute_hash(hash);
8280 u_read_undo(NULL, hash, curbuf->b_fname);
8281 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008282 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008283 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008284 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008285 }
8286#endif
8287
Bram Moolenaar071d4272004-06-13 20:20:40 +00008288 else if ((int *)varp == &curbuf->b_p_ro)
8289 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008290 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008291 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8292 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008293
8294 /* when 'readonly' is set may give W10 again */
8295 if (curbuf->b_p_ro)
8296 curbuf->b_did_warn = FALSE;
8297
Bram Moolenaar071d4272004-06-13 20:20:40 +00008298#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008299 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008300#endif
8301 }
8302
Bram Moolenaar9c449722010-07-20 18:44:27 +02008303#ifdef FEAT_GUI
8304 else if ((int *)varp == &p_mh)
8305 {
8306 if (!p_mh)
8307 gui_mch_mousehide(FALSE);
8308 }
8309#endif
8310
Bram Moolenaara539df02010-08-01 14:35:05 +02008311 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008312 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008313 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008314# ifdef FEAT_TERMINAL
8315 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008316 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8317 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008318 {
8319 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008320 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008321 }
8322# endif
8323# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008324 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008325# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008326 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008327#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008328 /* when 'endofline' is changed, redraw the window title */
8329 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008330 {
8331 redraw_titles();
8332 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008333 /* when 'fixeol' is changed, redraw the window title */
8334 else if ((int *)varp == &curbuf->b_p_fixeol)
8335 {
8336 redraw_titles();
8337 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008338 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008339 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008340 {
8341 redraw_titles();
8342 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343#endif
8344
8345 /* when 'bin' is set also set some other options */
8346 else if ((int *)varp == &curbuf->b_p_bin)
8347 {
8348 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8349#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008350 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008351#endif
8352 }
8353
Bram Moolenaar071d4272004-06-13 20:20:40 +00008354 /* when 'buflisted' changes, trigger autocommands */
8355 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8356 {
8357 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8358 NULL, NULL, TRUE, curbuf);
8359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360
8361 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8362 else if ((int *)varp == &curbuf->b_p_swf)
8363 {
8364 if (curbuf->b_p_swf && p_uc)
8365 ml_open_file(curbuf); /* create the swap file */
8366 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008367 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8368 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008369 mf_close_file(curbuf, TRUE); /* remove the swap file */
8370 }
8371
8372 /* when 'terse' is set change 'shortmess' */
8373 else if ((int *)varp == &p_terse)
8374 {
8375 char_u *p;
8376
8377 p = vim_strchr(p_shm, SHM_SEARCH);
8378
8379 /* insert 's' in p_shm */
8380 if (p_terse && p == NULL)
8381 {
8382 STRCPY(IObuff, p_shm);
8383 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008384 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008385 }
8386 /* remove 's' from p_shm */
8387 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008388 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389 }
8390
8391 /* when 'paste' is set or reset also change other options */
8392 else if ((int *)varp == &p_paste)
8393 {
8394 paste_option_changed();
8395 }
8396
8397 /* when 'insertmode' is set from an autocommand need to do work here */
8398 else if ((int *)varp == &p_im)
8399 {
8400 if (p_im)
8401 {
8402 if ((State & INSERT) == 0)
8403 need_start_insertmode = TRUE;
8404 stop_insert_mode = FALSE;
8405 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008406 /* only reset if it was set previously */
8407 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008408 {
8409 need_start_insertmode = FALSE;
8410 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008411 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008412 clear_cmdline = TRUE; /* remove "(insert)" */
8413 restart_edit = 0;
8414 }
8415 }
8416
8417 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8418 else if ((int *)varp == &p_ic && p_hls)
8419 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008420 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008421 }
8422
8423#ifdef FEAT_SEARCH_EXTRA
8424 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8425 else if ((int *)varp == &p_hls)
8426 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008427 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428 }
8429#endif
8430
Bram Moolenaar071d4272004-06-13 20:20:40 +00008431 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8432 * at the end of normal_cmd() */
8433 else if ((int *)varp == &curwin->w_p_scb)
8434 {
8435 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008436 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008437 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008438 curwin->w_scbind_pos = curwin->w_topline;
8439 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008440 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441
Bram Moolenaar4033c552017-09-16 20:54:51 +02008442#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008443 /* There can be only one window with 'previewwindow' set. */
8444 else if ((int *)varp == &curwin->w_p_pvw)
8445 {
8446 if (curwin->w_p_pvw)
8447 {
8448 win_T *win;
8449
Bram Moolenaar29323592016-07-24 22:04:11 +02008450 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451 if (win->w_p_pvw && win != curwin)
8452 {
8453 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008454 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008455 }
8456 }
8457 }
8458#endif
8459
8460 /* when 'textmode' is set or reset also change 'fileformat' */
8461 else if ((int *)varp == &curbuf->b_p_tx)
8462 {
8463 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8464 }
8465
8466 /* when 'textauto' is set or reset also change 'fileformats' */
8467 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008468 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008469 set_string_option_direct((char_u *)"ffs", -1,
8470 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008471 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008472 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008473
8474 /*
8475 * When 'lisp' option changes include/exclude '-' in
8476 * keyword characters.
8477 */
8478#ifdef FEAT_LISP
8479 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8480 {
8481 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8482 }
8483#endif
8484
8485#ifdef FEAT_TITLE
8486 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008487 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008488 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008489 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008490 }
8491#endif
8492
8493 else if ((int *)varp == &curbuf->b_changed)
8494 {
8495 if (!value)
8496 save_file_ff(curbuf); /* Buffer is unchanged */
8497#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008498 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008499#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008500 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008501 }
8502
8503#ifdef BACKSLASH_IN_FILENAME
8504 else if ((int *)varp == &p_ssl)
8505 {
8506 if (p_ssl)
8507 {
8508 psepc = '/';
8509 psepcN = '\\';
8510 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008511 }
8512 else
8513 {
8514 psepc = '\\';
8515 psepcN = '/';
8516 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008517 }
8518
8519 /* need to adjust the file name arguments and buffer names. */
8520 buflist_slash_adjust();
8521 alist_slash_adjust();
8522# ifdef FEAT_EVAL
8523 scriptnames_slash_adjust();
8524# endif
8525 }
8526#endif
8527
8528 /* If 'wrap' is set, set w_leftcol to zero. */
8529 else if ((int *)varp == &curwin->w_p_wrap)
8530 {
8531 if (curwin->w_p_wrap)
8532 curwin->w_leftcol = 0;
8533 }
8534
Bram Moolenaar071d4272004-06-13 20:20:40 +00008535 else if ((int *)varp == &p_ea)
8536 {
8537 if (p_ea && !old_value)
8538 win_equal(curwin, FALSE, 0);
8539 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008540
8541 else if ((int *)varp == &p_wiv)
8542 {
8543 /*
8544 * When 'weirdinvert' changed, set/reset 't_xs'.
8545 * Then set 'weirdinvert' according to value of 't_xs'.
8546 */
8547 if (p_wiv && !old_value)
8548 T_XS = (char_u *)"y";
8549 else if (!p_wiv && old_value)
8550 T_XS = empty_option;
8551 p_wiv = (*T_XS != NUL);
8552 }
8553
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008554#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008555 else if ((int *)varp == &p_beval)
8556 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008557 if (!balloonEvalForTerm)
8558 {
8559 if (p_beval && !old_value)
8560 gui_mch_enable_beval_area(balloonEval);
8561 else if (!p_beval && old_value)
8562 gui_mch_disable_beval_area(balloonEval);
8563 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008564 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008565#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008566#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008567 else if ((int *)varp == &p_bevalterm)
8568 {
8569 mch_bevalterm_changed();
8570 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008571#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008572
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008573#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008574 else if ((int *)varp == &p_acd)
8575 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008576 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008577 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008578 }
8579#endif
8580
8581#ifdef FEAT_DIFF
8582 /* 'diff' */
8583 else if ((int *)varp == &curwin->w_p_diff)
8584 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008585 /* May add or remove the buffer from the list of diff buffers. */
8586 diff_buf_adjust(curwin);
8587# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008588 if (foldmethodIsDiff(curwin))
8589 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008590# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008591 }
8592#endif
8593
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008594#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008595 /* 'imdisable' */
8596 else if ((int *)varp == &p_imdisable)
8597 {
8598 /* Only de-activate it here, it will be enabled when changing mode. */
8599 if (p_imdisable)
8600 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008601 else if (State & INSERT)
8602 /* When the option is set from an autocommand, it may need to take
8603 * effect right away. */
8604 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008605 }
8606#endif
8607
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008608#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008609 /* 'spell' */
8610 else if ((int *)varp == &curwin->w_p_spell)
8611 {
8612 if (curwin->w_p_spell)
8613 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008614 char *errmsg = did_set_spelllang(curwin);
8615
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008616 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008617 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008618 }
8619 }
8620#endif
8621
Bram Moolenaar071d4272004-06-13 20:20:40 +00008622#ifdef FEAT_ARABIC
8623 if ((int *)varp == &curwin->w_p_arab)
8624 {
8625 if (curwin->w_p_arab)
8626 {
8627 /*
8628 * 'arabic' is set, handle various sub-settings.
8629 */
8630 if (!p_tbidi)
8631 {
8632 /* set rightleft mode */
8633 if (!curwin->w_p_rl)
8634 {
8635 curwin->w_p_rl = TRUE;
8636 changed_window_setting();
8637 }
8638
8639 /* Enable Arabic shaping (major part of what Arabic requires) */
8640 if (!p_arshape)
8641 {
8642 p_arshape = TRUE;
8643 redraw_later_clear();
8644 }
8645 }
8646
8647 /* Arabic requires a utf-8 encoding, inform the user if its not
8648 * set. */
8649 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008650 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008651 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8652
Bram Moolenaar8820b482017-03-16 17:23:31 +01008653 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008654 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008655#ifdef FEAT_EVAL
8656 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8657#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008658 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008659
Bram Moolenaar071d4272004-06-13 20:20:40 +00008660 /* set 'delcombine' */
8661 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008662
8663# ifdef FEAT_KEYMAP
8664 /* Force-set the necessary keymap for arabic */
8665 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8666 OPT_LOCAL);
8667# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008668 }
8669 else
8670 {
8671 /*
8672 * 'arabic' is reset, handle various sub-settings.
8673 */
8674 if (!p_tbidi)
8675 {
8676 /* reset rightleft mode */
8677 if (curwin->w_p_rl)
8678 {
8679 curwin->w_p_rl = FALSE;
8680 changed_window_setting();
8681 }
8682
8683 /* 'arabicshape' isn't reset, it is a global option and
8684 * another window may still need it "on". */
8685 }
8686
8687 /* 'delcombine' isn't reset, it is a global option and another
8688 * window may still want it "on". */
8689
8690# ifdef FEAT_KEYMAP
8691 /* Revert to the default keymap */
8692 curbuf->b_p_iminsert = B_IMODE_NONE;
8693 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8694# endif
8695 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008696 }
8697
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008698#endif
8699
Bram Moolenaar44826212019-08-22 21:23:20 +02008700#if defined(FEAT_SIGNS) && defined(FEAT_GUI)
8701 else if (((int *)varp == &curwin->w_p_nu
8702 || (int *)varp == &curwin->w_p_rnu)
8703 && gui.in_use
8704 && (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) == 'u')
8705 && curbuf->b_signlist != NULL)
8706 {
8707 // If the 'number' or 'relativenumber' options are modified and
8708 // 'signcolumn' is set to 'number', then clear the screen for a full
8709 // refresh. Otherwise the sign icons are not displayed properly in the
8710 // number column. If the 'number' option is set and only the
8711 // 'relativenumber' option is toggled, then don't refresh the screen
8712 // (optimization).
8713 if (!(curwin->w_p_nu && ((int *)varp == &curwin->w_p_rnu)))
8714 redraw_all_later(CLEAR);
8715 }
8716#endif
8717
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008718#ifdef FEAT_TERMGUICOLORS
8719 /* 'termguicolors' */
8720 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008721 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008722# ifdef FEAT_VTP
8723 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02008724 if (
8725# ifdef VIMDLL
8726 !gui.in_use && !gui.starting &&
8727# endif
8728 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008729 {
8730 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008731 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008732 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008733 if (is_term_win32())
8734 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008735# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008736# ifdef FEAT_GUI
8737 if (!gui.in_use && !gui.starting)
8738# endif
8739 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008740# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008741 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008742 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008743 {
8744 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008745 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008746 init_highlight(TRUE, FALSE);
8747 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008748# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008749 }
8750#endif
8751
Bram Moolenaar071d4272004-06-13 20:20:40 +00008752 /*
8753 * End of handling side effects for bool options.
8754 */
8755
Bram Moolenaar53744302015-07-17 17:38:22 +02008756 /* after handling side effects, call autocommand */
8757
Bram Moolenaar071d4272004-06-13 20:20:40 +00008758 options[opt_idx].flags |= P_WAS_SET;
8759
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008760#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008761 // Don't do this while starting up or recursively.
8762 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008763 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02008764 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008765
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008766 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02008767 vim_snprintf((char *)buf_old_global, 2, "%d",
8768 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008769 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02008770 vim_snprintf((char *)buf_type, 7, "%s",
8771 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008772 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8773 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8774 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02008775 if (opt_flags & OPT_LOCAL)
8776 {
8777 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
8778 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
8779 }
8780 if (opt_flags & OPT_GLOBAL)
8781 {
8782 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
8783 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
8784 }
8785 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8786 {
8787 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
8788 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
8789 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
8790 }
8791 if (opt_flags & OPT_MODELINE)
8792 {
8793 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
8794 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
8795 }
8796 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
8797 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02008798 reset_v_option_vars();
8799 }
8800#endif
8801
Bram Moolenaar071d4272004-06-13 20:20:40 +00008802 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008803 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008804 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008805 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008806 check_redraw(options[opt_idx].flags);
8807
8808 return NULL;
8809}
8810
8811/*
8812 * Set the value of a number option, and take care of side effects.
8813 * Returns NULL for success, or an error message for an error.
8814 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008815 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008816set_num_option(
8817 int opt_idx, /* index in options[] table */
8818 char_u *varp, /* pointer to the option variable */
8819 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008820 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008821 size_t errbuflen, /* length of "errbuf" */
8822 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 OPT_MODELINE */
8824{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008825 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008826 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008827#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008828 long old_global_value = 0; // only used when setting a local and
8829 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008830#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008831 long old_Rows = Rows; // remember old Rows
8832 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00008833 long *pp = (long *)varp;
8834
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008835 /* Disallow changing some options from secure mode. */
8836 if ((secure
8837#ifdef HAVE_SANDBOX
8838 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008839#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008840 ) && (options[opt_idx].flags & P_SECURE))
8841 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008842
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008843#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008844 // Save the global value before changing anything. This is needed as for
8845 // a global-only option setting the "local value" infact sets the global
8846 // value (since there is only one value).
8847 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008848 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
8849 OPT_GLOBAL);
8850#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008851
Bram Moolenaar071d4272004-06-13 20:20:40 +00008852 *pp = value;
8853#ifdef FEAT_EVAL
8854 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008855 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008856#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008857#ifdef FEAT_GUI
8858 need_mouse_correct = TRUE;
8859#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008860
Bram Moolenaar14f24742012-08-08 18:01:05 +02008861 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862 {
8863 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008864#ifdef FEAT_VARTABS
8865 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8866 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8867 ? tabstop_first(curbuf->b_p_vts_array)
8868 : curbuf->b_p_ts;
8869#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008870 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008871#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872 }
8873
8874 /*
8875 * Number options that need some action when changed
8876 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008877 if (pp == &p_wh || pp == &p_hh)
8878 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008879 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880 if (p_wh < 1)
8881 {
8882 errmsg = e_positive;
8883 p_wh = 1;
8884 }
8885 if (p_wmh > p_wh)
8886 {
8887 errmsg = e_winheight;
8888 p_wh = p_wmh;
8889 }
8890 if (p_hh < 0)
8891 {
8892 errmsg = e_positive;
8893 p_hh = 0;
8894 }
8895
8896 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008897 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008898 {
8899 if (pp == &p_wh && curwin->w_height < p_wh)
8900 win_setheight((int)p_wh);
8901 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8902 win_setheight((int)p_hh);
8903 }
8904 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008905 else if (pp == &p_wmh)
8906 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008907 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008908 if (p_wmh < 0)
8909 {
8910 errmsg = e_positive;
8911 p_wmh = 0;
8912 }
8913 if (p_wmh > p_wh)
8914 {
8915 errmsg = e_winheight;
8916 p_wmh = p_wh;
8917 }
8918 win_setminheight();
8919 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008920 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008921 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008922 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008923 if (p_wiw < 1)
8924 {
8925 errmsg = e_positive;
8926 p_wiw = 1;
8927 }
8928 if (p_wmw > p_wiw)
8929 {
8930 errmsg = e_winwidth;
8931 p_wiw = p_wmw;
8932 }
8933
8934 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008935 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008936 win_setwidth((int)p_wiw);
8937 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008938 else if (pp == &p_wmw)
8939 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008940 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941 if (p_wmw < 0)
8942 {
8943 errmsg = e_positive;
8944 p_wmw = 0;
8945 }
8946 if (p_wmw > p_wiw)
8947 {
8948 errmsg = e_winwidth;
8949 p_wmw = p_wiw;
8950 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008951 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008952 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008953
Bram Moolenaar071d4272004-06-13 20:20:40 +00008954 /* (re)set last window status line */
8955 else if (pp == &p_ls)
8956 {
8957 last_status(FALSE);
8958 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008959
8960 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008961 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008962 {
8963 shell_new_rows(); /* recompute window positions and heights */
8964 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008965
8966#ifdef FEAT_GUI
8967 else if (pp == &p_linespace)
8968 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008969 /* Recompute gui.char_height and resize the Vim window to keep the
8970 * same number of lines. */
8971 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008972 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973 }
8974#endif
8975
8976#ifdef FEAT_FOLDING
8977 /* 'foldlevel' */
8978 else if (pp == &curwin->w_p_fdl)
8979 {
8980 if (curwin->w_p_fdl < 0)
8981 curwin->w_p_fdl = 0;
8982 newFoldLevel();
8983 }
8984
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008985 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008986 else if (pp == &curwin->w_p_fml)
8987 {
8988 foldUpdateAll(curwin);
8989 }
8990
8991 /* 'foldnestmax' */
8992 else if (pp == &curwin->w_p_fdn)
8993 {
8994 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
8995 foldUpdateAll(curwin);
8996 }
8997
8998 /* 'foldcolumn' */
8999 else if (pp == &curwin->w_p_fdc)
9000 {
9001 if (curwin->w_p_fdc < 0)
9002 {
9003 errmsg = e_positive;
9004 curwin->w_p_fdc = 0;
9005 }
9006 else if (curwin->w_p_fdc > 12)
9007 {
9008 errmsg = e_invarg;
9009 curwin->w_p_fdc = 12;
9010 }
9011 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009012#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009014#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009015 /* 'shiftwidth' or 'tabstop' */
9016 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9017 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009018# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009019 if (foldmethodIsIndent(curwin))
9020 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009021# endif
9022# ifdef FEAT_CINDENT
9023 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9024 * parse 'cinoptions'. */
9025 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9026 parse_cino(curbuf);
9027# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009028 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009029#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009030
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009031 /* 'maxcombine' */
9032 else if (pp == &p_mco)
9033 {
9034 if (p_mco > MAX_MCO)
9035 p_mco = MAX_MCO;
9036 else if (p_mco < 0)
9037 p_mco = 0;
9038 screenclear(); /* will re-allocate the screen */
9039 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009040
Bram Moolenaar071d4272004-06-13 20:20:40 +00009041 else if (pp == &curbuf->b_p_iminsert)
9042 {
9043 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9044 {
9045 errmsg = e_invarg;
9046 curbuf->b_p_iminsert = B_IMODE_NONE;
9047 }
9048 p_iminsert = curbuf->b_p_iminsert;
9049 if (termcap_active) /* don't do this in the alternate screen */
9050 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009051#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009052 /* Show/unshow value of 'keymap' in status lines. */
9053 status_redraw_curbuf();
9054#endif
9055 }
9056
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009057#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9058 /* 'imstyle' */
9059 else if (pp == &p_imst)
9060 {
9061 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9062 errmsg = e_invarg;
9063 }
9064#endif
9065
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009066 else if (pp == &p_window)
9067 {
9068 if (p_window < 1)
9069 p_window = 1;
9070 else if (p_window >= Rows)
9071 p_window = Rows - 1;
9072 }
9073
Bram Moolenaar071d4272004-06-13 20:20:40 +00009074 else if (pp == &curbuf->b_p_imsearch)
9075 {
9076 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9077 {
9078 errmsg = e_invarg;
9079 curbuf->b_p_imsearch = B_IMODE_NONE;
9080 }
9081 p_imsearch = curbuf->b_p_imsearch;
9082 }
9083
9084#ifdef FEAT_TITLE
9085 /* if 'titlelen' has changed, redraw the title */
9086 else if (pp == &p_titlelen)
9087 {
9088 if (p_titlelen < 0)
9089 {
9090 errmsg = e_positive;
9091 p_titlelen = 85;
9092 }
9093 if (starting != NO_SCREEN && old_value != p_titlelen)
9094 need_maketitle = TRUE;
9095 }
9096#endif
9097
9098 /* if p_ch changed value, change the command line height */
9099 else if (pp == &p_ch)
9100 {
9101 if (p_ch < 1)
9102 {
9103 errmsg = e_positive;
9104 p_ch = 1;
9105 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009106 if (p_ch > Rows - min_rows() + 1)
9107 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009108
9109 /* Only compute the new window layout when startup has been
9110 * completed. Otherwise the frame sizes may be wrong. */
9111 if (p_ch != old_value && full_screen
9112#ifdef FEAT_GUI
9113 && !gui.starting
9114#endif
9115 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009116 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009117 }
9118
9119 /* when 'updatecount' changes from zero to non-zero, open swap files */
9120 else if (pp == &p_uc)
9121 {
9122 if (p_uc < 0)
9123 {
9124 errmsg = e_positive;
9125 p_uc = 100;
9126 }
9127 if (p_uc && !old_value)
9128 ml_open_files();
9129 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009130#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009131 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009132 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009133 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009134 {
9135 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009136 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009137 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009138 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009139 {
9140 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009141 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009142 }
9143 }
9144#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009145#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009146 else if (pp == &p_mzq)
9147 mzvim_reset_timer();
9148#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009149
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009150#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9151 /* 'pyxversion' */
9152 else if (pp == &p_pyx)
9153 {
9154 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9155 errmsg = e_invarg;
9156 }
9157#endif
9158
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159 /* sync undo before 'undolevels' changes */
9160 else if (pp == &p_ul)
9161 {
9162 /* use the old value, otherwise u_sync() may not work properly */
9163 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009164 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009165 p_ul = value;
9166 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009167 else if (pp == &curbuf->b_p_ul)
9168 {
9169 /* use the old value, otherwise u_sync() may not work properly */
9170 curbuf->b_p_ul = old_value;
9171 u_sync(TRUE);
9172 curbuf->b_p_ul = value;
9173 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009174
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009175#ifdef FEAT_LINEBREAK
9176 /* 'numberwidth' must be positive */
9177 else if (pp == &curwin->w_p_nuw)
9178 {
9179 if (curwin->w_p_nuw < 1)
9180 {
9181 errmsg = e_positive;
9182 curwin->w_p_nuw = 1;
9183 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009184 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009185 {
9186 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009187 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009188 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009189 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009190 }
9191#endif
9192
Bram Moolenaar1a384422010-07-14 19:53:30 +02009193 else if (pp == &curbuf->b_p_tw)
9194 {
9195 if (curbuf->b_p_tw < 0)
9196 {
9197 errmsg = e_positive;
9198 curbuf->b_p_tw = 0;
9199 }
9200#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009201 {
9202 win_T *wp;
9203 tabpage_T *tp;
9204
9205 FOR_ALL_TAB_WINDOWS(tp, wp)
9206 check_colorcolumn(wp);
9207 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009208#endif
9209 }
9210
Bram Moolenaar071d4272004-06-13 20:20:40 +00009211 /*
9212 * Check the bounds for numeric options here
9213 */
9214 if (Rows < min_rows() && full_screen)
9215 {
9216 if (errbuf != NULL)
9217 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009218 vim_snprintf((char *)errbuf, errbuflen,
9219 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009220 errmsg = errbuf;
9221 }
9222 Rows = min_rows();
9223 }
9224 if (Columns < MIN_COLUMNS && full_screen)
9225 {
9226 if (errbuf != NULL)
9227 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009228 vim_snprintf((char *)errbuf, errbuflen,
9229 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009230 errmsg = errbuf;
9231 }
9232 Columns = MIN_COLUMNS;
9233 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009234 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009235
Bram Moolenaar071d4272004-06-13 20:20:40 +00009236 /*
9237 * If the screen (shell) height has been changed, assume it is the
9238 * physical screenheight.
9239 */
9240 if (old_Rows != Rows || old_Columns != Columns)
9241 {
9242 /* Changing the screen size is not allowed while updating the screen. */
9243 if (updating_screen)
9244 *pp = old_value;
9245 else if (full_screen
9246#ifdef FEAT_GUI
9247 && !gui.starting
9248#endif
9249 )
9250 set_shellsize((int)Columns, (int)Rows, TRUE);
9251 else
9252 {
9253 /* Postpone the resizing; check the size and cmdline position for
9254 * messages. */
9255 check_shellsize();
9256 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9257 cmdline_row = Rows - p_ch;
9258 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009259 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009260 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009261 }
9262
Bram Moolenaar071d4272004-06-13 20:20:40 +00009263 if (curbuf->b_p_ts <= 0)
9264 {
9265 errmsg = e_positive;
9266 curbuf->b_p_ts = 8;
9267 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009268 if (p_tm < 0)
9269 {
9270 errmsg = e_positive;
9271 p_tm = 0;
9272 }
9273 if ((curwin->w_p_scr <= 0
9274 || (curwin->w_p_scr > curwin->w_height
9275 && curwin->w_height > 0))
9276 && full_screen)
9277 {
9278 if (pp == &(curwin->w_p_scr))
9279 {
9280 if (curwin->w_p_scr != 0)
9281 errmsg = e_scroll;
9282 win_comp_scroll(curwin);
9283 }
9284 /* If 'scroll' became invalid because of a side effect silently adjust
9285 * it. */
9286 else if (curwin->w_p_scr <= 0)
9287 curwin->w_p_scr = 1;
9288 else /* curwin->w_p_scr > curwin->w_height */
9289 curwin->w_p_scr = curwin->w_height;
9290 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009291 if (p_hi < 0)
9292 {
9293 errmsg = e_positive;
9294 p_hi = 0;
9295 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009296 else if (p_hi > 10000)
9297 {
9298 errmsg = e_invarg;
9299 p_hi = 10000;
9300 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009301 if (p_re < 0 || p_re > 2)
9302 {
9303 errmsg = e_invarg;
9304 p_re = 0;
9305 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009306 if (p_report < 0)
9307 {
9308 errmsg = e_positive;
9309 p_report = 1;
9310 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009311 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009312 {
9313 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9314 p_sj = Rows / 2;
9315 else
9316 {
9317 errmsg = e_scroll;
9318 p_sj = 1;
9319 }
9320 }
9321 if (p_so < 0 && full_screen)
9322 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009323 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009324 p_so = 0;
9325 }
9326 if (p_siso < 0 && full_screen)
9327 {
9328 errmsg = e_positive;
9329 p_siso = 0;
9330 }
9331#ifdef FEAT_CMDWIN
9332 if (p_cwh < 1)
9333 {
9334 errmsg = e_positive;
9335 p_cwh = 1;
9336 }
9337#endif
9338 if (p_ut < 0)
9339 {
9340 errmsg = e_positive;
9341 p_ut = 2000;
9342 }
9343 if (p_ss < 0)
9344 {
9345 errmsg = e_positive;
9346 p_ss = 0;
9347 }
9348
9349 /* May set global value for local option. */
9350 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9351 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9352
9353 options[opt_idx].flags |= P_WAS_SET;
9354
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009355#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009356 // Don't do this while starting up, failure or recursively.
9357 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009358 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009359 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009360 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009361 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009362 vim_snprintf((char *)buf_new, 10, "%ld", value);
9363 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009364 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9365 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9366 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009367 if (opt_flags & OPT_LOCAL)
9368 {
9369 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9370 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9371 }
9372 if (opt_flags & OPT_GLOBAL)
9373 {
9374 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9375 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9376 }
9377 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9378 {
9379 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9380 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9381 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9382 }
9383 if (opt_flags & OPT_MODELINE)
9384 {
9385 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9386 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9387 }
9388 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9389 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009390 reset_v_option_vars();
9391 }
9392#endif
9393
Bram Moolenaar071d4272004-06-13 20:20:40 +00009394 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009395 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009396 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009397 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009398 check_redraw(options[opt_idx].flags);
9399
9400 return errmsg;
9401}
9402
9403/*
9404 * Called after an option changed: check if something needs to be redrawn.
9405 */
9406 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009407check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009408{
9409 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009410 int doclear = (flags & P_RCLR) == P_RCLR;
9411 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009412
Bram Moolenaar071d4272004-06-13 20:20:40 +00009413 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9414 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009415
9416 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9417 changed_window_setting();
9418 if (flags & P_RBUF)
9419 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009420 if (flags & P_RWINONLY)
9421 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009422 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009423 redraw_all_later(CLEAR);
9424 else if (all)
9425 redraw_all_later(NOT_VALID);
9426}
9427
9428/*
9429 * Find index for option 'arg'.
9430 * Return -1 if not found.
9431 */
9432 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009433findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009434{
9435 int opt_idx;
9436 char *s, *p;
9437 static short quick_tab[27] = {0, 0}; /* quick access table */
9438 int is_term_opt;
9439
9440 /*
9441 * For first call: Initialize the quick-access table.
9442 * It contains the index for the first option that starts with a certain
9443 * letter. There are 26 letters, plus the first "t_" option.
9444 */
9445 if (quick_tab[1] == 0)
9446 {
9447 p = options[0].fullname;
9448 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9449 {
9450 if (s[0] != p[0])
9451 {
9452 if (s[0] == 't' && s[1] == '_')
9453 quick_tab[26] = opt_idx;
9454 else
9455 quick_tab[CharOrdLow(s[0])] = opt_idx;
9456 }
9457 p = s;
9458 }
9459 }
9460
9461 /*
9462 * Check for name starting with an illegal character.
9463 */
9464#ifdef EBCDIC
9465 if (!islower(arg[0]))
9466#else
9467 if (arg[0] < 'a' || arg[0] > 'z')
9468#endif
9469 return -1;
9470
9471 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9472 if (is_term_opt)
9473 opt_idx = quick_tab[26];
9474 else
9475 opt_idx = quick_tab[CharOrdLow(arg[0])];
9476 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9477 {
9478 if (STRCMP(arg, s) == 0) /* match full name */
9479 break;
9480 }
9481 if (s == NULL && !is_term_opt)
9482 {
9483 opt_idx = quick_tab[CharOrdLow(arg[0])];
9484 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9485 {
9486 s = options[opt_idx].shortname;
9487 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9488 break;
9489 s = NULL;
9490 }
9491 }
9492 if (s == NULL)
9493 opt_idx = -1;
9494 return opt_idx;
9495}
9496
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009497#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009498/*
9499 * Get the value for an option.
9500 *
9501 * Returns:
9502 * Number or Toggle option: 1, *numval gets value.
9503 * String option: 0, *stringval gets allocated string.
9504 * Hidden Number or Toggle option: -1.
9505 * hidden String option: -2.
9506 * unknown option: -3.
9507 */
9508 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009509get_option_value(
9510 char_u *name,
9511 long *numval,
9512 char_u **stringval, /* NULL when only checking existence */
9513 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009514{
9515 int opt_idx;
9516 char_u *varp;
9517
9518 opt_idx = findoption(name);
9519 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009520 {
9521 int key;
9522
9523 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009524 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009525 {
9526 char_u key_name[2];
9527 char_u *p;
9528
9529 if (key < 0)
9530 {
9531 key_name[0] = KEY2TERMCAP0(key);
9532 key_name[1] = KEY2TERMCAP1(key);
9533 }
9534 else
9535 {
9536 key_name[0] = KS_KEY;
9537 key_name[1] = (key & 0xff);
9538 }
9539 p = find_termcode(key_name);
9540 if (p != NULL)
9541 {
9542 if (stringval != NULL)
9543 *stringval = vim_strsave(p);
9544 return 0;
9545 }
9546 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009548 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009549
9550 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9551
9552 if (options[opt_idx].flags & P_STRING)
9553 {
9554 if (varp == NULL) /* hidden option */
9555 return -2;
9556 if (stringval != NULL)
9557 {
9558#ifdef FEAT_CRYPT
9559 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009560 if ((char_u **)varp == &curbuf->b_p_key
9561 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009562 *stringval = vim_strsave((char_u *)"*****");
9563 else
9564#endif
9565 *stringval = vim_strsave(*(char_u **)(varp));
9566 }
9567 return 0;
9568 }
9569
9570 if (varp == NULL) /* hidden option */
9571 return -1;
9572 if (options[opt_idx].flags & P_NUM)
9573 *numval = *(long *)varp;
9574 else
9575 {
9576 /* Special case: 'modified' is b_changed, but we also want to consider
9577 * it set when 'ff' or 'fenc' changed. */
9578 if ((int *)varp == &curbuf->b_changed)
9579 *numval = curbufIsChanged();
9580 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009581 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582 }
9583 return 1;
9584}
9585#endif
9586
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009587#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009588/*
9589 * Returns the option attributes and its value. Unlike the above function it
9590 * will return either global value or local value of the option depending on
9591 * what was requested, but it will never return global value if it was
9592 * requested to return local one and vice versa. Neither it will return
9593 * buffer-local value if it was requested to return window-local one.
9594 *
9595 * Pretends that option is absent if it is not present in the requested scope
9596 * (i.e. has no global, window-local or buffer-local value depending on
9597 * opt_type). Uses
9598 *
9599 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009600 * 0 hidden or unknown option, also option that does not have requested
9601 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009602 * see SOPT_* in vim.h for other flags
9603 *
9604 * Possible opt_type values: see SREQ_* in vim.h
9605 */
9606 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009607get_option_value_strict(
9608 char_u *name,
9609 long *numval,
9610 char_u **stringval, /* NULL when only obtaining attributes */
9611 int opt_type,
9612 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009613{
9614 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009615 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009616 struct vimoption *p;
9617 int r = 0;
9618
9619 opt_idx = findoption(name);
9620 if (opt_idx < 0)
9621 return 0;
9622
9623 p = &(options[opt_idx]);
9624
9625 /* Hidden option */
9626 if (p->var == NULL)
9627 return 0;
9628
9629 if (p->flags & P_BOOL)
9630 r |= SOPT_BOOL;
9631 else if (p->flags & P_NUM)
9632 r |= SOPT_NUM;
9633 else if (p->flags & P_STRING)
9634 r |= SOPT_STRING;
9635
9636 if (p->indir == PV_NONE)
9637 {
9638 if (opt_type == SREQ_GLOBAL)
9639 r |= SOPT_GLOBAL;
9640 else
9641 return 0; /* Did not request global-only option */
9642 }
9643 else
9644 {
9645 if (p->indir & PV_BOTH)
9646 r |= SOPT_GLOBAL;
9647 else if (opt_type == SREQ_GLOBAL)
9648 return 0; /* Requested global option */
9649
9650 if (p->indir & PV_WIN)
9651 {
9652 if (opt_type == SREQ_BUF)
9653 return 0; /* Did not request window-local option */
9654 else
9655 r |= SOPT_WIN;
9656 }
9657 else if (p->indir & PV_BUF)
9658 {
9659 if (opt_type == SREQ_WIN)
9660 return 0; /* Did not request buffer-local option */
9661 else
9662 r |= SOPT_BUF;
9663 }
9664 }
9665
9666 if (stringval == NULL)
9667 return r;
9668
9669 if (opt_type == SREQ_GLOBAL)
9670 varp = p->var;
9671 else
9672 {
9673 if (opt_type == SREQ_BUF)
9674 {
9675 /* Special case: 'modified' is b_changed, but we also want to
9676 * consider it set when 'ff' or 'fenc' changed. */
9677 if (p->indir == PV_MOD)
9678 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009679 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009680 varp = NULL;
9681 }
9682#ifdef FEAT_CRYPT
9683 else if (p->indir == PV_KEY)
9684 {
9685 /* never return the value of the crypt key */
9686 *stringval = NULL;
9687 varp = NULL;
9688 }
9689#endif
9690 else
9691 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009692 buf_T *save_curbuf = curbuf;
9693
9694 // only getting a pointer, no need to use aucmd_prepbuf()
9695 curbuf = (buf_T *)from;
9696 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009697 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009698 curbuf = save_curbuf;
9699 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009700 }
9701 }
9702 else if (opt_type == SREQ_WIN)
9703 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009704 win_T *save_curwin = curwin;
9705
9706 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009707 curbuf = curwin->w_buffer;
9708 varp = get_varp(p);
9709 curwin = save_curwin;
9710 curbuf = curwin->w_buffer;
9711 }
9712 if (varp == p->var)
9713 return (r | SOPT_UNSET);
9714 }
9715
9716 if (varp != NULL)
9717 {
9718 if (p->flags & P_STRING)
9719 *stringval = vim_strsave(*(char_u **)(varp));
9720 else if (p->flags & P_NUM)
9721 *numval = *(long *) varp;
9722 else
9723 *numval = *(int *)varp;
9724 }
9725
9726 return r;
9727}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009728
9729/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009730 * Iterate over options. First argument is a pointer to a pointer to a
9731 * structure inside options[] array, second is option type like in the above
9732 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009733 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009734 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009735 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009736 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009737 * first argument to NULL.
9738 *
9739 * Returns full option name for current option on each call.
9740 */
9741 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009742option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009743{
9744 struct vimoption *ret = NULL;
9745 do
9746 {
9747 if (*option == NULL)
9748 *option = (void *) options;
9749 else if (((struct vimoption *) (*option))->fullname == NULL)
9750 {
9751 *option = NULL;
9752 return NULL;
9753 }
9754 else
9755 *option = (void *) (((struct vimoption *) (*option)) + 1);
9756
9757 ret = ((struct vimoption *) (*option));
9758
9759 /* Hidden option */
9760 if (ret->var == NULL)
9761 {
9762 ret = NULL;
9763 continue;
9764 }
9765
9766 switch (opt_type)
9767 {
9768 case SREQ_GLOBAL:
9769 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9770 ret = NULL;
9771 break;
9772 case SREQ_BUF:
9773 if (!(ret->indir & PV_BUF))
9774 ret = NULL;
9775 break;
9776 case SREQ_WIN:
9777 if (!(ret->indir & PV_WIN))
9778 ret = NULL;
9779 break;
9780 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009781 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009782 return NULL;
9783 }
9784 }
9785 while (ret == NULL);
9786
9787 return (char_u *)ret->fullname;
9788}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009789#endif
9790
Bram Moolenaar071d4272004-06-13 20:20:40 +00009791/*
9792 * Set the value of option "name".
9793 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009794 *
9795 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009796 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009797 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009798set_option_value(
9799 char_u *name,
9800 long number,
9801 char_u *string,
9802 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009803{
9804 int opt_idx;
9805 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009806 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009807
9808 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009809 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009810 {
9811 int key;
9812
9813 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009814 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009815 {
9816 char_u key_name[2];
9817
9818 if (key < 0)
9819 {
9820 key_name[0] = KEY2TERMCAP0(key);
9821 key_name[1] = KEY2TERMCAP1(key);
9822 }
9823 else
9824 {
9825 key_name[0] = KS_KEY;
9826 key_name[1] = (key & 0xff);
9827 }
9828 add_termcode(key_name, string, FALSE);
9829 if (full_screen)
9830 ttest(FALSE);
9831 redraw_all_later(CLEAR);
9832 return NULL;
9833 }
9834
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009835 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009836 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009837 else
9838 {
9839 flags = options[opt_idx].flags;
9840#ifdef HAVE_SANDBOX
9841 /* Disallow changing some options in the sandbox */
9842 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009843 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009844 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009845 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009846 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009847#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009848 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009849 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009850 else
9851 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009852 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009853 if (varp != NULL) /* hidden option is not changed */
9854 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009855 if (number == 0 && string != NULL)
9856 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009857 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009858
9859 /* Either we are given a string or we are setting option
9860 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009861 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009862 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009863 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009864 {
9865 /* There's another character after zeros or the string
9866 * is empty. In both cases, we are trying to set a
9867 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009868 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009869 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009870 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009871
9872 }
9873 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009874 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009875 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009876 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009877 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009878 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009879 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009880 }
9881 }
9882 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009883 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009884}
9885
9886/*
9887 * Get the terminal code for a terminal option.
9888 * Returns NULL when not found.
9889 */
9890 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009891get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009892{
9893 int opt_idx;
9894 char_u *varp;
9895
9896 if (tname[0] != 't' || tname[1] != '_' ||
9897 tname[2] == NUL || tname[3] == NUL)
9898 return NULL;
9899 if ((opt_idx = findoption(tname)) >= 0)
9900 {
9901 varp = get_varp(&(options[opt_idx]));
9902 if (varp != NULL)
9903 varp = *(char_u **)(varp);
9904 return varp;
9905 }
9906 return find_termcode(tname + 2);
9907}
9908
9909 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009910get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009911{
9912 int i;
9913
9914 i = findoption((char_u *)"hl");
9915 if (i >= 0)
9916 return options[i].def_val[VI_DEFAULT];
9917 return (char_u *)NULL;
9918}
9919
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009920 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009921get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009922{
9923 int i;
9924
9925 i = findoption((char_u *)"enc");
9926 if (i >= 0)
9927 return options[i].def_val[VI_DEFAULT];
9928 return (char_u *)NULL;
9929}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009930
Bram Moolenaar071d4272004-06-13 20:20:40 +00009931/*
9932 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009933 * When "has_lt" is true there is a '<' before "*arg_arg".
9934 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009935 */
9936 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009937find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009938{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009939 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009940 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009941 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009942
9943 /*
9944 * Don't use get_special_key_code() for t_xx, we don't want it to call
9945 * add_termcap_entry().
9946 */
9947 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9948 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009949 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009950 {
9951 --arg; /* put arg at the '<' */
9952 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009953 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009954 if (modifiers) /* can't handle modifiers here */
9955 key = 0;
9956 }
9957 return key;
9958}
9959
9960/*
9961 * if 'all' == 0: show changed options
9962 * if 'all' == 1: show all normal options
9963 * if 'all' == 2: show all terminal options
9964 */
9965 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009966showoptions(
9967 int all,
9968 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009969{
9970 struct vimoption *p;
9971 int col;
9972 int isterm;
9973 char_u *varp;
9974 struct vimoption **items;
9975 int item_count;
9976 int run;
9977 int row, rows;
9978 int cols;
9979 int i;
9980 int len;
9981
9982#define INC 20
9983#define GAP 3
9984
Bram Moolenaarc799fe22019-05-28 23:08:19 +02009985 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009986 if (items == NULL)
9987 return;
9988
9989 /* Highlight title */
9990 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +01009991 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009992 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +01009993 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009994 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +01009995 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009996 else
Bram Moolenaar32526b32019-01-19 17:43:09 +01009997 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +00009998
9999 /*
10000 * do the loop two times:
10001 * 1. display the short items
10002 * 2. display the long items (only strings and numbers)
10003 */
10004 for (run = 1; run <= 2 && !got_int; ++run)
10005 {
10006 /*
10007 * collect the items in items[]
10008 */
10009 item_count = 0;
10010 for (p = &options[0]; p->fullname != NULL; p++)
10011 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010012 // apply :filter /pat/
10013 if (message_filtered((char_u *) p->fullname))
10014 continue;
10015
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016 varp = NULL;
10017 isterm = istermoption(p);
10018 if (opt_flags != 0)
10019 {
10020 if (p->indir != PV_NONE && !isterm)
10021 varp = get_varp_scope(p, opt_flags);
10022 }
10023 else
10024 varp = get_varp(p);
10025 if (varp != NULL
10026 && ((all == 2 && isterm)
10027 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010028 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010029 {
10030 if (p->flags & P_BOOL)
10031 len = 1; /* a toggle option fits always */
10032 else
10033 {
10034 option_value2string(p, opt_flags);
10035 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10036 }
10037 if ((len <= INC - GAP && run == 1) ||
10038 (len > INC - GAP && run == 2))
10039 items[item_count++] = p;
10040 }
10041 }
10042
10043 /*
10044 * display the items
10045 */
10046 if (run == 1)
10047 {
10048 cols = (Columns + GAP - 3) / INC;
10049 if (cols == 0)
10050 cols = 1;
10051 rows = (item_count + cols - 1) / cols;
10052 }
10053 else /* run == 2 */
10054 rows = item_count;
10055 for (row = 0; row < rows && !got_int; ++row)
10056 {
10057 msg_putchar('\n'); /* go to next line */
10058 if (got_int) /* 'q' typed in more */
10059 break;
10060 col = 0;
10061 for (i = row; i < item_count; i += rows)
10062 {
10063 msg_col = col; /* make columns */
10064 showoneopt(items[i], opt_flags);
10065 col += INC;
10066 }
10067 out_flush();
10068 ui_breakcheck();
10069 }
10070 }
10071 vim_free(items);
10072}
10073
10074/*
10075 * Return TRUE if option "p" has its default value.
10076 */
10077 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010078optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010079{
10080 int dvi;
10081
10082 if (varp == NULL)
10083 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010084 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010085 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010086 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010087 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010088 /* the cast to long is required for Manx C, long_i is
10089 * needed for MSVC */
10090 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010091 /* P_STRING */
10092 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10093}
10094
10095/*
10096 * showoneopt: show the value of one option
10097 * must not be called with a hidden option!
10098 */
10099 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010100showoneopt(
10101 struct vimoption *p,
10102 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010103{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010104 char_u *varp;
10105 int save_silent = silent_mode;
10106
10107 silent_mode = FALSE;
10108 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010109
10110 varp = get_varp_scope(p, opt_flags);
10111
10112 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10113 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10114 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010115 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010116 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010117 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010118 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010119 msg_puts(" ");
10120 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010121 if (!(p->flags & P_BOOL))
10122 {
10123 msg_putchar('=');
10124 /* put value string in NameBuff */
10125 option_value2string(p, opt_flags);
10126 msg_outtrans(NameBuff);
10127 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010128
10129 silent_mode = save_silent;
10130 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010131}
10132
10133/*
10134 * Write modified options as ":set" commands to a file.
10135 *
10136 * There are three values for "opt_flags":
10137 * OPT_GLOBAL: Write global option values and fresh values of
10138 * buffer-local options (used for start of a session
10139 * file).
10140 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10141 * curwin (used for a vimrc file).
10142 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10143 * and local values for window-local options of
10144 * curwin. Local values are also written when at the
10145 * default value, because a modeline or autocommand
10146 * may have set them when doing ":edit file" and the
10147 * user has set them back at the default or fresh
10148 * value.
10149 * When "local_only" is TRUE, don't write fresh
10150 * values, only local values (for ":mkview").
10151 * (fresh value = value used for a new buffer or window for a local option).
10152 *
10153 * Return FAIL on error, OK otherwise.
10154 */
10155 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010156makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010157{
10158 struct vimoption *p;
10159 char_u *varp; /* currently used value */
10160 char_u *varp_fresh; /* local value */
10161 char_u *varp_local = NULL; /* fresh value */
10162 char *cmd;
10163 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010164 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010165
10166 /*
10167 * The options that don't have a default (terminal name, columns, lines)
10168 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010169 * Do the loop over "options[]" twice: once for options with the
10170 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010171 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010172 for (pri = 1; pri >= 0; --pri)
10173 {
10174 for (p = &options[0]; !istermoption(p); p++)
10175 if (!(p->flags & P_NO_MKRC)
10176 && !istermoption(p)
10177 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010178 {
10179 /* skip global option when only doing locals */
10180 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10181 continue;
10182
10183 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10184 * file, they are always buffer-specific. */
10185 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10186 continue;
10187
10188 /* Global values are only written when not at the default value. */
10189 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010190 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 continue;
10192
10193 round = 2;
10194 if (p->indir != PV_NONE)
10195 {
10196 if (p->var == VAR_WIN)
10197 {
10198 /* skip window-local option when only doing globals */
10199 if (!(opt_flags & OPT_LOCAL))
10200 continue;
10201 /* When fresh value of window-local option is not at the
10202 * default, need to write it too. */
10203 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10204 {
10205 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010206 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010207 {
10208 round = 1;
10209 varp_local = varp;
10210 varp = varp_fresh;
10211 }
10212 }
10213 }
10214 }
10215
10216 /* Round 1: fresh value for window-local options.
10217 * Round 2: other values */
10218 for ( ; round <= 2; varp = varp_local, ++round)
10219 {
10220 if (round == 1 || (opt_flags & OPT_GLOBAL))
10221 cmd = "set";
10222 else
10223 cmd = "setlocal";
10224
10225 if (p->flags & P_BOOL)
10226 {
10227 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10228 return FAIL;
10229 }
10230 else if (p->flags & P_NUM)
10231 {
10232 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10233 return FAIL;
10234 }
10235 else /* P_STRING */
10236 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010237 int do_endif = FALSE;
10238
Bram Moolenaar071d4272004-06-13 20:20:40 +000010239 /* Don't set 'syntax' and 'filetype' again if the value is
10240 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010241 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010242#if defined(FEAT_SYN_HL)
10243 p->indir == PV_SYN ||
10244#endif
10245 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010246 {
10247 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10248 *(char_u **)(varp)) < 0
10249 || put_eol(fd) < 0)
10250 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010251 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010252 }
10253 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010254 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010255 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010256 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010257 {
10258 if (put_line(fd, "endif") == FAIL)
10259 return FAIL;
10260 }
10261 }
10262 }
10263 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010264 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010265 return OK;
10266}
10267
10268#if defined(FEAT_FOLDING) || defined(PROTO)
10269/*
10270 * Generate set commands for the local fold options only. Used when
10271 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10272 */
10273 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010274makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010276 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010277# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010278 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010279 == FAIL
10280# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010281 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010282 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010283 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010284 == FAIL
10285 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10286 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10287 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10288 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10289 )
10290 return FAIL;
10291
10292 return OK;
10293}
10294#endif
10295
10296 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010297put_setstring(
10298 FILE *fd,
10299 char *cmd,
10300 char *name,
10301 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010302 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010303{
10304 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010305 char_u *buf = NULL;
10306 char_u *part = NULL;
10307 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010308
10309 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10310 return FAIL;
10311 if (*valuep != NULL)
10312 {
10313 /* Output 'pastetoggle' as key names. For other
10314 * options some characters have to be escaped with
10315 * CTRL-V or backslash */
10316 if (valuep == &p_pt)
10317 {
10318 s = *valuep;
10319 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010320 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010321 return FAIL;
10322 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010323 // expand the option value, replace $HOME by ~
10324 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010325 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010326 int size = (int)STRLEN(*valuep) + 1;
10327
10328 // replace home directory in the whole option value into "buf"
10329 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010330 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010331 goto fail;
10332 home_replace(NULL, *valuep, buf, size, FALSE);
10333
10334 // If the option value is longer than MAXPATHL, we need to append
10335 // earch comma separated part of the option separately, so that it
10336 // can be expanded when read back.
10337 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10338 && vim_strchr(*valuep, ',') != NULL)
10339 {
10340 part = alloc(size);
10341 if (part == NULL)
10342 goto fail;
10343
10344 // write line break to clear the option, e.g. ':set rtp='
10345 if (put_eol(fd) == FAIL)
10346 goto fail;
10347
10348 p = buf;
10349 while (*p != NUL)
10350 {
10351 // for each comma separated option part, append value to
10352 // the option, :set rtp+=value
10353 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10354 goto fail;
10355 (void)copy_option_part(&p, part, size, ",");
10356 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10357 goto fail;
10358 }
10359 vim_free(buf);
10360 vim_free(part);
10361 return OK;
10362 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010363 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010364 {
10365 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010366 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010367 }
10368 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010369 }
10370 else if (put_escstr(fd, *valuep, 2) == FAIL)
10371 return FAIL;
10372 }
10373 if (put_eol(fd) < 0)
10374 return FAIL;
10375 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010376fail:
10377 vim_free(buf);
10378 vim_free(part);
10379 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010380}
10381
10382 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010383put_setnum(
10384 FILE *fd,
10385 char *cmd,
10386 char *name,
10387 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010388{
10389 long wc;
10390
10391 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10392 return FAIL;
10393 if (wc_use_keyname((char_u *)valuep, &wc))
10394 {
10395 /* print 'wildchar' and 'wildcharm' as a key name */
10396 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10397 return FAIL;
10398 }
10399 else if (fprintf(fd, "%ld", *valuep) < 0)
10400 return FAIL;
10401 if (put_eol(fd) < 0)
10402 return FAIL;
10403 return OK;
10404}
10405
10406 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010407put_setbool(
10408 FILE *fd,
10409 char *cmd,
10410 char *name,
10411 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010412{
Bram Moolenaar893de922007-10-02 18:40:57 +000010413 if (value < 0) /* global/local option using global value */
10414 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10416 || put_eol(fd) < 0)
10417 return FAIL;
10418 return OK;
10419}
10420
10421/*
10422 * Clear all the terminal options.
10423 * If the option has been allocated, free the memory.
10424 * Terminal options are never hidden or indirect.
10425 */
10426 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010427clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010428{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010429 /*
10430 * Reset a few things before clearing the old options. This may cause
10431 * outputting a few things that the terminal doesn't understand, but the
10432 * screen will be cleared later, so this is OK.
10433 */
10434#ifdef FEAT_MOUSE_TTY
10435 mch_setmouse(FALSE); /* switch mouse off */
10436#endif
10437#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010438 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439#endif
10440#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10441 /* When starting the GUI close the display opened for the clipboard.
10442 * After restoring the title, because that will need the display. */
10443 if (gui.starting)
10444 clear_xterm_clip();
10445#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010446 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010447
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010448 free_termoptions();
10449}
10450
10451 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010452free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010453{
10454 struct vimoption *p;
10455
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010456 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010457 if (istermoption(p))
10458 {
10459 if (p->flags & P_ALLOCED)
10460 free_string_option(*(char_u **)(p->var));
10461 if (p->flags & P_DEF_ALLOCED)
10462 free_string_option(p->def_val[VI_DEFAULT]);
10463 *(char_u **)(p->var) = empty_option;
10464 p->def_val[VI_DEFAULT] = empty_option;
10465 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010466#ifdef FEAT_EVAL
10467 // remember where the option was cleared
10468 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10469#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010470 }
10471 clear_termcodes();
10472}
10473
10474/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010475 * Free the string for one term option, if it was allocated.
10476 * Set the string to empty_option and clear allocated flag.
10477 * "var" points to the option value.
10478 */
10479 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010480free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010481{
10482 struct vimoption *p;
10483
10484 for (p = &options[0]; p->fullname != NULL; p++)
10485 if (p->var == var)
10486 {
10487 if (p->flags & P_ALLOCED)
10488 free_string_option(*(char_u **)(p->var));
10489 *(char_u **)(p->var) = empty_option;
10490 p->flags &= ~P_ALLOCED;
10491 break;
10492 }
10493}
10494
10495/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010496 * Set the terminal option defaults to the current value.
10497 * Used after setting the terminal name.
10498 */
10499 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010500set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501{
10502 struct vimoption *p;
10503
10504 for (p = &options[0]; p->fullname != NULL; p++)
10505 {
10506 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10507 {
10508 if (p->flags & P_DEF_ALLOCED)
10509 {
10510 free_string_option(p->def_val[VI_DEFAULT]);
10511 p->flags &= ~P_DEF_ALLOCED;
10512 }
10513 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10514 if (p->flags & P_ALLOCED)
10515 {
10516 p->flags |= P_DEF_ALLOCED;
10517 p->flags &= ~P_ALLOCED; /* don't free the value now */
10518 }
10519 }
10520 }
10521}
10522
10523/*
10524 * return TRUE if 'p' starts with 't_'
10525 */
10526 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010527istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010528{
10529 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10530}
10531
Bram Moolenaar113e1072019-01-20 15:30:40 +010010532#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010533/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010534 * Unset local option value, similar to ":set opt<".
10535 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010536 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010537unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010538{
10539 struct vimoption *p;
10540 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010541 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010542
10543 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010544 if (opt_idx < 0)
10545 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010546 p = &(options[opt_idx]);
10547
10548 switch ((int)p->indir)
10549 {
10550 /* global option with local value: use local value if it's been set */
10551 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010552 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010553 break;
10554 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010555 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010556 break;
10557 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010558 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010559 break;
10560 case PV_AR:
10561 buf->b_p_ar = -1;
10562 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010563 case PV_BKC:
10564 clear_string_option(&buf->b_p_bkc);
10565 buf->b_bkc_flags = 0;
10566 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010567 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010568 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010569 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010570 case PV_TC:
10571 clear_string_option(&buf->b_p_tc);
10572 buf->b_tc_flags = 0;
10573 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010574 case PV_SISO:
10575 curwin->w_p_siso = -1;
10576 break;
10577 case PV_SO:
10578 curwin->w_p_so = -1;
10579 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010580#ifdef FEAT_FIND_ID
10581 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010582 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010583 break;
10584 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010585 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010586 break;
10587#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010588 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010589 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010590 break;
10591 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010592 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010593 break;
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010594 case PV_FP:
10595 clear_string_option(&buf->b_p_fp);
10596 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010597#ifdef FEAT_QUICKFIX
10598 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010599 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010600 break;
10601 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010602 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010603 break;
10604 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010605 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010606 break;
10607#endif
10608#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10609 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010610 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010611 break;
10612#endif
10613#if defined(FEAT_CRYPT)
10614 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010615 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010616 break;
10617#endif
10618#ifdef FEAT_STL_OPT
10619 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010620 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010621 break;
10622#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010623 case PV_UL:
10624 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10625 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010626#ifdef FEAT_LISP
10627 case PV_LW:
10628 clear_string_option(&buf->b_p_lw);
10629 break;
10630#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010631 case PV_MENC:
10632 clear_string_option(&buf->b_p_menc);
10633 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010634 }
10635}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010636#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010637
10638/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010639 * Get pointer to option variable, depending on local or global scope.
10640 */
10641 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010642get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010643{
10644 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10645 {
10646 if (p->var == VAR_WIN)
10647 return (char_u *)GLOBAL_WO(get_varp(p));
10648 return p->var;
10649 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010650 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010651 {
10652 switch ((int)p->indir)
10653 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010654 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010655#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010656 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10657 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10658 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010659#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010660 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10661 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10662 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010663 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010664 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010665 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010666 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10667 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010668#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010669 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10670 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010671#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010672 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10673 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010674#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10675 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10676#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010677#if defined(FEAT_CRYPT)
10678 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10679#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010680#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010681 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010682#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010683 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010684#ifdef FEAT_LISP
10685 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10686#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010687 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010688 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010689 }
10690 return NULL; /* "cannot happen" */
10691 }
10692 return get_varp(p);
10693}
10694
10695/*
10696 * Get pointer to option variable.
10697 */
10698 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010699get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010700{
10701 /* hidden option, always return NULL */
10702 if (p->var == NULL)
10703 return NULL;
10704
10705 switch ((int)p->indir)
10706 {
10707 case PV_NONE: return p->var;
10708
10709 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010710 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010711 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010712 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010713 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010714 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010715 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010716 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010717 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010718 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010719 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010720 case PV_TC: return *curbuf->b_p_tc != NUL
10721 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010722 case PV_BKC: return *curbuf->b_p_bkc != NUL
10723 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010724 case PV_SISO: return curwin->w_p_siso >= 0
10725 ? (char_u *)&(curwin->w_p_siso) : p->var;
10726 case PV_SO: return curwin->w_p_so >= 0
10727 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010728#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010729 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010730 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010731 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010732 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10733#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010734 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010736 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010738 case PV_FP: return *curbuf->b_p_fp != NUL
10739 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010740#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010741 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010742 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010743 case PV_GP: return *curbuf->b_p_gp != NUL
10744 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10745 case PV_MP: return *curbuf->b_p_mp != NUL
10746 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010747#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010748#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10749 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10750 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10751#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010752#if defined(FEAT_CRYPT)
10753 case PV_CM: return *curbuf->b_p_cm != NUL
10754 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10755#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010756#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010757 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010758 ? (char_u *)&(curwin->w_p_stl) : p->var;
10759#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010760 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10761 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010762#ifdef FEAT_LISP
10763 case PV_LW: return *curbuf->b_p_lw != NUL
10764 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10765#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010766 case PV_MENC: return *curbuf->b_p_menc != NUL
10767 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010768#ifdef FEAT_ARABIC
10769 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10770#endif
10771 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010772#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010773 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10774#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010775#ifdef FEAT_SYN_HL
10776 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10777 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010778 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010779#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010780#ifdef FEAT_DIFF
10781 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10782#endif
10783#ifdef FEAT_FOLDING
10784 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10785 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10786 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10787 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10788 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10789 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10790 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10791# ifdef FEAT_EVAL
10792 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10793 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10794# endif
10795 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10796#endif
10797 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010798 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010799#ifdef FEAT_LINEBREAK
10800 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10801#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010802 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010803 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010804#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010805 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10806#endif
10807#ifdef FEAT_RIGHTLEFT
10808 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10809 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10810#endif
10811 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10812 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10813#ifdef FEAT_LINEBREAK
10814 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010815 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10816 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010817#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020010818 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010819 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010820 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010821#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010822 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10823 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10824#endif
10825#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010826 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10827 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10828 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010829#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010830
10831 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10832 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010833 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010834 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10835 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010836 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10837 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10838#ifdef FEAT_CINDENT
10839 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10840 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10841 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10842#endif
10843#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10844 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10845#endif
10846#ifdef FEAT_COMMENTS
10847 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10848#endif
10849#ifdef FEAT_FOLDING
10850 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10851#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010852 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaare2c453d2019-08-21 14:37:09 +020010853#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +020010854 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010856#ifdef FEAT_COMPL_FUNC
10857 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010858 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010859#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020010860#ifdef FEAT_EVAL
10861 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
10862#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010863 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010864 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010865 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010866 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010867 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010868 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010869 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010870 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010871 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10872 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10873 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10874 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10875#ifdef FEAT_FIND_ID
10876# ifdef FEAT_EVAL
10877 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10878# endif
10879#endif
10880#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10881 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10882 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10883#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010884#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010885 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10886#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887#ifdef FEAT_CRYPT
10888 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10889#endif
10890#ifdef FEAT_LISP
10891 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10892#endif
10893 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10894 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10895 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10896 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10897 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010898 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010899#ifdef FEAT_TEXTOBJ
10900 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10901#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010902 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10903#ifdef FEAT_SMARTINDENT
10904 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10905#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010906 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010907 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10908#ifdef FEAT_SEARCHPATH
10909 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10910#endif
10911 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10912#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010913 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010914 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10915#endif
10916#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010917 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10918 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10919 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010920#endif
10921 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10922 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10923 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10924 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010925#ifdef FEAT_PERSISTENT_UNDO
10926 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10927#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010928 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10929#ifdef FEAT_KEYMAP
10930 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10931#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010932#ifdef FEAT_SIGNS
10933 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10934#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020010935#ifdef FEAT_VARTABS
10936 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
10937 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
10938#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010939 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010940 }
10941 /* always return a valid pointer to avoid a crash! */
10942 return (char_u *)&(curbuf->b_p_wm);
10943}
10944
10945/*
10946 * Get the value of 'equalprg', either the buffer-local one or the global one.
10947 */
10948 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010949get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010950{
10951 if (*curbuf->b_p_ep == NUL)
10952 return p_ep;
10953 return curbuf->b_p_ep;
10954}
10955
Bram Moolenaar071d4272004-06-13 20:20:40 +000010956/*
10957 * Copy options from one window to another.
10958 * Used when splitting a window.
10959 */
10960 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010961win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010962{
10963 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10964 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010965#if defined(FEAT_LINEBREAK)
10966 briopt_check(wp_to);
10967#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010968}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010969
10970/*
10971 * Copy the options from one winopt_T to another.
10972 * Doesn't free the old option values in "to", use clear_winopt() for that.
10973 * The 'scroll' option is not copied, because it depends on the window height.
10974 * The 'previewwindow' option is reset, there can be only one preview window.
10975 */
10976 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010977copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010978{
10979#ifdef FEAT_ARABIC
10980 to->wo_arab = from->wo_arab;
10981#endif
10982 to->wo_list = from->wo_list;
10983 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020010984 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010985#ifdef FEAT_LINEBREAK
10986 to->wo_nuw = from->wo_nuw;
10987#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010988#ifdef FEAT_RIGHTLEFT
10989 to->wo_rl = from->wo_rl;
10990 to->wo_rlc = vim_strsave(from->wo_rlc);
10991#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010992#ifdef FEAT_STL_OPT
10993 to->wo_stl = vim_strsave(from->wo_stl);
10994#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010995 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020010996#ifdef FEAT_DIFF
10997 to->wo_wrap_save = from->wo_wrap_save;
10998#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010999#ifdef FEAT_LINEBREAK
11000 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011001 to->wo_bri = from->wo_bri;
11002 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011003#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011004 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011005 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011006 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011007 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011008 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011009#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011010 to->wo_spell = from->wo_spell;
11011#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011012#ifdef FEAT_SYN_HL
11013 to->wo_cuc = from->wo_cuc;
11014 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011015 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011016#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011017#ifdef FEAT_DIFF
11018 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011019 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011020#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011021#ifdef FEAT_CONCEAL
11022 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011023 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011024#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011025#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011026 to->wo_twk = vim_strsave(from->wo_twk);
11027 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011028#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011029#ifdef FEAT_FOLDING
11030 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011031 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011032 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011033 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011034 to->wo_fdi = vim_strsave(from->wo_fdi);
11035 to->wo_fml = from->wo_fml;
11036 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011037 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011038 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011039 to->wo_fdm_save = from->wo_diff_saved
11040 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011041 to->wo_fdn = from->wo_fdn;
11042# ifdef FEAT_EVAL
11043 to->wo_fde = vim_strsave(from->wo_fde);
11044 to->wo_fdt = vim_strsave(from->wo_fdt);
11045# endif
11046 to->wo_fmr = vim_strsave(from->wo_fmr);
11047#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011048#ifdef FEAT_SIGNS
11049 to->wo_scl = vim_strsave(from->wo_scl);
11050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051 check_winopt(to); /* don't want NULL pointers */
11052}
11053
11054/*
11055 * Check string options in a window for a NULL value.
11056 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020011057 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011058check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011059{
11060 check_winopt(&win->w_onebuf_opt);
11061 check_winopt(&win->w_allbuf_opt);
11062}
11063
11064/*
11065 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11066 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011067 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011068check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011069{
11070#ifdef FEAT_FOLDING
11071 check_string_option(&wop->wo_fdi);
11072 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011073 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011074# ifdef FEAT_EVAL
11075 check_string_option(&wop->wo_fde);
11076 check_string_option(&wop->wo_fdt);
11077# endif
11078 check_string_option(&wop->wo_fmr);
11079#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011080#ifdef FEAT_SIGNS
11081 check_string_option(&wop->wo_scl);
11082#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011083#ifdef FEAT_RIGHTLEFT
11084 check_string_option(&wop->wo_rlc);
11085#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011086#ifdef FEAT_STL_OPT
11087 check_string_option(&wop->wo_stl);
11088#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011089#ifdef FEAT_SYN_HL
11090 check_string_option(&wop->wo_cc);
11091#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011092#ifdef FEAT_CONCEAL
11093 check_string_option(&wop->wo_cocu);
11094#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011095#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011096 check_string_option(&wop->wo_twk);
11097 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011098#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011099#ifdef FEAT_LINEBREAK
11100 check_string_option(&wop->wo_briopt);
11101#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011102 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103}
11104
11105/*
11106 * Free the allocated memory inside a winopt_T.
11107 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011108 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011109clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011110{
11111#ifdef FEAT_FOLDING
11112 clear_string_option(&wop->wo_fdi);
11113 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011114 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011115# ifdef FEAT_EVAL
11116 clear_string_option(&wop->wo_fde);
11117 clear_string_option(&wop->wo_fdt);
11118# endif
11119 clear_string_option(&wop->wo_fmr);
11120#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011121#ifdef FEAT_SIGNS
11122 clear_string_option(&wop->wo_scl);
11123#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011124#ifdef FEAT_LINEBREAK
11125 clear_string_option(&wop->wo_briopt);
11126#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011127 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011128#ifdef FEAT_RIGHTLEFT
11129 clear_string_option(&wop->wo_rlc);
11130#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011131#ifdef FEAT_STL_OPT
11132 clear_string_option(&wop->wo_stl);
11133#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011134#ifdef FEAT_SYN_HL
11135 clear_string_option(&wop->wo_cc);
11136#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011137#ifdef FEAT_CONCEAL
11138 clear_string_option(&wop->wo_cocu);
11139#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011140#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011141 clear_string_option(&wop->wo_twk);
11142 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011143#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011144}
11145
11146/*
11147 * Copy global option values to local options for one buffer.
11148 * Used when creating a new buffer and sometimes when entering a buffer.
11149 * flags:
11150 * BCO_ENTER We will enter the buf buffer.
11151 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11152 * appropriate.
11153 * BCO_NOHELP Don't copy the values to a help buffer.
11154 */
11155 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011156buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011157{
11158 int should_copy = TRUE;
11159 char_u *save_p_isk = NULL; /* init for GCC */
11160 int dont_do_help;
11161 int did_isk = FALSE;
11162
11163 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011164 * Skip this when the option defaults have not been set yet. Happens when
11165 * main() allocates the first buffer.
11166 */
11167 if (p_cpo != NULL)
11168 {
11169 /*
11170 * Always copy when entering and 'cpo' contains 'S'.
11171 * Don't copy when already initialized.
11172 * Don't copy when 'cpo' contains 's' and not entering.
11173 * 'S' BCO_ENTER initialized 's' should_copy
11174 * yes yes X X TRUE
11175 * yes no yes X FALSE
11176 * no X yes X FALSE
11177 * X no no yes FALSE
11178 * X no no no TRUE
11179 * no yes no X TRUE
11180 */
11181 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11182 && (buf->b_p_initialized
11183 || (!(flags & BCO_ENTER)
11184 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11185 should_copy = FALSE;
11186
11187 if (should_copy || (flags & BCO_ALWAYS))
11188 {
11189 /* Don't copy the options specific to a help buffer when
11190 * BCO_NOHELP is given or the options were initialized already
11191 * (jumping back to a help file with CTRL-T or CTRL-O) */
11192 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11193 || buf->b_p_initialized;
11194 if (dont_do_help) /* don't free b_p_isk */
11195 {
11196 save_p_isk = buf->b_p_isk;
11197 buf->b_p_isk = NULL;
11198 }
11199 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011200 * Always free the allocated strings. If not already initialized,
11201 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011202 */
11203 if (!buf->b_p_initialized)
11204 {
11205 free_buf_options(buf, TRUE);
11206 buf->b_p_ro = FALSE; /* don't copy readonly */
11207 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011208 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011209 switch (*p_ffs)
11210 {
11211 case 'm':
11212 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11213 case 'd':
11214 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11215 case 'u':
11216 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11217 default:
11218 buf->b_p_ff = vim_strsave(p_ff);
11219 }
11220 if (buf->b_p_ff != NULL)
11221 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011222 buf->b_p_bh = empty_option;
11223 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011224 }
11225 else
11226 free_buf_options(buf, FALSE);
11227
11228 buf->b_p_ai = p_ai;
11229 buf->b_p_ai_nopaste = p_ai_nopaste;
11230 buf->b_p_sw = p_sw;
11231 buf->b_p_tw = p_tw;
11232 buf->b_p_tw_nopaste = p_tw_nopaste;
11233 buf->b_p_tw_nobin = p_tw_nobin;
11234 buf->b_p_wm = p_wm;
11235 buf->b_p_wm_nopaste = p_wm_nopaste;
11236 buf->b_p_wm_nobin = p_wm_nobin;
11237 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011238 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011239 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011240 buf->b_p_et = p_et;
11241 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011242 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011243 buf->b_p_ml = p_ml;
11244 buf->b_p_ml_nobin = p_ml_nobin;
11245 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011246 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011247 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaare2c453d2019-08-21 14:37:09 +020011248#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011249 buf->b_p_csl = vim_strsave(p_csl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011250#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011251#ifdef FEAT_COMPL_FUNC
11252 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011253 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011254#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011255#ifdef FEAT_EVAL
11256 buf->b_p_tfu = vim_strsave(p_tfu);
11257#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011258 buf->b_p_sts = p_sts;
11259 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011260#ifdef FEAT_VARTABS
11261 buf->b_p_vsts = vim_strsave(p_vsts);
11262 if (p_vsts && p_vsts != empty_option)
11263 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11264 else
11265 buf->b_p_vsts_array = 0;
11266 buf->b_p_vsts_nopaste = p_vsts_nopaste
11267 ? vim_strsave(p_vsts_nopaste) : NULL;
11268#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011269 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011270#ifdef FEAT_COMMENTS
11271 buf->b_p_com = vim_strsave(p_com);
11272#endif
11273#ifdef FEAT_FOLDING
11274 buf->b_p_cms = vim_strsave(p_cms);
11275#endif
11276 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011277 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011278 buf->b_p_nf = vim_strsave(p_nf);
11279 buf->b_p_mps = vim_strsave(p_mps);
11280#ifdef FEAT_SMARTINDENT
11281 buf->b_p_si = p_si;
11282#endif
11283 buf->b_p_ci = p_ci;
11284#ifdef FEAT_CINDENT
11285 buf->b_p_cin = p_cin;
11286 buf->b_p_cink = vim_strsave(p_cink);
11287 buf->b_p_cino = vim_strsave(p_cino);
11288#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011289 /* Don't copy 'filetype', it must be detected */
11290 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011291 buf->b_p_pi = p_pi;
11292#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11293 buf->b_p_cinw = vim_strsave(p_cinw);
11294#endif
11295#ifdef FEAT_LISP
11296 buf->b_p_lisp = p_lisp;
11297#endif
11298#ifdef FEAT_SYN_HL
11299 /* Don't copy 'syntax', it must be set */
11300 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011301 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011302 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011303#endif
11304#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011305 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011306 (void)compile_cap_prog(&buf->b_s);
11307 buf->b_s.b_p_spf = vim_strsave(p_spf);
11308 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011309#endif
11310#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11311 buf->b_p_inde = vim_strsave(p_inde);
11312 buf->b_p_indk = vim_strsave(p_indk);
11313#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011314 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011315#if defined(FEAT_EVAL)
11316 buf->b_p_fex = vim_strsave(p_fex);
11317#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011318#ifdef FEAT_CRYPT
11319 buf->b_p_key = vim_strsave(p_key);
11320#endif
11321#ifdef FEAT_SEARCHPATH
11322 buf->b_p_sua = vim_strsave(p_sua);
11323#endif
11324#ifdef FEAT_KEYMAP
11325 buf->b_p_keymap = vim_strsave(p_keymap);
11326 buf->b_kmap_state |= KEYMAP_INIT;
11327#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011328#ifdef FEAT_TERMINAL
11329 buf->b_p_twsl = p_twsl;
11330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011331 /* This isn't really an option, but copying the langmap and IME
11332 * state from the current buffer is better than resetting it. */
11333 buf->b_p_iminsert = p_iminsert;
11334 buf->b_p_imsearch = p_imsearch;
11335
11336 /* options that are normally global but also have a local value
11337 * are not copied, start using the global value */
11338 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011339 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011340 buf->b_p_bkc = empty_option;
11341 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342#ifdef FEAT_QUICKFIX
11343 buf->b_p_gp = empty_option;
11344 buf->b_p_mp = empty_option;
11345 buf->b_p_efm = empty_option;
11346#endif
11347 buf->b_p_ep = empty_option;
11348 buf->b_p_kp = empty_option;
11349 buf->b_p_path = empty_option;
11350 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011351 buf->b_p_tc = empty_option;
11352 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011353#ifdef FEAT_FIND_ID
11354 buf->b_p_def = empty_option;
11355 buf->b_p_inc = empty_option;
11356# ifdef FEAT_EVAL
11357 buf->b_p_inex = vim_strsave(p_inex);
11358# endif
11359#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011360 buf->b_p_dict = empty_option;
11361 buf->b_p_tsr = empty_option;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011362#ifdef FEAT_TEXTOBJ
11363 buf->b_p_qe = vim_strsave(p_qe);
11364#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011365#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11366 buf->b_p_bexpr = empty_option;
11367#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011368#if defined(FEAT_CRYPT)
11369 buf->b_p_cm = empty_option;
11370#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011371#ifdef FEAT_PERSISTENT_UNDO
11372 buf->b_p_udf = p_udf;
11373#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011374#ifdef FEAT_LISP
11375 buf->b_p_lw = empty_option;
11376#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011377 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011378
11379 /*
11380 * Don't copy the options set by ex_help(), use the saved values,
11381 * when going from a help buffer to a non-help buffer.
11382 * Don't touch these at all when BCO_NOHELP is used and going from
11383 * or to a help buffer.
11384 */
11385 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011386 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011388#ifdef FEAT_VARTABS
11389 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11390 tabstop_set(p_vts, &buf->b_p_vts_array);
11391 else
11392 buf->b_p_vts_array = NULL;
11393#endif
11394 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011395 else
11396 {
11397 buf->b_p_isk = vim_strsave(p_isk);
11398 did_isk = TRUE;
11399 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011400#ifdef FEAT_VARTABS
11401 buf->b_p_vts = vim_strsave(p_vts);
11402 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11403 tabstop_set(p_vts, &buf->b_p_vts_array);
11404 else
11405 buf->b_p_vts_array = NULL;
11406#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011407 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408 if (buf->b_p_bt[0] == 'h')
11409 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011410 buf->b_p_ma = p_ma;
11411 }
11412 }
11413
11414 /*
11415 * When the options should be copied (ignoring BCO_ALWAYS), set the
11416 * flag that indicates that the options have been initialized.
11417 */
11418 if (should_copy)
11419 buf->b_p_initialized = TRUE;
11420 }
11421
11422 check_buf_options(buf); /* make sure we don't have NULLs */
11423 if (did_isk)
11424 (void)buf_init_chartab(buf, FALSE);
11425}
11426
11427/*
11428 * Reset the 'modifiable' option and its default value.
11429 */
11430 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011431reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011432{
11433 int opt_idx;
11434
11435 curbuf->b_p_ma = FALSE;
11436 p_ma = FALSE;
11437 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011438 if (opt_idx >= 0)
11439 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011440}
11441
11442/*
11443 * Set the global value for 'iminsert' to the local value.
11444 */
11445 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011446set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011447{
11448 p_iminsert = curbuf->b_p_iminsert;
11449}
11450
11451/*
11452 * Set the global value for 'imsearch' to the local value.
11453 */
11454 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011455set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011456{
11457 p_imsearch = curbuf->b_p_imsearch;
11458}
11459
Bram Moolenaar071d4272004-06-13 20:20:40 +000011460static int expand_option_idx = -1;
11461static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11462static int expand_option_flags = 0;
11463
11464 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011465set_context_in_set_cmd(
11466 expand_T *xp,
11467 char_u *arg,
11468 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011469{
11470 int nextchar;
11471 long_u flags = 0; /* init for GCC */
11472 int opt_idx = 0; /* init for GCC */
11473 char_u *p;
11474 char_u *s;
11475 int is_term_option = FALSE;
11476 int key;
11477
11478 expand_option_flags = opt_flags;
11479
11480 xp->xp_context = EXPAND_SETTINGS;
11481 if (*arg == NUL)
11482 {
11483 xp->xp_pattern = arg;
11484 return;
11485 }
11486 p = arg + STRLEN(arg) - 1;
11487 if (*p == ' ' && *(p - 1) != '\\')
11488 {
11489 xp->xp_pattern = p + 1;
11490 return;
11491 }
11492 while (p > arg)
11493 {
11494 s = p;
11495 /* count number of backslashes before ' ' or ',' */
11496 if (*p == ' ' || *p == ',')
11497 {
11498 while (s > arg && *(s - 1) == '\\')
11499 --s;
11500 }
11501 /* break at a space with an even number of backslashes */
11502 if (*p == ' ' && ((p - s) & 1) == 0)
11503 {
11504 ++p;
11505 break;
11506 }
11507 --p;
11508 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011509 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011510 {
11511 xp->xp_context = EXPAND_BOOL_SETTINGS;
11512 p += 2;
11513 }
11514 if (STRNCMP(p, "inv", 3) == 0)
11515 {
11516 xp->xp_context = EXPAND_BOOL_SETTINGS;
11517 p += 3;
11518 }
11519 xp->xp_pattern = arg = p;
11520 if (*arg == '<')
11521 {
11522 while (*p != '>')
11523 if (*p++ == NUL) /* expand terminal option name */
11524 return;
11525 key = get_special_key_code(arg + 1);
11526 if (key == 0) /* unknown name */
11527 {
11528 xp->xp_context = EXPAND_NOTHING;
11529 return;
11530 }
11531 nextchar = *++p;
11532 is_term_option = TRUE;
11533 expand_option_name[2] = KEY2TERMCAP0(key);
11534 expand_option_name[3] = KEY2TERMCAP1(key);
11535 }
11536 else
11537 {
11538 if (p[0] == 't' && p[1] == '_')
11539 {
11540 p += 2;
11541 if (*p != NUL)
11542 ++p;
11543 if (*p == NUL)
11544 return; /* expand option name */
11545 nextchar = *++p;
11546 is_term_option = TRUE;
11547 expand_option_name[2] = p[-2];
11548 expand_option_name[3] = p[-1];
11549 }
11550 else
11551 {
11552 /* Allow * wildcard */
11553 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11554 p++;
11555 if (*p == NUL)
11556 return;
11557 nextchar = *p;
11558 *p = NUL;
11559 opt_idx = findoption(arg);
11560 *p = nextchar;
11561 if (opt_idx == -1 || options[opt_idx].var == NULL)
11562 {
11563 xp->xp_context = EXPAND_NOTHING;
11564 return;
11565 }
11566 flags = options[opt_idx].flags;
11567 if (flags & P_BOOL)
11568 {
11569 xp->xp_context = EXPAND_NOTHING;
11570 return;
11571 }
11572 }
11573 }
11574 /* handle "-=" and "+=" */
11575 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11576 {
11577 ++p;
11578 nextchar = '=';
11579 }
11580 if ((nextchar != '=' && nextchar != ':')
11581 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11582 {
11583 xp->xp_context = EXPAND_UNSUCCESSFUL;
11584 return;
11585 }
11586 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11587 {
11588 xp->xp_context = EXPAND_OLD_SETTING;
11589 if (is_term_option)
11590 expand_option_idx = -1;
11591 else
11592 expand_option_idx = opt_idx;
11593 xp->xp_pattern = p + 1;
11594 return;
11595 }
11596 xp->xp_context = EXPAND_NOTHING;
11597 if (is_term_option || (flags & P_NUM))
11598 return;
11599
11600 xp->xp_pattern = p + 1;
11601
11602 if (flags & P_EXPAND)
11603 {
11604 p = options[opt_idx].var;
11605 if (p == (char_u *)&p_bdir
11606 || p == (char_u *)&p_dir
11607 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011608 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011609 || p == (char_u *)&p_rtp
11610#ifdef FEAT_SEARCHPATH
11611 || p == (char_u *)&p_cdpath
11612#endif
11613#ifdef FEAT_SESSION
11614 || p == (char_u *)&p_vdir
11615#endif
11616 )
11617 {
11618 xp->xp_context = EXPAND_DIRECTORIES;
11619 if (p == (char_u *)&p_path
11620#ifdef FEAT_SEARCHPATH
11621 || p == (char_u *)&p_cdpath
11622#endif
11623 )
11624 xp->xp_backslash = XP_BS_THREE;
11625 else
11626 xp->xp_backslash = XP_BS_ONE;
11627 }
11628 else
11629 {
11630 xp->xp_context = EXPAND_FILES;
11631 /* for 'tags' need three backslashes for a space */
11632 if (p == (char_u *)&p_tags)
11633 xp->xp_backslash = XP_BS_THREE;
11634 else
11635 xp->xp_backslash = XP_BS_ONE;
11636 }
11637 }
11638
11639 /* For an option that is a list of file names, find the start of the
11640 * last file name. */
11641 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11642 {
11643 /* count number of backslashes before ' ' or ',' */
11644 if (*p == ' ' || *p == ',')
11645 {
11646 s = p;
11647 while (s > xp->xp_pattern && *(s - 1) == '\\')
11648 --s;
11649 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11650 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11651 {
11652 xp->xp_pattern = p + 1;
11653 break;
11654 }
11655 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011656
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011657#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011658 /* for 'spellsuggest' start at "file:" */
11659 if (options[opt_idx].var == (char_u *)&p_sps
11660 && STRNCMP(p, "file:", 5) == 0)
11661 {
11662 xp->xp_pattern = p + 5;
11663 break;
11664 }
11665#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011666 }
11667
11668 return;
11669}
11670
11671 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011672ExpandSettings(
11673 expand_T *xp,
11674 regmatch_T *regmatch,
11675 int *num_file,
11676 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011677{
11678 int num_normal = 0; /* Nr of matching non-term-code settings */
11679 int num_term = 0; /* Nr of matching terminal code settings */
11680 int opt_idx;
11681 int match;
11682 int count = 0;
11683 char_u *str;
11684 int loop;
11685 int is_term_opt;
11686 char_u name_buf[MAX_KEY_NAME_LEN];
11687 static char *(names[]) = {"all", "termcap"};
11688 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11689
11690 /* do this loop twice:
11691 * loop == 0: count the number of matching options
11692 * loop == 1: copy the matching options into allocated memory
11693 */
11694 for (loop = 0; loop <= 1; ++loop)
11695 {
11696 regmatch->rm_ic = ic;
11697 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11698 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011699 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11700 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011701 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11702 {
11703 if (loop == 0)
11704 num_normal++;
11705 else
11706 (*file)[count++] = vim_strsave((char_u *)names[match]);
11707 }
11708 }
11709 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11710 opt_idx++)
11711 {
11712 if (options[opt_idx].var == NULL)
11713 continue;
11714 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11715 && !(options[opt_idx].flags & P_BOOL))
11716 continue;
11717 is_term_opt = istermoption(&options[opt_idx]);
11718 if (is_term_opt && num_normal > 0)
11719 continue;
11720 match = FALSE;
11721 if (vim_regexec(regmatch, str, (colnr_T)0)
11722 || (options[opt_idx].shortname != NULL
11723 && vim_regexec(regmatch,
11724 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11725 match = TRUE;
11726 else if (is_term_opt)
11727 {
11728 name_buf[0] = '<';
11729 name_buf[1] = 't';
11730 name_buf[2] = '_';
11731 name_buf[3] = str[2];
11732 name_buf[4] = str[3];
11733 name_buf[5] = '>';
11734 name_buf[6] = NUL;
11735 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11736 {
11737 match = TRUE;
11738 str = name_buf;
11739 }
11740 }
11741 if (match)
11742 {
11743 if (loop == 0)
11744 {
11745 if (is_term_opt)
11746 num_term++;
11747 else
11748 num_normal++;
11749 }
11750 else
11751 (*file)[count++] = vim_strsave(str);
11752 }
11753 }
11754 /*
11755 * Check terminal key codes, these are not in the option table
11756 */
11757 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11758 {
11759 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11760 {
11761 if (!isprint(str[0]) || !isprint(str[1]))
11762 continue;
11763
11764 name_buf[0] = 't';
11765 name_buf[1] = '_';
11766 name_buf[2] = str[0];
11767 name_buf[3] = str[1];
11768 name_buf[4] = NUL;
11769
11770 match = FALSE;
11771 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11772 match = TRUE;
11773 else
11774 {
11775 name_buf[0] = '<';
11776 name_buf[1] = 't';
11777 name_buf[2] = '_';
11778 name_buf[3] = str[0];
11779 name_buf[4] = str[1];
11780 name_buf[5] = '>';
11781 name_buf[6] = NUL;
11782
11783 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11784 match = TRUE;
11785 }
11786 if (match)
11787 {
11788 if (loop == 0)
11789 num_term++;
11790 else
11791 (*file)[count++] = vim_strsave(name_buf);
11792 }
11793 }
11794
11795 /*
11796 * Check special key names.
11797 */
11798 regmatch->rm_ic = TRUE; /* ignore case here */
11799 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11800 {
11801 name_buf[0] = '<';
11802 STRCPY(name_buf + 1, str);
11803 STRCAT(name_buf, ">");
11804
11805 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11806 {
11807 if (loop == 0)
11808 num_term++;
11809 else
11810 (*file)[count++] = vim_strsave(name_buf);
11811 }
11812 }
11813 }
11814 if (loop == 0)
11815 {
11816 if (num_normal > 0)
11817 *num_file = num_normal;
11818 else if (num_term > 0)
11819 *num_file = num_term;
11820 else
11821 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020011822 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011823 if (*file == NULL)
11824 {
11825 *file = (char_u **)"";
11826 return FAIL;
11827 }
11828 }
11829 }
11830 return OK;
11831}
11832
11833 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011834ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011835{
11836 char_u *var = NULL; /* init for GCC */
11837 char_u *buf;
11838
11839 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020011840 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011841 if (*file == NULL)
11842 return FAIL;
11843
11844 /*
11845 * For a terminal key code expand_option_idx is < 0.
11846 */
11847 if (expand_option_idx < 0)
11848 {
11849 var = find_termcode(expand_option_name + 2);
11850 if (var == NULL)
11851 expand_option_idx = findoption(expand_option_name);
11852 }
11853
11854 if (expand_option_idx >= 0)
11855 {
11856 /* put string of option value in NameBuff */
11857 option_value2string(&options[expand_option_idx], expand_option_flags);
11858 var = NameBuff;
11859 }
11860 else if (var == NULL)
11861 var = (char_u *)"";
11862
11863 /* A backslash is required before some characters. This is the reverse of
11864 * what happens in do_set(). */
11865 buf = vim_strsave_escaped(var, escape_chars);
11866
11867 if (buf == NULL)
11868 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011869 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011870 return FAIL;
11871 }
11872
11873#ifdef BACKSLASH_IN_FILENAME
11874 /* For MS-Windows et al. we don't double backslashes at the start and
11875 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011876 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011877 if (var[0] == '\\' && var[1] == '\\'
11878 && expand_option_idx >= 0
11879 && (options[expand_option_idx].flags & P_EXPAND)
11880 && vim_isfilec(var[2])
11881 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011882 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011883#endif
11884
11885 *file[0] = buf;
11886 *num_file = 1;
11887 return OK;
11888}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011889
11890/*
11891 * Get the value for the numeric or string option *opp in a nice format into
11892 * NameBuff[]. Must not be called with a hidden option!
11893 */
11894 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011895option_value2string(
11896 struct vimoption *opp,
11897 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011898{
11899 char_u *varp;
11900
11901 varp = get_varp_scope(opp, opt_flags);
11902
11903 if (opp->flags & P_NUM)
11904 {
11905 long wc = 0;
11906
11907 if (wc_use_keyname(varp, &wc))
11908 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11909 else if (wc != 0)
11910 STRCPY(NameBuff, transchar((int)wc));
11911 else
11912 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11913 }
11914 else /* P_STRING */
11915 {
11916 varp = *(char_u **)(varp);
11917 if (varp == NULL) /* just in case */
11918 NameBuff[0] = NUL;
11919#ifdef FEAT_CRYPT
11920 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011921 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011922 STRCPY(NameBuff, "*****");
11923#endif
11924 else if (opp->flags & P_EXPAND)
11925 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11926 /* Translate 'pastetoggle' into special key names */
11927 else if ((char_u **)opp->var == &p_pt)
11928 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11929 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011930 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011931 }
11932}
11933
11934/*
11935 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11936 * printed as a keyname.
11937 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11938 */
11939 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011940wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011941{
11942 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11943 {
11944 *wcp = *(long *)varp;
11945 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11946 return TRUE;
11947 }
11948 return FALSE;
11949}
11950
Bram Moolenaar071d4272004-06-13 20:20:40 +000011951/*
11952 * Return TRUE if format option 'x' is in effect.
11953 * Take care of no formatting when 'paste' is set.
11954 */
11955 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011956has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011957{
11958 if (p_paste)
11959 return FALSE;
11960 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11961}
11962
11963/*
11964 * Return TRUE if "x" is present in 'shortmess' option, or
11965 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11966 */
11967 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011968shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011969{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011970 return p_shm != NULL &&
11971 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011972 || (vim_strchr(p_shm, 'a') != NULL
11973 && vim_strchr((char_u *)SHM_A, x) != NULL));
11974}
11975
11976/*
11977 * paste_option_changed() - Called after p_paste was set or reset.
11978 */
11979 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011980paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011981{
11982 static int old_p_paste = FALSE;
11983 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011984 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011985#ifdef FEAT_CMDL_INFO
11986 static int save_ru = 0;
11987#endif
11988#ifdef FEAT_RIGHTLEFT
11989 static int save_ri = 0;
11990 static int save_hkmap = 0;
11991#endif
11992 buf_T *buf;
11993
11994 if (p_paste)
11995 {
11996 /*
11997 * Paste switched from off to on.
11998 * Save the current values, so they can be restored later.
11999 */
12000 if (!old_p_paste)
12001 {
12002 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012003 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012004 {
12005 buf->b_p_tw_nopaste = buf->b_p_tw;
12006 buf->b_p_wm_nopaste = buf->b_p_wm;
12007 buf->b_p_sts_nopaste = buf->b_p_sts;
12008 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012009 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012010#ifdef FEAT_VARTABS
12011 if (buf->b_p_vsts_nopaste)
12012 vim_free(buf->b_p_vsts_nopaste);
12013 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12014 ? vim_strsave(buf->b_p_vsts) : NULL;
12015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012016 }
12017
12018 /* save global options */
12019 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012020 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012021#ifdef FEAT_CMDL_INFO
12022 save_ru = p_ru;
12023#endif
12024#ifdef FEAT_RIGHTLEFT
12025 save_ri = p_ri;
12026 save_hkmap = p_hkmap;
12027#endif
12028 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012029 p_ai_nopaste = p_ai;
12030 p_et_nopaste = p_et;
12031 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012032 p_tw_nopaste = p_tw;
12033 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012034#ifdef FEAT_VARTABS
12035 if (p_vsts_nopaste)
12036 vim_free(p_vsts_nopaste);
12037 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12038#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012039 }
12040
12041 /*
12042 * Always set the option values, also when 'paste' is set when it is
12043 * already on.
12044 */
12045 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012046 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012047 {
12048 buf->b_p_tw = 0; /* textwidth is 0 */
12049 buf->b_p_wm = 0; /* wrapmargin is 0 */
12050 buf->b_p_sts = 0; /* softtabstop is 0 */
12051 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012052 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012053#ifdef FEAT_VARTABS
12054 if (buf->b_p_vsts)
12055 free_string_option(buf->b_p_vsts);
12056 buf->b_p_vsts = empty_option;
12057 if (buf->b_p_vsts_array)
12058 vim_free(buf->b_p_vsts_array);
12059 buf->b_p_vsts_array = 0;
12060#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012061 }
12062
12063 /* set global options */
12064 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012065 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012066#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012067 if (p_ru)
12068 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012069 p_ru = 0; /* no ruler */
12070#endif
12071#ifdef FEAT_RIGHTLEFT
12072 p_ri = 0; /* no reverse insert */
12073 p_hkmap = 0; /* no Hebrew keyboard */
12074#endif
12075 /* set global values for local buffer options */
12076 p_tw = 0;
12077 p_wm = 0;
12078 p_sts = 0;
12079 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012080#ifdef FEAT_VARTABS
12081 if (p_vsts)
12082 free_string_option(p_vsts);
12083 p_vsts = empty_option;
12084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012085 }
12086
12087 /*
12088 * Paste switched from on to off: Restore saved values.
12089 */
12090 else if (old_p_paste)
12091 {
12092 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012093 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012094 {
12095 buf->b_p_tw = buf->b_p_tw_nopaste;
12096 buf->b_p_wm = buf->b_p_wm_nopaste;
12097 buf->b_p_sts = buf->b_p_sts_nopaste;
12098 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012099 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012100#ifdef FEAT_VARTABS
12101 if (buf->b_p_vsts)
12102 free_string_option(buf->b_p_vsts);
12103 buf->b_p_vsts = buf->b_p_vsts_nopaste
12104 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12105 if (buf->b_p_vsts_array)
12106 vim_free(buf->b_p_vsts_array);
12107 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12108 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12109 else
12110 buf->b_p_vsts_array = 0;
12111#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012112 }
12113
12114 /* restore global options */
12115 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012116 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012117#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012118 if (p_ru != save_ru)
12119 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012120 p_ru = save_ru;
12121#endif
12122#ifdef FEAT_RIGHTLEFT
12123 p_ri = save_ri;
12124 p_hkmap = save_hkmap;
12125#endif
12126 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012127 p_ai = p_ai_nopaste;
12128 p_et = p_et_nopaste;
12129 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012130 p_tw = p_tw_nopaste;
12131 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012132#ifdef FEAT_VARTABS
12133 if (p_vsts)
12134 free_string_option(p_vsts);
12135 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12136#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012137 }
12138
12139 old_p_paste = p_paste;
12140}
12141
12142/*
12143 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12144 *
12145 * Reset 'compatible' and set the values for options that didn't get set yet
12146 * to the Vim defaults.
12147 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012148 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012149 */
12150 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012151vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012152{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012153 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012154 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012155 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012156
12157 if (!option_was_set((char_u *)"cp"))
12158 {
12159 p_cp = FALSE;
12160 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12161 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12162 set_option_default(opt_idx, OPT_FREE, FALSE);
12163 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012164 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012165 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012166
12167 if (fname != NULL)
12168 {
12169 p = vim_getenv(envname, &dofree);
12170 if (p == NULL)
12171 {
12172 /* Set $MYVIMRC to the first vimrc file found. */
12173 p = FullName_save(fname, FALSE);
12174 if (p != NULL)
12175 {
12176 vim_setenv(envname, p);
12177 vim_free(p);
12178 }
12179 }
12180 else if (dofree)
12181 vim_free(p);
12182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012183}
12184
12185/*
12186 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12187 */
12188 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012189change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012190{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012191 int opt_idx;
12192
Bram Moolenaar071d4272004-06-13 20:20:40 +000012193 if (p_cp != on)
12194 {
12195 p_cp = on;
12196 compatible_set();
12197 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012198 opt_idx = findoption((char_u *)"cp");
12199 if (opt_idx >= 0)
12200 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012201}
12202
12203/*
12204 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012205 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012206 */
12207 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012208option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012209{
12210 int idx;
12211
12212 idx = findoption(name);
12213 if (idx < 0) /* unknown option */
12214 return FALSE;
12215 if (options[idx].flags & P_WAS_SET)
12216 return TRUE;
12217 return FALSE;
12218}
12219
12220/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012221 * Reset the flag indicating option "name" was set.
12222 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012223 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012224reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012225{
12226 int idx = findoption(name);
12227
12228 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012229 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012230 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012231 return OK;
12232 }
12233 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012234}
12235
12236/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012237 * compatible_set() - Called when 'compatible' has been set or unset.
12238 *
12239 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12240 * flag) to a Vi compatible value.
12241 * When 'compatible' is unset: Set all options that have a different default
12242 * for Vim (without the P_VI_DEF flag) to that default.
12243 */
12244 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012245compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012246{
12247 int opt_idx;
12248
12249 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12250 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12251 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12252 set_option_default(opt_idx, OPT_FREE, p_cp);
12253 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012254 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012255}
12256
12257#ifdef FEAT_LINEBREAK
12258
Bram Moolenaar071d4272004-06-13 20:20:40 +000012259/*
12260 * fill_breakat_flags() -- called when 'breakat' changes value.
12261 */
12262 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012263fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012264{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012265 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012266 int i;
12267
12268 for (i = 0; i < 256; i++)
12269 breakat_flags[i] = FALSE;
12270
12271 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012272 for (p = p_breakat; *p; p++)
12273 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012274}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012275#endif
12276
12277/*
12278 * Check an option that can be a range of string values.
12279 *
12280 * Return OK for correct value, FAIL otherwise.
12281 * Empty is always OK.
12282 */
12283 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012284check_opt_strings(
12285 char_u *val,
12286 char **values,
12287 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288{
12289 return opt_strings_flags(val, values, NULL, list);
12290}
12291
12292/*
12293 * Handle an option that can be a range of string values.
12294 * Set a flag in "*flagp" for each string present.
12295 *
12296 * Return OK for correct value, FAIL otherwise.
12297 * Empty is always OK.
12298 */
12299 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012300opt_strings_flags(
12301 char_u *val, /* new value */
12302 char **values, /* array of valid string values */
12303 unsigned *flagp,
12304 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012305{
12306 int i;
12307 int len;
12308 unsigned new_flags = 0;
12309
12310 while (*val)
12311 {
12312 for (i = 0; ; ++i)
12313 {
12314 if (values[i] == NULL) /* val not found in values[] */
12315 return FAIL;
12316
12317 len = (int)STRLEN(values[i]);
12318 if (STRNCMP(values[i], val, len) == 0
12319 && ((list && val[len] == ',') || val[len] == NUL))
12320 {
12321 val += len + (val[len] == ',');
12322 new_flags |= (1 << i);
12323 break; /* check next item in val list */
12324 }
12325 }
12326 }
12327 if (flagp != NULL)
12328 *flagp = new_flags;
12329
12330 return OK;
12331}
12332
12333/*
12334 * Read the 'wildmode' option, fill wim_flags[].
12335 */
12336 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012337check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012338{
12339 char_u new_wim_flags[4];
12340 char_u *p;
12341 int i;
12342 int idx = 0;
12343
12344 for (i = 0; i < 4; ++i)
12345 new_wim_flags[i] = 0;
12346
12347 for (p = p_wim; *p; ++p)
12348 {
12349 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12350 ;
12351 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12352 return FAIL;
12353 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12354 new_wim_flags[idx] |= WIM_LONGEST;
12355 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12356 new_wim_flags[idx] |= WIM_FULL;
12357 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12358 new_wim_flags[idx] |= WIM_LIST;
12359 else
12360 return FAIL;
12361 p += i;
12362 if (*p == NUL)
12363 break;
12364 if (*p == ',')
12365 {
12366 if (idx == 3)
12367 return FAIL;
12368 ++idx;
12369 }
12370 }
12371
12372 /* fill remaining entries with last flag */
12373 while (idx < 3)
12374 {
12375 new_wim_flags[idx + 1] = new_wim_flags[idx];
12376 ++idx;
12377 }
12378
12379 /* only when there are no errors, wim_flags[] is changed */
12380 for (i = 0; i < 4; ++i)
12381 wim_flags[i] = new_wim_flags[i];
12382 return OK;
12383}
12384
12385/*
12386 * Check if backspacing over something is allowed.
12387 */
12388 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012389can_bs(
12390 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012391{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012392#ifdef FEAT_JOB_CHANNEL
12393 if (what == BS_START && bt_prompt(curbuf))
12394 return FALSE;
12395#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012396 switch (*p_bs)
12397 {
12398 case '2': return TRUE;
12399 case '1': return (what != BS_START);
12400 case '0': return FALSE;
12401 }
12402 return vim_strchr(p_bs, what) != NULL;
12403}
12404
12405/*
12406 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12407 * the file must be considered changed when the value is different.
12408 */
12409 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012410save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012411{
12412 buf->b_start_ffc = *buf->b_p_ff;
12413 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012414 buf->b_start_bomb = buf->b_p_bomb;
12415
Bram Moolenaar071d4272004-06-13 20:20:40 +000012416 /* Only use free/alloc when necessary, they take time. */
12417 if (buf->b_start_fenc == NULL
12418 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12419 {
12420 vim_free(buf->b_start_fenc);
12421 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12422 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012423}
12424
12425/*
12426 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12427 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012428 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12429 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012430 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012431 * When "ignore_empty" is true don't consider a new, empty buffer to be
12432 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012433 */
12434 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012435file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012436{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012437 /* In a buffer that was never loaded the options are not valid. */
12438 if (buf->b_flags & BF_NEVERLOADED)
12439 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012440 if (ignore_empty
12441 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012442 && buf->b_ml.ml_line_count == 1
12443 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12444 return FALSE;
12445 if (buf->b_start_ffc != *buf->b_p_ff)
12446 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012447 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012448 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012449 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12450 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012451 if (buf->b_start_fenc == NULL)
12452 return (*buf->b_p_fenc != NUL);
12453 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012454}
12455
12456/*
12457 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12458 */
12459 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012460check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012461{
12462 return check_opt_strings(p, p_ff_values, FALSE);
12463}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012464
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012465/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010012466 * Return the effective 'scrolloff' value for the current window, using the
12467 * global value when appropriate.
12468 */
12469 long
12470get_scrolloff_value(void)
12471{
12472 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
12473}
12474
12475/*
12476 * Return the effective 'sidescrolloff' value for the current window, using the
12477 * global value when appropriate.
12478 */
12479 long
12480get_sidescrolloff_value(void)
12481{
12482 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
12483}
12484
12485/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012486 * Check matchpairs option for "*initc".
12487 * If there is a match set "*initc" to the matching character and "*findc" to
12488 * the opposite character. Set "*backwards" to the direction.
12489 * When "switchit" is TRUE swap the direction.
12490 */
12491 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012492find_mps_values(
12493 int *initc,
12494 int *findc,
12495 int *backwards,
12496 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012497{
12498 char_u *ptr;
12499
12500 ptr = curbuf->b_p_mps;
12501 while (*ptr != NUL)
12502 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012503 if (has_mbyte)
12504 {
12505 char_u *prev;
12506
12507 if (mb_ptr2char(ptr) == *initc)
12508 {
12509 if (switchit)
12510 {
12511 *findc = *initc;
12512 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12513 *backwards = TRUE;
12514 }
12515 else
12516 {
12517 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12518 *backwards = FALSE;
12519 }
12520 return;
12521 }
12522 prev = ptr;
12523 ptr += mb_ptr2len(ptr) + 1;
12524 if (mb_ptr2char(ptr) == *initc)
12525 {
12526 if (switchit)
12527 {
12528 *findc = *initc;
12529 *initc = mb_ptr2char(prev);
12530 *backwards = FALSE;
12531 }
12532 else
12533 {
12534 *findc = mb_ptr2char(prev);
12535 *backwards = TRUE;
12536 }
12537 return;
12538 }
12539 ptr += mb_ptr2len(ptr);
12540 }
12541 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012542 {
12543 if (*ptr == *initc)
12544 {
12545 if (switchit)
12546 {
12547 *backwards = TRUE;
12548 *findc = *initc;
12549 *initc = ptr[2];
12550 }
12551 else
12552 {
12553 *backwards = FALSE;
12554 *findc = ptr[2];
12555 }
12556 return;
12557 }
12558 ptr += 2;
12559 if (*ptr == *initc)
12560 {
12561 if (switchit)
12562 {
12563 *backwards = FALSE;
12564 *findc = *initc;
12565 *initc = ptr[-2];
12566 }
12567 else
12568 {
12569 *backwards = TRUE;
12570 *findc = ptr[-2];
12571 }
12572 return;
12573 }
12574 ++ptr;
12575 }
12576 if (*ptr == ',')
12577 ++ptr;
12578 }
12579}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012580
12581#if defined(FEAT_LINEBREAK) || defined(PROTO)
12582/*
12583 * This is called when 'breakindentopt' is changed and when a window is
12584 * initialized.
12585 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012586 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012587briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012588{
12589 char_u *p;
12590 int bri_shift = 0;
12591 long bri_min = 20;
12592 int bri_sbr = FALSE;
12593
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012594 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012595 while (*p != NUL)
12596 {
12597 if (STRNCMP(p, "shift:", 6) == 0
12598 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12599 {
12600 p += 6;
12601 bri_shift = getdigits(&p);
12602 }
12603 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12604 {
12605 p += 4;
12606 bri_min = getdigits(&p);
12607 }
12608 else if (STRNCMP(p, "sbr", 3) == 0)
12609 {
12610 p += 3;
12611 bri_sbr = TRUE;
12612 }
12613 if (*p != ',' && *p != NUL)
12614 return FAIL;
12615 if (*p == ',')
12616 ++p;
12617 }
12618
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012619 wp->w_p_brishift = bri_shift;
12620 wp->w_p_brimin = bri_min;
12621 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012622
12623 return OK;
12624}
12625#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012626
12627/*
12628 * Get the local or global value of 'backupcopy'.
12629 */
12630 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012631get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012632{
12633 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12634}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012635
12636#if defined(FEAT_SIGNS) || defined(PROTO)
12637/*
12638 * Return TRUE when window "wp" has a column to draw signs in.
12639 */
12640 int
12641signcolumn_on(win_T *wp)
12642{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020012643 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
12644 // column (if present). Otherwise signs are to be displayed in the sign
12645 // column.
12646 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
12647 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
12648
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012649 if (*wp->w_p_scl == 'n')
12650 return FALSE;
12651 if (*wp->w_p_scl == 'y')
12652 return TRUE;
12653 return (wp->w_buffer->b_signlist != NULL
12654# ifdef FEAT_NETBEANS_INTG
12655 || wp->w_buffer->b_has_sign_column
12656# endif
12657 );
12658}
12659#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012660
12661#if defined(FEAT_EVAL) || defined(PROTO)
12662/*
12663 * Get window or buffer local options.
12664 */
12665 dict_T *
12666get_winbuf_options(int bufopt)
12667{
12668 dict_T *d;
12669 int opt_idx;
12670
12671 d = dict_alloc();
12672 if (d == NULL)
12673 return NULL;
12674
12675 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12676 {
12677 struct vimoption *opt = &options[opt_idx];
12678
12679 if ((bufopt && (opt->indir & PV_BUF))
12680 || (!bufopt && (opt->indir & PV_WIN)))
12681 {
12682 char_u *varp = get_varp(opt);
12683
12684 if (varp != NULL)
12685 {
12686 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020012687 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012688 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020012689 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012690 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020012691 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012692 }
12693 }
12694 }
12695
12696 return d;
12697}
12698#endif