blob: 907036411504754ca45040bb2ded68e57a5fcbb9 [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 Moolenaar410e98a2019-09-09 22:05:49 +0200241# define PV_CULOPT OPT_WIN(WV_CULOPT)
Bram Moolenaar1a384422010-07-14 19:53:30 +0200242# define PV_CC OPT_WIN(WV_CC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000243#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000244#ifdef FEAT_STL_OPT
245# define PV_STL OPT_BOTH(OPT_WIN(WV_STL))
246#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +0100247#define PV_UL OPT_BOTH(OPT_BUF(BV_UL))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000248# define PV_WFH OPT_WIN(WV_WFH)
Bram Moolenaar97b2ad32006-03-18 21:40:56 +0000249# define PV_WFW OPT_WIN(WV_WFW)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000250#define PV_WRAP OPT_WIN(WV_WRAP)
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100251#define PV_CRBIND OPT_WIN(WV_CRBIND)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200252#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200253# define PV_COCU OPT_WIN(WV_COCU)
254# define PV_COLE OPT_WIN(WV_COLE)
Bram Moolenaar860cae12010-06-05 23:22:07 +0200255#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200256#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200257# define PV_TWK OPT_WIN(WV_TWK)
258# define PV_TWS OPT_WIN(WV_TWS)
259# define PV_TWSL OPT_BUF(BV_TWSL)
Bram Moolenaare4f25e42017-07-07 11:54:15 +0200260#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +0200261#ifdef FEAT_SIGNS
262# define PV_SCL OPT_WIN(WV_SCL)
263#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000264
265/* WV_ and BV_ values get typecasted to this for the "indir" field */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000266typedef enum
267{
Bram Moolenaar7d96acd2008-06-09 15:07:54 +0000268 PV_NONE = 0,
269 PV_MAXVAL = 0xffff /* to avoid warnings for value out of range */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000270} idopt_T;
271
272/*
273 * Options local to a window have a value local to a buffer and global to all
274 * buffers. Indicate this by setting "var" to VAR_WIN.
275 */
276#define VAR_WIN ((char_u *)-1)
277
278/*
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000279 * These are the global values for options which are also local to a buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000280 * Only to be used in option.c!
281 */
282static int p_ai;
283static int p_bin;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000284static int p_bomb;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285static char_u *p_bh;
286static char_u *p_bt;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287static int p_bl;
288static int p_ci;
289#ifdef FEAT_CINDENT
290static int p_cin;
291static char_u *p_cink;
292static char_u *p_cino;
293#endif
294#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
295static char_u *p_cinw;
296#endif
297#ifdef FEAT_COMMENTS
298static char_u *p_com;
299#endif
300#ifdef FEAT_FOLDING
301static char_u *p_cms;
302#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000303static char_u *p_cpt;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000304#ifdef FEAT_COMPL_FUNC
305static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000306static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000307#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200308#ifdef FEAT_EVAL
309static char_u *p_tfu;
310#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200312static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000314static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static char_u *p_ff;
316static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000317static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000318static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000319static long p_iminsert;
320static long p_imsearch;
321#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
322static char_u *p_inex;
323#endif
324#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
325static char_u *p_inde;
326static char_u *p_indk;
327#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000328#if defined(FEAT_EVAL)
329static char_u *p_fex;
330#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000331static int p_inf;
332static char_u *p_isk;
333#ifdef FEAT_CRYPT
334static char_u *p_key;
335#endif
336#ifdef FEAT_LISP
337static int p_lisp;
338#endif
339static int p_ml;
340static int p_ma;
341static int p_mod;
342static char_u *p_mps;
343static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000344static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000345#ifdef FEAT_TEXTOBJ
346static char_u *p_qe;
347#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000348static int p_ro;
349#ifdef FEAT_SMARTINDENT
350static int p_si;
351#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000352static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000353static long p_sts;
354#if defined(FEAT_SEARCHPATH)
355static char_u *p_sua;
356#endif
357static long p_sw;
358static int p_swf;
359#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000360static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000362#endif
363#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000364static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000365static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000366static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000367#endif
368static long p_ts;
369static long p_tw;
370static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200371#ifdef FEAT_PERSISTENT_UNDO
372static int p_udf;
373#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000374static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200375#ifdef FEAT_VARTABS
376static char_u *p_vsts;
377static char_u *p_vts;
378#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000379#ifdef FEAT_KEYMAP
380static char_u *p_keymap;
381#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200382#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200383static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200384#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000385
386/* Saved values for when 'bin' is set. */
387static int p_et_nobin;
388static int p_ml_nobin;
389static long p_tw_nobin;
390static long p_wm_nobin;
391
392/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200393static int p_ai_nopaste;
394static int p_et_nopaste;
395static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000396static long p_tw_nopaste;
397static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200398#ifdef FEAT_VARTABS
399static char_u *p_vsts_nopaste;
400#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000401
402struct vimoption
403{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200404 char *fullname; // full option name
405 char *shortname; // permissible abbreviation
406 long_u flags; // see below
407 char_u *var; // global option: pointer to variable;
408 // window-local option: VAR_WIN;
409 // buffer-local option: global value
410 idopt_T indir; // global option: PV_NONE;
411 // local option: indirect option index
412 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000413#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200414 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaar558ca4a2019-04-04 18:15:38 +0200415# define SCTX_INIT , {0, 0, 0, 1}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000416#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200417# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000418#endif
419};
420
421#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
422#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
423
424/*
425 * Flags
426 */
427#define P_BOOL 0x01 /* the option is boolean */
428#define P_NUM 0x02 /* the option is numeric */
429#define P_STRING 0x04 /* the option is a string */
430#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000431 must use free_string_option() when
432 assigning new value. Not set if default is
433 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000434#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
435 never be used for local or hidden options! */
436#define P_NODEFAULT 0x40 /* don't set to default value */
437#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
438 use vim_free() when assigning new value */
439#define P_WAS_SET 0x100 /* option has been set/reset */
440#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
441#define P_VI_DEF 0x400 /* Use Vi default for Vim */
442#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
443
444 /* when option changed, what to display: */
445#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100446#define P_RWIN 0x2000 /* redraw current window and recompute text */
447#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000448#define P_RALL 0x6000 /* redraw all windows */
449#define P_RCLR 0x7000 /* clear and redraw all */
450
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200451#define P_COMMA 0x8000 /* comma separated list */
452#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
453 * commas */
454#define P_NODUP 0x20000L /* don't allow duplicate strings */
455#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000456
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200457#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
458#define P_GETTEXT 0x100000L /* expand default value with _() */
459#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
460#define P_NFNAME 0x400000L /* only normal file name chars allowed */
461#define P_INSECURE 0x800000L /* option was set from a modeline */
462#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100463 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200464#define P_NO_ML 0x2000000L /* not allowed in modeline */
465#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200466 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100467#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100468#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar110289e2019-05-23 15:38:06 +0200469#define P_MLE 0x20000000L /* under control of 'modelineexpr' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000470
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000471#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
472
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000473/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
474 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100475#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000476# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000477#else
478# define ISP_LATIN1 (char_u *)"@,161-255"
479#endif
480
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200481# define HIGHLIGHT_INIT "8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn,q:QuickFixLine,z:StatusLineTerm,Z:StatusLineTermNC"
Bram Moolenaar3991dab2006-03-27 17:01:56 +0000482
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100483/* Default python version for pyx* commands */
484#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
485# define DEFAULT_PYTHON_VER 0
486#elif defined(FEAT_PYTHON3)
487# define DEFAULT_PYTHON_VER 3
488#elif defined(FEAT_PYTHON)
489# define DEFAULT_PYTHON_VER 2
490#else
491# define DEFAULT_PYTHON_VER 0
492#endif
493
Bram Moolenaarce655742019-01-31 14:12:57 +0100494// used for 'cinkeys' and 'indentkeys'
495#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
496
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497/*
498 * options[] is initialized here.
499 * The order of the options MUST be alphabetic for ":set all" and findoption().
500 * All option names MUST start with a lowercase letter (for findoption()).
501 * Exception: "t_" options are at the end.
502 * The options with a NULL variable are 'hidden': a set command for them is
503 * ignored and they are not printed.
504 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100505static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000506{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200507 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508#ifdef FEAT_RIGHTLEFT
509 (char_u *)&p_aleph, PV_NONE,
510#else
511 (char_u *)NULL, PV_NONE,
512#endif
513 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100514#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000515 (char_u *)128L,
516#else
517 (char_u *)224L,
518#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200519 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200521#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 (char_u *)&p_antialias, PV_NONE,
523 {(char_u *)FALSE, (char_u *)FALSE}
524#else
525 (char_u *)NULL, PV_NONE,
526 {(char_u *)FALSE, (char_u *)FALSE}
527#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200528 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200529 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530#ifdef FEAT_ARABIC
531 (char_u *)VAR_WIN, PV_ARAB,
532#else
533 (char_u *)NULL, PV_NONE,
534#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200535 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000536 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
537#ifdef FEAT_ARABIC
538 (char_u *)&p_arshape, PV_NONE,
539#else
540 (char_u *)NULL, PV_NONE,
541#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200542 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000543 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
544#ifdef FEAT_RIGHTLEFT
545 (char_u *)&p_ari, PV_NONE,
546#else
547 (char_u *)NULL, PV_NONE,
548#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200549 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000550 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000551 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200552 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000554 (char_u *)&p_ambw, PV_NONE,
555 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200556 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000557 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100558#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100560 {(char_u *)FALSE, (char_u *)0L}
561#else
562 (char_u *)NULL, PV_NONE,
563 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000564#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200565 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566 {"autoindent", "ai", P_BOOL|P_VI_DEF,
567 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200568 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000569 {"autoprint", "ap", P_BOOL|P_VI_DEF,
570 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200571 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000572 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000573 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200574 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000575 {"autowrite", "aw", P_BOOL|P_VI_DEF,
576 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200577 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000578 {"autowriteall","awa", P_BOOL|P_VI_DEF,
579 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200580 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000581 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
582 (char_u *)&p_bg, PV_NONE,
583 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100584#if (defined(MSWIN)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000585 (char_u *)"dark",
586#else
587 (char_u *)"light",
588#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200589 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200590 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000591 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200592 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
594 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200595 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200596 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200597 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000598#ifdef UNIX
599 {(char_u *)"yes", (char_u *)"auto"}
600#else
601 {(char_u *)"auto", (char_u *)"auto"}
602#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200603 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200604 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
605 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200607 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000608 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000609 (char_u *)&p_bex, PV_NONE,
610 {
611#ifdef VMS
612 (char_u *)"_",
613#else
614 (char_u *)"~",
615#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200616 (char_u *)0L} SCTX_INIT},
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200617 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000618#ifdef FEAT_WILDIGN
619 (char_u *)&p_bsk, PV_NONE,
620 {(char_u *)"", (char_u *)0L}
621#else
622 (char_u *)NULL, PV_NONE,
623 {(char_u *)0L, (char_u *)0L}
624#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200625 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000626 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100627#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100629 {(char_u *)600L, (char_u *)0L}
630#else
631 (char_u *)NULL, PV_NONE,
632 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000633#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200634 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100635 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100636#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100637 (char_u *)&p_beval, PV_NONE,
638 {(char_u *)FALSE, (char_u *)0L}
639#else
640 (char_u *)NULL, PV_NONE,
641 {(char_u *)0L, (char_u *)0L}
642#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200643 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100644 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100645#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100646 (char_u *)&p_bevalterm, PV_NONE,
647 {(char_u *)FALSE, (char_u *)0L}
648#else
649 (char_u *)NULL, PV_NONE,
650 {(char_u *)0L, (char_u *)0L}
651#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200652 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200653 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100654#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
655 (char_u *)&p_bexpr, PV_BEXPR,
656 {(char_u *)"", (char_u *)0L}
657#else
658 (char_u *)NULL, PV_NONE,
659 {(char_u *)0L, (char_u *)0L}
660#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200661 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000662 {"beautify", "bf", P_BOOL|P_VI_DEF,
663 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200664 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200665 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
666 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200667 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000668 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
669 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200670 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000672 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200673 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000675 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200676 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
678#ifdef FEAT_LINEBREAK
679 (char_u *)&p_breakat, PV_NONE,
680 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
681#else
682 (char_u *)NULL, PV_NONE,
683 {(char_u *)0L, (char_u *)0L}
684#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200685 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200686 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
687#ifdef FEAT_LINEBREAK
688 (char_u *)VAR_WIN, PV_BRI,
689 {(char_u *)FALSE, (char_u *)0L}
690#else
691 (char_u *)NULL, PV_NONE,
692 {(char_u *)0L, (char_u *)0L}
693#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200694 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200695 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
696 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200697#ifdef FEAT_LINEBREAK
698 (char_u *)VAR_WIN, PV_BRIOPT,
699 {(char_u *)"", (char_u *)NULL}
700#else
701 (char_u *)NULL, PV_NONE,
702 {(char_u *)"", (char_u *)NULL}
703#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200704 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000705 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
706#ifdef FEAT_BROWSE
707 (char_u *)&p_bsdir, PV_NONE,
708 {(char_u *)"last", (char_u *)0L}
709#else
710 (char_u *)NULL, PV_NONE,
711 {(char_u *)0L, (char_u *)0L}
712#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200713 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000714 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 (char_u *)&p_bh, PV_BH,
716 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200717 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000718 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
719 (char_u *)&p_bl, PV_BL,
720 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200721 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000722 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000723 (char_u *)&p_bt, PV_BT,
724 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200725 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200726 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 (char_u *)&p_cmp, PV_NONE,
728 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200729 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200730 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000731#ifdef FEAT_SEARCHPATH
732 (char_u *)&p_cdpath, PV_NONE,
733 {(char_u *)",,", (char_u *)0L}
734#else
735 (char_u *)NULL, PV_NONE,
736 {(char_u *)0L, (char_u *)0L}
737#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200738 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000739 {"cedit", NULL, P_STRING,
740#ifdef FEAT_CMDWIN
741 (char_u *)&p_cedit, PV_NONE,
742 {(char_u *)"", (char_u *)CTRL_F_STR}
743#else
744 (char_u *)NULL, PV_NONE,
745 {(char_u *)0L, (char_u *)0L}
746#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200747 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000748 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100749#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 (char_u *)&p_ccv, PV_NONE,
751 {(char_u *)"", (char_u *)0L}
752#else
753 (char_u *)NULL, PV_NONE,
754 {(char_u *)0L, (char_u *)0L}
755#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200756 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000757 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
758#ifdef FEAT_CINDENT
759 (char_u *)&p_cin, PV_CIN,
760#else
761 (char_u *)NULL, PV_NONE,
762#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200763 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200764 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000765#ifdef FEAT_CINDENT
766 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100767 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000768#else
769 (char_u *)NULL, PV_NONE,
770 {(char_u *)0L, (char_u *)0L}
771#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200772 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200773 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774#ifdef FEAT_CINDENT
775 (char_u *)&p_cino, PV_CINO,
776#else
777 (char_u *)NULL, PV_NONE,
778#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200779 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200780 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000781#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
782 (char_u *)&p_cinw, PV_CINW,
783 {(char_u *)"if,else,while,do,for,switch",
784 (char_u *)0L}
785#else
786 (char_u *)NULL, PV_NONE,
787 {(char_u *)0L, (char_u *)0L}
788#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200789 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200790 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000791#ifdef FEAT_CLIPBOARD
792 (char_u *)&p_cb, PV_NONE,
793# ifdef FEAT_XCLIPBOARD
794 {(char_u *)"autoselect,exclude:cons\\|linux",
795 (char_u *)0L}
796# else
797 {(char_u *)"", (char_u *)0L}
798# endif
799#else
800 (char_u *)NULL, PV_NONE,
801 {(char_u *)"", (char_u *)0L}
802#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200803 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000804 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
805 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200806 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000807 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
808#ifdef FEAT_CMDWIN
809 (char_u *)&p_cwh, PV_NONE,
810#else
811 (char_u *)NULL, PV_NONE,
812#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200813 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200814 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200815#ifdef FEAT_SYN_HL
816 (char_u *)VAR_WIN, PV_CC,
817#else
818 (char_u *)NULL, PV_NONE,
819#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200820 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000821 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
822 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200823 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200824 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
825 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000826#ifdef FEAT_COMMENTS
827 (char_u *)&p_com, PV_COM,
828 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
829 (char_u *)0L}
830#else
831 (char_u *)NULL, PV_NONE,
832 {(char_u *)0L, (char_u *)0L}
833#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200834 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200835 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000836#ifdef FEAT_FOLDING
837 (char_u *)&p_cms, PV_CMS,
838 {(char_u *)"/*%s*/", (char_u *)0L}
839#else
840 (char_u *)NULL, PV_NONE,
841 {(char_u *)0L, (char_u *)0L}
842#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200843 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000844 /* P_PRI_MKRC isn't needed here, optval_default()
845 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846 {"compatible", "cp", P_BOOL|P_RALL,
847 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200848 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200849 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000850 (char_u *)&p_cpt, PV_CPT,
851 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200852 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200853 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200854#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200855 (char_u *)VAR_WIN, PV_COCU,
856 {(char_u *)"", (char_u *)NULL}
857#else
858 (char_u *)NULL, PV_NONE,
859 {(char_u *)NULL, (char_u *)0L}
860#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200861 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200862 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
863#ifdef FEAT_CONCEAL
864 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200865#else
866 (char_u *)NULL, PV_NONE,
867#endif
868 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200869 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000870 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
871#ifdef FEAT_COMPL_FUNC
872 (char_u *)&p_cfu, PV_CFU,
873 {(char_u *)"", (char_u *)0L}
874#else
875 (char_u *)NULL, PV_NONE,
876 {(char_u *)0L, (char_u *)0L}
877#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200878 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200879 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000880 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000881 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200882 SCTX_INIT},
Bram Moolenaar62a0cb42019-08-18 16:35:23 +0200883 {"completepopup", "cpp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar36e4d982019-08-20 21:12:16 +0200884#if defined(FEAT_TEXT_PROP) && defined(FEAT_QUICKFIX)
Bram Moolenaar62a0cb42019-08-18 16:35:23 +0200885 (char_u *)&p_cpp, PV_NONE,
886 {(char_u *)"", (char_u *)0L}
887#else
888 (char_u *)NULL, PV_NONE,
889 {(char_u *)NULL, (char_u *)0L}
890#endif
891 SCTX_INIT},
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200892 {"completeslash", "csl", P_STRING|P_VI_DEF|P_VIM,
Bram Moolenaare2c453d2019-08-21 14:37:09 +0200893#if defined(BACKSLASH_IN_FILENAME)
Bram Moolenaarac3150d2019-07-28 16:36:39 +0200894 (char_u *)&p_csl, PV_CSL,
895 {(char_u *)"", (char_u *)0L}
896#else
897 (char_u *)NULL, PV_NONE,
898 {(char_u *)0L, (char_u *)0L}
899#endif
900 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000901 {"confirm", "cf", P_BOOL|P_VI_DEF,
902#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
903 (char_u *)&p_confirm, PV_NONE,
904#else
905 (char_u *)NULL, PV_NONE,
906#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200907 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000909 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200910 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000911 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
912 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200913 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
915 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000916 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200917 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200918 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200919#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200920 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100921 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200922#else
923 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200924 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200925#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200926 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000927 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
928#ifdef FEAT_CSCOPE
929 (char_u *)&p_cspc, PV_NONE,
930#else
931 (char_u *)NULL, PV_NONE,
932#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200933 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000934 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
935#ifdef FEAT_CSCOPE
936 (char_u *)&p_csprg, PV_NONE,
937 {(char_u *)"cscope", (char_u *)0L}
938#else
939 (char_u *)NULL, PV_NONE,
940 {(char_u *)0L, (char_u *)0L}
941#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200942 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200943 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
945 (char_u *)&p_csqf, PV_NONE,
946 {(char_u *)"", (char_u *)0L}
947#else
948 (char_u *)NULL, PV_NONE,
949 {(char_u *)0L, (char_u *)0L}
950#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200951 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200952 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
953#ifdef FEAT_CSCOPE
954 (char_u *)&p_csre, PV_NONE,
955#else
956 (char_u *)NULL, PV_NONE,
957#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200958 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000959 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
960#ifdef FEAT_CSCOPE
961 (char_u *)&p_cst, PV_NONE,
962#else
963 (char_u *)NULL, PV_NONE,
964#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200965 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000966 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
967#ifdef FEAT_CSCOPE
968 (char_u *)&p_csto, PV_NONE,
969#else
970 (char_u *)NULL, PV_NONE,
971#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200972 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000973 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
974#ifdef FEAT_CSCOPE
975 (char_u *)&p_csverbose, PV_NONE,
976#else
977 (char_u *)NULL, PV_NONE,
978#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200979 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200980 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200981 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200982 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100983 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000984#ifdef FEAT_SYN_HL
985 (char_u *)VAR_WIN, PV_CUC,
986#else
987 (char_u *)NULL, PV_NONE,
988#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200989 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100990 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000991#ifdef FEAT_SYN_HL
992 (char_u *)VAR_WIN, PV_CUL,
993#else
994 (char_u *)NULL, PV_NONE,
995#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200996 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar410e98a2019-09-09 22:05:49 +0200997 {"cursorlineopt", "culopt", P_STRING|P_VI_DEF|P_RWIN,
998#ifdef FEAT_SYN_HL
999 (char_u *)VAR_WIN, PV_CULOPT,
1000#else
1001 (char_u *)NULL, PV_NONE,
1002#endif
1003 {(char_u *)"both", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 {"debug", NULL, P_STRING|P_VI_DEF,
1005 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001006 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001007 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001008#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001009 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +00001010 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001011#else
1012 (char_u *)NULL, PV_NONE,
1013 {(char_u *)NULL, (char_u *)0L}
1014#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001015 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001016 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001017 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001018 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001019 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001020 (char_u *)&p_dict, PV_DICT,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001021 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001022 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1023#ifdef FEAT_DIFF
1024 (char_u *)VAR_WIN, PV_DIFF,
1025#else
1026 (char_u *)NULL, PV_NONE,
1027#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001028 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001029 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001030#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1031 (char_u *)&p_dex, PV_NONE,
1032 {(char_u *)"", (char_u *)0L}
1033#else
1034 (char_u *)NULL, PV_NONE,
1035 {(char_u *)0L, (char_u *)0L}
1036#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001037 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001038 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1039 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001040#ifdef FEAT_DIFF
1041 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001042 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001043#else
1044 (char_u *)NULL, PV_NONE,
1045 {(char_u *)"", (char_u *)NULL}
1046#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001047 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1049#ifdef FEAT_DIGRAPHS
1050 (char_u *)&p_dg, PV_NONE,
1051#else
1052 (char_u *)NULL, PV_NONE,
1053#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001054 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001055 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1056 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001058 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001059 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001060 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001061 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001062 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001063 (char_u *)&p_ead, PV_NONE,
1064 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001065 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001066 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1067 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001068 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001069 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001070 (char_u *)&p_emoji, PV_NONE,
1071 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001072 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001073 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 (char_u *)&p_enc, PV_NONE,
1075 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001076 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1078 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001079 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1081 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001082 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001084 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001085 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001086 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1087 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001088 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1090#ifdef FEAT_QUICKFIX
1091 (char_u *)&p_ef, PV_NONE,
1092 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1093#else
1094 (char_u *)NULL, PV_NONE,
1095 {(char_u *)NULL, (char_u *)0L}
1096#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001097 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001098 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001100 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001101 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102#else
1103 (char_u *)NULL, PV_NONE,
1104 {(char_u *)NULL, (char_u *)0L}
1105#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001106 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"esckeys", "ek", P_BOOL|P_VIM,
1108 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001109 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001110 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001111 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001112 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001113 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1114 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001115 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1117 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001118 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001119 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1120 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 (char_u *)&p_fenc, PV_FENC,
1122 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001123 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001124 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001125 (char_u *)&p_fencs, PV_NONE,
1126 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001127 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001128 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1129 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001130 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001131 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001132 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001133 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001134 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001135 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001136 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1137 (char_u *)&p_fic, PV_NONE,
1138 {
1139#ifdef CASE_INSENSITIVE_FILENAME
1140 (char_u *)TRUE,
1141#else
1142 (char_u *)FALSE,
1143#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001144 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001145 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146 (char_u *)&p_ft, PV_FT,
1147 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001148 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001149 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 (char_u *)&p_fcs, PV_NONE,
1151 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001152 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001153 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1154 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001155 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001156 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001158 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 {"flash", "fl", P_BOOL|P_VI_DEF,
1160 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001161 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001162 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001163#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001164 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001165 {(char_u *)"", (char_u *)0L}
1166#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001167 (char_u *)NULL, PV_NONE,
1168 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001169#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001170 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001171 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1172#ifdef FEAT_FOLDING
1173 (char_u *)VAR_WIN, PV_FDC,
1174 {(char_u *)FALSE, (char_u *)0L}
1175#else
1176 (char_u *)NULL, PV_NONE,
1177 {(char_u *)NULL, (char_u *)0L}
1178#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001179 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001180 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1181#ifdef FEAT_FOLDING
1182 (char_u *)VAR_WIN, PV_FEN,
1183 {(char_u *)TRUE, (char_u *)0L}
1184#else
1185 (char_u *)NULL, PV_NONE,
1186 {(char_u *)NULL, (char_u *)0L}
1187#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001188 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001189 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001190#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1191 (char_u *)VAR_WIN, PV_FDE,
1192 {(char_u *)"0", (char_u *)NULL}
1193#else
1194 (char_u *)NULL, PV_NONE,
1195 {(char_u *)NULL, (char_u *)0L}
1196#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001197 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001198 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001199#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001200 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001201 {(char_u *)"#", (char_u *)NULL}
1202#else
1203 (char_u *)NULL, PV_NONE,
1204 {(char_u *)NULL, (char_u *)0L}
1205#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001206 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001207 {"foldlevel", "fdl", P_NUM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001208#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 (char_u *)VAR_WIN, PV_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001210 {(char_u *)0L, (char_u *)0L}
1211#else
1212 (char_u *)NULL, PV_NONE,
1213 {(char_u *)NULL, (char_u *)0L}
1214#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001215 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001216 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001217#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001218 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001219 {(char_u *)-1L, (char_u *)0L}
1220#else
1221 (char_u *)NULL, PV_NONE,
1222 {(char_u *)NULL, (char_u *)0L}
1223#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001224 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001225 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001226 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001227#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001229 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001230#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001233#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001234 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001235 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1236#ifdef FEAT_FOLDING
1237 (char_u *)VAR_WIN, PV_FDM,
1238 {(char_u *)"manual", (char_u *)NULL}
1239#else
1240 (char_u *)NULL, PV_NONE,
1241 {(char_u *)NULL, (char_u *)0L}
1242#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001243 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001244 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1245#ifdef FEAT_FOLDING
1246 (char_u *)VAR_WIN, PV_FML,
1247 {(char_u *)1L, (char_u *)0L}
1248#else
1249 (char_u *)NULL, PV_NONE,
1250 {(char_u *)NULL, (char_u *)0L}
1251#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001252 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001253 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1254#ifdef FEAT_FOLDING
1255 (char_u *)VAR_WIN, PV_FDN,
1256 {(char_u *)20L, (char_u *)0L}
1257#else
1258 (char_u *)NULL, PV_NONE,
1259 {(char_u *)NULL, (char_u *)0L}
1260#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001261 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001262 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1263#ifdef FEAT_FOLDING
1264 (char_u *)&p_fdo, PV_NONE,
1265 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1266 (char_u *)0L}
1267#else
1268 (char_u *)NULL, PV_NONE,
1269 {(char_u *)NULL, (char_u *)0L}
1270#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001271 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001272 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001273#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1274 (char_u *)VAR_WIN, PV_FDT,
1275 {(char_u *)"foldtext()", (char_u *)NULL}
1276#else
1277 (char_u *)NULL, PV_NONE,
1278 {(char_u *)NULL, (char_u *)0L}
1279#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001280 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001281 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001282#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001283 (char_u *)&p_fex, PV_FEX,
1284 {(char_u *)"", (char_u *)0L}
1285#else
1286 (char_u *)NULL, PV_NONE,
1287 {(char_u *)0L, (char_u *)0L}
1288#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001289 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1291 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001292 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001293 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001294 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1295 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001296 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001297 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001298 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001299 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001300 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001301 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1302#ifdef HAVE_FSYNC
1303 (char_u *)&p_fs, PV_NONE,
1304 {(char_u *)TRUE, (char_u *)0L}
1305#else
1306 (char_u *)NULL, PV_NONE,
1307 {(char_u *)FALSE, (char_u *)0L}
1308#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001309 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001310 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1311 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001312 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001313 {"graphic", "gr", P_BOOL|P_VI_DEF,
1314 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001315 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001316 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001317#ifdef FEAT_QUICKFIX
1318 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001319 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001320#else
1321 (char_u *)NULL, PV_NONE,
1322 {(char_u *)NULL, (char_u *)0L}
1323#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001324 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001325 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1326#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001327 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001328 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001329# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001330 /* may be changed to "grep -n" in os_win32.c */
1331 (char_u *)"findstr /n",
1332# else
1333# ifdef UNIX
1334 /* Add an extra file name so that grep will always
1335 * insert a file name in the match line. */
1336 (char_u *)"grep -n $* /dev/null",
1337# else
1338# ifdef VMS
1339 (char_u *)"SEARCH/NUMBERS ",
1340# else
1341 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001342# endif
1343# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001344# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001345 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001346#else
1347 (char_u *)NULL, PV_NONE,
1348 {(char_u *)NULL, (char_u *)0L}
1349#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001350 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001351 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001352#ifdef CURSOR_SHAPE
1353 (char_u *)&p_guicursor, PV_NONE,
1354 {
1355# ifdef FEAT_GUI
1356 (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 +01001357# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1359# endif
1360 (char_u *)0L}
1361#else
1362 (char_u *)NULL, PV_NONE,
1363 {(char_u *)NULL, (char_u *)0L}
1364#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001365 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001366 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367#ifdef FEAT_GUI
1368 (char_u *)&p_guifont, PV_NONE,
1369 {(char_u *)"", (char_u *)0L}
1370#else
1371 (char_u *)NULL, PV_NONE,
1372 {(char_u *)NULL, (char_u *)0L}
1373#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001374 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001375 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001376#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1377 (char_u *)&p_guifontset, PV_NONE,
1378 {(char_u *)"", (char_u *)0L}
1379#else
1380 (char_u *)NULL, PV_NONE,
1381 {(char_u *)NULL, (char_u *)0L}
1382#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001383 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001384 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001385#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 (char_u *)&p_guifontwide, PV_NONE,
1387 {(char_u *)"", (char_u *)0L}
1388#else
1389 (char_u *)NULL, PV_NONE,
1390 {(char_u *)NULL, (char_u *)0L}
1391#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001392 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001394#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001395 (char_u *)&p_ghr, PV_NONE,
1396#else
1397 (char_u *)NULL, PV_NONE,
1398#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001399 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001400 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001401#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001402 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001403# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001404 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001405# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001406 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001407# endif
1408#else
1409 (char_u *)NULL, PV_NONE,
1410 {(char_u *)NULL, (char_u *)0L}
1411#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001412 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001413 {"guipty", NULL, P_BOOL|P_VI_DEF,
1414#if defined(FEAT_GUI)
1415 (char_u *)&p_guipty, PV_NONE,
1416#else
1417 (char_u *)NULL, PV_NONE,
1418#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001419 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001420 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001421#if defined(FEAT_GUI_TABLINE)
1422 (char_u *)&p_gtl, PV_NONE,
1423 {(char_u *)"", (char_u *)0L}
1424#else
1425 (char_u *)NULL, PV_NONE,
1426 {(char_u *)NULL, (char_u *)0L}
1427#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001428 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001429 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001430#if defined(FEAT_GUI_TABLINE)
1431 (char_u *)&p_gtt, PV_NONE,
1432 {(char_u *)"", (char_u *)0L}
1433#else
1434 (char_u *)NULL, PV_NONE,
1435 {(char_u *)NULL, (char_u *)0L}
1436#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001437 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001438 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1439 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001440 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001441 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1442 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001443 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001444 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001445 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001446 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001447 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001448 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001449#ifdef FEAT_MULTI_LANG
1450 (char_u *)&p_hlg, PV_NONE,
1451 {(char_u *)"", (char_u *)0L}
1452#else
1453 (char_u *)NULL, PV_NONE,
1454 {(char_u *)0L, (char_u *)0L}
1455#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001456 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001457 {"hidden", "hid", P_BOOL|P_VI_DEF,
1458 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001459 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001460 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001461 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001462 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001463 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001464 {"history", "hi", P_NUM|P_VIM,
1465 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001466 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001467 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1468#ifdef FEAT_RIGHTLEFT
1469 (char_u *)&p_hkmap, PV_NONE,
1470#else
1471 (char_u *)NULL, PV_NONE,
1472#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001473 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001474 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1475#ifdef FEAT_RIGHTLEFT
1476 (char_u *)&p_hkmapp, PV_NONE,
1477#else
1478 (char_u *)NULL, PV_NONE,
1479#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001480 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001481 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1482 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001483 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001484 {"icon", NULL, P_BOOL|P_VI_DEF,
1485#ifdef FEAT_TITLE
1486 (char_u *)&p_icon, PV_NONE,
1487#else
1488 (char_u *)NULL, PV_NONE,
1489#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001490 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001491 {"iconstring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001492#ifdef FEAT_TITLE
1493 (char_u *)&p_iconstring, PV_NONE,
1494#else
1495 (char_u *)NULL, PV_NONE,
1496#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001497 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001498 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1499 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001500 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001501 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001502#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001503 (char_u *)&p_imaf, PV_NONE,
1504 {(char_u *)"", (char_u *)NULL}
1505# else
1506 (char_u *)NULL, PV_NONE,
1507 {(char_u *)NULL, (char_u *)0L}
1508# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001509 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001510 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001511#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 (char_u *)&p_imak, PV_NONE,
1513#else
1514 (char_u *)NULL, PV_NONE,
1515#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001516 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001517 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001518 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001519 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001520 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001522#ifdef __sgi
1523 {(char_u *)TRUE, (char_u *)0L}
1524#else
1525 {(char_u *)FALSE, (char_u *)0L}
1526#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001527 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001528 {"iminsert", "imi", P_NUM|P_VI_DEF,
1529 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001530 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001531 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001532 {"imsearch", "ims", P_NUM|P_VI_DEF,
1533 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001534 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001535 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001536 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001537#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001538 (char_u *)&p_imsf, PV_NONE,
1539 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001540#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001541 (char_u *)NULL, PV_NONE,
1542 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001543#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001544 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001545 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1546#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1547 (char_u *)&p_imst, PV_NONE,
1548 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1549#else
1550 (char_u *)NULL, PV_NONE,
1551 {(char_u *)0L, (char_u *)0L}
1552#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001553 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001554 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1555#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001556 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001557 {(char_u *)"^\\s*#\\s*include", (char_u *)0L}
1558#else
1559 (char_u *)NULL, PV_NONE,
1560 {(char_u *)0L, (char_u *)0L}
1561#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001562 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001563 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001564#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1565 (char_u *)&p_inex, PV_INEX,
1566 {(char_u *)"", (char_u *)0L}
1567#else
1568 (char_u *)NULL, PV_NONE,
1569 {(char_u *)0L, (char_u *)0L}
1570#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001571 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001572 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1573 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001574 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001575 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1577 (char_u *)&p_inde, PV_INDE,
1578 {(char_u *)"", (char_u *)0L}
1579#else
1580 (char_u *)NULL, PV_NONE,
1581 {(char_u *)0L, (char_u *)0L}
1582#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001583 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001584 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001585#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1586 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001587 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001588#else
1589 (char_u *)NULL, PV_NONE,
1590 {(char_u *)0L, (char_u *)0L}
1591#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001592 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001593 {"infercase", "inf", P_BOOL|P_VI_DEF,
1594 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001595 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001596 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1597 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001598 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001599 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1600 (char_u *)&p_isf, PV_NONE,
1601 {
1602#ifdef BACKSLASH_IN_FILENAME
1603 /* Excluded are: & and ^ are special in cmd.exe
1604 * ( and ) are used in text separating fnames */
1605 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1606#else
1607# ifdef AMIGA
1608 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1609# else
1610# ifdef VMS
1611 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1612# else /* UNIX et al. */
1613# ifdef EBCDIC
1614 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1615# else
1616 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1617# endif
1618# endif
1619# endif
1620#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001621 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001622 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1623 (char_u *)&p_isi, PV_NONE,
1624 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001625#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001626 (char_u *)"@,48-57,_,128-167,224-235",
1627#else
1628# ifdef EBCDIC
1629 /* TODO: EBCDIC Check this! @ == isalpha()*/
1630 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1631 "112-120,128,140-142,156,158,172,"
1632 "174,186,191,203-207,219-225,235-239,"
1633 "251-254",
1634# else
1635 (char_u *)"@,48-57,_,192-255",
1636# endif
1637#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001638 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001639 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1640 (char_u *)&p_isk, PV_ISK,
1641 {
1642#ifdef EBCDIC
1643 (char_u *)"@,240-249,_",
1644 /* TODO: EBCDIC Check this! @ == isalpha()*/
1645 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1646 "112-120,128,140-142,156,158,172,"
1647 "174,186,191,203-207,219-225,235-239,"
1648 "251-254",
1649#else
1650 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001651# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001652 (char_u *)"@,48-57,_,128-167,224-235"
1653# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001654 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655# endif
1656#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001657 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001658 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1659 (char_u *)&p_isp, PV_NONE,
1660 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001661#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662 (char_u *)"@,~-255",
1663#else
1664# ifdef EBCDIC
1665 /* all chars above 63 are printable */
1666 (char_u *)"63-255",
1667# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001668 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001669# endif
1670#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001671 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001672 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1673 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001674 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001675 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1676#ifdef FEAT_CRYPT
1677 (char_u *)&p_key, PV_KEY,
1678 {(char_u *)"", (char_u *)0L}
1679#else
1680 (char_u *)NULL, PV_NONE,
1681 {(char_u *)0L, (char_u *)0L}
1682#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001683 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001684 {"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 +00001685#ifdef FEAT_KEYMAP
1686 (char_u *)&p_keymap, PV_KMAP,
1687 {(char_u *)"", (char_u *)0L}
1688#else
1689 (char_u *)NULL, PV_NONE,
1690 {(char_u *)"", (char_u *)0L}
1691#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001692 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001693 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001695 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001696 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001697 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001698 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001699#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001700 (char_u *)":help",
1701#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001702# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001703 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001704# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001705# ifdef USEMAN_S
1706 (char_u *)"man -s",
1707# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001709# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001710# endif
1711#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001712 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001713 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714#ifdef FEAT_LANGMAP
1715 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001716 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001717#else
1718 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001719 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001720#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001721 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001722 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001723#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1724 (char_u *)&p_lm, PV_NONE,
1725#else
1726 (char_u *)NULL, PV_NONE,
1727#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001728 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001729 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1730#ifdef FEAT_LANGMAP
1731 (char_u *)&p_lnr, PV_NONE,
1732#else
1733 (char_u *)NULL, PV_NONE,
1734#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001735 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001736 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1737#ifdef FEAT_LANGMAP
1738 (char_u *)&p_lrm, PV_NONE,
1739#else
1740 (char_u *)NULL, PV_NONE,
1741#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001742 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001743 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001744 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001745 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001746 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1747 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001748 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001749 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1750#ifdef FEAT_LINEBREAK
1751 (char_u *)VAR_WIN, PV_LBR,
1752#else
1753 (char_u *)NULL, PV_NONE,
1754#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001755 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1757 (char_u *)&Rows, PV_NONE,
1758 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001759#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001760 (char_u *)25L,
1761#else
1762 (char_u *)24L,
1763#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001764 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001765 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1766#ifdef FEAT_GUI
1767 (char_u *)&p_linespace, PV_NONE,
1768#else
1769 (char_u *)NULL, PV_NONE,
1770#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001771#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001772 {(char_u *)1L, (char_u *)0L}
1773#else
1774 {(char_u *)0L, (char_u *)0L}
1775#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001776 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001777 {"lisp", NULL, P_BOOL|P_VI_DEF,
1778#ifdef FEAT_LISP
1779 (char_u *)&p_lisp, PV_LISP,
1780#else
1781 (char_u *)NULL, PV_NONE,
1782#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001783 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001784 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001785#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001786 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001787 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1788#else
1789 (char_u *)NULL, PV_NONE,
1790 {(char_u *)"", (char_u *)0L}
1791#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001792 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001793 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1794 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001795 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001796 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001797 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001798 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001799 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1800 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001801 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001802 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001803#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001804 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001805 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001806#else
1807 (char_u *)NULL, PV_NONE,
1808 {(char_u *)"", (char_u *)0L}
1809#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001810 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001811 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001812#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001813 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001814 {(char_u *)TRUE, (char_u *)0L}
1815#else
1816 (char_u *)NULL, PV_NONE,
1817 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001818#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001819 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820 {"magic", NULL, P_BOOL|P_VI_DEF,
1821 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001822 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001823 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001824#ifdef FEAT_QUICKFIX
1825 (char_u *)&p_mef, PV_NONE,
1826 {(char_u *)"", (char_u *)0L}
1827#else
1828 (char_u *)NULL, PV_NONE,
1829 {(char_u *)NULL, (char_u *)0L}
1830#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001831 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001832 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001833 (char_u *)&p_menc, PV_MENC,
1834 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001835 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001836 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1837#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001838 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001839# ifdef VMS
1840 {(char_u *)"MMS", (char_u *)0L}
1841# else
1842 {(char_u *)"make", (char_u *)0L}
1843# endif
1844#else
1845 (char_u *)NULL, PV_NONE,
1846 {(char_u *)NULL, (char_u *)0L}
1847#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001848 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001849 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001851 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001852 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001853 {"matchtime", "mat", P_NUM|P_VI_DEF,
1854 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001855 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001856 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001857 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001858 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001859 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1860#ifdef FEAT_EVAL
1861 (char_u *)&p_mfd, PV_NONE,
1862#else
1863 (char_u *)NULL, PV_NONE,
1864#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001865 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001866 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1867 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001868 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001869 {"maxmem", "mm", P_NUM|P_VI_DEF,
1870 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001871 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001872 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001873 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1874 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001875 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001876 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1877 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001878 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001879 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001880 {"menuitems", "mis", P_NUM|P_VI_DEF,
1881#ifdef FEAT_MENU
1882 (char_u *)&p_mis, PV_NONE,
1883#else
1884 (char_u *)NULL, PV_NONE,
1885#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001886 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001887 {"mesg", NULL, P_BOOL|P_VI_DEF,
1888 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001889 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001890 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001891#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001892 (char_u *)&p_msm, PV_NONE,
1893 {(char_u *)"460000,2000,500", (char_u *)0L}
1894#else
1895 (char_u *)NULL, PV_NONE,
1896 {(char_u *)0L, (char_u *)0L}
1897#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001898 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"modeline", "ml", P_BOOL|P_VIM,
1900 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001901 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar7e800c62019-05-23 17:08:49 +02001902 {"modelineexpr", "mle", P_BOOL|P_VI_DEF|P_SECURE,
Bram Moolenaar110289e2019-05-23 15:38:06 +02001903 (char_u *)&p_mle, PV_NONE,
1904 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905 {"modelines", "mls", P_NUM|P_VI_DEF,
1906 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001907 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1909 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001910 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001911 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1912 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001913 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001914 {"more", NULL, P_BOOL|P_VIM,
1915 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001916 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1918 (char_u *)&p_mouse, PV_NONE,
1919 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001920#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001921 (char_u *)"a",
1922#else
1923 (char_u *)"",
1924#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001925 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001926 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1927#ifdef FEAT_GUI
1928 (char_u *)&p_mousef, PV_NONE,
1929#else
1930 (char_u *)NULL, PV_NONE,
1931#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001932 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001933 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1934#ifdef FEAT_GUI
1935 (char_u *)&p_mh, PV_NONE,
1936#else
1937 (char_u *)NULL, PV_NONE,
1938#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001939 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001940 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1941 (char_u *)&p_mousem, PV_NONE,
1942 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001943#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944 (char_u *)"popup",
1945#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001946# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001947 (char_u *)"popup_setpos",
1948# else
1949 (char_u *)"extend",
1950# endif
1951#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001952 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001953 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001954#ifdef FEAT_MOUSESHAPE
1955 (char_u *)&p_mouseshape, PV_NONE,
1956 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1957#else
1958 (char_u *)NULL, PV_NONE,
1959 {(char_u *)NULL, (char_u *)0L}
1960#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001961 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001962 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1963 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001964 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001965 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1966#if defined(DYNAMIC_MZSCHEME)
1967 (char_u *)&p_mzschemedll, PV_NONE,
1968 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1969#else
1970 (char_u *)NULL, PV_NONE,
1971 {(char_u *)"", (char_u *)0L}
1972#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001973 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001974 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1975#if defined(DYNAMIC_MZSCHEME)
1976 (char_u *)&p_mzschemegcdll, PV_NONE,
1977 {(char_u *)DYNAMIC_MZGC_DLL, (char_u *)0L}
1978#else
1979 (char_u *)NULL, PV_NONE,
1980 {(char_u *)"", (char_u *)0L}
1981#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001982 SCTX_INIT},
Bram Moolenaar325b7a22004-07-05 15:58:32 +00001983 {"mzquantum", "mzq", P_NUM,
1984#ifdef FEAT_MZSCHEME
1985 (char_u *)&p_mzq, PV_NONE,
1986#else
1987 (char_u *)NULL, PV_NONE,
1988#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001989 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001990 {"novice", NULL, P_BOOL|P_VI_DEF,
1991 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001992 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001993 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001994 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001995 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001996 SCTX_INIT},
Bram Moolenaar44826212019-08-22 21:23:20 +02001997 {"number", "nu", P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001999 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002000 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
2001#ifdef FEAT_LINEBREAK
2002 (char_u *)VAR_WIN, PV_NUW,
2003#else
2004 (char_u *)NULL, PV_NONE,
2005#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002006 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00002007 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00002008#ifdef FEAT_COMPL_FUNC
2009 (char_u *)&p_ofu, PV_OFU,
2010 {(char_u *)"", (char_u *)0L}
2011#else
2012 (char_u *)NULL, PV_NONE,
2013 {(char_u *)0L, (char_u *)0L}
2014#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002015 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002016 {"open", NULL, P_BOOL|P_VI_DEF,
2017 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002018 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002019 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002020#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002021 (char_u *)&p_odev, PV_NONE,
2022#else
2023 (char_u *)NULL, PV_NONE,
2024#endif
2025 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002026 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002027 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2028 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002029 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002030 {"optimize", "opt", P_BOOL|P_VI_DEF,
2031 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002032 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002034 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002035 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002036 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2037 |P_SECURE,
2038 (char_u *)&p_pp, PV_NONE,
2039 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002040 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002041 {"paragraphs", "para", P_STRING|P_VI_DEF,
2042 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002043 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002044 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002045 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002046 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002047 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002048 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2049 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002050 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002051 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2052#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2053 (char_u *)&p_pex, PV_NONE,
2054 {(char_u *)"", (char_u *)0L}
2055#else
2056 (char_u *)NULL, PV_NONE,
2057 {(char_u *)0L, (char_u *)0L}
2058#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002059 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002060 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002062 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002063 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002064 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002065 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002066#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002067 (char_u *)".,,",
2068#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002069 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002070#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002071 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002072 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002073#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002074 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002075 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002076#else
2077 (char_u *)NULL, PV_NONE,
2078 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002079#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002080 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002081 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2082 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002083 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002084 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002085#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002086 (char_u *)&p_pvh, PV_NONE,
2087#else
2088 (char_u *)NULL, PV_NONE,
2089#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002090 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar79648732019-07-18 21:43:07 +02002091 {"previewpopup", "pvp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2092#ifdef FEAT_TEXT_PROP
2093 (char_u *)&p_pvp, PV_NONE,
2094 {(char_u *)"", (char_u *)0L}
2095#else
2096 (char_u *)NULL, PV_NONE,
2097 {(char_u *)NULL, (char_u *)0L}
2098#endif
2099 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002100 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002101#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002102 (char_u *)VAR_WIN, PV_PVW,
2103#else
2104 (char_u *)NULL, PV_NONE,
2105#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002106 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002107 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002108#ifdef FEAT_PRINTER
2109 (char_u *)&p_pdev, PV_NONE,
2110 {(char_u *)"", (char_u *)0L}
2111#else
2112 (char_u *)NULL, PV_NONE,
2113 {(char_u *)NULL, (char_u *)0L}
2114#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002115 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002116 {"printencoding", "penc", P_STRING|P_VI_DEF,
2117#ifdef FEAT_POSTSCRIPT
2118 (char_u *)&p_penc, PV_NONE,
2119 {(char_u *)"", (char_u *)0L}
2120#else
2121 (char_u *)NULL, PV_NONE,
2122 {(char_u *)NULL, (char_u *)0L}
2123#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002124 SCTX_INIT},
Bram Moolenaar031cb742016-11-24 21:46:19 +01002125 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002126#ifdef FEAT_POSTSCRIPT
2127 (char_u *)&p_pexpr, PV_NONE,
2128 {(char_u *)"", (char_u *)0L}
2129#else
2130 (char_u *)NULL, PV_NONE,
2131 {(char_u *)NULL, (char_u *)0L}
2132#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002133 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002134 {"printfont", "pfn", P_STRING|P_VI_DEF,
2135#ifdef FEAT_PRINTER
2136 (char_u *)&p_pfn, PV_NONE,
2137 {
2138# ifdef MSWIN
2139 (char_u *)"Courier_New:h10",
2140# else
2141 (char_u *)"courier",
2142# endif
2143 (char_u *)0L}
2144#else
2145 (char_u *)NULL, PV_NONE,
2146 {(char_u *)NULL, (char_u *)0L}
2147#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002148 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002149 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2150#ifdef FEAT_PRINTER
2151 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002152 /* untranslated to avoid problems when 'encoding'
2153 * is changed */
2154 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002155#else
2156 (char_u *)NULL, PV_NONE,
2157 {(char_u *)NULL, (char_u *)0L}
2158#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002159 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002160 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002161#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002162 (char_u *)&p_pmcs, PV_NONE,
2163 {(char_u *)"", (char_u *)0L}
2164#else
2165 (char_u *)NULL, PV_NONE,
2166 {(char_u *)NULL, (char_u *)0L}
2167#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002168 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002169 {"printmbfont", "pmbfn", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002170#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002171 (char_u *)&p_pmfn, PV_NONE,
2172 {(char_u *)"", (char_u *)0L}
2173#else
2174 (char_u *)NULL, PV_NONE,
2175 {(char_u *)NULL, (char_u *)0L}
2176#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002177 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002178 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002179#ifdef FEAT_PRINTER
2180 (char_u *)&p_popt, PV_NONE,
2181 {(char_u *)"", (char_u *)0L}
2182#else
2183 (char_u *)NULL, PV_NONE,
2184 {(char_u *)NULL, (char_u *)0L}
2185#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002186 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002187 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002188 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002189 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002190 {"pumheight", "ph", P_NUM|P_VI_DEF,
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002191 (char_u *)&p_ph, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002192 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002193 {"pumwidth", "pw", P_NUM|P_VI_DEF,
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002194 (char_u *)&p_pw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002195 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002196 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002197#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002198 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002199 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002200#else
2201 (char_u *)NULL, PV_NONE,
2202 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002203#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002204 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002205 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2206#if defined(FEAT_PYTHON3)
2207 (char_u *)&p_py3home, PV_NONE,
2208 {(char_u *)"", (char_u *)0L}
2209#else
2210 (char_u *)NULL, PV_NONE,
2211 {(char_u *)NULL, (char_u *)0L}
2212#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002213 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002214 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002215#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002216 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002217 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002218#else
2219 (char_u *)NULL, PV_NONE,
2220 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002221#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002222 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002223 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2224#if defined(FEAT_PYTHON)
2225 (char_u *)&p_pyhome, PV_NONE,
2226 {(char_u *)"", (char_u *)0L}
2227#else
2228 (char_u *)NULL, PV_NONE,
2229 {(char_u *)NULL, (char_u *)0L}
2230#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002231 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002232 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2233#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2234 (char_u *)&p_pyx, PV_NONE,
2235#else
2236 (char_u *)NULL, PV_NONE,
2237#endif
2238 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002239 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002240 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2241#ifdef FEAT_TEXTOBJ
2242 (char_u *)&p_qe, PV_QE,
2243 {(char_u *)"\\", (char_u *)0L}
2244#else
2245 (char_u *)NULL, PV_NONE,
2246 {(char_u *)NULL, (char_u *)0L}
2247#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002248 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002249 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2250 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002251 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002252 {"redraw", NULL, P_BOOL|P_VI_DEF,
2253 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002254 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002255 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2256#ifdef FEAT_RELTIME
2257 (char_u *)&p_rdt, PV_NONE,
2258#else
2259 (char_u *)NULL, PV_NONE,
2260#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002261 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002262 {"regexpengine", "re", P_NUM|P_VI_DEF,
2263 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002264 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar44826212019-08-22 21:23:20 +02002265 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaar64486672010-05-16 15:46:46 +02002266 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002267 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002268 {"remap", NULL, P_BOOL|P_VI_DEF,
2269 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002270 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002271 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002272#ifdef FEAT_RENDER_OPTIONS
2273 (char_u *)&p_rop, PV_NONE,
2274 {(char_u *)"", (char_u *)0L}
2275#else
2276 (char_u *)NULL, PV_NONE,
2277 {(char_u *)NULL, (char_u *)0L}
2278#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002279 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002280 {"report", NULL, P_NUM|P_VI_DEF,
2281 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002282 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002283 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002284#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002285 (char_u *)&p_rs, PV_NONE,
2286#else
2287 (char_u *)NULL, PV_NONE,
2288#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002289 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002290 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2291#ifdef FEAT_RIGHTLEFT
2292 (char_u *)&p_ri, PV_NONE,
2293#else
2294 (char_u *)NULL, PV_NONE,
2295#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002296 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002297 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2298#ifdef FEAT_RIGHTLEFT
2299 (char_u *)VAR_WIN, PV_RL,
2300#else
2301 (char_u *)NULL, PV_NONE,
2302#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002303 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002304 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2305#ifdef FEAT_RIGHTLEFT
2306 (char_u *)VAR_WIN, PV_RLC,
2307 {(char_u *)"search", (char_u *)NULL}
2308#else
2309 (char_u *)NULL, PV_NONE,
2310 {(char_u *)NULL, (char_u *)0L}
2311#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002312 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002313 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002314#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002315 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002316 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002317#else
2318 (char_u *)NULL, PV_NONE,
2319 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002320#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002321 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002322 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2323#ifdef FEAT_CMDL_INFO
2324 (char_u *)&p_ru, PV_NONE,
2325#else
2326 (char_u *)NULL, PV_NONE,
2327#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002328 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002329 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002330#ifdef FEAT_STL_OPT
2331 (char_u *)&p_ruf, PV_NONE,
2332#else
2333 (char_u *)NULL, PV_NONE,
2334#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002335 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002336 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2337 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002338 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002339 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002340 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002341 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2342 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002343 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002345 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002346 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002347 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2348 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002349 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002350 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002351 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002352 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002353 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002354 (char_u *)&p_sbo, PV_NONE,
2355 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002356 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002357 {"sections", "sect", P_STRING|P_VI_DEF,
2358 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002359 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002360 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002361 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2362 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002363 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002365 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002366 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002367 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002368 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002369 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002370 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002371 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002372#ifdef FEAT_SESSION
2373 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002374 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002375 (char_u *)0L}
2376#else
2377 (char_u *)NULL, PV_NONE,
2378 {(char_u *)0L, (char_u *)0L}
2379#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002380 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002381 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2382 (char_u *)&p_sh, PV_NONE,
2383 {
2384#ifdef VMS
2385 (char_u *)"-",
2386#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002387# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002388 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002389# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002391# endif
2392#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002393 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002394 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2395 (char_u *)&p_shcf, PV_NONE,
2396 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002397#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002398 (char_u *)"/c",
2399#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002401#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002402 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002403 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2404#ifdef FEAT_QUICKFIX
2405 (char_u *)&p_sp, PV_NONE,
2406 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002407#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002409#else
2410 (char_u *)">",
2411#endif
2412 (char_u *)0L}
2413#else
2414 (char_u *)NULL, PV_NONE,
2415 {(char_u *)0L, (char_u *)0L}
2416#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002417 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002418 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2419 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002420 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002421 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2422 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002423 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002424 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2425#ifdef BACKSLASH_IN_FILENAME
2426 (char_u *)&p_ssl, PV_NONE,
2427#else
2428 (char_u *)NULL, PV_NONE,
2429#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002430 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002431 {"shelltemp", "stmp", P_BOOL,
2432 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002433 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002434 {"shelltype", "st", P_NUM|P_VI_DEF,
2435#ifdef AMIGA
2436 (char_u *)&p_st, PV_NONE,
2437#else
2438 (char_u *)NULL, PV_NONE,
2439#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002440 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002441 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2442 (char_u *)&p_sxq, PV_NONE,
2443 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002444#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002445 (char_u *)"\"",
2446#else
2447 (char_u *)"",
2448#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002449 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002450 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2451 (char_u *)&p_sxe, PV_NONE,
2452 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002453#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002454 (char_u *)"\"&|<>()@^",
2455#else
2456 (char_u *)"",
2457#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002458 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002459 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2460 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002461 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002462 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2463 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002464 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002465 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2466 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02002467 {(char_u *)"S", (char_u *)"filnxtToOS"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002468 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002470 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002471 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002472 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2473#ifdef FEAT_LINEBREAK
2474 (char_u *)&p_sbr, PV_NONE,
2475#else
2476 (char_u *)NULL, PV_NONE,
2477#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002478 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002479 {"showcmd", "sc", P_BOOL|P_VIM,
2480#ifdef FEAT_CMDL_INFO
2481 (char_u *)&p_sc, PV_NONE,
2482#else
2483 (char_u *)NULL, PV_NONE,
2484#endif
2485 {(char_u *)FALSE,
2486#ifdef UNIX
2487 (char_u *)FALSE
2488#else
2489 (char_u *)TRUE
2490#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002491 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002492 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2493 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002494 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002495 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2496 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002497 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002498 {"showmode", "smd", P_BOOL|P_VIM,
2499 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002500 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002501 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002502 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002503 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002504 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2505 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002506 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002507 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002508 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002509 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002510 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RCLR,
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002511#ifdef FEAT_SIGNS
2512 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002513 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002514#else
2515 (char_u *)NULL, PV_NONE,
2516 {(char_u *)NULL, (char_u *)0L}
2517#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002518 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002519 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2520 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002521 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002522 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2523 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002524 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002525 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2526#ifdef FEAT_SMARTINDENT
2527 (char_u *)&p_si, PV_SI,
2528#else
2529 (char_u *)NULL, PV_NONE,
2530#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002531 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002532 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2533 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002534 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002535 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2536 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002537 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002538 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2539 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002540 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002541 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002542#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002543 (char_u *)VAR_WIN, PV_SPELL,
2544#else
2545 (char_u *)NULL, PV_NONE,
2546#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002547 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002548 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002549#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002550 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002551 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002552#else
2553 (char_u *)NULL, PV_NONE,
2554 {(char_u *)0L, (char_u *)0L}
2555#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002556 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002557 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2558 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002559#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002560 (char_u *)&p_spf, PV_SPF,
2561 {(char_u *)"", (char_u *)0L}
2562#else
2563 (char_u *)NULL, PV_NONE,
2564 {(char_u *)0L, (char_u *)0L}
2565#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002566 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002567 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2568 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002569#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002570 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002571 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002572#else
2573 (char_u *)NULL, PV_NONE,
2574 {(char_u *)0L, (char_u *)0L}
2575#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002576 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002577 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002578#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002579 (char_u *)&p_sps, PV_NONE,
2580 {(char_u *)"best", (char_u *)0L}
2581#else
2582 (char_u *)NULL, PV_NONE,
2583 {(char_u *)0L, (char_u *)0L}
2584#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002585 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002587 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002588 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002590 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002591 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002592 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2593 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002594 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002595 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002596#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002597 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002598#else
2599 (char_u *)NULL, PV_NONE,
2600#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002601 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002602 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002603 (char_u *)&p_su, PV_NONE,
2604 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002605 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002606 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002607#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002608 (char_u *)&p_sua, PV_SUA,
2609 {(char_u *)"", (char_u *)0L}
2610#else
2611 (char_u *)NULL, PV_NONE,
2612 {(char_u *)0L, (char_u *)0L}
2613#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002614 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002615 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2616 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002617 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002618 {"swapsync", "sws", P_STRING|P_VI_DEF,
2619 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002620 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002621 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002622 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002623 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002624 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2625#ifdef FEAT_SYN_HL
2626 (char_u *)&p_smc, PV_SMC,
2627 {(char_u *)3000L, (char_u *)0L}
2628#else
2629 (char_u *)NULL, PV_NONE,
2630 {(char_u *)0L, (char_u *)0L}
2631#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002632 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002633 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002634#ifdef FEAT_SYN_HL
2635 (char_u *)&p_syn, PV_SYN,
2636 {(char_u *)"", (char_u *)0L}
2637#else
2638 (char_u *)NULL, PV_NONE,
2639 {(char_u *)0L, (char_u *)0L}
2640#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002641 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002642 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL|P_MLE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002643#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002644 (char_u *)&p_tal, PV_NONE,
2645#else
2646 (char_u *)NULL, PV_NONE,
2647#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002648 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002649 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002650 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002651 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002652 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2653 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002654 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002655 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2656 (char_u *)&p_tbs, PV_NONE,
2657#ifdef VMS /* binary searching doesn't appear to work on VMS */
2658 {(char_u *)0L, (char_u *)0L}
2659#else
2660 {(char_u *)TRUE, (char_u *)0L}
2661#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002662 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002663 {"tagcase", "tc", P_STRING|P_VIM,
2664 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002665 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002666 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2667#ifdef FEAT_EVAL
2668 (char_u *)&p_tfu, PV_TFU,
2669 {(char_u *)"", (char_u *)0L}
2670#else
2671 (char_u *)NULL, PV_NONE,
2672 {(char_u *)0L, (char_u *)0L}
2673#endif
2674 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002675 {"taglength", "tl", P_NUM|P_VI_DEF,
2676 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002677 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002678 {"tagrelative", "tr", P_BOOL|P_VIM,
2679 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002680 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002681 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002682 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002683 {
2684#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2685 (char_u *)"./tags,./TAGS,tags,TAGS",
2686#else
2687 (char_u *)"./tags,tags",
2688#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002689 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002690 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2691 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002692 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002693 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002694#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002695 (char_u *)&p_tcldll, PV_NONE,
2696 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002697#else
2698 (char_u *)NULL, PV_NONE,
2699 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002700#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002701 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002702 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2703 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002704 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002705 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2706#ifdef FEAT_ARABIC
2707 (char_u *)&p_tbidi, PV_NONE,
2708#else
2709 (char_u *)NULL, PV_NONE,
2710#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002711 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002713 (char_u *)&p_tenc, PV_NONE,
2714 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002715 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002716 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2717#ifdef FEAT_TERMGUICOLORS
2718 (char_u *)&p_tgc, PV_NONE,
2719 {(char_u *)FALSE, (char_u *)FALSE}
2720#else
2721 (char_u*)NULL, PV_NONE,
2722 {(char_u *)FALSE, (char_u *)FALSE}
2723#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002724 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002725 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2726#ifdef FEAT_TERMINAL
2727 (char_u *)VAR_WIN, PV_TWK,
2728 {(char_u *)"", (char_u *)NULL}
2729#else
2730 (char_u *)NULL, PV_NONE,
2731 {(char_u *)NULL, (char_u *)0L}
2732#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002733 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002734 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2735#ifdef FEAT_TERMINAL
2736 (char_u *)&p_twsl, PV_TWSL,
2737 {(char_u *)10000L, (char_u *)10000L}
2738#else
2739 (char_u *)NULL, PV_NONE,
2740 {(char_u *)NULL, (char_u *)0L}
2741#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002742 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002743 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2744#ifdef FEAT_TERMINAL
2745 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002746 {(char_u *)"", (char_u *)NULL}
2747#else
2748 (char_u *)NULL, PV_NONE,
2749 {(char_u *)NULL, (char_u *)0L}
2750#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002751 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002752 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002753#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002754 (char_u *)&p_twt, PV_NONE,
2755 {(char_u *)"", (char_u *)NULL}
2756#else
2757 (char_u *)NULL, PV_NONE,
2758 {(char_u *)NULL, (char_u *)0L}
2759#endif
2760 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002761 {"terse", NULL, P_BOOL|P_VI_DEF,
2762 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002763 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002764 {"textauto", "ta", P_BOOL|P_VIM,
2765 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002766 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002767 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002768 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2769 (char_u *)&p_tx, PV_TX,
2770 {
2771#ifdef USE_CRNL
2772 (char_u *)TRUE,
2773#else
2774 (char_u *)FALSE,
2775#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002776 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002777 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002778 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002779 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002780 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002781 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002782 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002783 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2784 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002785 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {"timeout", "to", P_BOOL|P_VI_DEF,
2787 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002788 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2790 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002791 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 {"title", NULL, P_BOOL|P_VI_DEF,
2793#ifdef FEAT_TITLE
2794 (char_u *)&p_title, PV_NONE,
2795#else
2796 (char_u *)NULL, PV_NONE,
2797#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002798 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002799 {"titlelen", NULL, P_NUM|P_VI_DEF,
2800#ifdef FEAT_TITLE
2801 (char_u *)&p_titlelen, PV_NONE,
2802#else
2803 (char_u *)NULL, PV_NONE,
2804#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002805 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002806 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002807#ifdef FEAT_TITLE
2808 (char_u *)&p_titleold, PV_NONE,
2809 {(char_u *)N_("Thanks for flying Vim"),
2810 (char_u *)0L}
2811#else
2812 (char_u *)NULL, PV_NONE,
2813 {(char_u *)0L, (char_u *)0L}
2814#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002815 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002816 {"titlestring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002817#ifdef FEAT_TITLE
2818 (char_u *)&p_titlestring, PV_NONE,
2819#else
2820 (char_u *)NULL, PV_NONE,
2821#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002822 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002823 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002824#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002825 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002826 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002827#else
2828 (char_u *)NULL, PV_NONE,
2829 {(char_u *)0L, (char_u *)0L}
2830#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002831 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002832 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002833#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002834 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002835 {(char_u *)"small", (char_u *)0L}
2836#else
2837 (char_u *)NULL, PV_NONE,
2838 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002839#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002840 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002841 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2842 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002843 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2845 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002846 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2848 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002849 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2851 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002852 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2854#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2855 (char_u *)&p_ttym, PV_NONE,
2856#else
2857 (char_u *)NULL, PV_NONE,
2858#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002859 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002860 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2861 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002862 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2864 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002865 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002866 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2867 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002868#ifdef FEAT_PERSISTENT_UNDO
2869 (char_u *)&p_udir, PV_NONE,
2870 {(char_u *)".", (char_u *)0L}
2871#else
2872 (char_u *)NULL, PV_NONE,
2873 {(char_u *)0L, (char_u *)0L}
2874#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002875 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002876 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2877#ifdef FEAT_PERSISTENT_UNDO
2878 (char_u *)&p_udf, PV_UDF,
2879#else
2880 (char_u *)NULL, PV_NONE,
2881#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002882 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002883 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002884 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002885 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002886#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002887 (char_u *)1000L,
2888#else
2889 (char_u *)100L,
2890#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002891 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002892 {"undoreload", "ur", P_NUM|P_VI_DEF,
2893 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002894 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002895 {"updatecount", "uc", P_NUM|P_VI_DEF,
2896 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002897 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"updatetime", "ut", P_NUM|P_VI_DEF,
2899 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002900 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002901 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2902#ifdef FEAT_VARTABS
2903 (char_u *)&p_vsts, PV_VSTS,
2904 {(char_u *)"", (char_u *)0L}
2905#else
2906 (char_u *)NULL, PV_NONE,
2907 {(char_u *)"", (char_u *)NULL}
2908#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002909 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002910 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2911#ifdef FEAT_VARTABS
2912 (char_u *)&p_vts, PV_VTS,
2913 {(char_u *)"", (char_u *)0L}
2914#else
2915 (char_u *)NULL, PV_NONE,
2916 {(char_u *)"", (char_u *)NULL}
2917#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002918 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002919 {"verbose", "vbs", P_NUM|P_VI_DEF,
2920 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002921 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002922 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2923 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002924 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002925 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2926#ifdef FEAT_SESSION
2927 (char_u *)&p_vdir, PV_NONE,
2928 {(char_u *)DFLT_VDIR, (char_u *)0L}
2929#else
2930 (char_u *)NULL, PV_NONE,
2931 {(char_u *)0L, (char_u *)0L}
2932#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002933 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002934 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002935#ifdef FEAT_SESSION
2936 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002937 {(char_u *)"folds,options,cursor,curdir",
2938 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002939#else
2940 (char_u *)NULL, PV_NONE,
2941 {(char_u *)0L, (char_u *)0L}
2942#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002943 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002944 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002945#ifdef FEAT_VIMINFO
2946 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002947#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002948 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002949#else
2950# ifdef AMIGA
2951 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002952 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002953# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002954 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002955# endif
2956#endif
2957#else
2958 (char_u *)NULL, PV_NONE,
2959 {(char_u *)0L, (char_u *)0L}
2960#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002961 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002962 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2963 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002964#ifdef FEAT_VIMINFO
2965 (char_u *)&p_viminfofile, PV_NONE,
2966 {(char_u *)"", (char_u *)0L}
2967#else
2968 (char_u *)NULL, PV_NONE,
2969 {(char_u *)0L, (char_u *)0L}
2970#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002971 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002972 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2973 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002974 (char_u *)&p_ve, PV_NONE,
2975 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002976 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2978 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002979 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"w300", NULL, P_NUM|P_VI_DEF,
2981 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002982 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 {"w1200", NULL, P_NUM|P_VI_DEF,
2984 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002985 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002986 {"w9600", NULL, P_NUM|P_VI_DEF,
2987 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002988 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002989 {"warn", NULL, P_BOOL|P_VI_DEF,
2990 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002991 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2993 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002994 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002995 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002996 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002997 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002998 {"wildchar", "wc", P_NUM|P_VIM,
2999 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003000 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003001 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003002 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003003 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003004 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003005 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006#ifdef FEAT_WILDIGN
3007 (char_u *)&p_wig, PV_NONE,
3008#else
3009 (char_u *)NULL, PV_NONE,
3010#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003011 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003012 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3013 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003014 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003015 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3016#ifdef FEAT_WILDMENU
3017 (char_u *)&p_wmnu, PV_NONE,
3018#else
3019 (char_u *)NULL, PV_NONE,
3020#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003021 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003022 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003023 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003024 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003025 {"wildoptions", "wop", P_STRING|P_VI_DEF,
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003026 (char_u *)&p_wop, PV_NONE,
3027 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003028 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003029 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3030#ifdef FEAT_WAK
3031 (char_u *)&p_wak, PV_NONE,
3032 {(char_u *)"menu", (char_u *)0L}
3033#else
3034 (char_u *)NULL, PV_NONE,
3035 {(char_u *)NULL, (char_u *)0L}
3036#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003037 SCTX_INIT},
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003038 {"wincolor", "wcr", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
3039 (char_u *)VAR_WIN, PV_WCR,
3040 {(char_u *)"", (char_u *)NULL}
3041 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003042 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003043 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003044 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003045 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003046 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003047 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003048 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003049 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003050 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003051 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003052 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003053 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003055 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003056 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003058 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003059 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003060 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003061#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003062 (char_u *)&p_winptydll, PV_NONE, {
3063# ifdef _WIN64
3064 (char_u *)"winpty64.dll",
3065# else
3066 (char_u *)"winpty32.dll",
3067# endif
3068 (char_u *)0L}
3069#else
3070 (char_u *)NULL, PV_NONE,
3071 {(char_u *)0L, (char_u *)0L}
3072#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003073 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003074 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003075 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003076 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003077 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3078 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003079 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003080 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3081 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003082 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3084 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003085 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003086 {"write", NULL, P_BOOL|P_VI_DEF,
3087 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003088 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003089 {"writeany", "wa", P_BOOL|P_VI_DEF,
3090 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003091 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003092 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3093 (char_u *)&p_wb, PV_NONE,
3094 {
3095#ifdef FEAT_WRITEBACKUP
3096 (char_u *)TRUE,
3097#else
3098 (char_u *)FALSE,
3099#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003100 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003101 {"writedelay", "wd", P_NUM|P_VI_DEF,
3102 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003103 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003104
3105/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003106#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003107 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003108 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109
3110 p_term("t_AB", T_CAB)
3111 p_term("t_AF", T_CAF)
3112 p_term("t_AL", T_CAL)
3113 p_term("t_al", T_AL)
3114 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003115 p_term("t_BE", T_BE)
3116 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117 p_term("t_cd", T_CD)
3118 p_term("t_ce", T_CE)
3119 p_term("t_cl", T_CL)
3120 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003121 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003122 p_term("t_Co", T_CCO)
3123 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003124 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003126 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003127 p_term("t_da", T_DA)
3128 p_term("t_db", T_DB)
3129 p_term("t_DL", T_CDL)
3130 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003131 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003132 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003134 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 p_term("t_IE", T_CIE)
3136 p_term("t_IS", T_CIS)
3137 p_term("t_ke", T_KE)
3138 p_term("t_ks", T_KS)
3139 p_term("t_le", T_LE)
3140 p_term("t_mb", T_MB)
3141 p_term("t_md", T_MD)
3142 p_term("t_me", T_ME)
3143 p_term("t_mr", T_MR)
3144 p_term("t_ms", T_MS)
3145 p_term("t_nd", T_ND)
3146 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003147 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003148 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003149 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003150 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003151 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003152 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003153 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003154 p_term("t_RV", T_CRV)
3155 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003156 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003157 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003158 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003159 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003160 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003161 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003163 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003164 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003165 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003166 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003167 p_term("t_te", T_TE)
3168 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003169 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003170 p_term("t_ts", T_TS)
3171 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_ue", T_UE)
3173 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003174 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 p_term("t_vb", T_VB)
3176 p_term("t_ve", T_VE)
3177 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003178 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003179 p_term("t_vs", T_VS)
3180 p_term("t_WP", T_CWP)
3181 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003182 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 p_term("t_xs", T_XS)
3184 p_term("t_ZH", T_CZH)
3185 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003186 p_term("t_8f", T_8F)
3187 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003188
3189/* terminal key codes are not in here */
3190
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003191 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003192 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003193};
3194
3195#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3196
Bram Moolenaar071d4272004-06-13 20:20:40 +00003197static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003198static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003199static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003200static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003201#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003202static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003203#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003204static char *(p_wop_values[]) = {"tagfile", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205#ifdef FEAT_WAK
3206static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3207#endif
3208static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003209static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3210static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003211static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003212#ifdef FEAT_BROWSE
3213static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3214#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003216static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003217static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003218static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003219static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003220static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3221#ifdef FEAT_FOLDING
3222static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003223# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003224 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003225# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003226 NULL};
3227static char *(p_fcl_values[]) = {"all", NULL};
3228#endif
Bram Moolenaar576a4a62019-08-18 15:25:17 +02003229static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "popup", "noinsert", "noselect", NULL};
Bram Moolenaare2c453d2019-08-21 14:37:09 +02003230#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +02003231static char *(p_csl_values[]) = {"slash", "backslash", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003232#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003233#ifdef FEAT_SIGNS
Bram Moolenaar394c5d82019-06-17 21:48:05 +02003234static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003235#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003236#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003237static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003238#endif
Bram Moolenaar410e98a2019-09-09 22:05:49 +02003239#ifdef FEAT_SYN_HL
3240static char *(p_culopt_values[]) = {"line", "number", "both", NULL};
3241#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003242
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003243static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003244static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003245static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003246static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003247static char_u *option_expand(int opt_idx, char_u *val);
3248static void didset_options(void);
3249static void didset_options2(void);
3250static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003251#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003252static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003253#else
3254# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3255#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003256static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003257static 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 +02003258#ifdef FEAT_STL_OPT
3259static char *check_stl_option(char_u *s);
3260#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003261#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003262static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003263#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003264#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003265static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003266#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003267static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3268static 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 +01003269static void check_redraw(long_u flags);
3270static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003271static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003272static void showoptions(int all, int opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003273static int optval_default(struct vimoption *, char_u *varp, int compatible);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003274static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003275static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003276static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3277static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3278static int istermoption(struct vimoption *);
3279static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3280static char_u *get_varp(struct vimoption *);
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02003281static void check_win_options(win_T *win);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003282static void option_value2string(struct vimoption *, int opt_flags);
3283static void check_winopt(winopt_T *wop);
3284static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003285static void paste_option_changed(void);
3286static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003287#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003288static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003289#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003290static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3291static int check_opt_strings(char_u *val, char **values, int);
3292static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003293#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003294static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003295#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003296
3297/*
3298 * Initialize the options, first part.
3299 *
3300 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003301 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003302 */
3303 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003304set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003305{
3306 char_u *p;
3307 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003308 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003309
3310#ifdef FEAT_LANGMAP
3311 langmap_init();
3312#endif
3313
3314 /* Be Vi compatible by default */
3315 p_cp = TRUE;
3316
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003317 /* Use POSIX compatibility when $VIM_POSIX is set. */
3318 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003319 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003320 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003321 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003322 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003323
Bram Moolenaar071d4272004-06-13 20:20:40 +00003324 /*
3325 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003326 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003327 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003328 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003329#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003330 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003331 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003332#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003333 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003334 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335
3336#ifdef FEAT_WILDIGN
3337 /*
3338 * Set the default for 'backupskip' to include environment variables for
3339 * temp files.
3340 */
3341 {
3342# ifdef UNIX
3343 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3344# else
3345 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3346# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003347 int len;
3348 garray_T ga;
3349 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003350
3351 ga_init2(&ga, 1, 100);
3352 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3353 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003354 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003355# ifdef UNIX
3356 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003357# ifdef MACOS_X
3358 p = (char_u *)"/private/tmp";
3359# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003360 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003361# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003362 else
3363# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003364 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003365 if (p != NULL && *p != NUL)
3366 {
3367 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003368 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003369 if (ga_grow(&ga, len) == OK)
3370 {
3371 if (ga.ga_len > 0)
3372 STRCAT(ga.ga_data, ",");
3373 STRCAT(ga.ga_data, p);
3374 add_pathsep(ga.ga_data);
3375 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376 ga.ga_len += len;
3377 }
3378 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003379 if (mustfree)
3380 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003381 }
3382 if (ga.ga_data != NULL)
3383 {
3384 set_string_default("bsk", ga.ga_data);
3385 vim_free(ga.ga_data);
3386 }
3387 }
3388#endif
3389
3390 /*
3391 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3392 */
3393 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003394 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003395 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003396#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3397 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3398#endif
3399 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003400#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003401 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003402 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003403#else
3404# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003405 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003406 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003407# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003408 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003409# endif
3410#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003412 opt_idx = findoption((char_u *)"maxmem");
3413 if (opt_idx >= 0)
3414 {
3415#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003416 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3417 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003418#endif
3419 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3420 }
3421 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422 }
3423
Bram Moolenaar071d4272004-06-13 20:20:40 +00003424#ifdef FEAT_SEARCHPATH
3425 {
3426 char_u *cdpath;
3427 char_u *buf;
3428 int i;
3429 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003430 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003431
3432 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003433 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003434 if (cdpath != NULL)
3435 {
Bram Moolenaar964b3742019-05-24 18:54:09 +02003436 buf = alloc((STRLEN(cdpath) << 1) + 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003437 if (buf != NULL)
3438 {
3439 buf[0] = ','; /* start with ",", current dir first */
3440 j = 1;
3441 for (i = 0; cdpath[i] != NUL; ++i)
3442 {
3443 if (vim_ispathlistsep(cdpath[i]))
3444 buf[j++] = ',';
3445 else
3446 {
3447 if (cdpath[i] == ' ' || cdpath[i] == ',')
3448 buf[j++] = '\\';
3449 buf[j++] = cdpath[i];
3450 }
3451 }
3452 buf[j] = NUL;
3453 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003454 if (opt_idx >= 0)
3455 {
3456 options[opt_idx].def_val[VI_DEFAULT] = buf;
3457 options[opt_idx].flags |= P_DEF_ALLOCED;
3458 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003459 else
3460 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003461 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003462 if (mustfree)
3463 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003464 }
3465 }
3466#endif
3467
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003468#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003469 /* Set print encoding on platforms that don't default to latin1 */
3470 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003471# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 (char_u *)"cp1252"
3473# else
3474# ifdef VMS
3475 (char_u *)"dec-mcs"
3476# else
3477# ifdef EBCDIC
3478 (char_u *)"ebcdic-uk"
3479# else
3480# ifdef MAC
3481 (char_u *)"mac-roman"
3482# else /* HPUX */
3483 (char_u *)"hp-roman8"
3484# endif
3485# endif
3486# endif
3487# endif
3488 );
3489#endif
3490
3491#ifdef FEAT_POSTSCRIPT
3492 /* 'printexpr' must be allocated to be able to evaluate it. */
3493 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003494# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003495 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003496# else
3497# ifdef VMS
3498 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3499
3500# else
3501 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3502# endif
3503# endif
3504 );
3505#endif
3506
3507 /*
3508 * Set all the options (except the terminal options) to their default
3509 * value. Also set the global value for local options.
3510 */
3511 set_options_default(0);
3512
Bram Moolenaar07268702018-03-01 21:57:32 +01003513#ifdef CLEAN_RUNTIMEPATH
3514 if (clean_arg)
3515 {
3516 opt_idx = findoption((char_u *)"runtimepath");
3517 if (opt_idx >= 0)
3518 {
3519 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3520 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3521 }
3522 opt_idx = findoption((char_u *)"packpath");
3523 if (opt_idx >= 0)
3524 {
3525 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3526 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3527 }
3528 }
3529#endif
3530
Bram Moolenaar071d4272004-06-13 20:20:40 +00003531#ifdef FEAT_GUI
3532 if (found_reverse_arg)
3533 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3534#endif
3535
3536 curbuf->b_p_initialized = TRUE;
3537 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003538 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003539 check_buf_options(curbuf);
3540 check_win_options(curwin);
3541 check_options();
3542
3543 /* Must be before option_expand(), because that one needs vim_isIDc() */
3544 didset_options();
3545
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003546#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003547 /* Use the current chartab for the generic chartab. This is not in
3548 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003549 init_spell_chartab();
3550#endif
3551
Bram Moolenaar071d4272004-06-13 20:20:40 +00003552 /*
3553 * Expand environment variables and things like "~" for the defaults.
3554 * If option_expand() returns non-NULL the variable is expanded. This can
3555 * only happen for non-indirect options.
3556 * Also set the default to the expanded value, so ":set" does not list
3557 * them.
3558 * Don't set the P_ALLOCED flag, because we don't want to free the
3559 * default.
3560 */
3561 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3562 {
3563 if ((options[opt_idx].flags & P_GETTEXT)
3564 && options[opt_idx].var != NULL)
3565 p = (char_u *)_(*(char **)options[opt_idx].var);
3566 else
3567 p = option_expand(opt_idx, NULL);
3568 if (p != NULL && (p = vim_strsave(p)) != NULL)
3569 {
3570 *(char_u **)options[opt_idx].var = p;
3571 /* VIMEXP
3572 * Defaults for all expanded options are currently the same for Vi
3573 * and Vim. When this changes, add some code here! Also need to
3574 * split P_DEF_ALLOCED in two.
3575 */
3576 if (options[opt_idx].flags & P_DEF_ALLOCED)
3577 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3578 options[opt_idx].def_val[VI_DEFAULT] = p;
3579 options[opt_idx].flags |= P_DEF_ALLOCED;
3580 }
3581 }
3582
Bram Moolenaar071d4272004-06-13 20:20:40 +00003583 save_file_ff(curbuf); /* Buffer is unchanged */
3584
Bram Moolenaar071d4272004-06-13 20:20:40 +00003585#if defined(FEAT_ARABIC)
3586 /* Detect use of mlterm.
3587 * Mlterm is a terminal emulator akin to xterm that has some special
3588 * abilities (bidi namely).
3589 * NOTE: mlterm's author is being asked to 'set' a variable
3590 * instead of an environment variable due to inheritance.
3591 */
3592 if (mch_getenv((char_u *)"MLTERM") != NULL)
3593 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3594#endif
3595
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003596 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003597
Bram Moolenaar4f974752019-02-17 17:44:42 +01003598# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003599 /*
3600 * If $LANG isn't set, try to get a good value for it. This makes the
3601 * right language be used automatically. Don't do this for English.
3602 */
3603 if (mch_getenv((char_u *)"LANG") == NULL)
3604 {
3605 char buf[20];
3606
3607 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3608 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3609 * only the first two. */
3610 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3611 (LPTSTR)buf, 20);
3612 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3613 {
3614 /* There are a few exceptions (probably more) */
3615 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3616 STRCPY(buf, "zh_TW");
3617 else if (STRNICMP(buf, "chs", 3) == 0
3618 || STRNICMP(buf, "zhc", 3) == 0)
3619 STRCPY(buf, "zh_CN");
3620 else if (STRNICMP(buf, "jp", 2) == 0)
3621 STRCPY(buf, "ja");
3622 else
3623 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003624 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003625 }
3626 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003627# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003628# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003629 /* Moved to os_mac_conv.c to avoid dependency problems. */
3630 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003631# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003632# endif
3633
3634 /* enc_locale() will try to find the encoding of the current locale. */
3635 p = enc_locale();
3636 if (p != NULL)
3637 {
3638 char_u *save_enc;
3639
3640 /* Try setting 'encoding' and check if the value is valid.
3641 * If not, go back to the default "latin1". */
3642 save_enc = p_enc;
3643 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003644 if (STRCMP(p_enc, "gb18030") == 0)
3645 {
3646 /* We don't support "gb18030", but "cp936" is a good substitute
3647 * for practical purposes, thus use that. It's not an alias to
3648 * still support conversion between gb18030 and utf-8. */
3649 p_enc = vim_strsave((char_u *)"cp936");
3650 vim_free(p);
3651 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003652 if (mb_init() == NULL)
3653 {
3654 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003655 if (opt_idx >= 0)
3656 {
3657 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3658 options[opt_idx].flags |= P_DEF_ALLOCED;
3659 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003660
Bram Moolenaard0573012017-10-28 21:11:06 +02003661#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003662 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003663 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003664 /* Adjust the default for 'isprint' and 'iskeyword' to match
3665 * latin1. Also set the defaults for when 'nocompatible' is
3666 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003667 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003668 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003669 set_string_option_direct((char_u *)"isk", -1,
3670 ISK_LATIN1, OPT_FREE, SID_NONE);
3671 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003672 if (opt_idx >= 0)
3673 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003674 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003675 if (opt_idx >= 0)
3676 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003677 (void)init_chartab();
3678 }
3679#endif
3680
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003681#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003682 /* Win32 console: When GetACP() returns a different value from
3683 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003684 if (
3685# ifdef VIMDLL
3686 (!gui.in_use && !gui.starting) &&
3687# endif
3688 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003689 {
3690 char buf[50];
3691
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003692 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3693 * Use an alternative value. */
3694 if (GetConsoleCP() == 0)
3695 sprintf(buf, "cp%ld", (long)GetACP());
3696 else
3697 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003698 p_tenc = vim_strsave((char_u *)buf);
3699 if (p_tenc != NULL)
3700 {
3701 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003702 if (opt_idx >= 0)
3703 {
3704 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3705 options[opt_idx].flags |= P_DEF_ALLOCED;
3706 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003707 convert_setup(&input_conv, p_tenc, p_enc);
3708 convert_setup(&output_conv, p_enc, p_tenc);
3709 }
3710 else
3711 p_tenc = empty_option;
3712 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003713#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003714#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003715 /* $HOME may have characters in active code page. */
3716 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 }
3719 else
3720 {
3721 vim_free(p_enc);
3722 p_enc = save_enc;
3723 }
3724 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003725
3726#ifdef FEAT_MULTI_LANG
3727 /* Set the default for 'helplang'. */
3728 set_helplang_default(get_mess_lang());
3729#endif
3730}
3731
3732/*
3733 * Set an option to its default value.
3734 * This does not take care of side effects!
3735 */
3736 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003737set_option_default(
3738 int opt_idx,
3739 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3740 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003741{
3742 char_u *varp; /* pointer to variable for current option */
3743 int dvi; /* index in def_val[] */
3744 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003745 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003746 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3747
3748 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3749 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003750 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003751 {
3752 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3753 if (flags & P_STRING)
3754 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003755 /* Use set_string_option_direct() for local options to handle
3756 * freeing and allocating the value. */
3757 if (options[opt_idx].indir != PV_NONE)
3758 set_string_option_direct(NULL, opt_idx,
3759 options[opt_idx].def_val[dvi], opt_flags, 0);
3760 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003761 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003762 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3763 free_string_option(*(char_u **)(varp));
3764 *(char_u **)varp = options[opt_idx].def_val[dvi];
3765 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003766 }
3767 }
3768 else if (flags & P_NUM)
3769 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003770 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003771 win_comp_scroll(curwin);
3772 else
3773 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003774 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3775
3776 if ((long *)varp == &curwin->w_p_so
3777 || (long *)varp == &curwin->w_p_siso)
3778 // 'scrolloff' and 'sidescrolloff' local values have a
3779 // different default value than the global default.
3780 *(long *)varp = -1;
3781 else
3782 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003783 /* May also set global value for local option. */
3784 if (both)
3785 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003786 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003787 }
3788 }
3789 else /* P_BOOL */
3790 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003791 /* the cast to long is required for Manx C, long_i is needed for
3792 * MSVC */
3793 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003794#ifdef UNIX
3795 /* 'modeline' defaults to off for root */
3796 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3797 *(int *)varp = FALSE;
3798#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003799 /* May also set global value for local option. */
3800 if (both)
3801 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3802 *(int *)varp;
3803 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003804
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003805 /* The default value is not insecure. */
3806 flagsp = insecure_flag(opt_idx, opt_flags);
3807 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003808 }
3809
3810#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003811 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003812#endif
3813}
3814
3815/*
3816 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003817 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003818 */
3819 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003820set_options_default(
3821 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003822{
3823 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003824 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003825 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003826
3827 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003828 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003829 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003830 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003831# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003832 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003833 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003834# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003835 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003836 set_option_default(i, opt_flags, p_cp);
3837
Bram Moolenaar071d4272004-06-13 20:20:40 +00003838 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003839 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003840 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003841#ifdef FEAT_CINDENT
3842 parse_cino(curbuf);
3843#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003844}
3845
3846/*
3847 * Set the Vi-default value of a string option.
3848 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003849 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003850 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003851 static void
3852set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003853{
3854 char_u *p;
3855 int opt_idx;
3856
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003857 if (escape && vim_strchr(val, ' ') != NULL)
3858 p = vim_strsave_escaped(val, (char_u *)" ");
3859 else
3860 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861 if (p != NULL) /* we don't want a NULL */
3862 {
3863 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003864 if (opt_idx >= 0)
3865 {
3866 if (options[opt_idx].flags & P_DEF_ALLOCED)
3867 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3868 options[opt_idx].def_val[VI_DEFAULT] = p;
3869 options[opt_idx].flags |= P_DEF_ALLOCED;
3870 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003871 }
3872}
3873
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003874 void
3875set_string_default(char *name, char_u *val)
3876{
3877 set_string_default_esc(name, val, FALSE);
3878}
3879
Bram Moolenaar071d4272004-06-13 20:20:40 +00003880/*
3881 * Set the Vi-default value of a number option.
3882 * Used for 'lines' and 'columns'.
3883 */
3884 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003885set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003886{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003887 int opt_idx;
3888
3889 opt_idx = findoption((char_u *)name);
3890 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003891 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003892}
3893
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003894/*
3895 * Set all window-local and buffer-local options to the Vim default.
3896 * local-global options will use the global value.
Bram Moolenaar46451042019-08-24 15:50:46 +02003897 * When "do_buffer" is FALSE don't set buffer-local options.
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003898 */
3899 void
Bram Moolenaar46451042019-08-24 15:50:46 +02003900set_local_options_default(win_T *wp, int do_buffer)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003901{
3902 win_T *save_curwin = curwin;
3903 int i;
3904
3905 curwin = wp;
3906 curbuf = curwin->w_buffer;
3907 block_autocmds();
3908
3909 for (i = 0; !istermoption(&options[i]); i++)
3910 {
3911 struct vimoption *p = &(options[i]);
3912 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3913
3914 if (p->indir != PV_NONE
Bram Moolenaar46451042019-08-24 15:50:46 +02003915 && (do_buffer || (p->indir & PV_BUF) == 0)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003916 && !(options[i].flags & P_NODEFAULT)
3917 && !optval_default(p, varp, FALSE))
3918 set_option_default(i, OPT_LOCAL, FALSE);
3919 }
3920
3921 unblock_autocmds();
3922 curwin = save_curwin;
3923 curbuf = curwin->w_buffer;
3924}
3925
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003926#if defined(EXITFREE) || defined(PROTO)
3927/*
3928 * Free all options.
3929 */
3930 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003931free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003932{
3933 int i;
3934
3935 for (i = 0; !istermoption(&options[i]); i++)
3936 {
3937 if (options[i].indir == PV_NONE)
3938 {
3939 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003940 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003941 free_string_option(*(char_u **)options[i].var);
3942 if (options[i].flags & P_DEF_ALLOCED)
3943 free_string_option(options[i].def_val[VI_DEFAULT]);
3944 }
3945 else if (options[i].var != VAR_WIN
3946 && (options[i].flags & P_STRING))
3947 /* buffer-local option: free global value */
3948 free_string_option(*(char_u **)options[i].var);
3949 }
3950}
3951#endif
3952
3953
Bram Moolenaar071d4272004-06-13 20:20:40 +00003954/*
3955 * Initialize the options, part two: After getting Rows and Columns and
3956 * setting 'term'.
3957 */
3958 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003959set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003960{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003961 int idx;
3962
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003964 * 'scroll' defaults to half the window height. The stored default is zero,
3965 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003966 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003967 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003968 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003969 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003970 comp_col();
3971
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003972 /*
3973 * 'window' is only for backwards compatibility with Vi.
3974 * Default is Rows - 1.
3975 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003976 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003977 p_window = Rows - 1;
3978 set_number_default("window", Rows - 1);
3979
Bram Moolenaarf740b292006-02-16 22:11:02 +00003980 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003981#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003982 /*
3983 * If 'background' wasn't set by the user, try guessing the value,
3984 * depending on the terminal name. Only need to check for terminals
3985 * with a dark background, that can handle color.
3986 */
3987 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003988 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3989 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003990 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003991 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00003992 /* don't mark it as set, when starting the GUI it may be
3993 * changed again */
3994 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003995 }
3996#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00003997
3998#ifdef CURSOR_SHAPE
3999 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4000#endif
4001#ifdef FEAT_MOUSESHAPE
4002 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4003#endif
4004#ifdef FEAT_PRINTER
4005 (void)parse_printoptions(); /* parse 'printoptions' default value */
4006#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004007}
4008
4009/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004010 * Return "dark" or "light" depending on the kind of terminal.
4011 * This is just guessing! Recognized are:
4012 * "linux" Linux console
4013 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004014 * "cygwin.*" Cygwin shell
4015 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004016 * We also check the COLORFGBG environment variable, which is set by
4017 * rxvt and derivatives. This variable contains either two or three
4018 * values separated by semicolons; we want the last value in either
4019 * case. If this value is 0-6 or 8, our background is dark.
4020 */
4021 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004022term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004023{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004024#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004025 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004026 return (char_u *)"dark";
4027#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004028 char_u *p;
4029
Bram Moolenaarf740b292006-02-16 22:11:02 +00004030 if (STRCMP(T_NAME, "linux") == 0
4031 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004032 || STRNCMP(T_NAME, "cygwin", 6) == 0
4033 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004034 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4035 && (p = vim_strrchr(p, ';')) != NULL
4036 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4037 && p[2] == NUL))
4038 return (char_u *)"dark";
4039 return (char_u *)"light";
4040#endif
4041}
4042
4043/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004044 * Initialize the options, part three: After reading the .vimrc
4045 */
4046 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004047set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004048{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004049#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004050/*
4051 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4052 * This is done after other initializations, where 'shell' might have been
4053 * set, but only if they have not been set before.
4054 */
4055 char_u *p;
4056 int idx_srr;
4057 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004058# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059 int idx_sp;
4060 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004061# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004062
4063 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004064 if (idx_srr < 0)
4065 do_srr = FALSE;
4066 else
4067 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004068# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004069 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004070 if (idx_sp < 0)
4071 do_sp = FALSE;
4072 else
4073 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004074# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004075 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004076 if (p != NULL)
4077 {
4078 /*
4079 * Default for p_sp is "| tee", for p_srr is ">".
4080 * For known shells it is changed here to include stderr.
4081 */
4082 if ( fnamecmp(p, "csh") == 0
4083 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004084# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 || fnamecmp(p, "csh.exe") == 0
4086 || fnamecmp(p, "tcsh.exe") == 0
4087# endif
4088 )
4089 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004090# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004091 if (do_sp)
4092 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004093# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004095# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004096 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004097# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004098 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4099 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004100# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004101 if (do_srr)
4102 {
4103 p_srr = (char_u *)">&";
4104 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4105 }
4106 }
4107 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004108 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004109 if ( fnamecmp(p, "sh") == 0
4110 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004111 || fnamecmp(p, "mksh") == 0
4112 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004113 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004114 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004115 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004116 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004117# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 || fnamecmp(p, "cmd") == 0
4119 || fnamecmp(p, "sh.exe") == 0
4120 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004121 || fnamecmp(p, "mksh.exe") == 0
4122 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004123 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004124 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004125 || fnamecmp(p, "bash.exe") == 0
4126 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004128 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004129 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004130# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004131 if (do_sp)
4132 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004133# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004135# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004137# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4139 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004140# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004141 if (do_srr)
4142 {
4143 p_srr = (char_u *)">%s 2>&1";
4144 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4145 }
4146 }
4147 vim_free(p);
4148 }
4149#endif
4150
Bram Moolenaar4f974752019-02-17 17:44:42 +01004151#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004152 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004153 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4154 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004155 * This is done after other initializations, where 'shell' might have been
4156 * set, but only if they have not been set before. Default for p_shcf is
4157 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004158 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004159 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004160 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 {
4162 int idx3;
4163
4164 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004165 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004166 {
4167 p_shcf = (char_u *)"-c";
4168 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4169 }
4170
Bram Moolenaar071d4272004-06-13 20:20:40 +00004171 /* Somehow Win32 requires the quotes around the redirection too */
4172 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004173 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004174 {
4175 p_sxq = (char_u *)"\"";
4176 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4177 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004178 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004179 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4180 {
4181 int idx3;
4182
4183 /*
4184 * cmd.exe on Windows will strip the first and last double quote given
4185 * on the command line, e.g. most of the time things like:
4186 * cmd /c "my path/to/echo" "my args to echo"
4187 * become:
4188 * my path/to/echo" "my args to echo
4189 * when executed.
4190 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004191 * To avoid this, set shellxquote to surround the command in
4192 * parenthesis. This appears to make most commands work, without
4193 * breaking commands that worked previously, such as
4194 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004195 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004196 idx3 = findoption((char_u *)"sxq");
4197 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4198 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004199 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004200 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4201 }
4202
Bram Moolenaara64ba222012-02-12 23:23:31 +01004203 idx3 = findoption((char_u *)"shcf");
4204 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4205 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004206 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004207 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4208 }
4209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004210#endif
4211
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004212 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004213 {
4214 int idx_ffs = findoption((char_u *)"ffs");
4215
4216 /* Apply the first entry of 'fileformats' to the initial buffer. */
4217 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4218 set_fileformat(default_fileformat(), OPT_LOCAL);
4219 }
4220
Bram Moolenaar071d4272004-06-13 20:20:40 +00004221#ifdef FEAT_TITLE
4222 set_title_defaults();
4223#endif
4224}
4225
4226#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4227/*
4228 * When 'helplang' is still at its default value, set it to "lang".
4229 * Only the first two characters of "lang" are used.
4230 */
4231 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004232set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004233{
4234 int idx;
4235
4236 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4237 return;
4238 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004239 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004240 {
4241 if (options[idx].flags & P_ALLOCED)
4242 free_string_option(p_hlg);
4243 p_hlg = vim_strsave(lang);
4244 if (p_hlg == NULL)
4245 p_hlg = empty_option;
4246 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004247 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004248 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004249 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4250 {
4251 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4252 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4253 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004254 // any C like setting, such as C.UTF-8, becomes "en"
4255 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4256 {
4257 p_hlg[0] = 'e';
4258 p_hlg[1] = 'n';
4259 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004260 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004261 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004262 options[idx].flags |= P_ALLOCED;
4263 }
4264}
4265#endif
4266
4267#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004268 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004269gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004270{
4271 if (gui_get_lightness(gui.back_pixel) < 127)
4272 return (char_u *)"dark";
4273 return (char_u *)"light";
4274}
4275
4276/*
4277 * Option initializations that can only be done after opening the GUI window.
4278 */
4279 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004280init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004281{
4282 /* Set the 'background' option according to the lightness of the
4283 * background color, unless the user has set it already. */
4284 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4285 {
4286 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4287 highlight_changed();
4288 }
4289}
4290#endif
4291
4292#ifdef FEAT_TITLE
4293/*
4294 * 'title' and 'icon' only default to true if they have not been set or reset
4295 * in .vimrc and we can read the old value.
4296 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4297 * they can be reset. This reduces startup time when using X on a remote
4298 * machine.
4299 */
4300 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004301set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004302{
4303 int idx1;
4304 long val;
4305
4306 /*
4307 * If GUI is (going to be) used, we can always set the window title and
4308 * icon name. Saves a bit of time, because the X11 display server does
4309 * not need to be contacted.
4310 */
4311 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004312 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004313 {
4314#ifdef FEAT_GUI
4315 if (gui.starting || gui.in_use)
4316 val = TRUE;
4317 else
4318#endif
4319 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004320 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004321 p_title = val;
4322 }
4323 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004324 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004325 {
4326#ifdef FEAT_GUI
4327 if (gui.starting || gui.in_use)
4328 val = TRUE;
4329 else
4330#endif
4331 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004332 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004333 p_icon = val;
4334 }
4335}
4336#endif
4337
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004338#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02004339/*
4340 * Trigger the OptionSet autocommand.
4341 * "opt_idx" is the index of the option being set.
4342 * "opt_flags" can be OPT_LOCAL etc.
4343 * "oldval" the old value
4344 * "oldval_l" the old local value (only non-NULL if global and local value
4345 * are set)
4346 * "oldval_g" the old global value (only non-NULL if global and local value
4347 * are set)
4348 * "newval" the new value
4349 */
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004350 static void
4351trigger_optionsset_string(
4352 int opt_idx,
4353 int opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02004354 char_u *oldval,
4355 char_u *oldval_l,
4356 char_u *oldval_g,
4357 char_u *newval)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004358{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004359 // Don't do this recursively.
4360 if (oldval != NULL && newval != NULL
4361 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004362 {
4363 char_u buf_type[7];
4364
4365 sprintf((char *)buf_type, "%s",
4366 (opt_flags & OPT_LOCAL) ? "local" : "global");
4367 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4368 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4369 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02004370 if (opt_flags & OPT_LOCAL)
4371 {
4372 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
4373 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4374 }
4375 if (opt_flags & OPT_GLOBAL)
4376 {
4377 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
4378 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
4379 }
4380 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4381 {
4382 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
4383 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
4384 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
4385 }
4386 if (opt_flags & OPT_MODELINE)
4387 {
4388 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
4389 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4390 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004391 apply_autocmds(EVENT_OPTIONSET,
4392 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4393 reset_v_option_vars();
4394 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004395}
4396#endif
4397
Bram Moolenaar071d4272004-06-13 20:20:40 +00004398/*
4399 * Parse 'arg' for option settings.
4400 *
4401 * 'arg' may be IObuff, but only when no errors can be present and option
4402 * does not need to be expanded with option_expand().
4403 * "opt_flags":
4404 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004405 * OPT_GLOBAL for ":setglobal"
4406 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004407 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004408 * OPT_WINONLY to only set window-local options
4409 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004410 *
4411 * returns FAIL if an error is detected, OK otherwise
4412 */
4413 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004414do_set(
4415 char_u *arg, /* option string (may be written to!) */
4416 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004417{
4418 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004419 char *errmsg;
4420 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004421 char_u *startarg;
4422 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4423 int nextchar; /* next non-white char after option name */
4424 int afterchar; /* character just after option name */
4425 int len;
4426 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004427 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004428 int key;
4429 long_u flags; /* flags for current option */
4430 char_u *varp = NULL; /* pointer to variable for current option */
4431 int did_show = FALSE; /* already showed one value */
4432 int adding; /* "opt+=arg" */
4433 int prepending; /* "opt^=arg" */
4434 int removing; /* "opt-=arg" */
4435 int cp_val = 0;
4436 char_u key_name[2];
4437
4438 if (*arg == NUL)
4439 {
4440 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004441 did_show = TRUE;
4442 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004443 }
4444
4445 while (*arg != NUL) /* loop to process all options */
4446 {
4447 errmsg = NULL;
4448 startarg = arg; /* remember for error message */
4449
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004450 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4451 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004452 {
4453 /*
4454 * ":set all" show all options.
4455 * ":set all&" set all options to their default value.
4456 */
4457 arg += 3;
4458 if (*arg == '&')
4459 {
4460 ++arg;
4461 /* Only for :set command set global value of local options. */
4462 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004463 didset_options();
4464 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004465 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004466 }
4467 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004468 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004469 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004470 did_show = TRUE;
4471 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004472 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004473 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004474 {
4475 showoptions(2, opt_flags);
4476 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004477 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004478 arg += 7;
4479 }
4480 else
4481 {
4482 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004483 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004484 {
4485 prefix = 0;
4486 arg += 2;
4487 }
4488 else if (STRNCMP(arg, "inv", 3) == 0)
4489 {
4490 prefix = 2;
4491 arg += 3;
4492 }
4493
4494 /* find end of name */
4495 key = 0;
4496 if (*arg == '<')
4497 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004498 opt_idx = -1;
4499 /* look out for <t_>;> */
4500 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4501 len = 5;
4502 else
4503 {
4504 len = 1;
4505 while (arg[len] != NUL && arg[len] != '>')
4506 ++len;
4507 }
4508 if (arg[len] != '>')
4509 {
4510 errmsg = e_invarg;
4511 goto skip;
4512 }
4513 arg[len] = NUL; /* put NUL after name */
4514 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4515 opt_idx = findoption(arg + 1);
4516 arg[len++] = '>'; /* restore '>' */
4517 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004518 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004519 }
4520 else
4521 {
4522 len = 0;
4523 /*
4524 * The two characters after "t_" may not be alphanumeric.
4525 */
4526 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4527 len = 4;
4528 else
4529 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4530 ++len;
4531 nextchar = arg[len];
4532 arg[len] = NUL; /* put NUL after name */
4533 opt_idx = findoption(arg);
4534 arg[len] = nextchar; /* restore nextchar */
4535 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004536 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004537 }
4538
4539 /* remember character after option name */
4540 afterchar = arg[len];
4541
4542 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004543 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004544 ++len;
4545
4546 adding = FALSE;
4547 prepending = FALSE;
4548 removing = FALSE;
4549 if (arg[len] != NUL && arg[len + 1] == '=')
4550 {
4551 if (arg[len] == '+')
4552 {
4553 adding = TRUE; /* "+=" */
4554 ++len;
4555 }
4556 else if (arg[len] == '^')
4557 {
4558 prepending = TRUE; /* "^=" */
4559 ++len;
4560 }
4561 else if (arg[len] == '-')
4562 {
4563 removing = TRUE; /* "-=" */
4564 ++len;
4565 }
4566 }
4567 nextchar = arg[len];
4568
4569 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4570 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004571 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004572 goto skip;
4573 }
4574
4575 if (opt_idx >= 0)
4576 {
4577 if (options[opt_idx].var == NULL) /* hidden option: skip */
4578 {
4579 /* Only give an error message when requesting the value of
4580 * a hidden option, ignore setting it. */
4581 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4582 && (!(options[opt_idx].flags & P_BOOL)
4583 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004584 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004585 goto skip;
4586 }
4587
4588 flags = options[opt_idx].flags;
4589 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4590 }
4591 else
4592 {
4593 flags = P_STRING;
4594 if (key < 0)
4595 {
4596 key_name[0] = KEY2TERMCAP0(key);
4597 key_name[1] = KEY2TERMCAP1(key);
4598 }
4599 else
4600 {
4601 key_name[0] = KS_KEY;
4602 key_name[1] = (key & 0xff);
4603 }
4604 }
4605
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004606 /* Skip all options that are not window-local (used when showing
4607 * an already loaded buffer in a window). */
4608 if ((opt_flags & OPT_WINONLY)
4609 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4610 goto skip;
4611
Bram Moolenaara3227e22006-03-08 21:32:40 +00004612 /* Skip all options that are window-local (used for :vimgrep). */
4613 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4614 && options[opt_idx].var == VAR_WIN)
4615 goto skip;
4616
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004617 /* Disallow changing some options from modelines. */
4618 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004619 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004620 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004621 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004622 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004623 goto skip;
4624 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004625 if ((flags & P_MLE) && !p_mle)
4626 {
4627 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4628 goto skip;
4629 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004630#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004631 /* In diff mode some options are overruled. This avoids that
4632 * 'foldmethod' becomes "marker" instead of "diff" and that
4633 * "wrap" gets set. */
4634 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004635 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004636 && (
4637#ifdef FEAT_FOLDING
4638 options[opt_idx].indir == PV_FDM ||
4639#endif
4640 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004641 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004642#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004643 }
4644
4645#ifdef HAVE_SANDBOX
4646 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004647 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004648 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004649 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004650 goto skip;
4651 }
4652#endif
4653
4654 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4655 {
4656 arg += len;
4657 cp_val = p_cp;
4658 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4659 {
4660 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4661 {
4662 cp_val = FALSE;
4663 arg += 3;
4664 }
4665 else /* "opt&vi": set to Vi default */
4666 {
4667 cp_val = TRUE;
4668 arg += 2;
4669 }
4670 }
4671 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004672 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004673 {
4674 errmsg = e_trailing;
4675 goto skip;
4676 }
4677 }
4678
4679 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004680 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4681 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004682 */
4683 if (nextchar == '?'
4684 || (prefix == 1
4685 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4686 && !(flags & P_BOOL)))
4687 {
4688 /*
4689 * print value
4690 */
4691 if (did_show)
4692 msg_putchar('\n'); /* cursor below last one */
4693 else
4694 {
4695 gotocmdline(TRUE); /* cursor at status line */
4696 did_show = TRUE; /* remember that we did a line */
4697 }
4698 if (opt_idx >= 0)
4699 {
4700 showoneopt(&options[opt_idx], opt_flags);
4701#ifdef FEAT_EVAL
4702 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004703 {
4704 /* Mention where the option was last set. */
4705 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004706 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004707 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004708 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004709 (int)options[opt_idx].indir & PV_MASK]);
4710 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004711 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004712 (int)options[opt_idx].indir & PV_MASK]);
4713 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004714#endif
4715 }
4716 else
4717 {
4718 char_u *p;
4719
4720 p = find_termcode(key_name);
4721 if (p == NULL)
4722 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004723 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004724 goto skip;
4725 }
4726 else
4727 (void)show_one_termcode(key_name, p, TRUE);
4728 }
4729 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004730 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004731 errmsg = e_trailing;
4732 }
4733 else
4734 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004735 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004736 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004737
Bram Moolenaar071d4272004-06-13 20:20:40 +00004738 if (flags & P_BOOL) /* boolean */
4739 {
4740 if (nextchar == '=' || nextchar == ':')
4741 {
4742 errmsg = e_invarg;
4743 goto skip;
4744 }
4745
4746 /*
4747 * ":set opt!": invert
4748 * ":set opt&": reset to default value
4749 * ":set opt<": reset to global value
4750 */
4751 if (nextchar == '!')
4752 value = *(int *)(varp) ^ 1;
4753 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004754 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004755 ((flags & P_VI_DEF) || cp_val)
4756 ? VI_DEFAULT : VIM_DEFAULT];
4757 else if (nextchar == '<')
4758 {
4759 /* For 'autoread' -1 means to use global value. */
4760 if ((int *)varp == &curbuf->b_p_ar
4761 && opt_flags == OPT_LOCAL)
4762 value = -1;
4763 else
4764 value = *(int *)get_varp_scope(&(options[opt_idx]),
4765 OPT_GLOBAL);
4766 }
4767 else
4768 {
4769 /*
4770 * ":set invopt": invert
4771 * ":set opt" or ":set noopt": set or reset
4772 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004773 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004774 {
4775 errmsg = e_trailing;
4776 goto skip;
4777 }
4778 if (prefix == 2) /* inv */
4779 value = *(int *)(varp) ^ 1;
4780 else
4781 value = prefix;
4782 }
4783
4784 errmsg = set_bool_option(opt_idx, varp, (int)value,
4785 opt_flags);
4786 }
4787 else /* numeric or string */
4788 {
4789 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4790 || prefix != 1)
4791 {
4792 errmsg = e_invarg;
4793 goto skip;
4794 }
4795
4796 if (flags & P_NUM) /* numeric */
4797 {
4798 /*
4799 * Different ways to set a number option:
4800 * & set to default value
4801 * < set to global value
4802 * <xx> accept special key codes for 'wildchar'
4803 * c accept any non-digit for 'wildchar'
4804 * [-]0-9 set number
4805 * other error
4806 */
4807 ++arg;
4808 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004809 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004810 ((flags & P_VI_DEF) || cp_val)
4811 ? VI_DEFAULT : VIM_DEFAULT];
4812 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004813 {
4814 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4815 * use the global value. */
4816 if ((long *)varp == &curbuf->b_p_ul
4817 && opt_flags == OPT_LOCAL)
4818 value = NO_LOCAL_UNDOLEVEL;
4819 else
4820 value = *(long *)get_varp_scope(
4821 &(options[opt_idx]), OPT_GLOBAL);
4822 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004823 else if (((long *)varp == &p_wc
4824 || (long *)varp == &p_wcm)
4825 && (*arg == '<'
4826 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004827 || (*arg != NUL
4828 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004829 && !VIM_ISDIGIT(*arg))))
4830 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004831 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004832 if (value == 0 && (long *)varp != &p_wcm)
4833 {
4834 errmsg = e_invarg;
4835 goto skip;
4836 }
4837 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004838 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4839 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004840 /* Allow negative (for 'undolevels'), octal and
4841 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004842 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004843 &value, NULL, 0, TRUE);
Bram Moolenaar06e2c812019-06-12 19:05:48 +02004844 if (i == 0 || (arg[i] != NUL
4845 && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004846 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004847 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004848 goto skip;
4849 }
4850 }
4851 else
4852 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004853 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004854 goto skip;
4855 }
4856
4857 if (adding)
4858 value = *(long *)varp + value;
4859 if (prepending)
4860 value = *(long *)varp * value;
4861 if (removing)
4862 value = *(long *)varp - value;
4863 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004864 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004865 }
4866 else if (opt_idx >= 0) /* string */
4867 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004868 char_u *save_arg = NULL;
4869 char_u *s = NULL;
4870 char_u *oldval = NULL; /* previous value if *varp */
4871 char_u *newval;
4872 char_u *origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004873 char_u *origval_l = NULL;
4874 char_u *origval_g = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004875#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004876 char_u *saved_origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004877 char_u *saved_origval_l = NULL;
4878 char_u *saved_origval_g = NULL;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004879 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004880#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004881 unsigned newlen;
4882 int comma;
4883 int bs;
4884 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004885 was allocated */
4886
4887 /* When using ":set opt=val" for a global option
4888 * with a local value the local value will be
4889 * reset, use the global value here. */
4890 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004891 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004892 varp = options[opt_idx].var;
4893
4894 /* The old value is kept until we are sure that the
4895 * new value is valid. */
4896 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004897
Bram Moolenaard7c96872019-06-15 17:12:48 +02004898 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4899 {
4900 origval_l = *(char_u **)get_varp_scope(
4901 &(options[opt_idx]), OPT_LOCAL);
4902 origval_g = *(char_u **)get_varp_scope(
4903 &(options[opt_idx]), OPT_GLOBAL);
4904
4905 // A global-local string option might have an empty
4906 // option as value to indicate that the global
4907 // value should be used.
4908 if (((int)options[opt_idx].indir & PV_BOTH)
4909 && origval_l == empty_option)
4910 origval_l = origval_g;
4911 }
4912
4913 // When setting the local value of a global
4914 // option, the old value may be the global value.
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004915 if (((int)options[opt_idx].indir & PV_BOTH)
4916 && (opt_flags & OPT_LOCAL))
4917 origval = *(char_u **)get_varp(
4918 &options[opt_idx]);
4919 else
4920 origval = oldval;
4921
Bram Moolenaar071d4272004-06-13 20:20:40 +00004922 if (nextchar == '&') /* set to default val */
4923 {
4924 newval = options[opt_idx].def_val[
4925 ((flags & P_VI_DEF) || cp_val)
4926 ? VI_DEFAULT : VIM_DEFAULT];
4927 if ((char_u **)varp == &p_bg)
4928 {
4929 /* guess the value of 'background' */
4930#ifdef FEAT_GUI
4931 if (gui.in_use)
4932 newval = gui_bg_default();
4933 else
4934#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004935 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004936 }
4937
4938 /* expand environment variables and ~ (since the
4939 * default value was already expanded, only
4940 * required when an environment variable was set
4941 * later */
4942 if (newval == NULL)
4943 newval = empty_option;
4944 else
4945 {
4946 s = option_expand(opt_idx, newval);
4947 if (s == NULL)
4948 s = newval;
4949 newval = vim_strsave(s);
4950 }
4951 new_value_alloced = TRUE;
4952 }
4953 else if (nextchar == '<') /* set to global val */
4954 {
4955 newval = vim_strsave(*(char_u **)get_varp_scope(
4956 &(options[opt_idx]), OPT_GLOBAL));
4957 new_value_alloced = TRUE;
4958 }
4959 else
4960 {
4961 ++arg; /* jump to after the '=' or ':' */
4962
4963 /*
4964 * Set 'keywordprg' to ":help" if an empty
4965 * value was passed to :set by the user.
4966 * Misuse errbuf[] for the resulting string.
4967 */
4968 if (varp == (char_u *)&p_kp
4969 && (*arg == NUL || *arg == ' '))
4970 {
4971 STRCPY(errbuf, ":help");
4972 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004973 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004974 }
4975 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004976 * Convert 'backspace' number to string, for
4977 * adding, prepending and removing string.
4978 */
4979 else if (varp == (char_u *)&p_bs
4980 && VIM_ISDIGIT(**(char_u **)varp))
4981 {
4982 i = getdigits((char_u **)varp);
4983 switch (i)
4984 {
4985 case 0:
4986 *(char_u **)varp = empty_option;
4987 break;
4988 case 1:
4989 *(char_u **)varp = vim_strsave(
4990 (char_u *)"indent,eol");
4991 break;
4992 case 2:
4993 *(char_u **)varp = vim_strsave(
4994 (char_u *)"indent,eol,start");
4995 break;
4996 }
4997 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02004998 if (origval == oldval)
4999 origval = *(char_u **)varp;
Bram Moolenaard7c96872019-06-15 17:12:48 +02005000 if (origval_l == oldval)
5001 origval_l = *(char_u **)varp;
5002 if (origval_g == oldval)
5003 origval_g = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01005004 oldval = *(char_u **)varp;
5005 }
5006 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005007 * Convert 'whichwrap' number to string, for
5008 * backwards compatibility with Vim 3.0.
5009 * Misuse errbuf[] for the resulting string.
5010 */
5011 else if (varp == (char_u *)&p_ww
5012 && VIM_ISDIGIT(*arg))
5013 {
5014 *errbuf = NUL;
5015 i = getdigits(&arg);
5016 if (i & 1)
5017 STRCAT(errbuf, "b,");
5018 if (i & 2)
5019 STRCAT(errbuf, "s,");
5020 if (i & 4)
5021 STRCAT(errbuf, "h,l,");
5022 if (i & 8)
5023 STRCAT(errbuf, "<,>,");
5024 if (i & 16)
5025 STRCAT(errbuf, "[,],");
5026 if (*errbuf != NUL) /* remove trailing , */
5027 errbuf[STRLEN(errbuf) - 1] = NUL;
5028 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005029 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005030 }
5031 /*
5032 * Remove '>' before 'dir' and 'bdir', for
5033 * backwards compatibility with version 3.0
5034 */
5035 else if ( *arg == '>'
5036 && (varp == (char_u *)&p_dir
5037 || varp == (char_u *)&p_bdir))
5038 {
5039 ++arg;
5040 }
5041
Bram Moolenaar071d4272004-06-13 20:20:40 +00005042 /*
5043 * Copy the new string into allocated memory.
5044 * Can't use set_string_option_direct(), because
5045 * we need to remove the backslashes.
5046 */
5047 /* get a bit too much */
5048 newlen = (unsigned)STRLEN(arg) + 1;
5049 if (adding || prepending || removing)
5050 newlen += (unsigned)STRLEN(origval) + 1;
5051 newval = alloc(newlen);
5052 if (newval == NULL) /* out of mem, don't change */
5053 break;
5054 s = newval;
5055
5056 /*
5057 * Copy the string, skip over escaped chars.
5058 * For MS-DOS and WIN32 backslashes before normal
5059 * file name characters are not removed, and keep
5060 * backslash at start, for "\\machine\path", but
5061 * do remove it for "\\\\machine\\path".
5062 * The reverse is found in ExpandOldSetting().
5063 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005064 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005065 {
5066 if (*arg == '\\' && arg[1] != NUL
5067#ifdef BACKSLASH_IN_FILENAME
5068 && !((flags & P_EXPAND)
5069 && vim_isfilec(arg[1])
5070 && (arg[1] != '\\'
5071 || (s == newval
5072 && arg[2] != '\\')))
5073#endif
5074 )
5075 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005076 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005077 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005078 {
5079 /* copy multibyte char */
5080 mch_memmove(s, arg, (size_t)i);
5081 arg += i;
5082 s += i;
5083 }
5084 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005085 *s++ = *arg++;
5086 }
5087 *s = NUL;
5088
5089 /*
5090 * Expand environment variables and ~.
5091 * Don't do it when adding without inserting a
5092 * comma.
5093 */
5094 if (!(adding || prepending || removing)
5095 || (flags & P_COMMA))
5096 {
5097 s = option_expand(opt_idx, newval);
5098 if (s != NULL)
5099 {
5100 vim_free(newval);
5101 newlen = (unsigned)STRLEN(s) + 1;
5102 if (adding || prepending || removing)
5103 newlen += (unsigned)STRLEN(origval) + 1;
5104 newval = alloc(newlen);
5105 if (newval == NULL)
5106 break;
5107 STRCPY(newval, s);
5108 }
5109 }
5110
5111 /* locate newval[] in origval[] when removing it
5112 * and when adding to avoid duplicates */
5113 i = 0; /* init for GCC */
5114 if (removing || (flags & P_NODUP))
5115 {
5116 i = (int)STRLEN(newval);
5117 bs = 0;
5118 for (s = origval; *s; ++s)
5119 {
5120 if ((!(flags & P_COMMA)
5121 || s == origval
5122 || (s[-1] == ',' && !(bs & 1)))
5123 && STRNCMP(s, newval, i) == 0
5124 && (!(flags & P_COMMA)
5125 || s[i] == ','
5126 || s[i] == NUL))
5127 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005128 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005129 * even number of backslashes or a single
5130 * backslash preceded by a comma before it
5131 * is recognized as a separator */
5132 if ((s > origval + 1
5133 && s[-1] == '\\'
5134 && s[-2] != ',')
5135 || (s == origval + 1
5136 && s[-1] == '\\'))
5137
Bram Moolenaar071d4272004-06-13 20:20:40 +00005138 ++bs;
5139 else
5140 bs = 0;
5141 }
5142
5143 /* do not add if already there */
5144 if ((adding || prepending) && *s)
5145 {
5146 prepending = FALSE;
5147 adding = FALSE;
5148 STRCPY(newval, origval);
5149 }
5150 }
5151
5152 /* concatenate the two strings; add a ',' if
5153 * needed */
5154 if (adding || prepending)
5155 {
5156 comma = ((flags & P_COMMA) && *origval != NUL
5157 && *newval != NUL);
5158 if (adding)
5159 {
5160 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005161 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005162 if (comma && i > 1
5163 && (flags & P_ONECOMMA) == P_ONECOMMA
5164 && origval[i - 1] == ','
5165 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005166 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005167 mch_memmove(newval + i + comma, newval,
5168 STRLEN(newval) + 1);
5169 mch_memmove(newval, origval, (size_t)i);
5170 }
5171 else
5172 {
5173 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005174 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005175 }
5176 if (comma)
5177 newval[i] = ',';
5178 }
5179
5180 /* Remove newval[] from origval[]. (Note: "i" has
5181 * been set above and is used here). */
5182 if (removing)
5183 {
5184 STRCPY(newval, origval);
5185 if (*s)
5186 {
5187 /* may need to remove a comma */
5188 if (flags & P_COMMA)
5189 {
5190 if (s == origval)
5191 {
5192 /* include comma after string */
5193 if (s[i] == ',')
5194 ++i;
5195 }
5196 else
5197 {
5198 /* include comma before string */
5199 --s;
5200 ++i;
5201 }
5202 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005203 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005204 }
5205 }
5206
5207 if (flags & P_FLAGLIST)
5208 {
5209 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005210 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005211 {
5212 /* if options have P_FLAGLIST and
5213 * P_ONECOMMA such as 'whichwrap' */
5214 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005215 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005216 if (*s != ',' && *(s + 1) == ','
5217 && vim_strchr(s + 2, *s) != NULL)
5218 {
5219 /* Remove the duplicated value and
5220 * the next comma. */
5221 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005222 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005223 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005224 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005225 else
5226 {
5227 if ((!(flags & P_COMMA) || *s != ',')
5228 && vim_strchr(s + 1, *s) != NULL)
5229 {
5230 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005231 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005232 }
5233 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005234 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005235 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005236 }
5237
5238 if (save_arg != NULL) /* number for 'whichwrap' */
5239 arg = save_arg;
5240 new_value_alloced = TRUE;
5241 }
5242
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005243 /*
5244 * Set the new value.
5245 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005246 *(char_u **)(varp) = newval;
5247
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005248#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005249 if (!starting
5250# ifdef FEAT_CRYPT
5251 && options[opt_idx].indir != PV_KEY
5252# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005253 && origval != NULL && newval != NULL)
5254 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005255 /* origval may be freed by
5256 * did_set_string_option(), make a copy. */
5257 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005258 /* newval (and varp) may become invalid if the
5259 * buffer is closed by autocommands. */
5260 saved_newval = vim_strsave(newval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005261 if (origval_l != NULL)
5262 saved_origval_l = vim_strsave(origval_l);
5263 if (origval_g != NULL)
5264 saved_origval_g = vim_strsave(origval_g);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005265 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005266#endif
5267
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005268 {
5269 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005270 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005271
5272 // When an option is set in the sandbox, from a
5273 // modeline or in secure mode, then deal with side
5274 // effects in secure mode. Also when the value was
5275 // set with the P_INSECURE flag and is not
5276 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005277 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005278#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005279 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005280#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005281 || (!value_is_replaced && (*p & P_INSECURE)))
5282 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005283
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005284 // Handle side effects, and set the global value
5285 // for ":set" on local options. Note: when setting
5286 // 'syntax' or 'filetype' autocommands may be
5287 // triggered that can cause havoc.
5288 errmsg = did_set_string_option(
5289 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005290 new_value_alloced, oldval, errbuf,
5291 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005292
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005293 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005294 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005295
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005296#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005297 if (errmsg == NULL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02005298 trigger_optionsset_string(
5299 opt_idx, opt_flags, saved_origval,
5300 saved_origval_l, saved_origval_g,
5301 saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005302 vim_free(saved_origval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005303 vim_free(saved_origval_l);
5304 vim_free(saved_origval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005305 vim_free(saved_newval);
5306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005307 /* If error detected, print the error message. */
5308 if (errmsg != NULL)
5309 goto skip;
5310 }
5311 else /* key code option */
5312 {
5313 char_u *p;
5314
5315 if (nextchar == '&')
5316 {
5317 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005318 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005319 }
5320 else
5321 {
5322 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005323 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005324 if (*p == '\\' && p[1] != NUL)
5325 ++p;
5326 nextchar = *p;
5327 *p = NUL;
5328 add_termcode(key_name, arg, FALSE);
5329 *p = nextchar;
5330 }
5331 if (full_screen)
5332 ttest(FALSE);
5333 redraw_all_later(CLEAR);
5334 }
5335 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005336
Bram Moolenaar071d4272004-06-13 20:20:40 +00005337 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005338 did_set_option(
5339 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005340 }
5341
5342skip:
5343 /*
5344 * Advance to next argument.
5345 * - skip until a blank found, taking care of backslashes
5346 * - skip blanks
5347 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5348 */
5349 for (i = 0; i < 2 ; ++i)
5350 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005351 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005352 if (*arg++ == '\\' && *arg != NUL)
5353 ++arg;
5354 arg = skipwhite(arg);
5355 if (*arg != '=')
5356 break;
5357 }
5358 }
5359
5360 if (errmsg != NULL)
5361 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005362 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005363 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005364 if (i + (arg - startarg) < IOSIZE)
5365 {
5366 /* append the argument with the error */
5367 STRCAT(IObuff, ": ");
5368 mch_memmove(IObuff + i, startarg, (arg - startarg));
5369 IObuff[i + (arg - startarg)] = NUL;
5370 }
5371 /* make sure all characters are printable */
5372 trans_characters(IObuff, IOSIZE);
5373
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005374 ++no_wait_return; // wait_return done later
5375 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005376 --no_wait_return;
5377
5378 return FAIL;
5379 }
5380
5381 arg = skipwhite(arg);
5382 }
5383
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005384theend:
5385 if (silent_mode && did_show)
5386 {
5387 /* After displaying option values in silent mode. */
5388 silent_mode = FALSE;
5389 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5390 msg_putchar('\n');
5391 cursor_on(); /* msg_start() switches it off */
5392 out_flush();
5393 silent_mode = TRUE;
5394 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5395 }
5396
Bram Moolenaar071d4272004-06-13 20:20:40 +00005397 return OK;
5398}
5399
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005400/*
5401 * Call this when an option has been given a new value through a user command.
5402 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5403 */
5404 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005405did_set_option(
5406 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005407 int opt_flags, // possibly with OPT_MODELINE
5408 int new_value, // value was replaced completely
5409 int value_checked) // value was checked to be safe, no need to set the
5410 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005411{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005412 long_u *p;
5413
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005414 options[opt_idx].flags |= P_WAS_SET;
5415
5416 /* When an option is set in the sandbox, from a modeline or in secure mode
5417 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005418 * flag. */
5419 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005420 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005421#ifdef HAVE_SANDBOX
5422 || sandbox != 0
5423#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005424 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005425 *p = *p | P_INSECURE;
5426 else if (new_value)
5427 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005428}
5429
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005430 static char *
5431illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005432{
5433 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005434 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005435 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005436 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005437 return errbuf;
5438}
5439
5440/*
5441 * Convert a key name or string into a key value.
5442 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005443 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005444 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005445 int
5446string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005447{
5448 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005449 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005450 if (*arg == '^')
5451 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005452 if (multi_byte)
5453 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005454 return *arg;
5455}
5456
5457#ifdef FEAT_CMDWIN
5458/*
5459 * Check value of 'cedit' and set cedit_key.
5460 * Returns NULL if value is OK, error message otherwise.
5461 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005462 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005463check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005464{
5465 int n;
5466
5467 if (*p_cedit == NUL)
5468 cedit_key = -1;
5469 else
5470 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005471 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005472 if (vim_isprintc(n))
5473 return e_invarg;
5474 cedit_key = n;
5475 }
5476 return NULL;
5477}
5478#endif
5479
5480#ifdef FEAT_TITLE
5481/*
5482 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5483 * maketitle() to create and display it.
5484 * When switching the title or icon off, call mch_restore_title() to get
5485 * the old value back.
5486 */
5487 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005488did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005489{
5490 if (starting != NO_SCREEN
5491#ifdef FEAT_GUI
5492 && !gui.starting
5493#endif
5494 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005495 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005496}
5497#endif
5498
5499/*
5500 * set_options_bin - called when 'bin' changes value.
5501 */
5502 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005503set_options_bin(
5504 int oldval,
5505 int newval,
5506 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005507{
5508 /*
5509 * The option values that are changed when 'bin' changes are
5510 * copied when 'bin is set and restored when 'bin' is reset.
5511 */
5512 if (newval)
5513 {
5514 if (!oldval) /* switched on */
5515 {
5516 if (!(opt_flags & OPT_GLOBAL))
5517 {
5518 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5519 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5520 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5521 curbuf->b_p_et_nobin = curbuf->b_p_et;
5522 }
5523 if (!(opt_flags & OPT_LOCAL))
5524 {
5525 p_tw_nobin = p_tw;
5526 p_wm_nobin = p_wm;
5527 p_ml_nobin = p_ml;
5528 p_et_nobin = p_et;
5529 }
5530 }
5531
5532 if (!(opt_flags & OPT_GLOBAL))
5533 {
5534 curbuf->b_p_tw = 0; /* no automatic line wrap */
5535 curbuf->b_p_wm = 0; /* no automatic line wrap */
5536 curbuf->b_p_ml = 0; /* no modelines */
5537 curbuf->b_p_et = 0; /* no expandtab */
5538 }
5539 if (!(opt_flags & OPT_LOCAL))
5540 {
5541 p_tw = 0;
5542 p_wm = 0;
5543 p_ml = FALSE;
5544 p_et = FALSE;
5545 p_bin = TRUE; /* needed when called for the "-b" argument */
5546 }
5547 }
5548 else if (oldval) /* switched off */
5549 {
5550 if (!(opt_flags & OPT_GLOBAL))
5551 {
5552 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5553 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5554 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5555 curbuf->b_p_et = curbuf->b_p_et_nobin;
5556 }
5557 if (!(opt_flags & OPT_LOCAL))
5558 {
5559 p_tw = p_tw_nobin;
5560 p_wm = p_wm_nobin;
5561 p_ml = p_ml_nobin;
5562 p_et = p_et_nobin;
5563 }
5564 }
5565}
5566
Bram Moolenaar071d4272004-06-13 20:20:40 +00005567/*
5568 * Expand environment variables for some string options.
5569 * These string options cannot be indirect!
5570 * If "val" is NULL expand the current value of the option.
5571 * Return pointer to NameBuff, or NULL when not expanded.
5572 */
5573 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005574option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005575{
5576 /* if option doesn't need expansion nothing to do */
5577 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5578 return NULL;
5579
5580 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5581 * expand_env() would truncate the string. */
5582 if (val != NULL && STRLEN(val) > MAXPATHL)
5583 return NULL;
5584
5585 if (val == NULL)
5586 val = *(char_u **)options[opt_idx].var;
5587
5588 /*
5589 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5590 * Escape spaces when expanding 'tags', they are used to separate file
5591 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005592 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005593 */
5594 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005595 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005596#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005597 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5598#endif
5599 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005600 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5601 return NULL;
5602
5603 return NameBuff;
5604}
5605
5606/*
5607 * After setting various option values: recompute variables that depend on
5608 * option values.
5609 */
5610 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005611didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005612{
5613 /* initialize the table for 'iskeyword' et.al. */
5614 (void)init_chartab();
5615
5616 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5617 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005618 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005619#ifdef FEAT_SESSION
5620 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5621 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5622#endif
5623#ifdef FEAT_FOLDING
5624 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5625#endif
5626 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005627 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005628 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005629#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5630 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5631#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005632#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005633 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005634 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005635 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005636 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005637#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005638#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005639 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5640#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005641#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005642 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5643#endif
5644#ifdef FEAT_CMDWIN
5645 /* set cedit_key */
5646 (void)check_cedit();
5647#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005648#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005649 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005650#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005651#ifdef FEAT_LINEBREAK
5652 /* initialize the table for 'breakat'. */
5653 fill_breakat_flags();
5654#endif
5655
5656}
5657
5658/*
5659 * More side effects of setting options.
5660 */
5661 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005662didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005663{
5664 /* Initialize the highlight_attr[] table. */
5665 (void)highlight_changed();
5666
5667 /* Parse default for 'wildmode' */
5668 check_opt_wim();
5669
5670 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005671 /* Parse default for 'fillchars'. */
5672 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005673
5674#ifdef FEAT_CLIPBOARD
5675 /* Parse default for 'clipboard' */
5676 (void)check_clipboard_option();
5677#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005678#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005679 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005680 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005681 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005682 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5683#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005684}
5685
5686/*
5687 * Check for string options that are NULL (normally only termcap options).
5688 */
5689 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005690check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691{
5692 int opt_idx;
5693
5694 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5695 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5696 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5697}
5698
5699/*
5700 * Check string options in a buffer for NULL value.
5701 */
5702 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005703check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005704{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005705 check_string_option(&buf->b_p_bh);
5706 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005707 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005708 check_string_option(&buf->b_p_ff);
5709#ifdef FEAT_FIND_ID
5710 check_string_option(&buf->b_p_def);
5711 check_string_option(&buf->b_p_inc);
5712# ifdef FEAT_EVAL
5713 check_string_option(&buf->b_p_inex);
5714# endif
5715#endif
5716#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5717 check_string_option(&buf->b_p_inde);
5718 check_string_option(&buf->b_p_indk);
5719#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005720#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5721 check_string_option(&buf->b_p_bexpr);
5722#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005723#if defined(FEAT_CRYPT)
5724 check_string_option(&buf->b_p_cm);
5725#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005726 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005727#if defined(FEAT_EVAL)
5728 check_string_option(&buf->b_p_fex);
5729#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005730#ifdef FEAT_CRYPT
5731 check_string_option(&buf->b_p_key);
5732#endif
5733 check_string_option(&buf->b_p_kp);
5734 check_string_option(&buf->b_p_mps);
5735 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005736 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005737 check_string_option(&buf->b_p_isk);
5738#ifdef FEAT_COMMENTS
5739 check_string_option(&buf->b_p_com);
5740#endif
5741#ifdef FEAT_FOLDING
5742 check_string_option(&buf->b_p_cms);
5743#endif
5744 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005745#ifdef FEAT_TEXTOBJ
5746 check_string_option(&buf->b_p_qe);
5747#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005748#ifdef FEAT_SYN_HL
5749 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005750 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005751#endif
5752#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005753 check_string_option(&buf->b_s.b_p_spc);
5754 check_string_option(&buf->b_s.b_p_spf);
5755 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756#endif
5757#ifdef FEAT_SEARCHPATH
5758 check_string_option(&buf->b_p_sua);
5759#endif
5760#ifdef FEAT_CINDENT
5761 check_string_option(&buf->b_p_cink);
5762 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005763 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005764#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005765 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005766#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5767 check_string_option(&buf->b_p_cinw);
5768#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005769 check_string_option(&buf->b_p_cpt);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005770#ifdef FEAT_COMPL_FUNC
5771 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005772 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005773#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005774#ifdef FEAT_EVAL
5775 check_string_option(&buf->b_p_tfu);
5776#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005777#ifdef FEAT_KEYMAP
5778 check_string_option(&buf->b_p_keymap);
5779#endif
5780#ifdef FEAT_QUICKFIX
5781 check_string_option(&buf->b_p_gp);
5782 check_string_option(&buf->b_p_mp);
5783 check_string_option(&buf->b_p_efm);
5784#endif
5785 check_string_option(&buf->b_p_ep);
5786 check_string_option(&buf->b_p_path);
5787 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005788 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005789 check_string_option(&buf->b_p_dict);
5790 check_string_option(&buf->b_p_tsr);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005791#ifdef FEAT_LISP
5792 check_string_option(&buf->b_p_lw);
5793#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005794 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005795 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005796#ifdef FEAT_VARTABS
5797 check_string_option(&buf->b_p_vsts);
5798 check_string_option(&buf->b_p_vts);
5799#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005800}
5801
5802/*
5803 * Free the string allocated for an option.
5804 * Checks for the string being empty_option. This may happen if we're out of
5805 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5806 * check_options().
5807 * Does NOT check for P_ALLOCED flag!
5808 */
5809 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005810free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005811{
5812 if (p != empty_option)
5813 vim_free(p);
5814}
5815
5816 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005817clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818{
5819 if (*pp != empty_option)
5820 vim_free(*pp);
5821 *pp = empty_option;
5822}
5823
5824 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005825check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005826{
5827 if (*pp == NULL)
5828 *pp = empty_option;
5829}
5830
5831/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005832 * Return the option index found by a pointer into term_strings[].
5833 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005834 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005835 int
5836get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005837{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005838 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005839
5840 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5841 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005842 return opt_idx;
5843 return -1; // cannot happen: didn't find it!
5844}
5845
5846/*
5847 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5848 * Return the option index or -1 if not found.
5849 */
5850 int
5851set_term_option_alloced(char_u **p)
5852{
5853 int opt_idx = get_term_opt_idx(p);
5854
5855 if (opt_idx >= 0)
5856 options[opt_idx].flags |= P_ALLOCED;
5857 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005858}
5859
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005860#if defined(FEAT_EVAL) || defined(PROTO)
5861/*
5862 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5863 * Return FALSE when it wasn't.
5864 * Return -1 for an unknown option.
5865 */
5866 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005867was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005868{
5869 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005870 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005871
5872 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005873 {
5874 flagp = insecure_flag(idx, opt_flags);
5875 return (*flagp & P_INSECURE) != 0;
5876 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005877 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005878 return -1;
5879}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005880
5881/*
5882 * Get a pointer to the flags used for the P_INSECURE flag of option
5883 * "opt_idx". For some local options a local flags field is used.
5884 */
5885 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005886insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005887{
5888 if (opt_flags & OPT_LOCAL)
5889 switch ((int)options[opt_idx].indir)
5890 {
5891#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005892 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005893#endif
5894#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005895# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005896 case PV_FDE: return &curwin->w_p_fde_flags;
5897 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005898# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005899# ifdef FEAT_BEVAL
5900 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5901# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005902# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005903 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005904# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005905 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005906# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005907 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005908# endif
5909#endif
5910 }
5911
5912 /* Nothing special, return global flags field. */
5913 return &options[opt_idx].flags;
5914}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005915#endif
5916
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005917#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005918/*
5919 * Redraw the window title and/or tab page text later.
5920 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005921static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005922{
5923 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005924 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005925}
5926#endif
5927
Bram Moolenaar071d4272004-06-13 20:20:40 +00005928/*
5929 * Set a string option to a new value (without checking the effect).
5930 * The string is copied into allocated memory.
5931 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005932 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5933 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5934 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005935 */
5936 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005937set_string_option_direct(
5938 char_u *name,
5939 int opt_idx,
5940 char_u *val,
5941 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5942 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005943{
5944 char_u *s;
5945 char_u **varp;
5946 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00005947 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005948
Bram Moolenaar89d40322006-08-29 15:30:07 +00005949 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005950 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005951 idx = findoption(name);
5952 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005953 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005954 semsg(_(e_intern2), "set_string_option_direct()");
5955 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005956 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005957 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005958 }
5959
Bram Moolenaar89d40322006-08-29 15:30:07 +00005960 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005961 return;
5962
5963 s = vim_strsave(val);
5964 if (s != NULL)
5965 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00005966 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00005967 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00005968 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005969 free_string_option(*varp);
5970 *varp = s;
5971
5972 /* For buffer/window local option may also set the global value. */
5973 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00005974 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005975
Bram Moolenaar89d40322006-08-29 15:30:07 +00005976 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005977
5978 /* When setting both values of a global option with a local value,
5979 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00005980 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005981 {
5982 free_string_option(*varp);
5983 *varp = empty_option;
5984 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005985# ifdef FEAT_EVAL
5986 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005987 {
5988 sctx_T script_ctx;
5989
5990 if (set_sid == 0)
5991 script_ctx = current_sctx;
5992 else
5993 {
5994 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01005995 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005996 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02005997 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005998 }
5999 set_option_sctx_idx(idx, opt_flags, script_ctx);
6000 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006001# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006002 }
6003}
6004
6005/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02006006 * Like set_string_option_direct(), but for a window-local option in "wp".
6007 * Blocks autocommands to avoid the old curwin becoming invalid.
6008 */
6009 void
6010set_string_option_direct_in_win(
6011 win_T *wp,
6012 char_u *name,
6013 int opt_idx,
6014 char_u *val,
6015 int opt_flags,
6016 int set_sid)
6017{
6018 win_T *save_curwin = curwin;
6019
6020 block_autocmds();
6021 curwin = wp;
6022 curbuf = curwin->w_buffer;
6023 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6024 curwin = save_curwin;
6025 curbuf = curwin->w_buffer;
6026 unblock_autocmds();
6027}
6028
6029/*
6030 * Like set_string_option_direct(), but for a buffer-local option in "buf".
6031 * Blocks autocommands to avoid the old curbuf becoming invalid.
6032 */
6033 void
6034set_string_option_direct_in_buf(
6035 buf_T *buf,
6036 char_u *name,
6037 int opt_idx,
6038 char_u *val,
6039 int opt_flags,
6040 int set_sid)
6041{
6042 buf_T *save_curbuf = curbuf;
6043
6044 block_autocmds();
6045 curbuf = buf;
6046 curwin->w_buffer = curbuf;
6047 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6048 curbuf = save_curbuf;
6049 curwin->w_buffer = curbuf;
6050 unblock_autocmds();
6051}
6052
6053/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006054 * Set global value for string option when it's a local option.
6055 */
6056 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006057set_string_option_global(
6058 int opt_idx, /* option index */
6059 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006060{
6061 char_u **p, *s;
6062
6063 /* the global value is always allocated */
6064 if (options[opt_idx].var == VAR_WIN)
6065 p = (char_u **)GLOBAL_WO(varp);
6066 else
6067 p = (char_u **)options[opt_idx].var;
6068 if (options[opt_idx].indir != PV_NONE
6069 && p != varp
6070 && (s = vim_strsave(*varp)) != NULL)
6071 {
6072 free_string_option(*p);
6073 *p = s;
6074 }
6075}
6076
6077/*
6078 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006079 *
6080 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006081 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006082 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006083set_string_option(
6084 int opt_idx,
6085 char_u *value,
6086 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006087{
6088 char_u *s;
6089 char_u **varp;
6090 char_u *oldval;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006091#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006092 char_u *oldval_l = NULL;
6093 char_u *oldval_g = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006094 char_u *saved_oldval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02006095 char_u *saved_oldval_l = NULL;
6096 char_u *saved_oldval_g = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006097 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006098#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006099 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006100 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006101
6102 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006103 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006104
6105 s = vim_strsave(value);
6106 if (s != NULL)
6107 {
6108 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6109 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006110 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006111 ? OPT_GLOBAL : OPT_LOCAL)
6112 : opt_flags);
6113 oldval = *varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006114#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006115 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6116 {
6117 oldval_l = *(char_u **)get_varp_scope(&(options[opt_idx]),
6118 OPT_LOCAL);
6119 oldval_g = *(char_u **)get_varp_scope(&(options[opt_idx]),
6120 OPT_GLOBAL);
6121 }
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006122#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006123 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006124
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006125#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006126 if (!starting
6127# ifdef FEAT_CRYPT
6128 && options[opt_idx].indir != PV_KEY
6129# endif
6130 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006131 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02006132 if (oldval_l != NULL)
6133 saved_oldval_l = vim_strsave(oldval_l);
6134 if (oldval_g != NULL)
6135 saved_oldval_g = vim_strsave(oldval_g);
Bram Moolenaar53744302015-07-17 17:38:22 +02006136 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006137 saved_newval = vim_strsave(s);
6138 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006139#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006140 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006141 opt_flags, &value_checked)) == NULL)
6142 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006143
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006144#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006145 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006146 if (r == NULL)
6147 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02006148 saved_oldval, saved_oldval_l,
6149 saved_oldval_g, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006150 vim_free(saved_oldval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02006151 vim_free(saved_oldval_l);
6152 vim_free(saved_oldval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006153 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006154#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006155 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006156 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006157}
6158
6159/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006160 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6161 * characters or characters in "allowed".
6162 */
Bram Moolenaare677df82019-09-02 22:31:11 +02006163 int
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006164valid_name(char_u *val, char *allowed)
6165{
6166 char_u *s;
6167
6168 for (s = val; *s != NUL; ++s)
6169 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6170 return FALSE;
6171 return TRUE;
6172}
6173
6174/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006175 * Return TRUE if "val" is a valid 'filetype' name.
6176 * Also used for 'syntax' and 'keymap'.
6177 */
6178 static int
6179valid_filetype(char_u *val)
6180{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006181 return valid_name(val, ".-_");
6182}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006183
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006184/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006185 * Handle string options that need some action to perform when changed.
6186 * Returns NULL for success, or an error message for an error.
6187 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006188 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006189did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006190 int opt_idx, // index in options[] table
6191 char_u **varp, // pointer to the option variable
6192 int new_value_alloced, // new value was allocated
6193 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006194 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006195 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6196 int *value_checked) // value was checked to be save, no
6197 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006198{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006199 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006200 char_u *s, *p;
6201 int did_chartab = FALSE;
6202 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006203 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006204#ifdef FEAT_GUI
6205 /* set when changing an option that only requires a redraw in the GUI */
6206 int redraw_gui_only = FALSE;
6207#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006208 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006209#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6210 int did_swaptcap = FALSE;
6211#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006212
6213 /* Get the global option to compare with, otherwise we would have to check
6214 * two values for all local options. */
6215 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6216
6217 /* Disallow changing some options from secure mode */
6218 if ((secure
6219#ifdef HAVE_SANDBOX
6220 || sandbox != 0
6221#endif
6222 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006223 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006224
Bram Moolenaar916a8182018-11-25 02:18:29 +01006225 // Check for a "normal" directory or file name in some options. Disallow a
6226 // path separator (slash and/or backslash), wildcards and characters that
6227 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006228 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006229 && vim_strpbrk(*varp, (char_u *)(secure
6230 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006231 || ((options[opt_idx].flags & P_NDNAME)
6232 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006233 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006234
Bram Moolenaar071d4272004-06-13 20:20:40 +00006235 /* 'term' */
6236 else if (varp == &T_NAME)
6237 {
6238 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006239 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006240#ifdef FEAT_GUI
6241 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006242 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006243 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006244 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006245#endif
6246 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006247 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006248 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006249 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006250 /* Screen colors may have changed. */
6251 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006252
6253 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6254 * P_ALLOCED flag on 'term'. */
6255 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006256 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006257 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006258 }
6259
6260 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006261 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006262 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006263 char_u *bkc = p_bkc;
6264 unsigned int *flags = &bkc_flags;
6265
6266 if (opt_flags & OPT_LOCAL)
6267 {
6268 bkc = curbuf->b_p_bkc;
6269 flags = &curbuf->b_bkc_flags;
6270 }
6271
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006272 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6273 /* make the local value empty: use the global value */
6274 *flags = 0;
6275 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006276 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006277 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6278 errmsg = e_invarg;
6279 if ((((int)*flags & BKC_AUTO) != 0)
6280 + (((int)*flags & BKC_YES) != 0)
6281 + (((int)*flags & BKC_NO) != 0) != 1)
6282 {
6283 /* Must have exactly one of "auto", "yes" and "no". */
6284 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6285 errmsg = e_invarg;
6286 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006287 }
6288 }
6289
6290 /* 'backupext' and 'patchmode' */
6291 else if (varp == &p_bex || varp == &p_pm)
6292 {
6293 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6294 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006295 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006296 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006297#ifdef FEAT_LINEBREAK
6298 /* 'breakindentopt' */
6299 else if (varp == &curwin->w_p_briopt)
6300 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006301 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006302 errmsg = e_invarg;
6303 }
6304#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305
6306 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006307 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006308 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006309 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006310 */
6311 else if ( varp == &p_isi
6312 || varp == &(curbuf->b_p_isk)
6313 || varp == &p_isp
6314 || varp == &p_isf)
6315 {
6316 if (init_chartab() == FAIL)
6317 {
6318 did_chartab = TRUE; /* need to restore it below */
6319 errmsg = e_invarg; /* error in value */
6320 }
6321 }
6322
6323 /* 'helpfile' */
6324 else if (varp == &p_hf)
6325 {
6326 /* May compute new values for $VIM and $VIMRUNTIME */
6327 if (didset_vim)
6328 {
6329 vim_setenv((char_u *)"VIM", (char_u *)"");
6330 didset_vim = FALSE;
6331 }
6332 if (didset_vimruntime)
6333 {
6334 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6335 didset_vimruntime = FALSE;
6336 }
6337 }
6338
Bram Moolenaar1a384422010-07-14 19:53:30 +02006339#ifdef FEAT_SYN_HL
Bram Moolenaar410e98a2019-09-09 22:05:49 +02006340 /* 'cursorlineopt' */
6341 else if (varp == &curwin->w_p_culopt
6342 || gvarp == &curwin->w_allbuf_opt.wo_culopt)
6343 {
6344 if (**varp == NUL
6345 || check_opt_strings(*varp, p_culopt_values, FALSE) != OK)
6346 errmsg = e_invarg;
6347 }
6348
Bram Moolenaar1a384422010-07-14 19:53:30 +02006349 /* 'colorcolumn' */
6350 else if (varp == &curwin->w_p_cc)
6351 errmsg = check_colorcolumn(curwin);
6352#endif
6353
Bram Moolenaar071d4272004-06-13 20:20:40 +00006354#ifdef FEAT_MULTI_LANG
6355 /* 'helplang' */
6356 else if (varp == &p_hlg)
6357 {
6358 /* Check for "", "ab", "ab,cd", etc. */
6359 for (s = p_hlg; *s != NUL; s += 3)
6360 {
6361 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6362 {
6363 errmsg = e_invarg;
6364 break;
6365 }
6366 if (s[2] == NUL)
6367 break;
6368 }
6369 }
6370#endif
6371
6372 /* 'highlight' */
6373 else if (varp == &p_hl)
6374 {
6375 if (highlight_changed() == FAIL)
6376 errmsg = e_invarg; /* invalid flags */
6377 }
6378
6379 /* 'nrformats' */
6380 else if (gvarp == &p_nf)
6381 {
6382 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6383 errmsg = e_invarg;
6384 }
6385
6386#ifdef FEAT_SESSION
6387 /* 'sessionoptions' */
6388 else if (varp == &p_ssop)
6389 {
6390 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6391 errmsg = e_invarg;
6392 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6393 {
6394 /* Don't allow both "sesdir" and "curdir". */
6395 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6396 errmsg = e_invarg;
6397 }
6398 }
6399 /* 'viewoptions' */
6400 else if (varp == &p_vop)
6401 {
6402 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6403 errmsg = e_invarg;
6404 }
6405#endif
6406
6407 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006408 else if (varp == &p_sbo)
6409 {
6410 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6411 errmsg = e_invarg;
6412 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006413
6414 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006415 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006416 {
6417 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6418 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006419 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006420 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006421 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006422 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006423 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006424
6425 /* 'background' */
6426 else if (varp == &p_bg)
6427 {
6428 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6429 {
6430#ifdef FEAT_EVAL
6431 int dark = (*p_bg == 'd');
6432#endif
6433
6434 init_highlight(FALSE, FALSE);
6435
6436#ifdef FEAT_EVAL
6437 if (dark != (*p_bg == 'd')
6438 && get_var_value((char_u *)"g:colors_name") != NULL)
6439 {
6440 /* The color scheme must have set 'background' back to another
6441 * value, that's not what we want here. Disable the color
6442 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006443 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006444 free_string_option(p_bg);
6445 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6446 check_string_option(&p_bg);
6447 init_highlight(FALSE, FALSE);
6448 }
6449#endif
6450 }
6451 else
6452 errmsg = e_invarg;
6453 }
6454
6455 /* 'wildmode' */
6456 else if (varp == &p_wim)
6457 {
6458 if (check_opt_wim() == FAIL)
6459 errmsg = e_invarg;
6460 }
6461
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006462 /* 'wildoptions' */
6463 else if (varp == &p_wop)
6464 {
6465 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6466 errmsg = e_invarg;
6467 }
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006468
Bram Moolenaar071d4272004-06-13 20:20:40 +00006469#ifdef FEAT_WAK
6470 /* 'winaltkeys' */
6471 else if (varp == &p_wak)
6472 {
6473 if (*p_wak == NUL
6474 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6475 errmsg = e_invarg;
6476# ifdef FEAT_MENU
6477# ifdef FEAT_GUI_MOTIF
6478 else if (gui.in_use)
6479 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6480# else
6481# ifdef FEAT_GUI_GTK
6482 else if (gui.in_use)
6483 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6484# endif
6485# endif
6486# endif
6487 }
6488#endif
6489
Bram Moolenaar071d4272004-06-13 20:20:40 +00006490 /* 'eventignore' */
6491 else if (varp == &p_ei)
6492 {
6493 if (check_ei() == FAIL)
6494 errmsg = e_invarg;
6495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006496
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006497 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6498 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6499 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006500 {
6501 if (gvarp == &p_fenc)
6502 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006503 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006504 errmsg = e_modifiable;
6505 else if (vim_strchr(*varp, ',') != NULL)
6506 /* No comma allowed in 'fileencoding'; catches confusing it
6507 * with 'fileencodings'. */
6508 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006509 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006510 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006511#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006512 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006513 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006514#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006515 /* Add 'fileencoding' to the swap file. */
6516 ml_setflags(curbuf);
6517 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006518 }
6519 if (errmsg == NULL)
6520 {
6521 /* canonize the value, so that STRCMP() can be used on it */
6522 p = enc_canonize(*varp);
6523 if (p != NULL)
6524 {
6525 vim_free(*varp);
6526 *varp = p;
6527 }
6528 if (varp == &p_enc)
6529 {
6530 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006531#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006532 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006533#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006534 }
6535 }
6536
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006537#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006538 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6539 {
6540 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6541 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006542 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006543 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006544#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006545
6546 if (errmsg == NULL)
6547 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006548#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006549 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6550 * (with another encoding). */
6551 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6552 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006553#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006554
6555 /* When 'termencoding' is not empty and 'encoding' changes or when
6556 * 'termencoding' changes, need to setup for keyboard input and
6557 * display output conversion. */
6558 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6559 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006560 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6561 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6562 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006563 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006564 p_tenc, p_enc);
6565 errmsg = e_invarg;
6566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006567 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006568
Bram Moolenaar4f974752019-02-17 17:44:42 +01006569#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006570 /* $HOME may have characters in active code page. */
6571 if (varp == &p_enc)
6572 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006573#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006574 }
6575 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006576
6577#if defined(FEAT_POSTSCRIPT)
6578 else if (varp == &p_penc)
6579 {
6580 /* Canonize printencoding if VIM standard one */
6581 p = enc_canonize(p_penc);
6582 if (p != NULL)
6583 {
6584 vim_free(p_penc);
6585 p_penc = p;
6586 }
6587 else
6588 {
6589 /* Ensure lower case and '-' for '_' */
6590 for (s = p_penc; *s != NUL; s++)
6591 {
6592 if (*s == '_')
6593 *s = '-';
6594 else
6595 *s = TOLOWER_ASC(*s);
6596 }
6597 }
6598 }
6599#endif
6600
Bram Moolenaar9372a112005-12-06 19:59:18 +00006601#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006602 else if (varp == &p_imak)
6603 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006604 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006605 errmsg = e_invarg;
6606 }
6607#endif
6608
6609#ifdef FEAT_KEYMAP
6610 else if (varp == &curbuf->b_p_keymap)
6611 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006612 if (!valid_filetype(*varp))
6613 errmsg = e_invarg;
6614 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006615 {
6616 int secure_save = secure;
6617
6618 // Reset the secure flag, since the value of 'keymap' has
6619 // been checked to be safe.
6620 secure = 0;
6621
6622 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006623 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006624
Bram Moolenaar916a8182018-11-25 02:18:29 +01006625 secure = secure_save;
6626
6627 // Since we check the value, there is no need to set P_INSECURE,
6628 // even when the value comes from a modeline.
6629 *value_checked = TRUE;
6630 }
6631
Bram Moolenaarfab06232009-03-04 03:13:35 +00006632 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006633 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006634 if (*curbuf->b_p_keymap != NUL)
6635 {
6636 /* Installed a new keymap, switch on using it. */
6637 curbuf->b_p_iminsert = B_IMODE_LMAP;
6638 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6639 curbuf->b_p_imsearch = B_IMODE_LMAP;
6640 }
6641 else
6642 {
6643 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6644 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6645 curbuf->b_p_iminsert = B_IMODE_NONE;
6646 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6647 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6648 }
6649 if ((opt_flags & OPT_LOCAL) == 0)
6650 {
6651 set_iminsert_global();
6652 set_imsearch_global();
6653 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006654 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006655 }
6656 }
6657#endif
6658
6659 /* 'fileformat' */
6660 else if (gvarp == &p_ff)
6661 {
6662 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6663 errmsg = e_modifiable;
6664 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6665 errmsg = e_invarg;
6666 else
6667 {
6668 /* may also change 'textmode' */
6669 if (get_fileformat(curbuf) == EOL_DOS)
6670 curbuf->b_p_tx = TRUE;
6671 else
6672 curbuf->b_p_tx = FALSE;
6673#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006674 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006675#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006676 /* update flag in swap file */
6677 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006678 /* Redraw needed when switching to/from "mac": a CR in the text
6679 * will be displayed differently. */
6680 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6681 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006682 }
6683 }
6684
6685 /* 'fileformats' */
6686 else if (varp == &p_ffs)
6687 {
6688 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6689 errmsg = e_invarg;
6690 else
6691 {
6692 /* also change 'textauto' */
6693 if (*p_ffs == NUL)
6694 p_ta = FALSE;
6695 else
6696 p_ta = TRUE;
6697 }
6698 }
6699
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006700#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006701 /* 'cryptkey' */
6702 else if (gvarp == &p_key)
6703 {
Bram Moolenaard7663c22019-08-06 21:59:57 +02006704 // Make sure the ":set" command doesn't show the new value in the
6705 // history.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006706 remove_key_from_history();
Bram Moolenaard7663c22019-08-06 21:59:57 +02006707
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006708 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6709 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006710 ml_set_crypt_key(curbuf, oldval,
6711 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006712 }
6713
6714 else if (gvarp == &p_cm)
6715 {
6716 if (opt_flags & OPT_LOCAL)
6717 p = curbuf->b_p_cm;
6718 else
6719 p = p_cm;
6720 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6721 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006722 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006723 errmsg = e_invarg;
6724 else
6725 {
6726 /* When setting the global value to empty, make it "zip". */
6727 if (*p_cm == NUL)
6728 {
6729 if (new_value_alloced)
6730 free_string_option(p_cm);
6731 p_cm = vim_strsave((char_u *)"zip");
6732 new_value_alloced = TRUE;
6733 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006734 /* When using ":set cm=name" the local value is going to be empty.
6735 * Do that here, otherwise the crypt functions will still use the
6736 * local value. */
6737 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6738 {
6739 free_string_option(curbuf->b_p_cm);
6740 curbuf->b_p_cm = empty_option;
6741 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006742
6743 /* Need to update the swapfile when the effective method changed.
6744 * Set "s" to the effective old value, "p" to the effective new
6745 * method and compare. */
6746 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6747 s = p_cm; /* was previously using the global value */
6748 else
6749 s = oldval;
6750 if (*curbuf->b_p_cm == NUL)
6751 p = p_cm; /* is now using the global value */
6752 else
6753 p = curbuf->b_p_cm;
6754 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006755 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006756
6757 /* If the global value changes need to update the swapfile for all
6758 * buffers using that value. */
6759 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6760 {
6761 buf_T *buf;
6762
Bram Moolenaar29323592016-07-24 22:04:11 +02006763 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006764 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006765 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006766 }
6767 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006768 }
6769#endif
6770
6771 /* 'matchpairs' */
6772 else if (gvarp == &p_mps)
6773 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006774 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006775 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006776 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006777 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006778 int x2 = -1;
6779 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006780
6781 if (*p != NUL)
6782 p += mb_ptr2len(p);
6783 if (*p != NUL)
6784 x2 = *p++;
6785 if (*p != NUL)
6786 {
6787 x3 = mb_ptr2char(p);
6788 p += mb_ptr2len(p);
6789 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006790 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006791 {
6792 errmsg = e_invarg;
6793 break;
6794 }
6795 if (*p == NUL)
6796 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006797 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006798 }
6799 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006800 {
6801 /* Check for "x:y,x:y" */
6802 for (p = *varp; *p != NUL; p += 4)
6803 {
6804 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6805 {
6806 errmsg = e_invarg;
6807 break;
6808 }
6809 if (p[3] == NUL)
6810 break;
6811 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006812 }
6813 }
6814
6815#ifdef FEAT_COMMENTS
6816 /* 'comments' */
6817 else if (gvarp == &p_com)
6818 {
6819 for (s = *varp; *s; )
6820 {
6821 while (*s && *s != ':')
6822 {
6823 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6824 && !VIM_ISDIGIT(*s) && *s != '-')
6825 {
6826 errmsg = illegal_char(errbuf, *s);
6827 break;
6828 }
6829 ++s;
6830 }
6831 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006832 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006833 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006834 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006835 if (errmsg != NULL)
6836 break;
6837 while (*s && *s != ',')
6838 {
6839 if (*s == '\\' && s[1] != NUL)
6840 ++s;
6841 ++s;
6842 }
6843 s = skip_to_option_part(s);
6844 }
6845 }
6846#endif
6847
6848 /* 'listchars' */
6849 else if (varp == &p_lcs)
6850 {
6851 errmsg = set_chars_option(varp);
6852 }
6853
Bram Moolenaar071d4272004-06-13 20:20:40 +00006854 /* 'fillchars' */
6855 else if (varp == &p_fcs)
6856 {
6857 errmsg = set_chars_option(varp);
6858 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006859
6860#ifdef FEAT_CMDWIN
6861 /* 'cedit' */
6862 else if (varp == &p_cedit)
6863 {
6864 errmsg = check_cedit();
6865 }
6866#endif
6867
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006868 /* 'verbosefile' */
6869 else if (varp == &p_vfile)
6870 {
6871 verbose_stop();
6872 if (*p_vfile != NUL && verbose_open() == FAIL)
6873 errmsg = e_invarg;
6874 }
6875
Bram Moolenaar071d4272004-06-13 20:20:40 +00006876#ifdef FEAT_VIMINFO
6877 /* 'viminfo' */
6878 else if (varp == &p_viminfo)
6879 {
6880 for (s = p_viminfo; *s;)
6881 {
6882 /* Check it's a valid character */
6883 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6884 {
6885 errmsg = illegal_char(errbuf, *s);
6886 break;
6887 }
6888 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006889 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006890 else if (*s == 'r') /* skip until next ',' */
6891 {
6892 while (*++s && *s != ',')
6893 ;
6894 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006895 else if (*s == '%')
6896 {
6897 /* optional number */
6898 while (vim_isdigit(*++s))
6899 ;
6900 }
6901 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006902 ++s; /* no extra chars */
6903 else /* must have a number */
6904 {
6905 while (vim_isdigit(*++s))
6906 ;
6907
6908 if (!VIM_ISDIGIT(*(s - 1)))
6909 {
6910 if (errbuf != NULL)
6911 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006912 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006913 transchar_byte(*(s - 1)));
6914 errmsg = errbuf;
6915 }
6916 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006917 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006918 break;
6919 }
6920 }
6921 if (*s == ',')
6922 ++s;
6923 else if (*s)
6924 {
6925 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006926 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006927 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006928 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006929 break;
6930 }
6931 }
6932 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006933 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006934 }
6935#endif /* FEAT_VIMINFO */
6936
6937 /* terminal options */
6938 else if (istermoption(&options[opt_idx]) && full_screen)
6939 {
6940 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
6941 if (varp == &T_CCO)
6942 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006943 int colors = atoi((char *)T_CCO);
6944
6945 /* Only reinitialize colors if t_Co value has really changed to
6946 * avoid expensive reload of colorscheme if t_Co is set to the
6947 * same value multiple times. */
6948 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006949 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006950 t_colors = colors;
6951 if (t_colors <= 1)
6952 {
6953 if (new_value_alloced)
6954 vim_free(T_CCO);
6955 T_CCO = empty_option;
6956 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006957#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6958 if (is_term_win32())
6959 {
6960 swap_tcap();
6961 did_swaptcap = TRUE;
6962 }
6963#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00006964 /* We now have a different color setup, initialize it again. */
6965 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006966 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006967 }
6968 ttest(FALSE);
6969 if (varp == &T_ME)
6970 {
6971 out_str(T_ME);
6972 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006973#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006974 /* Since t_me has been set, this probably means that the user
6975 * wants to use this as default colors. Need to reset default
6976 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02006977# ifdef VIMDLL
6978 if (!gui.in_use && !gui.starting)
6979# endif
6980 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006981#endif
6982 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01006983 if (varp == &T_BE && termcap_active)
6984 {
6985 if (*T_BE == NUL)
6986 /* When clearing t_BE we assume the user no longer wants
6987 * bracketed paste, thus disable it by writing t_BD. */
6988 out_str(T_BD);
6989 else
6990 out_str(T_BE);
6991 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006992 }
6993
6994#ifdef FEAT_LINEBREAK
6995 /* 'showbreak' */
6996 else if (varp == &p_sbr)
6997 {
6998 for (s = p_sbr; *s; )
6999 {
7000 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007001 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01007002 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007003 }
7004 }
7005#endif
7006
7007#ifdef FEAT_GUI
7008 /* 'guifont' */
7009 else if (varp == &p_guifont)
7010 {
7011 if (gui.in_use)
7012 {
7013 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00007014# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007015 /*
7016 * Put up a font dialog and let the user select a new value.
7017 * If this is cancelled go back to the old value but don't
7018 * give an error message.
7019 */
7020 if (STRCMP(p, "*") == 0)
7021 {
7022 p = gui_mch_font_dialog(oldval);
7023
7024 if (new_value_alloced)
7025 free_string_option(p_guifont);
7026
7027 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
7028 new_value_alloced = TRUE;
7029 }
7030# endif
7031 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
7032 {
7033# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
7034 if (STRCMP(p_guifont, "*") == 0)
7035 {
7036 /* Dialog was cancelled: Keep the old value without giving
7037 * an error message. */
7038 if (new_value_alloced)
7039 free_string_option(p_guifont);
7040 p_guifont = vim_strsave(oldval);
7041 new_value_alloced = TRUE;
7042 }
7043 else
7044# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007045 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007046 }
7047 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007048 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049 }
7050# ifdef FEAT_XFONTSET
7051 else if (varp == &p_guifontset)
7052 {
7053 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007054 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007055 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007056 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007057 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007058 }
7059# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007060 else if (varp == &p_guifontwide)
7061 {
7062 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007063 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007064 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007065 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007066 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007068#endif
7069
7070#ifdef CURSOR_SHAPE
7071 /* 'guicursor' */
7072 else if (varp == &p_guicursor)
7073 errmsg = parse_shape_opt(SHAPE_CURSOR);
7074#endif
7075
7076#ifdef FEAT_MOUSESHAPE
7077 /* 'mouseshape' */
7078 else if (varp == &p_mouseshape)
7079 {
7080 errmsg = parse_shape_opt(SHAPE_MOUSE);
7081 update_mouseshape(-1);
7082 }
7083#endif
7084
7085#ifdef FEAT_PRINTER
7086 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007087 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007088# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007089 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007090 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007091# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007092#endif
7093
7094#ifdef FEAT_LANGMAP
7095 /* 'langmap' */
7096 else if (varp == &p_langmap)
7097 langmap_set();
7098#endif
7099
7100#ifdef FEAT_LINEBREAK
7101 /* 'breakat' */
7102 else if (varp == &p_breakat)
7103 fill_breakat_flags();
7104#endif
7105
7106#ifdef FEAT_TITLE
7107 /* 'titlestring' and 'iconstring' */
7108 else if (varp == &p_titlestring || varp == &p_iconstring)
7109 {
7110# ifdef FEAT_STL_OPT
7111 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7112
7113 /* NULL => statusline syntax */
7114 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7115 stl_syntax |= flagval;
7116 else
7117 stl_syntax &= ~flagval;
7118# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007119 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007120 }
7121#endif
7122
7123#ifdef FEAT_GUI
7124 /* 'guioptions' */
7125 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007126 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007127 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007128 redraw_gui_only = TRUE;
7129 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130#endif
7131
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007132#if defined(FEAT_GUI_TABLINE)
7133 /* 'guitablabel' */
7134 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007135 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007136 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007137 redraw_gui_only = TRUE;
7138 }
7139 /* 'guitabtooltip' */
7140 else if (varp == &p_gtt)
7141 {
7142 redraw_gui_only = TRUE;
7143 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007144#endif
7145
Bram Moolenaar071d4272004-06-13 20:20:40 +00007146#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7147 /* 'ttymouse' */
7148 else if (varp == &p_ttym)
7149 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007150 /* Switch the mouse off before changing the escape sequences used for
7151 * that. */
7152 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007153 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7154 errmsg = e_invarg;
7155 else
7156 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007157 if (termcap_active)
7158 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007159 }
7160#endif
7161
Bram Moolenaar071d4272004-06-13 20:20:40 +00007162 /* 'selection' */
7163 else if (varp == &p_sel)
7164 {
7165 if (*p_sel == NUL
7166 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7167 errmsg = e_invarg;
7168 }
7169
7170 /* 'selectmode' */
7171 else if (varp == &p_slm)
7172 {
7173 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7174 errmsg = e_invarg;
7175 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007176
7177#ifdef FEAT_BROWSE
7178 /* 'browsedir' */
7179 else if (varp == &p_bsdir)
7180 {
7181 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7182 && !mch_isdir(p_bsdir))
7183 errmsg = e_invarg;
7184 }
7185#endif
7186
Bram Moolenaar071d4272004-06-13 20:20:40 +00007187 /* 'keymodel' */
7188 else if (varp == &p_km)
7189 {
7190 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7191 errmsg = e_invarg;
7192 else
7193 {
7194 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7195 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7196 }
7197 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007198
7199 /* 'mousemodel' */
7200 else if (varp == &p_mousem)
7201 {
7202 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7203 errmsg = e_invarg;
7204#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7205 else if (*p_mousem != *oldval)
7206 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7207 * to create or delete the popup menus. */
7208 gui_motif_update_mousemodel(root_menu);
7209#endif
7210 }
7211
7212 /* 'switchbuf' */
7213 else if (varp == &p_swb)
7214 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007215 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007216 errmsg = e_invarg;
7217 }
7218
7219 /* 'debug' */
7220 else if (varp == &p_debug)
7221 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007222 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007223 errmsg = e_invarg;
7224 }
7225
7226 /* 'display' */
7227 else if (varp == &p_dy)
7228 {
7229 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7230 errmsg = e_invarg;
7231 else
7232 (void)init_chartab();
7233
7234 }
7235
Bram Moolenaar071d4272004-06-13 20:20:40 +00007236 /* 'eadirection' */
7237 else if (varp == &p_ead)
7238 {
7239 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7240 errmsg = e_invarg;
7241 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007242
7243#ifdef FEAT_CLIPBOARD
7244 /* 'clipboard' */
7245 else if (varp == &p_cb)
7246 errmsg = check_clipboard_option();
7247#endif
7248
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007249#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007250 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7251 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007252 else if (varp == &(curwin->w_s->b_p_spl)
7253 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007254 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007255 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7256
7257 if ((is_spellfile && !valid_spellfile(*varp))
7258 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007259 errmsg = e_invarg;
7260 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007261 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007262 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007263 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007264 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007265 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007266 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007267 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007268 /* 'spellsuggest' */
7269 else if (varp == &p_sps)
7270 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007271 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007272 errmsg = e_invarg;
7273 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007274 /* 'mkspellmem' */
7275 else if (varp == &p_msm)
7276 {
7277 if (spell_check_msm() != OK)
7278 errmsg = e_invarg;
7279 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007280#endif
7281
Bram Moolenaar071d4272004-06-13 20:20:40 +00007282 /* When 'bufhidden' is set, check for valid value. */
7283 else if (gvarp == &p_bh)
7284 {
7285 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7286 errmsg = e_invarg;
7287 }
7288
7289 /* When 'buftype' is set, check for valid value. */
7290 else if (gvarp == &p_bt)
7291 {
7292 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7293 errmsg = e_invarg;
7294 else
7295 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007296 if (curwin->w_status_height)
7297 {
7298 curwin->w_redr_status = TRUE;
7299 redraw_later(VALID);
7300 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007301 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007302#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007303 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007304#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007305 }
7306 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007307
7308#ifdef FEAT_STL_OPT
7309 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007310 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 {
7312 int wid;
7313
7314 if (varp == &p_ruf) /* reset ru_wid first */
7315 ru_wid = 0;
7316 s = *varp;
7317 if (varp == &p_ruf && *s == '%')
7318 {
7319 /* set ru_wid if 'ruf' starts with "%99(" */
7320 if (*++s == '-') /* ignore a '-' */
7321 s++;
7322 wid = getdigits(&s);
7323 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7324 ru_wid = wid;
7325 else
7326 errmsg = check_stl_option(p_ruf);
7327 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007328 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007329 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007330 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007331 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007332 comp_col();
7333 }
7334#endif
7335
Bram Moolenaar071d4272004-06-13 20:20:40 +00007336 /* check if it is a valid value for 'complete' -- Acevedo */
7337 else if (gvarp == &p_cpt)
7338 {
7339 for (s = *varp; *s;)
7340 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007341 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007342 s++;
7343 if (!*s)
7344 break;
7345 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7346 {
7347 errmsg = illegal_char(errbuf, *s);
7348 break;
7349 }
7350 if (*++s != NUL && *s != ',' && *s != ' ')
7351 {
7352 if (s[-1] == 'k' || s[-1] == 's')
7353 {
7354 /* skip optional filename after 'k' and 's' */
7355 while (*s && *s != ',' && *s != ' ')
7356 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007357 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007358 ++s;
7359 ++s;
7360 }
7361 }
7362 else
7363 {
7364 if (errbuf != NULL)
7365 {
7366 sprintf((char *)errbuf,
7367 _("E535: Illegal character after <%c>"),
7368 *--s);
7369 errmsg = errbuf;
7370 }
7371 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007372 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007373 break;
7374 }
7375 }
7376 }
7377 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007378
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007379 // 'completeopt'
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007380 else if (varp == &p_cot)
7381 {
7382 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7383 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007384 else
7385 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007386 }
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007387
Bram Moolenaare2c453d2019-08-21 14:37:09 +02007388#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007389 // 'completeslash'
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007390 else if (gvarp == &p_csl)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007391 {
Bram Moolenaarb78564d2019-07-28 19:24:36 +02007392 if (check_opt_strings(p_csl, p_csl_values, FALSE) != OK
7393 || check_opt_strings(curbuf->b_p_csl, p_csl_values, FALSE) != OK)
Bram Moolenaarac3150d2019-07-28 16:36:39 +02007394 errmsg = e_invarg;
7395 }
Bram Moolenaare2c453d2019-08-21 14:37:09 +02007396#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007397
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007398#ifdef FEAT_SIGNS
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007399 // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007400 else if (varp == &curwin->w_p_scl)
7401 {
7402 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7403 errmsg = e_invarg;
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007404 // When changing the 'signcolumn' to or from 'number', recompute the
7405 // width of the number column if 'number' or 'relativenumber' is set.
7406 if (((*oldval == 'n' && *(oldval + 1) == 'u')
7407 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
7408 && (curwin->w_p_nu || curwin->w_p_rnu))
7409 curwin->w_nrwidth_line_count = 0;
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007410 }
7411#endif
7412
Bram Moolenaar071d4272004-06-13 20:20:40 +00007413
Bram Moolenaar4f974752019-02-17 17:44:42 +01007414#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007415 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007416 else if (varp == &p_toolbar)
7417 {
7418 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7419 &toolbar_flags, TRUE) != OK)
7420 errmsg = e_invarg;
7421 else
7422 {
7423 out_flush();
7424 gui_mch_show_toolbar((toolbar_flags &
7425 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7426 }
7427 }
7428#endif
7429
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007430#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007431 /* 'toolbariconsize': GTK+ 2 only */
7432 else if (varp == &p_tbis)
7433 {
7434 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7435 errmsg = e_invarg;
7436 else
7437 {
7438 out_flush();
7439 gui_mch_show_toolbar((toolbar_flags &
7440 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7441 }
7442 }
7443#endif
7444
7445 /* 'pastetoggle': translate key codes like in a mapping */
7446 else if (varp == &p_pt)
7447 {
7448 if (*p_pt)
7449 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007450 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007451 if (p != NULL)
7452 {
7453 if (new_value_alloced)
7454 free_string_option(p_pt);
7455 p_pt = p;
7456 new_value_alloced = TRUE;
7457 }
7458 }
7459 }
7460
7461 /* 'backspace' */
7462 else if (varp == &p_bs)
7463 {
7464 if (VIM_ISDIGIT(*p_bs))
7465 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007466 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007467 errmsg = e_invarg;
7468 }
7469 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7470 errmsg = e_invarg;
7471 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007472 else if (varp == &p_bo)
7473 {
7474 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7475 errmsg = e_invarg;
7476 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007477
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007478 /* 'tagcase' */
7479 else if (gvarp == &p_tc)
7480 {
7481 unsigned int *flags;
7482
7483 if (opt_flags & OPT_LOCAL)
7484 {
7485 p = curbuf->b_p_tc;
7486 flags = &curbuf->b_tc_flags;
7487 }
7488 else
7489 {
7490 p = p_tc;
7491 flags = &tc_flags;
7492 }
7493
7494 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7495 /* make the local value empty: use the global value */
7496 *flags = 0;
7497 else if (*p == NUL
7498 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7499 errmsg = e_invarg;
7500 }
7501
Bram Moolenaar071d4272004-06-13 20:20:40 +00007502 /* 'casemap' */
7503 else if (varp == &p_cmp)
7504 {
7505 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7506 errmsg = e_invarg;
7507 }
7508
7509#ifdef FEAT_DIFF
7510 /* 'diffopt' */
7511 else if (varp == &p_dip)
7512 {
7513 if (diffopt_changed() == FAIL)
7514 errmsg = e_invarg;
7515 }
7516#endif
7517
7518#ifdef FEAT_FOLDING
7519 /* 'foldmethod' */
7520 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7521 {
7522 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7523 || *curwin->w_p_fdm == NUL)
7524 errmsg = e_invarg;
7525 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007526 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007527 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007528 if (foldmethodIsDiff(curwin))
7529 newFoldLevel();
7530 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007531 }
7532# ifdef FEAT_EVAL
7533 /* 'foldexpr' */
7534 else if (varp == &curwin->w_p_fde)
7535 {
7536 if (foldmethodIsExpr(curwin))
7537 foldUpdateAll(curwin);
7538 }
7539# endif
7540 /* 'foldmarker' */
7541 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7542 {
7543 p = vim_strchr(*varp, ',');
7544 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007545 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007546 else if (p == *varp || p[1] == NUL)
7547 errmsg = e_invarg;
7548 else if (foldmethodIsMarker(curwin))
7549 foldUpdateAll(curwin);
7550 }
7551 /* 'commentstring' */
7552 else if (gvarp == &p_cms)
7553 {
7554 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007555 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007556 }
7557 /* 'foldopen' */
7558 else if (varp == &p_fdo)
7559 {
7560 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7561 errmsg = e_invarg;
7562 }
7563 /* 'foldclose' */
7564 else if (varp == &p_fcl)
7565 {
7566 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7567 errmsg = e_invarg;
7568 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007569 /* 'foldignore' */
7570 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7571 {
7572 if (foldmethodIsIndent(curwin))
7573 foldUpdateAll(curwin);
7574 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007575#endif
7576
Bram Moolenaar071d4272004-06-13 20:20:40 +00007577 /* 'virtualedit' */
7578 else if (varp == &p_ve)
7579 {
7580 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7581 errmsg = e_invarg;
7582 else if (STRCMP(p_ve, oldval) != 0)
7583 {
7584 /* Recompute cursor position in case the new 've' setting
7585 * changes something. */
7586 validate_virtcol();
7587 coladvance(curwin->w_virtcol);
7588 }
7589 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007590
7591#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7592 else if (varp == &p_csqf)
7593 {
7594 if (p_csqf != NULL)
7595 {
7596 p = p_csqf;
7597 while (*p != NUL)
7598 {
7599 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7600 || p[1] == NUL
7601 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7602 || (p[2] != NUL && p[2] != ','))
7603 {
7604 errmsg = e_invarg;
7605 break;
7606 }
7607 else if (p[2] == NUL)
7608 break;
7609 else
7610 p += 3;
7611 }
7612 }
7613 }
7614#endif
7615
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007616#ifdef FEAT_CINDENT
7617 /* 'cinoptions' */
7618 else if (gvarp == &p_cino)
7619 {
7620 /* TODO: recognize errors */
7621 parse_cino(curbuf);
7622 }
7623#endif
7624
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007625#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007626 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007627 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007628 {
7629 if (!gui_mch_set_rendering_options(p_rop))
7630 errmsg = e_invarg;
7631 }
7632#endif
7633
Bram Moolenaard0b51382016-11-04 15:23:45 +01007634 else if (gvarp == &p_ft)
7635 {
7636 if (!valid_filetype(*varp))
7637 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007638 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007639 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007640 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007641
7642 // Since we check the value, there is no need to set P_INSECURE,
7643 // even when the value comes from a modeline.
7644 *value_checked = TRUE;
7645 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007646 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007647
7648#ifdef FEAT_SYN_HL
7649 else if (gvarp == &p_syn)
7650 {
7651 if (!valid_filetype(*varp))
7652 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007653 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007654 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007655 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007656
7657 // Since we check the value, there is no need to set P_INSECURE,
7658 // even when the value comes from a modeline.
7659 *value_checked = TRUE;
7660 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007661 }
7662#endif
7663
Bram Moolenaar825680f2017-07-22 17:04:02 +02007664#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007665 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007666 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007667 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007668 if (*curwin->w_p_twk != NUL
7669 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007670 errmsg = e_invarg;
7671 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007672 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007673 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007674 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007675 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007676 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007677 p = skipdigits(curwin->w_p_tws);
7678 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007679 || (*p != 'x' && *p != '*')
7680 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007681 errmsg = e_invarg;
7682 }
7683 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007684# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007685 // 'termwintype'
7686 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007687 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007688 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007689 errmsg = e_invarg;
7690 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007691# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007692#endif
7693
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007694#ifdef FEAT_VARTABS
7695 /* 'varsofttabstop' */
7696 else if (varp == &(curbuf->b_p_vsts))
7697 {
7698 char_u *cp;
7699
7700 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7701 {
7702 if (curbuf->b_p_vsts_array)
7703 {
7704 vim_free(curbuf->b_p_vsts_array);
7705 curbuf->b_p_vsts_array = 0;
7706 }
7707 }
7708 else
7709 {
7710 for (cp = *varp; *cp; ++cp)
7711 {
7712 if (vim_isdigit(*cp))
7713 continue;
7714 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7715 continue;
7716 errmsg = e_invarg;
7717 break;
7718 }
7719 if (errmsg == NULL)
7720 {
7721 int *oldarray = curbuf->b_p_vsts_array;
7722 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7723 {
7724 if (oldarray)
7725 vim_free(oldarray);
7726 }
7727 else
7728 errmsg = e_invarg;
7729 }
7730 }
7731 }
7732
7733 /* 'vartabstop' */
7734 else if (varp == &(curbuf->b_p_vts))
7735 {
7736 char_u *cp;
7737
7738 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7739 {
7740 if (curbuf->b_p_vts_array)
7741 {
7742 vim_free(curbuf->b_p_vts_array);
7743 curbuf->b_p_vts_array = NULL;
7744 }
7745 }
7746 else
7747 {
7748 for (cp = *varp; *cp; ++cp)
7749 {
7750 if (vim_isdigit(*cp))
7751 continue;
7752 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7753 continue;
7754 errmsg = e_invarg;
7755 break;
7756 }
7757 if (errmsg == NULL)
7758 {
7759 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007760
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007761 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7762 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007763 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007764#ifdef FEAT_FOLDING
7765 if (foldmethodIsIndent(curwin))
7766 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007767#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007768 }
7769 else
7770 errmsg = e_invarg;
7771 }
7772 }
7773 }
7774#endif
7775
Bram Moolenaar79648732019-07-18 21:43:07 +02007776#ifdef FEAT_TEXT_PROP
7777 // 'previewpopup'
7778 else if (varp == &p_pvp)
7779 {
7780 if (parse_previewpopup(NULL) == FAIL)
7781 errmsg = e_invarg;
7782 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007783# ifdef FEAT_QUICKFIX
Bram Moolenaar62a0cb42019-08-18 16:35:23 +02007784 // 'completepopup'
7785 else if (varp == &p_cpp)
7786 {
7787 if (parse_completepopup(NULL) == FAIL)
7788 errmsg = e_invarg;
7789 }
Bram Moolenaar36e4d982019-08-20 21:12:16 +02007790# endif
Bram Moolenaar79648732019-07-18 21:43:07 +02007791#endif
7792
Bram Moolenaar071d4272004-06-13 20:20:40 +00007793 /* Options that are a list of flags. */
7794 else
7795 {
7796 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007797 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007798 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007799 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007800 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007801 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007802 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007803 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007804 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007805#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007806 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007807 p = (char_u *)COCU_ALL;
7808#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007809 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007810 {
7811#ifdef FEAT_MOUSE
7812 p = (char_u *)MOUSE_ALL;
7813#else
7814 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007815 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007816#endif
7817 }
7818#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007819 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007820 p = (char_u *)GO_ALL;
7821#endif
7822 if (p != NULL)
7823 {
7824 for (s = *varp; *s; ++s)
7825 if (vim_strchr(p, *s) == NULL)
7826 {
7827 errmsg = illegal_char(errbuf, *s);
7828 break;
7829 }
7830 }
7831 }
7832
7833 /*
7834 * If error detected, restore the previous value.
7835 */
7836 if (errmsg != NULL)
7837 {
7838 if (new_value_alloced)
7839 free_string_option(*varp);
7840 *varp = oldval;
7841 /*
7842 * When resetting some values, need to act on it.
7843 */
7844 if (did_chartab)
7845 (void)init_chartab();
7846 if (varp == &p_hl)
7847 (void)highlight_changed();
7848 }
7849 else
7850 {
7851#ifdef FEAT_EVAL
7852 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007853 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007854#endif
7855 /*
7856 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007857 * Use "free_oldval", because recursiveness may change the flags under
7858 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007860 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861 free_string_option(oldval);
7862 if (new_value_alloced)
7863 options[opt_idx].flags |= P_ALLOCED;
7864 else
7865 options[opt_idx].flags &= ~P_ALLOCED;
7866
7867 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007868 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869 {
7870 /* global option with local value set to use global value; free
7871 * the local value and make it empty */
7872 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7873 free_string_option(*(char_u **)p);
7874 *(char_u **)p = empty_option;
7875 }
7876
7877 /* May set global value for local option. */
7878 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7879 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007880
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007881 /*
7882 * Trigger the autocommand only after setting the flags.
7883 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007884#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007885 /* When 'syntax' is set, load the syntax of that name */
7886 if (varp == &(curbuf->b_p_syn))
7887 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007888 static int syn_recursive = 0;
7889
7890 ++syn_recursive;
7891 // Only pass TRUE for "force" when the value changed or not used
7892 // recursively, to avoid endless recurrence.
7893 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7894 value_changed || syn_recursive == 1, curbuf);
Bram Moolenaarc7f1e402019-08-03 13:29:46 +02007895 curbuf->b_flags |= BF_SYN_SET;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007896 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007897 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007898#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007899 else if (varp == &(curbuf->b_p_ft))
7900 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007901 /* 'filetype' is set, trigger the FileType autocommand.
7902 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007903 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007904 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007905 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007906 static int ft_recursive = 0;
7907 int secure_save = secure;
7908
7909 // Reset the secure flag, since the value of 'filetype' has
7910 // been checked to be safe.
7911 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007912
7913 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007914 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007915 // Only pass TRUE for "force" when the value changed or not
7916 // used recursively, to avoid endless recurrence.
7917 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7918 value_changed || ft_recursive == 1, curbuf);
7919 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007920 /* Just in case the old "curbuf" is now invalid. */
7921 if (varp != &(curbuf->b_p_ft))
7922 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007923
7924 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007925 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007926 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007927#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007928 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007929 {
7930 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007931 char_u *q = curwin->w_s->b_p_spl;
7932
7933 /* Skip the first name if it is "cjk". */
7934 if (STRNCMP(q, "cjk,", 4) == 0)
7935 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007936
7937 /*
7938 * Source the spell/LANG.vim in 'runtimepath'.
7939 * They could set 'spellcapcheck' depending on the language.
7940 * Use the first name in 'spelllang' up to '_region' or
7941 * '.encoding'.
7942 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007943 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01007944 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007945 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007946 if (p > q)
7947 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007948 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
7949 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01007950 source_runtime(fname, DIP_ALL);
7951 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007952 }
7953#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007954 }
7955
7956#ifdef FEAT_MOUSE
7957 if (varp == &p_mouse)
7958 {
7959# ifdef FEAT_MOUSE_TTY
7960 if (*p_mouse == NUL)
7961 mch_setmouse(FALSE); /* switch mouse off */
7962 else
7963# endif
7964 setmouse(); /* in case 'mouse' changed */
7965 }
7966#endif
7967
Bram Moolenaar913077c2012-03-28 19:59:04 +02007968 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01007969 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02007970 curwin->w_set_curswant = TRUE;
7971
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007972#ifdef FEAT_GUI
7973 /* check redraw when it's not a GUI option or the GUI is active. */
7974 if (!redraw_gui_only || gui.in_use)
7975#endif
7976 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007977
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007978#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7979 if (did_swaptcap)
7980 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007981 set_termname((char_u *)"win32");
7982 init_highlight(TRUE, FALSE);
7983 }
7984#endif
7985
Bram Moolenaar071d4272004-06-13 20:20:40 +00007986 return errmsg;
7987}
7988
Bram Moolenaar071d4272004-06-13 20:20:40 +00007989#ifdef FEAT_STL_OPT
7990/*
7991 * Check validity of options with the 'statusline' format.
7992 * Return error message or NULL.
7993 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +02007994 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01007995check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007996{
7997 int itemcnt = 0;
7998 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007999 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008000
8001 while (*s && itemcnt < STL_MAX_ITEM)
8002 {
8003 /* Check for valid keys after % sequences */
8004 while (*s && *s != '%')
8005 s++;
8006 if (!*s)
8007 break;
8008 s++;
8009 if (*s != '%' && *s != ')')
8010 ++itemcnt;
8011 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8012 {
8013 s++;
8014 continue;
8015 }
8016 if (*s == ')')
8017 {
8018 s++;
8019 if (--groupdepth < 0)
8020 break;
8021 continue;
8022 }
8023 if (*s == '-')
8024 s++;
8025 while (VIM_ISDIGIT(*s))
8026 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008027 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008028 continue;
8029 if (*s == '.')
8030 {
8031 s++;
8032 while (*s && VIM_ISDIGIT(*s))
8033 s++;
8034 }
8035 if (*s == '(')
8036 {
8037 groupdepth++;
8038 continue;
8039 }
8040 if (vim_strchr(STL_ALL, *s) == NULL)
8041 {
8042 return illegal_char(errbuf, *s);
8043 }
8044 if (*s == '{')
8045 {
8046 s++;
8047 while (*s != '}' && *s)
8048 s++;
8049 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008050 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008051 }
8052 }
8053 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008054 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008055 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008056 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008057 return NULL;
8058}
8059#endif
8060
8061#ifdef FEAT_CLIPBOARD
8062/*
8063 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008064 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008065 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008066 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008067check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008068{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008069 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008070 int new_autoselect_star = FALSE;
8071 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008072 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008073 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008074 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008075 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008076 char_u *p;
8077
8078 for (p = p_cb; *p != NUL; )
8079 {
8080 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8081 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008082 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008083 p += 7;
8084 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008085 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008086 && (p[11] == ',' || p[11] == NUL))
8087 {
8088 new_unnamed |= CLIP_UNNAMED_PLUS;
8089 p += 11;
8090 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008091 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008092 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008093 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008094 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008095 p += 10;
8096 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008097 else if (STRNCMP(p, "autoselectplus", 14) == 0
8098 && (p[14] == ',' || p[14] == NUL))
8099 {
8100 new_autoselect_plus = TRUE;
8101 p += 14;
8102 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008103 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008104 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008105 {
8106 new_autoselectml = TRUE;
8107 p += 12;
8108 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008109 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8110 {
8111 new_html = TRUE;
8112 p += 4;
8113 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008114 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8115 {
8116 p += 8;
8117 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8118 if (new_exclude_prog == NULL)
8119 errmsg = e_invarg;
8120 break;
8121 }
8122 else
8123 {
8124 errmsg = e_invarg;
8125 break;
8126 }
8127 if (*p == ',')
8128 ++p;
8129 }
8130 if (errmsg == NULL)
8131 {
8132 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008133 clip_autoselect_star = new_autoselect_star;
8134 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008135 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008136 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008137 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008138 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008139#ifdef FEAT_GUI_GTK
8140 if (gui.in_use)
8141 {
8142 gui_gtk_set_selection_targets();
8143 gui_gtk_set_dnd_targets();
8144 }
8145#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008146 }
8147 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008148 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008149
8150 return errmsg;
8151}
8152#endif
8153
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008154#if defined(FEAT_EVAL) || defined(PROTO)
8155/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008156 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008157 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008158 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008159 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008160set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008161{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008162 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8163 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008164 sctx_T new_script_ctx = script_ctx;
8165
8166 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008167
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008168 /* Remember where the option was set. For local options need to do that
8169 * in the buffer or window structure. */
8170 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008171 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008172 if (both || (opt_flags & OPT_LOCAL))
8173 {
8174 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008175 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008176 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008177 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008178 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008179}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008180
8181/*
8182 * Set the script_ctx for a termcap option.
8183 * "name" must be the two character code, e.g. "RV".
8184 * When "name" is NULL use "opt_idx".
8185 */
8186 void
8187set_term_option_sctx_idx(char *name, int opt_idx)
8188{
8189 char_u buf[5];
8190 int idx;
8191
8192 if (name == NULL)
8193 idx = opt_idx;
8194 else
8195 {
8196 buf[0] = 't';
8197 buf[1] = '_';
8198 buf[2] = name[0];
8199 buf[3] = name[1];
8200 buf[4] = 0;
8201 idx = findoption(buf);
8202 }
8203 if (idx >= 0)
8204 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8205}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008206#endif
8207
Bram Moolenaar071d4272004-06-13 20:20:40 +00008208/*
8209 * Set the value of a boolean option, and take care of side effects.
8210 * Returns NULL for success, or an error message for an error.
8211 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008212 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008213set_bool_option(
8214 int opt_idx, /* index in options[] table */
8215 char_u *varp, /* pointer to the option variable */
8216 int value, /* new value */
8217 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008218{
8219 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008220#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008221 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008222#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008223
Bram Moolenaar071d4272004-06-13 20:20:40 +00008224 /* Disallow changing some options from secure mode */
8225 if ((secure
8226#ifdef HAVE_SANDBOX
8227 || sandbox != 0
8228#endif
8229 ) && (options[opt_idx].flags & P_SECURE))
8230 return e_secure;
8231
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008232#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008233 // Save the global value before changing anything. This is needed as for
8234 // a global-only option setting the "local value" in fact sets the global
8235 // value (since there is only one value).
8236 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8237 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8238 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008239#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008240
Bram Moolenaar071d4272004-06-13 20:20:40 +00008241 *(int *)varp = value; /* set the new value */
8242#ifdef FEAT_EVAL
8243 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008244 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008245#endif
8246
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008247#ifdef FEAT_GUI
8248 need_mouse_correct = TRUE;
8249#endif
8250
Bram Moolenaar071d4272004-06-13 20:20:40 +00008251 /* May set global value for local option. */
8252 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8253 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8254
8255 /*
8256 * Handle side effects of changing a bool option.
8257 */
8258
8259 /* 'compatible' */
8260 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008261 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008262
Bram Moolenaar920694c2016-08-21 17:45:02 +02008263#ifdef FEAT_LANGMAP
8264 if ((int *)varp == &p_lrm)
8265 /* 'langremap' -> !'langnoremap' */
8266 p_lnr = !p_lrm;
8267 else if ((int *)varp == &p_lnr)
8268 /* 'langnoremap' -> !'langremap' */
8269 p_lrm = !p_lnr;
8270#endif
8271
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008272#ifdef FEAT_SYN_HL
8273 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8274 reset_cursorline();
8275#endif
8276
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008277#ifdef FEAT_PERSISTENT_UNDO
8278 /* 'undofile' */
8279 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8280 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008281 /* Only take action when the option was set. When reset we do not
8282 * delete the undo file, the option may be set again without making
8283 * any changes in between. */
8284 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008285 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008286 char_u hash[UNDO_HASH_SIZE];
8287 buf_T *save_curbuf = curbuf;
8288
Bram Moolenaar29323592016-07-24 22:04:11 +02008289 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008290 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008291 /* When 'undofile' is set globally: for every buffer, otherwise
8292 * only for the current buffer: Try to read in the undofile,
8293 * if one exists, the buffer wasn't changed and the buffer was
8294 * loaded */
8295 if ((curbuf == save_curbuf
8296 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8297 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8298 {
8299 u_compute_hash(hash);
8300 u_read_undo(NULL, hash, curbuf->b_fname);
8301 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008302 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008303 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008304 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008305 }
8306#endif
8307
Bram Moolenaar071d4272004-06-13 20:20:40 +00008308 else if ((int *)varp == &curbuf->b_p_ro)
8309 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008310 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008311 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8312 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008313
8314 /* when 'readonly' is set may give W10 again */
8315 if (curbuf->b_p_ro)
8316 curbuf->b_did_warn = FALSE;
8317
Bram Moolenaar071d4272004-06-13 20:20:40 +00008318#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008319 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320#endif
8321 }
8322
Bram Moolenaar9c449722010-07-20 18:44:27 +02008323#ifdef FEAT_GUI
8324 else if ((int *)varp == &p_mh)
8325 {
8326 if (!p_mh)
8327 gui_mch_mousehide(FALSE);
8328 }
8329#endif
8330
Bram Moolenaara539df02010-08-01 14:35:05 +02008331 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008332 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008333 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008334# ifdef FEAT_TERMINAL
8335 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008336 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8337 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008338 {
8339 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008340 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008341 }
8342# endif
8343# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008344 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008345# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008346 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008347#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008348 /* when 'endofline' is changed, redraw the window title */
8349 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008350 {
8351 redraw_titles();
8352 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008353 /* when 'fixeol' is changed, redraw the window title */
8354 else if ((int *)varp == &curbuf->b_p_fixeol)
8355 {
8356 redraw_titles();
8357 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008358 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008359 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008360 {
8361 redraw_titles();
8362 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008363#endif
8364
8365 /* when 'bin' is set also set some other options */
8366 else if ((int *)varp == &curbuf->b_p_bin)
8367 {
8368 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8369#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008370 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008371#endif
8372 }
8373
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374 /* when 'buflisted' changes, trigger autocommands */
8375 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8376 {
8377 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8378 NULL, NULL, TRUE, curbuf);
8379 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008380
8381 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8382 else if ((int *)varp == &curbuf->b_p_swf)
8383 {
8384 if (curbuf->b_p_swf && p_uc)
8385 ml_open_file(curbuf); /* create the swap file */
8386 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008387 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8388 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008389 mf_close_file(curbuf, TRUE); /* remove the swap file */
8390 }
8391
8392 /* when 'terse' is set change 'shortmess' */
8393 else if ((int *)varp == &p_terse)
8394 {
8395 char_u *p;
8396
8397 p = vim_strchr(p_shm, SHM_SEARCH);
8398
8399 /* insert 's' in p_shm */
8400 if (p_terse && p == NULL)
8401 {
8402 STRCPY(IObuff, p_shm);
8403 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008404 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008405 }
8406 /* remove 's' from p_shm */
8407 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008408 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008409 }
8410
8411 /* when 'paste' is set or reset also change other options */
8412 else if ((int *)varp == &p_paste)
8413 {
8414 paste_option_changed();
8415 }
8416
8417 /* when 'insertmode' is set from an autocommand need to do work here */
8418 else if ((int *)varp == &p_im)
8419 {
8420 if (p_im)
8421 {
8422 if ((State & INSERT) == 0)
8423 need_start_insertmode = TRUE;
8424 stop_insert_mode = FALSE;
8425 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008426 /* only reset if it was set previously */
8427 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008428 {
8429 need_start_insertmode = FALSE;
8430 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008431 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008432 clear_cmdline = TRUE; /* remove "(insert)" */
8433 restart_edit = 0;
8434 }
8435 }
8436
8437 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8438 else if ((int *)varp == &p_ic && p_hls)
8439 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008440 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008441 }
8442
8443#ifdef FEAT_SEARCH_EXTRA
8444 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8445 else if ((int *)varp == &p_hls)
8446 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008447 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008448 }
8449#endif
8450
Bram Moolenaar071d4272004-06-13 20:20:40 +00008451 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8452 * at the end of normal_cmd() */
8453 else if ((int *)varp == &curwin->w_p_scb)
8454 {
8455 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008456 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008457 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008458 curwin->w_scbind_pos = curwin->w_topline;
8459 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008460 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008461
Bram Moolenaar4033c552017-09-16 20:54:51 +02008462#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008463 /* There can be only one window with 'previewwindow' set. */
8464 else if ((int *)varp == &curwin->w_p_pvw)
8465 {
8466 if (curwin->w_p_pvw)
8467 {
8468 win_T *win;
8469
Bram Moolenaar29323592016-07-24 22:04:11 +02008470 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008471 if (win->w_p_pvw && win != curwin)
8472 {
8473 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008474 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008475 }
8476 }
8477 }
8478#endif
8479
8480 /* when 'textmode' is set or reset also change 'fileformat' */
8481 else if ((int *)varp == &curbuf->b_p_tx)
8482 {
8483 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8484 }
8485
8486 /* when 'textauto' is set or reset also change 'fileformats' */
8487 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008488 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008489 set_string_option_direct((char_u *)"ffs", -1,
8490 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008491 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008492 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008493
8494 /*
8495 * When 'lisp' option changes include/exclude '-' in
8496 * keyword characters.
8497 */
8498#ifdef FEAT_LISP
8499 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8500 {
8501 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8502 }
8503#endif
8504
8505#ifdef FEAT_TITLE
8506 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008507 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008508 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008509 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008510 }
8511#endif
8512
8513 else if ((int *)varp == &curbuf->b_changed)
8514 {
8515 if (!value)
8516 save_file_ff(curbuf); /* Buffer is unchanged */
8517#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008518 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008519#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008520 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008521 }
8522
8523#ifdef BACKSLASH_IN_FILENAME
8524 else if ((int *)varp == &p_ssl)
8525 {
8526 if (p_ssl)
8527 {
8528 psepc = '/';
8529 psepcN = '\\';
8530 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008531 }
8532 else
8533 {
8534 psepc = '\\';
8535 psepcN = '/';
8536 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008537 }
8538
8539 /* need to adjust the file name arguments and buffer names. */
8540 buflist_slash_adjust();
8541 alist_slash_adjust();
8542# ifdef FEAT_EVAL
8543 scriptnames_slash_adjust();
8544# endif
8545 }
8546#endif
8547
8548 /* If 'wrap' is set, set w_leftcol to zero. */
8549 else if ((int *)varp == &curwin->w_p_wrap)
8550 {
8551 if (curwin->w_p_wrap)
8552 curwin->w_leftcol = 0;
8553 }
8554
Bram Moolenaar071d4272004-06-13 20:20:40 +00008555 else if ((int *)varp == &p_ea)
8556 {
8557 if (p_ea && !old_value)
8558 win_equal(curwin, FALSE, 0);
8559 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008560
8561 else if ((int *)varp == &p_wiv)
8562 {
8563 /*
8564 * When 'weirdinvert' changed, set/reset 't_xs'.
8565 * Then set 'weirdinvert' according to value of 't_xs'.
8566 */
8567 if (p_wiv && !old_value)
8568 T_XS = (char_u *)"y";
8569 else if (!p_wiv && old_value)
8570 T_XS = empty_option;
8571 p_wiv = (*T_XS != NUL);
8572 }
8573
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008574#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575 else if ((int *)varp == &p_beval)
8576 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008577 if (!balloonEvalForTerm)
8578 {
8579 if (p_beval && !old_value)
8580 gui_mch_enable_beval_area(balloonEval);
8581 else if (!p_beval && old_value)
8582 gui_mch_disable_beval_area(balloonEval);
8583 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008584 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008585#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008586#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008587 else if ((int *)varp == &p_bevalterm)
8588 {
8589 mch_bevalterm_changed();
8590 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008591#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008592
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008593#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008594 else if ((int *)varp == &p_acd)
8595 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008596 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008597 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008598 }
8599#endif
8600
8601#ifdef FEAT_DIFF
8602 /* 'diff' */
8603 else if ((int *)varp == &curwin->w_p_diff)
8604 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008605 /* May add or remove the buffer from the list of diff buffers. */
8606 diff_buf_adjust(curwin);
8607# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008608 if (foldmethodIsDiff(curwin))
8609 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008610# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008611 }
8612#endif
8613
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008614#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008615 /* 'imdisable' */
8616 else if ((int *)varp == &p_imdisable)
8617 {
8618 /* Only de-activate it here, it will be enabled when changing mode. */
8619 if (p_imdisable)
8620 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008621 else if (State & INSERT)
8622 /* When the option is set from an autocommand, it may need to take
8623 * effect right away. */
8624 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008625 }
8626#endif
8627
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008628#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008629 /* 'spell' */
8630 else if ((int *)varp == &curwin->w_p_spell)
8631 {
8632 if (curwin->w_p_spell)
8633 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008634 char *errmsg = did_set_spelllang(curwin);
8635
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008636 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008637 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008638 }
8639 }
8640#endif
8641
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642#ifdef FEAT_ARABIC
8643 if ((int *)varp == &curwin->w_p_arab)
8644 {
8645 if (curwin->w_p_arab)
8646 {
8647 /*
8648 * 'arabic' is set, handle various sub-settings.
8649 */
8650 if (!p_tbidi)
8651 {
8652 /* set rightleft mode */
8653 if (!curwin->w_p_rl)
8654 {
8655 curwin->w_p_rl = TRUE;
8656 changed_window_setting();
8657 }
8658
8659 /* Enable Arabic shaping (major part of what Arabic requires) */
8660 if (!p_arshape)
8661 {
8662 p_arshape = TRUE;
8663 redraw_later_clear();
8664 }
8665 }
8666
8667 /* Arabic requires a utf-8 encoding, inform the user if its not
8668 * set. */
8669 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008670 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00008671 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
8672
Bram Moolenaar8820b482017-03-16 17:23:31 +01008673 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01008674 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00008675#ifdef FEAT_EVAL
8676 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
8677#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008678 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008679
Bram Moolenaar071d4272004-06-13 20:20:40 +00008680 /* set 'delcombine' */
8681 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682
8683# ifdef FEAT_KEYMAP
8684 /* Force-set the necessary keymap for arabic */
8685 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
8686 OPT_LOCAL);
8687# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008688 }
8689 else
8690 {
8691 /*
8692 * 'arabic' is reset, handle various sub-settings.
8693 */
8694 if (!p_tbidi)
8695 {
8696 /* reset rightleft mode */
8697 if (curwin->w_p_rl)
8698 {
8699 curwin->w_p_rl = FALSE;
8700 changed_window_setting();
8701 }
8702
8703 /* 'arabicshape' isn't reset, it is a global option and
8704 * another window may still need it "on". */
8705 }
8706
8707 /* 'delcombine' isn't reset, it is a global option and another
8708 * window may still want it "on". */
8709
8710# ifdef FEAT_KEYMAP
8711 /* Revert to the default keymap */
8712 curbuf->b_p_iminsert = B_IMODE_NONE;
8713 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
8714# endif
8715 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00008716 }
8717
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00008718#endif
8719
Bram Moolenaar44826212019-08-22 21:23:20 +02008720#if defined(FEAT_SIGNS) && defined(FEAT_GUI)
8721 else if (((int *)varp == &curwin->w_p_nu
8722 || (int *)varp == &curwin->w_p_rnu)
8723 && gui.in_use
8724 && (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) == 'u')
8725 && curbuf->b_signlist != NULL)
8726 {
8727 // If the 'number' or 'relativenumber' options are modified and
8728 // 'signcolumn' is set to 'number', then clear the screen for a full
8729 // refresh. Otherwise the sign icons are not displayed properly in the
8730 // number column. If the 'number' option is set and only the
8731 // 'relativenumber' option is toggled, then don't refresh the screen
8732 // (optimization).
8733 if (!(curwin->w_p_nu && ((int *)varp == &curwin->w_p_rnu)))
8734 redraw_all_later(CLEAR);
8735 }
8736#endif
8737
Bram Moolenaar61be73b2016-04-29 22:59:22 +02008738#ifdef FEAT_TERMGUICOLORS
8739 /* 'termguicolors' */
8740 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008741 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008742# ifdef FEAT_VTP
8743 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02008744 if (
8745# ifdef VIMDLL
8746 !gui.in_use && !gui.starting &&
8747# endif
8748 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008749 {
8750 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01008751 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008752 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008753 if (is_term_win32())
8754 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008755# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008756# ifdef FEAT_GUI
8757 if (!gui.in_use && !gui.starting)
8758# endif
8759 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008760# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008761 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008762 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008763 {
8764 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008765 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02008766 init_highlight(TRUE, FALSE);
8767 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01008768# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02008769 }
8770#endif
8771
Bram Moolenaar071d4272004-06-13 20:20:40 +00008772 /*
8773 * End of handling side effects for bool options.
8774 */
8775
Bram Moolenaar53744302015-07-17 17:38:22 +02008776 /* after handling side effects, call autocommand */
8777
Bram Moolenaar071d4272004-06-13 20:20:40 +00008778 options[opt_idx].flags |= P_WAS_SET;
8779
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008780#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008781 // Don't do this while starting up or recursively.
8782 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02008783 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02008784 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02008785
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008786 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02008787 vim_snprintf((char *)buf_old_global, 2, "%d",
8788 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02008789 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02008790 vim_snprintf((char *)buf_type, 7, "%s",
8791 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02008792 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
8793 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
8794 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02008795 if (opt_flags & OPT_LOCAL)
8796 {
8797 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
8798 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
8799 }
8800 if (opt_flags & OPT_GLOBAL)
8801 {
8802 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
8803 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
8804 }
8805 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8806 {
8807 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
8808 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
8809 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
8810 }
8811 if (opt_flags & OPT_MODELINE)
8812 {
8813 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
8814 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
8815 }
8816 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
8817 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02008818 reset_v_option_vars();
8819 }
8820#endif
8821
Bram Moolenaar071d4272004-06-13 20:20:40 +00008822 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02008823 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008824 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008825 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008826 check_redraw(options[opt_idx].flags);
8827
8828 return NULL;
8829}
8830
8831/*
8832 * Set the value of a number option, and take care of side effects.
8833 * Returns NULL for success, or an error message for an error.
8834 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008835 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008836set_num_option(
8837 int opt_idx, /* index in options[] table */
8838 char_u *varp, /* pointer to the option variable */
8839 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008840 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01008841 size_t errbuflen, /* length of "errbuf" */
8842 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00008843 OPT_MODELINE */
8844{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008845 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008846 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008847#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008848 long old_global_value = 0; // only used when setting a local and
8849 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008850#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008851 long old_Rows = Rows; // remember old Rows
8852 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853 long *pp = (long *)varp;
8854
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008855 /* Disallow changing some options from secure mode. */
8856 if ((secure
8857#ifdef HAVE_SANDBOX
8858 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00008859#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008860 ) && (options[opt_idx].flags & P_SECURE))
8861 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008862
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008863#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008864 // Save the global value before changing anything. This is needed as for
8865 // a global-only option setting the "local value" infact sets the global
8866 // value (since there is only one value).
8867 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008868 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
8869 OPT_GLOBAL);
8870#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008871
Bram Moolenaar071d4272004-06-13 20:20:40 +00008872 *pp = value;
8873#ifdef FEAT_EVAL
8874 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008875 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008876#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008877#ifdef FEAT_GUI
8878 need_mouse_correct = TRUE;
8879#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008880
Bram Moolenaar14f24742012-08-08 18:01:05 +02008881 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008882 {
8883 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008884#ifdef FEAT_VARTABS
8885 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
8886 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
8887 ? tabstop_first(curbuf->b_p_vts_array)
8888 : curbuf->b_p_ts;
8889#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00008890 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02008891#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008892 }
8893
8894 /*
8895 * Number options that need some action when changed
8896 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008897 if (pp == &p_wh || pp == &p_hh)
8898 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008899 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008900 if (p_wh < 1)
8901 {
8902 errmsg = e_positive;
8903 p_wh = 1;
8904 }
8905 if (p_wmh > p_wh)
8906 {
8907 errmsg = e_winheight;
8908 p_wh = p_wmh;
8909 }
8910 if (p_hh < 0)
8911 {
8912 errmsg = e_positive;
8913 p_hh = 0;
8914 }
8915
8916 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008917 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918 {
8919 if (pp == &p_wh && curwin->w_height < p_wh)
8920 win_setheight((int)p_wh);
8921 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
8922 win_setheight((int)p_hh);
8923 }
8924 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008925 else if (pp == &p_wmh)
8926 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008927 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928 if (p_wmh < 0)
8929 {
8930 errmsg = e_positive;
8931 p_wmh = 0;
8932 }
8933 if (p_wmh > p_wh)
8934 {
8935 errmsg = e_winheight;
8936 p_wmh = p_wh;
8937 }
8938 win_setminheight();
8939 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00008940 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008941 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008942 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008943 if (p_wiw < 1)
8944 {
8945 errmsg = e_positive;
8946 p_wiw = 1;
8947 }
8948 if (p_wmw > p_wiw)
8949 {
8950 errmsg = e_winwidth;
8951 p_wiw = p_wmw;
8952 }
8953
8954 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01008955 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008956 win_setwidth((int)p_wiw);
8957 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008958 else if (pp == &p_wmw)
8959 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008960 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00008961 if (p_wmw < 0)
8962 {
8963 errmsg = e_positive;
8964 p_wmw = 0;
8965 }
8966 if (p_wmw > p_wiw)
8967 {
8968 errmsg = e_winwidth;
8969 p_wmw = p_wiw;
8970 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02008971 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008972 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008973
Bram Moolenaar071d4272004-06-13 20:20:40 +00008974 /* (re)set last window status line */
8975 else if (pp == &p_ls)
8976 {
8977 last_status(FALSE);
8978 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008979
8980 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00008981 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00008982 {
8983 shell_new_rows(); /* recompute window positions and heights */
8984 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008985
8986#ifdef FEAT_GUI
8987 else if (pp == &p_linespace)
8988 {
Bram Moolenaar02743632005-07-25 20:42:36 +00008989 /* Recompute gui.char_height and resize the Vim window to keep the
8990 * same number of lines. */
8991 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00008992 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008993 }
8994#endif
8995
8996#ifdef FEAT_FOLDING
8997 /* 'foldlevel' */
8998 else if (pp == &curwin->w_p_fdl)
8999 {
9000 if (curwin->w_p_fdl < 0)
9001 curwin->w_p_fdl = 0;
9002 newFoldLevel();
9003 }
9004
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009005 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009006 else if (pp == &curwin->w_p_fml)
9007 {
9008 foldUpdateAll(curwin);
9009 }
9010
9011 /* 'foldnestmax' */
9012 else if (pp == &curwin->w_p_fdn)
9013 {
9014 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9015 foldUpdateAll(curwin);
9016 }
9017
9018 /* 'foldcolumn' */
9019 else if (pp == &curwin->w_p_fdc)
9020 {
9021 if (curwin->w_p_fdc < 0)
9022 {
9023 errmsg = e_positive;
9024 curwin->w_p_fdc = 0;
9025 }
9026 else if (curwin->w_p_fdc > 12)
9027 {
9028 errmsg = e_invarg;
9029 curwin->w_p_fdc = 12;
9030 }
9031 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009032#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009033
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009034#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009035 /* 'shiftwidth' or 'tabstop' */
9036 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9037 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009038# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009039 if (foldmethodIsIndent(curwin))
9040 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009041# endif
9042# ifdef FEAT_CINDENT
9043 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9044 * parse 'cinoptions'. */
9045 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9046 parse_cino(curbuf);
9047# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009048 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009049#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009050
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009051 /* 'maxcombine' */
9052 else if (pp == &p_mco)
9053 {
9054 if (p_mco > MAX_MCO)
9055 p_mco = MAX_MCO;
9056 else if (p_mco < 0)
9057 p_mco = 0;
9058 screenclear(); /* will re-allocate the screen */
9059 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009060
Bram Moolenaar071d4272004-06-13 20:20:40 +00009061 else if (pp == &curbuf->b_p_iminsert)
9062 {
9063 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9064 {
9065 errmsg = e_invarg;
9066 curbuf->b_p_iminsert = B_IMODE_NONE;
9067 }
9068 p_iminsert = curbuf->b_p_iminsert;
9069 if (termcap_active) /* don't do this in the alternate screen */
9070 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009071#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009072 /* Show/unshow value of 'keymap' in status lines. */
9073 status_redraw_curbuf();
9074#endif
9075 }
9076
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009077#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9078 /* 'imstyle' */
9079 else if (pp == &p_imst)
9080 {
9081 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9082 errmsg = e_invarg;
9083 }
9084#endif
9085
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009086 else if (pp == &p_window)
9087 {
9088 if (p_window < 1)
9089 p_window = 1;
9090 else if (p_window >= Rows)
9091 p_window = Rows - 1;
9092 }
9093
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094 else if (pp == &curbuf->b_p_imsearch)
9095 {
9096 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9097 {
9098 errmsg = e_invarg;
9099 curbuf->b_p_imsearch = B_IMODE_NONE;
9100 }
9101 p_imsearch = curbuf->b_p_imsearch;
9102 }
9103
9104#ifdef FEAT_TITLE
9105 /* if 'titlelen' has changed, redraw the title */
9106 else if (pp == &p_titlelen)
9107 {
9108 if (p_titlelen < 0)
9109 {
9110 errmsg = e_positive;
9111 p_titlelen = 85;
9112 }
9113 if (starting != NO_SCREEN && old_value != p_titlelen)
9114 need_maketitle = TRUE;
9115 }
9116#endif
9117
9118 /* if p_ch changed value, change the command line height */
9119 else if (pp == &p_ch)
9120 {
9121 if (p_ch < 1)
9122 {
9123 errmsg = e_positive;
9124 p_ch = 1;
9125 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009126 if (p_ch > Rows - min_rows() + 1)
9127 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009128
9129 /* Only compute the new window layout when startup has been
9130 * completed. Otherwise the frame sizes may be wrong. */
9131 if (p_ch != old_value && full_screen
9132#ifdef FEAT_GUI
9133 && !gui.starting
9134#endif
9135 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009136 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009137 }
9138
9139 /* when 'updatecount' changes from zero to non-zero, open swap files */
9140 else if (pp == &p_uc)
9141 {
9142 if (p_uc < 0)
9143 {
9144 errmsg = e_positive;
9145 p_uc = 100;
9146 }
9147 if (p_uc && !old_value)
9148 ml_open_files();
9149 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009150#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009151 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009152 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009153 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009154 {
9155 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009156 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009157 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009158 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009159 {
9160 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009161 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009162 }
9163 }
9164#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009165#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009166 else if (pp == &p_mzq)
9167 mzvim_reset_timer();
9168#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009169
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009170#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9171 /* 'pyxversion' */
9172 else if (pp == &p_pyx)
9173 {
9174 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9175 errmsg = e_invarg;
9176 }
9177#endif
9178
Bram Moolenaar071d4272004-06-13 20:20:40 +00009179 /* sync undo before 'undolevels' changes */
9180 else if (pp == &p_ul)
9181 {
9182 /* use the old value, otherwise u_sync() may not work properly */
9183 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009184 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009185 p_ul = value;
9186 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009187 else if (pp == &curbuf->b_p_ul)
9188 {
9189 /* use the old value, otherwise u_sync() may not work properly */
9190 curbuf->b_p_ul = old_value;
9191 u_sync(TRUE);
9192 curbuf->b_p_ul = value;
9193 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009194
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009195#ifdef FEAT_LINEBREAK
9196 /* 'numberwidth' must be positive */
9197 else if (pp == &curwin->w_p_nuw)
9198 {
9199 if (curwin->w_p_nuw < 1)
9200 {
9201 errmsg = e_positive;
9202 curwin->w_p_nuw = 1;
9203 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009204 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009205 {
9206 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009207 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009208 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009209 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009210 }
9211#endif
9212
Bram Moolenaar1a384422010-07-14 19:53:30 +02009213 else if (pp == &curbuf->b_p_tw)
9214 {
9215 if (curbuf->b_p_tw < 0)
9216 {
9217 errmsg = e_positive;
9218 curbuf->b_p_tw = 0;
9219 }
9220#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009221 {
9222 win_T *wp;
9223 tabpage_T *tp;
9224
9225 FOR_ALL_TAB_WINDOWS(tp, wp)
9226 check_colorcolumn(wp);
9227 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009228#endif
9229 }
9230
Bram Moolenaar071d4272004-06-13 20:20:40 +00009231 /*
9232 * Check the bounds for numeric options here
9233 */
9234 if (Rows < min_rows() && full_screen)
9235 {
9236 if (errbuf != NULL)
9237 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009238 vim_snprintf((char *)errbuf, errbuflen,
9239 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009240 errmsg = errbuf;
9241 }
9242 Rows = min_rows();
9243 }
9244 if (Columns < MIN_COLUMNS && full_screen)
9245 {
9246 if (errbuf != NULL)
9247 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009248 vim_snprintf((char *)errbuf, errbuflen,
9249 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009250 errmsg = errbuf;
9251 }
9252 Columns = MIN_COLUMNS;
9253 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009254 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009255
Bram Moolenaar071d4272004-06-13 20:20:40 +00009256 /*
9257 * If the screen (shell) height has been changed, assume it is the
9258 * physical screenheight.
9259 */
9260 if (old_Rows != Rows || old_Columns != Columns)
9261 {
9262 /* Changing the screen size is not allowed while updating the screen. */
9263 if (updating_screen)
9264 *pp = old_value;
9265 else if (full_screen
9266#ifdef FEAT_GUI
9267 && !gui.starting
9268#endif
9269 )
9270 set_shellsize((int)Columns, (int)Rows, TRUE);
9271 else
9272 {
9273 /* Postpone the resizing; check the size and cmdline position for
9274 * messages. */
9275 check_shellsize();
9276 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9277 cmdline_row = Rows - p_ch;
9278 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009279 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009280 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009281 }
9282
Bram Moolenaar071d4272004-06-13 20:20:40 +00009283 if (curbuf->b_p_ts <= 0)
9284 {
9285 errmsg = e_positive;
9286 curbuf->b_p_ts = 8;
9287 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009288 if (p_tm < 0)
9289 {
9290 errmsg = e_positive;
9291 p_tm = 0;
9292 }
9293 if ((curwin->w_p_scr <= 0
9294 || (curwin->w_p_scr > curwin->w_height
9295 && curwin->w_height > 0))
9296 && full_screen)
9297 {
9298 if (pp == &(curwin->w_p_scr))
9299 {
9300 if (curwin->w_p_scr != 0)
9301 errmsg = e_scroll;
9302 win_comp_scroll(curwin);
9303 }
9304 /* If 'scroll' became invalid because of a side effect silently adjust
9305 * it. */
9306 else if (curwin->w_p_scr <= 0)
9307 curwin->w_p_scr = 1;
9308 else /* curwin->w_p_scr > curwin->w_height */
9309 curwin->w_p_scr = curwin->w_height;
9310 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009311 if (p_hi < 0)
9312 {
9313 errmsg = e_positive;
9314 p_hi = 0;
9315 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009316 else if (p_hi > 10000)
9317 {
9318 errmsg = e_invarg;
9319 p_hi = 10000;
9320 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009321 if (p_re < 0 || p_re > 2)
9322 {
9323 errmsg = e_invarg;
9324 p_re = 0;
9325 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009326 if (p_report < 0)
9327 {
9328 errmsg = e_positive;
9329 p_report = 1;
9330 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009331 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009332 {
9333 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9334 p_sj = Rows / 2;
9335 else
9336 {
9337 errmsg = e_scroll;
9338 p_sj = 1;
9339 }
9340 }
9341 if (p_so < 0 && full_screen)
9342 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009343 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009344 p_so = 0;
9345 }
9346 if (p_siso < 0 && full_screen)
9347 {
9348 errmsg = e_positive;
9349 p_siso = 0;
9350 }
9351#ifdef FEAT_CMDWIN
9352 if (p_cwh < 1)
9353 {
9354 errmsg = e_positive;
9355 p_cwh = 1;
9356 }
9357#endif
9358 if (p_ut < 0)
9359 {
9360 errmsg = e_positive;
9361 p_ut = 2000;
9362 }
9363 if (p_ss < 0)
9364 {
9365 errmsg = e_positive;
9366 p_ss = 0;
9367 }
9368
9369 /* May set global value for local option. */
9370 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9371 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9372
9373 options[opt_idx].flags |= P_WAS_SET;
9374
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009375#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009376 // Don't do this while starting up, failure or recursively.
9377 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009378 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009379 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009380 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009381 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009382 vim_snprintf((char *)buf_new, 10, "%ld", value);
9383 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009384 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9385 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9386 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009387 if (opt_flags & OPT_LOCAL)
9388 {
9389 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9390 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9391 }
9392 if (opt_flags & OPT_GLOBAL)
9393 {
9394 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9395 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9396 }
9397 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9398 {
9399 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9400 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9401 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9402 }
9403 if (opt_flags & OPT_MODELINE)
9404 {
9405 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9406 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9407 }
9408 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9409 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009410 reset_v_option_vars();
9411 }
9412#endif
9413
Bram Moolenaar071d4272004-06-13 20:20:40 +00009414 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009415 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009416 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009417 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009418 check_redraw(options[opt_idx].flags);
9419
9420 return errmsg;
9421}
9422
9423/*
9424 * Called after an option changed: check if something needs to be redrawn.
9425 */
9426 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009427check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009428{
9429 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009430 int doclear = (flags & P_RCLR) == P_RCLR;
9431 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009432
Bram Moolenaar071d4272004-06-13 20:20:40 +00009433 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9434 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009435
9436 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9437 changed_window_setting();
9438 if (flags & P_RBUF)
9439 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009440 if (flags & P_RWINONLY)
9441 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009442 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009443 redraw_all_later(CLEAR);
9444 else if (all)
9445 redraw_all_later(NOT_VALID);
9446}
9447
9448/*
9449 * Find index for option 'arg'.
9450 * Return -1 if not found.
9451 */
9452 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009453findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009454{
9455 int opt_idx;
9456 char *s, *p;
9457 static short quick_tab[27] = {0, 0}; /* quick access table */
9458 int is_term_opt;
9459
9460 /*
9461 * For first call: Initialize the quick-access table.
9462 * It contains the index for the first option that starts with a certain
9463 * letter. There are 26 letters, plus the first "t_" option.
9464 */
9465 if (quick_tab[1] == 0)
9466 {
9467 p = options[0].fullname;
9468 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9469 {
9470 if (s[0] != p[0])
9471 {
9472 if (s[0] == 't' && s[1] == '_')
9473 quick_tab[26] = opt_idx;
9474 else
9475 quick_tab[CharOrdLow(s[0])] = opt_idx;
9476 }
9477 p = s;
9478 }
9479 }
9480
9481 /*
9482 * Check for name starting with an illegal character.
9483 */
9484#ifdef EBCDIC
9485 if (!islower(arg[0]))
9486#else
9487 if (arg[0] < 'a' || arg[0] > 'z')
9488#endif
9489 return -1;
9490
9491 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9492 if (is_term_opt)
9493 opt_idx = quick_tab[26];
9494 else
9495 opt_idx = quick_tab[CharOrdLow(arg[0])];
9496 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9497 {
9498 if (STRCMP(arg, s) == 0) /* match full name */
9499 break;
9500 }
9501 if (s == NULL && !is_term_opt)
9502 {
9503 opt_idx = quick_tab[CharOrdLow(arg[0])];
9504 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9505 {
9506 s = options[opt_idx].shortname;
9507 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9508 break;
9509 s = NULL;
9510 }
9511 }
9512 if (s == NULL)
9513 opt_idx = -1;
9514 return opt_idx;
9515}
9516
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009517#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009518/*
9519 * Get the value for an option.
9520 *
9521 * Returns:
9522 * Number or Toggle option: 1, *numval gets value.
9523 * String option: 0, *stringval gets allocated string.
9524 * Hidden Number or Toggle option: -1.
9525 * hidden String option: -2.
9526 * unknown option: -3.
9527 */
9528 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009529get_option_value(
9530 char_u *name,
9531 long *numval,
9532 char_u **stringval, /* NULL when only checking existence */
9533 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009534{
9535 int opt_idx;
9536 char_u *varp;
9537
9538 opt_idx = findoption(name);
9539 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009540 {
9541 int key;
9542
9543 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009544 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009545 {
9546 char_u key_name[2];
9547 char_u *p;
9548
9549 if (key < 0)
9550 {
9551 key_name[0] = KEY2TERMCAP0(key);
9552 key_name[1] = KEY2TERMCAP1(key);
9553 }
9554 else
9555 {
9556 key_name[0] = KS_KEY;
9557 key_name[1] = (key & 0xff);
9558 }
9559 p = find_termcode(key_name);
9560 if (p != NULL)
9561 {
9562 if (stringval != NULL)
9563 *stringval = vim_strsave(p);
9564 return 0;
9565 }
9566 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009567 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009568 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009569
9570 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9571
9572 if (options[opt_idx].flags & P_STRING)
9573 {
9574 if (varp == NULL) /* hidden option */
9575 return -2;
9576 if (stringval != NULL)
9577 {
9578#ifdef FEAT_CRYPT
9579 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009580 if ((char_u **)varp == &curbuf->b_p_key
9581 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009582 *stringval = vim_strsave((char_u *)"*****");
9583 else
9584#endif
9585 *stringval = vim_strsave(*(char_u **)(varp));
9586 }
9587 return 0;
9588 }
9589
9590 if (varp == NULL) /* hidden option */
9591 return -1;
9592 if (options[opt_idx].flags & P_NUM)
9593 *numval = *(long *)varp;
9594 else
9595 {
9596 /* Special case: 'modified' is b_changed, but we also want to consider
9597 * it set when 'ff' or 'fenc' changed. */
9598 if ((int *)varp == &curbuf->b_changed)
9599 *numval = curbufIsChanged();
9600 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009601 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009602 }
9603 return 1;
9604}
9605#endif
9606
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009607#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009608/*
9609 * Returns the option attributes and its value. Unlike the above function it
9610 * will return either global value or local value of the option depending on
9611 * what was requested, but it will never return global value if it was
9612 * requested to return local one and vice versa. Neither it will return
9613 * buffer-local value if it was requested to return window-local one.
9614 *
9615 * Pretends that option is absent if it is not present in the requested scope
9616 * (i.e. has no global, window-local or buffer-local value depending on
9617 * opt_type). Uses
9618 *
9619 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009620 * 0 hidden or unknown option, also option that does not have requested
9621 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009622 * see SOPT_* in vim.h for other flags
9623 *
9624 * Possible opt_type values: see SREQ_* in vim.h
9625 */
9626 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009627get_option_value_strict(
9628 char_u *name,
9629 long *numval,
9630 char_u **stringval, /* NULL when only obtaining attributes */
9631 int opt_type,
9632 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009633{
9634 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009635 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009636 struct vimoption *p;
9637 int r = 0;
9638
9639 opt_idx = findoption(name);
9640 if (opt_idx < 0)
9641 return 0;
9642
9643 p = &(options[opt_idx]);
9644
9645 /* Hidden option */
9646 if (p->var == NULL)
9647 return 0;
9648
9649 if (p->flags & P_BOOL)
9650 r |= SOPT_BOOL;
9651 else if (p->flags & P_NUM)
9652 r |= SOPT_NUM;
9653 else if (p->flags & P_STRING)
9654 r |= SOPT_STRING;
9655
9656 if (p->indir == PV_NONE)
9657 {
9658 if (opt_type == SREQ_GLOBAL)
9659 r |= SOPT_GLOBAL;
9660 else
9661 return 0; /* Did not request global-only option */
9662 }
9663 else
9664 {
9665 if (p->indir & PV_BOTH)
9666 r |= SOPT_GLOBAL;
9667 else if (opt_type == SREQ_GLOBAL)
9668 return 0; /* Requested global option */
9669
9670 if (p->indir & PV_WIN)
9671 {
9672 if (opt_type == SREQ_BUF)
9673 return 0; /* Did not request window-local option */
9674 else
9675 r |= SOPT_WIN;
9676 }
9677 else if (p->indir & PV_BUF)
9678 {
9679 if (opt_type == SREQ_WIN)
9680 return 0; /* Did not request buffer-local option */
9681 else
9682 r |= SOPT_BUF;
9683 }
9684 }
9685
9686 if (stringval == NULL)
9687 return r;
9688
9689 if (opt_type == SREQ_GLOBAL)
9690 varp = p->var;
9691 else
9692 {
9693 if (opt_type == SREQ_BUF)
9694 {
9695 /* Special case: 'modified' is b_changed, but we also want to
9696 * consider it set when 'ff' or 'fenc' changed. */
9697 if (p->indir == PV_MOD)
9698 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009699 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009700 varp = NULL;
9701 }
9702#ifdef FEAT_CRYPT
9703 else if (p->indir == PV_KEY)
9704 {
9705 /* never return the value of the crypt key */
9706 *stringval = NULL;
9707 varp = NULL;
9708 }
9709#endif
9710 else
9711 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009712 buf_T *save_curbuf = curbuf;
9713
9714 // only getting a pointer, no need to use aucmd_prepbuf()
9715 curbuf = (buf_T *)from;
9716 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009717 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +02009718 curbuf = save_curbuf;
9719 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009720 }
9721 }
9722 else if (opt_type == SREQ_WIN)
9723 {
Bram Moolenaardefe6422018-06-24 15:14:07 +02009724 win_T *save_curwin = curwin;
9725
9726 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009727 curbuf = curwin->w_buffer;
9728 varp = get_varp(p);
9729 curwin = save_curwin;
9730 curbuf = curwin->w_buffer;
9731 }
9732 if (varp == p->var)
9733 return (r | SOPT_UNSET);
9734 }
9735
9736 if (varp != NULL)
9737 {
9738 if (p->flags & P_STRING)
9739 *stringval = vim_strsave(*(char_u **)(varp));
9740 else if (p->flags & P_NUM)
9741 *numval = *(long *) varp;
9742 else
9743 *numval = *(int *)varp;
9744 }
9745
9746 return r;
9747}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009748
9749/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009750 * Iterate over options. First argument is a pointer to a pointer to a
9751 * structure inside options[] array, second is option type like in the above
9752 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009753 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009754 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009755 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02009756 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009757 * first argument to NULL.
9758 *
9759 * Returns full option name for current option on each call.
9760 */
9761 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009762option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009763{
9764 struct vimoption *ret = NULL;
9765 do
9766 {
9767 if (*option == NULL)
9768 *option = (void *) options;
9769 else if (((struct vimoption *) (*option))->fullname == NULL)
9770 {
9771 *option = NULL;
9772 return NULL;
9773 }
9774 else
9775 *option = (void *) (((struct vimoption *) (*option)) + 1);
9776
9777 ret = ((struct vimoption *) (*option));
9778
9779 /* Hidden option */
9780 if (ret->var == NULL)
9781 {
9782 ret = NULL;
9783 continue;
9784 }
9785
9786 switch (opt_type)
9787 {
9788 case SREQ_GLOBAL:
9789 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
9790 ret = NULL;
9791 break;
9792 case SREQ_BUF:
9793 if (!(ret->indir & PV_BUF))
9794 ret = NULL;
9795 break;
9796 case SREQ_WIN:
9797 if (!(ret->indir & PV_WIN))
9798 ret = NULL;
9799 break;
9800 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +01009801 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009802 return NULL;
9803 }
9804 }
9805 while (ret == NULL);
9806
9807 return (char_u *)ret->fullname;
9808}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009809#endif
9810
Bram Moolenaar071d4272004-06-13 20:20:40 +00009811/*
9812 * Set the value of option "name".
9813 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009814 *
9815 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009816 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009817 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009818set_option_value(
9819 char_u *name,
9820 long number,
9821 char_u *string,
9822 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009823{
9824 int opt_idx;
9825 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00009826 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009827
9828 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00009829 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009830 {
9831 int key;
9832
9833 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009834 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009835 {
9836 char_u key_name[2];
9837
9838 if (key < 0)
9839 {
9840 key_name[0] = KEY2TERMCAP0(key);
9841 key_name[1] = KEY2TERMCAP1(key);
9842 }
9843 else
9844 {
9845 key_name[0] = KS_KEY;
9846 key_name[1] = (key & 0xff);
9847 }
9848 add_termcode(key_name, string, FALSE);
9849 if (full_screen)
9850 ttest(FALSE);
9851 redraw_all_later(CLEAR);
9852 return NULL;
9853 }
9854
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009855 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +01009856 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009857 else
9858 {
9859 flags = options[opt_idx].flags;
9860#ifdef HAVE_SANDBOX
9861 /* Disallow changing some options in the sandbox */
9862 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009863 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009864 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009865 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009866 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009867#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009868 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009869 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009870 else
9871 {
Bram Moolenaarb3163762008-07-08 15:15:08 +00009872 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009873 if (varp != NULL) /* hidden option is not changed */
9874 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009875 if (number == 0 && string != NULL)
9876 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009877 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009878
9879 /* Either we are given a string or we are setting option
9880 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009881 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009882 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +00009883 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009884 {
9885 /* There's another character after zeros or the string
9886 * is empty. In both cases, we are trying to set a
9887 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009888 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009889 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009890 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +00009891
9892 }
9893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009894 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009895 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +00009896 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009897 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009898 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009899 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009900 }
9901 }
9902 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02009903 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009904}
9905
9906/*
9907 * Get the terminal code for a terminal option.
9908 * Returns NULL when not found.
9909 */
9910 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009911get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009912{
9913 int opt_idx;
9914 char_u *varp;
9915
9916 if (tname[0] != 't' || tname[1] != '_' ||
9917 tname[2] == NUL || tname[3] == NUL)
9918 return NULL;
9919 if ((opt_idx = findoption(tname)) >= 0)
9920 {
9921 varp = get_varp(&(options[opt_idx]));
9922 if (varp != NULL)
9923 varp = *(char_u **)(varp);
9924 return varp;
9925 }
9926 return find_termcode(tname + 2);
9927}
9928
9929 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009930get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009931{
9932 int i;
9933
9934 i = findoption((char_u *)"hl");
9935 if (i >= 0)
9936 return options[i].def_val[VI_DEFAULT];
9937 return (char_u *)NULL;
9938}
9939
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009940 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009941get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009942{
9943 int i;
9944
9945 i = findoption((char_u *)"enc");
9946 if (i >= 0)
9947 return options[i].def_val[VI_DEFAULT];
9948 return (char_u *)NULL;
9949}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00009950
Bram Moolenaar071d4272004-06-13 20:20:40 +00009951/*
9952 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009953 * When "has_lt" is true there is a '<' before "*arg_arg".
9954 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +00009955 */
9956 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009957find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009958{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009959 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009960 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009961 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009962
9963 /*
9964 * Don't use get_special_key_code() for t_xx, we don't want it to call
9965 * add_termcap_entry().
9966 */
9967 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
9968 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009969 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009970 {
9971 --arg; /* put arg at the '<' */
9972 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +02009973 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009974 if (modifiers) /* can't handle modifiers here */
9975 key = 0;
9976 }
9977 return key;
9978}
9979
9980/*
9981 * if 'all' == 0: show changed options
9982 * if 'all' == 1: show all normal options
9983 * if 'all' == 2: show all terminal options
9984 */
9985 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009986showoptions(
9987 int all,
9988 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009989{
9990 struct vimoption *p;
9991 int col;
9992 int isterm;
9993 char_u *varp;
9994 struct vimoption **items;
9995 int item_count;
9996 int run;
9997 int row, rows;
9998 int cols;
9999 int i;
10000 int len;
10001
10002#define INC 20
10003#define GAP 3
10004
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010005 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010006 if (items == NULL)
10007 return;
10008
10009 /* Highlight title */
10010 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010011 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010012 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010013 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010014 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010015 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010016 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010017 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010018
10019 /*
10020 * do the loop two times:
10021 * 1. display the short items
10022 * 2. display the long items (only strings and numbers)
10023 */
10024 for (run = 1; run <= 2 && !got_int; ++run)
10025 {
10026 /*
10027 * collect the items in items[]
10028 */
10029 item_count = 0;
10030 for (p = &options[0]; p->fullname != NULL; p++)
10031 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010032 // apply :filter /pat/
10033 if (message_filtered((char_u *) p->fullname))
10034 continue;
10035
Bram Moolenaar071d4272004-06-13 20:20:40 +000010036 varp = NULL;
10037 isterm = istermoption(p);
10038 if (opt_flags != 0)
10039 {
10040 if (p->indir != PV_NONE && !isterm)
10041 varp = get_varp_scope(p, opt_flags);
10042 }
10043 else
10044 varp = get_varp(p);
10045 if (varp != NULL
10046 && ((all == 2 && isterm)
10047 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010048 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010049 {
10050 if (p->flags & P_BOOL)
10051 len = 1; /* a toggle option fits always */
10052 else
10053 {
10054 option_value2string(p, opt_flags);
10055 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10056 }
10057 if ((len <= INC - GAP && run == 1) ||
10058 (len > INC - GAP && run == 2))
10059 items[item_count++] = p;
10060 }
10061 }
10062
10063 /*
10064 * display the items
10065 */
10066 if (run == 1)
10067 {
10068 cols = (Columns + GAP - 3) / INC;
10069 if (cols == 0)
10070 cols = 1;
10071 rows = (item_count + cols - 1) / cols;
10072 }
10073 else /* run == 2 */
10074 rows = item_count;
10075 for (row = 0; row < rows && !got_int; ++row)
10076 {
10077 msg_putchar('\n'); /* go to next line */
10078 if (got_int) /* 'q' typed in more */
10079 break;
10080 col = 0;
10081 for (i = row; i < item_count; i += rows)
10082 {
10083 msg_col = col; /* make columns */
10084 showoneopt(items[i], opt_flags);
10085 col += INC;
10086 }
10087 out_flush();
10088 ui_breakcheck();
10089 }
10090 }
10091 vim_free(items);
10092}
10093
10094/*
10095 * Return TRUE if option "p" has its default value.
10096 */
10097 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010098optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010099{
10100 int dvi;
10101
10102 if (varp == NULL)
10103 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010104 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010105 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010106 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010107 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010108 /* the cast to long is required for Manx C, long_i is
10109 * needed for MSVC */
10110 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010111 /* P_STRING */
10112 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10113}
10114
10115/*
10116 * showoneopt: show the value of one option
10117 * must not be called with a hidden option!
10118 */
10119 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010120showoneopt(
10121 struct vimoption *p,
10122 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010123{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010124 char_u *varp;
10125 int save_silent = silent_mode;
10126
10127 silent_mode = FALSE;
10128 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010129
10130 varp = get_varp_scope(p, opt_flags);
10131
10132 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10133 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10134 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010135 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010136 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010137 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010138 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010139 msg_puts(" ");
10140 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010141 if (!(p->flags & P_BOOL))
10142 {
10143 msg_putchar('=');
10144 /* put value string in NameBuff */
10145 option_value2string(p, opt_flags);
10146 msg_outtrans(NameBuff);
10147 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010148
10149 silent_mode = save_silent;
10150 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010151}
10152
10153/*
10154 * Write modified options as ":set" commands to a file.
10155 *
10156 * There are three values for "opt_flags":
10157 * OPT_GLOBAL: Write global option values and fresh values of
10158 * buffer-local options (used for start of a session
10159 * file).
10160 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10161 * curwin (used for a vimrc file).
10162 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10163 * and local values for window-local options of
10164 * curwin. Local values are also written when at the
10165 * default value, because a modeline or autocommand
10166 * may have set them when doing ":edit file" and the
10167 * user has set them back at the default or fresh
10168 * value.
10169 * When "local_only" is TRUE, don't write fresh
10170 * values, only local values (for ":mkview").
10171 * (fresh value = value used for a new buffer or window for a local option).
10172 *
10173 * Return FAIL on error, OK otherwise.
10174 */
10175 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010176makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010177{
10178 struct vimoption *p;
10179 char_u *varp; /* currently used value */
10180 char_u *varp_fresh; /* local value */
10181 char_u *varp_local = NULL; /* fresh value */
10182 char *cmd;
10183 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010184 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010185
10186 /*
10187 * The options that don't have a default (terminal name, columns, lines)
10188 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010189 * Do the loop over "options[]" twice: once for options with the
10190 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010191 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010192 for (pri = 1; pri >= 0; --pri)
10193 {
10194 for (p = &options[0]; !istermoption(p); p++)
10195 if (!(p->flags & P_NO_MKRC)
10196 && !istermoption(p)
10197 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010198 {
10199 /* skip global option when only doing locals */
10200 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10201 continue;
10202
10203 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10204 * file, they are always buffer-specific. */
10205 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10206 continue;
10207
10208 /* Global values are only written when not at the default value. */
10209 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010210 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010211 continue;
10212
10213 round = 2;
10214 if (p->indir != PV_NONE)
10215 {
10216 if (p->var == VAR_WIN)
10217 {
10218 /* skip window-local option when only doing globals */
10219 if (!(opt_flags & OPT_LOCAL))
10220 continue;
10221 /* When fresh value of window-local option is not at the
10222 * default, need to write it too. */
10223 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10224 {
10225 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010226 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010227 {
10228 round = 1;
10229 varp_local = varp;
10230 varp = varp_fresh;
10231 }
10232 }
10233 }
10234 }
10235
10236 /* Round 1: fresh value for window-local options.
10237 * Round 2: other values */
10238 for ( ; round <= 2; varp = varp_local, ++round)
10239 {
10240 if (round == 1 || (opt_flags & OPT_GLOBAL))
10241 cmd = "set";
10242 else
10243 cmd = "setlocal";
10244
10245 if (p->flags & P_BOOL)
10246 {
10247 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10248 return FAIL;
10249 }
10250 else if (p->flags & P_NUM)
10251 {
10252 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10253 return FAIL;
10254 }
10255 else /* P_STRING */
10256 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010257 int do_endif = FALSE;
10258
Bram Moolenaar071d4272004-06-13 20:20:40 +000010259 /* Don't set 'syntax' and 'filetype' again if the value is
10260 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010261 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010262#if defined(FEAT_SYN_HL)
10263 p->indir == PV_SYN ||
10264#endif
10265 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010266 {
10267 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10268 *(char_u **)(varp)) < 0
10269 || put_eol(fd) < 0)
10270 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010271 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010272 }
10273 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010274 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010275 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010276 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010277 {
10278 if (put_line(fd, "endif") == FAIL)
10279 return FAIL;
10280 }
10281 }
10282 }
10283 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010284 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010285 return OK;
10286}
10287
10288#if defined(FEAT_FOLDING) || defined(PROTO)
10289/*
10290 * Generate set commands for the local fold options only. Used when
10291 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10292 */
10293 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010294makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010295{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010296 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010297# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010298 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010299 == FAIL
10300# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010301 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010302 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010303 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010304 == FAIL
10305 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10306 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10307 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10308 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10309 )
10310 return FAIL;
10311
10312 return OK;
10313}
10314#endif
10315
10316 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010317put_setstring(
10318 FILE *fd,
10319 char *cmd,
10320 char *name,
10321 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010322 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010323{
10324 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010325 char_u *buf = NULL;
10326 char_u *part = NULL;
10327 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010328
10329 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10330 return FAIL;
10331 if (*valuep != NULL)
10332 {
10333 /* Output 'pastetoggle' as key names. For other
10334 * options some characters have to be escaped with
10335 * CTRL-V or backslash */
10336 if (valuep == &p_pt)
10337 {
10338 s = *valuep;
10339 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010340 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010341 return FAIL;
10342 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010343 // expand the option value, replace $HOME by ~
10344 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010345 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010346 int size = (int)STRLEN(*valuep) + 1;
10347
10348 // replace home directory in the whole option value into "buf"
10349 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010350 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010351 goto fail;
10352 home_replace(NULL, *valuep, buf, size, FALSE);
10353
10354 // If the option value is longer than MAXPATHL, we need to append
10355 // earch comma separated part of the option separately, so that it
10356 // can be expanded when read back.
10357 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10358 && vim_strchr(*valuep, ',') != NULL)
10359 {
10360 part = alloc(size);
10361 if (part == NULL)
10362 goto fail;
10363
10364 // write line break to clear the option, e.g. ':set rtp='
10365 if (put_eol(fd) == FAIL)
10366 goto fail;
10367
10368 p = buf;
10369 while (*p != NUL)
10370 {
10371 // for each comma separated option part, append value to
10372 // the option, :set rtp+=value
10373 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10374 goto fail;
10375 (void)copy_option_part(&p, part, size, ",");
10376 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10377 goto fail;
10378 }
10379 vim_free(buf);
10380 vim_free(part);
10381 return OK;
10382 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010383 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010384 {
10385 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010386 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010387 }
10388 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010389 }
10390 else if (put_escstr(fd, *valuep, 2) == FAIL)
10391 return FAIL;
10392 }
10393 if (put_eol(fd) < 0)
10394 return FAIL;
10395 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010396fail:
10397 vim_free(buf);
10398 vim_free(part);
10399 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010400}
10401
10402 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010403put_setnum(
10404 FILE *fd,
10405 char *cmd,
10406 char *name,
10407 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010408{
10409 long wc;
10410
10411 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10412 return FAIL;
10413 if (wc_use_keyname((char_u *)valuep, &wc))
10414 {
10415 /* print 'wildchar' and 'wildcharm' as a key name */
10416 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10417 return FAIL;
10418 }
10419 else if (fprintf(fd, "%ld", *valuep) < 0)
10420 return FAIL;
10421 if (put_eol(fd) < 0)
10422 return FAIL;
10423 return OK;
10424}
10425
10426 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010427put_setbool(
10428 FILE *fd,
10429 char *cmd,
10430 char *name,
10431 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010432{
Bram Moolenaar893de922007-10-02 18:40:57 +000010433 if (value < 0) /* global/local option using global value */
10434 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010435 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10436 || put_eol(fd) < 0)
10437 return FAIL;
10438 return OK;
10439}
10440
10441/*
10442 * Clear all the terminal options.
10443 * If the option has been allocated, free the memory.
10444 * Terminal options are never hidden or indirect.
10445 */
10446 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010447clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010448{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010449 /*
10450 * Reset a few things before clearing the old options. This may cause
10451 * outputting a few things that the terminal doesn't understand, but the
10452 * screen will be cleared later, so this is OK.
10453 */
10454#ifdef FEAT_MOUSE_TTY
10455 mch_setmouse(FALSE); /* switch mouse off */
10456#endif
10457#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010458 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010459#endif
10460#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10461 /* When starting the GUI close the display opened for the clipboard.
10462 * After restoring the title, because that will need the display. */
10463 if (gui.starting)
10464 clear_xterm_clip();
10465#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010466 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010467
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010468 free_termoptions();
10469}
10470
10471 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010472free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010473{
10474 struct vimoption *p;
10475
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010476 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010477 if (istermoption(p))
10478 {
10479 if (p->flags & P_ALLOCED)
10480 free_string_option(*(char_u **)(p->var));
10481 if (p->flags & P_DEF_ALLOCED)
10482 free_string_option(p->def_val[VI_DEFAULT]);
10483 *(char_u **)(p->var) = empty_option;
10484 p->def_val[VI_DEFAULT] = empty_option;
10485 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010486#ifdef FEAT_EVAL
10487 // remember where the option was cleared
10488 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10489#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010490 }
10491 clear_termcodes();
10492}
10493
10494/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010495 * Free the string for one term option, if it was allocated.
10496 * Set the string to empty_option and clear allocated flag.
10497 * "var" points to the option value.
10498 */
10499 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010500free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010501{
10502 struct vimoption *p;
10503
10504 for (p = &options[0]; p->fullname != NULL; p++)
10505 if (p->var == var)
10506 {
10507 if (p->flags & P_ALLOCED)
10508 free_string_option(*(char_u **)(p->var));
10509 *(char_u **)(p->var) = empty_option;
10510 p->flags &= ~P_ALLOCED;
10511 break;
10512 }
10513}
10514
10515/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010516 * Set the terminal option defaults to the current value.
10517 * Used after setting the terminal name.
10518 */
10519 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010520set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010521{
10522 struct vimoption *p;
10523
10524 for (p = &options[0]; p->fullname != NULL; p++)
10525 {
10526 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10527 {
10528 if (p->flags & P_DEF_ALLOCED)
10529 {
10530 free_string_option(p->def_val[VI_DEFAULT]);
10531 p->flags &= ~P_DEF_ALLOCED;
10532 }
10533 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10534 if (p->flags & P_ALLOCED)
10535 {
10536 p->flags |= P_DEF_ALLOCED;
10537 p->flags &= ~P_ALLOCED; /* don't free the value now */
10538 }
10539 }
10540 }
10541}
10542
10543/*
10544 * return TRUE if 'p' starts with 't_'
10545 */
10546 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010547istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010548{
10549 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10550}
10551
Bram Moolenaar113e1072019-01-20 15:30:40 +010010552#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010553/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010554 * Unset local option value, similar to ":set opt<".
10555 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010556 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010557unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010558{
10559 struct vimoption *p;
10560 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010561 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010562
10563 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010564 if (opt_idx < 0)
10565 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010566 p = &(options[opt_idx]);
10567
10568 switch ((int)p->indir)
10569 {
10570 /* global option with local value: use local value if it's been set */
10571 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010572 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010573 break;
10574 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010575 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010576 break;
10577 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010578 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010579 break;
10580 case PV_AR:
10581 buf->b_p_ar = -1;
10582 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010583 case PV_BKC:
10584 clear_string_option(&buf->b_p_bkc);
10585 buf->b_bkc_flags = 0;
10586 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010587 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010588 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010589 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010590 case PV_TC:
10591 clear_string_option(&buf->b_p_tc);
10592 buf->b_tc_flags = 0;
10593 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010594 case PV_SISO:
10595 curwin->w_p_siso = -1;
10596 break;
10597 case PV_SO:
10598 curwin->w_p_so = -1;
10599 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010600#ifdef FEAT_FIND_ID
10601 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010602 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010603 break;
10604 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010605 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010606 break;
10607#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010608 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010609 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010610 break;
10611 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010612 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010613 break;
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010614 case PV_FP:
10615 clear_string_option(&buf->b_p_fp);
10616 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010617#ifdef FEAT_QUICKFIX
10618 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010619 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010620 break;
10621 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010622 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010623 break;
10624 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010625 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010626 break;
10627#endif
10628#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10629 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010630 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010631 break;
10632#endif
10633#if defined(FEAT_CRYPT)
10634 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010635 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010636 break;
10637#endif
10638#ifdef FEAT_STL_OPT
10639 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010640 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010641 break;
10642#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010643 case PV_UL:
10644 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
10645 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010646#ifdef FEAT_LISP
10647 case PV_LW:
10648 clear_string_option(&buf->b_p_lw);
10649 break;
10650#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010651 case PV_MENC:
10652 clear_string_option(&buf->b_p_menc);
10653 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010654 }
10655}
Bram Moolenaar113e1072019-01-20 15:30:40 +010010656#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010657
10658/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010659 * Get pointer to option variable, depending on local or global scope.
10660 */
10661 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010662get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010663{
10664 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
10665 {
10666 if (p->var == VAR_WIN)
10667 return (char_u *)GLOBAL_WO(get_varp(p));
10668 return p->var;
10669 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010670 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010671 {
10672 switch ((int)p->indir)
10673 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010674 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010675#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010676 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
10677 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
10678 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010679#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010680 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
10681 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
10682 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010683 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010684 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010685 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010010686 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
10687 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010688#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010689 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
10690 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010691#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010692 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
10693 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010694#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10695 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
10696#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010697#if defined(FEAT_CRYPT)
10698 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
10699#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010700#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010701 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010702#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010703 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010704#ifdef FEAT_LISP
10705 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
10706#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010707 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010708 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010709 }
10710 return NULL; /* "cannot happen" */
10711 }
10712 return get_varp(p);
10713}
10714
10715/*
10716 * Get pointer to option variable.
10717 */
10718 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010719get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010720{
10721 /* hidden option, always return NULL */
10722 if (p->var == NULL)
10723 return NULL;
10724
10725 switch ((int)p->indir)
10726 {
10727 case PV_NONE: return p->var;
10728
10729 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010730 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010731 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010732 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010733 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010734 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010735 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000010736 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000010737 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010738 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010739 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010740 case PV_TC: return *curbuf->b_p_tc != NUL
10741 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010742 case PV_BKC: return *curbuf->b_p_bkc != NUL
10743 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010744 case PV_SISO: return curwin->w_p_siso >= 0
10745 ? (char_u *)&(curwin->w_p_siso) : p->var;
10746 case PV_SO: return curwin->w_p_so >= 0
10747 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010749 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010750 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010751 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010752 ? (char_u *)&(curbuf->b_p_inc) : p->var;
10753#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010754 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010755 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010756 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010757 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010758 case PV_FP: return *curbuf->b_p_fp != NUL
10759 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010760#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010761 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010762 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010763 case PV_GP: return *curbuf->b_p_gp != NUL
10764 ? (char_u *)&(curbuf->b_p_gp) : p->var;
10765 case PV_MP: return *curbuf->b_p_mp != NUL
10766 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010767#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000010768#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10769 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
10770 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
10771#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020010772#if defined(FEAT_CRYPT)
10773 case PV_CM: return *curbuf->b_p_cm != NUL
10774 ? (char_u *)&(curbuf->b_p_cm) : p->var;
10775#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010776#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010777 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000010778 ? (char_u *)&(curwin->w_p_stl) : p->var;
10779#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010010780 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
10781 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010010782#ifdef FEAT_LISP
10783 case PV_LW: return *curbuf->b_p_lw != NUL
10784 ? (char_u *)&(curbuf->b_p_lw) : p->var;
10785#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010010786 case PV_MENC: return *curbuf->b_p_menc != NUL
10787 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010788#ifdef FEAT_ARABIC
10789 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
10790#endif
10791 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010792#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000010793 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
10794#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010795#ifdef FEAT_SYN_HL
10796 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
10797 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar410e98a2019-09-09 22:05:49 +020010798 case PV_CULOPT: return (char_u *)&(curwin->w_p_culopt);
Bram Moolenaar1a384422010-07-14 19:53:30 +020010799 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010800#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010801#ifdef FEAT_DIFF
10802 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
10803#endif
10804#ifdef FEAT_FOLDING
10805 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
10806 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
10807 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
10808 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
10809 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
10810 case PV_FML: return (char_u *)&(curwin->w_p_fml);
10811 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
10812# ifdef FEAT_EVAL
10813 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
10814 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
10815# endif
10816 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
10817#endif
10818 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020010819 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000010820#ifdef FEAT_LINEBREAK
10821 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
10822#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010823 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000010824 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020010825#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010826 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
10827#endif
10828#ifdef FEAT_RIGHTLEFT
10829 case PV_RL: return (char_u *)&(curwin->w_p_rl);
10830 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
10831#endif
10832 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
10833 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
10834#ifdef FEAT_LINEBREAK
10835 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020010836 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
10837 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010838#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020010839 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010840 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010841 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010842#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020010843 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
10844 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
10845#endif
10846#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020010847 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
10848 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
10849 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020010850#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010851
10852 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
10853 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010854 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010855 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
10856 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010857 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
10858 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
10859#ifdef FEAT_CINDENT
10860 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
10861 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
10862 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
10863#endif
10864#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
10865 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
10866#endif
10867#ifdef FEAT_COMMENTS
10868 case PV_COM: return (char_u *)&(curbuf->b_p_com);
10869#endif
10870#ifdef FEAT_FOLDING
10871 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
10872#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010873 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
Bram Moolenaare2c453d2019-08-21 14:37:09 +020010874#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +020010875 case PV_CSL: return (char_u *)&(curbuf->b_p_csl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010876#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010877#ifdef FEAT_COMPL_FUNC
10878 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000010879 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010880#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020010881#ifdef FEAT_EVAL
10882 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
10883#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010884 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020010885 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010886 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010887 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010888 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010889 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000010891 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
10893 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
10894 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
10895 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
10896#ifdef FEAT_FIND_ID
10897# ifdef FEAT_EVAL
10898 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
10899# endif
10900#endif
10901#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
10902 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
10903 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
10904#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010905#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000010906 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
10907#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010908#ifdef FEAT_CRYPT
10909 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
10910#endif
10911#ifdef FEAT_LISP
10912 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
10913#endif
10914 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
10915 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
10916 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
10917 case PV_MOD: return (char_u *)&(curbuf->b_changed);
10918 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010919 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000010920#ifdef FEAT_TEXTOBJ
10921 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
10922#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010923 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
10924#ifdef FEAT_SMARTINDENT
10925 case PV_SI: return (char_u *)&(curbuf->b_p_si);
10926#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010927 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010928 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
10929#ifdef FEAT_SEARCHPATH
10930 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
10931#endif
10932 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
10933#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000010934 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000010935 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
10936#endif
10937#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020010938 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
10939 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
10940 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010941#endif
10942 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
10943 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
10944 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
10945 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020010946#ifdef FEAT_PERSISTENT_UNDO
10947 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
10948#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010949 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
10950#ifdef FEAT_KEYMAP
10951 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
10952#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020010953#ifdef FEAT_SIGNS
10954 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
10955#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020010956#ifdef FEAT_VARTABS
10957 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
10958 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
10959#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010960 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010961 }
10962 /* always return a valid pointer to avoid a crash! */
10963 return (char_u *)&(curbuf->b_p_wm);
10964}
10965
10966/*
10967 * Get the value of 'equalprg', either the buffer-local one or the global one.
10968 */
10969 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010970get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010971{
10972 if (*curbuf->b_p_ep == NUL)
10973 return p_ep;
10974 return curbuf->b_p_ep;
10975}
10976
Bram Moolenaar071d4272004-06-13 20:20:40 +000010977/*
10978 * Copy options from one window to another.
10979 * Used when splitting a window.
10980 */
10981 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010982win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010983{
10984 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
10985 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020010986#if defined(FEAT_LINEBREAK)
10987 briopt_check(wp_to);
10988#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010989}
Bram Moolenaar071d4272004-06-13 20:20:40 +000010990
10991/*
10992 * Copy the options from one winopt_T to another.
10993 * Doesn't free the old option values in "to", use clear_winopt() for that.
10994 * The 'scroll' option is not copied, because it depends on the window height.
10995 * The 'previewwindow' option is reset, there can be only one preview window.
10996 */
10997 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010998copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010999{
11000#ifdef FEAT_ARABIC
11001 to->wo_arab = from->wo_arab;
11002#endif
11003 to->wo_list = from->wo_list;
11004 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011005 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011006#ifdef FEAT_LINEBREAK
11007 to->wo_nuw = from->wo_nuw;
11008#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011009#ifdef FEAT_RIGHTLEFT
11010 to->wo_rl = from->wo_rl;
11011 to->wo_rlc = vim_strsave(from->wo_rlc);
11012#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011013#ifdef FEAT_STL_OPT
11014 to->wo_stl = vim_strsave(from->wo_stl);
11015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011016 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011017#ifdef FEAT_DIFF
11018 to->wo_wrap_save = from->wo_wrap_save;
11019#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011020#ifdef FEAT_LINEBREAK
11021 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011022 to->wo_bri = from->wo_bri;
11023 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011024#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011025 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011026 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011027 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011028 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011029 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011030#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011031 to->wo_spell = from->wo_spell;
11032#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011033#ifdef FEAT_SYN_HL
11034 to->wo_cuc = from->wo_cuc;
11035 to->wo_cul = from->wo_cul;
Bram Moolenaar410e98a2019-09-09 22:05:49 +020011036 to->wo_culopt = vim_strsave(from->wo_culopt);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011037 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011038#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011039#ifdef FEAT_DIFF
11040 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011041 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011042#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011043#ifdef FEAT_CONCEAL
11044 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011045 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011046#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011047#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011048 to->wo_twk = vim_strsave(from->wo_twk);
11049 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011050#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011051#ifdef FEAT_FOLDING
11052 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011053 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011054 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011055 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011056 to->wo_fdi = vim_strsave(from->wo_fdi);
11057 to->wo_fml = from->wo_fml;
11058 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011059 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011060 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011061 to->wo_fdm_save = from->wo_diff_saved
11062 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011063 to->wo_fdn = from->wo_fdn;
11064# ifdef FEAT_EVAL
11065 to->wo_fde = vim_strsave(from->wo_fde);
11066 to->wo_fdt = vim_strsave(from->wo_fdt);
11067# endif
11068 to->wo_fmr = vim_strsave(from->wo_fmr);
11069#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011070#ifdef FEAT_SIGNS
11071 to->wo_scl = vim_strsave(from->wo_scl);
11072#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011073 check_winopt(to); /* don't want NULL pointers */
11074}
11075
11076/*
11077 * Check string options in a window for a NULL value.
11078 */
Bram Moolenaar5843f5f2019-08-20 20:13:45 +020011079 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011080check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011081{
11082 check_winopt(&win->w_onebuf_opt);
11083 check_winopt(&win->w_allbuf_opt);
11084}
11085
11086/*
11087 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11088 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011089 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011090check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011091{
11092#ifdef FEAT_FOLDING
11093 check_string_option(&wop->wo_fdi);
11094 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011095 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011096# ifdef FEAT_EVAL
11097 check_string_option(&wop->wo_fde);
11098 check_string_option(&wop->wo_fdt);
11099# endif
11100 check_string_option(&wop->wo_fmr);
11101#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011102#ifdef FEAT_SIGNS
11103 check_string_option(&wop->wo_scl);
11104#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011105#ifdef FEAT_RIGHTLEFT
11106 check_string_option(&wop->wo_rlc);
11107#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011108#ifdef FEAT_STL_OPT
11109 check_string_option(&wop->wo_stl);
11110#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011111#ifdef FEAT_SYN_HL
Bram Moolenaar410e98a2019-09-09 22:05:49 +020011112 check_string_option(&wop->wo_culopt);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011113 check_string_option(&wop->wo_cc);
11114#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011115#ifdef FEAT_CONCEAL
11116 check_string_option(&wop->wo_cocu);
11117#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011118#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011119 check_string_option(&wop->wo_twk);
11120 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011121#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011122#ifdef FEAT_LINEBREAK
11123 check_string_option(&wop->wo_briopt);
11124#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011125 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011126}
11127
11128/*
11129 * Free the allocated memory inside a winopt_T.
11130 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011131 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011132clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011133{
11134#ifdef FEAT_FOLDING
11135 clear_string_option(&wop->wo_fdi);
11136 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011137 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011138# ifdef FEAT_EVAL
11139 clear_string_option(&wop->wo_fde);
11140 clear_string_option(&wop->wo_fdt);
11141# endif
11142 clear_string_option(&wop->wo_fmr);
11143#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011144#ifdef FEAT_SIGNS
11145 clear_string_option(&wop->wo_scl);
11146#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011147#ifdef FEAT_LINEBREAK
11148 clear_string_option(&wop->wo_briopt);
11149#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011150 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011151#ifdef FEAT_RIGHTLEFT
11152 clear_string_option(&wop->wo_rlc);
11153#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011154#ifdef FEAT_STL_OPT
11155 clear_string_option(&wop->wo_stl);
11156#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011157#ifdef FEAT_SYN_HL
Bram Moolenaar410e98a2019-09-09 22:05:49 +020011158 clear_string_option(&wop->wo_culopt);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011159 clear_string_option(&wop->wo_cc);
11160#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011161#ifdef FEAT_CONCEAL
11162 clear_string_option(&wop->wo_cocu);
11163#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011164#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011165 clear_string_option(&wop->wo_twk);
11166 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011167#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011168}
11169
11170/*
11171 * Copy global option values to local options for one buffer.
11172 * Used when creating a new buffer and sometimes when entering a buffer.
11173 * flags:
11174 * BCO_ENTER We will enter the buf buffer.
11175 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11176 * appropriate.
11177 * BCO_NOHELP Don't copy the values to a help buffer.
11178 */
11179 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011180buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011181{
11182 int should_copy = TRUE;
11183 char_u *save_p_isk = NULL; /* init for GCC */
11184 int dont_do_help;
11185 int did_isk = FALSE;
11186
11187 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011188 * Skip this when the option defaults have not been set yet. Happens when
11189 * main() allocates the first buffer.
11190 */
11191 if (p_cpo != NULL)
11192 {
11193 /*
11194 * Always copy when entering and 'cpo' contains 'S'.
11195 * Don't copy when already initialized.
11196 * Don't copy when 'cpo' contains 's' and not entering.
11197 * 'S' BCO_ENTER initialized 's' should_copy
11198 * yes yes X X TRUE
11199 * yes no yes X FALSE
11200 * no X yes X FALSE
11201 * X no no yes FALSE
11202 * X no no no TRUE
11203 * no yes no X TRUE
11204 */
11205 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11206 && (buf->b_p_initialized
11207 || (!(flags & BCO_ENTER)
11208 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11209 should_copy = FALSE;
11210
11211 if (should_copy || (flags & BCO_ALWAYS))
11212 {
11213 /* Don't copy the options specific to a help buffer when
11214 * BCO_NOHELP is given or the options were initialized already
11215 * (jumping back to a help file with CTRL-T or CTRL-O) */
11216 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11217 || buf->b_p_initialized;
11218 if (dont_do_help) /* don't free b_p_isk */
11219 {
11220 save_p_isk = buf->b_p_isk;
11221 buf->b_p_isk = NULL;
11222 }
11223 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011224 * Always free the allocated strings. If not already initialized,
11225 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011226 */
11227 if (!buf->b_p_initialized)
11228 {
11229 free_buf_options(buf, TRUE);
11230 buf->b_p_ro = FALSE; /* don't copy readonly */
11231 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011232 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011233 switch (*p_ffs)
11234 {
11235 case 'm':
11236 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11237 case 'd':
11238 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11239 case 'u':
11240 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11241 default:
11242 buf->b_p_ff = vim_strsave(p_ff);
11243 }
11244 if (buf->b_p_ff != NULL)
11245 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011246 buf->b_p_bh = empty_option;
11247 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011248 }
11249 else
11250 free_buf_options(buf, FALSE);
11251
11252 buf->b_p_ai = p_ai;
11253 buf->b_p_ai_nopaste = p_ai_nopaste;
11254 buf->b_p_sw = p_sw;
11255 buf->b_p_tw = p_tw;
11256 buf->b_p_tw_nopaste = p_tw_nopaste;
11257 buf->b_p_tw_nobin = p_tw_nobin;
11258 buf->b_p_wm = p_wm;
11259 buf->b_p_wm_nopaste = p_wm_nopaste;
11260 buf->b_p_wm_nobin = p_wm_nobin;
11261 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011262 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011263 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011264 buf->b_p_et = p_et;
11265 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011266 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011267 buf->b_p_ml = p_ml;
11268 buf->b_p_ml_nobin = p_ml_nobin;
11269 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011270 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011271 buf->b_p_cpt = vim_strsave(p_cpt);
Bram Moolenaare2c453d2019-08-21 14:37:09 +020011272#ifdef BACKSLASH_IN_FILENAME
Bram Moolenaarac3150d2019-07-28 16:36:39 +020011273 buf->b_p_csl = vim_strsave(p_csl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011274#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011275#ifdef FEAT_COMPL_FUNC
11276 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011277 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011278#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011279#ifdef FEAT_EVAL
11280 buf->b_p_tfu = vim_strsave(p_tfu);
11281#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011282 buf->b_p_sts = p_sts;
11283 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011284#ifdef FEAT_VARTABS
11285 buf->b_p_vsts = vim_strsave(p_vsts);
11286 if (p_vsts && p_vsts != empty_option)
11287 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11288 else
11289 buf->b_p_vsts_array = 0;
11290 buf->b_p_vsts_nopaste = p_vsts_nopaste
11291 ? vim_strsave(p_vsts_nopaste) : NULL;
11292#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011293 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011294#ifdef FEAT_COMMENTS
11295 buf->b_p_com = vim_strsave(p_com);
11296#endif
11297#ifdef FEAT_FOLDING
11298 buf->b_p_cms = vim_strsave(p_cms);
11299#endif
11300 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011301 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011302 buf->b_p_nf = vim_strsave(p_nf);
11303 buf->b_p_mps = vim_strsave(p_mps);
11304#ifdef FEAT_SMARTINDENT
11305 buf->b_p_si = p_si;
11306#endif
11307 buf->b_p_ci = p_ci;
11308#ifdef FEAT_CINDENT
11309 buf->b_p_cin = p_cin;
11310 buf->b_p_cink = vim_strsave(p_cink);
11311 buf->b_p_cino = vim_strsave(p_cino);
11312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011313 /* Don't copy 'filetype', it must be detected */
11314 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011315 buf->b_p_pi = p_pi;
11316#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11317 buf->b_p_cinw = vim_strsave(p_cinw);
11318#endif
11319#ifdef FEAT_LISP
11320 buf->b_p_lisp = p_lisp;
11321#endif
11322#ifdef FEAT_SYN_HL
11323 /* Don't copy 'syntax', it must be set */
11324 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011325 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011326 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011327#endif
11328#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011329 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011330 (void)compile_cap_prog(&buf->b_s);
11331 buf->b_s.b_p_spf = vim_strsave(p_spf);
11332 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011333#endif
11334#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11335 buf->b_p_inde = vim_strsave(p_inde);
11336 buf->b_p_indk = vim_strsave(p_indk);
11337#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011338 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011339#if defined(FEAT_EVAL)
11340 buf->b_p_fex = vim_strsave(p_fex);
11341#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011342#ifdef FEAT_CRYPT
11343 buf->b_p_key = vim_strsave(p_key);
11344#endif
11345#ifdef FEAT_SEARCHPATH
11346 buf->b_p_sua = vim_strsave(p_sua);
11347#endif
11348#ifdef FEAT_KEYMAP
11349 buf->b_p_keymap = vim_strsave(p_keymap);
11350 buf->b_kmap_state |= KEYMAP_INIT;
11351#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011352#ifdef FEAT_TERMINAL
11353 buf->b_p_twsl = p_twsl;
11354#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011355 /* This isn't really an option, but copying the langmap and IME
11356 * state from the current buffer is better than resetting it. */
11357 buf->b_p_iminsert = p_iminsert;
11358 buf->b_p_imsearch = p_imsearch;
11359
11360 /* options that are normally global but also have a local value
11361 * are not copied, start using the global value */
11362 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011363 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011364 buf->b_p_bkc = empty_option;
11365 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366#ifdef FEAT_QUICKFIX
11367 buf->b_p_gp = empty_option;
11368 buf->b_p_mp = empty_option;
11369 buf->b_p_efm = empty_option;
11370#endif
11371 buf->b_p_ep = empty_option;
11372 buf->b_p_kp = empty_option;
11373 buf->b_p_path = empty_option;
11374 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011375 buf->b_p_tc = empty_option;
11376 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011377#ifdef FEAT_FIND_ID
11378 buf->b_p_def = empty_option;
11379 buf->b_p_inc = empty_option;
11380# ifdef FEAT_EVAL
11381 buf->b_p_inex = vim_strsave(p_inex);
11382# endif
11383#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011384 buf->b_p_dict = empty_option;
11385 buf->b_p_tsr = empty_option;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011386#ifdef FEAT_TEXTOBJ
11387 buf->b_p_qe = vim_strsave(p_qe);
11388#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011389#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11390 buf->b_p_bexpr = empty_option;
11391#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011392#if defined(FEAT_CRYPT)
11393 buf->b_p_cm = empty_option;
11394#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011395#ifdef FEAT_PERSISTENT_UNDO
11396 buf->b_p_udf = p_udf;
11397#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011398#ifdef FEAT_LISP
11399 buf->b_p_lw = empty_option;
11400#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011401 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011402
11403 /*
11404 * Don't copy the options set by ex_help(), use the saved values,
11405 * when going from a help buffer to a non-help buffer.
11406 * Don't touch these at all when BCO_NOHELP is used and going from
11407 * or to a help buffer.
11408 */
11409 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011410 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011411 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011412#ifdef FEAT_VARTABS
11413 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11414 tabstop_set(p_vts, &buf->b_p_vts_array);
11415 else
11416 buf->b_p_vts_array = NULL;
11417#endif
11418 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011419 else
11420 {
11421 buf->b_p_isk = vim_strsave(p_isk);
11422 did_isk = TRUE;
11423 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011424#ifdef FEAT_VARTABS
11425 buf->b_p_vts = vim_strsave(p_vts);
11426 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11427 tabstop_set(p_vts, &buf->b_p_vts_array);
11428 else
11429 buf->b_p_vts_array = NULL;
11430#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011431 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011432 if (buf->b_p_bt[0] == 'h')
11433 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011434 buf->b_p_ma = p_ma;
11435 }
11436 }
11437
11438 /*
11439 * When the options should be copied (ignoring BCO_ALWAYS), set the
11440 * flag that indicates that the options have been initialized.
11441 */
11442 if (should_copy)
11443 buf->b_p_initialized = TRUE;
11444 }
11445
11446 check_buf_options(buf); /* make sure we don't have NULLs */
11447 if (did_isk)
11448 (void)buf_init_chartab(buf, FALSE);
11449}
11450
11451/*
11452 * Reset the 'modifiable' option and its default value.
11453 */
11454 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011455reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011456{
11457 int opt_idx;
11458
11459 curbuf->b_p_ma = FALSE;
11460 p_ma = FALSE;
11461 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011462 if (opt_idx >= 0)
11463 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011464}
11465
11466/*
11467 * Set the global value for 'iminsert' to the local value.
11468 */
11469 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011470set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011471{
11472 p_iminsert = curbuf->b_p_iminsert;
11473}
11474
11475/*
11476 * Set the global value for 'imsearch' to the local value.
11477 */
11478 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011479set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011480{
11481 p_imsearch = curbuf->b_p_imsearch;
11482}
11483
Bram Moolenaar071d4272004-06-13 20:20:40 +000011484static int expand_option_idx = -1;
11485static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11486static int expand_option_flags = 0;
11487
11488 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011489set_context_in_set_cmd(
11490 expand_T *xp,
11491 char_u *arg,
11492 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011493{
11494 int nextchar;
11495 long_u flags = 0; /* init for GCC */
11496 int opt_idx = 0; /* init for GCC */
11497 char_u *p;
11498 char_u *s;
11499 int is_term_option = FALSE;
11500 int key;
11501
11502 expand_option_flags = opt_flags;
11503
11504 xp->xp_context = EXPAND_SETTINGS;
11505 if (*arg == NUL)
11506 {
11507 xp->xp_pattern = arg;
11508 return;
11509 }
11510 p = arg + STRLEN(arg) - 1;
11511 if (*p == ' ' && *(p - 1) != '\\')
11512 {
11513 xp->xp_pattern = p + 1;
11514 return;
11515 }
11516 while (p > arg)
11517 {
11518 s = p;
11519 /* count number of backslashes before ' ' or ',' */
11520 if (*p == ' ' || *p == ',')
11521 {
11522 while (s > arg && *(s - 1) == '\\')
11523 --s;
11524 }
11525 /* break at a space with an even number of backslashes */
11526 if (*p == ' ' && ((p - s) & 1) == 0)
11527 {
11528 ++p;
11529 break;
11530 }
11531 --p;
11532 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011533 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011534 {
11535 xp->xp_context = EXPAND_BOOL_SETTINGS;
11536 p += 2;
11537 }
11538 if (STRNCMP(p, "inv", 3) == 0)
11539 {
11540 xp->xp_context = EXPAND_BOOL_SETTINGS;
11541 p += 3;
11542 }
11543 xp->xp_pattern = arg = p;
11544 if (*arg == '<')
11545 {
11546 while (*p != '>')
11547 if (*p++ == NUL) /* expand terminal option name */
11548 return;
11549 key = get_special_key_code(arg + 1);
11550 if (key == 0) /* unknown name */
11551 {
11552 xp->xp_context = EXPAND_NOTHING;
11553 return;
11554 }
11555 nextchar = *++p;
11556 is_term_option = TRUE;
11557 expand_option_name[2] = KEY2TERMCAP0(key);
11558 expand_option_name[3] = KEY2TERMCAP1(key);
11559 }
11560 else
11561 {
11562 if (p[0] == 't' && p[1] == '_')
11563 {
11564 p += 2;
11565 if (*p != NUL)
11566 ++p;
11567 if (*p == NUL)
11568 return; /* expand option name */
11569 nextchar = *++p;
11570 is_term_option = TRUE;
11571 expand_option_name[2] = p[-2];
11572 expand_option_name[3] = p[-1];
11573 }
11574 else
11575 {
11576 /* Allow * wildcard */
11577 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11578 p++;
11579 if (*p == NUL)
11580 return;
11581 nextchar = *p;
11582 *p = NUL;
11583 opt_idx = findoption(arg);
11584 *p = nextchar;
11585 if (opt_idx == -1 || options[opt_idx].var == NULL)
11586 {
11587 xp->xp_context = EXPAND_NOTHING;
11588 return;
11589 }
11590 flags = options[opt_idx].flags;
11591 if (flags & P_BOOL)
11592 {
11593 xp->xp_context = EXPAND_NOTHING;
11594 return;
11595 }
11596 }
11597 }
11598 /* handle "-=" and "+=" */
11599 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11600 {
11601 ++p;
11602 nextchar = '=';
11603 }
11604 if ((nextchar != '=' && nextchar != ':')
11605 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11606 {
11607 xp->xp_context = EXPAND_UNSUCCESSFUL;
11608 return;
11609 }
11610 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11611 {
11612 xp->xp_context = EXPAND_OLD_SETTING;
11613 if (is_term_option)
11614 expand_option_idx = -1;
11615 else
11616 expand_option_idx = opt_idx;
11617 xp->xp_pattern = p + 1;
11618 return;
11619 }
11620 xp->xp_context = EXPAND_NOTHING;
11621 if (is_term_option || (flags & P_NUM))
11622 return;
11623
11624 xp->xp_pattern = p + 1;
11625
11626 if (flags & P_EXPAND)
11627 {
11628 p = options[opt_idx].var;
11629 if (p == (char_u *)&p_bdir
11630 || p == (char_u *)&p_dir
11631 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011632 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011633 || p == (char_u *)&p_rtp
11634#ifdef FEAT_SEARCHPATH
11635 || p == (char_u *)&p_cdpath
11636#endif
11637#ifdef FEAT_SESSION
11638 || p == (char_u *)&p_vdir
11639#endif
11640 )
11641 {
11642 xp->xp_context = EXPAND_DIRECTORIES;
11643 if (p == (char_u *)&p_path
11644#ifdef FEAT_SEARCHPATH
11645 || p == (char_u *)&p_cdpath
11646#endif
11647 )
11648 xp->xp_backslash = XP_BS_THREE;
11649 else
11650 xp->xp_backslash = XP_BS_ONE;
11651 }
11652 else
11653 {
11654 xp->xp_context = EXPAND_FILES;
11655 /* for 'tags' need three backslashes for a space */
11656 if (p == (char_u *)&p_tags)
11657 xp->xp_backslash = XP_BS_THREE;
11658 else
11659 xp->xp_backslash = XP_BS_ONE;
11660 }
11661 }
11662
11663 /* For an option that is a list of file names, find the start of the
11664 * last file name. */
11665 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
11666 {
11667 /* count number of backslashes before ' ' or ',' */
11668 if (*p == ' ' || *p == ',')
11669 {
11670 s = p;
11671 while (s > xp->xp_pattern && *(s - 1) == '\\')
11672 --s;
11673 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
11674 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
11675 {
11676 xp->xp_pattern = p + 1;
11677 break;
11678 }
11679 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011680
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011681#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000011682 /* for 'spellsuggest' start at "file:" */
11683 if (options[opt_idx].var == (char_u *)&p_sps
11684 && STRNCMP(p, "file:", 5) == 0)
11685 {
11686 xp->xp_pattern = p + 5;
11687 break;
11688 }
11689#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011690 }
11691
11692 return;
11693}
11694
11695 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011696ExpandSettings(
11697 expand_T *xp,
11698 regmatch_T *regmatch,
11699 int *num_file,
11700 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011701{
11702 int num_normal = 0; /* Nr of matching non-term-code settings */
11703 int num_term = 0; /* Nr of matching terminal code settings */
11704 int opt_idx;
11705 int match;
11706 int count = 0;
11707 char_u *str;
11708 int loop;
11709 int is_term_opt;
11710 char_u name_buf[MAX_KEY_NAME_LEN];
11711 static char *(names[]) = {"all", "termcap"};
11712 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
11713
11714 /* do this loop twice:
11715 * loop == 0: count the number of matching options
11716 * loop == 1: copy the matching options into allocated memory
11717 */
11718 for (loop = 0; loop <= 1; ++loop)
11719 {
11720 regmatch->rm_ic = ic;
11721 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
11722 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000011723 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
11724 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011725 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
11726 {
11727 if (loop == 0)
11728 num_normal++;
11729 else
11730 (*file)[count++] = vim_strsave((char_u *)names[match]);
11731 }
11732 }
11733 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
11734 opt_idx++)
11735 {
11736 if (options[opt_idx].var == NULL)
11737 continue;
11738 if (xp->xp_context == EXPAND_BOOL_SETTINGS
11739 && !(options[opt_idx].flags & P_BOOL))
11740 continue;
11741 is_term_opt = istermoption(&options[opt_idx]);
11742 if (is_term_opt && num_normal > 0)
11743 continue;
11744 match = FALSE;
11745 if (vim_regexec(regmatch, str, (colnr_T)0)
11746 || (options[opt_idx].shortname != NULL
11747 && vim_regexec(regmatch,
11748 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
11749 match = TRUE;
11750 else if (is_term_opt)
11751 {
11752 name_buf[0] = '<';
11753 name_buf[1] = 't';
11754 name_buf[2] = '_';
11755 name_buf[3] = str[2];
11756 name_buf[4] = str[3];
11757 name_buf[5] = '>';
11758 name_buf[6] = NUL;
11759 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11760 {
11761 match = TRUE;
11762 str = name_buf;
11763 }
11764 }
11765 if (match)
11766 {
11767 if (loop == 0)
11768 {
11769 if (is_term_opt)
11770 num_term++;
11771 else
11772 num_normal++;
11773 }
11774 else
11775 (*file)[count++] = vim_strsave(str);
11776 }
11777 }
11778 /*
11779 * Check terminal key codes, these are not in the option table
11780 */
11781 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
11782 {
11783 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
11784 {
11785 if (!isprint(str[0]) || !isprint(str[1]))
11786 continue;
11787
11788 name_buf[0] = 't';
11789 name_buf[1] = '_';
11790 name_buf[2] = str[0];
11791 name_buf[3] = str[1];
11792 name_buf[4] = NUL;
11793
11794 match = FALSE;
11795 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11796 match = TRUE;
11797 else
11798 {
11799 name_buf[0] = '<';
11800 name_buf[1] = 't';
11801 name_buf[2] = '_';
11802 name_buf[3] = str[0];
11803 name_buf[4] = str[1];
11804 name_buf[5] = '>';
11805 name_buf[6] = NUL;
11806
11807 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11808 match = TRUE;
11809 }
11810 if (match)
11811 {
11812 if (loop == 0)
11813 num_term++;
11814 else
11815 (*file)[count++] = vim_strsave(name_buf);
11816 }
11817 }
11818
11819 /*
11820 * Check special key names.
11821 */
11822 regmatch->rm_ic = TRUE; /* ignore case here */
11823 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
11824 {
11825 name_buf[0] = '<';
11826 STRCPY(name_buf + 1, str);
11827 STRCAT(name_buf, ">");
11828
11829 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
11830 {
11831 if (loop == 0)
11832 num_term++;
11833 else
11834 (*file)[count++] = vim_strsave(name_buf);
11835 }
11836 }
11837 }
11838 if (loop == 0)
11839 {
11840 if (num_normal > 0)
11841 *num_file = num_normal;
11842 else if (num_term > 0)
11843 *num_file = num_term;
11844 else
11845 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020011846 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011847 if (*file == NULL)
11848 {
11849 *file = (char_u **)"";
11850 return FAIL;
11851 }
11852 }
11853 }
11854 return OK;
11855}
11856
11857 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011858ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011859{
11860 char_u *var = NULL; /* init for GCC */
11861 char_u *buf;
11862
11863 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020011864 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011865 if (*file == NULL)
11866 return FAIL;
11867
11868 /*
11869 * For a terminal key code expand_option_idx is < 0.
11870 */
11871 if (expand_option_idx < 0)
11872 {
11873 var = find_termcode(expand_option_name + 2);
11874 if (var == NULL)
11875 expand_option_idx = findoption(expand_option_name);
11876 }
11877
11878 if (expand_option_idx >= 0)
11879 {
11880 /* put string of option value in NameBuff */
11881 option_value2string(&options[expand_option_idx], expand_option_flags);
11882 var = NameBuff;
11883 }
11884 else if (var == NULL)
11885 var = (char_u *)"";
11886
11887 /* A backslash is required before some characters. This is the reverse of
11888 * what happens in do_set(). */
11889 buf = vim_strsave_escaped(var, escape_chars);
11890
11891 if (buf == NULL)
11892 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010011893 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011894 return FAIL;
11895 }
11896
11897#ifdef BACKSLASH_IN_FILENAME
11898 /* For MS-Windows et al. we don't double backslashes at the start and
11899 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011900 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011901 if (var[0] == '\\' && var[1] == '\\'
11902 && expand_option_idx >= 0
11903 && (options[expand_option_idx].flags & P_EXPAND)
11904 && vim_isfilec(var[2])
11905 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000011906 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011907#endif
11908
11909 *file[0] = buf;
11910 *num_file = 1;
11911 return OK;
11912}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011913
11914/*
11915 * Get the value for the numeric or string option *opp in a nice format into
11916 * NameBuff[]. Must not be called with a hidden option!
11917 */
11918 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011919option_value2string(
11920 struct vimoption *opp,
11921 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011922{
11923 char_u *varp;
11924
11925 varp = get_varp_scope(opp, opt_flags);
11926
11927 if (opp->flags & P_NUM)
11928 {
11929 long wc = 0;
11930
11931 if (wc_use_keyname(varp, &wc))
11932 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
11933 else if (wc != 0)
11934 STRCPY(NameBuff, transchar((int)wc));
11935 else
11936 sprintf((char *)NameBuff, "%ld", *(long *)varp);
11937 }
11938 else /* P_STRING */
11939 {
11940 varp = *(char_u **)(varp);
11941 if (varp == NULL) /* just in case */
11942 NameBuff[0] = NUL;
11943#ifdef FEAT_CRYPT
11944 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000011945 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011946 STRCPY(NameBuff, "*****");
11947#endif
11948 else if (opp->flags & P_EXPAND)
11949 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
11950 /* Translate 'pastetoggle' into special key names */
11951 else if ((char_u **)opp->var == &p_pt)
11952 str2specialbuf(p_pt, NameBuff, MAXPATHL);
11953 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000011954 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011955 }
11956}
11957
11958/*
11959 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
11960 * printed as a keyname.
11961 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
11962 */
11963 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011964wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011965{
11966 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
11967 {
11968 *wcp = *(long *)varp;
11969 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
11970 return TRUE;
11971 }
11972 return FALSE;
11973}
11974
Bram Moolenaar071d4272004-06-13 20:20:40 +000011975/*
11976 * Return TRUE if format option 'x' is in effect.
11977 * Take care of no formatting when 'paste' is set.
11978 */
11979 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011980has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011981{
11982 if (p_paste)
11983 return FALSE;
11984 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
11985}
11986
11987/*
11988 * Return TRUE if "x" is present in 'shortmess' option, or
11989 * 'shortmess' contains 'a' and "x" is present in SHM_A.
11990 */
11991 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010011992shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011993{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010011994 return p_shm != NULL &&
11995 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011996 || (vim_strchr(p_shm, 'a') != NULL
11997 && vim_strchr((char_u *)SHM_A, x) != NULL));
11998}
11999
12000/*
12001 * paste_option_changed() - Called after p_paste was set or reset.
12002 */
12003 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012004paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012005{
12006 static int old_p_paste = FALSE;
12007 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012008 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012009#ifdef FEAT_CMDL_INFO
12010 static int save_ru = 0;
12011#endif
12012#ifdef FEAT_RIGHTLEFT
12013 static int save_ri = 0;
12014 static int save_hkmap = 0;
12015#endif
12016 buf_T *buf;
12017
12018 if (p_paste)
12019 {
12020 /*
12021 * Paste switched from off to on.
12022 * Save the current values, so they can be restored later.
12023 */
12024 if (!old_p_paste)
12025 {
12026 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012027 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012028 {
12029 buf->b_p_tw_nopaste = buf->b_p_tw;
12030 buf->b_p_wm_nopaste = buf->b_p_wm;
12031 buf->b_p_sts_nopaste = buf->b_p_sts;
12032 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012033 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012034#ifdef FEAT_VARTABS
12035 if (buf->b_p_vsts_nopaste)
12036 vim_free(buf->b_p_vsts_nopaste);
12037 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12038 ? vim_strsave(buf->b_p_vsts) : NULL;
12039#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012040 }
12041
12042 /* save global options */
12043 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012044 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012045#ifdef FEAT_CMDL_INFO
12046 save_ru = p_ru;
12047#endif
12048#ifdef FEAT_RIGHTLEFT
12049 save_ri = p_ri;
12050 save_hkmap = p_hkmap;
12051#endif
12052 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012053 p_ai_nopaste = p_ai;
12054 p_et_nopaste = p_et;
12055 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056 p_tw_nopaste = p_tw;
12057 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012058#ifdef FEAT_VARTABS
12059 if (p_vsts_nopaste)
12060 vim_free(p_vsts_nopaste);
12061 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12062#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012063 }
12064
12065 /*
12066 * Always set the option values, also when 'paste' is set when it is
12067 * already on.
12068 */
12069 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012070 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012071 {
12072 buf->b_p_tw = 0; /* textwidth is 0 */
12073 buf->b_p_wm = 0; /* wrapmargin is 0 */
12074 buf->b_p_sts = 0; /* softtabstop is 0 */
12075 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012076 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012077#ifdef FEAT_VARTABS
12078 if (buf->b_p_vsts)
12079 free_string_option(buf->b_p_vsts);
12080 buf->b_p_vsts = empty_option;
12081 if (buf->b_p_vsts_array)
12082 vim_free(buf->b_p_vsts_array);
12083 buf->b_p_vsts_array = 0;
12084#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012085 }
12086
12087 /* set global options */
12088 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012089 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012090#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012091 if (p_ru)
12092 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012093 p_ru = 0; /* no ruler */
12094#endif
12095#ifdef FEAT_RIGHTLEFT
12096 p_ri = 0; /* no reverse insert */
12097 p_hkmap = 0; /* no Hebrew keyboard */
12098#endif
12099 /* set global values for local buffer options */
12100 p_tw = 0;
12101 p_wm = 0;
12102 p_sts = 0;
12103 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012104#ifdef FEAT_VARTABS
12105 if (p_vsts)
12106 free_string_option(p_vsts);
12107 p_vsts = empty_option;
12108#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012109 }
12110
12111 /*
12112 * Paste switched from on to off: Restore saved values.
12113 */
12114 else if (old_p_paste)
12115 {
12116 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012117 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012118 {
12119 buf->b_p_tw = buf->b_p_tw_nopaste;
12120 buf->b_p_wm = buf->b_p_wm_nopaste;
12121 buf->b_p_sts = buf->b_p_sts_nopaste;
12122 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012123 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012124#ifdef FEAT_VARTABS
12125 if (buf->b_p_vsts)
12126 free_string_option(buf->b_p_vsts);
12127 buf->b_p_vsts = buf->b_p_vsts_nopaste
12128 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12129 if (buf->b_p_vsts_array)
12130 vim_free(buf->b_p_vsts_array);
12131 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12132 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12133 else
12134 buf->b_p_vsts_array = 0;
12135#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012136 }
12137
12138 /* restore global options */
12139 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012140 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012141#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012142 if (p_ru != save_ru)
12143 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012144 p_ru = save_ru;
12145#endif
12146#ifdef FEAT_RIGHTLEFT
12147 p_ri = save_ri;
12148 p_hkmap = save_hkmap;
12149#endif
12150 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012151 p_ai = p_ai_nopaste;
12152 p_et = p_et_nopaste;
12153 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012154 p_tw = p_tw_nopaste;
12155 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012156#ifdef FEAT_VARTABS
12157 if (p_vsts)
12158 free_string_option(p_vsts);
12159 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12160#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012161 }
12162
12163 old_p_paste = p_paste;
12164}
12165
12166/*
12167 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12168 *
12169 * Reset 'compatible' and set the values for options that didn't get set yet
12170 * to the Vim defaults.
12171 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012172 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012173 */
12174 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012175vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012176{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012177 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012178 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012179 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012180
12181 if (!option_was_set((char_u *)"cp"))
12182 {
12183 p_cp = FALSE;
12184 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12185 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12186 set_option_default(opt_idx, OPT_FREE, FALSE);
12187 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012188 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012189 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012190
12191 if (fname != NULL)
12192 {
12193 p = vim_getenv(envname, &dofree);
12194 if (p == NULL)
12195 {
12196 /* Set $MYVIMRC to the first vimrc file found. */
12197 p = FullName_save(fname, FALSE);
12198 if (p != NULL)
12199 {
12200 vim_setenv(envname, p);
12201 vim_free(p);
12202 }
12203 }
12204 else if (dofree)
12205 vim_free(p);
12206 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012207}
12208
12209/*
12210 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12211 */
12212 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012213change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012214{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012215 int opt_idx;
12216
Bram Moolenaar071d4272004-06-13 20:20:40 +000012217 if (p_cp != on)
12218 {
12219 p_cp = on;
12220 compatible_set();
12221 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012222 opt_idx = findoption((char_u *)"cp");
12223 if (opt_idx >= 0)
12224 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012225}
12226
12227/*
12228 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012229 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012230 */
12231 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012232option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012233{
12234 int idx;
12235
12236 idx = findoption(name);
12237 if (idx < 0) /* unknown option */
12238 return FALSE;
12239 if (options[idx].flags & P_WAS_SET)
12240 return TRUE;
12241 return FALSE;
12242}
12243
12244/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012245 * Reset the flag indicating option "name" was set.
12246 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012247 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012248reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012249{
12250 int idx = findoption(name);
12251
12252 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012253 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012254 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012255 return OK;
12256 }
12257 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012258}
12259
12260/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012261 * compatible_set() - Called when 'compatible' has been set or unset.
12262 *
12263 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12264 * flag) to a Vi compatible value.
12265 * When 'compatible' is unset: Set all options that have a different default
12266 * for Vim (without the P_VI_DEF flag) to that default.
12267 */
12268 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012269compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012270{
12271 int opt_idx;
12272
12273 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12274 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12275 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12276 set_option_default(opt_idx, OPT_FREE, p_cp);
12277 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012278 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012279}
12280
12281#ifdef FEAT_LINEBREAK
12282
Bram Moolenaar071d4272004-06-13 20:20:40 +000012283/*
12284 * fill_breakat_flags() -- called when 'breakat' changes value.
12285 */
12286 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012287fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012288{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012289 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012290 int i;
12291
12292 for (i = 0; i < 256; i++)
12293 breakat_flags[i] = FALSE;
12294
12295 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012296 for (p = p_breakat; *p; p++)
12297 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012298}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012299#endif
12300
12301/*
12302 * Check an option that can be a range of string values.
12303 *
12304 * Return OK for correct value, FAIL otherwise.
12305 * Empty is always OK.
12306 */
12307 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012308check_opt_strings(
12309 char_u *val,
12310 char **values,
12311 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012312{
12313 return opt_strings_flags(val, values, NULL, list);
12314}
12315
12316/*
12317 * Handle an option that can be a range of string values.
12318 * Set a flag in "*flagp" for each string present.
12319 *
12320 * Return OK for correct value, FAIL otherwise.
12321 * Empty is always OK.
12322 */
12323 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012324opt_strings_flags(
12325 char_u *val, /* new value */
12326 char **values, /* array of valid string values */
12327 unsigned *flagp,
12328 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012329{
12330 int i;
12331 int len;
12332 unsigned new_flags = 0;
12333
12334 while (*val)
12335 {
12336 for (i = 0; ; ++i)
12337 {
12338 if (values[i] == NULL) /* val not found in values[] */
12339 return FAIL;
12340
12341 len = (int)STRLEN(values[i]);
12342 if (STRNCMP(values[i], val, len) == 0
12343 && ((list && val[len] == ',') || val[len] == NUL))
12344 {
12345 val += len + (val[len] == ',');
12346 new_flags |= (1 << i);
12347 break; /* check next item in val list */
12348 }
12349 }
12350 }
12351 if (flagp != NULL)
12352 *flagp = new_flags;
12353
12354 return OK;
12355}
12356
12357/*
12358 * Read the 'wildmode' option, fill wim_flags[].
12359 */
12360 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012361check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012362{
12363 char_u new_wim_flags[4];
12364 char_u *p;
12365 int i;
12366 int idx = 0;
12367
12368 for (i = 0; i < 4; ++i)
12369 new_wim_flags[i] = 0;
12370
12371 for (p = p_wim; *p; ++p)
12372 {
12373 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12374 ;
12375 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12376 return FAIL;
12377 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12378 new_wim_flags[idx] |= WIM_LONGEST;
12379 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12380 new_wim_flags[idx] |= WIM_FULL;
12381 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12382 new_wim_flags[idx] |= WIM_LIST;
12383 else
12384 return FAIL;
12385 p += i;
12386 if (*p == NUL)
12387 break;
12388 if (*p == ',')
12389 {
12390 if (idx == 3)
12391 return FAIL;
12392 ++idx;
12393 }
12394 }
12395
12396 /* fill remaining entries with last flag */
12397 while (idx < 3)
12398 {
12399 new_wim_flags[idx + 1] = new_wim_flags[idx];
12400 ++idx;
12401 }
12402
12403 /* only when there are no errors, wim_flags[] is changed */
12404 for (i = 0; i < 4; ++i)
12405 wim_flags[i] = new_wim_flags[i];
12406 return OK;
12407}
12408
12409/*
12410 * Check if backspacing over something is allowed.
12411 */
12412 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012413can_bs(
12414 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012415{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012416#ifdef FEAT_JOB_CHANNEL
12417 if (what == BS_START && bt_prompt(curbuf))
12418 return FALSE;
12419#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012420 switch (*p_bs)
12421 {
12422 case '2': return TRUE;
12423 case '1': return (what != BS_START);
12424 case '0': return FALSE;
12425 }
12426 return vim_strchr(p_bs, what) != NULL;
12427}
12428
12429/*
12430 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12431 * the file must be considered changed when the value is different.
12432 */
12433 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012434save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012435{
12436 buf->b_start_ffc = *buf->b_p_ff;
12437 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012438 buf->b_start_bomb = buf->b_p_bomb;
12439
Bram Moolenaar071d4272004-06-13 20:20:40 +000012440 /* Only use free/alloc when necessary, they take time. */
12441 if (buf->b_start_fenc == NULL
12442 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
12443 {
12444 vim_free(buf->b_start_fenc);
12445 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
12446 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012447}
12448
12449/*
12450 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
12451 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012452 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
12453 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012454 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012455 * When "ignore_empty" is true don't consider a new, empty buffer to be
12456 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012457 */
12458 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012459file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012460{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000012461 /* In a buffer that was never loaded the options are not valid. */
12462 if (buf->b_flags & BF_NEVERLOADED)
12463 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010012464 if (ignore_empty
12465 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012466 && buf->b_ml.ml_line_count == 1
12467 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
12468 return FALSE;
12469 if (buf->b_start_ffc != *buf->b_p_ff)
12470 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020012471 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012472 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012473 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
12474 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012475 if (buf->b_start_fenc == NULL)
12476 return (*buf->b_p_fenc != NUL);
12477 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012478}
12479
12480/*
12481 * return OK if "p" is a valid fileformat name, FAIL otherwise.
12482 */
12483 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012484check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012485{
12486 return check_opt_strings(p, p_ff_values, FALSE);
12487}
Bram Moolenaar14f24742012-08-08 18:01:05 +020012488
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012489/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010012490 * Return the effective 'scrolloff' value for the current window, using the
12491 * global value when appropriate.
12492 */
12493 long
12494get_scrolloff_value(void)
12495{
12496 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
12497}
12498
12499/*
12500 * Return the effective 'sidescrolloff' value for the current window, using the
12501 * global value when appropriate.
12502 */
12503 long
12504get_sidescrolloff_value(void)
12505{
12506 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
12507}
12508
12509/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012510 * Check matchpairs option for "*initc".
12511 * If there is a match set "*initc" to the matching character and "*findc" to
12512 * the opposite character. Set "*backwards" to the direction.
12513 * When "switchit" is TRUE swap the direction.
12514 */
12515 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012516find_mps_values(
12517 int *initc,
12518 int *findc,
12519 int *backwards,
12520 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012521{
12522 char_u *ptr;
12523
12524 ptr = curbuf->b_p_mps;
12525 while (*ptr != NUL)
12526 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012527 if (has_mbyte)
12528 {
12529 char_u *prev;
12530
12531 if (mb_ptr2char(ptr) == *initc)
12532 {
12533 if (switchit)
12534 {
12535 *findc = *initc;
12536 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12537 *backwards = TRUE;
12538 }
12539 else
12540 {
12541 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
12542 *backwards = FALSE;
12543 }
12544 return;
12545 }
12546 prev = ptr;
12547 ptr += mb_ptr2len(ptr) + 1;
12548 if (mb_ptr2char(ptr) == *initc)
12549 {
12550 if (switchit)
12551 {
12552 *findc = *initc;
12553 *initc = mb_ptr2char(prev);
12554 *backwards = FALSE;
12555 }
12556 else
12557 {
12558 *findc = mb_ptr2char(prev);
12559 *backwards = TRUE;
12560 }
12561 return;
12562 }
12563 ptr += mb_ptr2len(ptr);
12564 }
12565 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010012566 {
12567 if (*ptr == *initc)
12568 {
12569 if (switchit)
12570 {
12571 *backwards = TRUE;
12572 *findc = *initc;
12573 *initc = ptr[2];
12574 }
12575 else
12576 {
12577 *backwards = FALSE;
12578 *findc = ptr[2];
12579 }
12580 return;
12581 }
12582 ptr += 2;
12583 if (*ptr == *initc)
12584 {
12585 if (switchit)
12586 {
12587 *backwards = FALSE;
12588 *findc = *initc;
12589 *initc = ptr[-2];
12590 }
12591 else
12592 {
12593 *backwards = TRUE;
12594 *findc = ptr[-2];
12595 }
12596 return;
12597 }
12598 ++ptr;
12599 }
12600 if (*ptr == ',')
12601 ++ptr;
12602 }
12603}
Bram Moolenaar597a4222014-06-25 14:39:50 +020012604
12605#if defined(FEAT_LINEBREAK) || defined(PROTO)
12606/*
12607 * This is called when 'breakindentopt' is changed and when a window is
12608 * initialized.
12609 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012610 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012611briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020012612{
12613 char_u *p;
12614 int bri_shift = 0;
12615 long bri_min = 20;
12616 int bri_sbr = FALSE;
12617
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012618 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012619 while (*p != NUL)
12620 {
12621 if (STRNCMP(p, "shift:", 6) == 0
12622 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
12623 {
12624 p += 6;
12625 bri_shift = getdigits(&p);
12626 }
12627 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
12628 {
12629 p += 4;
12630 bri_min = getdigits(&p);
12631 }
12632 else if (STRNCMP(p, "sbr", 3) == 0)
12633 {
12634 p += 3;
12635 bri_sbr = TRUE;
12636 }
12637 if (*p != ',' && *p != NUL)
12638 return FAIL;
12639 if (*p == ',')
12640 ++p;
12641 }
12642
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020012643 wp->w_p_brishift = bri_shift;
12644 wp->w_p_brimin = bri_min;
12645 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020012646
12647 return OK;
12648}
12649#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012650
12651/*
12652 * Get the local or global value of 'backupcopy'.
12653 */
12654 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012655get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020012656{
12657 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
12658}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012659
12660#if defined(FEAT_SIGNS) || defined(PROTO)
12661/*
12662 * Return TRUE when window "wp" has a column to draw signs in.
12663 */
12664 int
12665signcolumn_on(win_T *wp)
12666{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020012667 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
12668 // column (if present). Otherwise signs are to be displayed in the sign
12669 // column.
12670 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
12671 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
12672
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020012673 if (*wp->w_p_scl == 'n')
12674 return FALSE;
12675 if (*wp->w_p_scl == 'y')
12676 return TRUE;
12677 return (wp->w_buffer->b_signlist != NULL
12678# ifdef FEAT_NETBEANS_INTG
12679 || wp->w_buffer->b_has_sign_column
12680# endif
12681 );
12682}
12683#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012684
12685#if defined(FEAT_EVAL) || defined(PROTO)
12686/*
12687 * Get window or buffer local options.
12688 */
12689 dict_T *
12690get_winbuf_options(int bufopt)
12691{
12692 dict_T *d;
12693 int opt_idx;
12694
12695 d = dict_alloc();
12696 if (d == NULL)
12697 return NULL;
12698
12699 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12700 {
12701 struct vimoption *opt = &options[opt_idx];
12702
12703 if ((bufopt && (opt->indir & PV_BUF))
12704 || (!bufopt && (opt->indir & PV_WIN)))
12705 {
12706 char_u *varp = get_varp(opt);
12707
12708 if (varp != NULL)
12709 {
12710 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020012711 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020012712 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020012713 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012714 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020012715 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020012716 }
12717 }
12718 }
12719
12720 return d;
12721}
12722#endif