blob: c17e9128a211eb8d6d2ea8f246086b7d0dc58e58 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * Code to handle user-settable options. This is all pretty much table-
12 * driven. Checklist for adding a new option:
13 * - Put it in the options array below (copy an existing entry).
14 * - For a global option: Add a variable for it in option.h.
15 * - For a buffer or window local option:
16 * - Add a PV_XX entry to the enum below.
17 * - Add a variable to the window or buffer struct in structs.h.
18 * - For a window option, add some code to copy_winopt().
19 * - For a buffer option, add some code to buf_copy_options().
20 * - For a buffer string option, add code to check_buf_options().
21 * - If it's a numeric option, add any necessary bounds checks to do_set().
22 * - If it's a list of flags, add some code in do_set(), search for WW_ALL.
23 * - When adding an option with expansion (P_EXPAND), but with a different
24 * default for Vi and Vim (no P_VI_DEF), add some code at VIMEXP.
Bram Moolenaarcea912a2016-10-12 14:20:24 +020025 * - Add documentation! One line in doc/quickref.txt, full description in
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 * options.txt, and any other related places.
27 * - Add an entry in runtime/optwin.vim.
28 * When making changes:
29 * - Adjust the help for the option in doc/option.txt.
30 * - When an entry has the P_VIM flag, or is lacking the P_VI_DEF flag, add a
31 * comment at the help for the 'compatible' option.
32 */
33
34#define IN_OPTION_C
35#include "vim.h"
36
37/*
38 * The options that are local to a window or buffer have "indir" set to one of
39 * these values. Special values:
40 * PV_NONE: global option.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000041 * PV_WIN is added: window-local option
42 * PV_BUF is added: buffer-local option
Bram Moolenaar071d4272004-06-13 20:20:40 +000043 * PV_BOTH is added: global option which also has a local value.
44 */
45#define PV_BOTH 0x1000
Bram Moolenaara23ccb82006-02-27 00:08:02 +000046#define PV_WIN 0x2000
47#define PV_BUF 0x4000
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000048#define PV_MASK 0x0fff
Bram Moolenaara23ccb82006-02-27 00:08:02 +000049#define OPT_WIN(x) (idopt_T)(PV_WIN + (int)(x))
50#define OPT_BUF(x) (idopt_T)(PV_BUF + (int)(x))
Bram Moolenaar071d4272004-06-13 20:20:40 +000051#define OPT_BOTH(x) (idopt_T)(PV_BOTH + (int)(x))
52
Bram Moolenaara23ccb82006-02-27 00:08:02 +000053/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000054 * Definition of the PV_ values for buffer-local options.
55 * The BV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +000056 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +000057#define PV_AI OPT_BUF(BV_AI)
58#define PV_AR OPT_BOTH(OPT_BUF(BV_AR))
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020059#define PV_BKC OPT_BOTH(OPT_BUF(BV_BKC))
Bram Moolenaar81bdd6a2017-07-23 22:57:00 +020060#define PV_BH OPT_BUF(BV_BH)
61#define PV_BT OPT_BUF(BV_BT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000062#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000063# define PV_EFM OPT_BOTH(OPT_BUF(BV_EFM))
64# define PV_GP OPT_BOTH(OPT_BUF(BV_GP))
65# define PV_MP OPT_BOTH(OPT_BUF(BV_MP))
Bram Moolenaara23ccb82006-02-27 00:08:02 +000066#endif
67#define PV_BIN OPT_BUF(BV_BIN)
68#define PV_BL OPT_BUF(BV_BL)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010069#define PV_BOMB OPT_BUF(BV_BOMB)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000070#define PV_CI OPT_BUF(BV_CI)
71#ifdef FEAT_CINDENT
72# define PV_CIN OPT_BUF(BV_CIN)
73# define PV_CINK OPT_BUF(BV_CINK)
74# define PV_CINO OPT_BUF(BV_CINO)
75#endif
76#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
77# define PV_CINW OPT_BUF(BV_CINW)
78#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020079#define PV_CM OPT_BOTH(OPT_BUF(BV_CM))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000080#ifdef FEAT_FOLDING
81# define PV_CMS OPT_BUF(BV_CMS)
82#endif
83#ifdef FEAT_COMMENTS
84# define PV_COM OPT_BUF(BV_COM)
85#endif
86#ifdef FEAT_INS_EXPAND
87# define PV_CPT OPT_BUF(BV_CPT)
88# define PV_DICT OPT_BOTH(OPT_BUF(BV_DICT))
89# define PV_TSR OPT_BOTH(OPT_BUF(BV_TSR))
90#endif
91#ifdef FEAT_COMPL_FUNC
92# define PV_CFU OPT_BUF(BV_CFU)
93#endif
94#ifdef FEAT_FIND_ID
95# define PV_DEF OPT_BOTH(OPT_BUF(BV_DEF))
96# define PV_INC OPT_BOTH(OPT_BUF(BV_INC))
97#endif
98#define PV_EOL OPT_BUF(BV_EOL)
Bram Moolenaar34d72d42015-07-17 14:18:08 +020099#define PV_FIXEOL OPT_BUF(BV_FIXEOL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000100#define PV_EP OPT_BOTH(OPT_BUF(BV_EP))
101#define PV_ET OPT_BUF(BV_ET)
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100102#define PV_FENC OPT_BUF(BV_FENC)
Bram Moolenaar9b2200a2006-03-20 21:55:45 +0000103#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
104# define PV_BEXPR OPT_BOTH(OPT_BUF(BV_BEXPR))
105#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +0100106#define PV_FP OPT_BOTH(OPT_BUF(BV_FP))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000107#ifdef FEAT_EVAL
108# define PV_FEX OPT_BUF(BV_FEX)
109#endif
110#define PV_FF OPT_BUF(BV_FF)
111#define PV_FLP OPT_BUF(BV_FLP)
112#define PV_FO OPT_BUF(BV_FO)
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +0100113#define PV_FT OPT_BUF(BV_FT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000114#define PV_IMI OPT_BUF(BV_IMI)
115#define PV_IMS OPT_BUF(BV_IMS)
116#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
117# define PV_INDE OPT_BUF(BV_INDE)
118# define PV_INDK OPT_BUF(BV_INDK)
119#endif
120#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
121# define PV_INEX OPT_BUF(BV_INEX)
122#endif
123#define PV_INF OPT_BUF(BV_INF)
124#define PV_ISK OPT_BUF(BV_ISK)
125#ifdef FEAT_CRYPT
126# define PV_KEY OPT_BUF(BV_KEY)
127#endif
128#ifdef FEAT_KEYMAP
129# define PV_KMAP OPT_BUF(BV_KMAP)
130#endif
131#define PV_KP OPT_BOTH(OPT_BUF(BV_KP))
132#ifdef FEAT_LISP
133# define PV_LISP OPT_BUF(BV_LISP)
Bram Moolenaaraf6c1312014-03-12 18:55:58 +0100134# define PV_LW OPT_BOTH(OPT_BUF(BV_LW))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000135#endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100136#define PV_MENC OPT_BOTH(OPT_BUF(BV_MENC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000137#define PV_MA OPT_BUF(BV_MA)
138#define PV_ML OPT_BUF(BV_ML)
139#define PV_MOD OPT_BUF(BV_MOD)
140#define PV_MPS OPT_BUF(BV_MPS)
141#define PV_NF OPT_BUF(BV_NF)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000142#ifdef FEAT_COMPL_FUNC
143# define PV_OFU OPT_BUF(BV_OFU)
144#endif
145#define PV_PATH OPT_BOTH(OPT_BUF(BV_PATH))
146#define PV_PI OPT_BUF(BV_PI)
147#ifdef FEAT_TEXTOBJ
148# define PV_QE OPT_BUF(BV_QE)
149#endif
150#define PV_RO OPT_BUF(BV_RO)
151#ifdef FEAT_SMARTINDENT
152# define PV_SI OPT_BUF(BV_SI)
153#endif
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100154#define PV_SN OPT_BUF(BV_SN)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000155#ifdef FEAT_SYN_HL
156# define PV_SMC OPT_BUF(BV_SMC)
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000157# define PV_SYN OPT_BUF(BV_SYN)
158#endif
159#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000160# define PV_SPC OPT_BUF(BV_SPC)
161# define PV_SPF OPT_BUF(BV_SPF)
162# define PV_SPL OPT_BUF(BV_SPL)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000163#endif
164#define PV_STS OPT_BUF(BV_STS)
165#ifdef FEAT_SEARCHPATH
166# define PV_SUA OPT_BUF(BV_SUA)
167#endif
168#define PV_SW OPT_BUF(BV_SW)
169#define PV_SWF OPT_BUF(BV_SWF)
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200170#ifdef FEAT_EVAL
171# define PV_TFU OPT_BUF(BV_TFU)
172#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000173#define PV_TAGS OPT_BOTH(OPT_BUF(BV_TAGS))
Bram Moolenaar0f6562e2015-11-24 18:48:14 +0100174#define PV_TC OPT_BOTH(OPT_BUF(BV_TC))
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000175#define PV_TS OPT_BUF(BV_TS)
176#define PV_TW OPT_BUF(BV_TW)
177#define PV_TX OPT_BUF(BV_TX)
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200178#ifdef FEAT_PERSISTENT_UNDO
179# define PV_UDF OPT_BUF(BV_UDF)
180#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000181#define PV_WM OPT_BUF(BV_WM)
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200182#ifdef FEAT_VARTABS
183# define PV_VSTS OPT_BUF(BV_VSTS)
184# define PV_VTS OPT_BUF(BV_VTS)
185#endif
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000186
187/*
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000188 * Definition of the PV_ values for window-local options.
189 * The WV_ values are defined in option.h.
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000190 */
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000191#define PV_LIST OPT_WIN(WV_LIST)
192#ifdef FEAT_ARABIC
193# define PV_ARAB OPT_WIN(WV_ARAB)
194#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +0200195#ifdef FEAT_LINEBREAK
196# define PV_BRI OPT_WIN(WV_BRI)
197# define PV_BRIOPT OPT_WIN(WV_BRIOPT)
198#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +0200199# define PV_WCR OPT_WIN(WV_WCR)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000200#ifdef FEAT_DIFF
201# define PV_DIFF OPT_WIN(WV_DIFF)
202#endif
203#ifdef FEAT_FOLDING
204# define PV_FDC OPT_WIN(WV_FDC)
205# define PV_FEN OPT_WIN(WV_FEN)
206# define PV_FDI OPT_WIN(WV_FDI)
207# define PV_FDL OPT_WIN(WV_FDL)
208# define PV_FDM OPT_WIN(WV_FDM)
209# define PV_FML OPT_WIN(WV_FML)
210# define PV_FDN OPT_WIN(WV_FDN)
211# ifdef FEAT_EVAL
212# define PV_FDE OPT_WIN(WV_FDE)
213# define PV_FDT OPT_WIN(WV_FDT)
214# endif
215# define PV_FMR OPT_WIN(WV_FMR)
216#endif
217#ifdef FEAT_LINEBREAK
218# define PV_LBR OPT_WIN(WV_LBR)
219#endif
220#define PV_NU OPT_WIN(WV_NU)
Bram Moolenaar64486672010-05-16 15:46:46 +0200221#define PV_RNU OPT_WIN(WV_RNU)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000222#ifdef FEAT_LINEBREAK
223# define PV_NUW OPT_WIN(WV_NUW)
224#endif
Bram Moolenaar4033c552017-09-16 20:54:51 +0200225#if defined(FEAT_QUICKFIX)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000226# define PV_PVW OPT_WIN(WV_PVW)
227#endif
228#ifdef FEAT_RIGHTLEFT
229# define PV_RL OPT_WIN(WV_RL)
230# define PV_RLC OPT_WIN(WV_RLC)
231#endif
Bram Moolenaar8a3bb562018-03-04 20:14:14 +0100232#define PV_SCBIND OPT_WIN(WV_SCBIND)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000233#define PV_SCROLL OPT_WIN(WV_SCROLL)
Bram Moolenaar375e3392019-01-31 18:26:10 +0100234#define PV_SISO OPT_BOTH(OPT_WIN(WV_SISO))
235#define PV_SO OPT_BOTH(OPT_WIN(WV_SO))
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000236#ifdef FEAT_SPELL
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000237# define PV_SPELL OPT_WIN(WV_SPELL)
238#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000239#ifdef FEAT_SYN_HL
240# define PV_CUC OPT_WIN(WV_CUC)
241# define PV_CUL OPT_WIN(WV_CUL)
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
303#ifdef FEAT_INS_EXPAND
304static char_u *p_cpt;
305#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000306#ifdef FEAT_COMPL_FUNC
307static char_u *p_cfu;
Bram Moolenaare344bea2005-09-01 20:46:49 +0000308static char_u *p_ofu;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000309#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +0200310#ifdef FEAT_EVAL
311static char_u *p_tfu;
312#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000313static int p_eol;
Bram Moolenaar34d72d42015-07-17 14:18:08 +0200314static int p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000315static int p_et;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000316static char_u *p_fenc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000317static char_u *p_ff;
318static char_u *p_fo;
Bram Moolenaar86b68352004-12-27 21:59:20 +0000319static char_u *p_flp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000320static char_u *p_ft;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000321static long p_iminsert;
322static long p_imsearch;
323#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
324static char_u *p_inex;
325#endif
326#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
327static char_u *p_inde;
328static char_u *p_indk;
329#endif
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +0000330#if defined(FEAT_EVAL)
331static char_u *p_fex;
332#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000333static int p_inf;
334static char_u *p_isk;
335#ifdef FEAT_CRYPT
336static char_u *p_key;
337#endif
338#ifdef FEAT_LISP
339static int p_lisp;
340#endif
341static int p_ml;
342static int p_ma;
343static int p_mod;
344static char_u *p_mps;
345static char_u *p_nf;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000346static int p_pi;
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000347#ifdef FEAT_TEXTOBJ
348static char_u *p_qe;
349#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000350static int p_ro;
351#ifdef FEAT_SMARTINDENT
352static int p_si;
353#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354static int p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000355static long p_sts;
356#if defined(FEAT_SEARCHPATH)
357static char_u *p_sua;
358#endif
359static long p_sw;
360static int p_swf;
361#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +0000362static long p_smc;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363static char_u *p_syn;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000364#endif
365#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +0000366static char_u *p_spc;
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000367static char_u *p_spf;
Bram Moolenaar217ad922005-03-20 22:37:15 +0000368static char_u *p_spl;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000369#endif
370static long p_ts;
371static long p_tw;
372static int p_tx;
Bram Moolenaar55debbe2010-05-23 23:34:36 +0200373#ifdef FEAT_PERSISTENT_UNDO
374static int p_udf;
375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000376static long p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200377#ifdef FEAT_VARTABS
378static char_u *p_vsts;
379static char_u *p_vts;
380#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000381#ifdef FEAT_KEYMAP
382static char_u *p_keymap;
383#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200384#ifdef FEAT_TERMINAL
Bram Moolenaarb833c1e2018-05-05 16:36:06 +0200385static long p_twsl; /* 'termwinscroll' */
Bram Moolenaar6d150f72018-04-21 20:03:20 +0200386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000387
388/* Saved values for when 'bin' is set. */
389static int p_et_nobin;
390static int p_ml_nobin;
391static long p_tw_nobin;
392static long p_wm_nobin;
393
394/* Saved values for when 'paste' is set */
Bram Moolenaar54f018c2015-09-15 17:30:40 +0200395static int p_ai_nopaste;
396static int p_et_nopaste;
397static long p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000398static long p_tw_nopaste;
399static long p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +0200400#ifdef FEAT_VARTABS
401static char_u *p_vsts_nopaste;
402#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000403
404struct vimoption
405{
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200406 char *fullname; // full option name
407 char *shortname; // permissible abbreviation
408 long_u flags; // see below
409 char_u *var; // global option: pointer to variable;
410 // window-local option: VAR_WIN;
411 // buffer-local option: global value
412 idopt_T indir; // global option: PV_NONE;
413 // local option: indirect option index
414 char_u *def_val[2]; // default values for variable (vi and vim)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000415#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200416 sctx_T script_ctx; // script context where the option was last set
Bram Moolenaar558ca4a2019-04-04 18:15:38 +0200417# define SCTX_INIT , {0, 0, 0, 1}
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000418#else
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200419# define SCTX_INIT
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420#endif
421};
422
423#define VI_DEFAULT 0 /* def_val[VI_DEFAULT] is Vi default value */
424#define VIM_DEFAULT 1 /* def_val[VIM_DEFAULT] is Vim default value */
425
426/*
427 * Flags
428 */
429#define P_BOOL 0x01 /* the option is boolean */
430#define P_NUM 0x02 /* the option is numeric */
431#define P_STRING 0x04 /* the option is a string */
432#define P_ALLOCED 0x08 /* the string option is in allocated memory,
Bram Moolenaar363cb672009-07-22 12:28:17 +0000433 must use free_string_option() when
434 assigning new value. Not set if default is
435 the same. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000436#define P_EXPAND 0x10 /* environment expansion. NOTE: P_EXPAND can
437 never be used for local or hidden options! */
438#define P_NODEFAULT 0x40 /* don't set to default value */
439#define P_DEF_ALLOCED 0x80 /* default value is in allocated memory, must
440 use vim_free() when assigning new value */
441#define P_WAS_SET 0x100 /* option has been set/reset */
442#define P_NO_MKRC 0x200 /* don't include in :mkvimrc output */
443#define P_VI_DEF 0x400 /* Use Vi default for Vim */
444#define P_VIM 0x800 /* Vim option, reset when 'cp' set */
445
446 /* when option changed, what to display: */
447#define P_RSTAT 0x1000 /* redraw status lines */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100448#define P_RWIN 0x2000 /* redraw current window and recompute text */
449#define P_RBUF 0x4000 /* redraw current buffer and recompute text */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000450#define P_RALL 0x6000 /* redraw all windows */
451#define P_RCLR 0x7000 /* clear and redraw all */
452
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200453#define P_COMMA 0x8000 /* comma separated list */
454#define P_ONECOMMA 0x18000L /* P_COMMA and cannot have two consecutive
455 * commas */
456#define P_NODUP 0x20000L /* don't allow duplicate strings */
457#define P_FLAGLIST 0x40000L /* list of single-char flags */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000458
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200459#define P_SECURE 0x80000L /* cannot change in modeline or secure mode */
460#define P_GETTEXT 0x100000L /* expand default value with _() */
461#define P_NOGLOB 0x200000L /* do not use local value for global vimrc */
462#define P_NFNAME 0x400000L /* only normal file name chars allowed */
463#define P_INSECURE 0x800000L /* option was set from a modeline */
464#define P_PRI_MKRC 0x1000000L /* priority for :mkvimrc (setting option has
Bram Moolenaar7554da42016-11-25 22:04:13 +0100465 side effects) */
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200466#define P_NO_ML 0x2000000L /* not allowed in modeline */
467#define P_CURSWANT 0x4000000L /* update curswant required; not needed when
Bram Moolenaar913077c2012-03-28 19:59:04 +0200468 * there is a redraw flag */
Bram Moolenaar7554da42016-11-25 22:04:13 +0100469#define P_NDNAME 0x8000000L /* only normal dir name chars allowed */
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100470#define P_RWINONLY 0x10000000L /* only redraw current window */
Bram Moolenaar110289e2019-05-23 15:38:06 +0200471#define P_MLE 0x20000000L /* under control of 'modelineexpr' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000472
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000473#define ISK_LATIN1 (char_u *)"@,48-57,_,192-255"
474
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000475/* 'isprint' for latin1 is also used for MS-Windows cp1252, where 0x80 is used
476 * for the currency sign. */
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100477#if defined(MSWIN)
Bram Moolenaare2f98b92006-03-29 21:18:24 +0000478# define ISP_LATIN1 (char_u *)"@,~-255"
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000479#else
480# define ISP_LATIN1 (char_u *)"@,161-255"
481#endif
482
Bram Moolenaar05fbfdc2017-08-14 22:35:08 +0200483# 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 +0000484
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +0100485/* Default python version for pyx* commands */
486#if defined(FEAT_PYTHON) && defined(FEAT_PYTHON3)
487# define DEFAULT_PYTHON_VER 0
488#elif defined(FEAT_PYTHON3)
489# define DEFAULT_PYTHON_VER 3
490#elif defined(FEAT_PYTHON)
491# define DEFAULT_PYTHON_VER 2
492#else
493# define DEFAULT_PYTHON_VER 0
494#endif
495
Bram Moolenaarce655742019-01-31 14:12:57 +0100496// used for 'cinkeys' and 'indentkeys'
497#define INDENTKEYS_DEFAULT (char_u *)"0{,0},0),0],:,0#,!^F,o,O,e"
498
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499/*
500 * options[] is initialized here.
501 * The order of the options MUST be alphabetic for ":set all" and findoption().
502 * All option names MUST start with a lowercase letter (for findoption()).
503 * Exception: "t_" options are at the end.
504 * The options with a NULL variable are 'hidden': a set command for them is
505 * ignored and they are not printed.
506 */
Bram Moolenaare89ff042016-02-20 22:17:05 +0100507static struct vimoption options[] =
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508{
Bram Moolenaar913077c2012-03-28 19:59:04 +0200509 {"aleph", "al", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000510#ifdef FEAT_RIGHTLEFT
511 (char_u *)&p_aleph, PV_NONE,
512#else
513 (char_u *)NULL, PV_NONE,
514#endif
515 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100516#if defined(MSWIN) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000517 (char_u *)128L,
518#else
519 (char_u *)224L,
520#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200521 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522 {"antialias", "anti", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
Bram Moolenaard0573012017-10-28 21:11:06 +0200523#if defined(FEAT_GUI_MAC)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000524 (char_u *)&p_antialias, PV_NONE,
525 {(char_u *)FALSE, (char_u *)FALSE}
526#else
527 (char_u *)NULL, PV_NONE,
528 {(char_u *)FALSE, (char_u *)FALSE}
529#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200530 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200531 {"arabic", "arab", P_BOOL|P_VI_DEF|P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000532#ifdef FEAT_ARABIC
533 (char_u *)VAR_WIN, PV_ARAB,
534#else
535 (char_u *)NULL, PV_NONE,
536#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200537 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000538 {"arabicshape", "arshape", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
539#ifdef FEAT_ARABIC
540 (char_u *)&p_arshape, PV_NONE,
541#else
542 (char_u *)NULL, PV_NONE,
543#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200544 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 {"allowrevins", "ari", P_BOOL|P_VI_DEF|P_VIM,
546#ifdef FEAT_RIGHTLEFT
547 (char_u *)&p_ari, PV_NONE,
548#else
549 (char_u *)NULL, PV_NONE,
550#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200551 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000552 {"altkeymap", "akm", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000553 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200554 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000555 {"ambiwidth", "ambw", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000556 (char_u *)&p_ambw, PV_NONE,
557 {(char_u *)"single", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200558 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000559 {"autochdir", "acd", P_BOOL|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100560#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000561 (char_u *)&p_acd, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +0100562 {(char_u *)FALSE, (char_u *)0L}
563#else
564 (char_u *)NULL, PV_NONE,
565 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000566#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200567 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000568 {"autoindent", "ai", P_BOOL|P_VI_DEF,
569 (char_u *)&p_ai, PV_AI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200570 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000571 {"autoprint", "ap", P_BOOL|P_VI_DEF,
572 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200573 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000574 {"autoread", "ar", P_BOOL|P_VI_DEF,
Bram Moolenaara23ccb82006-02-27 00:08:02 +0000575 (char_u *)&p_ar, PV_AR,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200576 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000577 {"autowrite", "aw", P_BOOL|P_VI_DEF,
578 (char_u *)&p_aw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200579 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000580 {"autowriteall","awa", P_BOOL|P_VI_DEF,
581 (char_u *)&p_awa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200582 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000583 {"background", "bg", P_STRING|P_VI_DEF|P_RCLR,
584 (char_u *)&p_bg, PV_NONE,
585 {
Bram Moolenaar4f974752019-02-17 17:44:42 +0100586#if (defined(MSWIN)) && !defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000587 (char_u *)"dark",
588#else
589 (char_u *)"light",
590#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200591 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200592 {"backspace", "bs", P_STRING|P_VI_DEF|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 (char_u *)&p_bs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200594 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000595 {"backup", "bk", P_BOOL|P_VI_DEF|P_VIM,
596 (char_u *)&p_bk, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200597 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200598 {"backupcopy", "bkc", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +0200599 (char_u *)&p_bkc, PV_BKC,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600#ifdef UNIX
601 {(char_u *)"yes", (char_u *)"auto"}
602#else
603 {(char_u *)"auto", (char_u *)"auto"}
604#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200605 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200606 {"backupdir", "bdir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
607 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000608 (char_u *)&p_bdir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200609 {(char_u *)DFLT_BDIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000610 {"backupext", "bex", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000611 (char_u *)&p_bex, PV_NONE,
612 {
613#ifdef VMS
614 (char_u *)"_",
615#else
616 (char_u *)"~",
617#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200618 (char_u *)0L} SCTX_INIT},
Bram Moolenaar06e2c812019-06-12 19:05:48 +0200619 {"backupskip", "bsk", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000620#ifdef FEAT_WILDIGN
621 (char_u *)&p_bsk, PV_NONE,
622 {(char_u *)"", (char_u *)0L}
623#else
624 (char_u *)NULL, PV_NONE,
625 {(char_u *)0L, (char_u *)0L}
626#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200627 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000628 {"balloondelay","bdlay",P_NUM|P_VI_DEF,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100629#ifdef FEAT_BEVAL
Bram Moolenaar071d4272004-06-13 20:20:40 +0000630 (char_u *)&p_bdlay, PV_NONE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100631 {(char_u *)600L, (char_u *)0L}
632#else
633 (char_u *)NULL, PV_NONE,
634 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200636 SCTX_INIT},
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100637 {"ballooneval", "beval",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100638#ifdef FEAT_BEVAL_GUI
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100639 (char_u *)&p_beval, PV_NONE,
640 {(char_u *)FALSE, (char_u *)0L}
641#else
642 (char_u *)NULL, PV_NONE,
643 {(char_u *)0L, (char_u *)0L}
644#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200645 SCTX_INIT},
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100646 {"balloonevalterm", "bevalterm",P_BOOL|P_VI_DEF|P_NO_MKRC,
Bram Moolenaarc3719bd2017-11-18 22:13:31 +0100647#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +0100648 (char_u *)&p_bevalterm, PV_NONE,
649 {(char_u *)FALSE, (char_u *)0L}
650#else
651 (char_u *)NULL, PV_NONE,
652 {(char_u *)0L, (char_u *)0L}
653#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200654 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200655 {"balloonexpr", "bexpr", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaarc43a8b82017-02-25 21:12:29 +0100656#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
657 (char_u *)&p_bexpr, PV_BEXPR,
658 {(char_u *)"", (char_u *)0L}
659#else
660 (char_u *)NULL, PV_NONE,
661 {(char_u *)0L, (char_u *)0L}
662#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200663 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000664 {"beautify", "bf", P_BOOL|P_VI_DEF,
665 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200666 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar165bc692015-07-21 17:53:25 +0200667 {"belloff", "bo", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
668 (char_u *)&p_bo, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200669 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000670 {"binary", "bin", P_BOOL|P_VI_DEF|P_RSTAT,
671 (char_u *)&p_bin, PV_BIN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200672 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000673 {"bioskey", "biosk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000674 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200675 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000676 {"bomb", NULL, P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000677 (char_u *)&p_bomb, PV_BOMB,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200678 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000679 {"breakat", "brk", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
680#ifdef FEAT_LINEBREAK
681 (char_u *)&p_breakat, PV_NONE,
682 {(char_u *)" \t!@*-+;:,./?", (char_u *)0L}
683#else
684 (char_u *)NULL, PV_NONE,
685 {(char_u *)0L, (char_u *)0L}
686#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200687 SCTX_INIT},
Bram Moolenaar597a4222014-06-25 14:39:50 +0200688 {"breakindent", "bri", P_BOOL|P_VI_DEF|P_VIM|P_RWIN,
689#ifdef FEAT_LINEBREAK
690 (char_u *)VAR_WIN, PV_BRI,
691 {(char_u *)FALSE, (char_u *)0L}
692#else
693 (char_u *)NULL, PV_NONE,
694 {(char_u *)0L, (char_u *)0L}
695#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200696 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200697 {"breakindentopt", "briopt", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF
698 |P_ONECOMMA|P_NODUP,
Bram Moolenaar597a4222014-06-25 14:39:50 +0200699#ifdef FEAT_LINEBREAK
700 (char_u *)VAR_WIN, PV_BRIOPT,
701 {(char_u *)"", (char_u *)NULL}
702#else
703 (char_u *)NULL, PV_NONE,
704 {(char_u *)"", (char_u *)NULL}
705#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200706 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000707 {"browsedir", "bsdir",P_STRING|P_VI_DEF,
708#ifdef FEAT_BROWSE
709 (char_u *)&p_bsdir, PV_NONE,
710 {(char_u *)"last", (char_u *)0L}
711#else
712 (char_u *)NULL, PV_NONE,
713 {(char_u *)0L, (char_u *)0L}
714#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200715 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000716 {"bufhidden", "bh", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000717 (char_u *)&p_bh, PV_BH,
718 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200719 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000720 {"buflisted", "bl", P_BOOL|P_VI_DEF|P_NOGLOB,
721 (char_u *)&p_bl, PV_BL,
722 {(char_u *)1L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200723 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000724 {"buftype", "bt", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000725 (char_u *)&p_bt, PV_BT,
726 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200727 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200728 {"casemap", "cmp", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000729 (char_u *)&p_cmp, PV_NONE,
730 {(char_u *)"internal,keepascii", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200731 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +0200732 {"cdpath", "cd", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE|P_COMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000733#ifdef FEAT_SEARCHPATH
734 (char_u *)&p_cdpath, PV_NONE,
735 {(char_u *)",,", (char_u *)0L}
736#else
737 (char_u *)NULL, PV_NONE,
738 {(char_u *)0L, (char_u *)0L}
739#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200740 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000741 {"cedit", NULL, P_STRING,
742#ifdef FEAT_CMDWIN
743 (char_u *)&p_cedit, PV_NONE,
744 {(char_u *)"", (char_u *)CTRL_F_STR}
745#else
746 (char_u *)NULL, PV_NONE,
747 {(char_u *)0L, (char_u *)0L}
748#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200749 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000750 {"charconvert", "ccv", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +0100751#if defined(FEAT_EVAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752 (char_u *)&p_ccv, PV_NONE,
753 {(char_u *)"", (char_u *)0L}
754#else
755 (char_u *)NULL, PV_NONE,
756 {(char_u *)0L, (char_u *)0L}
757#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200758 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000759 {"cindent", "cin", P_BOOL|P_VI_DEF|P_VIM,
760#ifdef FEAT_CINDENT
761 (char_u *)&p_cin, PV_CIN,
762#else
763 (char_u *)NULL, PV_NONE,
764#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200765 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200766 {"cinkeys", "cink", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000767#ifdef FEAT_CINDENT
768 (char_u *)&p_cink, PV_CINK,
Bram Moolenaarce655742019-01-31 14:12:57 +0100769 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000770#else
771 (char_u *)NULL, PV_NONE,
772 {(char_u *)0L, (char_u *)0L}
773#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200774 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200775 {"cinoptions", "cino", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000776#ifdef FEAT_CINDENT
777 (char_u *)&p_cino, PV_CINO,
778#else
779 (char_u *)NULL, PV_NONE,
780#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200781 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200782 {"cinwords", "cinw", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000783#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
784 (char_u *)&p_cinw, PV_CINW,
785 {(char_u *)"if,else,while,do,for,switch",
786 (char_u *)0L}
787#else
788 (char_u *)NULL, PV_NONE,
789 {(char_u *)0L, (char_u *)0L}
790#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200791 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200792 {"clipboard", "cb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000793#ifdef FEAT_CLIPBOARD
794 (char_u *)&p_cb, PV_NONE,
795# ifdef FEAT_XCLIPBOARD
796 {(char_u *)"autoselect,exclude:cons\\|linux",
797 (char_u *)0L}
798# else
799 {(char_u *)"", (char_u *)0L}
800# endif
801#else
802 (char_u *)NULL, PV_NONE,
803 {(char_u *)"", (char_u *)0L}
804#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200805 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806 {"cmdheight", "ch", P_NUM|P_VI_DEF|P_RALL,
807 (char_u *)&p_ch, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200808 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000809 {"cmdwinheight", "cwh", P_NUM|P_VI_DEF,
810#ifdef FEAT_CMDWIN
811 (char_u *)&p_cwh, PV_NONE,
812#else
813 (char_u *)NULL, PV_NONE,
814#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200815 {(char_u *)7L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200816 {"colorcolumn", "cc", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaar1a384422010-07-14 19:53:30 +0200817#ifdef FEAT_SYN_HL
818 (char_u *)VAR_WIN, PV_CC,
819#else
820 (char_u *)NULL, PV_NONE,
821#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200822 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823 {"columns", "co", P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
824 (char_u *)&Columns, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200825 {(char_u *)80L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200826 {"comments", "com", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
827 |P_NODUP|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000828#ifdef FEAT_COMMENTS
829 (char_u *)&p_com, PV_COM,
830 {(char_u *)"s1:/*,mb:*,ex:*/,://,b:#,:%,:XCOMM,n:>,fb:-",
831 (char_u *)0L}
832#else
833 (char_u *)NULL, PV_NONE,
834 {(char_u *)0L, (char_u *)0L}
835#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200836 SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200837 {"commentstring", "cms", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000838#ifdef FEAT_FOLDING
839 (char_u *)&p_cms, PV_CMS,
840 {(char_u *)"/*%s*/", (char_u *)0L}
841#else
842 (char_u *)NULL, PV_NONE,
843 {(char_u *)0L, (char_u *)0L}
844#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200845 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +0000846 /* P_PRI_MKRC isn't needed here, optval_default()
847 * always returns TRUE for 'compatible' */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000848 {"compatible", "cp", P_BOOL|P_RALL,
849 (char_u *)&p_cp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200850 {(char_u *)TRUE, (char_u *)FALSE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200851 {"complete", "cpt", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000852#ifdef FEAT_INS_EXPAND
853 (char_u *)&p_cpt, PV_CPT,
854 {(char_u *)".,w,b,u,t,i", (char_u *)0L}
855#else
856 (char_u *)NULL, PV_NONE,
857 {(char_u *)0L, (char_u *)0L}
858#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200859 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200860 {"concealcursor","cocu", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200861#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200862 (char_u *)VAR_WIN, PV_COCU,
863 {(char_u *)"", (char_u *)NULL}
864#else
865 (char_u *)NULL, PV_NONE,
866 {(char_u *)NULL, (char_u *)0L}
867#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200868 SCTX_INIT},
Bram Moolenaarf5963f72010-07-23 22:10:27 +0200869 {"conceallevel","cole", P_NUM|P_RWIN|P_VI_DEF,
870#ifdef FEAT_CONCEAL
871 (char_u *)VAR_WIN, PV_COLE,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200872#else
873 (char_u *)NULL, PV_NONE,
874#endif
875 {(char_u *)0L, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200876 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000877 {"completefunc", "cfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
878#ifdef FEAT_COMPL_FUNC
879 (char_u *)&p_cfu, PV_CFU,
880 {(char_u *)"", (char_u *)0L}
881#else
882 (char_u *)NULL, PV_NONE,
883 {(char_u *)0L, (char_u *)0L}
884#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200885 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200886 {"completeopt", "cot", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000887#ifdef FEAT_INS_EXPAND
888 (char_u *)&p_cot, PV_NONE,
Bram Moolenaarc270d802006-03-11 21:29:41 +0000889 {(char_u *)"menu,preview", (char_u *)0L}
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000890#else
891 (char_u *)NULL, PV_NONE,
892 {(char_u *)0L, (char_u *)0L}
893#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200894 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 {"confirm", "cf", P_BOOL|P_VI_DEF,
896#if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
897 (char_u *)&p_confirm, PV_NONE,
898#else
899 (char_u *)NULL, PV_NONE,
900#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200901 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902 {"conskey", "consk",P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000903 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200904 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000905 {"copyindent", "ci", P_BOOL|P_VI_DEF|P_VIM,
906 (char_u *)&p_ci, PV_CI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200907 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908 {"cpoptions", "cpo", P_STRING|P_VIM|P_RALL|P_FLAGLIST,
909 (char_u *)&p_cpo, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000910 {(char_u *)CPO_VI, (char_u *)CPO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200911 SCTX_INIT},
Bram Moolenaar49771f42010-07-20 17:32:38 +0200912 {"cryptmethod", "cm", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200913#ifdef FEAT_CRYPT
Bram Moolenaar40e6a712010-05-16 22:32:54 +0200914 (char_u *)&p_cm, PV_CM,
Bram Moolenaara86187b2018-12-16 18:20:00 +0100915 {(char_u *)"blowfish2", (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200916#else
917 (char_u *)NULL, PV_NONE,
Bram Moolenaar49771f42010-07-20 17:32:38 +0200918 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar0bbabe82010-05-17 20:32:55 +0200919#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200920 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921 {"cscopepathcomp", "cspc", P_NUM|P_VI_DEF|P_VIM,
922#ifdef FEAT_CSCOPE
923 (char_u *)&p_cspc, PV_NONE,
924#else
925 (char_u *)NULL, PV_NONE,
926#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200927 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000928 {"cscopeprg", "csprg", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
929#ifdef FEAT_CSCOPE
930 (char_u *)&p_csprg, PV_NONE,
931 {(char_u *)"cscope", (char_u *)0L}
932#else
933 (char_u *)NULL, PV_NONE,
934 {(char_u *)0L, (char_u *)0L}
935#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200936 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +0200937 {"cscopequickfix", "csqf", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000938#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
939 (char_u *)&p_csqf, PV_NONE,
940 {(char_u *)"", (char_u *)0L}
941#else
942 (char_u *)NULL, PV_NONE,
943 {(char_u *)0L, (char_u *)0L}
944#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200945 SCTX_INIT},
Bram Moolenaarf7befa92011-06-12 22:13:40 +0200946 {"cscoperelative", "csre", P_BOOL|P_VI_DEF|P_VIM,
947#ifdef FEAT_CSCOPE
948 (char_u *)&p_csre, PV_NONE,
949#else
950 (char_u *)NULL, PV_NONE,
951#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200952 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000953 {"cscopetag", "cst", P_BOOL|P_VI_DEF|P_VIM,
954#ifdef FEAT_CSCOPE
955 (char_u *)&p_cst, PV_NONE,
956#else
957 (char_u *)NULL, PV_NONE,
958#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200959 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000960 {"cscopetagorder", "csto", P_NUM|P_VI_DEF|P_VIM,
961#ifdef FEAT_CSCOPE
962 (char_u *)&p_csto, PV_NONE,
963#else
964 (char_u *)NULL, PV_NONE,
965#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200966 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000967 {"cscopeverbose", "csverb", P_BOOL|P_VI_DEF|P_VIM,
968#ifdef FEAT_CSCOPE
969 (char_u *)&p_csverbose, PV_NONE,
970#else
971 (char_u *)NULL, PV_NONE,
972#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200973 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar860cae12010-06-05 23:22:07 +0200974 {"cursorbind", "crb", P_BOOL|P_VI_DEF,
Bram Moolenaar860cae12010-06-05 23:22:07 +0200975 (char_u *)VAR_WIN, PV_CRBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200976 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar177ab9e2019-01-15 21:12:57 +0100977 {"cursorcolumn", "cuc", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000978#ifdef FEAT_SYN_HL
979 (char_u *)VAR_WIN, PV_CUC,
980#else
981 (char_u *)NULL, PV_NONE,
982#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200983 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara2477fd2016-12-03 15:13:20 +0100984 {"cursorline", "cul", P_BOOL|P_VI_DEF|P_RWINONLY,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +0000985#ifdef FEAT_SYN_HL
986 (char_u *)VAR_WIN, PV_CUL,
987#else
988 (char_u *)NULL, PV_NONE,
989#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200990 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +0000991 {"debug", NULL, P_STRING|P_VI_DEF,
992 (char_u *)&p_debug, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +0200993 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +0200994 {"define", "def", P_STRING|P_ALLOCED|P_VI_DEF|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000995#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +0000996 (char_u *)&p_def, PV_DEF,
Bram Moolenaard4755bb2004-09-02 19:12:26 +0000997 {(char_u *)"^\\s*#\\s*define", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000998#else
999 (char_u *)NULL, PV_NONE,
1000 {(char_u *)NULL, (char_u *)0L}
1001#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001002 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001003 {"delcombine", "deco", P_BOOL|P_VI_DEF|P_VIM,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001004 (char_u *)&p_deco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001005 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar7554da42016-11-25 22:04:13 +01001006 {"dictionary", "dict", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001007#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001008 (char_u *)&p_dict, PV_DICT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001009#else
1010 (char_u *)NULL, PV_NONE,
1011#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001012 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001013 {"diff", NULL, P_BOOL|P_VI_DEF|P_RWIN|P_NOGLOB,
1014#ifdef FEAT_DIFF
1015 (char_u *)VAR_WIN, PV_DIFF,
1016#else
1017 (char_u *)NULL, PV_NONE,
1018#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001019 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001020 {"diffexpr", "dex", P_STRING|P_VI_DEF|P_SECURE|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001021#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
1022 (char_u *)&p_dex, PV_NONE,
1023 {(char_u *)"", (char_u *)0L}
1024#else
1025 (char_u *)NULL, PV_NONE,
1026 {(char_u *)0L, (char_u *)0L}
1027#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001028 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001029 {"diffopt", "dip", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN|P_ONECOMMA
1030 |P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031#ifdef FEAT_DIFF
1032 (char_u *)&p_dip, PV_NONE,
Bram Moolenaarc93262b2018-09-10 21:15:40 +02001033 {(char_u *)"internal,filler", (char_u *)NULL}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001034#else
1035 (char_u *)NULL, PV_NONE,
1036 {(char_u *)"", (char_u *)NULL}
1037#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001038 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001039 {"digraph", "dg", P_BOOL|P_VI_DEF|P_VIM,
1040#ifdef FEAT_DIGRAPHS
1041 (char_u *)&p_dg, PV_NONE,
1042#else
1043 (char_u *)NULL, PV_NONE,
1044#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001045 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001046 {"directory", "dir", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA
1047 |P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001048 (char_u *)&p_dir, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001049 {(char_u *)DFLT_DIR, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001050 {"display", "dy", P_STRING|P_VI_DEF|P_ONECOMMA|P_RALL|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 (char_u *)&p_dy, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001052 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001053 {"eadirection", "ead", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001054 (char_u *)&p_ead, PV_NONE,
1055 {(char_u *)"both", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001056 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001057 {"edcompatible","ed", P_BOOL|P_VI_DEF,
1058 (char_u *)&p_ed, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001059 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar3848e002016-03-19 18:42:29 +01001060 {"emoji", "emo", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar3848e002016-03-19 18:42:29 +01001061 (char_u *)&p_emoji, PV_NONE,
1062 {(char_u *)TRUE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001063 SCTX_INIT},
Bram Moolenaar865242e2010-07-14 21:12:05 +02001064 {"encoding", "enc", P_STRING|P_VI_DEF|P_RCLR|P_NO_ML,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001065 (char_u *)&p_enc, PV_NONE,
1066 {(char_u *)ENC_DFLT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001067 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 {"endofline", "eol", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1069 (char_u *)&p_eol, PV_EOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001070 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001071 {"equalalways", "ea", P_BOOL|P_VI_DEF|P_RALL,
1072 (char_u *)&p_ea, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001073 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001074 {"equalprg", "ep", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001075 (char_u *)&p_ep, PV_EP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001076 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001077 {"errorbells", "eb", P_BOOL|P_VI_DEF,
1078 (char_u *)&p_eb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001079 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001080 {"errorfile", "ef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1081#ifdef FEAT_QUICKFIX
1082 (char_u *)&p_ef, PV_NONE,
1083 {(char_u *)DFLT_ERRORFILE, (char_u *)0L}
1084#else
1085 (char_u *)NULL, PV_NONE,
1086 {(char_u *)NULL, (char_u *)0L}
1087#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001088 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001089 {"errorformat", "efm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001090#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001091 (char_u *)&p_efm, PV_EFM,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001092 {(char_u *)DFLT_EFM, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001093#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 Moolenaar071d4272004-06-13 20:20:40 +00001098 {"esckeys", "ek", P_BOOL|P_VIM,
1099 (char_u *)&p_ek, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001100 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001101 {"eventignore", "ei", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001102 (char_u *)&p_ei, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001103 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001104 {"expandtab", "et", P_BOOL|P_VI_DEF|P_VIM,
1105 (char_u *)&p_et, PV_ET,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001106 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001107 {"exrc", "ex", P_BOOL|P_VI_DEF|P_SECURE,
1108 (char_u *)&p_exrc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001109 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001110 {"fileencoding","fenc", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_RBUF
1111 |P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001112 (char_u *)&p_fenc, PV_FENC,
1113 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001114 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001115 {"fileencodings","fencs", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001116 (char_u *)&p_fencs, PV_NONE,
1117 {(char_u *)"ucs-bom", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001118 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001119 {"fileformat", "ff", P_STRING|P_ALLOCED|P_VI_DEF|P_RSTAT|P_NO_MKRC
1120 |P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001121 (char_u *)&p_ff, PV_FF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001122 {(char_u *)DFLT_FF, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001123 {"fileformats", "ffs", P_STRING|P_VIM|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001124 (char_u *)&p_ffs, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001125 {(char_u *)DFLT_FFS_VI, (char_u *)DFLT_FFS_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001126 SCTX_INIT},
Bram Moolenaar71afbfe2013-03-19 16:49:16 +01001127 {"fileignorecase", "fic", P_BOOL|P_VI_DEF,
1128 (char_u *)&p_fic, PV_NONE,
1129 {
1130#ifdef CASE_INSENSITIVE_FILENAME
1131 (char_u *)TRUE,
1132#else
1133 (char_u *)FALSE,
1134#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001135 (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001136 {"filetype", "ft", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001137 (char_u *)&p_ft, PV_FT,
1138 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001139 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001140 {"fillchars", "fcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001141 (char_u *)&p_fcs, PV_NONE,
1142 {(char_u *)"vert:|,fold:-", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001143 SCTX_INIT},
Bram Moolenaar34d72d42015-07-17 14:18:08 +02001144 {"fixendofline", "fixeol", P_BOOL|P_VI_DEF|P_RSTAT,
1145 (char_u *)&p_fixeol, PV_FIXEOL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001146 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147 {"fkmap", "fk", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001148 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001149 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 {"flash", "fl", P_BOOL|P_VI_DEF,
1151 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001152 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001153 {"foldclose", "fcl", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001154#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001155 (char_u *)&p_fcl, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001156 {(char_u *)"", (char_u *)0L}
1157#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001158 (char_u *)NULL, PV_NONE,
1159 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001160#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001161 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001162 {"foldcolumn", "fdc", P_NUM|P_VI_DEF|P_RWIN,
1163#ifdef FEAT_FOLDING
1164 (char_u *)VAR_WIN, PV_FDC,
1165 {(char_u *)FALSE, (char_u *)0L}
1166#else
1167 (char_u *)NULL, PV_NONE,
1168 {(char_u *)NULL, (char_u *)0L}
1169#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001170 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001171 {"foldenable", "fen", P_BOOL|P_VI_DEF|P_RWIN,
1172#ifdef FEAT_FOLDING
1173 (char_u *)VAR_WIN, PV_FEN,
1174 {(char_u *)TRUE, (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 Moolenaar110289e2019-05-23 15:38:06 +02001180 {"foldexpr", "fde", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001181#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1182 (char_u *)VAR_WIN, PV_FDE,
1183 {(char_u *)"0", (char_u *)NULL}
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 Moolenaar071d4272004-06-13 20:20:40 +00001189 {"foldignore", "fdi", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001190#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001191 (char_u *)VAR_WIN, PV_FDI,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001192 {(char_u *)"#", (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 {"foldlevel", "fdl", P_NUM|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_FDL,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001201 {(char_u *)0L, (char_u *)0L}
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 Moolenaar913077c2012-03-28 19:59:04 +02001207 {"foldlevelstart","fdls", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001208#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001209 (char_u *)&p_fdls, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001210 {(char_u *)-1L, (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 Moolenaar071d4272004-06-13 20:20:40 +00001216 {"foldmarker", "fmr", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001217 P_RWIN|P_ONECOMMA|P_NODUP,
Bram Moolenaar37640762017-02-25 22:37:15 +01001218#ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 (char_u *)VAR_WIN, PV_FMR,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001220 {(char_u *)"{{{,}}}", (char_u *)NULL}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001221#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001222 (char_u *)NULL, PV_NONE,
1223 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001225 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001226 {"foldmethod", "fdm", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN,
1227#ifdef FEAT_FOLDING
1228 (char_u *)VAR_WIN, PV_FDM,
1229 {(char_u *)"manual", (char_u *)NULL}
1230#else
1231 (char_u *)NULL, PV_NONE,
1232 {(char_u *)NULL, (char_u *)0L}
1233#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001234 SCTX_INIT},
Bram Moolenaara713ff82017-02-25 22:18:43 +01001235 {"foldminlines","fml", P_NUM|P_VI_DEF|P_RWIN,
1236#ifdef FEAT_FOLDING
1237 (char_u *)VAR_WIN, PV_FML,
1238 {(char_u *)1L, (char_u *)0L}
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 {"foldnestmax", "fdn", P_NUM|P_VI_DEF|P_RWIN,
1245#ifdef FEAT_FOLDING
1246 (char_u *)VAR_WIN, PV_FDN,
1247 {(char_u *)20L, (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 {"foldopen", "fdo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_CURSWANT,
1254#ifdef FEAT_FOLDING
1255 (char_u *)&p_fdo, PV_NONE,
1256 {(char_u *)"block,hor,mark,percent,quickfix,search,tag,undo",
1257 (char_u *)0L}
1258#else
1259 (char_u *)NULL, PV_NONE,
1260 {(char_u *)NULL, (char_u *)0L}
1261#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001262 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001263 {"foldtext", "fdt", P_STRING|P_ALLOCED|P_VIM|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001264#if defined(FEAT_FOLDING) && defined(FEAT_EVAL)
1265 (char_u *)VAR_WIN, PV_FDT,
1266 {(char_u *)"foldtext()", (char_u *)NULL}
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 {"formatexpr", "fex", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001273#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00001274 (char_u *)&p_fex, PV_FEX,
1275 {(char_u *)"", (char_u *)0L}
1276#else
1277 (char_u *)NULL, PV_NONE,
1278 {(char_u *)0L, (char_u *)0L}
1279#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001280 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001281 {"formatoptions","fo", P_STRING|P_ALLOCED|P_VIM|P_FLAGLIST,
1282 (char_u *)&p_fo, PV_FO,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001283 {(char_u *)DFLT_FO_VI, (char_u *)DFLT_FO_VIM}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001284 SCTX_INIT},
Bram Moolenaar86b68352004-12-27 21:59:20 +00001285 {"formatlistpat","flp", P_STRING|P_ALLOCED|P_VI_DEF,
1286 (char_u *)&p_flp, PV_FLP,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001287 {(char_u *)"^\\s*\\d\\+[\\]:.)}\\t ]\\s*",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001288 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001289 {"formatprg", "fp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar9be7c042017-01-14 14:28:30 +01001290 (char_u *)&p_fp, PV_FP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001291 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001292 {"fsync", "fs", P_BOOL|P_SECURE|P_VI_DEF,
1293#ifdef HAVE_FSYNC
1294 (char_u *)&p_fs, PV_NONE,
1295 {(char_u *)TRUE, (char_u *)0L}
1296#else
1297 (char_u *)NULL, PV_NONE,
1298 {(char_u *)FALSE, (char_u *)0L}
1299#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001300 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001301 {"gdefault", "gd", P_BOOL|P_VI_DEF|P_VIM,
1302 (char_u *)&p_gd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001303 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001304 {"graphic", "gr", P_BOOL|P_VI_DEF,
1305 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001306 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001307 {"grepformat", "gfm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001308#ifdef FEAT_QUICKFIX
1309 (char_u *)&p_gefm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001310 {(char_u *)DFLT_GREPFORMAT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001311#else
1312 (char_u *)NULL, PV_NONE,
1313 {(char_u *)NULL, (char_u *)0L}
1314#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001315 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316 {"grepprg", "gp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1317#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001318 (char_u *)&p_gp, PV_GP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001319 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001320# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001321 /* may be changed to "grep -n" in os_win32.c */
1322 (char_u *)"findstr /n",
1323# else
1324# ifdef UNIX
1325 /* Add an extra file name so that grep will always
1326 * insert a file name in the match line. */
1327 (char_u *)"grep -n $* /dev/null",
1328# else
1329# ifdef VMS
1330 (char_u *)"SEARCH/NUMBERS ",
1331# else
1332 (char_u *)"grep -n ",
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001333# endif
1334# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335# endif
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001336 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001337#else
1338 (char_u *)NULL, PV_NONE,
1339 {(char_u *)NULL, (char_u *)0L}
1340#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001341 SCTX_INIT},
Bram Moolenaar8a633e32016-04-21 21:10:14 +02001342 {"guicursor", "gcr", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001343#ifdef CURSOR_SHAPE
1344 (char_u *)&p_guicursor, PV_NONE,
1345 {
1346# ifdef FEAT_GUI
1347 (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 +01001348# else /* Win32 console */
Bram Moolenaar071d4272004-06-13 20:20:40 +00001349 (char_u *)"n-v-c:block,o:hor50,i-ci:hor15,r-cr:hor30,sm:block",
1350# endif
1351 (char_u *)0L}
1352#else
1353 (char_u *)NULL, PV_NONE,
1354 {(char_u *)NULL, (char_u *)0L}
1355#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001356 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001357 {"guifont", "gfn", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358#ifdef FEAT_GUI
1359 (char_u *)&p_guifont, PV_NONE,
1360 {(char_u *)"", (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 {"guifontset", "gfs", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001367#if defined(FEAT_GUI) && defined(FEAT_XFONTSET)
1368 (char_u *)&p_guifontset, 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 {"guifontwide", "gfw", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001376#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001377 (char_u *)&p_guifontwide, 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 Moolenaar071d4272004-06-13 20:20:40 +00001384 {"guiheadroom", "ghr", P_NUM|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001385#if defined(FEAT_GUI_GTK) || defined(FEAT_GUI_X11)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001386 (char_u *)&p_ghr, PV_NONE,
1387#else
1388 (char_u *)NULL, PV_NONE,
1389#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001390 {(char_u *)50L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001391 {"guioptions", "go", P_STRING|P_VI_DEF|P_RALL|P_FLAGLIST,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001392#if defined(FEAT_GUI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001393 (char_u *)&p_go, PV_NONE,
Bram Moolenaard0573012017-10-28 21:11:06 +02001394# if defined(UNIX) && !defined(FEAT_GUI_MAC)
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001395 {(char_u *)"aegimrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001396# else
Bram Moolenaar32466aa2006-02-24 23:53:04 +00001397 {(char_u *)"egmrLtT", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001398# endif
1399#else
1400 (char_u *)NULL, PV_NONE,
1401 {(char_u *)NULL, (char_u *)0L}
1402#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001403 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001404 {"guipty", NULL, P_BOOL|P_VI_DEF,
1405#if defined(FEAT_GUI)
1406 (char_u *)&p_guipty, PV_NONE,
1407#else
1408 (char_u *)NULL, PV_NONE,
1409#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001410 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001411 {"guitablabel", "gtl", P_STRING|P_VI_DEF|P_RWIN|P_MLE,
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00001412#if defined(FEAT_GUI_TABLINE)
1413 (char_u *)&p_gtl, PV_NONE,
1414 {(char_u *)"", (char_u *)0L}
1415#else
1416 (char_u *)NULL, PV_NONE,
1417 {(char_u *)NULL, (char_u *)0L}
1418#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001419 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001420 {"guitabtooltip", "gtt", P_STRING|P_VI_DEF|P_RWIN,
Bram Moolenaar57657d82006-04-21 22:12:41 +00001421#if defined(FEAT_GUI_TABLINE)
1422 (char_u *)&p_gtt, 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 Moolenaar071d4272004-06-13 20:20:40 +00001429 {"hardtabs", "ht", P_NUM|P_VI_DEF,
1430 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001431 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001432 {"helpfile", "hf", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1433 (char_u *)&p_hf, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001434 {(char_u *)DFLT_HELPFILE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001435 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001436 {"helpheight", "hh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001437 (char_u *)&p_hh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001438 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001439 {"helplang", "hlg", P_STRING|P_VI_DEF|P_ONECOMMA,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001440#ifdef FEAT_MULTI_LANG
1441 (char_u *)&p_hlg, PV_NONE,
1442 {(char_u *)"", (char_u *)0L}
1443#else
1444 (char_u *)NULL, PV_NONE,
1445 {(char_u *)0L, (char_u *)0L}
1446#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001447 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001448 {"hidden", "hid", P_BOOL|P_VI_DEF,
1449 (char_u *)&p_hid, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001450 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001451 {"highlight", "hl", P_STRING|P_VI_DEF|P_RCLR|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001452 (char_u *)&p_hl, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001453 {(char_u *)HIGHLIGHT_INIT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001454 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001455 {"history", "hi", P_NUM|P_VIM,
1456 (char_u *)&p_hi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001457 {(char_u *)0L, (char_u *)50L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001458 {"hkmap", "hk", P_BOOL|P_VI_DEF|P_VIM,
1459#ifdef FEAT_RIGHTLEFT
1460 (char_u *)&p_hkmap, PV_NONE,
1461#else
1462 (char_u *)NULL, PV_NONE,
1463#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001464 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001465 {"hkmapp", "hkp", P_BOOL|P_VI_DEF|P_VIM,
1466#ifdef FEAT_RIGHTLEFT
1467 (char_u *)&p_hkmapp, PV_NONE,
1468#else
1469 (char_u *)NULL, PV_NONE,
1470#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001471 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001472 {"hlsearch", "hls", P_BOOL|P_VI_DEF|P_VIM|P_RALL,
1473 (char_u *)&p_hls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001474 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001475 {"icon", NULL, P_BOOL|P_VI_DEF,
1476#ifdef FEAT_TITLE
1477 (char_u *)&p_icon, PV_NONE,
1478#else
1479 (char_u *)NULL, PV_NONE,
1480#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001481 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001482 {"iconstring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001483#ifdef FEAT_TITLE
1484 (char_u *)&p_iconstring, PV_NONE,
1485#else
1486 (char_u *)NULL, PV_NONE,
1487#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001488 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001489 {"ignorecase", "ic", P_BOOL|P_VI_DEF,
1490 (char_u *)&p_ic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001491 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001492 {"imactivatefunc","imaf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001493#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001494 (char_u *)&p_imaf, PV_NONE,
1495 {(char_u *)"", (char_u *)NULL}
1496# else
1497 (char_u *)NULL, PV_NONE,
1498 {(char_u *)NULL, (char_u *)0L}
1499# endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001500 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001501 {"imactivatekey","imak",P_STRING|P_VI_DEF,
Bram Moolenaar9372a112005-12-06 19:59:18 +00001502#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001503 (char_u *)&p_imak, PV_NONE,
1504#else
1505 (char_u *)NULL, PV_NONE,
1506#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001507 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001508 {"imcmdline", "imc", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001509 (char_u *)&p_imcmdline, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001510 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001511 {"imdisable", "imd", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001512 (char_u *)&p_imdisable, PV_NONE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001513#ifdef __sgi
1514 {(char_u *)TRUE, (char_u *)0L}
1515#else
1516 {(char_u *)FALSE, (char_u *)0L}
1517#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001518 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001519 {"iminsert", "imi", P_NUM|P_VI_DEF,
1520 (char_u *)&p_iminsert, PV_IMI,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001521 {(char_u *)B_IMODE_NONE, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001522 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001523 {"imsearch", "ims", P_NUM|P_VI_DEF,
1524 (char_u *)&p_imsearch, PV_IMS,
Bram Moolenaar4cf56bb2017-09-16 15:50:32 +02001525 {(char_u *)B_IMODE_USE_INSERT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001526 SCTX_INIT},
Bram Moolenaar4a460702013-06-29 14:42:26 +02001527 {"imstatusfunc","imsf",P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01001528#if defined(FEAT_EVAL)
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001529 (char_u *)&p_imsf, PV_NONE,
1530 {(char_u *)"", (char_u *)NULL}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001531#else
Bram Moolenaarabab85a2013-06-26 19:18:05 +02001532 (char_u *)NULL, PV_NONE,
1533 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001534#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001535 SCTX_INIT},
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02001536 {"imstyle", "imst", P_NUM|P_VI_DEF|P_SECURE,
1537#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1538 (char_u *)&p_imst, PV_NONE,
1539 {(char_u *)IM_OVER_THE_SPOT, (char_u *)0L}
1540#else
1541 (char_u *)NULL, PV_NONE,
1542 {(char_u *)0L, (char_u *)0L}
1543#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001544 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001545 {"include", "inc", P_STRING|P_ALLOCED|P_VI_DEF,
1546#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001547 (char_u *)&p_inc, PV_INC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001548 {(char_u *)"^\\s*#\\s*include", (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 Moolenaar110289e2019-05-23 15:38:06 +02001554 {"includeexpr", "inex", P_STRING|P_ALLOCED|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001555#if defined(FEAT_FIND_ID) && defined(FEAT_EVAL)
1556 (char_u *)&p_inex, PV_INEX,
1557 {(char_u *)"", (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 Moolenaar071d4272004-06-13 20:20:40 +00001563 {"incsearch", "is", P_BOOL|P_VI_DEF|P_VIM,
1564 (char_u *)&p_is, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001565 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02001566 {"indentexpr", "inde", P_STRING|P_ALLOCED|P_VI_DEF|P_VIM|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001567#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1568 (char_u *)&p_inde, PV_INDE,
1569 {(char_u *)"", (char_u *)0L}
1570#else
1571 (char_u *)NULL, PV_NONE,
1572 {(char_u *)0L, (char_u *)0L}
1573#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001574 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001575 {"indentkeys", "indk", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001576#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
1577 (char_u *)&p_indk, PV_INDK,
Bram Moolenaarce655742019-01-31 14:12:57 +01001578 {INDENTKEYS_DEFAULT, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001579#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 Moolenaar071d4272004-06-13 20:20:40 +00001584 {"infercase", "inf", P_BOOL|P_VI_DEF,
1585 (char_u *)&p_inf, PV_INF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001586 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001587 {"insertmode", "im", P_BOOL|P_VI_DEF|P_VIM,
1588 (char_u *)&p_im, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001589 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001590 {"isfname", "isf", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1591 (char_u *)&p_isf, PV_NONE,
1592 {
1593#ifdef BACKSLASH_IN_FILENAME
1594 /* Excluded are: & and ^ are special in cmd.exe
1595 * ( and ) are used in text separating fnames */
1596 (char_u *)"@,48-57,/,\\,.,-,_,+,,,#,$,%,{,},[,],:,@-@,!,~,=",
1597#else
1598# ifdef AMIGA
1599 (char_u *)"@,48-57,/,.,-,_,+,,,$,:",
1600# else
1601# ifdef VMS
1602 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,<,>,[,],:,;,~",
1603# else /* UNIX et al. */
1604# ifdef EBCDIC
1605 (char_u *)"@,240-249,/,.,-,_,+,,,#,$,%,~,=",
1606# else
1607 (char_u *)"@,48-57,/,.,-,_,+,,,#,$,%,~,=",
1608# endif
1609# endif
1610# endif
1611#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001612 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001613 {"isident", "isi", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
1614 (char_u *)&p_isi, PV_NONE,
1615 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001616#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001617 (char_u *)"@,48-57,_,128-167,224-235",
1618#else
1619# ifdef EBCDIC
1620 /* TODO: EBCDIC Check this! @ == isalpha()*/
1621 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1622 "112-120,128,140-142,156,158,172,"
1623 "174,186,191,203-207,219-225,235-239,"
1624 "251-254",
1625# else
1626 (char_u *)"@,48-57,_,192-255",
1627# endif
1628#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001629 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001630 {"iskeyword", "isk", P_STRING|P_ALLOCED|P_VIM|P_COMMA|P_NODUP,
1631 (char_u *)&p_isk, PV_ISK,
1632 {
1633#ifdef EBCDIC
1634 (char_u *)"@,240-249,_",
1635 /* TODO: EBCDIC Check this! @ == isalpha()*/
1636 (char_u *)"@,240-249,_,66-73,81-89,98-105,"
1637 "112-120,128,140-142,156,158,172,"
1638 "174,186,191,203-207,219-225,235-239,"
1639 "251-254",
1640#else
1641 (char_u *)"@,48-57,_",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001642# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001643 (char_u *)"@,48-57,_,128-167,224-235"
1644# else
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001645 ISK_LATIN1
Bram Moolenaar071d4272004-06-13 20:20:40 +00001646# endif
1647#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001648 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001649 {"isprint", "isp", P_STRING|P_VI_DEF|P_RALL|P_COMMA|P_NODUP,
1650 (char_u *)&p_isp, PV_NONE,
1651 {
Bram Moolenaard0573012017-10-28 21:11:06 +02001652#if defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 (char_u *)"@,~-255",
1654#else
1655# ifdef EBCDIC
1656 /* all chars above 63 are printable */
1657 (char_u *)"63-255",
1658# else
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001659 ISP_LATIN1,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001660# endif
1661#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001662 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001663 {"joinspaces", "js", P_BOOL|P_VI_DEF|P_VIM,
1664 (char_u *)&p_js, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001665 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001666 {"key", NULL, P_STRING|P_ALLOCED|P_VI_DEF|P_NO_MKRC,
1667#ifdef FEAT_CRYPT
1668 (char_u *)&p_key, PV_KEY,
1669 {(char_u *)"", (char_u *)0L}
1670#else
1671 (char_u *)NULL, PV_NONE,
1672 {(char_u *)0L, (char_u *)0L}
1673#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001674 SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00001675 {"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 +00001676#ifdef FEAT_KEYMAP
1677 (char_u *)&p_keymap, PV_KMAP,
1678 {(char_u *)"", (char_u *)0L}
1679#else
1680 (char_u *)NULL, PV_NONE,
1681 {(char_u *)"", (char_u *)0L}
1682#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001683 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001684 {"keymodel", "km", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001685 (char_u *)&p_km, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001686 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001687 {"keywordprg", "kp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001688 (char_u *)&p_kp, PV_KP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001689 {
Bram Moolenaarfd89d7e2016-06-04 20:25:05 +02001690#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001691 (char_u *)":help",
1692#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001693# ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +00001694 (char_u *)"help",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01001695# else
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001696# ifdef USEMAN_S
1697 (char_u *)"man -s",
1698# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00001699 (char_u *)"man",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001700# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001701# endif
1702#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001703 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001704 {"langmap", "lmap", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001705#ifdef FEAT_LANGMAP
1706 (char_u *)&p_langmap, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001707 {(char_u *)"", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001708#else
1709 (char_u *)NULL, PV_NONE,
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001710 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001711#endif
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02001712 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001713 {"langmenu", "lm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001714#if defined(FEAT_MENU) && defined(FEAT_MULTI_LANG)
1715 (char_u *)&p_lm, PV_NONE,
1716#else
1717 (char_u *)NULL, PV_NONE,
1718#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001719 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar4391cf92014-11-05 17:44:52 +01001720 {"langnoremap", "lnr", P_BOOL|P_VI_DEF,
1721#ifdef FEAT_LANGMAP
1722 (char_u *)&p_lnr, PV_NONE,
1723#else
1724 (char_u *)NULL, PV_NONE,
1725#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001726 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar920694c2016-08-21 17:45:02 +02001727 {"langremap", "lrm", P_BOOL|P_VI_DEF,
1728#ifdef FEAT_LANGMAP
1729 (char_u *)&p_lrm, PV_NONE,
1730#else
1731 (char_u *)NULL, PV_NONE,
1732#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001733 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001734 {"laststatus", "ls", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001735 (char_u *)&p_ls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001736 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001737 {"lazyredraw", "lz", P_BOOL|P_VI_DEF,
1738 (char_u *)&p_lz, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001739 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 {"linebreak", "lbr", P_BOOL|P_VI_DEF|P_RWIN,
1741#ifdef FEAT_LINEBREAK
1742 (char_u *)VAR_WIN, PV_LBR,
1743#else
1744 (char_u *)NULL, PV_NONE,
1745#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001746 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001747 {"lines", NULL, P_NUM|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RCLR,
1748 (char_u *)&Rows, PV_NONE,
1749 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001750#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001751 (char_u *)25L,
1752#else
1753 (char_u *)24L,
1754#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001755 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001756 {"linespace", "lsp", P_NUM|P_VI_DEF|P_RCLR,
1757#ifdef FEAT_GUI
1758 (char_u *)&p_linespace, PV_NONE,
1759#else
1760 (char_u *)NULL, PV_NONE,
1761#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01001762#ifdef FEAT_GUI_MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00001763 {(char_u *)1L, (char_u *)0L}
1764#else
1765 {(char_u *)0L, (char_u *)0L}
1766#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001767 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001768 {"lisp", NULL, P_BOOL|P_VI_DEF,
1769#ifdef FEAT_LISP
1770 (char_u *)&p_lisp, PV_LISP,
1771#else
1772 (char_u *)NULL, PV_NONE,
1773#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001774 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001775 {"lispwords", "lw", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001776#ifdef FEAT_LISP
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01001777 (char_u *)&p_lispwords, PV_LW,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001778 {(char_u *)LISPWORD_VALUE, (char_u *)0L}
1779#else
1780 (char_u *)NULL, PV_NONE,
1781 {(char_u *)"", (char_u *)0L}
1782#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001783 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001784 {"list", NULL, P_BOOL|P_VI_DEF|P_RWIN,
1785 (char_u *)VAR_WIN, PV_LIST,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001786 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001787 {"listchars", "lcs", P_STRING|P_VI_DEF|P_RALL|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001788 (char_u *)&p_lcs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001789 {(char_u *)"eol:$", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001790 {"loadplugins", "lpl", P_BOOL|P_VI_DEF,
1791 (char_u *)&p_lpl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001792 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02001793 {"luadll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001794#if defined(DYNAMIC_LUA)
Bram Moolenaard94464e2015-11-02 15:28:18 +01001795 (char_u *)&p_luadll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01001796 {(char_u *)DYNAMIC_LUA_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01001797#else
1798 (char_u *)NULL, PV_NONE,
1799 {(char_u *)"", (char_u *)0L}
1800#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001801 SCTX_INIT},
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001802 {"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001803#ifdef FEAT_GUI_MAC
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001804 (char_u *)&p_macatsui, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01001805 {(char_u *)TRUE, (char_u *)0L}
1806#else
1807 (char_u *)NULL, PV_NONE,
1808 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf9393ef2006-04-24 19:47:27 +00001809#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001810 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001811 {"magic", NULL, P_BOOL|P_VI_DEF,
1812 (char_u *)&p_magic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001813 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00001814 {"makeef", "mef", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001815#ifdef FEAT_QUICKFIX
1816 (char_u *)&p_mef, PV_NONE,
1817 {(char_u *)"", (char_u *)0L}
1818#else
1819 (char_u *)NULL, PV_NONE,
1820 {(char_u *)NULL, (char_u *)0L}
1821#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001822 SCTX_INIT},
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001823 {"makeencoding","menc", P_STRING|P_VI_DEF,
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01001824 (char_u *)&p_menc, PV_MENC,
1825 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001826 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 {"makeprg", "mp", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1828#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00001829 (char_u *)&p_mp, PV_MP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001830# ifdef VMS
1831 {(char_u *)"MMS", (char_u *)0L}
1832# else
1833 {(char_u *)"make", (char_u *)0L}
1834# endif
1835#else
1836 (char_u *)NULL, PV_NONE,
1837 {(char_u *)NULL, (char_u *)0L}
1838#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001839 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001840 {"matchpairs", "mps", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001841 (char_u *)&p_mps, PV_MPS,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001842 {(char_u *)"(:),{:},[:]", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001843 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001844 {"matchtime", "mat", P_NUM|P_VI_DEF,
1845 (char_u *)&p_mat, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001846 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar913077c2012-03-28 19:59:04 +02001847 {"maxcombine", "mco", P_NUM|P_VI_DEF|P_CURSWANT,
Bram Moolenaar362e1a32006-03-06 23:29:24 +00001848 (char_u *)&p_mco, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001849 {(char_u *)2, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001850 {"maxfuncdepth", "mfd", P_NUM|P_VI_DEF,
1851#ifdef FEAT_EVAL
1852 (char_u *)&p_mfd, PV_NONE,
1853#else
1854 (char_u *)NULL, PV_NONE,
1855#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001856 {(char_u *)100L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001857 {"maxmapdepth", "mmd", P_NUM|P_VI_DEF,
1858 (char_u *)&p_mmd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001859 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001860 {"maxmem", "mm", P_NUM|P_VI_DEF,
1861 (char_u *)&p_mm, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001862 {(char_u *)DFLT_MAXMEM, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001863 SCTX_INIT},
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00001864 {"maxmempattern","mmp", P_NUM|P_VI_DEF,
1865 (char_u *)&p_mmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001866 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001867 {"maxmemtot", "mmt", P_NUM|P_VI_DEF,
1868 (char_u *)&p_mmt, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00001869 {(char_u *)DFLT_MAXMEMTOT, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001870 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001871 {"menuitems", "mis", P_NUM|P_VI_DEF,
1872#ifdef FEAT_MENU
1873 (char_u *)&p_mis, PV_NONE,
1874#else
1875 (char_u *)NULL, PV_NONE,
1876#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001877 {(char_u *)25L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001878 {"mesg", NULL, P_BOOL|P_VI_DEF,
1879 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001880 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001881 {"mkspellmem", "msm", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00001882#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00001883 (char_u *)&p_msm, PV_NONE,
1884 {(char_u *)"460000,2000,500", (char_u *)0L}
1885#else
1886 (char_u *)NULL, PV_NONE,
1887 {(char_u *)0L, (char_u *)0L}
1888#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001889 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001890 {"modeline", "ml", P_BOOL|P_VIM,
1891 (char_u *)&p_ml, PV_ML,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001892 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar7e800c62019-05-23 17:08:49 +02001893 {"modelineexpr", "mle", P_BOOL|P_VI_DEF|P_SECURE,
Bram Moolenaar110289e2019-05-23 15:38:06 +02001894 (char_u *)&p_mle, PV_NONE,
1895 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001896 {"modelines", "mls", P_NUM|P_VI_DEF,
1897 (char_u *)&p_mls, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001898 {(char_u *)5L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001899 {"modifiable", "ma", P_BOOL|P_VI_DEF|P_NOGLOB,
1900 (char_u *)&p_ma, PV_MA,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001901 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001902 {"modified", "mod", P_BOOL|P_NO_MKRC|P_VI_DEF|P_RSTAT,
1903 (char_u *)&p_mod, PV_MOD,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001904 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001905 {"more", NULL, P_BOOL|P_VIM,
1906 (char_u *)&p_more, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001907 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001908 {"mouse", NULL, P_STRING|P_VI_DEF|P_FLAGLIST,
1909 (char_u *)&p_mouse, PV_NONE,
1910 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01001911#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001912 (char_u *)"a",
1913#else
1914 (char_u *)"",
1915#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001916 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001917 {"mousefocus", "mousef", P_BOOL|P_VI_DEF,
1918#ifdef FEAT_GUI
1919 (char_u *)&p_mousef, PV_NONE,
1920#else
1921 (char_u *)NULL, PV_NONE,
1922#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001923 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 {"mousehide", "mh", P_BOOL|P_VI_DEF,
1925#ifdef FEAT_GUI
1926 (char_u *)&p_mh, PV_NONE,
1927#else
1928 (char_u *)NULL, PV_NONE,
1929#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001930 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001931 {"mousemodel", "mousem", P_STRING|P_VI_DEF,
1932 (char_u *)&p_mousem, PV_NONE,
1933 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01001934#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001935 (char_u *)"popup",
1936#else
Bram Moolenaard0573012017-10-28 21:11:06 +02001937# if defined(MACOS_X)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001938 (char_u *)"popup_setpos",
1939# else
1940 (char_u *)"extend",
1941# endif
1942#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001943 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001944 {"mouseshape", "mouses", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001945#ifdef FEAT_MOUSESHAPE
1946 (char_u *)&p_mouseshape, PV_NONE,
1947 {(char_u *)"i-r:beam,s:updown,sd:udsizing,vs:leftright,vd:lrsizing,m:no,ml:up-arrow,v:rightup-arrow", (char_u *)0L}
1948#else
1949 (char_u *)NULL, PV_NONE,
1950 {(char_u *)NULL, (char_u *)0L}
1951#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001952 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001953 {"mousetime", "mouset", P_NUM|P_VI_DEF,
1954 (char_u *)&p_mouset, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001955 {(char_u *)500L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001956 {"mzschemedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1957#if defined(DYNAMIC_MZSCHEME)
1958 (char_u *)&p_mzschemedll, PV_NONE,
1959 {(char_u *)DYNAMIC_MZSCH_DLL, (char_u *)0L}
1960#else
1961 (char_u *)NULL, PV_NONE,
1962 {(char_u *)"", (char_u *)0L}
1963#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001964 SCTX_INIT},
Bram Moolenaar0ab35b22017-10-08 17:41:37 +02001965 {"mzschemegcdll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
1966#if defined(DYNAMIC_MZSCHEME)
1967 (char_u *)&p_mzschemegcdll, PV_NONE,
1968 {(char_u *)DYNAMIC_MZGC_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 Moolenaar325b7a22004-07-05 15:58:32 +00001974 {"mzquantum", "mzq", P_NUM,
1975#ifdef FEAT_MZSCHEME
1976 (char_u *)&p_mzq, PV_NONE,
1977#else
1978 (char_u *)NULL, PV_NONE,
1979#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001980 {(char_u *)100L, (char_u *)100L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00001981 {"novice", NULL, P_BOOL|P_VI_DEF,
1982 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001983 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02001984 {"nrformats", "nf", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001985 (char_u *)&p_nf, PV_NF,
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01001986 {(char_u *)"bin,octal,hex", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001987 SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02001988 {"number", "nu", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00001989 (char_u *)VAR_WIN, PV_NU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001990 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00001991 {"numberwidth", "nuw", P_NUM|P_RWIN|P_VIM,
1992#ifdef FEAT_LINEBREAK
1993 (char_u *)VAR_WIN, PV_NUW,
1994#else
1995 (char_u *)NULL, PV_NONE,
1996#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02001997 {(char_u *)8L, (char_u *)4L} SCTX_INIT},
Bram Moolenaarf75a9632005-09-13 21:20:47 +00001998 {"omnifunc", "ofu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
Bram Moolenaare344bea2005-09-01 20:46:49 +00001999#ifdef FEAT_COMPL_FUNC
2000 (char_u *)&p_ofu, PV_OFU,
2001 {(char_u *)"", (char_u *)0L}
2002#else
2003 (char_u *)NULL, PV_NONE,
2004 {(char_u *)0L, (char_u *)0L}
2005#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002006 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002007 {"open", NULL, P_BOOL|P_VI_DEF,
2008 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002009 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar043545e2006-10-10 16:44:07 +00002010 {"opendevice", "odev", P_BOOL|P_VI_DEF,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002011#if defined(MSWIN)
Bram Moolenaar043545e2006-10-10 16:44:07 +00002012 (char_u *)&p_odev, PV_NONE,
2013#else
2014 (char_u *)NULL, PV_NONE,
2015#endif
2016 {(char_u *)FALSE, (char_u *)FALSE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002017 SCTX_INIT},
Bram Moolenaar2c7a29c2005-12-12 22:02:31 +00002018 {"operatorfunc", "opfunc", P_STRING|P_VI_DEF|P_SECURE,
2019 (char_u *)&p_opfunc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002020 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002021 {"optimize", "opt", P_BOOL|P_VI_DEF,
2022 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002023 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002024 {"osfiletype", "oft", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002025 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002026 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +01002027 {"packpath", "pp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2028 |P_SECURE,
2029 (char_u *)&p_pp, PV_NONE,
2030 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002031 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002032 {"paragraphs", "para", P_STRING|P_VI_DEF,
2033 (char_u *)&p_para, PV_NONE,
Bram Moolenaar57e48462008-03-12 16:38:55 +00002034 {(char_u *)"IPLPPPQPP TPHPLIPpLpItpplpipbp",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002035 (char_u *)0L} SCTX_INIT},
Bram Moolenaar7fd16022007-09-06 14:35:35 +00002036 {"paste", NULL, P_BOOL|P_VI_DEF|P_PRI_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002037 (char_u *)&p_paste, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002038 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002039 {"pastetoggle", "pt", P_STRING|P_VI_DEF,
2040 (char_u *)&p_pt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002041 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002042 {"patchexpr", "pex", P_STRING|P_VI_DEF|P_SECURE,
2043#if defined(FEAT_DIFF) && defined(FEAT_EVAL)
2044 (char_u *)&p_pex, PV_NONE,
2045 {(char_u *)"", (char_u *)0L}
2046#else
2047 (char_u *)NULL, PV_NONE,
2048 {(char_u *)0L, (char_u *)0L}
2049#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002050 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002051 {"patchmode", "pm", P_STRING|P_VI_DEF|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 (char_u *)&p_pm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002053 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002054 {"path", "pa", P_STRING|P_EXPAND|P_VI_DEF|P_COMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002055 (char_u *)&p_path, PV_PATH,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002056 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002057#if defined(AMIGA) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002058 (char_u *)".,,",
2059#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002060 (char_u *)".,/usr/include,,",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002062 (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002063 {"perldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002064#if defined(DYNAMIC_PERL)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002065 (char_u *)&p_perldll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002066 {(char_u *)DYNAMIC_PERL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002067#else
2068 (char_u *)NULL, PV_NONE,
2069 {(char_u *)0L, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002070#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002071 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002072 {"preserveindent", "pi", P_BOOL|P_VI_DEF|P_VIM,
2073 (char_u *)&p_pi, PV_PI,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002074 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar592e0a22004-07-03 16:05:59 +00002075 {"previewheight", "pvh", P_NUM|P_VI_DEF,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002076#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002077 (char_u *)&p_pvh, PV_NONE,
2078#else
2079 (char_u *)NULL, PV_NONE,
2080#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002081 {(char_u *)12L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar79648732019-07-18 21:43:07 +02002082 {"previewpopup", "pvp", P_STRING|P_VI_DEF|P_COMMA|P_NODUP,
2083#ifdef FEAT_TEXT_PROP
2084 (char_u *)&p_pvp, PV_NONE,
2085 {(char_u *)"", (char_u *)0L}
2086#else
2087 (char_u *)NULL, PV_NONE,
2088 {(char_u *)NULL, (char_u *)0L}
2089#endif
2090 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002091 {"previewwindow", "pvw", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
Bram Moolenaar4033c552017-09-16 20:54:51 +02002092#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002093 (char_u *)VAR_WIN, PV_PVW,
2094#else
2095 (char_u *)NULL, PV_NONE,
2096#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002097 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002098 {"printdevice", "pdev", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002099#ifdef FEAT_PRINTER
2100 (char_u *)&p_pdev, PV_NONE,
2101 {(char_u *)"", (char_u *)0L}
2102#else
2103 (char_u *)NULL, PV_NONE,
2104 {(char_u *)NULL, (char_u *)0L}
2105#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002106 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002107 {"printencoding", "penc", P_STRING|P_VI_DEF,
2108#ifdef FEAT_POSTSCRIPT
2109 (char_u *)&p_penc, 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 Moolenaar031cb742016-11-24 21:46:19 +01002116 {"printexpr", "pexpr", P_STRING|P_VI_DEF|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117#ifdef FEAT_POSTSCRIPT
2118 (char_u *)&p_pexpr, 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 Moolenaar071d4272004-06-13 20:20:40 +00002125 {"printfont", "pfn", P_STRING|P_VI_DEF,
2126#ifdef FEAT_PRINTER
2127 (char_u *)&p_pfn, PV_NONE,
2128 {
2129# ifdef MSWIN
2130 (char_u *)"Courier_New:h10",
2131# else
2132 (char_u *)"courier",
2133# endif
2134 (char_u *)0L}
2135#else
2136 (char_u *)NULL, PV_NONE,
2137 {(char_u *)NULL, (char_u *)0L}
2138#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002139 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002140 {"printheader", "pheader", P_STRING|P_VI_DEF|P_GETTEXT,
2141#ifdef FEAT_PRINTER
2142 (char_u *)&p_header, PV_NONE,
Bram Moolenaar0903d562017-08-26 22:30:15 +02002143 /* untranslated to avoid problems when 'encoding'
2144 * is changed */
2145 {(char_u *)"%<%f%h%m%=Page %N", (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002146#else
2147 (char_u *)NULL, PV_NONE,
2148 {(char_u *)NULL, (char_u *)0L}
2149#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002150 SCTX_INIT},
Bram Moolenaar8299df92004-07-10 09:47:34 +00002151 {"printmbcharset", "pmbcs", P_STRING|P_VI_DEF,
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01002152#if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00002153 (char_u *)&p_pmcs, PV_NONE,
2154 {(char_u *)"", (char_u *)0L}
2155#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 {"printmbfont", "pmbfn", 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_pmfn, 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 Moolenaar0e7c4b92015-06-20 15:30:03 +02002169 {"printoptions", "popt", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002170#ifdef FEAT_PRINTER
2171 (char_u *)&p_popt, 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 Moolenaar071d4272004-06-13 20:20:40 +00002178 {"prompt", NULL, P_BOOL|P_VI_DEF,
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002179 (char_u *)&p_prompt, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002180 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9d47f172006-03-15 23:03:01 +00002181 {"pumheight", "ph", P_NUM|P_VI_DEF,
2182#ifdef FEAT_INS_EXPAND
2183 (char_u *)&p_ph, PV_NONE,
2184#else
2185 (char_u *)NULL, PV_NONE,
2186#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002187 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaara8f04aa2018-02-10 15:36:55 +01002188 {"pumwidth", "pw", P_NUM|P_VI_DEF,
2189#ifdef FEAT_INS_EXPAND
2190 (char_u *)&p_pw, PV_NONE,
2191#else
2192 (char_u *)NULL, PV_NONE,
2193#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002194 {(char_u *)15L, (char_u *)15L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002195 {"pythonthreedll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002196#if defined(DYNAMIC_PYTHON3)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002197 (char_u *)&p_py3dll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002198 {(char_u *)DYNAMIC_PYTHON3_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002199#else
2200 (char_u *)NULL, PV_NONE,
2201 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002202#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002203 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002204 {"pythonthreehome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2205#if defined(FEAT_PYTHON3)
2206 (char_u *)&p_py3home, PV_NONE,
2207 {(char_u *)"", (char_u *)0L}
2208#else
2209 (char_u *)NULL, PV_NONE,
2210 {(char_u *)NULL, (char_u *)0L}
2211#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002212 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002213 {"pythondll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002214#if defined(DYNAMIC_PYTHON)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002215 (char_u *)&p_pydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002216 {(char_u *)DYNAMIC_PYTHON_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002217#else
2218 (char_u *)NULL, PV_NONE,
2219 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002220#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002221 SCTX_INIT},
Bram Moolenaar94073162018-01-31 21:49:05 +01002222 {"pythonhome", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2223#if defined(FEAT_PYTHON)
2224 (char_u *)&p_pyhome, PV_NONE,
2225 {(char_u *)"", (char_u *)0L}
2226#else
2227 (char_u *)NULL, PV_NONE,
2228 {(char_u *)NULL, (char_u *)0L}
2229#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002230 SCTX_INIT},
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01002231 {"pyxversion", "pyx", P_NUM|P_VI_DEF|P_SECURE,
2232#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
2233 (char_u *)&p_pyx, PV_NONE,
2234#else
2235 (char_u *)NULL, PV_NONE,
2236#endif
2237 {(char_u *)DEFAULT_PYTHON_VER, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002238 SCTX_INIT},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00002239 {"quoteescape", "qe", P_STRING|P_ALLOCED|P_VI_DEF,
2240#ifdef FEAT_TEXTOBJ
2241 (char_u *)&p_qe, PV_QE,
2242 {(char_u *)"\\", (char_u *)0L}
2243#else
2244 (char_u *)NULL, PV_NONE,
2245 {(char_u *)NULL, (char_u *)0L}
2246#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002247 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002248 {"readonly", "ro", P_BOOL|P_VI_DEF|P_RSTAT|P_NOGLOB,
2249 (char_u *)&p_ro, PV_RO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002250 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002251 {"redraw", NULL, P_BOOL|P_VI_DEF,
2252 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002253 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar91a4e822008-01-19 14:59:58 +00002254 {"redrawtime", "rdt", P_NUM|P_VI_DEF,
2255#ifdef FEAT_RELTIME
2256 (char_u *)&p_rdt, PV_NONE,
2257#else
2258 (char_u *)NULL, PV_NONE,
2259#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002260 {(char_u *)2000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02002261 {"regexpengine", "re", P_NUM|P_VI_DEF,
2262 (char_u *)&p_re, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002263 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002264 {"relativenumber", "rnu", P_BOOL|P_VI_DEF|P_RCLR,
Bram Moolenaar64486672010-05-16 15:46:46 +02002265 (char_u *)VAR_WIN, PV_RNU,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002266 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002267 {"remap", NULL, P_BOOL|P_VI_DEF,
2268 (char_u *)&p_remap, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002269 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002270 {"renderoptions", "rop", P_STRING|P_ONECOMMA|P_RCLR|P_VI_DEF,
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02002271#ifdef FEAT_RENDER_OPTIONS
2272 (char_u *)&p_rop, PV_NONE,
2273 {(char_u *)"", (char_u *)0L}
2274#else
2275 (char_u *)NULL, PV_NONE,
2276 {(char_u *)NULL, (char_u *)0L}
2277#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002278 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002279 {"report", NULL, P_NUM|P_VI_DEF,
2280 (char_u *)&p_report, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002281 {(char_u *)2L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002282 {"restorescreen", "rs", P_BOOL|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002283#ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00002284 (char_u *)&p_rs, PV_NONE,
2285#else
2286 (char_u *)NULL, PV_NONE,
2287#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002288 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002289 {"revins", "ri", P_BOOL|P_VI_DEF|P_VIM,
2290#ifdef FEAT_RIGHTLEFT
2291 (char_u *)&p_ri, PV_NONE,
2292#else
2293 (char_u *)NULL, PV_NONE,
2294#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002295 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002296 {"rightleft", "rl", P_BOOL|P_VI_DEF|P_RWIN,
2297#ifdef FEAT_RIGHTLEFT
2298 (char_u *)VAR_WIN, PV_RL,
2299#else
2300 (char_u *)NULL, PV_NONE,
2301#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002302 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002303 {"rightleftcmd", "rlc", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
2304#ifdef FEAT_RIGHTLEFT
2305 (char_u *)VAR_WIN, PV_RLC,
2306 {(char_u *)"search", (char_u *)NULL}
2307#else
2308 (char_u *)NULL, PV_NONE,
2309 {(char_u *)NULL, (char_u *)0L}
2310#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002311 SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002312 {"rubydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002313#if defined(DYNAMIC_RUBY)
Bram Moolenaard94464e2015-11-02 15:28:18 +01002314 (char_u *)&p_rubydll, PV_NONE,
Bram Moolenaar25e4fcd2016-01-09 14:57:47 +01002315 {(char_u *)DYNAMIC_RUBY_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002316#else
2317 (char_u *)NULL, PV_NONE,
2318 {(char_u *)NULL, (char_u *)0L}
Bram Moolenaard94464e2015-11-02 15:28:18 +01002319#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002320 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002321 {"ruler", "ru", P_BOOL|P_VI_DEF|P_VIM|P_RSTAT,
2322#ifdef FEAT_CMDL_INFO
2323 (char_u *)&p_ru, PV_NONE,
2324#else
2325 (char_u *)NULL, PV_NONE,
2326#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002327 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002328 {"rulerformat", "ruf", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002329#ifdef FEAT_STL_OPT
2330 (char_u *)&p_ruf, PV_NONE,
2331#else
2332 (char_u *)NULL, PV_NONE,
2333#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002334 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002335 {"runtimepath", "rtp", P_STRING|P_VI_DEF|P_EXPAND|P_ONECOMMA|P_NODUP
2336 |P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002337 (char_u *)&p_rtp, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002338 {(char_u *)DFLT_RUNTIMEPATH, (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002339 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002340 {"scroll", "scr", P_NUM|P_NO_MKRC|P_VI_DEF,
2341 (char_u *)VAR_WIN, PV_SCROLL,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002342 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002343 {"scrollbind", "scb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002344 (char_u *)VAR_WIN, PV_SCBIND,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002345 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002346 {"scrolljump", "sj", P_NUM|P_VI_DEF|P_VIM,
2347 (char_u *)&p_sj, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002348 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002349 {"scrolloff", "so", P_NUM|P_VI_DEF|P_VIM|P_RALL,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002350 (char_u *)&p_so, PV_SO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002351 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002352 {"scrollopt", "sbo", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002353 (char_u *)&p_sbo, PV_NONE,
2354 {(char_u *)"ver,jump", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002355 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002356 {"sections", "sect", P_STRING|P_VI_DEF,
2357 (char_u *)&p_sections, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002358 {(char_u *)"SHNHH HUnhsh", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002359 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002360 {"secure", NULL, P_BOOL|P_VI_DEF|P_SECURE,
2361 (char_u *)&p_secure, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002362 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002363 {"selection", "sel", P_STRING|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002364 (char_u *)&p_sel, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002365 {(char_u *)"inclusive", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002366 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002367 {"selectmode", "slm", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002368 (char_u *)&p_slm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002369 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002370 {"sessionoptions", "ssop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002371#ifdef FEAT_SESSION
2372 (char_u *)&p_ssop, PV_NONE,
Bram Moolenaar4d8bac82018-03-09 21:33:34 +01002373 {(char_u *)"blank,buffers,curdir,folds,help,options,tabpages,winsize,terminal",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002374 (char_u *)0L}
2375#else
2376 (char_u *)NULL, PV_NONE,
2377 {(char_u *)0L, (char_u *)0L}
2378#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002379 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002380 {"shell", "sh", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2381 (char_u *)&p_sh, PV_NONE,
2382 {
2383#ifdef VMS
2384 (char_u *)"-",
2385#else
Bram Moolenaar4f974752019-02-17 17:44:42 +01002386# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002387 (char_u *)"", /* set in set_init_1() */
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002388# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002389 (char_u *)"sh",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002390# endif
2391#endif /* VMS */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002392 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002393 {"shellcmdflag","shcf", P_STRING|P_VI_DEF|P_SECURE,
2394 (char_u *)&p_shcf, PV_NONE,
2395 {
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002396#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002397 (char_u *)"/c",
2398#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00002399 (char_u *)"-c",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002400#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002401 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002402 {"shellpipe", "sp", P_STRING|P_VI_DEF|P_SECURE,
2403#ifdef FEAT_QUICKFIX
2404 (char_u *)&p_sp, PV_NONE,
2405 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01002406#if defined(UNIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002407 (char_u *)"| tee",
Bram Moolenaar071d4272004-06-13 20:20:40 +00002408#else
2409 (char_u *)">",
2410#endif
2411 (char_u *)0L}
2412#else
2413 (char_u *)NULL, PV_NONE,
2414 {(char_u *)0L, (char_u *)0L}
2415#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002416 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002417 {"shellquote", "shq", P_STRING|P_VI_DEF|P_SECURE,
2418 (char_u *)&p_shq, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002419 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002420 {"shellredir", "srr", P_STRING|P_VI_DEF|P_SECURE,
2421 (char_u *)&p_srr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002422 {(char_u *)">", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002423 {"shellslash", "ssl", P_BOOL|P_VI_DEF,
2424#ifdef BACKSLASH_IN_FILENAME
2425 (char_u *)&p_ssl, PV_NONE,
2426#else
2427 (char_u *)NULL, PV_NONE,
2428#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002429 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar26a60b42005-02-22 08:49:11 +00002430 {"shelltemp", "stmp", P_BOOL,
2431 (char_u *)&p_stmp, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002432 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002433 {"shelltype", "st", P_NUM|P_VI_DEF,
2434#ifdef AMIGA
2435 (char_u *)&p_st, PV_NONE,
2436#else
2437 (char_u *)NULL, PV_NONE,
2438#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002439 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002440 {"shellxquote", "sxq", P_STRING|P_VI_DEF|P_SECURE,
2441 (char_u *)&p_sxq, PV_NONE,
2442 {
Bram Moolenaara06ecab2016-07-16 14:47:36 +02002443#if defined(UNIX) && defined(USE_SYSTEM)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002444 (char_u *)"\"",
2445#else
2446 (char_u *)"",
2447#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002448 (char_u *)0L} SCTX_INIT},
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002449 {"shellxescape", "sxe", P_STRING|P_VI_DEF|P_SECURE,
2450 (char_u *)&p_sxe, PV_NONE,
2451 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002452#if defined(MSWIN)
Bram Moolenaarf66b3fc2012-02-20 22:18:30 +01002453 (char_u *)"\"&|<>()@^",
2454#else
2455 (char_u *)"",
2456#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002457 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002458 {"shiftround", "sr", P_BOOL|P_VI_DEF|P_VIM,
2459 (char_u *)&p_sr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002460 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002461 {"shiftwidth", "sw", P_NUM|P_VI_DEF,
2462 (char_u *)&p_sw, PV_SW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002463 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002464 {"shortmess", "shm", P_STRING|P_VIM|P_FLAGLIST,
2465 (char_u *)&p_shm, PV_NONE,
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02002466 {(char_u *)"S", (char_u *)"filnxtToOS"}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002467 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002468 {"shortname", "sn", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002469 (char_u *)&p_sn, PV_SN,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002470 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002471 {"showbreak", "sbr", P_STRING|P_VI_DEF|P_RALL,
2472#ifdef FEAT_LINEBREAK
2473 (char_u *)&p_sbr, PV_NONE,
2474#else
2475 (char_u *)NULL, PV_NONE,
2476#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002477 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002478 {"showcmd", "sc", P_BOOL|P_VIM,
2479#ifdef FEAT_CMDL_INFO
2480 (char_u *)&p_sc, PV_NONE,
2481#else
2482 (char_u *)NULL, PV_NONE,
2483#endif
2484 {(char_u *)FALSE,
2485#ifdef UNIX
2486 (char_u *)FALSE
2487#else
2488 (char_u *)TRUE
2489#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002490 } SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002491 {"showfulltag", "sft", P_BOOL|P_VI_DEF,
2492 (char_u *)&p_sft, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002493 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002494 {"showmatch", "sm", P_BOOL|P_VI_DEF,
2495 (char_u *)&p_sm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002496 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002497 {"showmode", "smd", P_BOOL|P_VIM,
2498 (char_u *)&p_smd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002499 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002500 {"showtabline", "stal", P_NUM|P_VI_DEF|P_RALL,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002501 (char_u *)&p_stal, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002502 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002503 {"sidescroll", "ss", P_NUM|P_VI_DEF,
2504 (char_u *)&p_ss, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002505 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002506 {"sidescrolloff", "siso", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar375e3392019-01-31 18:26:10 +01002507 (char_u *)&p_siso, PV_SISO,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002508 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar2b044ff2019-06-24 05:45:14 +02002509 {"signcolumn", "scl", P_STRING|P_ALLOCED|P_VI_DEF|P_RCLR,
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002510#ifdef FEAT_SIGNS
2511 (char_u *)VAR_WIN, PV_SCL,
Bram Moolenaarb3384832016-08-12 18:51:58 +02002512 {(char_u *)"auto", (char_u *)0L}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02002513#else
2514 (char_u *)NULL, PV_NONE,
2515 {(char_u *)NULL, (char_u *)0L}
2516#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002517 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002518 {"slowopen", "slow", P_BOOL|P_VI_DEF,
2519 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002520 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002521 {"smartcase", "scs", P_BOOL|P_VI_DEF|P_VIM,
2522 (char_u *)&p_scs, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002523 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002524 {"smartindent", "si", P_BOOL|P_VI_DEF|P_VIM,
2525#ifdef FEAT_SMARTINDENT
2526 (char_u *)&p_si, PV_SI,
2527#else
2528 (char_u *)NULL, PV_NONE,
2529#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002530 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002531 {"smarttab", "sta", P_BOOL|P_VI_DEF|P_VIM,
2532 (char_u *)&p_sta, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002533 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002534 {"softtabstop", "sts", P_NUM|P_VI_DEF|P_VIM,
2535 (char_u *)&p_sts, PV_STS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002536 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002537 {"sourceany", NULL, P_BOOL|P_VI_DEF,
2538 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002539 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar217ad922005-03-20 22:37:15 +00002540 {"spell", NULL, P_BOOL|P_VI_DEF|P_RWIN,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002541#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002542 (char_u *)VAR_WIN, PV_SPELL,
2543#else
2544 (char_u *)NULL, PV_NONE,
2545#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002546 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar488c6512005-08-11 20:09:58 +00002547 {"spellcapcheck", "spc", P_STRING|P_ALLOCED|P_VI_DEF|P_RBUF,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002548#ifdef FEAT_SPELL
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002549 (char_u *)&p_spc, PV_SPC,
Bram Moolenaar0dc065e2005-07-04 22:49:24 +00002550 {(char_u *)"[.?!]\\_[\\])'\" ]\\+", (char_u *)0L}
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00002551#else
2552 (char_u *)NULL, PV_NONE,
2553 {(char_u *)0L, (char_u *)0L}
2554#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002555 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002556 {"spellfile", "spf", P_STRING|P_EXPAND|P_ALLOCED|P_VI_DEF|P_SECURE
2557 |P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002558#ifdef FEAT_SPELL
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002559 (char_u *)&p_spf, PV_SPF,
2560 {(char_u *)"", (char_u *)0L}
2561#else
2562 (char_u *)NULL, PV_NONE,
2563 {(char_u *)0L, (char_u *)0L}
2564#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002565 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002566 {"spelllang", "spl", P_STRING|P_ALLOCED|P_VI_DEF|P_ONECOMMA
2567 |P_RBUF|P_EXPAND,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002568#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +00002569 (char_u *)&p_spl, PV_SPL,
Bram Moolenaar82cf9b62005-06-07 21:09:25 +00002570 {(char_u *)"en", (char_u *)0L}
Bram Moolenaar217ad922005-03-20 22:37:15 +00002571#else
2572 (char_u *)NULL, PV_NONE,
2573 {(char_u *)0L, (char_u *)0L}
2574#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002575 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002576 {"spellsuggest", "sps", P_STRING|P_VI_DEF|P_EXPAND|P_SECURE|P_ONECOMMA,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00002577#ifdef FEAT_SPELL
Bram Moolenaard857f0e2005-06-21 22:37:39 +00002578 (char_u *)&p_sps, PV_NONE,
2579 {(char_u *)"best", (char_u *)0L}
2580#else
2581 (char_u *)NULL, PV_NONE,
2582 {(char_u *)0L, (char_u *)0L}
2583#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002584 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002585 {"splitbelow", "sb", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002586 (char_u *)&p_sb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002587 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002588 {"splitright", "spr", P_BOOL|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002589 (char_u *)&p_spr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002590 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002591 {"startofline", "sol", P_BOOL|P_VI_DEF|P_VIM,
2592 (char_u *)&p_sol, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002593 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002594 {"statusline" ,"stl", P_STRING|P_VI_DEF|P_ALLOCED|P_RSTAT|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002595#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002596 (char_u *)&p_stl, PV_STL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002597#else
2598 (char_u *)NULL, PV_NONE,
2599#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002600 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002601 {"suffixes", "su", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002602 (char_u *)&p_su, PV_NONE,
2603 {(char_u *)".bak,~,.o,.h,.info,.swp,.obj",
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002604 (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002605 {"suffixesadd", "sua", P_STRING|P_VI_DEF|P_ALLOCED|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002606#ifdef FEAT_SEARCHPATH
Bram Moolenaar071d4272004-06-13 20:20:40 +00002607 (char_u *)&p_sua, PV_SUA,
2608 {(char_u *)"", (char_u *)0L}
2609#else
2610 (char_u *)NULL, PV_NONE,
2611 {(char_u *)0L, (char_u *)0L}
2612#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002613 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002614 {"swapfile", "swf", P_BOOL|P_VI_DEF|P_RSTAT,
2615 (char_u *)&p_swf, PV_SWF,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002616 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002617 {"swapsync", "sws", P_STRING|P_VI_DEF,
2618 (char_u *)&p_sws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002619 {(char_u *)"fsync", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002620 {"switchbuf", "swb", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002621 (char_u *)&p_swb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002622 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar3b56eb32005-07-11 22:40:32 +00002623 {"synmaxcol", "smc", P_NUM|P_VI_DEF|P_RBUF,
2624#ifdef FEAT_SYN_HL
2625 (char_u *)&p_smc, PV_SMC,
2626 {(char_u *)3000L, (char_u *)0L}
2627#else
2628 (char_u *)NULL, PV_NONE,
2629 {(char_u *)0L, (char_u *)0L}
2630#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002631 SCTX_INIT},
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00002632 {"syntax", "syn", P_STRING|P_ALLOCED|P_VI_DEF|P_NOGLOB|P_NFNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002633#ifdef FEAT_SYN_HL
2634 (char_u *)&p_syn, PV_SYN,
2635 {(char_u *)"", (char_u *)0L}
2636#else
2637 (char_u *)NULL, PV_NONE,
2638 {(char_u *)0L, (char_u *)0L}
2639#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002640 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002641 {"tabline", "tal", P_STRING|P_VI_DEF|P_RALL|P_MLE,
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00002642#ifdef FEAT_STL_OPT
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00002643 (char_u *)&p_tal, PV_NONE,
2644#else
2645 (char_u *)NULL, PV_NONE,
2646#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002647 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002648 {"tabpagemax", "tpm", P_NUM|P_VI_DEF,
Bram Moolenaarfd2ac762006-03-01 22:09:21 +00002649 (char_u *)&p_tpm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002650 {(char_u *)10L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002651 {"tabstop", "ts", P_NUM|P_VI_DEF|P_RBUF,
2652 (char_u *)&p_ts, PV_TS,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002653 {(char_u *)8L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002654 {"tagbsearch", "tbs", P_BOOL|P_VI_DEF,
2655 (char_u *)&p_tbs, PV_NONE,
2656#ifdef VMS /* binary searching doesn't appear to work on VMS */
2657 {(char_u *)0L, (char_u *)0L}
2658#else
2659 {(char_u *)TRUE, (char_u *)0L}
2660#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002661 SCTX_INIT},
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01002662 {"tagcase", "tc", P_STRING|P_VIM,
2663 (char_u *)&p_tc, PV_TC,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002664 {(char_u *)"followic", (char_u *)"followic"} SCTX_INIT},
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02002665 {"tagfunc", "tfu", P_STRING|P_ALLOCED|P_VI_DEF|P_SECURE,
2666#ifdef FEAT_EVAL
2667 (char_u *)&p_tfu, PV_TFU,
2668 {(char_u *)"", (char_u *)0L}
2669#else
2670 (char_u *)NULL, PV_NONE,
2671 {(char_u *)0L, (char_u *)0L}
2672#endif
2673 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002674 {"taglength", "tl", P_NUM|P_VI_DEF,
2675 (char_u *)&p_tl, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002676 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002677 {"tagrelative", "tr", P_BOOL|P_VIM,
2678 (char_u *)&p_tr, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002679 {(char_u *)FALSE, (char_u *)TRUE} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002680 {"tags", "tag", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002681 (char_u *)&p_tags, PV_TAGS,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002682 {
2683#if defined(FEAT_EMACS_TAGS) && !defined(CASE_INSENSITIVE_FILENAME)
2684 (char_u *)"./tags,./TAGS,tags,TAGS",
2685#else
2686 (char_u *)"./tags,tags",
2687#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002688 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002689 {"tagstack", "tgst", P_BOOL|P_VI_DEF,
2690 (char_u *)&p_tgst, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002691 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaara6e42502016-04-20 16:19:52 +02002692 {"tcldll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002693#if defined(DYNAMIC_TCL)
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002694 (char_u *)&p_tcldll, PV_NONE,
2695 {(char_u *)DYNAMIC_TCL_DLL, (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002696#else
2697 (char_u *)NULL, PV_NONE,
2698 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar8a5115c2016-01-09 19:41:11 +01002699#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002700 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002701 {"term", NULL, P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2702 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002703 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002704 {"termbidi", "tbidi", P_BOOL|P_VI_DEF,
2705#ifdef FEAT_ARABIC
2706 (char_u *)&p_tbidi, PV_NONE,
2707#else
2708 (char_u *)NULL, PV_NONE,
2709#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002710 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002711 {"termencoding", "tenc", P_STRING|P_VI_DEF|P_RCLR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002712 (char_u *)&p_tenc, PV_NONE,
2713 {(char_u *)"", (char_u *)0L}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002714 SCTX_INIT},
Bram Moolenaar61be73b2016-04-29 22:59:22 +02002715 {"termguicolors", "tgc", P_BOOL|P_VI_DEF|P_VIM|P_RCLR,
2716#ifdef FEAT_TERMGUICOLORS
2717 (char_u *)&p_tgc, PV_NONE,
2718 {(char_u *)FALSE, (char_u *)FALSE}
2719#else
2720 (char_u*)NULL, PV_NONE,
2721 {(char_u *)FALSE, (char_u *)FALSE}
2722#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002723 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002724 {"termwinkey", "twk", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2725#ifdef FEAT_TERMINAL
2726 (char_u *)VAR_WIN, PV_TWK,
2727 {(char_u *)"", (char_u *)NULL}
2728#else
2729 (char_u *)NULL, PV_NONE,
2730 {(char_u *)NULL, (char_u *)0L}
2731#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002732 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002733 {"termwinscroll", "twsl", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
2734#ifdef FEAT_TERMINAL
2735 (char_u *)&p_twsl, PV_TWSL,
2736 {(char_u *)10000L, (char_u *)10000L}
2737#else
2738 (char_u *)NULL, PV_NONE,
2739 {(char_u *)NULL, (char_u *)0L}
2740#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002741 SCTX_INIT},
Bram Moolenaar6d150f72018-04-21 20:03:20 +02002742 {"termwinsize", "tws", P_STRING|P_ALLOCED|P_RWIN|P_VI_DEF,
2743#ifdef FEAT_TERMINAL
2744 (char_u *)VAR_WIN, PV_TWS,
Bram Moolenaare4f25e42017-07-07 11:54:15 +02002745 {(char_u *)"", (char_u *)NULL}
2746#else
2747 (char_u *)NULL, PV_NONE,
2748 {(char_u *)NULL, (char_u *)0L}
2749#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002750 SCTX_INIT},
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002751 {"termwintype", "twt", P_STRING|P_ALLOCED|P_VI_DEF,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002752#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01002753 (char_u *)&p_twt, PV_NONE,
2754 {(char_u *)"", (char_u *)NULL}
2755#else
2756 (char_u *)NULL, PV_NONE,
2757 {(char_u *)NULL, (char_u *)0L}
2758#endif
2759 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002760 {"terse", NULL, P_BOOL|P_VI_DEF,
2761 (char_u *)&p_terse, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002762 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002763 {"textauto", "ta", P_BOOL|P_VIM,
2764 (char_u *)&p_ta, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002765 {(char_u *)DFLT_TEXTAUTO, (char_u *)TRUE}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002766 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002767 {"textmode", "tx", P_BOOL|P_VI_DEF|P_NO_MKRC,
2768 (char_u *)&p_tx, PV_TX,
2769 {
2770#ifdef USE_CRNL
2771 (char_u *)TRUE,
2772#else
2773 (char_u *)FALSE,
2774#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002775 (char_u *)0L} SCTX_INIT},
Bram Moolenaar1a384422010-07-14 19:53:30 +02002776 {"textwidth", "tw", P_NUM|P_VI_DEF|P_VIM|P_RBUF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002777 (char_u *)&p_tw, PV_TW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002778 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaarf422bcc2016-11-26 17:45:53 +01002779 {"thesaurus", "tsr", P_STRING|P_EXPAND|P_VI_DEF|P_ONECOMMA|P_NODUP|P_NDNAME,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002780#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00002781 (char_u *)&p_tsr, PV_TSR,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002782#else
2783 (char_u *)NULL, PV_NONE,
2784#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002785 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002786 {"tildeop", "top", P_BOOL|P_VI_DEF|P_VIM,
2787 (char_u *)&p_to, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002788 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002789 {"timeout", "to", P_BOOL|P_VI_DEF,
2790 (char_u *)&p_timeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002791 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002792 {"timeoutlen", "tm", P_NUM|P_VI_DEF,
2793 (char_u *)&p_tm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002794 {(char_u *)1000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002795 {"title", NULL, P_BOOL|P_VI_DEF,
2796#ifdef FEAT_TITLE
2797 (char_u *)&p_title, PV_NONE,
2798#else
2799 (char_u *)NULL, PV_NONE,
2800#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002801 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002802 {"titlelen", NULL, P_NUM|P_VI_DEF,
2803#ifdef FEAT_TITLE
2804 (char_u *)&p_titlelen, PV_NONE,
2805#else
2806 (char_u *)NULL, PV_NONE,
2807#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002808 {(char_u *)85L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00002809 {"titleold", NULL, P_STRING|P_VI_DEF|P_GETTEXT|P_SECURE|P_NO_MKRC,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002810#ifdef FEAT_TITLE
2811 (char_u *)&p_titleold, PV_NONE,
2812 {(char_u *)N_("Thanks for flying Vim"),
2813 (char_u *)0L}
2814#else
2815 (char_u *)NULL, PV_NONE,
2816 {(char_u *)0L, (char_u *)0L}
2817#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002818 SCTX_INIT},
Bram Moolenaar110289e2019-05-23 15:38:06 +02002819 {"titlestring", NULL, P_STRING|P_VI_DEF|P_MLE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002820#ifdef FEAT_TITLE
2821 (char_u *)&p_titlestring, PV_NONE,
2822#else
2823 (char_u *)NULL, PV_NONE,
2824#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002825 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002826 {"toolbar", "tb", P_STRING|P_ONECOMMA|P_VI_DEF|P_NODUP,
Bram Moolenaar4f974752019-02-17 17:44:42 +01002827#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002828 (char_u *)&p_toolbar, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00002829 {(char_u *)"icons,tooltips", (char_u *)0L}
Bram Moolenaara713ff82017-02-25 22:18:43 +01002830#else
2831 (char_u *)NULL, PV_NONE,
2832 {(char_u *)0L, (char_u *)0L}
2833#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002834 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002835 {"toolbariconsize", "tbis", P_STRING|P_VI_DEF,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002836#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002837 (char_u *)&p_tbis, PV_NONE,
Bram Moolenaara713ff82017-02-25 22:18:43 +01002838 {(char_u *)"small", (char_u *)0L}
2839#else
2840 (char_u *)NULL, PV_NONE,
2841 {(char_u *)0L, (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002842#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002843 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002844 {"ttimeout", NULL, P_BOOL|P_VI_DEF|P_VIM,
2845 (char_u *)&p_ttimeout, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002846 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002847 {"ttimeoutlen", "ttm", P_NUM|P_VI_DEF,
2848 (char_u *)&p_ttm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002849 {(char_u *)-1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002850 {"ttybuiltin", "tbi", P_BOOL|P_VI_DEF,
2851 (char_u *)&p_tbi, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002852 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002853 {"ttyfast", "tf", P_BOOL|P_NO_MKRC|P_VI_DEF,
2854 (char_u *)&p_tf, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002855 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002856 {"ttymouse", "ttym", P_STRING|P_NODEFAULT|P_NO_MKRC|P_VI_DEF,
2857#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
2858 (char_u *)&p_ttym, PV_NONE,
2859#else
2860 (char_u *)NULL, PV_NONE,
2861#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002862 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002863 {"ttyscroll", "tsl", P_NUM|P_VI_DEF,
2864 (char_u *)&p_ttyscroll, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002865 {(char_u *)999L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002866 {"ttytype", "tty", P_STRING|P_EXPAND|P_NODEFAULT|P_NO_MKRC|P_VI_DEF|P_RALL,
2867 (char_u *)&T_NAME, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002868 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002869 {"undodir", "udir", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP|P_SECURE
2870 |P_VI_DEF,
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002871#ifdef FEAT_PERSISTENT_UNDO
2872 (char_u *)&p_udir, PV_NONE,
2873 {(char_u *)".", (char_u *)0L}
2874#else
2875 (char_u *)NULL, PV_NONE,
2876 {(char_u *)0L, (char_u *)0L}
2877#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002878 SCTX_INIT},
Bram Moolenaar55debbe2010-05-23 23:34:36 +02002879 {"undofile", "udf", P_BOOL|P_VI_DEF|P_VIM,
2880#ifdef FEAT_PERSISTENT_UNDO
2881 (char_u *)&p_udf, PV_UDF,
2882#else
2883 (char_u *)NULL, PV_NONE,
2884#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002885 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002886 {"undolevels", "ul", P_NUM|P_VI_DEF,
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01002887 (char_u *)&p_ul, PV_UL,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002888 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01002889#if defined(UNIX) || defined(MSWIN) || defined(VMS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002890 (char_u *)1000L,
2891#else
2892 (char_u *)100L,
2893#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002894 (char_u *)0L} SCTX_INIT},
Bram Moolenaar59f931e2010-07-24 20:27:03 +02002895 {"undoreload", "ur", P_NUM|P_VI_DEF,
2896 (char_u *)&p_ur, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002897 { (char_u *)10000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002898 {"updatecount", "uc", P_NUM|P_VI_DEF,
2899 (char_u *)&p_uc, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002900 {(char_u *)200L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002901 {"updatetime", "ut", P_NUM|P_VI_DEF,
2902 (char_u *)&p_ut, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002903 {(char_u *)4000L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002904 {"varsofttabstop", "vsts", P_STRING|P_VI_DEF|P_VIM|P_COMMA,
2905#ifdef FEAT_VARTABS
2906 (char_u *)&p_vsts, PV_VSTS,
2907 {(char_u *)"", (char_u *)0L}
2908#else
2909 (char_u *)NULL, PV_NONE,
2910 {(char_u *)"", (char_u *)NULL}
2911#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002912 SCTX_INIT},
Bram Moolenaar04958cb2018-06-23 19:23:02 +02002913 {"vartabstop", "vts", P_STRING|P_VI_DEF|P_VIM|P_RBUF|P_COMMA,
2914#ifdef FEAT_VARTABS
2915 (char_u *)&p_vts, PV_VTS,
2916 {(char_u *)"", (char_u *)0L}
2917#else
2918 (char_u *)NULL, PV_NONE,
2919 {(char_u *)"", (char_u *)NULL}
2920#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002921 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002922 {"verbose", "vbs", P_NUM|P_VI_DEF,
2923 (char_u *)&p_verbose, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002924 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar54ee7752005-05-31 22:22:17 +00002925 {"verbosefile", "vfile", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2926 (char_u *)&p_vfile, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002927 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002928 {"viewdir", "vdir", P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
2929#ifdef FEAT_SESSION
2930 (char_u *)&p_vdir, PV_NONE,
2931 {(char_u *)DFLT_VDIR, (char_u *)0L}
2932#else
2933 (char_u *)NULL, PV_NONE,
2934 {(char_u *)0L, (char_u *)0L}
2935#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002936 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002937 {"viewoptions", "vop", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002938#ifdef FEAT_SESSION
2939 (char_u *)&p_vop, PV_NONE,
Bram Moolenaar13e90412017-11-11 18:16:48 +01002940 {(char_u *)"folds,options,cursor,curdir",
2941 (char_u *)0L}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002942#else
2943 (char_u *)NULL, PV_NONE,
2944 {(char_u *)0L, (char_u *)0L}
2945#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002946 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002947 {"viminfo", "vi", P_STRING|P_ONECOMMA|P_NODUP|P_SECURE,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002948#ifdef FEAT_VIMINFO
2949 (char_u *)&p_viminfo, PV_NONE,
Bram Moolenaar48e330a2016-02-23 14:53:34 +01002950#if defined(MSWIN)
Bram Moolenaard812df62008-11-09 12:46:09 +00002951 {(char_u *)"", (char_u *)"'100,<50,s10,h,rA:,rB:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002952#else
2953# ifdef AMIGA
2954 {(char_u *)"",
Bram Moolenaard812df62008-11-09 12:46:09 +00002955 (char_u *)"'100,<50,s10,h,rdf0:,rdf1:,rdf2:"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002956# else
Bram Moolenaard812df62008-11-09 12:46:09 +00002957 {(char_u *)"", (char_u *)"'100,<50,s10,h"}
Bram Moolenaar071d4272004-06-13 20:20:40 +00002958# endif
2959#endif
2960#else
2961 (char_u *)NULL, PV_NONE,
2962 {(char_u *)0L, (char_u *)0L}
2963#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002964 SCTX_INIT},
Bram Moolenaarc229e542018-07-08 21:46:56 +02002965 {"viminfofile", "vif", P_STRING|P_EXPAND|P_ONECOMMA|P_NODUP
2966 |P_SECURE|P_VI_DEF,
Bram Moolenaarc4da1132017-07-15 19:39:43 +02002967#ifdef FEAT_VIMINFO
2968 (char_u *)&p_viminfofile, PV_NONE,
2969 {(char_u *)"", (char_u *)0L}
2970#else
2971 (char_u *)NULL, PV_NONE,
2972 {(char_u *)0L, (char_u *)0L}
2973#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002974 SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002975 {"virtualedit", "ve", P_STRING|P_ONECOMMA|P_NODUP|P_VI_DEF
2976 |P_VIM|P_CURSWANT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002977 (char_u *)&p_ve, PV_NONE,
2978 {(char_u *)"", (char_u *)""}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002979 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002980 {"visualbell", "vb", P_BOOL|P_VI_DEF,
2981 (char_u *)&p_vb, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002982 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002983 {"w300", 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 {"w1200", 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 {"w9600", NULL, P_NUM|P_VI_DEF,
2990 (char_u *)NULL, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002991 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002992 {"warn", NULL, P_BOOL|P_VI_DEF,
2993 (char_u *)&p_warn, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002994 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00002995 {"weirdinvert", "wiv", P_BOOL|P_VI_DEF|P_RCLR,
2996 (char_u *)&p_wiv, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02002997 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02002998 {"whichwrap", "ww", P_STRING|P_VIM|P_ONECOMMA|P_FLAGLIST,
Bram Moolenaar071d4272004-06-13 20:20:40 +00002999 (char_u *)&p_ww, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003000 {(char_u *)"", (char_u *)"b,s"} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003001 {"wildchar", "wc", P_NUM|P_VIM,
3002 (char_u *)&p_wc, PV_NONE,
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003003 {(char_u *)(long)Ctrl_E, (char_u *)(long)TAB}
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003004 SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003005 {"wildcharm", "wcm", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003006 (char_u *)&p_wcm, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003007 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003008 {"wildignore", "wig", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003009#ifdef FEAT_WILDIGN
3010 (char_u *)&p_wig, PV_NONE,
3011#else
3012 (char_u *)NULL, PV_NONE,
3013#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003014 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar94950a92010-12-02 16:01:29 +01003015 {"wildignorecase", "wic", P_BOOL|P_VI_DEF,
3016 (char_u *)&p_wic, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003017 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003018 {"wildmenu", "wmnu", P_BOOL|P_VI_DEF,
3019#ifdef FEAT_WILDMENU
3020 (char_u *)&p_wmnu, PV_NONE,
3021#else
3022 (char_u *)NULL, PV_NONE,
3023#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003024 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar0e7c4b92015-06-20 15:30:03 +02003025 {"wildmode", "wim", P_STRING|P_VI_DEF|P_ONECOMMA|P_NODUP,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003026 (char_u *)&p_wim, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003027 {(char_u *)"full", (char_u *)0L} SCTX_INIT},
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003028 {"wildoptions", "wop", P_STRING|P_VI_DEF,
3029#ifdef FEAT_CMDL_COMPL
3030 (char_u *)&p_wop, PV_NONE,
3031 {(char_u *)"", (char_u *)0L}
3032#else
3033 (char_u *)NULL, PV_NONE,
3034 {(char_u *)NULL, (char_u *)0L}
3035#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003036 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003037 {"winaltkeys", "wak", P_STRING|P_VI_DEF,
3038#ifdef FEAT_WAK
3039 (char_u *)&p_wak, PV_NONE,
3040 {(char_u *)"menu", (char_u *)0L}
3041#else
3042 (char_u *)NULL, PV_NONE,
3043 {(char_u *)NULL, (char_u *)0L}
3044#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003045 SCTX_INIT},
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003046 {"wincolor", "wcr", P_STRING|P_ALLOCED|P_VI_DEF|P_RWIN,
3047 (char_u *)VAR_WIN, PV_WCR,
3048 {(char_u *)"", (char_u *)NULL}
3049 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003050 {"window", "wi", P_NUM|P_VI_DEF,
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003051 (char_u *)&p_window, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003052 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003053 {"winheight", "wh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003054 (char_u *)&p_wh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003055 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003056 {"winfixheight", "wfh", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003057 (char_u *)VAR_WIN, PV_WFH,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003058 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003059 {"winfixwidth", "wfw", P_BOOL|P_VI_DEF|P_RSTAT,
Bram Moolenaar97b2ad32006-03-18 21:40:56 +00003060 (char_u *)VAR_WIN, PV_WFW,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003061 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003062 {"winminheight", "wmh", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003063 (char_u *)&p_wmh, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003064 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003065 {"winminwidth", "wmw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003066 (char_u *)&p_wmw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003067 {(char_u *)1L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003068 {"winptydll", NULL, P_STRING|P_EXPAND|P_VI_DEF|P_SECURE,
Bram Moolenaar4f974752019-02-17 17:44:42 +01003069#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaar9e13aa72017-08-16 23:14:08 +02003070 (char_u *)&p_winptydll, PV_NONE, {
3071# ifdef _WIN64
3072 (char_u *)"winpty64.dll",
3073# else
3074 (char_u *)"winpty32.dll",
3075# endif
3076 (char_u *)0L}
3077#else
3078 (char_u *)NULL, PV_NONE,
3079 {(char_u *)0L, (char_u *)0L}
3080#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003081 SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003082 {"winwidth", "wiw", P_NUM|P_VI_DEF,
Bram Moolenaar071d4272004-06-13 20:20:40 +00003083 (char_u *)&p_wiw, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003084 {(char_u *)20L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003085 {"wrap", NULL, P_BOOL|P_VI_DEF|P_RWIN,
3086 (char_u *)VAR_WIN, PV_WRAP,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003087 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003088 {"wrapmargin", "wm", P_NUM|P_VI_DEF,
3089 (char_u *)&p_wm, PV_WM,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003090 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003091 {"wrapscan", "ws", P_BOOL|P_VI_DEF,
3092 (char_u *)&p_ws, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003093 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003094 {"write", NULL, P_BOOL|P_VI_DEF,
3095 (char_u *)&p_write, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003096 {(char_u *)TRUE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003097 {"writeany", "wa", P_BOOL|P_VI_DEF,
3098 (char_u *)&p_wa, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003099 {(char_u *)FALSE, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003100 {"writebackup", "wb", P_BOOL|P_VI_DEF|P_VIM,
3101 (char_u *)&p_wb, PV_NONE,
3102 {
3103#ifdef FEAT_WRITEBACKUP
3104 (char_u *)TRUE,
3105#else
3106 (char_u *)FALSE,
3107#endif
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003108 (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003109 {"writedelay", "wd", P_NUM|P_VI_DEF,
3110 (char_u *)&p_wd, PV_NONE,
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003111 {(char_u *)0L, (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003112
3113/* terminal output codes */
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00003114#define p_term(sss, vvv) {sss, NULL, P_STRING|P_VI_DEF|P_RALL|P_SECURE, \
Bram Moolenaar071d4272004-06-13 20:20:40 +00003115 (char_u *)&vvv, PV_NONE, \
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003116 {(char_u *)"", (char_u *)0L} SCTX_INIT},
Bram Moolenaar071d4272004-06-13 20:20:40 +00003117
3118 p_term("t_AB", T_CAB)
3119 p_term("t_AF", T_CAF)
3120 p_term("t_AL", T_CAL)
3121 p_term("t_al", T_AL)
3122 p_term("t_bc", T_BC)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003123 p_term("t_BE", T_BE)
3124 p_term("t_BD", T_BD)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003125 p_term("t_cd", T_CD)
3126 p_term("t_ce", T_CE)
3127 p_term("t_cl", T_CL)
3128 p_term("t_cm", T_CM)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003129 p_term("t_Ce", T_UCE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003130 p_term("t_Co", T_CCO)
3131 p_term("t_CS", T_CCS)
Bram Moolenaar450ca432015-11-10 13:30:39 +01003132 p_term("t_Cs", T_UCS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003133 p_term("t_cs", T_CS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003134 p_term("t_CV", T_CSV)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003135 p_term("t_da", T_DA)
3136 p_term("t_db", T_DB)
3137 p_term("t_DL", T_CDL)
3138 p_term("t_dl", T_DL)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003139 p_term("t_EC", T_CEC)
Bram Moolenaare5401222015-06-25 19:16:56 +02003140 p_term("t_EI", T_CEI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003141 p_term("t_fs", T_FS)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003142 p_term("t_GP", T_CGP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003143 p_term("t_IE", T_CIE)
3144 p_term("t_IS", T_CIS)
3145 p_term("t_ke", T_KE)
3146 p_term("t_ks", T_KS)
3147 p_term("t_le", T_LE)
3148 p_term("t_mb", T_MB)
3149 p_term("t_md", T_MD)
3150 p_term("t_me", T_ME)
3151 p_term("t_mr", T_MR)
3152 p_term("t_ms", T_MS)
3153 p_term("t_nd", T_ND)
3154 p_term("t_op", T_OP)
Bram Moolenaara20f83d2017-10-15 13:35:01 +02003155 p_term("t_RF", T_RFG)
Bram Moolenaare5401222015-06-25 19:16:56 +02003156 p_term("t_RB", T_RBG)
Bram Moolenaar4db25542017-08-28 22:43:05 +02003157 p_term("t_RC", T_CRC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003158 p_term("t_RI", T_CRI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003159 p_term("t_Ri", T_SRI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003160 p_term("t_RS", T_CRS)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003161 p_term("t_RT", T_CRT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003162 p_term("t_RV", T_CRV)
3163 p_term("t_Sb", T_CSB)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003164 p_term("t_SC", T_CSC)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003165 p_term("t_se", T_SE)
Bram Moolenaare5401222015-06-25 19:16:56 +02003166 p_term("t_Sf", T_CSF)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003167 p_term("t_SH", T_CSH)
Bram Moolenaare5401222015-06-25 19:16:56 +02003168 p_term("t_SI", T_CSI)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003169 p_term("t_Si", T_SSI)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003170 p_term("t_so", T_SO)
Bram Moolenaare5401222015-06-25 19:16:56 +02003171 p_term("t_SR", T_CSR)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003172 p_term("t_sr", T_SR)
Bram Moolenaar40385db2018-08-07 22:31:44 +02003173 p_term("t_ST", T_CST)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003174 p_term("t_Te", T_STE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003175 p_term("t_te", T_TE)
3176 p_term("t_ti", T_TI)
Bram Moolenaarcf4b00c2017-09-02 18:33:56 +02003177 p_term("t_Ts", T_STS)
Bram Moolenaare5401222015-06-25 19:16:56 +02003178 p_term("t_ts", T_TS)
3179 p_term("t_u7", T_U7)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003180 p_term("t_ue", T_UE)
3181 p_term("t_us", T_US)
Bram Moolenaare5401222015-06-25 19:16:56 +02003182 p_term("t_ut", T_UT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003183 p_term("t_vb", T_VB)
3184 p_term("t_ve", T_VE)
3185 p_term("t_vi", T_VI)
Bram Moolenaarce1c3272017-08-20 15:05:15 +02003186 p_term("t_VS", T_CVS)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003187 p_term("t_vs", T_VS)
3188 p_term("t_WP", T_CWP)
3189 p_term("t_WS", T_CWS)
Bram Moolenaar494838a2015-02-10 19:20:37 +01003190 p_term("t_xn", T_XN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003191 p_term("t_xs", T_XS)
3192 p_term("t_ZH", T_CZH)
3193 p_term("t_ZR", T_CZR)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02003194 p_term("t_8f", T_8F)
3195 p_term("t_8b", T_8B)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003196
3197/* terminal key codes are not in here */
3198
Bram Moolenaar2c4278f2009-05-17 11:33:22 +00003199 /* end marker */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003200 {NULL, NULL, 0, NULL, PV_NONE, {NULL, NULL} SCTX_INIT}
Bram Moolenaar071d4272004-06-13 20:20:40 +00003201};
3202
3203#define PARAM_COUNT (sizeof(options) / sizeof(struct vimoption))
3204
Bram Moolenaar071d4272004-06-13 20:20:40 +00003205static char *(p_ambw_values[]) = {"single", "double", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003206static char *(p_bg_values[]) = {"light", "dark", NULL};
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01003207static char *(p_nf_values[]) = {"bin", "octal", "hex", "alpha", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003208static char *(p_ff_values[]) = {FF_UNIX, FF_DOS, FF_MAC, NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003209#ifdef FEAT_CRYPT
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02003210static char *(p_cm_values[]) = {"zip", "blowfish", "blowfish2", NULL};
Bram Moolenaar49771f42010-07-20 17:32:38 +02003211#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00003212#ifdef FEAT_CMDL_COMPL
3213static char *(p_wop_values[]) = {"tagfile", NULL};
3214#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003215#ifdef FEAT_WAK
3216static char *(p_wak_values[]) = {"yes", "menu", "no", NULL};
3217#endif
3218static char *(p_mousem_values[]) = {"extend", "popup", "popup_setpos", "mac", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003219static char *(p_sel_values[]) = {"inclusive", "exclusive", "old", NULL};
3220static char *(p_slm_values[]) = {"mouse", "key", "cmd", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003221static char *(p_km_values[]) = {"startsel", "stopsel", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003222#ifdef FEAT_BROWSE
3223static char *(p_bsdir_values[]) = {"current", "last", "buffer", NULL};
3224#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003225static char *(p_scbopt_values[]) = {"ver", "hor", "jump", NULL};
Bram Moolenaar57657d82006-04-21 22:12:41 +00003226static char *(p_debug_values[]) = {"msg", "throw", "beep", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003227static char *(p_ead_values[]) = {"both", "ver", "hor", NULL};
Bram Moolenaar4d784b22019-05-25 19:51:39 +02003228static char *(p_buftype_values[]) = {"nofile", "nowrite", "quickfix", "help", "terminal", "acwrite", "prompt", "popup", NULL};
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02003229static char *(p_bufhidden_values[]) = {"hide", "unload", "delete", "wipe", NULL};
Bram Moolenaar071d4272004-06-13 20:20:40 +00003230static char *(p_bs_values[]) = {"indent", "eol", "start", NULL};
3231#ifdef FEAT_FOLDING
3232static char *(p_fdm_values[]) = {"manual", "expr", "marker", "indent", "syntax",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003233# ifdef FEAT_DIFF
Bram Moolenaar071d4272004-06-13 20:20:40 +00003234 "diff",
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003235# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003236 NULL};
3237static char *(p_fcl_values[]) = {"all", NULL};
3238#endif
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003239#ifdef FEAT_INS_EXPAND
Bram Moolenaarb6be1e22015-07-10 18:18:40 +02003240static char *(p_cot_values[]) = {"menu", "menuone", "longest", "preview", "noinsert", "noselect", NULL};
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00003241#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003242#ifdef FEAT_SIGNS
Bram Moolenaar394c5d82019-06-17 21:48:05 +02003243static char *(p_scl_values[]) = {"yes", "no", "auto", "number", NULL};
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02003244#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003245#if defined(MSWIN) && defined(FEAT_TERMINAL)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01003246static char *(p_twt_values[]) = {"winpty", "conpty", "", NULL};
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003247#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003248
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003249static void set_options_default(int opt_flags);
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003250static void set_string_default_esc(char *name, char_u *val, int escape);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003251static char_u *term_bg_default(void);
Bram Moolenaar916a8182018-11-25 02:18:29 +01003252static void did_set_option(int opt_idx, int opt_flags, int new_value, int value_checked);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003253static char_u *option_expand(int opt_idx, char_u *val);
3254static void didset_options(void);
3255static void didset_options2(void);
3256static void check_string_option(char_u **pp);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003257#if defined(FEAT_EVAL) || defined(PROTO)
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003258static long_u *insecure_flag(int opt_idx, int opt_flags);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003259#else
3260# define insecure_flag(opt_idx, opt_flags) (&options[opt_idx].flags)
3261#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003262static void set_string_option_global(int opt_idx, char_u **varp);
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003263static 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);
3264static char *set_chars_option(char_u **varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003265#ifdef FEAT_CLIPBOARD
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003266static char *check_clipboard_option(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003267#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003268#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003269static char *did_set_spell_option(int is_spellfile);
3270static char *compile_cap_prog(synblock_T *synblock);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00003271#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003272#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003273static void set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00003274#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003275static char *set_bool_option(int opt_idx, char_u *varp, int value, int opt_flags);
3276static 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 +01003277static void check_redraw(long_u flags);
3278static int findoption(char_u *);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02003279static int find_key_option(char_u *arg_arg, int has_lt);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003280static void showoptions(int all, int opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003281static int optval_default(struct vimoption *, char_u *varp, int compatible);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003282static void showoneopt(struct vimoption *, int opt_flags);
Bram Moolenaared18f2c2019-01-24 20:30:52 +01003283static int put_setstring(FILE *fd, char *cmd, char *name, char_u **valuep, long_u flags);
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003284static int put_setnum(FILE *fd, char *cmd, char *name, long *valuep);
3285static int put_setbool(FILE *fd, char *cmd, char *name, int value);
3286static int istermoption(struct vimoption *);
3287static char_u *get_varp_scope(struct vimoption *p, int opt_flags);
3288static char_u *get_varp(struct vimoption *);
3289static void option_value2string(struct vimoption *, int opt_flags);
3290static void check_winopt(winopt_T *wop);
3291static int wc_use_keyname(char_u *varp, long *wcp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003292#ifdef FEAT_LANGMAP
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003293static void langmap_init(void);
3294static void langmap_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003295#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003296static void paste_option_changed(void);
3297static void compatible_set(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003298#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003299static void fill_breakat_flags(void);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003300#endif
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003301static int opt_strings_flags(char_u *val, char **values, unsigned *flagp, int list);
3302static int check_opt_strings(char_u *val, char **values, int);
3303static int check_opt_wim(void);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003304#ifdef FEAT_LINEBREAK
Bram Moolenaarbaaa7e92016-01-29 22:47:03 +01003305static int briopt_check(win_T *wp);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02003306#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003307
3308/*
3309 * Initialize the options, first part.
3310 *
3311 * Called only once from main(), just after creating the first buffer.
Bram Moolenaar07268702018-03-01 21:57:32 +01003312 * If "clean_arg" is TRUE Vim was started with --clean.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003313 */
3314 void
Bram Moolenaar07268702018-03-01 21:57:32 +01003315set_init_1(int clean_arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003316{
3317 char_u *p;
3318 int opt_idx;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003319 long_u n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003320
3321#ifdef FEAT_LANGMAP
3322 langmap_init();
3323#endif
3324
3325 /* Be Vi compatible by default */
3326 p_cp = TRUE;
3327
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003328 /* Use POSIX compatibility when $VIM_POSIX is set. */
3329 if (mch_getenv((char_u *)"VIM_POSIX") != NULL)
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003330 {
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003331 set_string_default("cpo", (char_u *)CPO_ALL);
Bram Moolenaar9dfa3132019-05-04 21:08:40 +02003332 set_string_default("shm", (char_u *)SHM_POSIX);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003333 }
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003334
Bram Moolenaar071d4272004-06-13 20:20:40 +00003335 /*
3336 * Find default value for 'shell' option.
Bram Moolenaar7c626922005-02-07 22:01:03 +00003337 * Don't use it if it is empty.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003338 */
Bram Moolenaar7c626922005-02-07 22:01:03 +00003339 if (((p = mch_getenv((char_u *)"SHELL")) != NULL && *p != NUL)
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003340#if defined(MSWIN)
Bram Moolenaar7c626922005-02-07 22:01:03 +00003341 || ((p = mch_getenv((char_u *)"COMSPEC")) != NULL && *p != NUL)
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003342 || ((p = (char_u *)default_shell()) != NULL && *p != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003343#endif
Bram Moolenaar7c626922005-02-07 22:01:03 +00003344 )
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003345 set_string_default_esc("sh", p, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003346
3347#ifdef FEAT_WILDIGN
3348 /*
3349 * Set the default for 'backupskip' to include environment variables for
3350 * temp files.
3351 */
3352 {
3353# ifdef UNIX
3354 static char *(names[4]) = {"", "TMPDIR", "TEMP", "TMP"};
3355# else
3356 static char *(names[3]) = {"TMPDIR", "TEMP", "TMP"};
3357# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003358 int len;
3359 garray_T ga;
3360 int mustfree;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003361
3362 ga_init2(&ga, 1, 100);
3363 for (n = 0; n < (long)(sizeof(names) / sizeof(char *)); ++n)
3364 {
Bram Moolenaar05159a02005-02-26 23:04:13 +00003365 mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003366# ifdef UNIX
3367 if (*names[n] == NUL)
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003368# ifdef MACOS_X
3369 p = (char_u *)"/private/tmp";
3370# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003371 p = (char_u *)"/tmp";
Bram Moolenaarb8e22a02018-04-12 21:37:34 +02003372# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003373 else
3374# endif
Bram Moolenaar05159a02005-02-26 23:04:13 +00003375 p = vim_getenv((char_u *)names[n], &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003376 if (p != NULL && *p != NUL)
3377 {
3378 /* First time count the NUL, otherwise count the ','. */
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00003379 len = (int)STRLEN(p) + 3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003380 if (ga_grow(&ga, len) == OK)
3381 {
3382 if (ga.ga_len > 0)
3383 STRCAT(ga.ga_data, ",");
3384 STRCAT(ga.ga_data, p);
3385 add_pathsep(ga.ga_data);
3386 STRCAT(ga.ga_data, "*");
Bram Moolenaar071d4272004-06-13 20:20:40 +00003387 ga.ga_len += len;
3388 }
3389 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003390 if (mustfree)
3391 vim_free(p);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003392 }
3393 if (ga.ga_data != NULL)
3394 {
3395 set_string_default("bsk", ga.ga_data);
3396 vim_free(ga.ga_data);
3397 }
3398 }
3399#endif
3400
3401 /*
3402 * 'maxmemtot' and 'maxmem' may have to be adjusted for available memory
3403 */
3404 opt_idx = findoption((char_u *)"maxmemtot");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003405 if (opt_idx >= 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003406 {
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003407#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
3408 if (options[opt_idx].def_val[VI_DEFAULT] == (char_u *)0L)
3409#endif
3410 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00003411#ifdef HAVE_AVAIL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003412 /* Use amount of memory available at this moment. */
Bram Moolenaar11b73d62012-06-29 15:51:30 +02003413 n = (mch_avail_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003414#else
3415# ifdef HAVE_TOTAL_MEM
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003416 /* Use amount of memory available to Vim. */
Bram Moolenaar914572a2007-05-01 11:37:47 +00003417 n = (mch_total_mem(FALSE) >> 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003418# else
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003419 n = (0x7fffffff >> 11);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003420# endif
3421#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003422 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003423 opt_idx = findoption((char_u *)"maxmem");
3424 if (opt_idx >= 0)
3425 {
3426#if !defined(HAVE_AVAIL_MEM) && !defined(HAVE_TOTAL_MEM)
Bram Moolenaar35be4532015-12-11 22:38:36 +01003427 if ((long)(long_i)options[opt_idx].def_val[VI_DEFAULT] > (long)n
3428 || (long)(long_i)options[opt_idx].def_val[VI_DEFAULT] == 0L)
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003429#endif
3430 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)n;
3431 }
3432 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003433 }
3434
Bram Moolenaar071d4272004-06-13 20:20:40 +00003435#ifdef FEAT_SEARCHPATH
3436 {
3437 char_u *cdpath;
3438 char_u *buf;
3439 int i;
3440 int j;
Bram Moolenaar05159a02005-02-26 23:04:13 +00003441 int mustfree = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003442
3443 /* Initialize the 'cdpath' option's default value. */
Bram Moolenaar05159a02005-02-26 23:04:13 +00003444 cdpath = vim_getenv((char_u *)"CDPATH", &mustfree);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003445 if (cdpath != NULL)
3446 {
Bram Moolenaar964b3742019-05-24 18:54:09 +02003447 buf = alloc((STRLEN(cdpath) << 1) + 2);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003448 if (buf != NULL)
3449 {
3450 buf[0] = ','; /* start with ",", current dir first */
3451 j = 1;
3452 for (i = 0; cdpath[i] != NUL; ++i)
3453 {
3454 if (vim_ispathlistsep(cdpath[i]))
3455 buf[j++] = ',';
3456 else
3457 {
3458 if (cdpath[i] == ' ' || cdpath[i] == ',')
3459 buf[j++] = '\\';
3460 buf[j++] = cdpath[i];
3461 }
3462 }
3463 buf[j] = NUL;
3464 opt_idx = findoption((char_u *)"cdpath");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003465 if (opt_idx >= 0)
3466 {
3467 options[opt_idx].def_val[VI_DEFAULT] = buf;
3468 options[opt_idx].flags |= P_DEF_ALLOCED;
3469 }
Bram Moolenaara9d52e32010-07-31 16:44:19 +02003470 else
3471 vim_free(buf); /* cannot happen */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003472 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00003473 if (mustfree)
3474 vim_free(cdpath);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003475 }
3476 }
3477#endif
3478
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003479#if defined(FEAT_POSTSCRIPT) && (defined(MSWIN) || defined(VMS) || defined(EBCDIC) || defined(MAC) || defined(hpux))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003480 /* Set print encoding on platforms that don't default to latin1 */
3481 set_string_default("penc",
Bram Moolenaare7fedb62015-12-31 19:07:19 +01003482# if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003483 (char_u *)"cp1252"
3484# else
3485# ifdef VMS
3486 (char_u *)"dec-mcs"
3487# else
3488# ifdef EBCDIC
3489 (char_u *)"ebcdic-uk"
3490# else
3491# ifdef MAC
3492 (char_u *)"mac-roman"
3493# else /* HPUX */
3494 (char_u *)"hp-roman8"
3495# endif
3496# endif
3497# endif
3498# endif
3499 );
3500#endif
3501
3502#ifdef FEAT_POSTSCRIPT
3503 /* 'printexpr' must be allocated to be able to evaluate it. */
3504 set_string_default("pexpr",
Bram Moolenaar48e330a2016-02-23 14:53:34 +01003505# if defined(MSWIN)
Bram Moolenaared203462004-06-16 11:19:22 +00003506 (char_u *)"system('copy' . ' ' . v:fname_in . (&printdevice == '' ? ' LPT1:' : (' \"' . &printdevice . '\"'))) . delete(v:fname_in)"
Bram Moolenaar071d4272004-06-13 20:20:40 +00003507# else
3508# ifdef VMS
3509 (char_u *)"system('print/delete' . (&printdevice == '' ? '' : ' /queue=' . &printdevice) . ' ' . v:fname_in)"
3510
3511# else
3512 (char_u *)"system('lpr' . (&printdevice == '' ? '' : ' -P' . &printdevice) . ' ' . v:fname_in) . delete(v:fname_in) + v:shell_error"
3513# endif
3514# endif
3515 );
3516#endif
3517
3518 /*
3519 * Set all the options (except the terminal options) to their default
3520 * value. Also set the global value for local options.
3521 */
3522 set_options_default(0);
3523
Bram Moolenaar07268702018-03-01 21:57:32 +01003524#ifdef CLEAN_RUNTIMEPATH
3525 if (clean_arg)
3526 {
3527 opt_idx = findoption((char_u *)"runtimepath");
3528 if (opt_idx >= 0)
3529 {
3530 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3531 p_rtp = (char_u *)CLEAN_RUNTIMEPATH;
3532 }
3533 opt_idx = findoption((char_u *)"packpath");
3534 if (opt_idx >= 0)
3535 {
3536 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)CLEAN_RUNTIMEPATH;
3537 p_pp = (char_u *)CLEAN_RUNTIMEPATH;
3538 }
3539 }
3540#endif
3541
Bram Moolenaar071d4272004-06-13 20:20:40 +00003542#ifdef FEAT_GUI
3543 if (found_reverse_arg)
3544 set_option_value((char_u *)"bg", 0L, (char_u *)"dark", 0);
3545#endif
3546
3547 curbuf->b_p_initialized = TRUE;
3548 curbuf->b_p_ar = -1; /* no local 'autoread' value */
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01003549 curbuf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003550 check_buf_options(curbuf);
3551 check_win_options(curwin);
3552 check_options();
3553
3554 /* Must be before option_expand(), because that one needs vim_isIDc() */
3555 didset_options();
3556
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00003557#ifdef FEAT_SPELL
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003558 /* Use the current chartab for the generic chartab. This is not in
3559 * didset_options() because it only depends on 'encoding'. */
Bram Moolenaar6bb68362005-03-22 23:03:44 +00003560 init_spell_chartab();
3561#endif
3562
Bram Moolenaar071d4272004-06-13 20:20:40 +00003563 /*
3564 * Expand environment variables and things like "~" for the defaults.
3565 * If option_expand() returns non-NULL the variable is expanded. This can
3566 * only happen for non-indirect options.
3567 * Also set the default to the expanded value, so ":set" does not list
3568 * them.
3569 * Don't set the P_ALLOCED flag, because we don't want to free the
3570 * default.
3571 */
3572 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
3573 {
3574 if ((options[opt_idx].flags & P_GETTEXT)
3575 && options[opt_idx].var != NULL)
3576 p = (char_u *)_(*(char **)options[opt_idx].var);
3577 else
3578 p = option_expand(opt_idx, NULL);
3579 if (p != NULL && (p = vim_strsave(p)) != NULL)
3580 {
3581 *(char_u **)options[opt_idx].var = p;
3582 /* VIMEXP
3583 * Defaults for all expanded options are currently the same for Vi
3584 * and Vim. When this changes, add some code here! Also need to
3585 * split P_DEF_ALLOCED in two.
3586 */
3587 if (options[opt_idx].flags & P_DEF_ALLOCED)
3588 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3589 options[opt_idx].def_val[VI_DEFAULT] = p;
3590 options[opt_idx].flags |= P_DEF_ALLOCED;
3591 }
3592 }
3593
Bram Moolenaar071d4272004-06-13 20:20:40 +00003594 save_file_ff(curbuf); /* Buffer is unchanged */
3595
Bram Moolenaar071d4272004-06-13 20:20:40 +00003596#if defined(FEAT_ARABIC)
3597 /* Detect use of mlterm.
3598 * Mlterm is a terminal emulator akin to xterm that has some special
3599 * abilities (bidi namely).
3600 * NOTE: mlterm's author is being asked to 'set' a variable
3601 * instead of an environment variable due to inheritance.
3602 */
3603 if (mch_getenv((char_u *)"MLTERM") != NULL)
3604 set_option_value((char_u *)"tbidi", 1L, NULL, 0);
3605#endif
3606
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003607 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +00003608
Bram Moolenaar4f974752019-02-17 17:44:42 +01003609# if defined(MSWIN) && defined(FEAT_GETTEXT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003610 /*
3611 * If $LANG isn't set, try to get a good value for it. This makes the
3612 * right language be used automatically. Don't do this for English.
3613 */
3614 if (mch_getenv((char_u *)"LANG") == NULL)
3615 {
3616 char buf[20];
3617
3618 /* Could use LOCALE_SISO639LANGNAME, but it's not in Win95.
3619 * LOCALE_SABBREVLANGNAME gives us three letters, like "enu", we use
3620 * only the first two. */
3621 n = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SABBREVLANGNAME,
3622 (LPTSTR)buf, 20);
3623 if (n >= 2 && STRNICMP(buf, "en", 2) != 0)
3624 {
3625 /* There are a few exceptions (probably more) */
3626 if (STRNICMP(buf, "cht", 3) == 0 || STRNICMP(buf, "zht", 3) == 0)
3627 STRCPY(buf, "zh_TW");
3628 else if (STRNICMP(buf, "chs", 3) == 0
3629 || STRNICMP(buf, "zhc", 3) == 0)
3630 STRCPY(buf, "zh_CN");
3631 else if (STRNICMP(buf, "jp", 2) == 0)
3632 STRCPY(buf, "ja");
3633 else
3634 buf[2] = NUL; /* truncate to two-letter code */
Bram Moolenaar6aa2cd42016-02-16 15:06:59 +01003635 vim_setenv((char_u *)"LANG", (char_u *)buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003636 }
3637 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003638# else
Bram Moolenaar9d47f172006-03-15 23:03:01 +00003639# ifdef MACOS_CONVERT
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00003640 /* Moved to os_mac_conv.c to avoid dependency problems. */
3641 mac_lang_init();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003642# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003643# endif
3644
3645 /* enc_locale() will try to find the encoding of the current locale. */
3646 p = enc_locale();
3647 if (p != NULL)
3648 {
3649 char_u *save_enc;
3650
3651 /* Try setting 'encoding' and check if the value is valid.
3652 * If not, go back to the default "latin1". */
3653 save_enc = p_enc;
3654 p_enc = p;
Bram Moolenaar733f0a22007-03-02 18:56:27 +00003655 if (STRCMP(p_enc, "gb18030") == 0)
3656 {
3657 /* We don't support "gb18030", but "cp936" is a good substitute
3658 * for practical purposes, thus use that. It's not an alias to
3659 * still support conversion between gb18030 and utf-8. */
3660 p_enc = vim_strsave((char_u *)"cp936");
3661 vim_free(p);
3662 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003663 if (mb_init() == NULL)
3664 {
3665 opt_idx = findoption((char_u *)"encoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003666 if (opt_idx >= 0)
3667 {
3668 options[opt_idx].def_val[VI_DEFAULT] = p_enc;
3669 options[opt_idx].flags |= P_DEF_ALLOCED;
3670 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003671
Bram Moolenaard0573012017-10-28 21:11:06 +02003672#if defined(MSWIN) || defined(MACOS_X) || defined(VMS)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01003673 if (STRCMP(p_enc, "latin1") == 0 || enc_utf8)
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003674 {
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003675 /* Adjust the default for 'isprint' and 'iskeyword' to match
3676 * latin1. Also set the defaults for when 'nocompatible' is
3677 * set. */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003678 set_string_option_direct((char_u *)"isp", -1,
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00003679 ISP_LATIN1, OPT_FREE, SID_NONE);
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003680 set_string_option_direct((char_u *)"isk", -1,
3681 ISK_LATIN1, OPT_FREE, SID_NONE);
3682 opt_idx = findoption((char_u *)"isp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003683 if (opt_idx >= 0)
3684 options[opt_idx].def_val[VIM_DEFAULT] = ISP_LATIN1;
Bram Moolenaar362e1a32006-03-06 23:29:24 +00003685 opt_idx = findoption((char_u *)"isk");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003686 if (opt_idx >= 0)
3687 options[opt_idx].def_val[VIM_DEFAULT] = ISK_LATIN1;
Bram Moolenaarc0197e22004-09-13 20:26:32 +00003688 (void)init_chartab();
3689 }
3690#endif
3691
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003692#if defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003693 /* Win32 console: When GetACP() returns a different value from
3694 * GetConsoleCP() set 'termencoding'. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02003695 if (
3696# ifdef VIMDLL
3697 (!gui.in_use && !gui.starting) &&
3698# endif
3699 GetACP() != GetConsoleCP())
Bram Moolenaar071d4272004-06-13 20:20:40 +00003700 {
3701 char buf[50];
3702
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01003703 /* Win32 console: In ConPTY, GetConsoleCP() returns zero.
3704 * Use an alternative value. */
3705 if (GetConsoleCP() == 0)
3706 sprintf(buf, "cp%ld", (long)GetACP());
3707 else
3708 sprintf(buf, "cp%ld", (long)GetConsoleCP());
Bram Moolenaar071d4272004-06-13 20:20:40 +00003709 p_tenc = vim_strsave((char_u *)buf);
3710 if (p_tenc != NULL)
3711 {
3712 opt_idx = findoption((char_u *)"termencoding");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003713 if (opt_idx >= 0)
3714 {
3715 options[opt_idx].def_val[VI_DEFAULT] = p_tenc;
3716 options[opt_idx].flags |= P_DEF_ALLOCED;
3717 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003718 convert_setup(&input_conv, p_tenc, p_enc);
3719 convert_setup(&output_conv, p_enc, p_tenc);
3720 }
3721 else
3722 p_tenc = empty_option;
3723 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003724#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01003725#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00003726 /* $HOME may have characters in active code page. */
3727 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003728#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003729 }
3730 else
3731 {
3732 vim_free(p_enc);
3733 p_enc = save_enc;
3734 }
3735 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003736
3737#ifdef FEAT_MULTI_LANG
3738 /* Set the default for 'helplang'. */
3739 set_helplang_default(get_mess_lang());
3740#endif
3741}
3742
3743/*
3744 * Set an option to its default value.
3745 * This does not take care of side effects!
3746 */
3747 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003748set_option_default(
3749 int opt_idx,
3750 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
3751 int compatible) /* use Vi default value */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003752{
3753 char_u *varp; /* pointer to variable for current option */
3754 int dvi; /* index in def_val[] */
3755 long_u flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003756 long_u *flagsp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003757 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
3758
3759 varp = get_varp_scope(&(options[opt_idx]), both ? OPT_LOCAL : opt_flags);
3760 flags = options[opt_idx].flags;
Bram Moolenaar3638c682005-06-08 22:05:14 +00003761 if (varp != NULL) /* skip hidden option, nothing to do for it */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003762 {
3763 dvi = ((flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
3764 if (flags & P_STRING)
3765 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003766 /* Use set_string_option_direct() for local options to handle
3767 * freeing and allocating the value. */
3768 if (options[opt_idx].indir != PV_NONE)
3769 set_string_option_direct(NULL, opt_idx,
3770 options[opt_idx].def_val[dvi], opt_flags, 0);
3771 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00003772 {
Bram Moolenaarb833c1e2018-05-05 16:36:06 +02003773 if ((opt_flags & OPT_FREE) && (flags & P_ALLOCED))
3774 free_string_option(*(char_u **)(varp));
3775 *(char_u **)varp = options[opt_idx].def_val[dvi];
3776 options[opt_idx].flags &= ~P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003777 }
3778 }
3779 else if (flags & P_NUM)
3780 {
Bram Moolenaar5fc1a8b2006-10-17 16:34:24 +00003781 if (options[opt_idx].indir == PV_SCROLL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003782 win_comp_scroll(curwin);
3783 else
3784 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01003785 long def_val = (long)(long_i)options[opt_idx].def_val[dvi];
3786
3787 if ((long *)varp == &curwin->w_p_so
3788 || (long *)varp == &curwin->w_p_siso)
3789 // 'scrolloff' and 'sidescrolloff' local values have a
3790 // different default value than the global default.
3791 *(long *)varp = -1;
3792 else
3793 *(long *)varp = def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003794 /* May also set global value for local option. */
3795 if (both)
3796 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
Bram Moolenaar375e3392019-01-31 18:26:10 +01003797 def_val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003798 }
3799 }
3800 else /* P_BOOL */
3801 {
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003802 /* the cast to long is required for Manx C, long_i is needed for
3803 * MSVC */
3804 *(int *)varp = (int)(long)(long_i)options[opt_idx].def_val[dvi];
Bram Moolenaar8243a792007-05-01 17:05:03 +00003805#ifdef UNIX
3806 /* 'modeline' defaults to off for root */
3807 if (options[opt_idx].indir == PV_ML && getuid() == ROOT_UID)
3808 *(int *)varp = FALSE;
3809#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003810 /* May also set global value for local option. */
3811 if (both)
3812 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) =
3813 *(int *)varp;
3814 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00003815
Bram Moolenaard1f56e62006-02-22 21:25:37 +00003816 /* The default value is not insecure. */
3817 flagsp = insecure_flag(opt_idx, opt_flags);
3818 *flagsp = *flagsp & ~P_INSECURE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003819 }
3820
3821#ifdef FEAT_EVAL
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02003822 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003823#endif
3824}
3825
3826/*
3827 * Set all options (except terminal options) to their default value.
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003828 * When "opt_flags" is non-zero skip 'encoding'.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003829 */
3830 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003831set_options_default(
3832 int opt_flags) /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00003833{
3834 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003835 win_T *wp;
Bram Moolenaarf740b292006-02-16 22:11:02 +00003836 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003837
3838 for (i = 0; !istermoption(&options[i]); i++)
Bram Moolenaarb341dda2015-08-25 12:56:31 +02003839 if (!(options[i].flags & P_NODEFAULT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003840 && (opt_flags == 0
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003841 || (options[i].var != (char_u *)&p_enc
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003842# if defined(FEAT_CRYPT)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02003843 && options[i].var != (char_u *)&p_cm
Bram Moolenaar80606872015-08-25 21:27:35 +02003844 && options[i].var != (char_u *)&p_key
Bram Moolenaar5ea87a02015-08-26 23:24:09 +02003845# endif
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01003846 )))
Bram Moolenaar071d4272004-06-13 20:20:40 +00003847 set_option_default(i, opt_flags, p_cp);
3848
Bram Moolenaar071d4272004-06-13 20:20:40 +00003849 /* The 'scroll' option must be computed for all windows. */
Bram Moolenaarf740b292006-02-16 22:11:02 +00003850 FOR_ALL_TAB_WINDOWS(tp, wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003851 win_comp_scroll(wp);
Bram Moolenaar5a4eceb2014-09-09 17:33:07 +02003852#ifdef FEAT_CINDENT
3853 parse_cino(curbuf);
3854#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00003855}
3856
3857/*
3858 * Set the Vi-default value of a string option.
3859 * Used for 'sh', 'backupskip' and 'term'.
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003860 * When "escape" is TRUE escape spaces with a backslash.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003861 */
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003862 static void
3863set_string_default_esc(char *name, char_u *val, int escape)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003864{
3865 char_u *p;
3866 int opt_idx;
3867
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003868 if (escape && vim_strchr(val, ' ') != NULL)
3869 p = vim_strsave_escaped(val, (char_u *)" ");
3870 else
3871 p = vim_strsave(val);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003872 if (p != NULL) /* we don't want a NULL */
3873 {
3874 opt_idx = findoption((char_u *)name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003875 if (opt_idx >= 0)
3876 {
3877 if (options[opt_idx].flags & P_DEF_ALLOCED)
3878 vim_free(options[opt_idx].def_val[VI_DEFAULT]);
3879 options[opt_idx].def_val[VI_DEFAULT] = p;
3880 options[opt_idx].flags |= P_DEF_ALLOCED;
3881 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00003882 }
3883}
3884
Bram Moolenaar4bfa8af2018-02-03 15:14:46 +01003885 void
3886set_string_default(char *name, char_u *val)
3887{
3888 set_string_default_esc(name, val, FALSE);
3889}
3890
Bram Moolenaar071d4272004-06-13 20:20:40 +00003891/*
3892 * Set the Vi-default value of a number option.
3893 * Used for 'lines' and 'columns'.
3894 */
3895 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003896set_number_default(char *name, long val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003897{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003898 int opt_idx;
3899
3900 opt_idx = findoption((char_u *)name);
3901 if (opt_idx >= 0)
Bram Moolenaareb3593b2006-04-22 22:33:57 +00003902 options[opt_idx].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00003903}
3904
Bram Moolenaarcacc6a52019-05-30 15:22:43 +02003905/*
3906 * Set all window-local and buffer-local options to the Vim default.
3907 * local-global options will use the global value.
3908 */
3909 void
3910set_local_options_default(win_T *wp)
3911{
3912 win_T *save_curwin = curwin;
3913 int i;
3914
3915 curwin = wp;
3916 curbuf = curwin->w_buffer;
3917 block_autocmds();
3918
3919 for (i = 0; !istermoption(&options[i]); i++)
3920 {
3921 struct vimoption *p = &(options[i]);
3922 char_u *varp = get_varp_scope(p, OPT_LOCAL);
3923
3924 if (p->indir != PV_NONE
3925 && !(options[i].flags & P_NODEFAULT)
3926 && !optval_default(p, varp, FALSE))
3927 set_option_default(i, OPT_LOCAL, FALSE);
3928 }
3929
3930 unblock_autocmds();
3931 curwin = save_curwin;
3932 curbuf = curwin->w_buffer;
3933}
3934
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003935#if defined(EXITFREE) || defined(PROTO)
3936/*
3937 * Free all options.
3938 */
3939 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003940free_all_options(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003941{
3942 int i;
3943
3944 for (i = 0; !istermoption(&options[i]); i++)
3945 {
3946 if (options[i].indir == PV_NONE)
3947 {
3948 /* global option: free value and default value. */
Bram Moolenaar67391142017-02-19 21:07:04 +01003949 if ((options[i].flags & P_ALLOCED) && options[i].var != NULL)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +00003950 free_string_option(*(char_u **)options[i].var);
3951 if (options[i].flags & P_DEF_ALLOCED)
3952 free_string_option(options[i].def_val[VI_DEFAULT]);
3953 }
3954 else if (options[i].var != VAR_WIN
3955 && (options[i].flags & P_STRING))
3956 /* buffer-local option: free global value */
3957 free_string_option(*(char_u **)options[i].var);
3958 }
3959}
3960#endif
3961
3962
Bram Moolenaar071d4272004-06-13 20:20:40 +00003963/*
3964 * Initialize the options, part two: After getting Rows and Columns and
3965 * setting 'term'.
3966 */
3967 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01003968set_init_2(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00003969{
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003970 int idx;
3971
Bram Moolenaar071d4272004-06-13 20:20:40 +00003972 /*
Bram Moolenaaraf2d20c2017-10-29 15:26:57 +01003973 * 'scroll' defaults to half the window height. The stored default is zero,
3974 * which results in the actual value computed from the window height.
Bram Moolenaar071d4272004-06-13 20:20:40 +00003975 */
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003976 idx = findoption((char_u *)"scroll");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003977 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar26a60b42005-02-22 08:49:11 +00003978 set_option_default(idx, OPT_LOCAL, p_cp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00003979 comp_col();
3980
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003981 /*
3982 * 'window' is only for backwards compatibility with Vi.
3983 * Default is Rows - 1.
3984 */
Bram Moolenaard68071d2006-05-02 22:08:30 +00003985 if (!option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00003986 p_window = Rows - 1;
3987 set_number_default("window", Rows - 1);
3988
Bram Moolenaarf740b292006-02-16 22:11:02 +00003989 /* For DOS console the default is always black. */
Bram Moolenaar4f974752019-02-17 17:44:42 +01003990#if !((defined(MSWIN)) && !defined(FEAT_GUI))
Bram Moolenaarf740b292006-02-16 22:11:02 +00003991 /*
3992 * If 'background' wasn't set by the user, try guessing the value,
3993 * depending on the terminal name. Only need to check for terminals
3994 * with a dark background, that can handle color.
3995 */
3996 idx = findoption((char_u *)"bg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00003997 if (idx >= 0 && !(options[idx].flags & P_WAS_SET)
3998 && *term_bg_default() == 'd')
Bram Moolenaar071d4272004-06-13 20:20:40 +00003999 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004000 set_string_option_direct(NULL, idx, (char_u *)"dark", OPT_FREE, 0);
Bram Moolenaarf740b292006-02-16 22:11:02 +00004001 /* don't mark it as set, when starting the GUI it may be
4002 * changed again */
4003 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004004 }
4005#endif
Bram Moolenaar58d98232005-07-23 22:25:46 +00004006
4007#ifdef CURSOR_SHAPE
4008 parse_shape_opt(SHAPE_CURSOR); /* set cursor shapes from 'guicursor' */
4009#endif
4010#ifdef FEAT_MOUSESHAPE
4011 parse_shape_opt(SHAPE_MOUSE); /* set mouse shapes from 'mouseshape' */
4012#endif
4013#ifdef FEAT_PRINTER
4014 (void)parse_printoptions(); /* parse 'printoptions' default value */
4015#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004016}
4017
4018/*
Bram Moolenaarf740b292006-02-16 22:11:02 +00004019 * Return "dark" or "light" depending on the kind of terminal.
4020 * This is just guessing! Recognized are:
4021 * "linux" Linux console
4022 * "screen.linux" Linux console with screen
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004023 * "cygwin.*" Cygwin shell
4024 * "putty.*" Putty program
Bram Moolenaarf740b292006-02-16 22:11:02 +00004025 * We also check the COLORFGBG environment variable, which is set by
4026 * rxvt and derivatives. This variable contains either two or three
4027 * values separated by semicolons; we want the last value in either
4028 * case. If this value is 0-6 or 8, our background is dark.
4029 */
4030 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004031term_bg_default(void)
Bram Moolenaarf740b292006-02-16 22:11:02 +00004032{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004033#if defined(MSWIN)
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004034 /* DOS console is nearly always black */
Bram Moolenaarf740b292006-02-16 22:11:02 +00004035 return (char_u *)"dark";
4036#else
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00004037 char_u *p;
4038
Bram Moolenaarf740b292006-02-16 22:11:02 +00004039 if (STRCMP(T_NAME, "linux") == 0
4040 || STRCMP(T_NAME, "screen.linux") == 0
Bram Moolenaarc6da01a2017-09-07 22:37:36 +02004041 || STRNCMP(T_NAME, "cygwin", 6) == 0
4042 || STRNCMP(T_NAME, "putty", 5) == 0
Bram Moolenaarf740b292006-02-16 22:11:02 +00004043 || ((p = mch_getenv((char_u *)"COLORFGBG")) != NULL
4044 && (p = vim_strrchr(p, ';')) != NULL
4045 && ((p[1] >= '0' && p[1] <= '6') || p[1] == '8')
4046 && p[2] == NUL))
4047 return (char_u *)"dark";
4048 return (char_u *)"light";
4049#endif
4050}
4051
4052/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00004053 * Initialize the options, part three: After reading the .vimrc
4054 */
4055 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004056set_init_3(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004057{
Bram Moolenaar4f974752019-02-17 17:44:42 +01004058#if defined(UNIX) || defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004059/*
4060 * Set 'shellpipe' and 'shellredir', depending on the 'shell' option.
4061 * This is done after other initializations, where 'shell' might have been
4062 * set, but only if they have not been set before.
4063 */
4064 char_u *p;
4065 int idx_srr;
4066 int do_srr;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004067# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004068 int idx_sp;
4069 int do_sp;
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004070# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004071
4072 idx_srr = findoption((char_u *)"srr");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004073 if (idx_srr < 0)
4074 do_srr = FALSE;
4075 else
4076 do_srr = !(options[idx_srr].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004077# ifdef FEAT_QUICKFIX
Bram Moolenaar071d4272004-06-13 20:20:40 +00004078 idx_sp = findoption((char_u *)"sp");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004079 if (idx_sp < 0)
4080 do_sp = FALSE;
4081 else
4082 do_sp = !(options[idx_sp].flags & P_WAS_SET);
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004083# endif
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004084 p = get_isolated_shell_name();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004085 if (p != NULL)
4086 {
4087 /*
4088 * Default for p_sp is "| tee", for p_srr is ">".
4089 * For known shells it is changed here to include stderr.
4090 */
4091 if ( fnamecmp(p, "csh") == 0
4092 || fnamecmp(p, "tcsh") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004093# if defined(MSWIN) // also check with .exe extension
Bram Moolenaar071d4272004-06-13 20:20:40 +00004094 || fnamecmp(p, "csh.exe") == 0
4095 || fnamecmp(p, "tcsh.exe") == 0
4096# endif
4097 )
4098 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004099# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004100 if (do_sp)
4101 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004102# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004103 p_sp = (char_u *)">&";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004104# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004105 p_sp = (char_u *)"|& tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004106# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004107 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4108 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004109# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004110 if (do_srr)
4111 {
4112 p_srr = (char_u *)">&";
4113 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4114 }
4115 }
4116 else
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004117 /* Always use bourne shell style redirection if we reach this */
Bram Moolenaar071d4272004-06-13 20:20:40 +00004118 if ( fnamecmp(p, "sh") == 0
4119 || fnamecmp(p, "ksh") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004120 || fnamecmp(p, "mksh") == 0
4121 || fnamecmp(p, "pdksh") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004122 || fnamecmp(p, "zsh") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004123 || fnamecmp(p, "zsh-beta") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004124 || fnamecmp(p, "bash") == 0
Bram Moolenaar75a8d742014-05-07 15:10:21 +02004125 || fnamecmp(p, "fish") == 0
Bram Moolenaar4f974752019-02-17 17:44:42 +01004126# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004127 || fnamecmp(p, "cmd") == 0
4128 || fnamecmp(p, "sh.exe") == 0
4129 || fnamecmp(p, "ksh.exe") == 0
Bram Moolenaarf1fda2d2011-04-28 12:57:36 +02004130 || fnamecmp(p, "mksh.exe") == 0
4131 || fnamecmp(p, "pdksh.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004132 || fnamecmp(p, "zsh.exe") == 0
Bram Moolenaarc1e37902006-04-18 21:55:01 +00004133 || fnamecmp(p, "zsh-beta.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004134 || fnamecmp(p, "bash.exe") == 0
4135 || fnamecmp(p, "cmd.exe") == 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00004136# endif
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004137 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00004138 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004139# if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004140 if (do_sp)
4141 {
Bram Moolenaar4f974752019-02-17 17:44:42 +01004142# ifdef MSWIN
Bram Moolenaar071d4272004-06-13 20:20:40 +00004143 p_sp = (char_u *)">%s 2>&1";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004144# else
Bram Moolenaar071d4272004-06-13 20:20:40 +00004145 p_sp = (char_u *)"2>&1| tee";
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004146# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004147 options[idx_sp].def_val[VI_DEFAULT] = p_sp;
4148 }
Bram Moolenaare7fedb62015-12-31 19:07:19 +01004149# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004150 if (do_srr)
4151 {
4152 p_srr = (char_u *)">%s 2>&1";
4153 options[idx_srr].def_val[VI_DEFAULT] = p_srr;
4154 }
4155 }
4156 vim_free(p);
4157 }
4158#endif
4159
Bram Moolenaar4f974752019-02-17 17:44:42 +01004160#if defined(MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004161 /*
Bram Moolenaara64ba222012-02-12 23:23:31 +01004162 * Set 'shellcmdflag', 'shellxquote', and 'shellquote' depending on the
4163 * 'shell' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004164 * This is done after other initializations, where 'shell' might have been
4165 * set, but only if they have not been set before. Default for p_shcf is
4166 * "/c", for p_shq is "". For "sh" like shells it is changed here to
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004167 * "-c" and "\"". And for Win32 we need to set p_sxq instead.
Bram Moolenaar071d4272004-06-13 20:20:40 +00004168 */
Bram Moolenaarf4b8e572004-06-24 15:53:16 +00004169 if (strstr((char *)gettail(p_sh), "sh") != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004170 {
4171 int idx3;
4172
4173 idx3 = findoption((char_u *)"shcf");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004174 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004175 {
4176 p_shcf = (char_u *)"-c";
4177 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4178 }
4179
Bram Moolenaar071d4272004-06-13 20:20:40 +00004180 /* Somehow Win32 requires the quotes around the redirection too */
4181 idx3 = findoption((char_u *)"sxq");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004182 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004183 {
4184 p_sxq = (char_u *)"\"";
4185 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4186 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004187 }
Bram Moolenaara64ba222012-02-12 23:23:31 +01004188 else if (strstr((char *)gettail(p_sh), "cmd.exe") != NULL)
4189 {
4190 int idx3;
4191
4192 /*
4193 * cmd.exe on Windows will strip the first and last double quote given
4194 * on the command line, e.g. most of the time things like:
4195 * cmd /c "my path/to/echo" "my args to echo"
4196 * become:
4197 * my path/to/echo" "my args to echo
4198 * when executed.
4199 *
Bram Moolenaar034b1152012-02-19 18:19:30 +01004200 * To avoid this, set shellxquote to surround the command in
4201 * parenthesis. This appears to make most commands work, without
4202 * breaking commands that worked previously, such as
4203 * '"path with spaces/cmd" "a&b"'.
Bram Moolenaara64ba222012-02-12 23:23:31 +01004204 */
Bram Moolenaara64ba222012-02-12 23:23:31 +01004205 idx3 = findoption((char_u *)"sxq");
4206 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4207 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004208 p_sxq = (char_u *)"(";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004209 options[idx3].def_val[VI_DEFAULT] = p_sxq;
4210 }
4211
Bram Moolenaara64ba222012-02-12 23:23:31 +01004212 idx3 = findoption((char_u *)"shcf");
4213 if (idx3 >= 0 && !(options[idx3].flags & P_WAS_SET))
4214 {
Bram Moolenaar034b1152012-02-19 18:19:30 +01004215 p_shcf = (char_u *)"/c";
Bram Moolenaara64ba222012-02-12 23:23:31 +01004216 options[idx3].def_val[VI_DEFAULT] = p_shcf;
4217 }
4218 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004219#endif
4220
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01004221 if (BUFEMPTY())
Bram Moolenaar364fa5c2016-03-20 17:53:25 +01004222 {
4223 int idx_ffs = findoption((char_u *)"ffs");
4224
4225 /* Apply the first entry of 'fileformats' to the initial buffer. */
4226 if (idx_ffs >= 0 && (options[idx_ffs].flags & P_WAS_SET))
4227 set_fileformat(default_fileformat(), OPT_LOCAL);
4228 }
4229
Bram Moolenaar071d4272004-06-13 20:20:40 +00004230#ifdef FEAT_TITLE
4231 set_title_defaults();
4232#endif
4233}
4234
4235#if defined(FEAT_MULTI_LANG) || defined(PROTO)
4236/*
4237 * When 'helplang' is still at its default value, set it to "lang".
4238 * Only the first two characters of "lang" are used.
4239 */
4240 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004241set_helplang_default(char_u *lang)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004242{
4243 int idx;
4244
4245 if (lang == NULL || STRLEN(lang) < 2) /* safety check */
4246 return;
4247 idx = findoption((char_u *)"hlg");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004248 if (idx >= 0 && !(options[idx].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004249 {
4250 if (options[idx].flags & P_ALLOCED)
4251 free_string_option(p_hlg);
4252 p_hlg = vim_strsave(lang);
4253 if (p_hlg == NULL)
4254 p_hlg = empty_option;
4255 else
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004256 {
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004257 // zh_CN becomes "cn", zh_TW becomes "tw"
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004258 if (STRNICMP(p_hlg, "zh_", 3) == 0 && STRLEN(p_hlg) >= 5)
4259 {
4260 p_hlg[0] = TOLOWER_ASC(p_hlg[3]);
4261 p_hlg[1] = TOLOWER_ASC(p_hlg[4]);
4262 }
Bram Moolenaardcd71cb2018-11-04 14:40:47 +01004263 // any C like setting, such as C.UTF-8, becomes "en"
4264 else if (STRLEN(p_hlg) >= 1 && *p_hlg == 'C')
4265 {
4266 p_hlg[0] = 'e';
4267 p_hlg[1] = 'n';
4268 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004269 p_hlg[2] = NUL;
Bram Moolenaarab79bcb2004-07-18 21:34:53 +00004270 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004271 options[idx].flags |= P_ALLOCED;
4272 }
4273}
4274#endif
4275
4276#ifdef FEAT_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00004277 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01004278gui_bg_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004279{
4280 if (gui_get_lightness(gui.back_pixel) < 127)
4281 return (char_u *)"dark";
4282 return (char_u *)"light";
4283}
4284
4285/*
4286 * Option initializations that can only be done after opening the GUI window.
4287 */
4288 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004289init_gui_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004290{
4291 /* Set the 'background' option according to the lightness of the
4292 * background color, unless the user has set it already. */
4293 if (!option_was_set((char_u *)"bg") && STRCMP(p_bg, gui_bg_default()) != 0)
4294 {
4295 set_option_value((char_u *)"bg", 0L, gui_bg_default(), 0);
4296 highlight_changed();
4297 }
4298}
4299#endif
4300
4301#ifdef FEAT_TITLE
4302/*
4303 * 'title' and 'icon' only default to true if they have not been set or reset
4304 * in .vimrc and we can read the old value.
4305 * When 'title' and 'icon' have been reset in .vimrc, we won't even check if
4306 * they can be reset. This reduces startup time when using X on a remote
4307 * machine.
4308 */
4309 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01004310set_title_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004311{
4312 int idx1;
4313 long val;
4314
4315 /*
4316 * If GUI is (going to be) used, we can always set the window title and
4317 * icon name. Saves a bit of time, because the X11 display server does
4318 * not need to be contacted.
4319 */
4320 idx1 = findoption((char_u *)"title");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004321 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004322 {
4323#ifdef FEAT_GUI
4324 if (gui.starting || gui.in_use)
4325 val = TRUE;
4326 else
4327#endif
4328 val = mch_can_restore_title();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004329 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004330 p_title = val;
4331 }
4332 idx1 = findoption((char_u *)"icon");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +00004333 if (idx1 >= 0 && !(options[idx1].flags & P_WAS_SET))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004334 {
4335#ifdef FEAT_GUI
4336 if (gui.starting || gui.in_use)
4337 val = TRUE;
4338 else
4339#endif
4340 val = mch_can_restore_icon();
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004341 options[idx1].def_val[VI_DEFAULT] = (char_u *)(long_i)val;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004342 p_icon = val;
4343 }
4344}
4345#endif
4346
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004347#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02004348/*
4349 * Trigger the OptionSet autocommand.
4350 * "opt_idx" is the index of the option being set.
4351 * "opt_flags" can be OPT_LOCAL etc.
4352 * "oldval" the old value
4353 * "oldval_l" the old local value (only non-NULL if global and local value
4354 * are set)
4355 * "oldval_g" the old global value (only non-NULL if global and local value
4356 * are set)
4357 * "newval" the new value
4358 */
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004359 static void
4360trigger_optionsset_string(
4361 int opt_idx,
4362 int opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02004363 char_u *oldval,
4364 char_u *oldval_l,
4365 char_u *oldval_g,
4366 char_u *newval)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004367{
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02004368 // Don't do this recursively.
4369 if (oldval != NULL && newval != NULL
4370 && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004371 {
4372 char_u buf_type[7];
4373
4374 sprintf((char *)buf_type, "%s",
4375 (opt_flags & OPT_LOCAL) ? "local" : "global");
4376 set_vim_var_string(VV_OPTION_OLD, oldval, -1);
4377 set_vim_var_string(VV_OPTION_NEW, newval, -1);
4378 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02004379 if (opt_flags & OPT_LOCAL)
4380 {
4381 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
4382 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4383 }
4384 if (opt_flags & OPT_GLOBAL)
4385 {
4386 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
4387 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval, -1);
4388 }
4389 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4390 {
4391 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
4392 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval_l, -1);
4393 set_vim_var_string(VV_OPTION_OLDGLOBAL, oldval_g, -1);
4394 }
4395 if (opt_flags & OPT_MODELINE)
4396 {
4397 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
4398 set_vim_var_string(VV_OPTION_OLDLOCAL, oldval, -1);
4399 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004400 apply_autocmds(EVENT_OPTIONSET,
4401 (char_u *)options[opt_idx].fullname, NULL, FALSE, NULL);
4402 reset_v_option_vars();
4403 }
Bram Moolenaar182a17b2017-06-25 20:57:18 +02004404}
4405#endif
4406
Bram Moolenaar071d4272004-06-13 20:20:40 +00004407/*
4408 * Parse 'arg' for option settings.
4409 *
4410 * 'arg' may be IObuff, but only when no errors can be present and option
4411 * does not need to be expanded with option_expand().
4412 * "opt_flags":
4413 * 0 for ":set"
Bram Moolenaara3227e22006-03-08 21:32:40 +00004414 * OPT_GLOBAL for ":setglobal"
4415 * OPT_LOCAL for ":setlocal" and a modeline
Bram Moolenaar071d4272004-06-13 20:20:40 +00004416 * OPT_MODELINE for a modeline
Bram Moolenaara3227e22006-03-08 21:32:40 +00004417 * OPT_WINONLY to only set window-local options
4418 * OPT_NOWIN to skip setting window-local options
Bram Moolenaar071d4272004-06-13 20:20:40 +00004419 *
4420 * returns FAIL if an error is detected, OK otherwise
4421 */
4422 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01004423do_set(
4424 char_u *arg, /* option string (may be written to!) */
4425 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004426{
4427 int opt_idx;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004428 char *errmsg;
4429 char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00004430 char_u *startarg;
4431 int prefix; /* 1: nothing, 0: "no", 2: "inv" in front of name */
4432 int nextchar; /* next non-white char after option name */
4433 int afterchar; /* character just after option name */
4434 int len;
4435 int i;
Bram Moolenaar22fcfad2016-07-01 18:17:26 +02004436 varnumber_T value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004437 int key;
4438 long_u flags; /* flags for current option */
4439 char_u *varp = NULL; /* pointer to variable for current option */
4440 int did_show = FALSE; /* already showed one value */
4441 int adding; /* "opt+=arg" */
4442 int prepending; /* "opt^=arg" */
4443 int removing; /* "opt-=arg" */
4444 int cp_val = 0;
4445 char_u key_name[2];
4446
4447 if (*arg == NUL)
4448 {
4449 showoptions(0, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004450 did_show = TRUE;
4451 goto theend;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004452 }
4453
4454 while (*arg != NUL) /* loop to process all options */
4455 {
4456 errmsg = NULL;
4457 startarg = arg; /* remember for error message */
4458
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004459 if (STRNCMP(arg, "all", 3) == 0 && !isalpha(arg[3])
4460 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004461 {
4462 /*
4463 * ":set all" show all options.
4464 * ":set all&" set all options to their default value.
4465 */
4466 arg += 3;
4467 if (*arg == '&')
4468 {
4469 ++arg;
4470 /* Only for :set command set global value of local options. */
4471 set_options_default(OPT_FREE | opt_flags);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02004472 didset_options();
4473 didset_options2();
Bram Moolenaarb341dda2015-08-25 12:56:31 +02004474 redraw_all_later(CLEAR);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004475 }
4476 else
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004477 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004478 showoptions(1, opt_flags);
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004479 did_show = TRUE;
4480 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004481 }
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00004482 else if (STRNCMP(arg, "termcap", 7) == 0 && !(opt_flags & OPT_MODELINE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004483 {
4484 showoptions(2, opt_flags);
4485 show_termcodes();
Bram Moolenaar26a60b42005-02-22 08:49:11 +00004486 did_show = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004487 arg += 7;
4488 }
4489 else
4490 {
4491 prefix = 1;
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +00004492 if (STRNCMP(arg, "no", 2) == 0 && STRNCMP(arg, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004493 {
4494 prefix = 0;
4495 arg += 2;
4496 }
4497 else if (STRNCMP(arg, "inv", 3) == 0)
4498 {
4499 prefix = 2;
4500 arg += 3;
4501 }
4502
4503 /* find end of name */
4504 key = 0;
4505 if (*arg == '<')
4506 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00004507 opt_idx = -1;
4508 /* look out for <t_>;> */
4509 if (arg[1] == 't' && arg[2] == '_' && arg[3] && arg[4])
4510 len = 5;
4511 else
4512 {
4513 len = 1;
4514 while (arg[len] != NUL && arg[len] != '>')
4515 ++len;
4516 }
4517 if (arg[len] != '>')
4518 {
4519 errmsg = e_invarg;
4520 goto skip;
4521 }
4522 arg[len] = NUL; /* put NUL after name */
4523 if (arg[1] == 't' && arg[2] == '_') /* could be term code */
4524 opt_idx = findoption(arg + 1);
4525 arg[len++] = '>'; /* restore '>' */
4526 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004527 key = find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004528 }
4529 else
4530 {
4531 len = 0;
4532 /*
4533 * The two characters after "t_" may not be alphanumeric.
4534 */
4535 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
4536 len = 4;
4537 else
4538 while (ASCII_ISALNUM(arg[len]) || arg[len] == '_')
4539 ++len;
4540 nextchar = arg[len];
4541 arg[len] = NUL; /* put NUL after name */
4542 opt_idx = findoption(arg);
4543 arg[len] = nextchar; /* restore nextchar */
4544 if (opt_idx == -1)
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02004545 key = find_key_option(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004546 }
4547
4548 /* remember character after option name */
4549 afterchar = arg[len];
4550
4551 /* skip white space, allow ":set ai ?" */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004552 while (VIM_ISWHITE(arg[len]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004553 ++len;
4554
4555 adding = FALSE;
4556 prepending = FALSE;
4557 removing = FALSE;
4558 if (arg[len] != NUL && arg[len + 1] == '=')
4559 {
4560 if (arg[len] == '+')
4561 {
4562 adding = TRUE; /* "+=" */
4563 ++len;
4564 }
4565 else if (arg[len] == '^')
4566 {
4567 prepending = TRUE; /* "^=" */
4568 ++len;
4569 }
4570 else if (arg[len] == '-')
4571 {
4572 removing = TRUE; /* "-=" */
4573 ++len;
4574 }
4575 }
4576 nextchar = arg[len];
4577
4578 if (opt_idx == -1 && key == 0) /* found a mismatch: skip */
4579 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004580 errmsg = N_("E518: Unknown option");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004581 goto skip;
4582 }
4583
4584 if (opt_idx >= 0)
4585 {
4586 if (options[opt_idx].var == NULL) /* hidden option: skip */
4587 {
4588 /* Only give an error message when requesting the value of
4589 * a hidden option, ignore setting it. */
4590 if (vim_strchr((char_u *)"=:!&<", nextchar) == NULL
4591 && (!(options[opt_idx].flags & P_BOOL)
4592 || nextchar == '?'))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004593 errmsg = N_("E519: Option not supported");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004594 goto skip;
4595 }
4596
4597 flags = options[opt_idx].flags;
4598 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
4599 }
4600 else
4601 {
4602 flags = P_STRING;
4603 if (key < 0)
4604 {
4605 key_name[0] = KEY2TERMCAP0(key);
4606 key_name[1] = KEY2TERMCAP1(key);
4607 }
4608 else
4609 {
4610 key_name[0] = KS_KEY;
4611 key_name[1] = (key & 0xff);
4612 }
4613 }
4614
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004615 /* Skip all options that are not window-local (used when showing
4616 * an already loaded buffer in a window). */
4617 if ((opt_flags & OPT_WINONLY)
4618 && (opt_idx < 0 || options[opt_idx].var != VAR_WIN))
4619 goto skip;
4620
Bram Moolenaara3227e22006-03-08 21:32:40 +00004621 /* Skip all options that are window-local (used for :vimgrep). */
4622 if ((opt_flags & OPT_NOWIN) && opt_idx >= 0
4623 && options[opt_idx].var == VAR_WIN)
4624 goto skip;
4625
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004626 /* Disallow changing some options from modelines. */
4627 if (opt_flags & OPT_MODELINE)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004628 {
Bram Moolenaar865242e2010-07-14 21:12:05 +02004629 if (flags & (P_SECURE | P_NO_ML))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004630 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004631 errmsg = _("E520: Not allowed in a modeline");
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004632 goto skip;
4633 }
Bram Moolenaar110289e2019-05-23 15:38:06 +02004634 if ((flags & P_MLE) && !p_mle)
4635 {
4636 errmsg = _("E992: Not allowed in a modeline when 'modelineexpr' is off");
4637 goto skip;
4638 }
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004639#ifdef FEAT_DIFF
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004640 /* In diff mode some options are overruled. This avoids that
4641 * 'foldmethod' becomes "marker" instead of "diff" and that
4642 * "wrap" gets set. */
4643 if (curwin->w_p_diff
Bram Moolenaara9d52e32010-07-31 16:44:19 +02004644 && opt_idx >= 0 /* shut up coverity warning */
Bram Moolenaara6c07602017-03-05 21:18:27 +01004645 && (
4646#ifdef FEAT_FOLDING
4647 options[opt_idx].indir == PV_FDM ||
4648#endif
4649 options[opt_idx].indir == PV_WRAP))
Bram Moolenaar1bf0ddc2009-02-11 15:47:05 +00004650 goto skip;
Bram Moolenaarf69d9a32009-02-11 21:48:40 +00004651#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00004652 }
4653
4654#ifdef HAVE_SANDBOX
4655 /* Disallow changing some options in the sandbox */
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00004656 if (sandbox != 0 && (flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004657 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004658 errmsg = _(e_sandbox);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004659 goto skip;
4660 }
4661#endif
4662
4663 if (vim_strchr((char_u *)"?=:!&<", nextchar) != NULL)
4664 {
4665 arg += len;
4666 cp_val = p_cp;
4667 if (nextchar == '&' && arg[1] == 'v' && arg[2] == 'i')
4668 {
4669 if (arg[3] == 'm') /* "opt&vim": set to Vim default */
4670 {
4671 cp_val = FALSE;
4672 arg += 3;
4673 }
4674 else /* "opt&vi": set to Vi default */
4675 {
4676 cp_val = TRUE;
4677 arg += 2;
4678 }
4679 }
4680 if (vim_strchr((char_u *)"?!&<", nextchar) != NULL
Bram Moolenaar1c465442017-03-12 20:10:05 +01004681 && arg[1] != NUL && !VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004682 {
4683 errmsg = e_trailing;
4684 goto skip;
4685 }
4686 }
4687
4688 /*
Bram Moolenaar48e330a2016-02-23 14:53:34 +01004689 * allow '=' and ':' for hystorical reasons (MSDOS command.com
4690 * allows only one '=' character per "set" command line. grrr. (jw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00004691 */
4692 if (nextchar == '?'
4693 || (prefix == 1
4694 && vim_strchr((char_u *)"=:&<", nextchar) == NULL
4695 && !(flags & P_BOOL)))
4696 {
4697 /*
4698 * print value
4699 */
4700 if (did_show)
4701 msg_putchar('\n'); /* cursor below last one */
4702 else
4703 {
4704 gotocmdline(TRUE); /* cursor at status line */
4705 did_show = TRUE; /* remember that we did a line */
4706 }
4707 if (opt_idx >= 0)
4708 {
4709 showoneopt(&options[opt_idx], opt_flags);
4710#ifdef FEAT_EVAL
4711 if (p_verbose > 0)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004712 {
4713 /* Mention where the option was last set. */
4714 if (varp == options[opt_idx].var)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004715 last_set_msg(options[opt_idx].script_ctx);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004716 else if ((int)options[opt_idx].indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004717 last_set_msg(curwin->w_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004718 (int)options[opt_idx].indir & PV_MASK]);
4719 else if ((int)options[opt_idx].indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02004720 last_set_msg(curbuf->b_p_script_ctx[
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00004721 (int)options[opt_idx].indir & PV_MASK]);
4722 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004723#endif
4724 }
4725 else
4726 {
4727 char_u *p;
4728
4729 p = find_termcode(key_name);
4730 if (p == NULL)
4731 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004732 errmsg = N_("E846: Key code not set");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004733 goto skip;
4734 }
4735 else
4736 (void)show_one_termcode(key_name, p, TRUE);
4737 }
4738 if (nextchar != '?'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004739 && nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004740 errmsg = e_trailing;
4741 }
4742 else
4743 {
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004744 int value_is_replaced = !prepending && !adding && !removing;
Bram Moolenaar916a8182018-11-25 02:18:29 +01004745 int value_checked = FALSE;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01004746
Bram Moolenaar071d4272004-06-13 20:20:40 +00004747 if (flags & P_BOOL) /* boolean */
4748 {
4749 if (nextchar == '=' || nextchar == ':')
4750 {
4751 errmsg = e_invarg;
4752 goto skip;
4753 }
4754
4755 /*
4756 * ":set opt!": invert
4757 * ":set opt&": reset to default value
4758 * ":set opt<": reset to global value
4759 */
4760 if (nextchar == '!')
4761 value = *(int *)(varp) ^ 1;
4762 else if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004763 value = (int)(long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004764 ((flags & P_VI_DEF) || cp_val)
4765 ? VI_DEFAULT : VIM_DEFAULT];
4766 else if (nextchar == '<')
4767 {
4768 /* For 'autoread' -1 means to use global value. */
4769 if ((int *)varp == &curbuf->b_p_ar
4770 && opt_flags == OPT_LOCAL)
4771 value = -1;
4772 else
4773 value = *(int *)get_varp_scope(&(options[opt_idx]),
4774 OPT_GLOBAL);
4775 }
4776 else
4777 {
4778 /*
4779 * ":set invopt": invert
4780 * ":set opt" or ":set noopt": set or reset
4781 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01004782 if (nextchar != NUL && !VIM_ISWHITE(afterchar))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004783 {
4784 errmsg = e_trailing;
4785 goto skip;
4786 }
4787 if (prefix == 2) /* inv */
4788 value = *(int *)(varp) ^ 1;
4789 else
4790 value = prefix;
4791 }
4792
4793 errmsg = set_bool_option(opt_idx, varp, (int)value,
4794 opt_flags);
4795 }
4796 else /* numeric or string */
4797 {
4798 if (vim_strchr((char_u *)"=:&<", nextchar) == NULL
4799 || prefix != 1)
4800 {
4801 errmsg = e_invarg;
4802 goto skip;
4803 }
4804
4805 if (flags & P_NUM) /* numeric */
4806 {
4807 /*
4808 * Different ways to set a number option:
4809 * & set to default value
4810 * < set to global value
4811 * <xx> accept special key codes for 'wildchar'
4812 * c accept any non-digit for 'wildchar'
4813 * [-]0-9 set number
4814 * other error
4815 */
4816 ++arg;
4817 if (nextchar == '&')
Bram Moolenaareb3593b2006-04-22 22:33:57 +00004818 value = (long)(long_i)options[opt_idx].def_val[
Bram Moolenaar071d4272004-06-13 20:20:40 +00004819 ((flags & P_VI_DEF) || cp_val)
4820 ? VI_DEFAULT : VIM_DEFAULT];
4821 else if (nextchar == '<')
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01004822 {
4823 /* For 'undolevels' NO_LOCAL_UNDOLEVEL means to
4824 * use the global value. */
4825 if ((long *)varp == &curbuf->b_p_ul
4826 && opt_flags == OPT_LOCAL)
4827 value = NO_LOCAL_UNDOLEVEL;
4828 else
4829 value = *(long *)get_varp_scope(
4830 &(options[opt_idx]), OPT_GLOBAL);
4831 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004832 else if (((long *)varp == &p_wc
4833 || (long *)varp == &p_wcm)
4834 && (*arg == '<'
4835 || *arg == '^'
Bram Moolenaar1c465442017-03-12 20:10:05 +01004836 || (*arg != NUL
4837 && (!arg[1] || VIM_ISWHITE(arg[1]))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004838 && !VIM_ISDIGIT(*arg))))
4839 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02004840 value = string_to_key(arg, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004841 if (value == 0 && (long *)varp != &p_wcm)
4842 {
4843 errmsg = e_invarg;
4844 goto skip;
4845 }
4846 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00004847 else if (*arg == '-' || VIM_ISDIGIT(*arg))
4848 {
Bram Moolenaar18400e62015-01-27 15:58:40 +01004849 /* Allow negative (for 'undolevels'), octal and
4850 * hex numbers. */
Bram Moolenaar887c1fe2016-01-02 17:56:35 +01004851 vim_str2nr(arg, NULL, &i, STR2NR_ALL,
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004852 &value, NULL, 0, TRUE);
Bram Moolenaar06e2c812019-06-12 19:05:48 +02004853 if (i == 0 || (arg[i] != NUL
4854 && !VIM_ISWHITE(arg[i])))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004855 {
Bram Moolenaar16e9b852019-05-19 19:59:35 +02004856 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004857 goto skip;
4858 }
4859 }
4860 else
4861 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004862 errmsg = N_("E521: Number required after =");
Bram Moolenaar071d4272004-06-13 20:20:40 +00004863 goto skip;
4864 }
4865
4866 if (adding)
4867 value = *(long *)varp + value;
4868 if (prepending)
4869 value = *(long *)varp * value;
4870 if (removing)
4871 value = *(long *)varp - value;
4872 errmsg = set_num_option(opt_idx, varp, value,
Bram Moolenaar555b2802005-05-19 21:08:39 +00004873 errbuf, sizeof(errbuf), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00004874 }
4875 else if (opt_idx >= 0) /* string */
4876 {
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004877 char_u *save_arg = NULL;
4878 char_u *s = NULL;
4879 char_u *oldval = NULL; /* previous value if *varp */
4880 char_u *newval;
4881 char_u *origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004882 char_u *origval_l = NULL;
4883 char_u *origval_g = NULL;
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01004884#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004885 char_u *saved_origval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02004886 char_u *saved_origval_l = NULL;
4887 char_u *saved_origval_g = NULL;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004888 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02004889#endif
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004890 unsigned newlen;
4891 int comma;
4892 int bs;
4893 int new_value_alloced; /* new string option
Bram Moolenaar071d4272004-06-13 20:20:40 +00004894 was allocated */
4895
4896 /* When using ":set opt=val" for a global option
4897 * with a local value the local value will be
4898 * reset, use the global value here. */
4899 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00004900 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00004901 varp = options[opt_idx].var;
4902
4903 /* The old value is kept until we are sure that the
4904 * new value is valid. */
4905 oldval = *(char_u **)varp;
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004906
Bram Moolenaard7c96872019-06-15 17:12:48 +02004907 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
4908 {
4909 origval_l = *(char_u **)get_varp_scope(
4910 &(options[opt_idx]), OPT_LOCAL);
4911 origval_g = *(char_u **)get_varp_scope(
4912 &(options[opt_idx]), OPT_GLOBAL);
4913
4914 // A global-local string option might have an empty
4915 // option as value to indicate that the global
4916 // value should be used.
4917 if (((int)options[opt_idx].indir & PV_BOTH)
4918 && origval_l == empty_option)
4919 origval_l = origval_g;
4920 }
4921
4922 // When setting the local value of a global
4923 // option, the old value may be the global value.
Bram Moolenaar8efa0262017-08-20 15:47:20 +02004924 if (((int)options[opt_idx].indir & PV_BOTH)
4925 && (opt_flags & OPT_LOCAL))
4926 origval = *(char_u **)get_varp(
4927 &options[opt_idx]);
4928 else
4929 origval = oldval;
4930
Bram Moolenaar071d4272004-06-13 20:20:40 +00004931 if (nextchar == '&') /* set to default val */
4932 {
4933 newval = options[opt_idx].def_val[
4934 ((flags & P_VI_DEF) || cp_val)
4935 ? VI_DEFAULT : VIM_DEFAULT];
4936 if ((char_u **)varp == &p_bg)
4937 {
4938 /* guess the value of 'background' */
4939#ifdef FEAT_GUI
4940 if (gui.in_use)
4941 newval = gui_bg_default();
4942 else
4943#endif
Bram Moolenaarf740b292006-02-16 22:11:02 +00004944 newval = term_bg_default();
Bram Moolenaar071d4272004-06-13 20:20:40 +00004945 }
4946
4947 /* expand environment variables and ~ (since the
4948 * default value was already expanded, only
4949 * required when an environment variable was set
4950 * later */
4951 if (newval == NULL)
4952 newval = empty_option;
4953 else
4954 {
4955 s = option_expand(opt_idx, newval);
4956 if (s == NULL)
4957 s = newval;
4958 newval = vim_strsave(s);
4959 }
4960 new_value_alloced = TRUE;
4961 }
4962 else if (nextchar == '<') /* set to global val */
4963 {
4964 newval = vim_strsave(*(char_u **)get_varp_scope(
4965 &(options[opt_idx]), OPT_GLOBAL));
4966 new_value_alloced = TRUE;
4967 }
4968 else
4969 {
4970 ++arg; /* jump to after the '=' or ':' */
4971
4972 /*
4973 * Set 'keywordprg' to ":help" if an empty
4974 * value was passed to :set by the user.
4975 * Misuse errbuf[] for the resulting string.
4976 */
4977 if (varp == (char_u *)&p_kp
4978 && (*arg == NUL || *arg == ' '))
4979 {
4980 STRCPY(errbuf, ":help");
4981 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01004982 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00004983 }
4984 /*
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01004985 * Convert 'backspace' number to string, for
4986 * adding, prepending and removing string.
4987 */
4988 else if (varp == (char_u *)&p_bs
4989 && VIM_ISDIGIT(**(char_u **)varp))
4990 {
4991 i = getdigits((char_u **)varp);
4992 switch (i)
4993 {
4994 case 0:
4995 *(char_u **)varp = empty_option;
4996 break;
4997 case 1:
4998 *(char_u **)varp = vim_strsave(
4999 (char_u *)"indent,eol");
5000 break;
5001 case 2:
5002 *(char_u **)varp = vim_strsave(
5003 (char_u *)"indent,eol,start");
5004 break;
5005 }
5006 vim_free(oldval);
Bram Moolenaaredbc0d42017-08-20 16:11:51 +02005007 if (origval == oldval)
5008 origval = *(char_u **)varp;
Bram Moolenaard7c96872019-06-15 17:12:48 +02005009 if (origval_l == oldval)
5010 origval_l = *(char_u **)varp;
5011 if (origval_g == oldval)
5012 origval_g = *(char_u **)varp;
Bram Moolenaar4e5ccfa2011-11-30 11:15:47 +01005013 oldval = *(char_u **)varp;
5014 }
5015 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +00005016 * Convert 'whichwrap' number to string, for
5017 * backwards compatibility with Vim 3.0.
5018 * Misuse errbuf[] for the resulting string.
5019 */
5020 else if (varp == (char_u *)&p_ww
5021 && VIM_ISDIGIT(*arg))
5022 {
5023 *errbuf = NUL;
5024 i = getdigits(&arg);
5025 if (i & 1)
5026 STRCAT(errbuf, "b,");
5027 if (i & 2)
5028 STRCAT(errbuf, "s,");
5029 if (i & 4)
5030 STRCAT(errbuf, "h,l,");
5031 if (i & 8)
5032 STRCAT(errbuf, "<,>,");
5033 if (i & 16)
5034 STRCAT(errbuf, "[,],");
5035 if (*errbuf != NUL) /* remove trailing , */
5036 errbuf[STRLEN(errbuf) - 1] = NUL;
5037 save_arg = arg;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005038 arg = (char_u *)errbuf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005039 }
5040 /*
5041 * Remove '>' before 'dir' and 'bdir', for
5042 * backwards compatibility with version 3.0
5043 */
5044 else if ( *arg == '>'
5045 && (varp == (char_u *)&p_dir
5046 || varp == (char_u *)&p_bdir))
5047 {
5048 ++arg;
5049 }
5050
Bram Moolenaar071d4272004-06-13 20:20:40 +00005051 /*
5052 * Copy the new string into allocated memory.
5053 * Can't use set_string_option_direct(), because
5054 * we need to remove the backslashes.
5055 */
5056 /* get a bit too much */
5057 newlen = (unsigned)STRLEN(arg) + 1;
5058 if (adding || prepending || removing)
5059 newlen += (unsigned)STRLEN(origval) + 1;
5060 newval = alloc(newlen);
5061 if (newval == NULL) /* out of mem, don't change */
5062 break;
5063 s = newval;
5064
5065 /*
5066 * Copy the string, skip over escaped chars.
5067 * For MS-DOS and WIN32 backslashes before normal
5068 * file name characters are not removed, and keep
5069 * backslash at start, for "\\machine\path", but
5070 * do remove it for "\\\\machine\\path".
5071 * The reverse is found in ExpandOldSetting().
5072 */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005073 while (*arg && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005074 {
5075 if (*arg == '\\' && arg[1] != NUL
5076#ifdef BACKSLASH_IN_FILENAME
5077 && !((flags & P_EXPAND)
5078 && vim_isfilec(arg[1])
5079 && (arg[1] != '\\'
5080 || (s == newval
5081 && arg[2] != '\\')))
5082#endif
5083 )
5084 ++arg; /* remove backslash */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005085 if (has_mbyte
Bram Moolenaar0fa313a2005-08-10 21:07:57 +00005086 && (i = (*mb_ptr2len)(arg)) > 1)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005087 {
5088 /* copy multibyte char */
5089 mch_memmove(s, arg, (size_t)i);
5090 arg += i;
5091 s += i;
5092 }
5093 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00005094 *s++ = *arg++;
5095 }
5096 *s = NUL;
5097
5098 /*
5099 * Expand environment variables and ~.
5100 * Don't do it when adding without inserting a
5101 * comma.
5102 */
5103 if (!(adding || prepending || removing)
5104 || (flags & P_COMMA))
5105 {
5106 s = option_expand(opt_idx, newval);
5107 if (s != NULL)
5108 {
5109 vim_free(newval);
5110 newlen = (unsigned)STRLEN(s) + 1;
5111 if (adding || prepending || removing)
5112 newlen += (unsigned)STRLEN(origval) + 1;
5113 newval = alloc(newlen);
5114 if (newval == NULL)
5115 break;
5116 STRCPY(newval, s);
5117 }
5118 }
5119
5120 /* locate newval[] in origval[] when removing it
5121 * and when adding to avoid duplicates */
5122 i = 0; /* init for GCC */
5123 if (removing || (flags & P_NODUP))
5124 {
5125 i = (int)STRLEN(newval);
5126 bs = 0;
5127 for (s = origval; *s; ++s)
5128 {
5129 if ((!(flags & P_COMMA)
5130 || s == origval
5131 || (s[-1] == ',' && !(bs & 1)))
5132 && STRNCMP(s, newval, i) == 0
5133 && (!(flags & P_COMMA)
5134 || s[i] == ','
5135 || s[i] == NUL))
5136 break;
Bram Moolenaar0b2f94d2011-03-22 14:35:05 +01005137 /* Count backslashes. Only a comma with an
Bram Moolenaar8f79acd2016-01-01 14:48:20 +01005138 * even number of backslashes or a single
5139 * backslash preceded by a comma before it
5140 * is recognized as a separator */
5141 if ((s > origval + 1
5142 && s[-1] == '\\'
5143 && s[-2] != ',')
5144 || (s == origval + 1
5145 && s[-1] == '\\'))
5146
Bram Moolenaar071d4272004-06-13 20:20:40 +00005147 ++bs;
5148 else
5149 bs = 0;
5150 }
5151
5152 /* do not add if already there */
5153 if ((adding || prepending) && *s)
5154 {
5155 prepending = FALSE;
5156 adding = FALSE;
5157 STRCPY(newval, origval);
5158 }
5159 }
5160
5161 /* concatenate the two strings; add a ',' if
5162 * needed */
5163 if (adding || prepending)
5164 {
5165 comma = ((flags & P_COMMA) && *origval != NUL
5166 && *newval != NUL);
5167 if (adding)
5168 {
5169 i = (int)STRLEN(origval);
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005170 /* strip a trailing comma, would get 2 */
Bram Moolenaar17467472015-11-10 17:50:24 +01005171 if (comma && i > 1
5172 && (flags & P_ONECOMMA) == P_ONECOMMA
5173 && origval[i - 1] == ','
5174 && origval[i - 2] != '\\')
Bram Moolenaara7b7b1c2015-06-19 14:06:43 +02005175 i--;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005176 mch_memmove(newval + i + comma, newval,
5177 STRLEN(newval) + 1);
5178 mch_memmove(newval, origval, (size_t)i);
5179 }
5180 else
5181 {
5182 i = (int)STRLEN(newval);
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005183 STRMOVE(newval + i + comma, origval);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005184 }
5185 if (comma)
5186 newval[i] = ',';
5187 }
5188
5189 /* Remove newval[] from origval[]. (Note: "i" has
5190 * been set above and is used here). */
5191 if (removing)
5192 {
5193 STRCPY(newval, origval);
5194 if (*s)
5195 {
5196 /* may need to remove a comma */
5197 if (flags & P_COMMA)
5198 {
5199 if (s == origval)
5200 {
5201 /* include comma after string */
5202 if (s[i] == ',')
5203 ++i;
5204 }
5205 else
5206 {
5207 /* include comma before string */
5208 --s;
5209 ++i;
5210 }
5211 }
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00005212 STRMOVE(newval + (s - origval), s + i);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005213 }
5214 }
5215
5216 if (flags & P_FLAGLIST)
5217 {
5218 /* Remove flags that appear twice. */
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005219 for (s = newval; *s;)
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005220 {
5221 /* if options have P_FLAGLIST and
5222 * P_ONECOMMA such as 'whichwrap' */
5223 if (flags & P_ONECOMMA)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005224 {
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005225 if (*s != ',' && *(s + 1) == ','
5226 && vim_strchr(s + 2, *s) != NULL)
5227 {
5228 /* Remove the duplicated value and
5229 * the next comma. */
5230 STRMOVE(s, s + 2);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005231 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005232 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005233 }
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005234 else
5235 {
5236 if ((!(flags & P_COMMA) || *s != ',')
5237 && vim_strchr(s + 1, *s) != NULL)
5238 {
5239 STRMOVE(s, s + 1);
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005240 continue;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005241 }
5242 }
Bram Moolenaaraaaf57d2017-02-05 14:13:20 +01005243 ++s;
Bram Moolenaarc8ce6152016-08-07 13:48:20 +02005244 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005245 }
5246
5247 if (save_arg != NULL) /* number for 'whichwrap' */
5248 arg = save_arg;
5249 new_value_alloced = TRUE;
5250 }
5251
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005252 /*
5253 * Set the new value.
5254 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005255 *(char_u **)(varp) = newval;
5256
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005257#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02005258 if (!starting
5259# ifdef FEAT_CRYPT
5260 && options[opt_idx].indir != PV_KEY
5261# endif
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005262 && origval != NULL && newval != NULL)
5263 {
Bram Moolenaar53744302015-07-17 17:38:22 +02005264 /* origval may be freed by
5265 * did_set_string_option(), make a copy. */
5266 saved_origval = vim_strsave(origval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005267 /* newval (and varp) may become invalid if the
5268 * buffer is closed by autocommands. */
5269 saved_newval = vim_strsave(newval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005270 if (origval_l != NULL)
5271 saved_origval_l = vim_strsave(origval_l);
5272 if (origval_g != NULL)
5273 saved_origval_g = vim_strsave(origval_g);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02005274 }
Bram Moolenaar53744302015-07-17 17:38:22 +02005275#endif
5276
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005277 {
5278 long_u *p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005279 int secure_saved = secure;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005280
5281 // When an option is set in the sandbox, from a
5282 // modeline or in secure mode, then deal with side
5283 // effects in secure mode. Also when the value was
5284 // set with the P_INSECURE flag and is not
5285 // completely replaced.
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005286 if ((opt_flags & OPT_MODELINE)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005287#ifdef HAVE_SANDBOX
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005288 || sandbox != 0
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005289#endif
Bram Moolenaar82b033e2019-03-24 14:02:04 +01005290 || (!value_is_replaced && (*p & P_INSECURE)))
5291 secure = 1;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005292
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005293 // Handle side effects, and set the global value
5294 // for ":set" on local options. Note: when setting
5295 // 'syntax' or 'filetype' autocommands may be
5296 // triggered that can cause havoc.
5297 errmsg = did_set_string_option(
5298 opt_idx, (char_u **)varp,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005299 new_value_alloced, oldval, errbuf,
5300 opt_flags, &value_checked);
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005301
Bram Moolenaar48f377a2018-12-21 13:03:28 +01005302 secure = secure_saved;
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01005303 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00005304
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01005305#if defined(FEAT_EVAL)
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005306 if (errmsg == NULL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02005307 trigger_optionsset_string(
5308 opt_idx, opt_flags, saved_origval,
5309 saved_origval_l, saved_origval_g,
5310 saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005311 vim_free(saved_origval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02005312 vim_free(saved_origval_l);
5313 vim_free(saved_origval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02005314 vim_free(saved_newval);
5315#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005316 /* If error detected, print the error message. */
5317 if (errmsg != NULL)
5318 goto skip;
5319 }
5320 else /* key code option */
5321 {
5322 char_u *p;
5323
5324 if (nextchar == '&')
5325 {
5326 if (add_termcap_entry(key_name, TRUE) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005327 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00005328 }
5329 else
5330 {
5331 ++arg; /* jump to after the '=' or ':' */
Bram Moolenaar1c465442017-03-12 20:10:05 +01005332 for (p = arg; *p && !VIM_ISWHITE(*p); ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005333 if (*p == '\\' && p[1] != NUL)
5334 ++p;
5335 nextchar = *p;
5336 *p = NUL;
5337 add_termcode(key_name, arg, FALSE);
5338 *p = nextchar;
5339 }
5340 if (full_screen)
5341 ttest(FALSE);
5342 redraw_all_later(CLEAR);
5343 }
5344 }
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005345
Bram Moolenaar071d4272004-06-13 20:20:40 +00005346 if (opt_idx >= 0)
Bram Moolenaar916a8182018-11-25 02:18:29 +01005347 did_set_option(
5348 opt_idx, opt_flags, value_is_replaced, value_checked);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005349 }
5350
5351skip:
5352 /*
5353 * Advance to next argument.
5354 * - skip until a blank found, taking care of backslashes
5355 * - skip blanks
5356 * - skip one "=val" argument (for hidden options ":set gfn =xx")
5357 */
5358 for (i = 0; i < 2 ; ++i)
5359 {
Bram Moolenaar1c465442017-03-12 20:10:05 +01005360 while (*arg != NUL && !VIM_ISWHITE(*arg))
Bram Moolenaar071d4272004-06-13 20:20:40 +00005361 if (*arg++ == '\\' && *arg != NUL)
5362 ++arg;
5363 arg = skipwhite(arg);
5364 if (*arg != '=')
5365 break;
5366 }
5367 }
5368
5369 if (errmsg != NULL)
5370 {
Bram Moolenaarce0842a2005-07-18 21:58:11 +00005371 vim_strncpy(IObuff, (char_u *)_(errmsg), IOSIZE - 1);
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00005372 i = (int)STRLEN(IObuff) + 2;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005373 if (i + (arg - startarg) < IOSIZE)
5374 {
5375 /* append the argument with the error */
5376 STRCAT(IObuff, ": ");
5377 mch_memmove(IObuff + i, startarg, (arg - startarg));
5378 IObuff[i + (arg - startarg)] = NUL;
5379 }
5380 /* make sure all characters are printable */
5381 trans_characters(IObuff, IOSIZE);
5382
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005383 ++no_wait_return; // wait_return done later
5384 emsg((char *)IObuff); // show error highlighted
Bram Moolenaar071d4272004-06-13 20:20:40 +00005385 --no_wait_return;
5386
5387 return FAIL;
5388 }
5389
5390 arg = skipwhite(arg);
5391 }
5392
Bram Moolenaar26a60b42005-02-22 08:49:11 +00005393theend:
5394 if (silent_mode && did_show)
5395 {
5396 /* After displaying option values in silent mode. */
5397 silent_mode = FALSE;
5398 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
5399 msg_putchar('\n');
5400 cursor_on(); /* msg_start() switches it off */
5401 out_flush();
5402 silent_mode = TRUE;
5403 info_message = FALSE; /* use mch_msg(), not mch_errmsg() */
5404 }
5405
Bram Moolenaar071d4272004-06-13 20:20:40 +00005406 return OK;
5407}
5408
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005409/*
5410 * Call this when an option has been given a new value through a user command.
5411 * Sets the P_WAS_SET flag and takes care of the P_INSECURE flag.
5412 */
5413 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005414did_set_option(
5415 int opt_idx,
Bram Moolenaar916a8182018-11-25 02:18:29 +01005416 int opt_flags, // possibly with OPT_MODELINE
5417 int new_value, // value was replaced completely
5418 int value_checked) // value was checked to be safe, no need to set the
5419 // P_INSECURE flag.
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005420{
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005421 long_u *p;
5422
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005423 options[opt_idx].flags |= P_WAS_SET;
5424
5425 /* When an option is set in the sandbox, from a modeline or in secure mode
5426 * set the P_INSECURE flag. Otherwise, if a new value is stored reset the
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005427 * flag. */
5428 p = insecure_flag(opt_idx, opt_flags);
Bram Moolenaar916a8182018-11-25 02:18:29 +01005429 if (!value_checked && (secure
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005430#ifdef HAVE_SANDBOX
5431 || sandbox != 0
5432#endif
Bram Moolenaar916a8182018-11-25 02:18:29 +01005433 || (opt_flags & OPT_MODELINE)))
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005434 *p = *p | P_INSECURE;
5435 else if (new_value)
5436 *p = *p & ~P_INSECURE;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005437}
5438
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005439 static char *
5440illegal_char(char *errbuf, int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005441{
5442 if (errbuf == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005443 return "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00005444 sprintf((char *)errbuf, _("E539: Illegal character <%s>"),
Bram Moolenaar555b2802005-05-19 21:08:39 +00005445 (char *)transchar(c));
Bram Moolenaar071d4272004-06-13 20:20:40 +00005446 return errbuf;
5447}
5448
5449/*
5450 * Convert a key name or string into a key value.
5451 * Used for 'wildchar' and 'cedit' options.
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005452 * When "multi_byte" is TRUE allow for multi-byte characters.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005453 */
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005454 int
5455string_to_key(char_u *arg, int multi_byte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005456{
5457 if (*arg == '<')
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02005458 return find_key_option(arg + 1, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005459 if (*arg == '^')
5460 return Ctrl_chr(arg[1]);
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005461 if (multi_byte)
5462 return PTR2CHAR(arg);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005463 return *arg;
5464}
5465
5466#ifdef FEAT_CMDWIN
5467/*
5468 * Check value of 'cedit' and set cedit_key.
5469 * Returns NULL if value is OK, error message otherwise.
5470 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01005471 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005472check_cedit(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005473{
5474 int n;
5475
5476 if (*p_cedit == NUL)
5477 cedit_key = -1;
5478 else
5479 {
Bram Moolenaardbe948d2017-07-23 22:50:51 +02005480 n = string_to_key(p_cedit, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005481 if (vim_isprintc(n))
5482 return e_invarg;
5483 cedit_key = n;
5484 }
5485 return NULL;
5486}
5487#endif
5488
5489#ifdef FEAT_TITLE
5490/*
5491 * When changing 'title', 'titlestring', 'icon' or 'iconstring', call
5492 * maketitle() to create and display it.
5493 * When switching the title or icon off, call mch_restore_title() to get
5494 * the old value back.
5495 */
5496 static void
Bram Moolenaar84a93082018-06-16 22:58:15 +02005497did_set_title(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005498{
5499 if (starting != NO_SCREEN
5500#ifdef FEAT_GUI
5501 && !gui.starting
5502#endif
5503 )
Bram Moolenaar071d4272004-06-13 20:20:40 +00005504 maketitle();
Bram Moolenaar071d4272004-06-13 20:20:40 +00005505}
5506#endif
5507
5508/*
5509 * set_options_bin - called when 'bin' changes value.
5510 */
5511 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005512set_options_bin(
5513 int oldval,
5514 int newval,
5515 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00005516{
5517 /*
5518 * The option values that are changed when 'bin' changes are
5519 * copied when 'bin is set and restored when 'bin' is reset.
5520 */
5521 if (newval)
5522 {
5523 if (!oldval) /* switched on */
5524 {
5525 if (!(opt_flags & OPT_GLOBAL))
5526 {
5527 curbuf->b_p_tw_nobin = curbuf->b_p_tw;
5528 curbuf->b_p_wm_nobin = curbuf->b_p_wm;
5529 curbuf->b_p_ml_nobin = curbuf->b_p_ml;
5530 curbuf->b_p_et_nobin = curbuf->b_p_et;
5531 }
5532 if (!(opt_flags & OPT_LOCAL))
5533 {
5534 p_tw_nobin = p_tw;
5535 p_wm_nobin = p_wm;
5536 p_ml_nobin = p_ml;
5537 p_et_nobin = p_et;
5538 }
5539 }
5540
5541 if (!(opt_flags & OPT_GLOBAL))
5542 {
5543 curbuf->b_p_tw = 0; /* no automatic line wrap */
5544 curbuf->b_p_wm = 0; /* no automatic line wrap */
5545 curbuf->b_p_ml = 0; /* no modelines */
5546 curbuf->b_p_et = 0; /* no expandtab */
5547 }
5548 if (!(opt_flags & OPT_LOCAL))
5549 {
5550 p_tw = 0;
5551 p_wm = 0;
5552 p_ml = FALSE;
5553 p_et = FALSE;
5554 p_bin = TRUE; /* needed when called for the "-b" argument */
5555 }
5556 }
5557 else if (oldval) /* switched off */
5558 {
5559 if (!(opt_flags & OPT_GLOBAL))
5560 {
5561 curbuf->b_p_tw = curbuf->b_p_tw_nobin;
5562 curbuf->b_p_wm = curbuf->b_p_wm_nobin;
5563 curbuf->b_p_ml = curbuf->b_p_ml_nobin;
5564 curbuf->b_p_et = curbuf->b_p_et_nobin;
5565 }
5566 if (!(opt_flags & OPT_LOCAL))
5567 {
5568 p_tw = p_tw_nobin;
5569 p_wm = p_wm_nobin;
5570 p_ml = p_ml_nobin;
5571 p_et = p_et_nobin;
5572 }
5573 }
5574}
5575
5576#ifdef FEAT_VIMINFO
5577/*
5578 * Find the parameter represented by the given character (eg ', :, ", or /),
5579 * and return its associated value in the 'viminfo' string.
5580 * Only works for number parameters, not for 'r' or 'n'.
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00005581 * If the parameter is not specified in the string or there is no following
5582 * number, return -1.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005583 */
5584 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005585get_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005586{
5587 char_u *p;
5588
5589 p = find_viminfo_parameter(type);
5590 if (p != NULL && VIM_ISDIGIT(*p))
5591 return atoi((char *)p);
5592 return -1;
5593}
5594
5595/*
5596 * Find the parameter represented by the given character (eg ''', ':', '"', or
5597 * '/') in the 'viminfo' option and return a pointer to the string after it.
5598 * Return NULL if the parameter is not specified in the string.
5599 */
5600 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005601find_viminfo_parameter(int type)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005602{
5603 char_u *p;
5604
5605 for (p = p_viminfo; *p; ++p)
5606 {
5607 if (*p == type)
5608 return p + 1;
5609 if (*p == 'n') /* 'n' is always the last one */
5610 break;
5611 p = vim_strchr(p, ','); /* skip until next ',' */
5612 if (p == NULL) /* hit the end without finding parameter */
5613 break;
5614 }
5615 return NULL;
5616}
5617#endif
5618
5619/*
5620 * Expand environment variables for some string options.
5621 * These string options cannot be indirect!
5622 * If "val" is NULL expand the current value of the option.
5623 * Return pointer to NameBuff, or NULL when not expanded.
5624 */
5625 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005626option_expand(int opt_idx, char_u *val)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005627{
5628 /* if option doesn't need expansion nothing to do */
5629 if (!(options[opt_idx].flags & P_EXPAND) || options[opt_idx].var == NULL)
5630 return NULL;
5631
5632 /* If val is longer than MAXPATHL no meaningful expansion can be done,
5633 * expand_env() would truncate the string. */
5634 if (val != NULL && STRLEN(val) > MAXPATHL)
5635 return NULL;
5636
5637 if (val == NULL)
5638 val = *(char_u **)options[opt_idx].var;
5639
5640 /*
5641 * Expanding this with NameBuff, expand_env() must not be passed IObuff.
5642 * Escape spaces when expanding 'tags', they are used to separate file
5643 * names.
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005644 * For 'spellsuggest' expand after "file:".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005645 */
5646 expand_env_esc(val, NameBuff, MAXPATHL,
Bram Moolenaar9f0545d2007-09-26 20:36:32 +00005647 (char_u **)options[opt_idx].var == &p_tags, FALSE,
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005648#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005649 (char_u **)options[opt_idx].var == &p_sps ? (char_u *)"file:" :
5650#endif
5651 NULL);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005652 if (STRCMP(NameBuff, val) == 0) /* they are the same */
5653 return NULL;
5654
5655 return NameBuff;
5656}
5657
5658/*
5659 * After setting various option values: recompute variables that depend on
5660 * option values.
5661 */
5662 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005663didset_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005664{
5665 /* initialize the table for 'iskeyword' et.al. */
5666 (void)init_chartab();
5667
5668 (void)opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE);
5669 (void)opt_strings_flags(p_bkc, p_bkc_values, &bkc_flags, TRUE);
Bram Moolenaar165bc692015-07-21 17:53:25 +02005670 (void)opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005671#ifdef FEAT_SESSION
5672 (void)opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE);
5673 (void)opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE);
5674#endif
5675#ifdef FEAT_FOLDING
5676 (void)opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE);
5677#endif
5678 (void)opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005679 (void)opt_strings_flags(p_tc, p_tc_values, &tc_flags, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005680 (void)opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005681#if defined(FEAT_MOUSE) && (defined(UNIX) || defined(VMS))
5682 (void)opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE);
5683#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005684#ifdef FEAT_SPELL
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00005685 (void)spell_check_msm();
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00005686 (void)spell_check_sps();
Bram Moolenaar860cae12010-06-05 23:22:07 +02005687 (void)compile_cap_prog(curwin->w_s);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005688 (void)did_set_spell_option(TRUE);
Bram Moolenaard857f0e2005-06-21 22:37:39 +00005689#endif
Bram Moolenaar4f974752019-02-17 17:44:42 +01005690#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005691 (void)opt_strings_flags(p_toolbar, p_toolbar_values, &toolbar_flags, TRUE);
5692#endif
Bram Moolenaar182c5be2010-06-25 05:37:59 +02005693#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005694 (void)opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE);
5695#endif
5696#ifdef FEAT_CMDWIN
5697 /* set cedit_key */
5698 (void)check_cedit();
5699#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +02005700#ifdef FEAT_LINEBREAK
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02005701 briopt_check(curwin);
Bram Moolenaar597a4222014-06-25 14:39:50 +02005702#endif
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005703#ifdef FEAT_LINEBREAK
5704 /* initialize the table for 'breakat'. */
5705 fill_breakat_flags();
5706#endif
5707
5708}
5709
5710/*
5711 * More side effects of setting options.
5712 */
5713 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005714didset_options2(void)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005715{
5716 /* Initialize the highlight_attr[] table. */
5717 (void)highlight_changed();
5718
5719 /* Parse default for 'wildmode' */
5720 check_opt_wim();
5721
5722 (void)set_chars_option(&p_lcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005723 /* Parse default for 'fillchars'. */
5724 (void)set_chars_option(&p_fcs);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02005725
5726#ifdef FEAT_CLIPBOARD
5727 /* Parse default for 'clipboard' */
5728 (void)check_clipboard_option();
5729#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005730#ifdef FEAT_VARTABS
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005731 vim_free(curbuf->b_p_vsts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005732 tabstop_set(curbuf->b_p_vsts, &curbuf->b_p_vsts_array);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01005733 vim_free(curbuf->b_p_vts_array);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005734 tabstop_set(curbuf->b_p_vts, &curbuf->b_p_vts_array);
5735#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005736}
5737
5738/*
5739 * Check for string options that are NULL (normally only termcap options).
5740 */
5741 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005742check_options(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005743{
5744 int opt_idx;
5745
5746 for (opt_idx = 0; options[opt_idx].fullname != NULL; opt_idx++)
5747 if ((options[opt_idx].flags & P_STRING) && options[opt_idx].var != NULL)
5748 check_string_option((char_u **)get_varp(&(options[opt_idx])));
5749}
5750
5751/*
5752 * Check string options in a buffer for NULL value.
5753 */
5754 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005755check_buf_options(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005756{
Bram Moolenaar071d4272004-06-13 20:20:40 +00005757 check_string_option(&buf->b_p_bh);
5758 check_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005759 check_string_option(&buf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005760 check_string_option(&buf->b_p_ff);
5761#ifdef FEAT_FIND_ID
5762 check_string_option(&buf->b_p_def);
5763 check_string_option(&buf->b_p_inc);
5764# ifdef FEAT_EVAL
5765 check_string_option(&buf->b_p_inex);
5766# endif
5767#endif
5768#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
5769 check_string_option(&buf->b_p_inde);
5770 check_string_option(&buf->b_p_indk);
5771#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005772#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
5773 check_string_option(&buf->b_p_bexpr);
5774#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +02005775#if defined(FEAT_CRYPT)
5776 check_string_option(&buf->b_p_cm);
5777#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +01005778 check_string_option(&buf->b_p_fp);
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +00005779#if defined(FEAT_EVAL)
5780 check_string_option(&buf->b_p_fex);
5781#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005782#ifdef FEAT_CRYPT
5783 check_string_option(&buf->b_p_key);
5784#endif
5785 check_string_option(&buf->b_p_kp);
5786 check_string_option(&buf->b_p_mps);
5787 check_string_option(&buf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +00005788 check_string_option(&buf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005789 check_string_option(&buf->b_p_isk);
5790#ifdef FEAT_COMMENTS
5791 check_string_option(&buf->b_p_com);
5792#endif
5793#ifdef FEAT_FOLDING
5794 check_string_option(&buf->b_p_cms);
5795#endif
5796 check_string_option(&buf->b_p_nf);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005797#ifdef FEAT_TEXTOBJ
5798 check_string_option(&buf->b_p_qe);
5799#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005800#ifdef FEAT_SYN_HL
5801 check_string_option(&buf->b_p_syn);
Bram Moolenaarb8060fe2016-01-19 22:29:28 +01005802 check_string_option(&buf->b_s.b_syn_isk);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00005803#endif
5804#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02005805 check_string_option(&buf->b_s.b_p_spc);
5806 check_string_option(&buf->b_s.b_p_spf);
5807 check_string_option(&buf->b_s.b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005808#endif
5809#ifdef FEAT_SEARCHPATH
5810 check_string_option(&buf->b_p_sua);
5811#endif
5812#ifdef FEAT_CINDENT
5813 check_string_option(&buf->b_p_cink);
5814 check_string_option(&buf->b_p_cino);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01005815 parse_cino(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005816#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005817 check_string_option(&buf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005818#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
5819 check_string_option(&buf->b_p_cinw);
5820#endif
5821#ifdef FEAT_INS_EXPAND
5822 check_string_option(&buf->b_p_cpt);
5823#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005824#ifdef FEAT_COMPL_FUNC
5825 check_string_option(&buf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +00005826 check_string_option(&buf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00005827#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +02005828#ifdef FEAT_EVAL
5829 check_string_option(&buf->b_p_tfu);
5830#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005831#ifdef FEAT_KEYMAP
5832 check_string_option(&buf->b_p_keymap);
5833#endif
5834#ifdef FEAT_QUICKFIX
5835 check_string_option(&buf->b_p_gp);
5836 check_string_option(&buf->b_p_mp);
5837 check_string_option(&buf->b_p_efm);
5838#endif
5839 check_string_option(&buf->b_p_ep);
5840 check_string_option(&buf->b_p_path);
5841 check_string_option(&buf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01005842 check_string_option(&buf->b_p_tc);
Bram Moolenaar071d4272004-06-13 20:20:40 +00005843#ifdef FEAT_INS_EXPAND
5844 check_string_option(&buf->b_p_dict);
5845 check_string_option(&buf->b_p_tsr);
5846#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +01005847#ifdef FEAT_LISP
5848 check_string_option(&buf->b_p_lw);
5849#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02005850 check_string_option(&buf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01005851 check_string_option(&buf->b_p_menc);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02005852#ifdef FEAT_VARTABS
5853 check_string_option(&buf->b_p_vsts);
5854 check_string_option(&buf->b_p_vts);
5855#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00005856}
5857
5858/*
5859 * Free the string allocated for an option.
5860 * Checks for the string being empty_option. This may happen if we're out of
5861 * memory, vim_strsave() returned NULL, which was replaced by empty_option by
5862 * check_options().
5863 * Does NOT check for P_ALLOCED flag!
5864 */
5865 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005866free_string_option(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005867{
5868 if (p != empty_option)
5869 vim_free(p);
5870}
5871
5872 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005873clear_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005874{
5875 if (*pp != empty_option)
5876 vim_free(*pp);
5877 *pp = empty_option;
5878}
5879
5880 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005881check_string_option(char_u **pp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005882{
5883 if (*pp == NULL)
5884 *pp = empty_option;
5885}
5886
5887/*
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005888 * Return the option index found by a pointer into term_strings[].
5889 * Return -1 if not found.
Bram Moolenaar071d4272004-06-13 20:20:40 +00005890 */
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005891 int
5892get_term_opt_idx(char_u **p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005893{
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005894 int opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005895
5896 for (opt_idx = 1; options[opt_idx].fullname != NULL; opt_idx++)
5897 if (options[opt_idx].var == (char_u *)p)
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02005898 return opt_idx;
5899 return -1; // cannot happen: didn't find it!
5900}
5901
5902/*
5903 * Mark a terminal option as allocated, found by a pointer into term_strings[].
5904 * Return the option index or -1 if not found.
5905 */
5906 int
5907set_term_option_alloced(char_u **p)
5908{
5909 int opt_idx = get_term_opt_idx(p);
5910
5911 if (opt_idx >= 0)
5912 options[opt_idx].flags |= P_ALLOCED;
5913 return opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00005914}
5915
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005916#if defined(FEAT_EVAL) || defined(PROTO)
5917/*
5918 * Return TRUE when option "opt" was set from a modeline or in secure mode.
5919 * Return FALSE when it wasn't.
5920 * Return -1 for an unknown option.
5921 */
5922 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01005923was_set_insecurely(char_u *opt, int opt_flags)
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005924{
5925 int idx = findoption(opt);
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005926 long_u *flagp;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005927
5928 if (idx >= 0)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005929 {
5930 flagp = insecure_flag(idx, opt_flags);
5931 return (*flagp & P_INSECURE) != 0;
5932 }
Bram Moolenaar95f09602016-11-10 20:01:45 +01005933 internal_error("was_set_insecurely()");
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005934 return -1;
5935}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005936
5937/*
5938 * Get a pointer to the flags used for the P_INSECURE flag of option
5939 * "opt_idx". For some local options a local flags field is used.
5940 */
5941 static long_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +01005942insecure_flag(int opt_idx, int opt_flags)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005943{
5944 if (opt_flags & OPT_LOCAL)
5945 switch ((int)options[opt_idx].indir)
5946 {
5947#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005948 case PV_STL: return &curwin->w_p_stl_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005949#endif
5950#ifdef FEAT_EVAL
Bram Moolenaar2e978902006-05-13 12:37:50 +00005951# ifdef FEAT_FOLDING
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005952 case PV_FDE: return &curwin->w_p_fde_flags;
5953 case PV_FDT: return &curwin->w_p_fdt_flags;
Bram Moolenaar2e978902006-05-13 12:37:50 +00005954# endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +00005955# ifdef FEAT_BEVAL
5956 case PV_BEXPR: return &curbuf->b_p_bexpr_flags;
5957# endif
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005958# if defined(FEAT_CINDENT)
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005959 case PV_INDE: return &curbuf->b_p_inde_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005960# endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005961 case PV_FEX: return &curbuf->b_p_fex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005962# ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00005963 case PV_INEX: return &curbuf->b_p_inex_flags;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00005964# endif
5965#endif
5966 }
5967
5968 /* Nothing special, return global flags field. */
5969 return &options[opt_idx].flags;
5970}
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00005971#endif
5972
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005973#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005974/*
5975 * Redraw the window title and/or tab page text later.
5976 */
Bram Moolenaar9b578142016-01-30 19:39:49 +01005977static void redraw_titles(void)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005978{
5979 need_maketitle = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005980 redraw_tabline = TRUE;
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00005981}
5982#endif
5983
Bram Moolenaar071d4272004-06-13 20:20:40 +00005984/*
5985 * Set a string option to a new value (without checking the effect).
5986 * The string is copied into allocated memory.
5987 * if ("opt_idx" == -1) "name" is used, otherwise "opt_idx" is used.
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02005988 * When "set_sid" is zero set the scriptID to current_sctx.sc_sid. When
5989 * "set_sid" is SID_NONE don't set the scriptID. Otherwise set the scriptID to
5990 * "set_sid".
Bram Moolenaar071d4272004-06-13 20:20:40 +00005991 */
5992 void
Bram Moolenaar9b578142016-01-30 19:39:49 +01005993set_string_option_direct(
5994 char_u *name,
5995 int opt_idx,
5996 char_u *val,
5997 int opt_flags, /* OPT_FREE, OPT_LOCAL and/or OPT_GLOBAL */
5998 int set_sid UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +00005999{
6000 char_u *s;
6001 char_u **varp;
6002 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
Bram Moolenaar89d40322006-08-29 15:30:07 +00006003 int idx = opt_idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006004
Bram Moolenaar89d40322006-08-29 15:30:07 +00006005 if (idx == -1) /* use name */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006006 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00006007 idx = findoption(name);
6008 if (idx < 0) /* not found (should not happen) */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006009 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006010 semsg(_(e_intern2), "set_string_option_direct()");
6011 siemsg(_("For option %s"), name);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006012 return;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006013 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006014 }
6015
Bram Moolenaar89d40322006-08-29 15:30:07 +00006016 if (options[idx].var == NULL) /* can't set hidden option */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006017 return;
6018
6019 s = vim_strsave(val);
6020 if (s != NULL)
6021 {
Bram Moolenaar89d40322006-08-29 15:30:07 +00006022 varp = (char_u **)get_varp_scope(&(options[idx]),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006023 both ? OPT_LOCAL : opt_flags);
Bram Moolenaar89d40322006-08-29 15:30:07 +00006024 if ((opt_flags & OPT_FREE) && (options[idx].flags & P_ALLOCED))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006025 free_string_option(*varp);
6026 *varp = s;
6027
6028 /* For buffer/window local option may also set the global value. */
6029 if (both)
Bram Moolenaar89d40322006-08-29 15:30:07 +00006030 set_string_option_global(idx, varp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006031
Bram Moolenaar89d40322006-08-29 15:30:07 +00006032 options[idx].flags |= P_ALLOCED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006033
6034 /* When setting both values of a global option with a local value,
6035 * make the local value empty, so that the global value is used. */
Bram Moolenaar89d40322006-08-29 15:30:07 +00006036 if (((int)options[idx].indir & PV_BOTH) && both)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006037 {
6038 free_string_option(*varp);
6039 *varp = empty_option;
6040 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006041# ifdef FEAT_EVAL
6042 if (set_sid != SID_NONE)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006043 {
6044 sctx_T script_ctx;
6045
6046 if (set_sid == 0)
6047 script_ctx = current_sctx;
6048 else
6049 {
6050 script_ctx.sc_sid = set_sid;
Bram Moolenaarded5f1b2018-11-10 17:33:29 +01006051 script_ctx.sc_seq = 0;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006052 script_ctx.sc_lnum = 0;
Bram Moolenaar558ca4a2019-04-04 18:15:38 +02006053 script_ctx.sc_version = 1;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02006054 }
6055 set_option_sctx_idx(idx, opt_flags, script_ctx);
6056 }
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00006057# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006058 }
6059}
6060
6061/*
Bram Moolenaar20c023a2019-05-26 21:03:24 +02006062 * Like set_string_option_direct(), but for a window-local option in "wp".
6063 * Blocks autocommands to avoid the old curwin becoming invalid.
6064 */
6065 void
6066set_string_option_direct_in_win(
6067 win_T *wp,
6068 char_u *name,
6069 int opt_idx,
6070 char_u *val,
6071 int opt_flags,
6072 int set_sid)
6073{
6074 win_T *save_curwin = curwin;
6075
6076 block_autocmds();
6077 curwin = wp;
6078 curbuf = curwin->w_buffer;
6079 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6080 curwin = save_curwin;
6081 curbuf = curwin->w_buffer;
6082 unblock_autocmds();
6083}
6084
6085/*
6086 * Like set_string_option_direct(), but for a buffer-local option in "buf".
6087 * Blocks autocommands to avoid the old curbuf becoming invalid.
6088 */
6089 void
6090set_string_option_direct_in_buf(
6091 buf_T *buf,
6092 char_u *name,
6093 int opt_idx,
6094 char_u *val,
6095 int opt_flags,
6096 int set_sid)
6097{
6098 buf_T *save_curbuf = curbuf;
6099
6100 block_autocmds();
6101 curbuf = buf;
6102 curwin->w_buffer = curbuf;
6103 set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
6104 curbuf = save_curbuf;
6105 curwin->w_buffer = curbuf;
6106 unblock_autocmds();
6107}
6108
6109/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006110 * Set global value for string option when it's a local option.
6111 */
6112 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01006113set_string_option_global(
6114 int opt_idx, /* option index */
6115 char_u **varp) /* pointer to option variable */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006116{
6117 char_u **p, *s;
6118
6119 /* the global value is always allocated */
6120 if (options[opt_idx].var == VAR_WIN)
6121 p = (char_u **)GLOBAL_WO(varp);
6122 else
6123 p = (char_u **)options[opt_idx].var;
6124 if (options[opt_idx].indir != PV_NONE
6125 && p != varp
6126 && (s = vim_strsave(*varp)) != NULL)
6127 {
6128 free_string_option(*p);
6129 *p = s;
6130 }
6131}
6132
6133/*
6134 * Set a string option to a new value, and handle the effects.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006135 *
6136 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +00006137 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006138 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006139set_string_option(
6140 int opt_idx,
6141 char_u *value,
6142 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006143{
6144 char_u *s;
6145 char_u **varp;
6146 char_u *oldval;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006147#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006148 char_u *oldval_l = NULL;
6149 char_u *oldval_g = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006150 char_u *saved_oldval = NULL;
Bram Moolenaard7c96872019-06-15 17:12:48 +02006151 char_u *saved_oldval_l = NULL;
6152 char_u *saved_oldval_g = NULL;
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006153 char_u *saved_newval = NULL;
Bram Moolenaar53744302015-07-17 17:38:22 +02006154#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006155 char *r = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01006156 int value_checked = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006157
6158 if (options[opt_idx].var == NULL) /* don't set hidden option */
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006159 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006160
6161 s = vim_strsave(value);
6162 if (s != NULL)
6163 {
6164 varp = (char_u **)get_varp_scope(&(options[opt_idx]),
6165 (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00006166 ? (((int)options[opt_idx].indir & PV_BOTH)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006167 ? OPT_GLOBAL : OPT_LOCAL)
6168 : opt_flags);
6169 oldval = *varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006170#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02006171 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6172 {
6173 oldval_l = *(char_u **)get_varp_scope(&(options[opt_idx]),
6174 OPT_LOCAL);
6175 oldval_g = *(char_u **)get_varp_scope(&(options[opt_idx]),
6176 OPT_GLOBAL);
6177 }
Bram Moolenaar983f2f12019-06-16 16:41:41 +02006178#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006179 *varp = s;
Bram Moolenaar53744302015-07-17 17:38:22 +02006180
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006181#if defined(FEAT_EVAL)
Bram Moolenaar5cbb8db2015-07-17 23:08:29 +02006182 if (!starting
6183# ifdef FEAT_CRYPT
6184 && options[opt_idx].indir != PV_KEY
6185# endif
6186 )
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006187 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02006188 if (oldval_l != NULL)
6189 saved_oldval_l = vim_strsave(oldval_l);
6190 if (oldval_g != NULL)
6191 saved_oldval_g = vim_strsave(oldval_g);
Bram Moolenaar53744302015-07-17 17:38:22 +02006192 saved_oldval = vim_strsave(oldval);
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006193 saved_newval = vim_strsave(s);
6194 }
Bram Moolenaar53744302015-07-17 17:38:22 +02006195#endif
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006196 if ((r = did_set_string_option(opt_idx, varp, TRUE, oldval, NULL,
Bram Moolenaar916a8182018-11-25 02:18:29 +01006197 opt_flags, &value_checked)) == NULL)
6198 did_set_option(opt_idx, opt_flags, TRUE, value_checked);
Bram Moolenaar53744302015-07-17 17:38:22 +02006199
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01006200#if defined(FEAT_EVAL)
Bram Moolenaar182a17b2017-06-25 20:57:18 +02006201 /* call autocommand after handling side effects */
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006202 if (r == NULL)
6203 trigger_optionsset_string(opt_idx, opt_flags,
Bram Moolenaard7c96872019-06-15 17:12:48 +02006204 saved_oldval, saved_oldval_l,
6205 saved_oldval_g, saved_newval);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006206 vim_free(saved_oldval);
Bram Moolenaard7c96872019-06-15 17:12:48 +02006207 vim_free(saved_oldval_l);
6208 vim_free(saved_oldval_g);
Bram Moolenaar8efa0262017-08-20 15:47:20 +02006209 vim_free(saved_newval);
Bram Moolenaar53744302015-07-17 17:38:22 +02006210#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006211 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +02006212 return r;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006213}
6214
6215/*
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006216 * Return TRUE if "val" is a valid name: only consists of alphanumeric ASCII
6217 * characters or characters in "allowed".
6218 */
6219 static int
6220valid_name(char_u *val, char *allowed)
6221{
6222 char_u *s;
6223
6224 for (s = val; *s != NUL; ++s)
6225 if (!ASCII_ISALNUM(*s) && vim_strchr((char_u *)allowed, *s) == NULL)
6226 return FALSE;
6227 return TRUE;
6228}
6229
6230/*
Bram Moolenaard0b51382016-11-04 15:23:45 +01006231 * Return TRUE if "val" is a valid 'filetype' name.
6232 * Also used for 'syntax' and 'keymap'.
6233 */
6234 static int
6235valid_filetype(char_u *val)
6236{
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006237 return valid_name(val, ".-_");
6238}
Bram Moolenaard0b51382016-11-04 15:23:45 +01006239
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006240#if defined(FEAT_SPELL) || defined(PROTO)
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02006241/*
6242 * Return TRUE if "val" is a valid 'spellang' value.
6243 */
6244 int
6245valid_spellang(char_u *val)
6246{
Bram Moolenaar9a061cb2019-05-05 16:55:03 +02006247 return valid_name(val, ".-_,@");
Bram Moolenaard0b51382016-11-04 15:23:45 +01006248}
6249
6250/*
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006251 * Return TRUE if "val" is a valid 'spellfile' value.
6252 */
6253 static int
6254valid_spellfile(char_u *val)
6255{
6256 char_u *s;
6257
6258 for (s = val; *s != NUL; ++s)
6259 if (!vim_isfilec(*s) && *s != ',')
6260 return FALSE;
6261 return TRUE;
6262}
Bram Moolenaara7be0f22019-04-11 11:19:32 +02006263#endif
Bram Moolenaar862f1e12019-04-10 22:33:41 +02006264
6265/*
Bram Moolenaar071d4272004-06-13 20:20:40 +00006266 * Handle string options that need some action to perform when changed.
6267 * Returns NULL for success, or an error message for an error.
6268 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006269 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01006270did_set_string_option(
Bram Moolenaar916a8182018-11-25 02:18:29 +01006271 int opt_idx, // index in options[] table
6272 char_u **varp, // pointer to the option variable
6273 int new_value_alloced, // new value was allocated
6274 char_u *oldval, // previous value of the option
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006275 char *errbuf, // buffer for errors, or NULL
Bram Moolenaar916a8182018-11-25 02:18:29 +01006276 int opt_flags, // OPT_LOCAL and/or OPT_GLOBAL
6277 int *value_checked) // value was checked to be save, no
6278 // need to set P_INSECURE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006279{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006280 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006281 char_u *s, *p;
6282 int did_chartab = FALSE;
6283 char_u **gvarp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +00006284 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00006285#ifdef FEAT_GUI
6286 /* set when changing an option that only requires a redraw in the GUI */
6287 int redraw_gui_only = FALSE;
6288#endif
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02006289 int value_changed = FALSE;
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02006290#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6291 int did_swaptcap = FALSE;
6292#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006293
6294 /* Get the global option to compare with, otherwise we would have to check
6295 * two values for all local options. */
6296 gvarp = (char_u **)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL);
6297
6298 /* Disallow changing some options from secure mode */
6299 if ((secure
6300#ifdef HAVE_SANDBOX
6301 || sandbox != 0
6302#endif
6303 ) && (options[opt_idx].flags & P_SECURE))
Bram Moolenaar071d4272004-06-13 20:20:40 +00006304 errmsg = e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006305
Bram Moolenaar916a8182018-11-25 02:18:29 +01006306 // Check for a "normal" directory or file name in some options. Disallow a
6307 // path separator (slash and/or backslash), wildcards and characters that
6308 // are often illegal in a file name. Be more permissive if "secure" is off.
Bram Moolenaar7554da42016-11-25 22:04:13 +01006309 else if (((options[opt_idx].flags & P_NFNAME)
Bram Moolenaar0945eaf2016-11-29 22:10:48 +01006310 && vim_strpbrk(*varp, (char_u *)(secure
6311 ? "/\\*?[|;&<>\r\n" : "/\\*?[<>\r\n")) != NULL)
Bram Moolenaar7554da42016-11-25 22:04:13 +01006312 || ((options[opt_idx].flags & P_NDNAME)
6313 && vim_strpbrk(*varp, (char_u *)"*?[|;&<>\r\n") != NULL))
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006314 errmsg = e_invarg;
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00006315
Bram Moolenaar071d4272004-06-13 20:20:40 +00006316 /* 'term' */
6317 else if (varp == &T_NAME)
6318 {
6319 if (T_NAME[0] == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006320 errmsg = N_("E529: Cannot set 'term' to empty string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006321#ifdef FEAT_GUI
6322 if (gui.in_use)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006323 errmsg = N_("E530: Cannot change term in GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006324 else if (term_is_gui(T_NAME))
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006325 errmsg = N_("E531: Use \":gui\" to start the GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006326#endif
6327 else if (set_termname(T_NAME) == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006328 errmsg = N_("E522: Not found in termcap");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006329 else
Bram Moolenaar67391142017-02-19 21:07:04 +01006330 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00006331 /* Screen colors may have changed. */
6332 redraw_later_clear();
Bram Moolenaar67391142017-02-19 21:07:04 +01006333
6334 /* Both 'term' and 'ttytype' point to T_NAME, only set the
6335 * P_ALLOCED flag on 'term'. */
6336 opt_idx = findoption((char_u *)"term");
Bram Moolenaar354796c2017-02-23 17:18:37 +01006337 free_oldval = (options[opt_idx].flags & P_ALLOCED);
Bram Moolenaar67391142017-02-19 21:07:04 +01006338 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006339 }
6340
6341 /* 'backupcopy' */
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006342 else if (gvarp == &p_bkc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006343 {
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +02006344 char_u *bkc = p_bkc;
6345 unsigned int *flags = &bkc_flags;
6346
6347 if (opt_flags & OPT_LOCAL)
6348 {
6349 bkc = curbuf->b_p_bkc;
6350 flags = &curbuf->b_bkc_flags;
6351 }
6352
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006353 if ((opt_flags & OPT_LOCAL) && *bkc == NUL)
6354 /* make the local value empty: use the global value */
6355 *flags = 0;
6356 else
Bram Moolenaar071d4272004-06-13 20:20:40 +00006357 {
Bram Moolenaar84d17a62014-09-29 17:15:18 +02006358 if (opt_strings_flags(bkc, p_bkc_values, flags, TRUE) != OK)
6359 errmsg = e_invarg;
6360 if ((((int)*flags & BKC_AUTO) != 0)
6361 + (((int)*flags & BKC_YES) != 0)
6362 + (((int)*flags & BKC_NO) != 0) != 1)
6363 {
6364 /* Must have exactly one of "auto", "yes" and "no". */
6365 (void)opt_strings_flags(oldval, p_bkc_values, flags, TRUE);
6366 errmsg = e_invarg;
6367 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006368 }
6369 }
6370
6371 /* 'backupext' and 'patchmode' */
6372 else if (varp == &p_bex || varp == &p_pm)
6373 {
6374 if (STRCMP(*p_bex == '.' ? p_bex + 1 : p_bex,
6375 *p_pm == '.' ? p_pm + 1 : p_pm) == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006376 errmsg = N_("E589: 'backupext' and 'patchmode' are equal");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006377 }
Bram Moolenaar597a4222014-06-25 14:39:50 +02006378#ifdef FEAT_LINEBREAK
6379 /* 'breakindentopt' */
6380 else if (varp == &curwin->w_p_briopt)
6381 {
Bram Moolenaar285ed7e2014-08-24 21:39:49 +02006382 if (briopt_check(curwin) == FAIL)
Bram Moolenaar597a4222014-06-25 14:39:50 +02006383 errmsg = e_invarg;
6384 }
6385#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006386
6387 /*
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006388 * 'isident', 'iskeyword', 'isprint or 'isfname' option: refill g_chartab[]
Bram Moolenaar071d4272004-06-13 20:20:40 +00006389 * If the new option is invalid, use old value. 'lisp' option: refill
Bram Moolenaar88e8f9f2016-01-20 22:48:02 +01006390 * g_chartab[] for '-' char
Bram Moolenaar071d4272004-06-13 20:20:40 +00006391 */
6392 else if ( varp == &p_isi
6393 || varp == &(curbuf->b_p_isk)
6394 || varp == &p_isp
6395 || varp == &p_isf)
6396 {
6397 if (init_chartab() == FAIL)
6398 {
6399 did_chartab = TRUE; /* need to restore it below */
6400 errmsg = e_invarg; /* error in value */
6401 }
6402 }
6403
6404 /* 'helpfile' */
6405 else if (varp == &p_hf)
6406 {
6407 /* May compute new values for $VIM and $VIMRUNTIME */
6408 if (didset_vim)
6409 {
6410 vim_setenv((char_u *)"VIM", (char_u *)"");
6411 didset_vim = FALSE;
6412 }
6413 if (didset_vimruntime)
6414 {
6415 vim_setenv((char_u *)"VIMRUNTIME", (char_u *)"");
6416 didset_vimruntime = FALSE;
6417 }
6418 }
6419
Bram Moolenaar1a384422010-07-14 19:53:30 +02006420#ifdef FEAT_SYN_HL
6421 /* 'colorcolumn' */
6422 else if (varp == &curwin->w_p_cc)
6423 errmsg = check_colorcolumn(curwin);
6424#endif
6425
Bram Moolenaar071d4272004-06-13 20:20:40 +00006426#ifdef FEAT_MULTI_LANG
6427 /* 'helplang' */
6428 else if (varp == &p_hlg)
6429 {
6430 /* Check for "", "ab", "ab,cd", etc. */
6431 for (s = p_hlg; *s != NUL; s += 3)
6432 {
6433 if (s[1] == NUL || ((s[2] != ',' || s[3] == NUL) && s[2] != NUL))
6434 {
6435 errmsg = e_invarg;
6436 break;
6437 }
6438 if (s[2] == NUL)
6439 break;
6440 }
6441 }
6442#endif
6443
6444 /* 'highlight' */
6445 else if (varp == &p_hl)
6446 {
6447 if (highlight_changed() == FAIL)
6448 errmsg = e_invarg; /* invalid flags */
6449 }
6450
6451 /* 'nrformats' */
6452 else if (gvarp == &p_nf)
6453 {
6454 if (check_opt_strings(*varp, p_nf_values, TRUE) != OK)
6455 errmsg = e_invarg;
6456 }
6457
6458#ifdef FEAT_SESSION
6459 /* 'sessionoptions' */
6460 else if (varp == &p_ssop)
6461 {
6462 if (opt_strings_flags(p_ssop, p_ssop_values, &ssop_flags, TRUE) != OK)
6463 errmsg = e_invarg;
6464 if ((ssop_flags & SSOP_CURDIR) && (ssop_flags & SSOP_SESDIR))
6465 {
6466 /* Don't allow both "sesdir" and "curdir". */
6467 (void)opt_strings_flags(oldval, p_ssop_values, &ssop_flags, TRUE);
6468 errmsg = e_invarg;
6469 }
6470 }
6471 /* 'viewoptions' */
6472 else if (varp == &p_vop)
6473 {
6474 if (opt_strings_flags(p_vop, p_ssop_values, &vop_flags, TRUE) != OK)
6475 errmsg = e_invarg;
6476 }
6477#endif
6478
6479 /* 'scrollopt' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006480 else if (varp == &p_sbo)
6481 {
6482 if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
6483 errmsg = e_invarg;
6484 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006485
6486 /* 'ambiwidth' */
Bram Moolenaar3848e002016-03-19 18:42:29 +01006487 else if (varp == &p_ambw || varp == &p_emoji)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006488 {
6489 if (check_opt_strings(p_ambw, p_ambw_values, FALSE) != OK)
6490 errmsg = e_invarg;
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006491 else if (set_chars_option(&p_lcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006492 errmsg = _("E834: Conflicts with value of 'listchars'");
Bram Moolenaar5c3bd0a2010-08-04 20:55:44 +02006493 else if (set_chars_option(&p_fcs) != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006494 errmsg = _("E835: Conflicts with value of 'fillchars'");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006495 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006496
6497 /* 'background' */
6498 else if (varp == &p_bg)
6499 {
6500 if (check_opt_strings(p_bg, p_bg_values, FALSE) == OK)
6501 {
6502#ifdef FEAT_EVAL
6503 int dark = (*p_bg == 'd');
6504#endif
6505
6506 init_highlight(FALSE, FALSE);
6507
6508#ifdef FEAT_EVAL
6509 if (dark != (*p_bg == 'd')
6510 && get_var_value((char_u *)"g:colors_name") != NULL)
6511 {
6512 /* The color scheme must have set 'background' back to another
6513 * value, that's not what we want here. Disable the color
6514 * scheme and set the colors again. */
Bram Moolenaar2ce06f62005-01-31 19:19:04 +00006515 do_unlet((char_u *)"g:colors_name", TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006516 free_string_option(p_bg);
6517 p_bg = vim_strsave((char_u *)(dark ? "dark" : "light"));
6518 check_string_option(&p_bg);
6519 init_highlight(FALSE, FALSE);
6520 }
6521#endif
6522 }
6523 else
6524 errmsg = e_invarg;
6525 }
6526
6527 /* 'wildmode' */
6528 else if (varp == &p_wim)
6529 {
6530 if (check_opt_wim() == FAIL)
6531 errmsg = e_invarg;
6532 }
6533
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00006534#ifdef FEAT_CMDL_COMPL
6535 /* 'wildoptions' */
6536 else if (varp == &p_wop)
6537 {
6538 if (check_opt_strings(p_wop, p_wop_values, TRUE) != OK)
6539 errmsg = e_invarg;
6540 }
6541#endif
6542
Bram Moolenaar071d4272004-06-13 20:20:40 +00006543#ifdef FEAT_WAK
6544 /* 'winaltkeys' */
6545 else if (varp == &p_wak)
6546 {
6547 if (*p_wak == NUL
6548 || check_opt_strings(p_wak, p_wak_values, FALSE) != OK)
6549 errmsg = e_invarg;
6550# ifdef FEAT_MENU
6551# ifdef FEAT_GUI_MOTIF
6552 else if (gui.in_use)
6553 gui_motif_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6554# else
6555# ifdef FEAT_GUI_GTK
6556 else if (gui.in_use)
6557 gui_gtk_set_mnemonics(p_wak[0] == 'y' || p_wak[0] == 'm');
6558# endif
6559# endif
6560# endif
6561 }
6562#endif
6563
Bram Moolenaar071d4272004-06-13 20:20:40 +00006564 /* 'eventignore' */
6565 else if (varp == &p_ei)
6566 {
6567 if (check_ei() == FAIL)
6568 errmsg = e_invarg;
6569 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006570
Bram Moolenaar2c7292d2017-03-05 17:43:31 +01006571 /* 'encoding', 'fileencoding', 'termencoding' and 'makeencoding' */
6572 else if (varp == &p_enc || gvarp == &p_fenc || varp == &p_tenc
6573 || gvarp == &p_menc)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006574 {
6575 if (gvarp == &p_fenc)
6576 {
Bram Moolenaarf2f70252008-02-13 17:36:06 +00006577 if (!curbuf->b_p_ma && opt_flags != OPT_GLOBAL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006578 errmsg = e_modifiable;
6579 else if (vim_strchr(*varp, ',') != NULL)
6580 /* No comma allowed in 'fileencoding'; catches confusing it
6581 * with 'fileencodings'. */
6582 errmsg = e_invarg;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006583 else
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006584 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006585#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00006586 /* May show a "+" in the title now. */
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006587 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006588#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006589 /* Add 'fileencoding' to the swap file. */
6590 ml_setflags(curbuf);
6591 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006592 }
6593 if (errmsg == NULL)
6594 {
6595 /* canonize the value, so that STRCMP() can be used on it */
6596 p = enc_canonize(*varp);
6597 if (p != NULL)
6598 {
6599 vim_free(*varp);
6600 *varp = p;
6601 }
6602 if (varp == &p_enc)
6603 {
6604 errmsg = mb_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006605#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006606 redraw_titles();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006607#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006608 }
6609 }
6610
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006611#if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006612 if (errmsg == NULL && varp == &p_tenc && gui.in_use)
6613 {
6614 /* GTK+ 2 uses only a single encoding, and that is UTF-8. */
6615 if (STRCMP(p_tenc, "utf-8") != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006616 errmsg = N_("E617: Cannot be changed in the GTK+ 2 GUI");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006617 }
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006618#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006619
6620 if (errmsg == NULL)
6621 {
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006622#ifdef FEAT_KEYMAP
Bram Moolenaar071d4272004-06-13 20:20:40 +00006623 /* When 'keymap' is used and 'encoding' changes, reload the keymap
6624 * (with another encoding). */
6625 if (varp == &p_enc && *curbuf->b_p_keymap != NUL)
6626 (void)keymap_init();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006627#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006628
6629 /* When 'termencoding' is not empty and 'encoding' changes or when
6630 * 'termencoding' changes, need to setup for keyboard input and
6631 * display output conversion. */
6632 if (((varp == &p_enc && *p_tenc != NUL) || varp == &p_tenc))
6633 {
Bram Moolenaar17471e82017-11-26 23:47:18 +01006634 if (convert_setup(&input_conv, p_tenc, p_enc) == FAIL
6635 || convert_setup(&output_conv, p_enc, p_tenc) == FAIL)
6636 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006637 semsg(_("E950: Cannot convert between %s and %s"),
Bram Moolenaar17471e82017-11-26 23:47:18 +01006638 p_tenc, p_enc);
6639 errmsg = e_invarg;
6640 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006641 }
Bram Moolenaar05159a02005-02-26 23:04:13 +00006642
Bram Moolenaar4f974752019-02-17 17:44:42 +01006643#if defined(MSWIN)
Bram Moolenaar05159a02005-02-26 23:04:13 +00006644 /* $HOME may have characters in active code page. */
6645 if (varp == &p_enc)
6646 init_homedir();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01006647#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00006648 }
6649 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006650
6651#if defined(FEAT_POSTSCRIPT)
6652 else if (varp == &p_penc)
6653 {
6654 /* Canonize printencoding if VIM standard one */
6655 p = enc_canonize(p_penc);
6656 if (p != NULL)
6657 {
6658 vim_free(p_penc);
6659 p_penc = p;
6660 }
6661 else
6662 {
6663 /* Ensure lower case and '-' for '_' */
6664 for (s = p_penc; *s != NUL; s++)
6665 {
6666 if (*s == '_')
6667 *s = '-';
6668 else
6669 *s = TOLOWER_ASC(*s);
6670 }
6671 }
6672 }
6673#endif
6674
Bram Moolenaar9372a112005-12-06 19:59:18 +00006675#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006676 else if (varp == &p_imak)
6677 {
Bram Moolenaar86e57922017-04-23 18:44:26 +02006678 if (!im_xim_isvalid_imactivate())
Bram Moolenaar071d4272004-06-13 20:20:40 +00006679 errmsg = e_invarg;
6680 }
6681#endif
6682
6683#ifdef FEAT_KEYMAP
6684 else if (varp == &curbuf->b_p_keymap)
6685 {
Bram Moolenaard0b51382016-11-04 15:23:45 +01006686 if (!valid_filetype(*varp))
6687 errmsg = e_invarg;
6688 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01006689 {
6690 int secure_save = secure;
6691
6692 // Reset the secure flag, since the value of 'keymap' has
6693 // been checked to be safe.
6694 secure = 0;
6695
6696 // load or unload key mapping tables
Bram Moolenaard0b51382016-11-04 15:23:45 +01006697 errmsg = keymap_init();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006698
Bram Moolenaar916a8182018-11-25 02:18:29 +01006699 secure = secure_save;
6700
6701 // Since we check the value, there is no need to set P_INSECURE,
6702 // even when the value comes from a modeline.
6703 *value_checked = TRUE;
6704 }
6705
Bram Moolenaarfab06232009-03-04 03:13:35 +00006706 if (errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006707 {
Bram Moolenaarfab06232009-03-04 03:13:35 +00006708 if (*curbuf->b_p_keymap != NUL)
6709 {
6710 /* Installed a new keymap, switch on using it. */
6711 curbuf->b_p_iminsert = B_IMODE_LMAP;
6712 if (curbuf->b_p_imsearch != B_IMODE_USE_INSERT)
6713 curbuf->b_p_imsearch = B_IMODE_LMAP;
6714 }
6715 else
6716 {
6717 /* Cleared the keymap, may reset 'iminsert' and 'imsearch'. */
6718 if (curbuf->b_p_iminsert == B_IMODE_LMAP)
6719 curbuf->b_p_iminsert = B_IMODE_NONE;
6720 if (curbuf->b_p_imsearch == B_IMODE_LMAP)
6721 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
6722 }
6723 if ((opt_flags & OPT_LOCAL) == 0)
6724 {
6725 set_iminsert_global();
6726 set_imsearch_global();
6727 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006728 status_redraw_curbuf();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006729 }
6730 }
6731#endif
6732
6733 /* 'fileformat' */
6734 else if (gvarp == &p_ff)
6735 {
6736 if (!curbuf->b_p_ma && !(opt_flags & OPT_GLOBAL))
6737 errmsg = e_modifiable;
6738 else if (check_opt_strings(*varp, p_ff_values, FALSE) != OK)
6739 errmsg = e_invarg;
6740 else
6741 {
6742 /* may also change 'textmode' */
6743 if (get_fileformat(curbuf) == EOL_DOS)
6744 curbuf->b_p_tx = TRUE;
6745 else
6746 curbuf->b_p_tx = FALSE;
6747#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00006748 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00006749#endif
Bram Moolenaar1cd871b2004-12-19 22:46:22 +00006750 /* update flag in swap file */
6751 ml_setflags(curbuf);
Bram Moolenaar0413d482010-02-11 17:02:11 +01006752 /* Redraw needed when switching to/from "mac": a CR in the text
6753 * will be displayed differently. */
6754 if (get_fileformat(curbuf) == EOL_MAC || *oldval == 'm')
6755 redraw_curbuf_later(NOT_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00006756 }
6757 }
6758
6759 /* 'fileformats' */
6760 else if (varp == &p_ffs)
6761 {
6762 if (check_opt_strings(p_ffs, p_ff_values, TRUE) != OK)
6763 errmsg = e_invarg;
6764 else
6765 {
6766 /* also change 'textauto' */
6767 if (*p_ffs == NUL)
6768 p_ta = FALSE;
6769 else
6770 p_ta = TRUE;
6771 }
6772 }
6773
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006774#if defined(FEAT_CRYPT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006775 /* 'cryptkey' */
6776 else if (gvarp == &p_key)
6777 {
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006778# if defined(FEAT_CMDHIST)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006779 /* Make sure the ":set" command doesn't show the new value in the
6780 * history. */
6781 remove_key_from_history();
Bram Moolenaara8ffcbb2010-06-21 06:15:46 +02006782# endif
6783 if (STRCMP(curbuf->b_p_key, oldval) != 0)
6784 /* Need to update the swapfile. */
Bram Moolenaarbc563362015-06-09 18:35:25 +02006785 ml_set_crypt_key(curbuf, oldval,
6786 *curbuf->b_p_cm == NUL ? p_cm : curbuf->b_p_cm);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006787 }
6788
6789 else if (gvarp == &p_cm)
6790 {
6791 if (opt_flags & OPT_LOCAL)
6792 p = curbuf->b_p_cm;
6793 else
6794 p = p_cm;
6795 if (check_opt_strings(p, p_cm_values, TRUE) != OK)
6796 errmsg = e_invarg;
Bram Moolenaar8f4ac012014-08-10 13:38:34 +02006797 else if (crypt_self_test() == FAIL)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006798 errmsg = e_invarg;
6799 else
6800 {
6801 /* When setting the global value to empty, make it "zip". */
6802 if (*p_cm == NUL)
6803 {
6804 if (new_value_alloced)
6805 free_string_option(p_cm);
6806 p_cm = vim_strsave((char_u *)"zip");
6807 new_value_alloced = TRUE;
6808 }
Bram Moolenaar2be79502014-08-13 21:58:28 +02006809 /* When using ":set cm=name" the local value is going to be empty.
6810 * Do that here, otherwise the crypt functions will still use the
6811 * local value. */
6812 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
6813 {
6814 free_string_option(curbuf->b_p_cm);
6815 curbuf->b_p_cm = empty_option;
6816 }
Bram Moolenaar49771f42010-07-20 17:32:38 +02006817
6818 /* Need to update the swapfile when the effective method changed.
6819 * Set "s" to the effective old value, "p" to the effective new
6820 * method and compare. */
6821 if ((opt_flags & OPT_LOCAL) && *oldval == NUL)
6822 s = p_cm; /* was previously using the global value */
6823 else
6824 s = oldval;
6825 if (*curbuf->b_p_cm == NUL)
6826 p = p_cm; /* is now using the global value */
6827 else
6828 p = curbuf->b_p_cm;
6829 if (STRCMP(s, p) != 0)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006830 ml_set_crypt_key(curbuf, curbuf->b_p_key, s);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006831
6832 /* If the global value changes need to update the swapfile for all
6833 * buffers using that value. */
6834 if ((opt_flags & OPT_GLOBAL) && STRCMP(p_cm, oldval) != 0)
6835 {
6836 buf_T *buf;
6837
Bram Moolenaar29323592016-07-24 22:04:11 +02006838 FOR_ALL_BUFFERS(buf)
Bram Moolenaar49771f42010-07-20 17:32:38 +02006839 if (buf != curbuf && *buf->b_p_cm == NUL)
Bram Moolenaarbc563362015-06-09 18:35:25 +02006840 ml_set_crypt_key(buf, buf->b_p_key, oldval);
Bram Moolenaar49771f42010-07-20 17:32:38 +02006841 }
6842 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006843 }
6844#endif
6845
6846 /* 'matchpairs' */
6847 else if (gvarp == &p_mps)
6848 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006849 if (has_mbyte)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006850 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006851 for (p = *varp; *p != NUL; ++p)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006852 {
Bram Moolenaar09365022013-01-17 17:37:35 +01006853 int x2 = -1;
6854 int x3 = -1;
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006855
6856 if (*p != NUL)
6857 p += mb_ptr2len(p);
6858 if (*p != NUL)
6859 x2 = *p++;
6860 if (*p != NUL)
6861 {
6862 x3 = mb_ptr2char(p);
6863 p += mb_ptr2len(p);
6864 }
Bram Moolenaar09365022013-01-17 17:37:35 +01006865 if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ','))
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006866 {
6867 errmsg = e_invarg;
6868 break;
6869 }
6870 if (*p == NUL)
6871 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006872 }
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006873 }
6874 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +01006875 {
6876 /* Check for "x:y,x:y" */
6877 for (p = *varp; *p != NUL; p += 4)
6878 {
6879 if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ','))
6880 {
6881 errmsg = e_invarg;
6882 break;
6883 }
6884 if (p[3] == NUL)
6885 break;
6886 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006887 }
6888 }
6889
6890#ifdef FEAT_COMMENTS
6891 /* 'comments' */
6892 else if (gvarp == &p_com)
6893 {
6894 for (s = *varp; *s; )
6895 {
6896 while (*s && *s != ':')
6897 {
6898 if (vim_strchr((char_u *)COM_ALL, *s) == NULL
6899 && !VIM_ISDIGIT(*s) && *s != '-')
6900 {
6901 errmsg = illegal_char(errbuf, *s);
6902 break;
6903 }
6904 ++s;
6905 }
6906 if (*s++ == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006907 errmsg = N_("E524: Missing colon");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006908 else if (*s == ',' || *s == NUL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006909 errmsg = N_("E525: Zero length string");
Bram Moolenaar071d4272004-06-13 20:20:40 +00006910 if (errmsg != NULL)
6911 break;
6912 while (*s && *s != ',')
6913 {
6914 if (*s == '\\' && s[1] != NUL)
6915 ++s;
6916 ++s;
6917 }
6918 s = skip_to_option_part(s);
6919 }
6920 }
6921#endif
6922
6923 /* 'listchars' */
6924 else if (varp == &p_lcs)
6925 {
6926 errmsg = set_chars_option(varp);
6927 }
6928
Bram Moolenaar071d4272004-06-13 20:20:40 +00006929 /* 'fillchars' */
6930 else if (varp == &p_fcs)
6931 {
6932 errmsg = set_chars_option(varp);
6933 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00006934
6935#ifdef FEAT_CMDWIN
6936 /* 'cedit' */
6937 else if (varp == &p_cedit)
6938 {
6939 errmsg = check_cedit();
6940 }
6941#endif
6942
Bram Moolenaar54ee7752005-05-31 22:22:17 +00006943 /* 'verbosefile' */
6944 else if (varp == &p_vfile)
6945 {
6946 verbose_stop();
6947 if (*p_vfile != NUL && verbose_open() == FAIL)
6948 errmsg = e_invarg;
6949 }
6950
Bram Moolenaar071d4272004-06-13 20:20:40 +00006951#ifdef FEAT_VIMINFO
6952 /* 'viminfo' */
6953 else if (varp == &p_viminfo)
6954 {
6955 for (s = p_viminfo; *s;)
6956 {
6957 /* Check it's a valid character */
6958 if (vim_strchr((char_u *)"!\"%'/:<@cfhnrs", *s) == NULL)
6959 {
6960 errmsg = illegal_char(errbuf, *s);
6961 break;
6962 }
6963 if (*s == 'n') /* name is always last one */
Bram Moolenaar071d4272004-06-13 20:20:40 +00006964 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +00006965 else if (*s == 'r') /* skip until next ',' */
6966 {
6967 while (*++s && *s != ',')
6968 ;
6969 }
Bram Moolenaar15d0a8c2004-09-06 17:44:46 +00006970 else if (*s == '%')
6971 {
6972 /* optional number */
6973 while (vim_isdigit(*++s))
6974 ;
6975 }
6976 else if (*s == '!' || *s == 'h' || *s == 'c')
Bram Moolenaar071d4272004-06-13 20:20:40 +00006977 ++s; /* no extra chars */
6978 else /* must have a number */
6979 {
6980 while (vim_isdigit(*++s))
6981 ;
6982
6983 if (!VIM_ISDIGIT(*(s - 1)))
6984 {
6985 if (errbuf != NULL)
6986 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006987 sprintf(errbuf, _("E526: Missing number after <%s>"),
Bram Moolenaar071d4272004-06-13 20:20:40 +00006988 transchar_byte(*(s - 1)));
6989 errmsg = errbuf;
6990 }
6991 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01006992 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00006993 break;
6994 }
6995 }
6996 if (*s == ',')
6997 ++s;
6998 else if (*s)
6999 {
7000 if (errbuf != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007001 errmsg = N_("E527: Missing comma");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007002 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007003 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007004 break;
7005 }
7006 }
7007 if (*p_viminfo && errmsg == NULL && get_viminfo_parameter('\'') < 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007008 errmsg = N_("E528: Must specify a ' value");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007009 }
7010#endif /* FEAT_VIMINFO */
7011
7012 /* terminal options */
7013 else if (istermoption(&options[opt_idx]) && full_screen)
7014 {
7015 /* ":set t_Co=0" and ":set t_Co=1" do ":set t_Co=" */
7016 if (varp == &T_CCO)
7017 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00007018 int colors = atoi((char *)T_CCO);
7019
7020 /* Only reinitialize colors if t_Co value has really changed to
7021 * avoid expensive reload of colorscheme if t_Co is set to the
7022 * same value multiple times. */
7023 if (colors != t_colors)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007024 {
Bram Moolenaarc84e8952009-03-18 13:21:18 +00007025 t_colors = colors;
7026 if (t_colors <= 1)
7027 {
7028 if (new_value_alloced)
7029 vim_free(T_CCO);
7030 T_CCO = empty_option;
7031 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02007032#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
7033 if (is_term_win32())
7034 {
7035 swap_tcap();
7036 did_swaptcap = TRUE;
7037 }
7038#endif
Bram Moolenaarc84e8952009-03-18 13:21:18 +00007039 /* We now have a different color setup, initialize it again. */
7040 init_highlight(TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007041 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007042 }
7043 ttest(FALSE);
7044 if (varp == &T_ME)
7045 {
7046 out_str(T_ME);
7047 redraw_later(CLEAR);
Bram Moolenaarafde13b2019-04-28 19:46:49 +02007048#if defined(MSWIN) && (!defined(FEAT_GUI_MSWIN) || defined(VIMDLL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007049 /* Since t_me has been set, this probably means that the user
7050 * wants to use this as default colors. Need to reset default
7051 * background/foreground colors. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02007052# ifdef VIMDLL
7053 if (!gui.in_use && !gui.starting)
7054# endif
7055 mch_set_normal_colors();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007056#endif
7057 }
Bram Moolenaard9c60642017-01-27 20:03:18 +01007058 if (varp == &T_BE && termcap_active)
7059 {
7060 if (*T_BE == NUL)
7061 /* When clearing t_BE we assume the user no longer wants
7062 * bracketed paste, thus disable it by writing t_BD. */
7063 out_str(T_BD);
7064 else
7065 out_str(T_BE);
7066 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007067 }
7068
7069#ifdef FEAT_LINEBREAK
7070 /* 'showbreak' */
7071 else if (varp == &p_sbr)
7072 {
7073 for (s = p_sbr; *s; )
7074 {
7075 if (ptr2cells(s) != 1)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007076 errmsg = N_("E595: contains unprintable or wide character");
Bram Moolenaar91acfff2017-03-12 19:22:36 +01007077 MB_PTR_ADV(s);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007078 }
7079 }
7080#endif
7081
7082#ifdef FEAT_GUI
7083 /* 'guifont' */
7084 else if (varp == &p_guifont)
7085 {
7086 if (gui.in_use)
7087 {
7088 p = p_guifont;
Bram Moolenaar9372a112005-12-06 19:59:18 +00007089# if defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007090 /*
7091 * Put up a font dialog and let the user select a new value.
7092 * If this is cancelled go back to the old value but don't
7093 * give an error message.
7094 */
7095 if (STRCMP(p, "*") == 0)
7096 {
7097 p = gui_mch_font_dialog(oldval);
7098
7099 if (new_value_alloced)
7100 free_string_option(p_guifont);
7101
7102 p_guifont = (p != NULL) ? p : vim_strsave(oldval);
7103 new_value_alloced = TRUE;
7104 }
7105# endif
7106 if (p != NULL && gui_init_font(p_guifont, FALSE) != OK)
7107 {
7108# if defined(FEAT_GUI_MSWIN) || defined(FEAT_GUI_PHOTON)
7109 if (STRCMP(p_guifont, "*") == 0)
7110 {
7111 /* Dialog was cancelled: Keep the old value without giving
7112 * an error message. */
7113 if (new_value_alloced)
7114 free_string_option(p_guifont);
7115 p_guifont = vim_strsave(oldval);
7116 new_value_alloced = TRUE;
7117 }
7118 else
7119# endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007120 errmsg = N_("E596: Invalid font(s)");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007121 }
7122 }
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007123 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007124 }
7125# ifdef FEAT_XFONTSET
7126 else if (varp == &p_guifontset)
7127 {
7128 if (STRCMP(p_guifontset, "*") == 0)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007129 errmsg = N_("E597: can't select fontset");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007130 else if (gui.in_use && gui_init_font(p_guifontset, TRUE) != OK)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007131 errmsg = N_("E598: Invalid fontset");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007132 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007133 }
7134# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007135 else if (varp == &p_guifontwide)
7136 {
7137 if (STRCMP(p_guifontwide, "*") == 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007138 errmsg = N_("E533: can't select wide font");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007139 else if (gui_get_wide_font() == FAIL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007140 errmsg = N_("E534: Invalid wide font");
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007141 redraw_gui_only = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00007142 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007143#endif
7144
7145#ifdef CURSOR_SHAPE
7146 /* 'guicursor' */
7147 else if (varp == &p_guicursor)
7148 errmsg = parse_shape_opt(SHAPE_CURSOR);
7149#endif
7150
7151#ifdef FEAT_MOUSESHAPE
7152 /* 'mouseshape' */
7153 else if (varp == &p_mouseshape)
7154 {
7155 errmsg = parse_shape_opt(SHAPE_MOUSE);
7156 update_mouseshape(-1);
7157 }
7158#endif
7159
7160#ifdef FEAT_PRINTER
7161 else if (varp == &p_popt)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007162 errmsg = parse_printoptions();
Bram Moolenaarfc3abf42019-01-24 15:54:21 +01007163# if defined(FEAT_POSTSCRIPT)
Bram Moolenaar8299df92004-07-10 09:47:34 +00007164 else if (varp == &p_pmfn)
Bram Moolenaar58d98232005-07-23 22:25:46 +00007165 errmsg = parse_printmbfont();
Bram Moolenaar8299df92004-07-10 09:47:34 +00007166# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007167#endif
7168
7169#ifdef FEAT_LANGMAP
7170 /* 'langmap' */
7171 else if (varp == &p_langmap)
7172 langmap_set();
7173#endif
7174
7175#ifdef FEAT_LINEBREAK
7176 /* 'breakat' */
7177 else if (varp == &p_breakat)
7178 fill_breakat_flags();
7179#endif
7180
7181#ifdef FEAT_TITLE
7182 /* 'titlestring' and 'iconstring' */
7183 else if (varp == &p_titlestring || varp == &p_iconstring)
7184 {
7185# ifdef FEAT_STL_OPT
7186 int flagval = (varp == &p_titlestring) ? STL_IN_TITLE : STL_IN_ICON;
7187
7188 /* NULL => statusline syntax */
7189 if (vim_strchr(*varp, '%') && check_stl_option(*varp) == NULL)
7190 stl_syntax |= flagval;
7191 else
7192 stl_syntax &= ~flagval;
7193# endif
Bram Moolenaar84a93082018-06-16 22:58:15 +02007194 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00007195 }
7196#endif
7197
7198#ifdef FEAT_GUI
7199 /* 'guioptions' */
7200 else if (varp == &p_go)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007201 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007202 gui_init_which_components(oldval);
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007203 redraw_gui_only = TRUE;
7204 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007205#endif
7206
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007207#if defined(FEAT_GUI_TABLINE)
7208 /* 'guitablabel' */
7209 else if (varp == &p_gtl)
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007210 {
Bram Moolenaar18144c82006-04-12 21:52:12 +00007211 redraw_tabline = TRUE;
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00007212 redraw_gui_only = TRUE;
7213 }
7214 /* 'guitabtooltip' */
7215 else if (varp == &p_gtt)
7216 {
7217 redraw_gui_only = TRUE;
7218 }
Bram Moolenaar5c8837f2006-02-25 21:52:33 +00007219#endif
7220
Bram Moolenaar071d4272004-06-13 20:20:40 +00007221#if defined(FEAT_MOUSE_TTY) && (defined(UNIX) || defined(VMS))
7222 /* 'ttymouse' */
7223 else if (varp == &p_ttym)
7224 {
Bram Moolenaarf1f8bc52005-03-07 23:20:08 +00007225 /* Switch the mouse off before changing the escape sequences used for
7226 * that. */
7227 mch_setmouse(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007228 if (opt_strings_flags(p_ttym, p_ttym_values, &ttym_flags, FALSE) != OK)
7229 errmsg = e_invarg;
7230 else
7231 check_mouse_termcode();
Bram Moolenaar6bb68362005-03-22 23:03:44 +00007232 if (termcap_active)
7233 setmouse(); /* may switch it on again */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007234 }
7235#endif
7236
Bram Moolenaar071d4272004-06-13 20:20:40 +00007237 /* 'selection' */
7238 else if (varp == &p_sel)
7239 {
7240 if (*p_sel == NUL
7241 || check_opt_strings(p_sel, p_sel_values, FALSE) != OK)
7242 errmsg = e_invarg;
7243 }
7244
7245 /* 'selectmode' */
7246 else if (varp == &p_slm)
7247 {
7248 if (check_opt_strings(p_slm, p_slm_values, TRUE) != OK)
7249 errmsg = e_invarg;
7250 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007251
7252#ifdef FEAT_BROWSE
7253 /* 'browsedir' */
7254 else if (varp == &p_bsdir)
7255 {
7256 if (check_opt_strings(p_bsdir, p_bsdir_values, FALSE) != OK
7257 && !mch_isdir(p_bsdir))
7258 errmsg = e_invarg;
7259 }
7260#endif
7261
Bram Moolenaar071d4272004-06-13 20:20:40 +00007262 /* 'keymodel' */
7263 else if (varp == &p_km)
7264 {
7265 if (check_opt_strings(p_km, p_km_values, TRUE) != OK)
7266 errmsg = e_invarg;
7267 else
7268 {
7269 km_stopsel = (vim_strchr(p_km, 'o') != NULL);
7270 km_startsel = (vim_strchr(p_km, 'a') != NULL);
7271 }
7272 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007273
7274 /* 'mousemodel' */
7275 else if (varp == &p_mousem)
7276 {
7277 if (check_opt_strings(p_mousem, p_mousem_values, FALSE) != OK)
7278 errmsg = e_invarg;
7279#if defined(FEAT_GUI_MOTIF) && defined(FEAT_MENU) && (XmVersion <= 1002)
7280 else if (*p_mousem != *oldval)
7281 /* Changed from "extend" to "popup" or "popup_setpos" or vv: need
7282 * to create or delete the popup menus. */
7283 gui_motif_update_mousemodel(root_menu);
7284#endif
7285 }
7286
7287 /* 'switchbuf' */
7288 else if (varp == &p_swb)
7289 {
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00007290 if (opt_strings_flags(p_swb, p_swb_values, &swb_flags, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007291 errmsg = e_invarg;
7292 }
7293
7294 /* 'debug' */
7295 else if (varp == &p_debug)
7296 {
Bram Moolenaar57657d82006-04-21 22:12:41 +00007297 if (check_opt_strings(p_debug, p_debug_values, TRUE) != OK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007298 errmsg = e_invarg;
7299 }
7300
7301 /* 'display' */
7302 else if (varp == &p_dy)
7303 {
7304 if (opt_strings_flags(p_dy, p_dy_values, &dy_flags, TRUE) != OK)
7305 errmsg = e_invarg;
7306 else
7307 (void)init_chartab();
7308
7309 }
7310
Bram Moolenaar071d4272004-06-13 20:20:40 +00007311 /* 'eadirection' */
7312 else if (varp == &p_ead)
7313 {
7314 if (check_opt_strings(p_ead, p_ead_values, FALSE) != OK)
7315 errmsg = e_invarg;
7316 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007317
7318#ifdef FEAT_CLIPBOARD
7319 /* 'clipboard' */
7320 else if (varp == &p_cb)
7321 errmsg = check_clipboard_option();
7322#endif
7323
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007324#ifdef FEAT_SPELL
Bram Moolenaar9ba0eb82005-06-13 22:28:56 +00007325 /* When 'spelllang' or 'spellfile' is set and there is a window for this
7326 * buffer in which 'spell' is set load the wordlists. */
Bram Moolenaar2683c8e2014-11-19 19:33:16 +01007327 else if (varp == &(curwin->w_s->b_p_spl)
7328 || varp == &(curwin->w_s->b_p_spf))
Bram Moolenaar217ad922005-03-20 22:37:15 +00007329 {
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007330 int is_spellfile = varp == &(curwin->w_s->b_p_spf);
7331
7332 if ((is_spellfile && !valid_spellfile(*varp))
7333 || (!is_spellfile && !valid_spellang(*varp)))
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02007334 errmsg = e_invarg;
7335 else
Bram Moolenaar862f1e12019-04-10 22:33:41 +02007336 errmsg = did_set_spell_option(is_spellfile);
Bram Moolenaar217ad922005-03-20 22:37:15 +00007337 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007338 /* When 'spellcapcheck' is set compile the regexp program. */
Bram Moolenaar860cae12010-06-05 23:22:07 +02007339 else if (varp == &(curwin->w_s->b_p_spc))
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007340 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02007341 errmsg = compile_cap_prog(curwin->w_s);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00007342 }
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007343 /* 'spellsuggest' */
7344 else if (varp == &p_sps)
7345 {
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +00007346 if (spell_check_sps() != OK)
Bram Moolenaard857f0e2005-06-21 22:37:39 +00007347 errmsg = e_invarg;
7348 }
Bram Moolenaar8aff23a2005-08-19 20:40:30 +00007349 /* 'mkspellmem' */
7350 else if (varp == &p_msm)
7351 {
7352 if (spell_check_msm() != OK)
7353 errmsg = e_invarg;
7354 }
Bram Moolenaar217ad922005-03-20 22:37:15 +00007355#endif
7356
Bram Moolenaar071d4272004-06-13 20:20:40 +00007357 /* When 'bufhidden' is set, check for valid value. */
7358 else if (gvarp == &p_bh)
7359 {
7360 if (check_opt_strings(curbuf->b_p_bh, p_bufhidden_values, FALSE) != OK)
7361 errmsg = e_invarg;
7362 }
7363
7364 /* When 'buftype' is set, check for valid value. */
7365 else if (gvarp == &p_bt)
7366 {
7367 if (check_opt_strings(curbuf->b_p_bt, p_buftype_values, FALSE) != OK)
7368 errmsg = e_invarg;
7369 else
7370 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007371 if (curwin->w_status_height)
7372 {
7373 curwin->w_redr_status = TRUE;
7374 redraw_later(VALID);
7375 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007376 curbuf->b_help = (curbuf->b_p_bt[0] == 'h');
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007377#ifdef FEAT_TITLE
Bram Moolenaar5075aad2010-01-27 15:58:13 +01007378 redraw_titles();
Bram Moolenaar1f2903c2017-07-23 19:51:01 +02007379#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00007380 }
7381 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007382
7383#ifdef FEAT_STL_OPT
7384 /* 'statusline' or 'rulerformat' */
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007385 else if (gvarp == &p_stl || varp == &p_ruf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007386 {
7387 int wid;
7388
7389 if (varp == &p_ruf) /* reset ru_wid first */
7390 ru_wid = 0;
7391 s = *varp;
7392 if (varp == &p_ruf && *s == '%')
7393 {
7394 /* set ru_wid if 'ruf' starts with "%99(" */
7395 if (*++s == '-') /* ignore a '-' */
7396 s++;
7397 wid = getdigits(&s);
7398 if (wid && *s == '(' && (errmsg = check_stl_option(p_ruf)) == NULL)
7399 ru_wid = wid;
7400 else
7401 errmsg = check_stl_option(p_ruf);
7402 }
Bram Moolenaar3709e7c2006-08-08 14:29:16 +00007403 /* check 'statusline' only if it doesn't start with "%!" */
Bram Moolenaar177d8c62007-09-06 11:33:37 +00007404 else if (varp == &p_ruf || s[0] != '%' || s[1] != '!')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007405 errmsg = check_stl_option(s);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +00007406 if (varp == &p_ruf && errmsg == NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007407 comp_col();
7408 }
7409#endif
7410
7411#ifdef FEAT_INS_EXPAND
7412 /* check if it is a valid value for 'complete' -- Acevedo */
7413 else if (gvarp == &p_cpt)
7414 {
7415 for (s = *varp; *s;)
7416 {
Bram Moolenaar11b73d62012-06-29 15:51:30 +02007417 while (*s == ',' || *s == ' ')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007418 s++;
7419 if (!*s)
7420 break;
7421 if (vim_strchr((char_u *)".wbuksid]tU", *s) == NULL)
7422 {
7423 errmsg = illegal_char(errbuf, *s);
7424 break;
7425 }
7426 if (*++s != NUL && *s != ',' && *s != ' ')
7427 {
7428 if (s[-1] == 'k' || s[-1] == 's')
7429 {
7430 /* skip optional filename after 'k' and 's' */
7431 while (*s && *s != ',' && *s != ' ')
7432 {
Bram Moolenaar226c5342017-02-17 14:53:15 +01007433 if (*s == '\\' && s[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007434 ++s;
7435 ++s;
7436 }
7437 }
7438 else
7439 {
7440 if (errbuf != NULL)
7441 {
7442 sprintf((char *)errbuf,
7443 _("E535: Illegal character after <%c>"),
7444 *--s);
7445 errmsg = errbuf;
7446 }
7447 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007448 errmsg = "";
Bram Moolenaar071d4272004-06-13 20:20:40 +00007449 break;
7450 }
7451 }
7452 }
7453 }
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007454
7455 /* 'completeopt' */
7456 else if (varp == &p_cot)
7457 {
7458 if (check_opt_strings(p_cot, p_cot_values, TRUE) != OK)
7459 errmsg = e_invarg;
Bram Moolenaarc0200422016-04-20 12:02:02 +02007460 else
7461 completeopt_was_set();
Bram Moolenaar1c7715d2005-10-03 22:02:18 +00007462 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007463#endif /* FEAT_INS_EXPAND */
7464
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007465#ifdef FEAT_SIGNS
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007466 // 'signcolumn'
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007467 else if (varp == &curwin->w_p_scl)
7468 {
7469 if (check_opt_strings(*varp, p_scl_values, FALSE) != OK)
7470 errmsg = e_invarg;
Bram Moolenaare4b407f2019-07-04 11:59:28 +02007471 // When changing the 'signcolumn' to or from 'number', recompute the
7472 // width of the number column if 'number' or 'relativenumber' is set.
7473 if (((*oldval == 'n' && *(oldval + 1) == 'u')
7474 || (*curwin->w_p_scl == 'n' && *(curwin->w_p_scl + 1) =='u'))
7475 && (curwin->w_p_nu || curwin->w_p_rnu))
7476 curwin->w_nrwidth_line_count = 0;
Bram Moolenaar95ec9d62016-08-12 18:29:59 +02007477 }
7478#endif
7479
Bram Moolenaar071d4272004-06-13 20:20:40 +00007480
Bram Moolenaar4f974752019-02-17 17:44:42 +01007481#if defined(FEAT_TOOLBAR) && !defined(FEAT_GUI_MSWIN)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007482 /* 'toolbar' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007483 else if (varp == &p_toolbar)
7484 {
7485 if (opt_strings_flags(p_toolbar, p_toolbar_values,
7486 &toolbar_flags, TRUE) != OK)
7487 errmsg = e_invarg;
7488 else
7489 {
7490 out_flush();
7491 gui_mch_show_toolbar((toolbar_flags &
7492 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7493 }
7494 }
7495#endif
7496
Bram Moolenaar182c5be2010-06-25 05:37:59 +02007497#if defined(FEAT_TOOLBAR) && defined(FEAT_GUI_GTK)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007498 /* 'toolbariconsize': GTK+ 2 only */
7499 else if (varp == &p_tbis)
7500 {
7501 if (opt_strings_flags(p_tbis, p_tbis_values, &tbis_flags, FALSE) != OK)
7502 errmsg = e_invarg;
7503 else
7504 {
7505 out_flush();
7506 gui_mch_show_toolbar((toolbar_flags &
7507 (TOOLBAR_TEXT | TOOLBAR_ICONS)) != 0);
7508 }
7509 }
7510#endif
7511
7512 /* 'pastetoggle': translate key codes like in a mapping */
7513 else if (varp == &p_pt)
7514 {
7515 if (*p_pt)
7516 {
Bram Moolenaar9c102382006-05-03 21:26:49 +00007517 (void)replace_termcodes(p_pt, &p, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007518 if (p != NULL)
7519 {
7520 if (new_value_alloced)
7521 free_string_option(p_pt);
7522 p_pt = p;
7523 new_value_alloced = TRUE;
7524 }
7525 }
7526 }
7527
7528 /* 'backspace' */
7529 else if (varp == &p_bs)
7530 {
7531 if (VIM_ISDIGIT(*p_bs))
7532 {
Bram Moolenaare7fedb62015-12-31 19:07:19 +01007533 if (*p_bs > '2' || p_bs[1] != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007534 errmsg = e_invarg;
7535 }
7536 else if (check_opt_strings(p_bs, p_bs_values, TRUE) != OK)
7537 errmsg = e_invarg;
7538 }
Bram Moolenaar165bc692015-07-21 17:53:25 +02007539 else if (varp == &p_bo)
7540 {
7541 if (opt_strings_flags(p_bo, p_bo_values, &bo_flags, TRUE) != OK)
7542 errmsg = e_invarg;
7543 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007544
Bram Moolenaar0f6562e2015-11-24 18:48:14 +01007545 /* 'tagcase' */
7546 else if (gvarp == &p_tc)
7547 {
7548 unsigned int *flags;
7549
7550 if (opt_flags & OPT_LOCAL)
7551 {
7552 p = curbuf->b_p_tc;
7553 flags = &curbuf->b_tc_flags;
7554 }
7555 else
7556 {
7557 p = p_tc;
7558 flags = &tc_flags;
7559 }
7560
7561 if ((opt_flags & OPT_LOCAL) && *p == NUL)
7562 /* make the local value empty: use the global value */
7563 *flags = 0;
7564 else if (*p == NUL
7565 || opt_strings_flags(p, p_tc_values, flags, FALSE) != OK)
7566 errmsg = e_invarg;
7567 }
7568
Bram Moolenaar071d4272004-06-13 20:20:40 +00007569 /* 'casemap' */
7570 else if (varp == &p_cmp)
7571 {
7572 if (opt_strings_flags(p_cmp, p_cmp_values, &cmp_flags, TRUE) != OK)
7573 errmsg = e_invarg;
7574 }
7575
7576#ifdef FEAT_DIFF
7577 /* 'diffopt' */
7578 else if (varp == &p_dip)
7579 {
7580 if (diffopt_changed() == FAIL)
7581 errmsg = e_invarg;
7582 }
7583#endif
7584
7585#ifdef FEAT_FOLDING
7586 /* 'foldmethod' */
7587 else if (gvarp == &curwin->w_allbuf_opt.wo_fdm)
7588 {
7589 if (check_opt_strings(*varp, p_fdm_values, FALSE) != OK
7590 || *curwin->w_p_fdm == NUL)
7591 errmsg = e_invarg;
7592 else
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007593 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00007594 foldUpdateAll(curwin);
Bram Moolenaarf4d7f942010-02-24 14:34:19 +01007595 if (foldmethodIsDiff(curwin))
7596 newFoldLevel();
7597 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007598 }
7599# ifdef FEAT_EVAL
7600 /* 'foldexpr' */
7601 else if (varp == &curwin->w_p_fde)
7602 {
7603 if (foldmethodIsExpr(curwin))
7604 foldUpdateAll(curwin);
7605 }
7606# endif
7607 /* 'foldmarker' */
7608 else if (gvarp == &curwin->w_allbuf_opt.wo_fmr)
7609 {
7610 p = vim_strchr(*varp, ',');
7611 if (p == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007612 errmsg = N_("E536: comma required");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007613 else if (p == *varp || p[1] == NUL)
7614 errmsg = e_invarg;
7615 else if (foldmethodIsMarker(curwin))
7616 foldUpdateAll(curwin);
7617 }
7618 /* 'commentstring' */
7619 else if (gvarp == &p_cms)
7620 {
7621 if (**varp != NUL && strstr((char *)*varp, "%s") == NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01007622 errmsg = N_("E537: 'commentstring' must be empty or contain %s");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007623 }
7624 /* 'foldopen' */
7625 else if (varp == &p_fdo)
7626 {
7627 if (opt_strings_flags(p_fdo, p_fdo_values, &fdo_flags, TRUE) != OK)
7628 errmsg = e_invarg;
7629 }
7630 /* 'foldclose' */
7631 else if (varp == &p_fcl)
7632 {
7633 if (check_opt_strings(p_fcl, p_fcl_values, TRUE) != OK)
7634 errmsg = e_invarg;
7635 }
Bram Moolenaar7fc904b2006-04-13 20:37:35 +00007636 /* 'foldignore' */
7637 else if (gvarp == &curwin->w_allbuf_opt.wo_fdi)
7638 {
7639 if (foldmethodIsIndent(curwin))
7640 foldUpdateAll(curwin);
7641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007642#endif
7643
Bram Moolenaar071d4272004-06-13 20:20:40 +00007644 /* 'virtualedit' */
7645 else if (varp == &p_ve)
7646 {
7647 if (opt_strings_flags(p_ve, p_ve_values, &ve_flags, TRUE) != OK)
7648 errmsg = e_invarg;
7649 else if (STRCMP(p_ve, oldval) != 0)
7650 {
7651 /* Recompute cursor position in case the new 've' setting
7652 * changes something. */
7653 validate_virtcol();
7654 coladvance(curwin->w_virtcol);
7655 }
7656 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00007657
7658#if defined(FEAT_CSCOPE) && defined(FEAT_QUICKFIX)
7659 else if (varp == &p_csqf)
7660 {
7661 if (p_csqf != NULL)
7662 {
7663 p = p_csqf;
7664 while (*p != NUL)
7665 {
7666 if (vim_strchr((char_u *)CSQF_CMDS, *p) == NULL
7667 || p[1] == NUL
7668 || vim_strchr((char_u *)CSQF_FLAGS, p[1]) == NULL
7669 || (p[2] != NUL && p[2] != ','))
7670 {
7671 errmsg = e_invarg;
7672 break;
7673 }
7674 else if (p[2] == NUL)
7675 break;
7676 else
7677 p += 3;
7678 }
7679 }
7680 }
7681#endif
7682
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01007683#ifdef FEAT_CINDENT
7684 /* 'cinoptions' */
7685 else if (gvarp == &p_cino)
7686 {
7687 /* TODO: recognize errors */
7688 parse_cino(curbuf);
7689 }
7690#endif
7691
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007692#if defined(FEAT_RENDER_OPTIONS)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007693 /* 'renderoptions' */
Bram Moolenaar3767c6e2017-12-05 16:57:56 +01007694 else if (varp == &p_rop)
Bram Moolenaarb5a7a8b2014-08-06 14:52:30 +02007695 {
7696 if (!gui_mch_set_rendering_options(p_rop))
7697 errmsg = e_invarg;
7698 }
7699#endif
7700
Bram Moolenaard0b51382016-11-04 15:23:45 +01007701 else if (gvarp == &p_ft)
7702 {
7703 if (!valid_filetype(*varp))
7704 errmsg = e_invarg;
Bram Moolenaar90492982017-06-22 14:16:31 +02007705 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007706 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007707 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007708
7709 // Since we check the value, there is no need to set P_INSECURE,
7710 // even when the value comes from a modeline.
7711 *value_checked = TRUE;
7712 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007713 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007714
7715#ifdef FEAT_SYN_HL
7716 else if (gvarp == &p_syn)
7717 {
7718 if (!valid_filetype(*varp))
7719 errmsg = e_invarg;
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007720 else
Bram Moolenaar916a8182018-11-25 02:18:29 +01007721 {
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007722 value_changed = STRCMP(oldval, *varp) != 0;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007723
7724 // Since we check the value, there is no need to set P_INSECURE,
7725 // even when the value comes from a modeline.
7726 *value_checked = TRUE;
7727 }
Bram Moolenaard0b51382016-11-04 15:23:45 +01007728 }
7729#endif
7730
Bram Moolenaar825680f2017-07-22 17:04:02 +02007731#ifdef FEAT_TERMINAL
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007732 // 'termwinkey'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007733 else if (varp == &curwin->w_p_twk)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007734 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007735 if (*curwin->w_p_twk != NUL
7736 && string_to_key(curwin->w_p_twk, TRUE) == 0)
Bram Moolenaardbe948d2017-07-23 22:50:51 +02007737 errmsg = e_invarg;
7738 }
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007739 // 'termwinsize'
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007740 else if (varp == &curwin->w_p_tws)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007741 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007742 if (*curwin->w_p_tws != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007743 {
Bram Moolenaar6d150f72018-04-21 20:03:20 +02007744 p = skipdigits(curwin->w_p_tws);
7745 if (p == curwin->w_p_tws
Bram Moolenaar498c2562018-04-15 23:45:15 +02007746 || (*p != 'x' && *p != '*')
7747 || *skipdigits(p + 1) != NUL)
Bram Moolenaar825680f2017-07-22 17:04:02 +02007748 errmsg = e_invarg;
7749 }
7750 }
Bram Moolenaar4f974752019-02-17 17:44:42 +01007751# if defined(MSWIN)
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007752 // 'termwintype'
7753 else if (varp == &p_twt)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007754 {
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007755 if (check_opt_strings(*varp, p_twt_values, FALSE) != OK)
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01007756 errmsg = e_invarg;
7757 }
Bram Moolenaarc6ddce32019-02-08 12:47:03 +01007758# endif
Bram Moolenaar825680f2017-07-22 17:04:02 +02007759#endif
7760
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007761#ifdef FEAT_VARTABS
7762 /* 'varsofttabstop' */
7763 else if (varp == &(curbuf->b_p_vsts))
7764 {
7765 char_u *cp;
7766
7767 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7768 {
7769 if (curbuf->b_p_vsts_array)
7770 {
7771 vim_free(curbuf->b_p_vsts_array);
7772 curbuf->b_p_vsts_array = 0;
7773 }
7774 }
7775 else
7776 {
7777 for (cp = *varp; *cp; ++cp)
7778 {
7779 if (vim_isdigit(*cp))
7780 continue;
7781 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7782 continue;
7783 errmsg = e_invarg;
7784 break;
7785 }
7786 if (errmsg == NULL)
7787 {
7788 int *oldarray = curbuf->b_p_vsts_array;
7789 if (tabstop_set(*varp, &(curbuf->b_p_vsts_array)))
7790 {
7791 if (oldarray)
7792 vim_free(oldarray);
7793 }
7794 else
7795 errmsg = e_invarg;
7796 }
7797 }
7798 }
7799
7800 /* 'vartabstop' */
7801 else if (varp == &(curbuf->b_p_vts))
7802 {
7803 char_u *cp;
7804
7805 if (!(*varp)[0] || ((*varp)[0] == '0' && !(*varp)[1]))
7806 {
7807 if (curbuf->b_p_vts_array)
7808 {
7809 vim_free(curbuf->b_p_vts_array);
7810 curbuf->b_p_vts_array = NULL;
7811 }
7812 }
7813 else
7814 {
7815 for (cp = *varp; *cp; ++cp)
7816 {
7817 if (vim_isdigit(*cp))
7818 continue;
7819 if (*cp == ',' && cp > *varp && *(cp-1) != ',')
7820 continue;
7821 errmsg = e_invarg;
7822 break;
7823 }
7824 if (errmsg == NULL)
7825 {
7826 int *oldarray = curbuf->b_p_vts_array;
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007827
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007828 if (tabstop_set(*varp, &(curbuf->b_p_vts_array)))
7829 {
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007830 vim_free(oldarray);
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007831#ifdef FEAT_FOLDING
7832 if (foldmethodIsIndent(curwin))
7833 foldUpdateAll(curwin);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +01007834#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +02007835 }
7836 else
7837 errmsg = e_invarg;
7838 }
7839 }
7840 }
7841#endif
7842
Bram Moolenaar79648732019-07-18 21:43:07 +02007843#ifdef FEAT_TEXT_PROP
7844 // 'previewpopup'
7845 else if (varp == &p_pvp)
7846 {
7847 if (parse_previewpopup(NULL) == FAIL)
7848 errmsg = e_invarg;
7849 }
7850#endif
7851
Bram Moolenaar071d4272004-06-13 20:20:40 +00007852 /* Options that are a list of flags. */
7853 else
7854 {
7855 p = NULL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007856 if (varp == &p_ww) /* 'whichwrap' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007857 p = (char_u *)WW_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007858 if (varp == &p_shm) /* 'shortmess' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007859 p = (char_u *)SHM_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007860 else if (varp == &(p_cpo)) /* 'cpoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007861 p = (char_u *)CPO_ALL;
Bram Moolenaar031cb742016-11-24 21:46:19 +01007862 else if (varp == &(curbuf->b_p_fo)) /* 'formatoptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007863 p = (char_u *)FO_ALL;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007864#ifdef FEAT_CONCEAL
Bram Moolenaar031cb742016-11-24 21:46:19 +01007865 else if (varp == &curwin->w_p_cocu) /* 'concealcursor' */
Bram Moolenaarf5963f72010-07-23 22:10:27 +02007866 p = (char_u *)COCU_ALL;
7867#endif
Bram Moolenaar031cb742016-11-24 21:46:19 +01007868 else if (varp == &p_mouse) /* 'mouse' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007869 {
7870#ifdef FEAT_MOUSE
7871 p = (char_u *)MOUSE_ALL;
7872#else
7873 if (*p_mouse != NUL)
Bram Moolenaarb1443b42019-01-13 23:51:14 +01007874 errmsg = N_("E538: No mouse support");
Bram Moolenaar071d4272004-06-13 20:20:40 +00007875#endif
7876 }
7877#if defined(FEAT_GUI)
Bram Moolenaar031cb742016-11-24 21:46:19 +01007878 else if (varp == &p_go) /* 'guioptions' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00007879 p = (char_u *)GO_ALL;
7880#endif
7881 if (p != NULL)
7882 {
7883 for (s = *varp; *s; ++s)
7884 if (vim_strchr(p, *s) == NULL)
7885 {
7886 errmsg = illegal_char(errbuf, *s);
7887 break;
7888 }
7889 }
7890 }
7891
7892 /*
7893 * If error detected, restore the previous value.
7894 */
7895 if (errmsg != NULL)
7896 {
7897 if (new_value_alloced)
7898 free_string_option(*varp);
7899 *varp = oldval;
7900 /*
7901 * When resetting some values, need to act on it.
7902 */
7903 if (did_chartab)
7904 (void)init_chartab();
7905 if (varp == &p_hl)
7906 (void)highlight_changed();
7907 }
7908 else
7909 {
7910#ifdef FEAT_EVAL
7911 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02007912 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00007913#endif
7914 /*
7915 * Free string options that are in allocated memory.
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007916 * Use "free_oldval", because recursiveness may change the flags under
7917 * our fingers (esp. init_highlight()).
Bram Moolenaar071d4272004-06-13 20:20:40 +00007918 */
Bram Moolenaarc0197e22004-09-13 20:26:32 +00007919 if (free_oldval)
Bram Moolenaar071d4272004-06-13 20:20:40 +00007920 free_string_option(oldval);
7921 if (new_value_alloced)
7922 options[opt_idx].flags |= P_ALLOCED;
7923 else
7924 options[opt_idx].flags &= ~P_ALLOCED;
7925
7926 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0
Bram Moolenaara23ccb82006-02-27 00:08:02 +00007927 && ((int)options[opt_idx].indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +00007928 {
7929 /* global option with local value set to use global value; free
7930 * the local value and make it empty */
7931 p = get_varp_scope(&(options[opt_idx]), OPT_LOCAL);
7932 free_string_option(*(char_u **)p);
7933 *(char_u **)p = empty_option;
7934 }
7935
7936 /* May set global value for local option. */
7937 else if (!(opt_flags & OPT_LOCAL) && opt_flags != OPT_GLOBAL)
7938 set_string_option_global(opt_idx, varp);
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007939
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007940 /*
7941 * Trigger the autocommand only after setting the flags.
7942 */
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007943#ifdef FEAT_SYN_HL
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007944 /* When 'syntax' is set, load the syntax of that name */
7945 if (varp == &(curbuf->b_p_syn))
7946 {
Bram Moolenaara5616b02018-06-17 19:08:30 +02007947 static int syn_recursive = 0;
7948
7949 ++syn_recursive;
7950 // Only pass TRUE for "force" when the value changed or not used
7951 // recursively, to avoid endless recurrence.
7952 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, curbuf->b_fname,
7953 value_changed || syn_recursive == 1, curbuf);
7954 --syn_recursive;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007955 }
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01007956#endif
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007957 else if (varp == &(curbuf->b_p_ft))
7958 {
Bram Moolenaar90492982017-06-22 14:16:31 +02007959 /* 'filetype' is set, trigger the FileType autocommand.
7960 * Skip this when called from a modeline and the filetype was
Bram Moolenaara5616b02018-06-17 19:08:30 +02007961 * already set to this value. */
Bram Moolenaarc3ffc9b2018-06-17 17:32:58 +02007962 if (!(opt_flags & OPT_MODELINE) || value_changed)
Bram Moolenaar90492982017-06-22 14:16:31 +02007963 {
Bram Moolenaar916a8182018-11-25 02:18:29 +01007964 static int ft_recursive = 0;
7965 int secure_save = secure;
7966
7967 // Reset the secure flag, since the value of 'filetype' has
7968 // been checked to be safe.
7969 secure = 0;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007970
7971 ++ft_recursive;
Bram Moolenaar90492982017-06-22 14:16:31 +02007972 did_filetype = TRUE;
Bram Moolenaara5616b02018-06-17 19:08:30 +02007973 // Only pass TRUE for "force" when the value changed or not
7974 // used recursively, to avoid endless recurrence.
7975 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, curbuf->b_fname,
7976 value_changed || ft_recursive == 1, curbuf);
7977 --ft_recursive;
Bram Moolenaar163095f2017-07-09 15:41:53 +02007978 /* Just in case the old "curbuf" is now invalid. */
7979 if (varp != &(curbuf->b_p_ft))
7980 varp = NULL;
Bram Moolenaar916a8182018-11-25 02:18:29 +01007981
7982 secure = secure_save;
Bram Moolenaar90492982017-06-22 14:16:31 +02007983 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007984 }
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00007985#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +02007986 if (varp == &(curwin->w_s->b_p_spl))
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007987 {
7988 char_u fname[200];
Bram Moolenaarcc63c642013-11-12 04:44:01 +01007989 char_u *q = curwin->w_s->b_p_spl;
7990
7991 /* Skip the first name if it is "cjk". */
7992 if (STRNCMP(q, "cjk,", 4) == 0)
7993 q += 4;
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00007994
7995 /*
7996 * Source the spell/LANG.vim in 'runtimepath'.
7997 * They could set 'spellcapcheck' depending on the language.
7998 * Use the first name in 'spelllang' up to '_region' or
7999 * '.encoding'.
8000 */
Bram Moolenaarcc63c642013-11-12 04:44:01 +01008001 for (p = q; *p != NUL; ++p)
Bram Moolenaar247bb7e2018-11-20 14:27:07 +01008002 if (!ASCII_ISALNUM(*p) && *p != '-')
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008003 break;
Bram Moolenaar82e8c922018-11-20 13:32:36 +01008004 if (p > q)
8005 {
Bram Moolenaar8f130ed2019-04-10 22:15:19 +02008006 vim_snprintf((char *)fname, 200, "spell/%.*s.vim",
8007 (int)(p - q), q);
Bram Moolenaar82e8c922018-11-20 13:32:36 +01008008 source_runtime(fname, DIP_ALL);
8009 }
Bram Moolenaar90cfdbe2005-08-12 19:59:19 +00008010 }
8011#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008012 }
8013
8014#ifdef FEAT_MOUSE
8015 if (varp == &p_mouse)
8016 {
8017# ifdef FEAT_MOUSE_TTY
8018 if (*p_mouse == NUL)
8019 mch_setmouse(FALSE); /* switch mouse off */
8020 else
8021# endif
8022 setmouse(); /* in case 'mouse' changed */
8023 }
8024#endif
8025
Bram Moolenaar913077c2012-03-28 19:59:04 +02008026 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01008027 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02008028 curwin->w_set_curswant = TRUE;
8029
Bram Moolenaarfaff14a2009-02-04 16:29:07 +00008030#ifdef FEAT_GUI
8031 /* check redraw when it's not a GUI option or the GUI is active. */
8032 if (!redraw_gui_only || gui.in_use)
8033#endif
8034 check_redraw(options[opt_idx].flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008035
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008036#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
8037 if (did_swaptcap)
8038 {
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02008039 set_termname((char_u *)"win32");
8040 init_highlight(TRUE, FALSE);
8041 }
8042#endif
8043
Bram Moolenaar071d4272004-06-13 20:20:40 +00008044 return errmsg;
8045}
8046
Bram Moolenaarf4e5e862013-02-13 15:44:26 +01008047#if defined(FEAT_SYN_HL) || defined(PROTO)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008048/*
8049 * Simple int comparison function for use with qsort()
8050 */
8051 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01008052int_cmp(const void *a, const void *b)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008053{
8054 return *(const int *)a - *(const int *)b;
8055}
8056
8057/*
8058 * Handle setting 'colorcolumn' or 'textwidth' in window "wp".
8059 * Returns error message, NULL if it's OK.
8060 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008061 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008062check_colorcolumn(win_T *wp)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008063{
8064 char_u *s;
8065 int col;
8066 int count = 0;
8067 int color_cols[256];
8068 int i;
8069 int j = 0;
8070
Bram Moolenaar50f834d2011-09-21 13:40:17 +02008071 if (wp->w_buffer == NULL)
8072 return NULL; /* buffer was closed */
8073
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008074 for (s = wp->w_p_cc; *s != NUL && count < 255;)
Bram Moolenaar1a384422010-07-14 19:53:30 +02008075 {
8076 if (*s == '-' || *s == '+')
8077 {
8078 /* -N and +N: add to 'textwidth' */
8079 col = (*s == '-') ? -1 : 1;
8080 ++s;
8081 if (!VIM_ISDIGIT(*s))
8082 return e_invarg;
8083 col = col * getdigits(&s);
8084 if (wp->w_buffer->b_p_tw == 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008085 goto skip; /* 'textwidth' not set, skip this item */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008086 col += wp->w_buffer->b_p_tw;
8087 if (col < 0)
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008088 goto skip;
Bram Moolenaar1a384422010-07-14 19:53:30 +02008089 }
8090 else if (VIM_ISDIGIT(*s))
8091 col = getdigits(&s);
8092 else
8093 return e_invarg;
8094 color_cols[count++] = col - 1; /* 1-based to 0-based */
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008095skip:
Bram Moolenaar1a384422010-07-14 19:53:30 +02008096 if (*s == NUL)
8097 break;
8098 if (*s != ',')
8099 return e_invarg;
Bram Moolenaar11505dc2010-07-16 21:29:06 +02008100 if (*++s == NUL)
8101 return e_invarg; /* illegal trailing comma as in "set cc=80," */
Bram Moolenaar1a384422010-07-14 19:53:30 +02008102 }
8103
8104 vim_free(wp->w_p_cc_cols);
8105 if (count == 0)
8106 wp->w_p_cc_cols = NULL;
8107 else
8108 {
Bram Moolenaarc799fe22019-05-28 23:08:19 +02008109 wp->w_p_cc_cols = ALLOC_MULT(int, count + 1);
Bram Moolenaar1a384422010-07-14 19:53:30 +02008110 if (wp->w_p_cc_cols != NULL)
8111 {
8112 /* sort the columns for faster usage on screen redraw inside
8113 * win_line() */
8114 qsort(color_cols, count, sizeof(int), int_cmp);
8115
8116 for (i = 0; i < count; ++i)
8117 /* skip duplicates */
8118 if (j == 0 || wp->w_p_cc_cols[j - 1] != color_cols[i])
8119 wp->w_p_cc_cols[j++] = color_cols[i];
8120 wp->w_p_cc_cols[j] = -1; /* end marker */
8121 }
8122 }
8123
8124 return NULL; /* no error */
8125}
8126#endif
8127
Bram Moolenaar071d4272004-06-13 20:20:40 +00008128/*
8129 * Handle setting 'listchars' or 'fillchars'.
8130 * Returns error message, NULL if it's OK.
8131 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008132 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008133set_chars_option(char_u **varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008134{
8135 int round, i, len, entries;
8136 char_u *p, *s;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008137 int c1 = 0, c2 = 0, c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008138 struct charstab
8139 {
8140 int *cp;
8141 char *name;
8142 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008143 static struct charstab filltab[] =
8144 {
8145 {&fill_stl, "stl"},
8146 {&fill_stlnc, "stlnc"},
8147 {&fill_vert, "vert"},
8148 {&fill_fold, "fold"},
8149 {&fill_diff, "diff"},
8150 };
Bram Moolenaar071d4272004-06-13 20:20:40 +00008151 static struct charstab lcstab[] =
8152 {
8153 {&lcs_eol, "eol"},
8154 {&lcs_ext, "extends"},
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00008155 {&lcs_nbsp, "nbsp"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008156 {&lcs_prec, "precedes"},
Bram Moolenaar4c6b3b22015-04-21 19:10:48 +02008157 {&lcs_space, "space"},
Bram Moolenaar071d4272004-06-13 20:20:40 +00008158 {&lcs_tab2, "tab"},
8159 {&lcs_trail, "trail"},
Bram Moolenaar860cae12010-06-05 23:22:07 +02008160#ifdef FEAT_CONCEAL
8161 {&lcs_conceal, "conceal"},
8162#else
8163 {NULL, "conceal"},
8164#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008165 };
8166 struct charstab *tab;
8167
Bram Moolenaar071d4272004-06-13 20:20:40 +00008168 if (varp == &p_lcs)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008169 {
8170 tab = lcstab;
8171 entries = sizeof(lcstab) / sizeof(struct charstab);
8172 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008173 else
8174 {
8175 tab = filltab;
8176 entries = sizeof(filltab) / sizeof(struct charstab);
8177 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008178
8179 /* first round: check for valid value, second round: assign values */
8180 for (round = 0; round <= 1; ++round)
8181 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008182 if (round > 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008183 {
8184 /* After checking that the value is valid: set defaults: space for
8185 * 'fillchars', NUL for 'listchars' */
8186 for (i = 0; i < entries; ++i)
Bram Moolenaar860cae12010-06-05 23:22:07 +02008187 if (tab[i].cp != NULL)
8188 *(tab[i].cp) = (varp == &p_lcs ? NUL : ' ');
Bram Moolenaar83a52172019-01-16 22:41:54 +01008189
Bram Moolenaar071d4272004-06-13 20:20:40 +00008190 if (varp == &p_lcs)
Bram Moolenaar83a52172019-01-16 22:41:54 +01008191 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008192 lcs_tab1 = NUL;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008193 lcs_tab3 = NUL;
8194 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008195 else
8196 fill_diff = '-';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008197 }
8198 p = *varp;
8199 while (*p)
8200 {
8201 for (i = 0; i < entries; ++i)
8202 {
8203 len = (int)STRLEN(tab[i].name);
8204 if (STRNCMP(p, tab[i].name, len) == 0
8205 && p[len] == ':'
8206 && p[len + 1] != NUL)
8207 {
Bram Moolenaar2c519cf2019-03-21 21:45:34 +01008208 c2 = c3 = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008209 s = p + len + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008210 c1 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008211 if (mb_char2cells(c1) > 1)
8212 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008213 if (tab[i].cp == &lcs_tab2)
8214 {
8215 if (*s == NUL)
8216 continue;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008217 c2 = mb_ptr2char_adv(&s);
Bram Moolenaar910f66f2006-04-05 20:41:53 +00008218 if (mb_char2cells(c2) > 1)
8219 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008220 if (!(*s == ',' || *s == NUL))
8221 {
Bram Moolenaar83a52172019-01-16 22:41:54 +01008222 c3 = mb_ptr2char_adv(&s);
8223 if (mb_char2cells(c3) > 1)
8224 continue;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008225 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008226 }
Bram Moolenaar83a52172019-01-16 22:41:54 +01008227
Bram Moolenaar071d4272004-06-13 20:20:40 +00008228 if (*s == ',' || *s == NUL)
8229 {
8230 if (round)
8231 {
8232 if (tab[i].cp == &lcs_tab2)
8233 {
8234 lcs_tab1 = c1;
8235 lcs_tab2 = c2;
Bram Moolenaar83a52172019-01-16 22:41:54 +01008236 lcs_tab3 = c3;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008237 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02008238 else if (tab[i].cp != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008239 *(tab[i].cp) = c1;
8240
8241 }
8242 p = s;
8243 break;
8244 }
8245 }
8246 }
8247
8248 if (i == entries)
8249 return e_invarg;
8250 if (*p == ',')
8251 ++p;
8252 }
8253 }
8254
8255 return NULL; /* no error */
8256}
8257
8258#ifdef FEAT_STL_OPT
8259/*
8260 * Check validity of options with the 'statusline' format.
8261 * Return error message or NULL.
8262 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008263 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008264check_stl_option(char_u *s)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008265{
8266 int itemcnt = 0;
8267 int groupdepth = 0;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008268 static char errbuf[80];
Bram Moolenaar071d4272004-06-13 20:20:40 +00008269
8270 while (*s && itemcnt < STL_MAX_ITEM)
8271 {
8272 /* Check for valid keys after % sequences */
8273 while (*s && *s != '%')
8274 s++;
8275 if (!*s)
8276 break;
8277 s++;
8278 if (*s != '%' && *s != ')')
8279 ++itemcnt;
8280 if (*s == '%' || *s == STL_TRUNCMARK || *s == STL_MIDDLEMARK)
8281 {
8282 s++;
8283 continue;
8284 }
8285 if (*s == ')')
8286 {
8287 s++;
8288 if (--groupdepth < 0)
8289 break;
8290 continue;
8291 }
8292 if (*s == '-')
8293 s++;
8294 while (VIM_ISDIGIT(*s))
8295 s++;
Bram Moolenaar238a5642006-02-21 22:12:05 +00008296 if (*s == STL_USER_HL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008297 continue;
8298 if (*s == '.')
8299 {
8300 s++;
8301 while (*s && VIM_ISDIGIT(*s))
8302 s++;
8303 }
8304 if (*s == '(')
8305 {
8306 groupdepth++;
8307 continue;
8308 }
8309 if (vim_strchr(STL_ALL, *s) == NULL)
8310 {
8311 return illegal_char(errbuf, *s);
8312 }
8313 if (*s == '{')
8314 {
8315 s++;
8316 while (*s != '}' && *s)
8317 s++;
8318 if (*s != '}')
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008319 return N_("E540: Unclosed expression sequence");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008320 }
8321 }
8322 if (itemcnt >= STL_MAX_ITEM)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008323 return N_("E541: too many items");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008324 if (groupdepth != 0)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008325 return N_("E542: unbalanced groups");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008326 return NULL;
8327}
8328#endif
8329
8330#ifdef FEAT_CLIPBOARD
8331/*
8332 * Extract the items in the 'clipboard' option and set global values.
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008333 * Return an error message or NULL for success.
Bram Moolenaar071d4272004-06-13 20:20:40 +00008334 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008335 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008336check_clipboard_option(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008337{
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008338 int new_unnamed = 0;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008339 int new_autoselect_star = FALSE;
8340 int new_autoselect_plus = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008341 int new_autoselectml = FALSE;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008342 int new_html = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008343 regprog_T *new_exclude_prog = NULL;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008344 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008345 char_u *p;
8346
8347 for (p = p_cb; *p != NUL; )
8348 {
8349 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
8350 {
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008351 new_unnamed |= CLIP_UNNAMED;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008352 p += 7;
8353 }
Bram Moolenaar11b73d62012-06-29 15:51:30 +02008354 else if (STRNCMP(p, "unnamedplus", 11) == 0
Bram Moolenaarbf9680e2010-12-02 21:43:16 +01008355 && (p[11] == ',' || p[11] == NUL))
8356 {
8357 new_unnamed |= CLIP_UNNAMED_PLUS;
8358 p += 11;
8359 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008360 else if (STRNCMP(p, "autoselect", 10) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008361 && (p[10] == ',' || p[10] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008362 {
Bram Moolenaar89af4392012-07-10 18:31:54 +02008363 new_autoselect_star = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008364 p += 10;
8365 }
Bram Moolenaar89af4392012-07-10 18:31:54 +02008366 else if (STRNCMP(p, "autoselectplus", 14) == 0
8367 && (p[14] == ',' || p[14] == NUL))
8368 {
8369 new_autoselect_plus = TRUE;
8370 p += 14;
8371 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008372 else if (STRNCMP(p, "autoselectml", 12) == 0
Bram Moolenaar89af4392012-07-10 18:31:54 +02008373 && (p[12] == ',' || p[12] == NUL))
Bram Moolenaar071d4272004-06-13 20:20:40 +00008374 {
8375 new_autoselectml = TRUE;
8376 p += 12;
8377 }
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008378 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
8379 {
8380 new_html = TRUE;
8381 p += 4;
8382 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008383 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
8384 {
8385 p += 8;
8386 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
8387 if (new_exclude_prog == NULL)
8388 errmsg = e_invarg;
8389 break;
8390 }
8391 else
8392 {
8393 errmsg = e_invarg;
8394 break;
8395 }
8396 if (*p == ',')
8397 ++p;
8398 }
8399 if (errmsg == NULL)
8400 {
8401 clip_unnamed = new_unnamed;
Bram Moolenaar89af4392012-07-10 18:31:54 +02008402 clip_autoselect_star = new_autoselect_star;
8403 clip_autoselect_plus = new_autoselect_plus;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008404 clip_autoselectml = new_autoselectml;
Bram Moolenaar3a6eaa52009-06-16 13:23:06 +00008405 clip_html = new_html;
Bram Moolenaar473de612013-06-08 18:19:48 +02008406 vim_regfree(clip_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008407 clip_exclude_prog = new_exclude_prog;
Bram Moolenaara76638f2010-06-05 12:49:46 +02008408#ifdef FEAT_GUI_GTK
8409 if (gui.in_use)
8410 {
8411 gui_gtk_set_selection_targets();
8412 gui_gtk_set_dnd_targets();
8413 }
8414#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008415 }
8416 else
Bram Moolenaar473de612013-06-08 18:19:48 +02008417 vim_regfree(new_exclude_prog);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008418
8419 return errmsg;
8420}
8421#endif
8422
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008423#ifdef FEAT_SPELL
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008424/*
8425 * Handle side effects of setting 'spell'.
8426 * Return an error message or NULL for success.
8427 */
8428 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008429did_set_spell_option(int is_spellfile)
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008430{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008431 char *errmsg = NULL;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008432 win_T *wp;
8433 int l;
8434
8435 if (is_spellfile)
8436 {
8437 l = (int)STRLEN(curwin->w_s->b_p_spf);
8438 if (l > 0 && (l < 4
8439 || STRCMP(curwin->w_s->b_p_spf + l - 4, ".add") != 0))
8440 errmsg = e_invarg;
8441 }
8442
8443 if (errmsg == NULL)
8444 {
8445 FOR_ALL_WINDOWS(wp)
8446 if (wp->w_buffer == curbuf && wp->w_p_spell)
8447 {
8448 errmsg = did_set_spelllang(wp);
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008449 break;
Bram Moolenaare68c25c2015-08-25 15:39:55 +02008450 }
8451 }
8452 return errmsg;
8453}
8454
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008455/*
8456 * Set curbuf->b_cap_prog to the regexp program for 'spellcapcheck'.
8457 * Return error message when failed, NULL when OK.
8458 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008459 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008460compile_cap_prog(synblock_T *synblock)
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008461{
Bram Moolenaar860cae12010-06-05 23:22:07 +02008462 regprog_T *rp = synblock->b_cap_prog;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008463 char_u *re;
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008464
Bram Moolenaar860cae12010-06-05 23:22:07 +02008465 if (*synblock->b_p_spc == NUL)
8466 synblock->b_cap_prog = NULL;
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008467 else
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008468 {
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008469 /* Prepend a ^ so that we only match at one column */
Bram Moolenaar860cae12010-06-05 23:22:07 +02008470 re = concat_str((char_u *)"^", synblock->b_p_spc);
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008471 if (re != NULL)
8472 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008473 synblock->b_cap_prog = vim_regcomp(re, RE_MAGIC);
Bram Moolenaar473de612013-06-08 18:19:48 +02008474 vim_free(re);
Bram Moolenaar860cae12010-06-05 23:22:07 +02008475 if (synblock->b_cap_prog == NULL)
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008476 {
Bram Moolenaar860cae12010-06-05 23:22:07 +02008477 synblock->b_cap_prog = rp; /* restore the previous program */
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008478 return e_invarg;
8479 }
Bram Moolenaar18f9a792005-12-08 22:02:51 +00008480 }
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008481 }
8482
Bram Moolenaar473de612013-06-08 18:19:48 +02008483 vim_regfree(rp);
Bram Moolenaar0d9c26d2005-07-02 23:19:16 +00008484 return NULL;
8485}
8486#endif
8487
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008488#if defined(FEAT_EVAL) || defined(PROTO)
8489/*
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008490 * Set the script_ctx for an option, taking care of setting the buffer- or
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008491 * window-local value.
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008492 */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008493 static void
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008494set_option_sctx_idx(int opt_idx, int opt_flags, sctx_T script_ctx)
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008495{
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008496 int both = (opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0;
8497 int indir = (int)options[opt_idx].indir;
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008498 sctx_T new_script_ctx = script_ctx;
8499
8500 new_script_ctx.sc_lnum += sourcing_lnum;
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008501
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008502 /* Remember where the option was set. For local options need to do that
8503 * in the buffer or window structure. */
8504 if (both || (opt_flags & OPT_GLOBAL) || (indir & (PV_BUF|PV_WIN)) == 0)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008505 options[opt_idx].script_ctx = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008506 if (both || (opt_flags & OPT_LOCAL))
8507 {
8508 if (indir & PV_BUF)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008509 curbuf->b_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008510 else if (indir & PV_WIN)
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008511 curwin->w_p_script_ctx[indir & PV_MASK] = new_script_ctx;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008512 }
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008513}
Bram Moolenaar35bc7d62018-10-02 14:45:10 +02008514
8515/*
8516 * Set the script_ctx for a termcap option.
8517 * "name" must be the two character code, e.g. "RV".
8518 * When "name" is NULL use "opt_idx".
8519 */
8520 void
8521set_term_option_sctx_idx(char *name, int opt_idx)
8522{
8523 char_u buf[5];
8524 int idx;
8525
8526 if (name == NULL)
8527 idx = opt_idx;
8528 else
8529 {
8530 buf[0] = 't';
8531 buf[1] = '_';
8532 buf[2] = name[0];
8533 buf[3] = name[1];
8534 buf[4] = 0;
8535 idx = findoption(buf);
8536 }
8537 if (idx >= 0)
8538 set_option_sctx_idx(idx, OPT_GLOBAL, current_sctx);
8539}
Bram Moolenaard1f56e62006-02-22 21:25:37 +00008540#endif
8541
Bram Moolenaar071d4272004-06-13 20:20:40 +00008542/*
8543 * Set the value of a boolean option, and take care of side effects.
8544 * Returns NULL for success, or an error message for an error.
8545 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008546 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01008547set_bool_option(
8548 int opt_idx, /* index in options[] table */
8549 char_u *varp, /* pointer to the option variable */
8550 int value, /* new value */
8551 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008552{
8553 int old_value = *(int *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008554#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008555 int old_global_value = 0;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008556#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008557
Bram Moolenaar071d4272004-06-13 20:20:40 +00008558 /* Disallow changing some options from secure mode */
8559 if ((secure
8560#ifdef HAVE_SANDBOX
8561 || sandbox != 0
8562#endif
8563 ) && (options[opt_idx].flags & P_SECURE))
8564 return e_secure;
8565
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008566#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02008567 // Save the global value before changing anything. This is needed as for
8568 // a global-only option setting the "local value" in fact sets the global
8569 // value (since there is only one value).
8570 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8571 old_global_value = *(int *)get_varp_scope(&(options[opt_idx]),
8572 OPT_GLOBAL);
Bram Moolenaar983f2f12019-06-16 16:41:41 +02008573#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02008574
Bram Moolenaar071d4272004-06-13 20:20:40 +00008575 *(int *)varp = value; /* set the new value */
8576#ifdef FEAT_EVAL
8577 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02008578 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008579#endif
8580
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00008581#ifdef FEAT_GUI
8582 need_mouse_correct = TRUE;
8583#endif
8584
Bram Moolenaar071d4272004-06-13 20:20:40 +00008585 /* May set global value for local option. */
8586 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
8587 *(int *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = value;
8588
8589 /*
8590 * Handle side effects of changing a bool option.
8591 */
8592
8593 /* 'compatible' */
8594 if ((int *)varp == &p_cp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008595 compatible_set();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008596
Bram Moolenaar920694c2016-08-21 17:45:02 +02008597#ifdef FEAT_LANGMAP
8598 if ((int *)varp == &p_lrm)
8599 /* 'langremap' -> !'langnoremap' */
8600 p_lnr = !p_lrm;
8601 else if ((int *)varp == &p_lnr)
8602 /* 'langnoremap' -> !'langremap' */
8603 p_lrm = !p_lnr;
8604#endif
8605
Bram Moolenaar8c63e0e2018-09-25 22:17:54 +02008606#ifdef FEAT_SYN_HL
8607 else if ((int *)varp == &curwin->w_p_cul && !value && old_value)
8608 reset_cursorline();
8609#endif
8610
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008611#ifdef FEAT_PERSISTENT_UNDO
8612 /* 'undofile' */
8613 else if ((int *)varp == &curbuf->b_p_udf || (int *)varp == &p_udf)
8614 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008615 /* Only take action when the option was set. When reset we do not
8616 * delete the undo file, the option may be set again without making
8617 * any changes in between. */
8618 if (curbuf->b_p_udf || p_udf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008619 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008620 char_u hash[UNDO_HASH_SIZE];
8621 buf_T *save_curbuf = curbuf;
8622
Bram Moolenaar29323592016-07-24 22:04:11 +02008623 FOR_ALL_BUFFERS(curbuf)
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008624 {
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008625 /* When 'undofile' is set globally: for every buffer, otherwise
8626 * only for the current buffer: Try to read in the undofile,
8627 * if one exists, the buffer wasn't changed and the buffer was
8628 * loaded */
8629 if ((curbuf == save_curbuf
8630 || (opt_flags & OPT_GLOBAL) || opt_flags == 0)
8631 && !curbufIsChanged() && curbuf->b_ml.ml_mfp != NULL)
8632 {
8633 u_compute_hash(hash);
8634 u_read_undo(NULL, hash, curbuf->b_fname);
8635 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008636 }
Bram Moolenaare8d8fd22012-10-21 03:46:05 +02008637 curbuf = save_curbuf;
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008638 }
Bram Moolenaar374d32d2012-01-04 19:34:37 +01008639 }
8640#endif
8641
Bram Moolenaar071d4272004-06-13 20:20:40 +00008642 else if ((int *)varp == &curbuf->b_p_ro)
8643 {
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008644 /* when 'readonly' is reset globally, also reset readonlymode */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008645 if (!curbuf->b_p_ro && (opt_flags & OPT_LOCAL) == 0)
8646 readonlymode = FALSE;
Bram Moolenaard5cdbeb2005-10-10 20:59:28 +00008647
8648 /* when 'readonly' is set may give W10 again */
8649 if (curbuf->b_p_ro)
8650 curbuf->b_did_warn = FALSE;
8651
Bram Moolenaar071d4272004-06-13 20:20:40 +00008652#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008653 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008654#endif
8655 }
8656
Bram Moolenaar9c449722010-07-20 18:44:27 +02008657#ifdef FEAT_GUI
8658 else if ((int *)varp == &p_mh)
8659 {
8660 if (!p_mh)
8661 gui_mch_mousehide(FALSE);
8662 }
8663#endif
8664
Bram Moolenaara539df02010-08-01 14:35:05 +02008665 /* when 'modifiable' is changed, redraw the window title */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008666 else if ((int *)varp == &curbuf->b_p_ma)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008667 {
Bram Moolenaar423802d2017-07-30 16:52:24 +02008668# ifdef FEAT_TERMINAL
8669 /* Cannot set 'modifiable' when in Terminal mode. */
Bram Moolenaard7db27b2018-03-07 23:02:33 +01008670 if (curbuf->b_p_ma && (term_in_normal_mode() || (bt_terminal(curbuf)
8671 && curbuf->b_term != NULL && !term_is_finished(curbuf))))
Bram Moolenaar423802d2017-07-30 16:52:24 +02008672 {
8673 curbuf->b_p_ma = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008674 return N_("E946: Cannot make a terminal with running job modifiable");
Bram Moolenaar423802d2017-07-30 16:52:24 +02008675 }
8676# endif
8677# ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008678 redraw_titles();
Bram Moolenaar423802d2017-07-30 16:52:24 +02008679# endif
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008680 }
Bram Moolenaar423802d2017-07-30 16:52:24 +02008681#ifdef FEAT_TITLE
Bram Moolenaar071d4272004-06-13 20:20:40 +00008682 /* when 'endofline' is changed, redraw the window title */
8683 else if ((int *)varp == &curbuf->b_p_eol)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008684 {
8685 redraw_titles();
8686 }
Bram Moolenaar34d72d42015-07-17 14:18:08 +02008687 /* when 'fixeol' is changed, redraw the window title */
8688 else if ((int *)varp == &curbuf->b_p_fixeol)
8689 {
8690 redraw_titles();
8691 }
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008692 /* when 'bomb' is changed, redraw the window title and tab page text */
Bram Moolenaar83eb8852007-08-12 13:51:26 +00008693 else if ((int *)varp == &curbuf->b_p_bomb)
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008694 {
8695 redraw_titles();
8696 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008697#endif
8698
8699 /* when 'bin' is set also set some other options */
8700 else if ((int *)varp == &curbuf->b_p_bin)
8701 {
8702 set_options_bin(old_value, curbuf->b_p_bin, opt_flags);
8703#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008704 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008705#endif
8706 }
8707
Bram Moolenaar071d4272004-06-13 20:20:40 +00008708 /* when 'buflisted' changes, trigger autocommands */
8709 else if ((int *)varp == &curbuf->b_p_bl && old_value != curbuf->b_p_bl)
8710 {
8711 apply_autocmds(curbuf->b_p_bl ? EVENT_BUFADD : EVENT_BUFDELETE,
8712 NULL, NULL, TRUE, curbuf);
8713 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008714
8715 /* when 'swf' is set, create swapfile, when reset remove swapfile */
8716 else if ((int *)varp == &curbuf->b_p_swf)
8717 {
8718 if (curbuf->b_p_swf && p_uc)
8719 ml_open_file(curbuf); /* create the swap file */
8720 else
Bram Moolenaard55de222007-05-06 13:38:48 +00008721 /* no need to reset curbuf->b_may_swap, ml_open_file() will check
8722 * buf->b_p_swf */
Bram Moolenaar071d4272004-06-13 20:20:40 +00008723 mf_close_file(curbuf, TRUE); /* remove the swap file */
8724 }
8725
8726 /* when 'terse' is set change 'shortmess' */
8727 else if ((int *)varp == &p_terse)
8728 {
8729 char_u *p;
8730
8731 p = vim_strchr(p_shm, SHM_SEARCH);
8732
8733 /* insert 's' in p_shm */
8734 if (p_terse && p == NULL)
8735 {
8736 STRCPY(IObuff, p_shm);
8737 STRCAT(IObuff, "s");
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008738 set_string_option_direct((char_u *)"shm", -1, IObuff, OPT_FREE, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008739 }
8740 /* remove 's' from p_shm */
8741 else if (!p_terse && p != NULL)
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00008742 STRMOVE(p, p + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008743 }
8744
8745 /* when 'paste' is set or reset also change other options */
8746 else if ((int *)varp == &p_paste)
8747 {
8748 paste_option_changed();
8749 }
8750
8751 /* when 'insertmode' is set from an autocommand need to do work here */
8752 else if ((int *)varp == &p_im)
8753 {
8754 if (p_im)
8755 {
8756 if ((State & INSERT) == 0)
8757 need_start_insertmode = TRUE;
8758 stop_insert_mode = FALSE;
8759 }
Bram Moolenaar00672e12016-06-26 18:38:13 +02008760 /* only reset if it was set previously */
8761 else if (old_value)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008762 {
8763 need_start_insertmode = FALSE;
8764 stop_insert_mode = TRUE;
Bram Moolenaard12f5c12006-01-25 22:10:52 +00008765 if (restart_edit != 0 && mode_displayed)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008766 clear_cmdline = TRUE; /* remove "(insert)" */
8767 restart_edit = 0;
8768 }
8769 }
8770
8771 /* when 'ignorecase' is set or reset and 'hlsearch' is set, redraw */
8772 else if ((int *)varp == &p_ic && p_hls)
8773 {
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008774 redraw_all_later(SOME_VALID);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008775 }
8776
8777#ifdef FEAT_SEARCH_EXTRA
8778 /* when 'hlsearch' is set or reset: reset no_hlsearch */
8779 else if ((int *)varp == &p_hls)
8780 {
Bram Moolenaar451fc7b2018-04-27 22:53:07 +02008781 set_no_hlsearch(FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008782 }
8783#endif
8784
Bram Moolenaar071d4272004-06-13 20:20:40 +00008785 /* when 'scrollbind' is set: snapshot the current position to avoid a jump
8786 * at the end of normal_cmd() */
8787 else if ((int *)varp == &curwin->w_p_scb)
8788 {
8789 if (curwin->w_p_scb)
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008790 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008791 do_check_scrollbind(FALSE);
Bram Moolenaar04c5c9e2013-07-09 13:44:59 +02008792 curwin->w_scbind_pos = curwin->w_topline;
8793 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008794 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008795
Bram Moolenaar4033c552017-09-16 20:54:51 +02008796#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008797 /* There can be only one window with 'previewwindow' set. */
8798 else if ((int *)varp == &curwin->w_p_pvw)
8799 {
8800 if (curwin->w_p_pvw)
8801 {
8802 win_T *win;
8803
Bram Moolenaar29323592016-07-24 22:04:11 +02008804 FOR_ALL_WINDOWS(win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008805 if (win->w_p_pvw && win != curwin)
8806 {
8807 curwin->w_p_pvw = FALSE;
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008808 return N_("E590: A preview window already exists");
Bram Moolenaar071d4272004-06-13 20:20:40 +00008809 }
8810 }
8811 }
8812#endif
8813
8814 /* when 'textmode' is set or reset also change 'fileformat' */
8815 else if ((int *)varp == &curbuf->b_p_tx)
8816 {
8817 set_fileformat(curbuf->b_p_tx ? EOL_DOS : EOL_UNIX, opt_flags);
8818 }
8819
8820 /* when 'textauto' is set or reset also change 'fileformats' */
8821 else if ((int *)varp == &p_ta)
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008822 {
Bram Moolenaar071d4272004-06-13 20:20:40 +00008823 set_string_option_direct((char_u *)"ffs", -1,
8824 p_ta ? (char_u *)DFLT_FFS_VIM : (char_u *)"",
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +00008825 OPT_FREE | opt_flags, 0);
Bram Moolenaarabab0b02019-03-30 18:47:01 +01008826 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008827
8828 /*
8829 * When 'lisp' option changes include/exclude '-' in
8830 * keyword characters.
8831 */
8832#ifdef FEAT_LISP
8833 else if (varp == (char_u *)&(curbuf->b_p_lisp))
8834 {
8835 (void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
8836 }
8837#endif
8838
8839#ifdef FEAT_TITLE
8840 /* when 'title' changed, may need to change the title; same for 'icon' */
Bram Moolenaar84a93082018-06-16 22:58:15 +02008841 else if ((int *)varp == &p_title || (int *)varp == &p_icon)
Bram Moolenaar071d4272004-06-13 20:20:40 +00008842 {
Bram Moolenaar84a93082018-06-16 22:58:15 +02008843 did_set_title();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008844 }
8845#endif
8846
8847 else if ((int *)varp == &curbuf->b_changed)
8848 {
8849 if (!value)
8850 save_file_ff(curbuf); /* Buffer is unchanged */
8851#ifdef FEAT_TITLE
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00008852 redraw_titles();
Bram Moolenaar071d4272004-06-13 20:20:40 +00008853#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008854 modified_was_set = value;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008855 }
8856
8857#ifdef BACKSLASH_IN_FILENAME
8858 else if ((int *)varp == &p_ssl)
8859 {
8860 if (p_ssl)
8861 {
8862 psepc = '/';
8863 psepcN = '\\';
8864 pseps[0] = '/';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008865 }
8866 else
8867 {
8868 psepc = '\\';
8869 psepcN = '/';
8870 pseps[0] = '\\';
Bram Moolenaar071d4272004-06-13 20:20:40 +00008871 }
8872
8873 /* need to adjust the file name arguments and buffer names. */
8874 buflist_slash_adjust();
8875 alist_slash_adjust();
8876# ifdef FEAT_EVAL
8877 scriptnames_slash_adjust();
8878# endif
8879 }
8880#endif
8881
8882 /* If 'wrap' is set, set w_leftcol to zero. */
8883 else if ((int *)varp == &curwin->w_p_wrap)
8884 {
8885 if (curwin->w_p_wrap)
8886 curwin->w_leftcol = 0;
8887 }
8888
Bram Moolenaar071d4272004-06-13 20:20:40 +00008889 else if ((int *)varp == &p_ea)
8890 {
8891 if (p_ea && !old_value)
8892 win_equal(curwin, FALSE, 0);
8893 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008894
8895 else if ((int *)varp == &p_wiv)
8896 {
8897 /*
8898 * When 'weirdinvert' changed, set/reset 't_xs'.
8899 * Then set 'weirdinvert' according to value of 't_xs'.
8900 */
8901 if (p_wiv && !old_value)
8902 T_XS = (char_u *)"y";
8903 else if (!p_wiv && old_value)
8904 T_XS = empty_option;
8905 p_wiv = (*T_XS != NUL);
8906 }
8907
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008908#ifdef FEAT_BEVAL_GUI
Bram Moolenaar071d4272004-06-13 20:20:40 +00008909 else if ((int *)varp == &p_beval)
8910 {
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008911 if (!balloonEvalForTerm)
8912 {
8913 if (p_beval && !old_value)
8914 gui_mch_enable_beval_area(balloonEval);
8915 else if (!p_beval && old_value)
8916 gui_mch_disable_beval_area(balloonEval);
8917 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00008918 }
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008919#endif
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008920#ifdef FEAT_BEVAL_TERM
Bram Moolenaar51b0f372017-11-18 18:52:04 +01008921 else if ((int *)varp == &p_bevalterm)
8922 {
8923 mch_bevalterm_changed();
8924 }
Bram Moolenaarc3719bd2017-11-18 22:13:31 +01008925#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008926
Bram Moolenaar8dff8182006-04-06 20:18:50 +00008927#ifdef FEAT_AUTOCHDIR
Bram Moolenaar071d4272004-06-13 20:20:40 +00008928 else if ((int *)varp == &p_acd)
8929 {
Bram Moolenaar498efdb2006-09-05 14:31:54 +00008930 /* Change directories when the 'acd' option is set now. */
Bram Moolenaar6f470022018-04-10 18:47:20 +02008931 DO_AUTOCHDIR;
Bram Moolenaar071d4272004-06-13 20:20:40 +00008932 }
8933#endif
8934
8935#ifdef FEAT_DIFF
8936 /* 'diff' */
8937 else if ((int *)varp == &curwin->w_p_diff)
8938 {
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008939 /* May add or remove the buffer from the list of diff buffers. */
8940 diff_buf_adjust(curwin);
8941# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00008942 if (foldmethodIsDiff(curwin))
8943 foldUpdateAll(curwin);
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00008944# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00008945 }
8946#endif
8947
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01008948#ifdef HAVE_INPUT_METHOD
Bram Moolenaar071d4272004-06-13 20:20:40 +00008949 /* 'imdisable' */
8950 else if ((int *)varp == &p_imdisable)
8951 {
8952 /* Only de-activate it here, it will be enabled when changing mode. */
8953 if (p_imdisable)
8954 im_set_active(FALSE);
Bram Moolenaar725a9622011-10-12 16:57:13 +02008955 else if (State & INSERT)
8956 /* When the option is set from an autocommand, it may need to take
8957 * effect right away. */
8958 im_set_active(curbuf->b_p_iminsert == B_IMODE_IM);
Bram Moolenaar071d4272004-06-13 20:20:40 +00008959 }
8960#endif
8961
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +00008962#ifdef FEAT_SPELL
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008963 /* 'spell' */
8964 else if ((int *)varp == &curwin->w_p_spell)
8965 {
8966 if (curwin->w_p_spell)
8967 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008968 char *errmsg = did_set_spelllang(curwin);
8969
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008970 if (errmsg != NULL)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01008971 emsg(_(errmsg));
Bram Moolenaar0cb032e2005-04-23 20:52:00 +00008972 }
8973 }
8974#endif
8975
Bram Moolenaar071d4272004-06-13 20:20:40 +00008976#ifdef FEAT_ARABIC
8977 if ((int *)varp == &curwin->w_p_arab)
8978 {
8979 if (curwin->w_p_arab)
8980 {
8981 /*
8982 * 'arabic' is set, handle various sub-settings.
8983 */
8984 if (!p_tbidi)
8985 {
8986 /* set rightleft mode */
8987 if (!curwin->w_p_rl)
8988 {
8989 curwin->w_p_rl = TRUE;
8990 changed_window_setting();
8991 }
8992
8993 /* Enable Arabic shaping (major part of what Arabic requires) */
8994 if (!p_arshape)
8995 {
8996 p_arshape = TRUE;
8997 redraw_later_clear();
8998 }
8999 }
9000
9001 /* Arabic requires a utf-8 encoding, inform the user if its not
9002 * set. */
9003 if (STRCMP(p_enc, "utf-8") != 0)
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009004 {
Bram Moolenaar496c5262009-03-18 14:42:00 +00009005 static char *w_arabic = N_("W17: Arabic requires UTF-8, do ':set encoding=utf-8'");
9006
Bram Moolenaar8820b482017-03-16 17:23:31 +01009007 msg_source(HL_ATTR(HLF_W));
Bram Moolenaar32526b32019-01-19 17:43:09 +01009008 msg_attr(_(w_arabic), HL_ATTR(HLF_W));
Bram Moolenaar496c5262009-03-18 14:42:00 +00009009#ifdef FEAT_EVAL
9010 set_vim_var_string(VV_WARNINGMSG, (char_u *)_(w_arabic), -1);
9011#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009012 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009013
Bram Moolenaar071d4272004-06-13 20:20:40 +00009014 /* set 'delcombine' */
9015 p_deco = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009016
9017# ifdef FEAT_KEYMAP
9018 /* Force-set the necessary keymap for arabic */
9019 set_option_value((char_u *)"keymap", 0L, (char_u *)"arabic",
9020 OPT_LOCAL);
9021# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009022 }
9023 else
9024 {
9025 /*
9026 * 'arabic' is reset, handle various sub-settings.
9027 */
9028 if (!p_tbidi)
9029 {
9030 /* reset rightleft mode */
9031 if (curwin->w_p_rl)
9032 {
9033 curwin->w_p_rl = FALSE;
9034 changed_window_setting();
9035 }
9036
9037 /* 'arabicshape' isn't reset, it is a global option and
9038 * another window may still need it "on". */
9039 }
9040
9041 /* 'delcombine' isn't reset, it is a global option and another
9042 * window may still want it "on". */
9043
9044# ifdef FEAT_KEYMAP
9045 /* Revert to the default keymap */
9046 curbuf->b_p_iminsert = B_IMODE_NONE;
9047 curbuf->b_p_imsearch = B_IMODE_USE_INSERT;
9048# endif
9049 }
Bram Moolenaar801f8b82009-07-29 13:42:05 +00009050 }
9051
Bram Moolenaar319bdbd2009-09-11 13:20:33 +00009052#endif
9053
Bram Moolenaar61be73b2016-04-29 22:59:22 +02009054#ifdef FEAT_TERMGUICOLORS
9055 /* 'termguicolors' */
9056 else if ((int *)varp == &p_tgc)
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009057 {
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009058# ifdef FEAT_VTP
9059 /* Do not turn on 'tgc' when 24-bit colors are not supported. */
Bram Moolenaarafde13b2019-04-28 19:46:49 +02009060 if (
9061# ifdef VIMDLL
9062 !gui.in_use && !gui.starting &&
9063# endif
9064 !has_vtp_working())
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009065 {
9066 p_tgc = 0;
Bram Moolenaaraa5df7e2019-02-03 14:53:10 +01009067 return N_("E954: 24-bit colors are not supported on this environment");
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009068 }
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009069 if (is_term_win32())
9070 swap_tcap();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009071# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009072# ifdef FEAT_GUI
9073 if (!gui.in_use && !gui.starting)
9074# endif
9075 highlight_gui_started();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009076# ifdef FEAT_VTP
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009077 /* reset t_Co */
Bram Moolenaarc5cd8852018-05-01 15:47:38 +02009078 if (is_term_win32())
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009079 {
9080 control_console_color_rgb();
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009081 set_termname(T_NAME);
Bram Moolenaarb0eb14f2018-06-28 15:29:52 +02009082 init_highlight(TRUE, FALSE);
9083 }
Bram Moolenaarcafafb32018-02-22 21:07:09 +01009084# endif
Bram Moolenaar8a633e32016-04-21 21:10:14 +02009085 }
9086#endif
9087
Bram Moolenaar071d4272004-06-13 20:20:40 +00009088 /*
9089 * End of handling side effects for bool options.
9090 */
9091
Bram Moolenaar53744302015-07-17 17:38:22 +02009092 /* after handling side effects, call autocommand */
9093
Bram Moolenaar071d4272004-06-13 20:20:40 +00009094 options[opt_idx].flags |= P_WAS_SET;
9095
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009096#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009097 // Don't do this while starting up or recursively.
9098 if (!starting && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009099 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009100 char_u buf_old[2], buf_old_global[2], buf_new[2], buf_type[7];
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009101
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009102 vim_snprintf((char *)buf_old, 2, "%d", old_value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009103 vim_snprintf((char *)buf_old_global, 2, "%d",
9104 old_global_value ? TRUE: FALSE);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009105 vim_snprintf((char *)buf_new, 2, "%d", value ? TRUE: FALSE);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009106 vim_snprintf((char *)buf_type, 7, "%s",
9107 (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009108 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9109 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9110 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009111 if (opt_flags & OPT_LOCAL)
9112 {
9113 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9114 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9115 }
9116 if (opt_flags & OPT_GLOBAL)
9117 {
9118 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9119 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9120 }
9121 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9122 {
9123 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9124 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9125 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9126 }
9127 if (opt_flags & OPT_MODELINE)
9128 {
9129 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9130 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9131 }
9132 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9133 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009134 reset_v_option_vars();
9135 }
9136#endif
9137
Bram Moolenaar071d4272004-06-13 20:20:40 +00009138 comp_col(); /* in case 'ruler' or 'showcmd' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009139 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009140 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009141 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009142 check_redraw(options[opt_idx].flags);
9143
9144 return NULL;
9145}
9146
9147/*
9148 * Set the value of a number option, and take care of side effects.
9149 * Returns NULL for success, or an error message for an error.
9150 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009151 static char *
Bram Moolenaar9b578142016-01-30 19:39:49 +01009152set_num_option(
9153 int opt_idx, /* index in options[] table */
9154 char_u *varp, /* pointer to the option variable */
9155 long value, /* new value */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009156 char *errbuf, /* buffer for error messages */
Bram Moolenaar9b578142016-01-30 19:39:49 +01009157 size_t errbuflen, /* length of "errbuf" */
9158 int opt_flags) /* OPT_LOCAL, OPT_GLOBAL and
Bram Moolenaar071d4272004-06-13 20:20:40 +00009159 OPT_MODELINE */
9160{
Bram Moolenaarf9e3e092019-01-13 23:38:42 +01009161 char *errmsg = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009162 long old_value = *(long *)varp;
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009163#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009164 long old_global_value = 0; // only used when setting a local and
9165 // global option
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009166#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009167 long old_Rows = Rows; // remember old Rows
9168 long old_Columns = Columns; // remember old Columns
Bram Moolenaar071d4272004-06-13 20:20:40 +00009169 long *pp = (long *)varp;
9170
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009171 /* Disallow changing some options from secure mode. */
9172 if ((secure
9173#ifdef HAVE_SANDBOX
9174 || sandbox != 0
Bram Moolenaar071d4272004-06-13 20:20:40 +00009175#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009176 ) && (options[opt_idx].flags & P_SECURE))
9177 return e_secure;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009178
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009179#if defined(FEAT_EVAL)
Bram Moolenaard7c96872019-06-15 17:12:48 +02009180 // Save the global value before changing anything. This is needed as for
9181 // a global-only option setting the "local value" infact sets the global
9182 // value (since there is only one value).
9183 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
Bram Moolenaar983f2f12019-06-16 16:41:41 +02009184 old_global_value = *(long *)get_varp_scope(&(options[opt_idx]),
9185 OPT_GLOBAL);
9186#endif
Bram Moolenaard7c96872019-06-15 17:12:48 +02009187
Bram Moolenaar071d4272004-06-13 20:20:40 +00009188 *pp = value;
9189#ifdef FEAT_EVAL
9190 /* Remember where the option was set. */
Bram Moolenaarf29c1c62018-09-10 21:05:02 +02009191 set_option_sctx_idx(opt_idx, opt_flags, current_sctx);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009192#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +00009193#ifdef FEAT_GUI
9194 need_mouse_correct = TRUE;
9195#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009196
Bram Moolenaar14f24742012-08-08 18:01:05 +02009197 if (curbuf->b_p_sw < 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009198 {
9199 errmsg = e_positive;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009200#ifdef FEAT_VARTABS
9201 // Use the first 'vartabstop' value, or 'tabstop' if vts isn't in use.
9202 curbuf->b_p_sw = tabstop_count(curbuf->b_p_vts_array) > 0
9203 ? tabstop_first(curbuf->b_p_vts_array)
9204 : curbuf->b_p_ts;
9205#else
Bram Moolenaar071d4272004-06-13 20:20:40 +00009206 curbuf->b_p_sw = curbuf->b_p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +02009207#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009208 }
9209
9210 /*
9211 * Number options that need some action when changed
9212 */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009213 if (pp == &p_wh || pp == &p_hh)
9214 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009215 // 'winheight' and 'helpheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009216 if (p_wh < 1)
9217 {
9218 errmsg = e_positive;
9219 p_wh = 1;
9220 }
9221 if (p_wmh > p_wh)
9222 {
9223 errmsg = e_winheight;
9224 p_wh = p_wmh;
9225 }
9226 if (p_hh < 0)
9227 {
9228 errmsg = e_positive;
9229 p_hh = 0;
9230 }
9231
9232 /* Change window height NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009233 if (!ONE_WINDOW)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009234 {
9235 if (pp == &p_wh && curwin->w_height < p_wh)
9236 win_setheight((int)p_wh);
9237 if (pp == &p_hh && curbuf->b_help && curwin->w_height < p_hh)
9238 win_setheight((int)p_hh);
9239 }
9240 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009241 else if (pp == &p_wmh)
9242 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009243 // 'winminheight'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009244 if (p_wmh < 0)
9245 {
9246 errmsg = e_positive;
9247 p_wmh = 0;
9248 }
9249 if (p_wmh > p_wh)
9250 {
9251 errmsg = e_winheight;
9252 p_wmh = p_wh;
9253 }
9254 win_setminheight();
9255 }
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009256 else if (pp == &p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009257 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009258 // 'winwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009259 if (p_wiw < 1)
9260 {
9261 errmsg = e_positive;
9262 p_wiw = 1;
9263 }
9264 if (p_wmw > p_wiw)
9265 {
9266 errmsg = e_winwidth;
9267 p_wiw = p_wmw;
9268 }
9269
9270 /* Change window width NOW */
Bram Moolenaar459ca562016-11-10 18:16:33 +01009271 if (!ONE_WINDOW && curwin->w_width < p_wiw)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009272 win_setwidth((int)p_wiw);
9273 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009274 else if (pp == &p_wmw)
9275 {
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009276 // 'winminwidth'
Bram Moolenaar071d4272004-06-13 20:20:40 +00009277 if (p_wmw < 0)
9278 {
9279 errmsg = e_positive;
9280 p_wmw = 0;
9281 }
9282 if (p_wmw > p_wiw)
9283 {
9284 errmsg = e_winwidth;
9285 p_wmw = p_wiw;
9286 }
Bram Moolenaar1c3c1042018-06-12 16:49:30 +02009287 win_setminwidth();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009288 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009289
Bram Moolenaar071d4272004-06-13 20:20:40 +00009290 /* (re)set last window status line */
9291 else if (pp == &p_ls)
9292 {
9293 last_status(FALSE);
9294 }
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009295
9296 /* (re)set tab page line */
Bram Moolenaarfaa959a2006-02-20 21:37:40 +00009297 else if (pp == &p_stal)
Bram Moolenaar4c7ed462006-02-15 22:18:42 +00009298 {
9299 shell_new_rows(); /* recompute window positions and heights */
9300 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009301
9302#ifdef FEAT_GUI
9303 else if (pp == &p_linespace)
9304 {
Bram Moolenaar02743632005-07-25 20:42:36 +00009305 /* Recompute gui.char_height and resize the Vim window to keep the
9306 * same number of lines. */
9307 if (gui.in_use && gui_mch_adjust_charheight() == OK)
Bram Moolenaar3964b7e2006-03-27 20:59:33 +00009308 gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009309 }
9310#endif
9311
9312#ifdef FEAT_FOLDING
9313 /* 'foldlevel' */
9314 else if (pp == &curwin->w_p_fdl)
9315 {
9316 if (curwin->w_p_fdl < 0)
9317 curwin->w_p_fdl = 0;
9318 newFoldLevel();
9319 }
9320
Bram Moolenaar1f26d2f2009-02-11 10:35:36 +00009321 /* 'foldminlines' */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009322 else if (pp == &curwin->w_p_fml)
9323 {
9324 foldUpdateAll(curwin);
9325 }
9326
9327 /* 'foldnestmax' */
9328 else if (pp == &curwin->w_p_fdn)
9329 {
9330 if (foldmethodIsSyntax(curwin) || foldmethodIsIndent(curwin))
9331 foldUpdateAll(curwin);
9332 }
9333
9334 /* 'foldcolumn' */
9335 else if (pp == &curwin->w_p_fdc)
9336 {
9337 if (curwin->w_p_fdc < 0)
9338 {
9339 errmsg = e_positive;
9340 curwin->w_p_fdc = 0;
9341 }
9342 else if (curwin->w_p_fdc > 12)
9343 {
9344 errmsg = e_invarg;
9345 curwin->w_p_fdc = 12;
9346 }
9347 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009348#endif /* FEAT_FOLDING */
Bram Moolenaar071d4272004-06-13 20:20:40 +00009349
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009350#if defined(FEAT_FOLDING) || defined(FEAT_CINDENT)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009351 /* 'shiftwidth' or 'tabstop' */
9352 else if (pp == &curbuf->b_p_sw || pp == &curbuf->b_p_ts)
9353 {
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009354# ifdef FEAT_FOLDING
Bram Moolenaar071d4272004-06-13 20:20:40 +00009355 if (foldmethodIsIndent(curwin))
9356 foldUpdateAll(curwin);
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009357# endif
9358# ifdef FEAT_CINDENT
9359 /* When 'shiftwidth' changes, or it's zero and 'tabstop' changes:
9360 * parse 'cinoptions'. */
9361 if (pp == &curbuf->b_p_sw || curbuf->b_p_sw == 0)
9362 parse_cino(curbuf);
9363# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009364 }
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +01009365#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009366
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009367 /* 'maxcombine' */
9368 else if (pp == &p_mco)
9369 {
9370 if (p_mco > MAX_MCO)
9371 p_mco = MAX_MCO;
9372 else if (p_mco < 0)
9373 p_mco = 0;
9374 screenclear(); /* will re-allocate the screen */
9375 }
Bram Moolenaar362e1a32006-03-06 23:29:24 +00009376
Bram Moolenaar071d4272004-06-13 20:20:40 +00009377 else if (pp == &curbuf->b_p_iminsert)
9378 {
9379 if (curbuf->b_p_iminsert < 0 || curbuf->b_p_iminsert > B_IMODE_LAST)
9380 {
9381 errmsg = e_invarg;
9382 curbuf->b_p_iminsert = B_IMODE_NONE;
9383 }
9384 p_iminsert = curbuf->b_p_iminsert;
9385 if (termcap_active) /* don't do this in the alternate screen */
9386 showmode();
Bram Moolenaar4033c552017-09-16 20:54:51 +02009387#if defined(FEAT_KEYMAP)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009388 /* Show/unshow value of 'keymap' in status lines. */
9389 status_redraw_curbuf();
9390#endif
9391 }
9392
Bram Moolenaar5c6dbcb2017-08-30 22:00:20 +02009393#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
9394 /* 'imstyle' */
9395 else if (pp == &p_imst)
9396 {
9397 if (p_imst != IM_ON_THE_SPOT && p_imst != IM_OVER_THE_SPOT)
9398 errmsg = e_invarg;
9399 }
9400#endif
9401
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009402 else if (pp == &p_window)
9403 {
9404 if (p_window < 1)
9405 p_window = 1;
9406 else if (p_window >= Rows)
9407 p_window = Rows - 1;
9408 }
9409
Bram Moolenaar071d4272004-06-13 20:20:40 +00009410 else if (pp == &curbuf->b_p_imsearch)
9411 {
9412 if (curbuf->b_p_imsearch < -1 || curbuf->b_p_imsearch > B_IMODE_LAST)
9413 {
9414 errmsg = e_invarg;
9415 curbuf->b_p_imsearch = B_IMODE_NONE;
9416 }
9417 p_imsearch = curbuf->b_p_imsearch;
9418 }
9419
9420#ifdef FEAT_TITLE
9421 /* if 'titlelen' has changed, redraw the title */
9422 else if (pp == &p_titlelen)
9423 {
9424 if (p_titlelen < 0)
9425 {
9426 errmsg = e_positive;
9427 p_titlelen = 85;
9428 }
9429 if (starting != NO_SCREEN && old_value != p_titlelen)
9430 need_maketitle = TRUE;
9431 }
9432#endif
9433
9434 /* if p_ch changed value, change the command line height */
9435 else if (pp == &p_ch)
9436 {
9437 if (p_ch < 1)
9438 {
9439 errmsg = e_positive;
9440 p_ch = 1;
9441 }
Bram Moolenaar719939c2007-09-25 12:51:28 +00009442 if (p_ch > Rows - min_rows() + 1)
9443 p_ch = Rows - min_rows() + 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009444
9445 /* Only compute the new window layout when startup has been
9446 * completed. Otherwise the frame sizes may be wrong. */
9447 if (p_ch != old_value && full_screen
9448#ifdef FEAT_GUI
9449 && !gui.starting
9450#endif
9451 )
Bram Moolenaarc6fe9192006-04-09 21:54:49 +00009452 command_height();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009453 }
9454
9455 /* when 'updatecount' changes from zero to non-zero, open swap files */
9456 else if (pp == &p_uc)
9457 {
9458 if (p_uc < 0)
9459 {
9460 errmsg = e_positive;
9461 p_uc = 100;
9462 }
9463 if (p_uc && !old_value)
9464 ml_open_files();
9465 }
Bram Moolenaar860cae12010-06-05 23:22:07 +02009466#ifdef FEAT_CONCEAL
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009467 else if (pp == &curwin->w_p_cole)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009468 {
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009469 if (curwin->w_p_cole < 0)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009470 {
9471 errmsg = e_positive;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009472 curwin->w_p_cole = 0;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009473 }
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009474 else if (curwin->w_p_cole > 3)
Bram Moolenaar860cae12010-06-05 23:22:07 +02009475 {
9476 errmsg = e_invarg;
Bram Moolenaarf5963f72010-07-23 22:10:27 +02009477 curwin->w_p_cole = 3;
Bram Moolenaar860cae12010-06-05 23:22:07 +02009478 }
9479 }
9480#endif
Bram Moolenaar2df6dcc2004-07-12 15:53:54 +00009481#ifdef MZSCHEME_GUI_THREADS
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009482 else if (pp == &p_mzq)
9483 mzvim_reset_timer();
9484#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00009485
Bram Moolenaarf42dd3c2017-01-28 16:06:38 +01009486#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
9487 /* 'pyxversion' */
9488 else if (pp == &p_pyx)
9489 {
9490 if (p_pyx != 0 && p_pyx != 2 && p_pyx != 3)
9491 errmsg = e_invarg;
9492 }
9493#endif
9494
Bram Moolenaar071d4272004-06-13 20:20:40 +00009495 /* sync undo before 'undolevels' changes */
9496 else if (pp == &p_ul)
9497 {
9498 /* use the old value, otherwise u_sync() may not work properly */
9499 p_ul = old_value;
Bram Moolenaar779b74b2006-04-10 14:55:34 +00009500 u_sync(TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009501 p_ul = value;
9502 }
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +01009503 else if (pp == &curbuf->b_p_ul)
9504 {
9505 /* use the old value, otherwise u_sync() may not work properly */
9506 curbuf->b_p_ul = old_value;
9507 u_sync(TRUE);
9508 curbuf->b_p_ul = value;
9509 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009510
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009511#ifdef FEAT_LINEBREAK
9512 /* 'numberwidth' must be positive */
9513 else if (pp == &curwin->w_p_nuw)
9514 {
9515 if (curwin->w_p_nuw < 1)
9516 {
9517 errmsg = e_positive;
9518 curwin->w_p_nuw = 1;
9519 }
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009520 if (curwin->w_p_nuw > 20)
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009521 {
9522 errmsg = e_invarg;
Bram Moolenaarf8a07122019-07-01 22:06:07 +02009523 curwin->w_p_nuw = 20;
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009524 }
Bram Moolenaar1e7813a2015-03-31 18:31:03 +02009525 curwin->w_nrwidth_line_count = 0; /* trigger a redraw */
Bram Moolenaar592e0a22004-07-03 16:05:59 +00009526 }
9527#endif
9528
Bram Moolenaar1a384422010-07-14 19:53:30 +02009529 else if (pp == &curbuf->b_p_tw)
9530 {
9531 if (curbuf->b_p_tw < 0)
9532 {
9533 errmsg = e_positive;
9534 curbuf->b_p_tw = 0;
9535 }
9536#ifdef FEAT_SYN_HL
Bram Moolenaar1a384422010-07-14 19:53:30 +02009537 {
9538 win_T *wp;
9539 tabpage_T *tp;
9540
9541 FOR_ALL_TAB_WINDOWS(tp, wp)
9542 check_colorcolumn(wp);
9543 }
Bram Moolenaar1a384422010-07-14 19:53:30 +02009544#endif
9545 }
9546
Bram Moolenaar071d4272004-06-13 20:20:40 +00009547 /*
9548 * Check the bounds for numeric options here
9549 */
9550 if (Rows < min_rows() && full_screen)
9551 {
9552 if (errbuf != NULL)
9553 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009554 vim_snprintf((char *)errbuf, errbuflen,
9555 _("E593: Need at least %d lines"), min_rows());
Bram Moolenaar071d4272004-06-13 20:20:40 +00009556 errmsg = errbuf;
9557 }
9558 Rows = min_rows();
9559 }
9560 if (Columns < MIN_COLUMNS && full_screen)
9561 {
9562 if (errbuf != NULL)
9563 {
Bram Moolenaar555b2802005-05-19 21:08:39 +00009564 vim_snprintf((char *)errbuf, errbuflen,
9565 _("E594: Need at least %d columns"), MIN_COLUMNS);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009566 errmsg = errbuf;
9567 }
9568 Columns = MIN_COLUMNS;
9569 }
Bram Moolenaare057d402013-06-30 17:51:51 +02009570 limit_screen_size();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009571
Bram Moolenaar071d4272004-06-13 20:20:40 +00009572 /*
9573 * If the screen (shell) height has been changed, assume it is the
9574 * physical screenheight.
9575 */
9576 if (old_Rows != Rows || old_Columns != Columns)
9577 {
9578 /* Changing the screen size is not allowed while updating the screen. */
9579 if (updating_screen)
9580 *pp = old_value;
9581 else if (full_screen
9582#ifdef FEAT_GUI
9583 && !gui.starting
9584#endif
9585 )
9586 set_shellsize((int)Columns, (int)Rows, TRUE);
9587 else
9588 {
9589 /* Postpone the resizing; check the size and cmdline position for
9590 * messages. */
9591 check_shellsize();
9592 if (cmdline_row > Rows - p_ch && Rows > p_ch)
9593 cmdline_row = Rows - p_ch;
9594 }
Bram Moolenaard68071d2006-05-02 22:08:30 +00009595 if (p_window >= Rows || !option_was_set((char_u *)"window"))
Bram Moolenaar4399ef42005-02-12 14:29:27 +00009596 p_window = Rows - 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009597 }
9598
Bram Moolenaar071d4272004-06-13 20:20:40 +00009599 if (curbuf->b_p_ts <= 0)
9600 {
9601 errmsg = e_positive;
9602 curbuf->b_p_ts = 8;
9603 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009604 if (p_tm < 0)
9605 {
9606 errmsg = e_positive;
9607 p_tm = 0;
9608 }
9609 if ((curwin->w_p_scr <= 0
9610 || (curwin->w_p_scr > curwin->w_height
9611 && curwin->w_height > 0))
9612 && full_screen)
9613 {
9614 if (pp == &(curwin->w_p_scr))
9615 {
9616 if (curwin->w_p_scr != 0)
9617 errmsg = e_scroll;
9618 win_comp_scroll(curwin);
9619 }
9620 /* If 'scroll' became invalid because of a side effect silently adjust
9621 * it. */
9622 else if (curwin->w_p_scr <= 0)
9623 curwin->w_p_scr = 1;
9624 else /* curwin->w_p_scr > curwin->w_height */
9625 curwin->w_p_scr = curwin->w_height;
9626 }
Bram Moolenaar991e10f2008-10-02 20:48:41 +00009627 if (p_hi < 0)
9628 {
9629 errmsg = e_positive;
9630 p_hi = 0;
9631 }
Bram Moolenaar78159bb2014-06-25 11:48:54 +02009632 else if (p_hi > 10000)
9633 {
9634 errmsg = e_invarg;
9635 p_hi = 10000;
9636 }
Bram Moolenaarfbc0d2e2013-05-19 19:40:29 +02009637 if (p_re < 0 || p_re > 2)
9638 {
9639 errmsg = e_invarg;
9640 p_re = 0;
9641 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009642 if (p_report < 0)
9643 {
9644 errmsg = e_positive;
9645 p_report = 1;
9646 }
Bram Moolenaar1e015462005-09-25 22:16:38 +00009647 if ((p_sj < -100 || p_sj >= Rows) && full_screen)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009648 {
9649 if (Rows != old_Rows) /* Rows changed, just adjust p_sj */
9650 p_sj = Rows / 2;
9651 else
9652 {
9653 errmsg = e_scroll;
9654 p_sj = 1;
9655 }
9656 }
9657 if (p_so < 0 && full_screen)
9658 {
Bram Moolenaar375e3392019-01-31 18:26:10 +01009659 errmsg = e_positive;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009660 p_so = 0;
9661 }
9662 if (p_siso < 0 && full_screen)
9663 {
9664 errmsg = e_positive;
9665 p_siso = 0;
9666 }
9667#ifdef FEAT_CMDWIN
9668 if (p_cwh < 1)
9669 {
9670 errmsg = e_positive;
9671 p_cwh = 1;
9672 }
9673#endif
9674 if (p_ut < 0)
9675 {
9676 errmsg = e_positive;
9677 p_ut = 2000;
9678 }
9679 if (p_ss < 0)
9680 {
9681 errmsg = e_positive;
9682 p_ss = 0;
9683 }
9684
9685 /* May set global value for local option. */
9686 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9687 *(long *)get_varp_scope(&(options[opt_idx]), OPT_GLOBAL) = *pp;
9688
9689 options[opt_idx].flags |= P_WAS_SET;
9690
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +01009691#if defined(FEAT_EVAL)
Bram Moolenaar3f3fb0b2018-09-21 11:59:32 +02009692 // Don't do this while starting up, failure or recursively.
9693 if (!starting && errmsg == NULL && *get_vim_var_str(VV_OPTION_TYPE) == NUL)
Bram Moolenaar53744302015-07-17 17:38:22 +02009694 {
Bram Moolenaard7c96872019-06-15 17:12:48 +02009695 char_u buf_old[11], buf_old_global[11], buf_new[11], buf_type[7];
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009696 vim_snprintf((char *)buf_old, 10, "%ld", old_value);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009697 vim_snprintf((char *)buf_old_global, 10, "%ld", old_global_value);
Bram Moolenaarfb9bc482015-07-17 22:04:48 +02009698 vim_snprintf((char *)buf_new, 10, "%ld", value);
9699 vim_snprintf((char *)buf_type, 7, "%s", (opt_flags & OPT_LOCAL) ? "local" : "global");
Bram Moolenaar53744302015-07-17 17:38:22 +02009700 set_vim_var_string(VV_OPTION_NEW, buf_new, -1);
9701 set_vim_var_string(VV_OPTION_OLD, buf_old, -1);
9702 set_vim_var_string(VV_OPTION_TYPE, buf_type, -1);
Bram Moolenaard7c96872019-06-15 17:12:48 +02009703 if (opt_flags & OPT_LOCAL)
9704 {
9705 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setlocal", -1);
9706 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9707 }
9708 if (opt_flags & OPT_GLOBAL)
9709 {
9710 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"setglobal", -1);
9711 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old, -1);
9712 }
9713 if ((opt_flags & (OPT_LOCAL | OPT_GLOBAL)) == 0)
9714 {
9715 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"set", -1);
9716 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9717 set_vim_var_string(VV_OPTION_OLDGLOBAL, buf_old_global, -1);
9718 }
9719 if (opt_flags & OPT_MODELINE)
9720 {
9721 set_vim_var_string(VV_OPTION_COMMAND, (char_u *)"modeline", -1);
9722 set_vim_var_string(VV_OPTION_OLDLOCAL, buf_old, -1);
9723 }
9724 apply_autocmds(EVENT_OPTIONSET, (char_u *)options[opt_idx].fullname,
9725 NULL, FALSE, NULL);
Bram Moolenaar53744302015-07-17 17:38:22 +02009726 reset_v_option_vars();
9727 }
9728#endif
9729
Bram Moolenaar071d4272004-06-13 20:20:40 +00009730 comp_col(); /* in case 'columns' or 'ls' changed */
Bram Moolenaar913077c2012-03-28 19:59:04 +02009731 if (curwin->w_curswant != MAXCOL
Bram Moolenaar488eb262015-03-13 11:23:50 +01009732 && (options[opt_idx].flags & (P_CURSWANT | P_RALL)) != 0)
Bram Moolenaar913077c2012-03-28 19:59:04 +02009733 curwin->w_set_curswant = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009734 check_redraw(options[opt_idx].flags);
9735
9736 return errmsg;
9737}
9738
9739/*
9740 * Called after an option changed: check if something needs to be redrawn.
9741 */
9742 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +01009743check_redraw(long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009744{
9745 /* Careful: P_RCLR and P_RALL are a combination of other P_ flags */
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009746 int doclear = (flags & P_RCLR) == P_RCLR;
9747 int all = ((flags & P_RALL) == P_RALL || doclear);
Bram Moolenaar071d4272004-06-13 20:20:40 +00009748
Bram Moolenaar071d4272004-06-13 20:20:40 +00009749 if ((flags & P_RSTAT) || all) /* mark all status lines dirty */
9750 status_redraw_all();
Bram Moolenaar071d4272004-06-13 20:20:40 +00009751
9752 if ((flags & P_RBUF) || (flags & P_RWIN) || all)
9753 changed_window_setting();
9754 if (flags & P_RBUF)
9755 redraw_curbuf_later(NOT_VALID);
Bram Moolenaara2477fd2016-12-03 15:13:20 +01009756 if (flags & P_RWINONLY)
9757 redraw_later(NOT_VALID);
Bram Moolenaar70b2a562012-01-10 22:26:17 +01009758 if (doclear)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009759 redraw_all_later(CLEAR);
9760 else if (all)
9761 redraw_all_later(NOT_VALID);
9762}
9763
9764/*
9765 * Find index for option 'arg'.
9766 * Return -1 if not found.
9767 */
9768 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009769findoption(char_u *arg)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009770{
9771 int opt_idx;
9772 char *s, *p;
9773 static short quick_tab[27] = {0, 0}; /* quick access table */
9774 int is_term_opt;
9775
9776 /*
9777 * For first call: Initialize the quick-access table.
9778 * It contains the index for the first option that starts with a certain
9779 * letter. There are 26 letters, plus the first "t_" option.
9780 */
9781 if (quick_tab[1] == 0)
9782 {
9783 p = options[0].fullname;
9784 for (opt_idx = 1; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9785 {
9786 if (s[0] != p[0])
9787 {
9788 if (s[0] == 't' && s[1] == '_')
9789 quick_tab[26] = opt_idx;
9790 else
9791 quick_tab[CharOrdLow(s[0])] = opt_idx;
9792 }
9793 p = s;
9794 }
9795 }
9796
9797 /*
9798 * Check for name starting with an illegal character.
9799 */
9800#ifdef EBCDIC
9801 if (!islower(arg[0]))
9802#else
9803 if (arg[0] < 'a' || arg[0] > 'z')
9804#endif
9805 return -1;
9806
9807 is_term_opt = (arg[0] == 't' && arg[1] == '_');
9808 if (is_term_opt)
9809 opt_idx = quick_tab[26];
9810 else
9811 opt_idx = quick_tab[CharOrdLow(arg[0])];
9812 for ( ; (s = options[opt_idx].fullname) != NULL; opt_idx++)
9813 {
9814 if (STRCMP(arg, s) == 0) /* match full name */
9815 break;
9816 }
9817 if (s == NULL && !is_term_opt)
9818 {
9819 opt_idx = quick_tab[CharOrdLow(arg[0])];
9820 for ( ; options[opt_idx].fullname != NULL; opt_idx++)
9821 {
9822 s = options[opt_idx].shortname;
9823 if (s != NULL && STRCMP(arg, s) == 0) /* match short name */
9824 break;
9825 s = NULL;
9826 }
9827 }
9828 if (s == NULL)
9829 opt_idx = -1;
9830 return opt_idx;
9831}
9832
Bram Moolenaar325b7a22004-07-05 15:58:32 +00009833#if defined(FEAT_EVAL) || defined(FEAT_TCL) || defined(FEAT_MZSCHEME)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009834/*
9835 * Get the value for an option.
9836 *
9837 * Returns:
9838 * Number or Toggle option: 1, *numval gets value.
9839 * String option: 0, *stringval gets allocated string.
9840 * Hidden Number or Toggle option: -1.
9841 * hidden String option: -2.
9842 * unknown option: -3.
9843 */
9844 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009845get_option_value(
9846 char_u *name,
9847 long *numval,
9848 char_u **stringval, /* NULL when only checking existence */
9849 int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009850{
9851 int opt_idx;
9852 char_u *varp;
9853
9854 opt_idx = findoption(name);
9855 if (opt_idx < 0) /* unknown option */
Bram Moolenaare353c402017-02-04 19:49:16 +01009856 {
9857 int key;
9858
9859 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +02009860 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +01009861 {
9862 char_u key_name[2];
9863 char_u *p;
9864
9865 if (key < 0)
9866 {
9867 key_name[0] = KEY2TERMCAP0(key);
9868 key_name[1] = KEY2TERMCAP1(key);
9869 }
9870 else
9871 {
9872 key_name[0] = KS_KEY;
9873 key_name[1] = (key & 0xff);
9874 }
9875 p = find_termcode(key_name);
9876 if (p != NULL)
9877 {
9878 if (stringval != NULL)
9879 *stringval = vim_strsave(p);
9880 return 0;
9881 }
9882 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009883 return -3;
Bram Moolenaare353c402017-02-04 19:49:16 +01009884 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00009885
9886 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
9887
9888 if (options[opt_idx].flags & P_STRING)
9889 {
9890 if (varp == NULL) /* hidden option */
9891 return -2;
9892 if (stringval != NULL)
9893 {
9894#ifdef FEAT_CRYPT
9895 /* never return the value of the crypt key */
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +00009896 if ((char_u **)varp == &curbuf->b_p_key
9897 && **(char_u **)(varp) != NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00009898 *stringval = vim_strsave((char_u *)"*****");
9899 else
9900#endif
9901 *stringval = vim_strsave(*(char_u **)(varp));
9902 }
9903 return 0;
9904 }
9905
9906 if (varp == NULL) /* hidden option */
9907 return -1;
9908 if (options[opt_idx].flags & P_NUM)
9909 *numval = *(long *)varp;
9910 else
9911 {
9912 /* Special case: 'modified' is b_changed, but we also want to consider
9913 * it set when 'ff' or 'fenc' changed. */
9914 if ((int *)varp == &curbuf->b_changed)
9915 *numval = curbufIsChanged();
9916 else
Bram Moolenaar2acfbed2016-07-01 23:14:02 +02009917 *numval = (long) *(int *)varp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00009918 }
9919 return 1;
9920}
9921#endif
9922
Bram Moolenaar1028f4d2014-01-14 16:55:00 +01009923#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009924/*
9925 * Returns the option attributes and its value. Unlike the above function it
9926 * will return either global value or local value of the option depending on
9927 * what was requested, but it will never return global value if it was
9928 * requested to return local one and vice versa. Neither it will return
9929 * buffer-local value if it was requested to return window-local one.
9930 *
9931 * Pretends that option is absent if it is not present in the requested scope
9932 * (i.e. has no global, window-local or buffer-local value depending on
9933 * opt_type). Uses
9934 *
9935 * Returned flags:
Bram Moolenaar75a8d742014-05-07 15:10:21 +02009936 * 0 hidden or unknown option, also option that does not have requested
9937 * type (see SREQ_* in vim.h)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009938 * see SOPT_* in vim.h for other flags
9939 *
9940 * Possible opt_type values: see SREQ_* in vim.h
9941 */
9942 int
Bram Moolenaar9b578142016-01-30 19:39:49 +01009943get_option_value_strict(
9944 char_u *name,
9945 long *numval,
9946 char_u **stringval, /* NULL when only obtaining attributes */
9947 int opt_type,
9948 void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009949{
9950 int opt_idx;
Bram Moolenaar68001862013-05-11 13:45:05 +02009951 char_u *varp = NULL;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +02009952 struct vimoption *p;
9953 int r = 0;
9954
9955 opt_idx = findoption(name);
9956 if (opt_idx < 0)
9957 return 0;
9958
9959 p = &(options[opt_idx]);
9960
9961 /* Hidden option */
9962 if (p->var == NULL)
9963 return 0;
9964
9965 if (p->flags & P_BOOL)
9966 r |= SOPT_BOOL;
9967 else if (p->flags & P_NUM)
9968 r |= SOPT_NUM;
9969 else if (p->flags & P_STRING)
9970 r |= SOPT_STRING;
9971
9972 if (p->indir == PV_NONE)
9973 {
9974 if (opt_type == SREQ_GLOBAL)
9975 r |= SOPT_GLOBAL;
9976 else
9977 return 0; /* Did not request global-only option */
9978 }
9979 else
9980 {
9981 if (p->indir & PV_BOTH)
9982 r |= SOPT_GLOBAL;
9983 else if (opt_type == SREQ_GLOBAL)
9984 return 0; /* Requested global option */
9985
9986 if (p->indir & PV_WIN)
9987 {
9988 if (opt_type == SREQ_BUF)
9989 return 0; /* Did not request window-local option */
9990 else
9991 r |= SOPT_WIN;
9992 }
9993 else if (p->indir & PV_BUF)
9994 {
9995 if (opt_type == SREQ_WIN)
9996 return 0; /* Did not request buffer-local option */
9997 else
9998 r |= SOPT_BUF;
9999 }
10000 }
10001
10002 if (stringval == NULL)
10003 return r;
10004
10005 if (opt_type == SREQ_GLOBAL)
10006 varp = p->var;
10007 else
10008 {
10009 if (opt_type == SREQ_BUF)
10010 {
10011 /* Special case: 'modified' is b_changed, but we also want to
10012 * consider it set when 'ff' or 'fenc' changed. */
10013 if (p->indir == PV_MOD)
10014 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010015 *numval = bufIsChanged((buf_T *)from);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010016 varp = NULL;
10017 }
10018#ifdef FEAT_CRYPT
10019 else if (p->indir == PV_KEY)
10020 {
10021 /* never return the value of the crypt key */
10022 *stringval = NULL;
10023 varp = NULL;
10024 }
10025#endif
10026 else
10027 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010028 buf_T *save_curbuf = curbuf;
10029
10030 // only getting a pointer, no need to use aucmd_prepbuf()
10031 curbuf = (buf_T *)from;
10032 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010033 varp = get_varp(p);
Bram Moolenaardefe6422018-06-24 15:14:07 +020010034 curbuf = save_curbuf;
10035 curwin->w_buffer = curbuf;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010036 }
10037 }
10038 else if (opt_type == SREQ_WIN)
10039 {
Bram Moolenaardefe6422018-06-24 15:14:07 +020010040 win_T *save_curwin = curwin;
10041
10042 curwin = (win_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010043 curbuf = curwin->w_buffer;
10044 varp = get_varp(p);
10045 curwin = save_curwin;
10046 curbuf = curwin->w_buffer;
10047 }
10048 if (varp == p->var)
10049 return (r | SOPT_UNSET);
10050 }
10051
10052 if (varp != NULL)
10053 {
10054 if (p->flags & P_STRING)
10055 *stringval = vim_strsave(*(char_u **)(varp));
10056 else if (p->flags & P_NUM)
10057 *numval = *(long *) varp;
10058 else
10059 *numval = *(int *)varp;
10060 }
10061
10062 return r;
10063}
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010064
10065/*
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010066 * Iterate over options. First argument is a pointer to a pointer to a
10067 * structure inside options[] array, second is option type like in the above
10068 * function.
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010069 *
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010070 * If first argument points to NULL it is assumed that iteration just started
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010071 * and caller needs the very first value.
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010072 * If first argument points to the end marker function returns NULL and sets
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010073 * first argument to NULL.
10074 *
10075 * Returns full option name for current option on each call.
10076 */
10077 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010078option_iter_next(void **option, int opt_type)
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010079{
10080 struct vimoption *ret = NULL;
10081 do
10082 {
10083 if (*option == NULL)
10084 *option = (void *) options;
10085 else if (((struct vimoption *) (*option))->fullname == NULL)
10086 {
10087 *option = NULL;
10088 return NULL;
10089 }
10090 else
10091 *option = (void *) (((struct vimoption *) (*option)) + 1);
10092
10093 ret = ((struct vimoption *) (*option));
10094
10095 /* Hidden option */
10096 if (ret->var == NULL)
10097 {
10098 ret = NULL;
10099 continue;
10100 }
10101
10102 switch (opt_type)
10103 {
10104 case SREQ_GLOBAL:
10105 if (!(ret->indir == PV_NONE || ret->indir & PV_BOTH))
10106 ret = NULL;
10107 break;
10108 case SREQ_BUF:
10109 if (!(ret->indir & PV_BUF))
10110 ret = NULL;
10111 break;
10112 case SREQ_WIN:
10113 if (!(ret->indir & PV_WIN))
10114 ret = NULL;
10115 break;
10116 default:
Bram Moolenaar95f09602016-11-10 20:01:45 +010010117 internal_error("option_iter_next()");
Bram Moolenaar1028f4d2014-01-14 16:55:00 +010010118 return NULL;
10119 }
10120 }
10121 while (ret == NULL);
10122
10123 return (char_u *)ret->fullname;
10124}
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010125#endif
10126
Bram Moolenaar071d4272004-06-13 20:20:40 +000010127/*
10128 * Set the value of option "name".
10129 * Use "string" for string options, use "number" for other options.
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010130 *
10131 * Returns NULL on success or error message on error.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010132 */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010133 char *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010134set_option_value(
10135 char_u *name,
10136 long number,
10137 char_u *string,
10138 int opt_flags) /* OPT_LOCAL or 0 (both) */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010139{
10140 int opt_idx;
10141 char_u *varp;
Bram Moolenaara93fa7e2006-04-17 22:14:47 +000010142 long_u flags;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010143
10144 opt_idx = findoption(name);
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000010145 if (opt_idx < 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010146 {
10147 int key;
10148
10149 if (STRLEN(name) == 4 && name[0] == 't' && name[1] == '_'
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010150 && (key = find_key_option(name, FALSE)) != 0)
Bram Moolenaare353c402017-02-04 19:49:16 +010010151 {
10152 char_u key_name[2];
10153
10154 if (key < 0)
10155 {
10156 key_name[0] = KEY2TERMCAP0(key);
10157 key_name[1] = KEY2TERMCAP1(key);
10158 }
10159 else
10160 {
10161 key_name[0] = KS_KEY;
10162 key_name[1] = (key & 0xff);
10163 }
10164 add_termcode(key_name, string, FALSE);
10165 if (full_screen)
10166 ttest(FALSE);
10167 redraw_all_later(CLEAR);
10168 return NULL;
10169 }
10170
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010171 semsg(_("E355: Unknown option: %s"), name);
Bram Moolenaare353c402017-02-04 19:49:16 +010010172 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010173 else
10174 {
10175 flags = options[opt_idx].flags;
10176#ifdef HAVE_SANDBOX
10177 /* Disallow changing some options in the sandbox */
10178 if (sandbox > 0 && (flags & P_SECURE))
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010179 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010180 emsg(_(e_sandbox));
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010181 return NULL;
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010182 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010183#endif
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010184 if (flags & P_STRING)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010185 return set_string_option(opt_idx, string, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010186 else
10187 {
Bram Moolenaarb3163762008-07-08 15:15:08 +000010188 varp = get_varp_scope(&(options[opt_idx]), opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010189 if (varp != NULL) /* hidden option is not changed */
10190 {
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010191 if (number == 0 && string != NULL)
10192 {
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010193 int idx;
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010194
10195 /* Either we are given a string or we are setting option
10196 * to zero. */
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010197 for (idx = 0; string[idx] == '0'; ++idx)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010198 ;
Bram Moolenaarfe86f2d2008-11-28 20:29:07 +000010199 if (string[idx] != NUL || idx == 0)
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010200 {
10201 /* There's another character after zeros or the string
10202 * is empty. In both cases, we are trying to set a
10203 * num option using a string. */
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010010204 semsg(_("E521: Number required: &%s = '%s'"),
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010205 name, string);
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010206 return NULL; /* do nothing as we hit an error */
Bram Moolenaar96bb6212007-06-19 18:52:53 +000010207
10208 }
10209 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010210 if (flags & P_NUM)
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010211 return set_num_option(opt_idx, varp, number,
Bram Moolenaar555b2802005-05-19 21:08:39 +000010212 NULL, 0, opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010213 else
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010214 return set_bool_option(opt_idx, varp, (int)number,
Bram Moolenaarb71eaae2006-01-20 23:10:18 +000010215 opt_flags);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010216 }
10217 }
10218 }
Bram Moolenaarc96ebe72013-05-21 22:38:18 +020010219 return NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010220}
10221
10222/*
10223 * Get the terminal code for a terminal option.
10224 * Returns NULL when not found.
10225 */
10226 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010227get_term_code(char_u *tname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010228{
10229 int opt_idx;
10230 char_u *varp;
10231
10232 if (tname[0] != 't' || tname[1] != '_' ||
10233 tname[2] == NUL || tname[3] == NUL)
10234 return NULL;
10235 if ((opt_idx = findoption(tname)) >= 0)
10236 {
10237 varp = get_varp(&(options[opt_idx]));
10238 if (varp != NULL)
10239 varp = *(char_u **)(varp);
10240 return varp;
10241 }
10242 return find_termcode(tname + 2);
10243}
10244
10245 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010246get_highlight_default(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010247{
10248 int i;
10249
10250 i = findoption((char_u *)"hl");
10251 if (i >= 0)
10252 return options[i].def_val[VI_DEFAULT];
10253 return (char_u *)NULL;
10254}
10255
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010256 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010010257get_encoding_default(void)
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010258{
10259 int i;
10260
10261 i = findoption((char_u *)"enc");
10262 if (i >= 0)
10263 return options[i].def_val[VI_DEFAULT];
10264 return (char_u *)NULL;
10265}
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000010266
Bram Moolenaar071d4272004-06-13 20:20:40 +000010267/*
10268 * Translate a string like "t_xx", "<t_xx>" or "<S-Tab>" to a key number.
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010269 * When "has_lt" is true there is a '<' before "*arg_arg".
10270 * Returns 0 when the key is not recognized.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010271 */
10272 static int
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010273find_key_option(char_u *arg_arg, int has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010274{
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010275 int key = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010276 int modifiers;
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010277 char_u *arg = arg_arg;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010278
10279 /*
10280 * Don't use get_special_key_code() for t_xx, we don't want it to call
10281 * add_termcap_entry().
10282 */
10283 if (arg[0] == 't' && arg[1] == '_' && arg[2] && arg[3])
10284 key = TERMCAP2KEY(arg[2], arg[3]);
Bram Moolenaar9cf4b502018-07-23 04:12:03 +020010285 else if (has_lt)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010286 {
10287 --arg; /* put arg at the '<' */
10288 modifiers = 0;
Bram Moolenaar35a4cfa2016-08-14 16:07:48 +020010289 key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010290 if (modifiers) /* can't handle modifiers here */
10291 key = 0;
10292 }
10293 return key;
10294}
10295
10296/*
10297 * if 'all' == 0: show changed options
10298 * if 'all' == 1: show all normal options
10299 * if 'all' == 2: show all terminal options
10300 */
10301 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010302showoptions(
10303 int all,
10304 int opt_flags) /* OPT_LOCAL and/or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010305{
10306 struct vimoption *p;
10307 int col;
10308 int isterm;
10309 char_u *varp;
10310 struct vimoption **items;
10311 int item_count;
10312 int run;
10313 int row, rows;
10314 int cols;
10315 int i;
10316 int len;
10317
10318#define INC 20
10319#define GAP 3
10320
Bram Moolenaarc799fe22019-05-28 23:08:19 +020010321 items = ALLOC_MULT(struct vimoption *, PARAM_COUNT);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010322 if (items == NULL)
10323 return;
10324
10325 /* Highlight title */
10326 if (all == 2)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010327 msg_puts_title(_("\n--- Terminal codes ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010328 else if (opt_flags & OPT_GLOBAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010329 msg_puts_title(_("\n--- Global option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010330 else if (opt_flags & OPT_LOCAL)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010331 msg_puts_title(_("\n--- Local option values ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010332 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010333 msg_puts_title(_("\n--- Options ---"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010334
10335 /*
10336 * do the loop two times:
10337 * 1. display the short items
10338 * 2. display the long items (only strings and numbers)
10339 */
10340 for (run = 1; run <= 2 && !got_int; ++run)
10341 {
10342 /*
10343 * collect the items in items[]
10344 */
10345 item_count = 0;
10346 for (p = &options[0]; p->fullname != NULL; p++)
10347 {
Bram Moolenaarf86db782018-10-25 13:31:37 +020010348 // apply :filter /pat/
10349 if (message_filtered((char_u *) p->fullname))
10350 continue;
10351
Bram Moolenaar071d4272004-06-13 20:20:40 +000010352 varp = NULL;
10353 isterm = istermoption(p);
10354 if (opt_flags != 0)
10355 {
10356 if (p->indir != PV_NONE && !isterm)
10357 varp = get_varp_scope(p, opt_flags);
10358 }
10359 else
10360 varp = get_varp(p);
10361 if (varp != NULL
10362 && ((all == 2 && isterm)
10363 || (all == 1 && !isterm)
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010364 || (all == 0 && !optval_default(p, varp, p_cp))))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010365 {
10366 if (p->flags & P_BOOL)
10367 len = 1; /* a toggle option fits always */
10368 else
10369 {
10370 option_value2string(p, opt_flags);
10371 len = (int)STRLEN(p->fullname) + vim_strsize(NameBuff) + 1;
10372 }
10373 if ((len <= INC - GAP && run == 1) ||
10374 (len > INC - GAP && run == 2))
10375 items[item_count++] = p;
10376 }
10377 }
10378
10379 /*
10380 * display the items
10381 */
10382 if (run == 1)
10383 {
10384 cols = (Columns + GAP - 3) / INC;
10385 if (cols == 0)
10386 cols = 1;
10387 rows = (item_count + cols - 1) / cols;
10388 }
10389 else /* run == 2 */
10390 rows = item_count;
10391 for (row = 0; row < rows && !got_int; ++row)
10392 {
10393 msg_putchar('\n'); /* go to next line */
10394 if (got_int) /* 'q' typed in more */
10395 break;
10396 col = 0;
10397 for (i = row; i < item_count; i += rows)
10398 {
10399 msg_col = col; /* make columns */
10400 showoneopt(items[i], opt_flags);
10401 col += INC;
10402 }
10403 out_flush();
10404 ui_breakcheck();
10405 }
10406 }
10407 vim_free(items);
10408}
10409
10410/*
10411 * Return TRUE if option "p" has its default value.
10412 */
10413 static int
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010414optval_default(struct vimoption *p, char_u *varp, int compatible)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010415{
10416 int dvi;
10417
10418 if (varp == NULL)
10419 return TRUE; /* hidden option is always at default */
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010420 dvi = ((p->flags & P_VI_DEF) || compatible) ? VI_DEFAULT : VIM_DEFAULT;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010421 if (p->flags & P_NUM)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010422 return (*(long *)varp == (long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010423 if (p->flags & P_BOOL)
Bram Moolenaareb3593b2006-04-22 22:33:57 +000010424 /* the cast to long is required for Manx C, long_i is
10425 * needed for MSVC */
10426 return (*(int *)varp == (int)(long)(long_i)p->def_val[dvi]);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010427 /* P_STRING */
10428 return (STRCMP(*(char_u **)varp, p->def_val[dvi]) == 0);
10429}
10430
10431/*
10432 * showoneopt: show the value of one option
10433 * must not be called with a hidden option!
10434 */
10435 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010436showoneopt(
10437 struct vimoption *p,
10438 int opt_flags) /* OPT_LOCAL or OPT_GLOBAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010439{
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010440 char_u *varp;
10441 int save_silent = silent_mode;
10442
10443 silent_mode = FALSE;
10444 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010445
10446 varp = get_varp_scope(p, opt_flags);
10447
10448 /* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
10449 if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
10450 ? !curbufIsChanged() : !*(int *)varp))
Bram Moolenaar32526b32019-01-19 17:43:09 +010010451 msg_puts("no");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010452 else if ((p->flags & P_BOOL) && *(int *)varp < 0)
Bram Moolenaar32526b32019-01-19 17:43:09 +010010453 msg_puts("--");
Bram Moolenaar071d4272004-06-13 20:20:40 +000010454 else
Bram Moolenaar32526b32019-01-19 17:43:09 +010010455 msg_puts(" ");
10456 msg_puts(p->fullname);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010457 if (!(p->flags & P_BOOL))
10458 {
10459 msg_putchar('=');
10460 /* put value string in NameBuff */
10461 option_value2string(p, opt_flags);
10462 msg_outtrans(NameBuff);
10463 }
Bram Moolenaar26a60b42005-02-22 08:49:11 +000010464
10465 silent_mode = save_silent;
10466 info_message = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010467}
10468
10469/*
10470 * Write modified options as ":set" commands to a file.
10471 *
10472 * There are three values for "opt_flags":
10473 * OPT_GLOBAL: Write global option values and fresh values of
10474 * buffer-local options (used for start of a session
10475 * file).
10476 * OPT_GLOBAL + OPT_LOCAL: Idem, add fresh values of window-local options for
10477 * curwin (used for a vimrc file).
10478 * OPT_LOCAL: Write buffer-local option values for curbuf, fresh
10479 * and local values for window-local options of
10480 * curwin. Local values are also written when at the
10481 * default value, because a modeline or autocommand
10482 * may have set them when doing ":edit file" and the
10483 * user has set them back at the default or fresh
10484 * value.
10485 * When "local_only" is TRUE, don't write fresh
10486 * values, only local values (for ":mkview").
10487 * (fresh value = value used for a new buffer or window for a local option).
10488 *
10489 * Return FAIL on error, OK otherwise.
10490 */
10491 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010492makeset(FILE *fd, int opt_flags, int local_only)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010493{
10494 struct vimoption *p;
10495 char_u *varp; /* currently used value */
10496 char_u *varp_fresh; /* local value */
10497 char_u *varp_local = NULL; /* fresh value */
10498 char *cmd;
10499 int round;
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010500 int pri;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010501
10502 /*
10503 * The options that don't have a default (terminal name, columns, lines)
10504 * are never written. Terminal options are also not written.
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010505 * Do the loop over "options[]" twice: once for options with the
10506 * P_PRI_MKRC flag and once without.
Bram Moolenaar071d4272004-06-13 20:20:40 +000010507 */
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010508 for (pri = 1; pri >= 0; --pri)
10509 {
10510 for (p = &options[0]; !istermoption(p); p++)
10511 if (!(p->flags & P_NO_MKRC)
10512 && !istermoption(p)
10513 && ((pri == 1) == ((p->flags & P_PRI_MKRC) != 0)))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010514 {
10515 /* skip global option when only doing locals */
10516 if (p->indir == PV_NONE && !(opt_flags & OPT_GLOBAL))
10517 continue;
10518
10519 /* Do not store options like 'bufhidden' and 'syntax' in a vimrc
10520 * file, they are always buffer-specific. */
10521 if ((opt_flags & OPT_GLOBAL) && (p->flags & P_NOGLOB))
10522 continue;
10523
10524 /* Global values are only written when not at the default value. */
10525 varp = get_varp_scope(p, opt_flags);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010526 if ((opt_flags & OPT_GLOBAL) && optval_default(p, varp, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010527 continue;
10528
10529 round = 2;
10530 if (p->indir != PV_NONE)
10531 {
10532 if (p->var == VAR_WIN)
10533 {
10534 /* skip window-local option when only doing globals */
10535 if (!(opt_flags & OPT_LOCAL))
10536 continue;
10537 /* When fresh value of window-local option is not at the
10538 * default, need to write it too. */
10539 if (!(opt_flags & OPT_GLOBAL) && !local_only)
10540 {
10541 varp_fresh = get_varp_scope(p, OPT_GLOBAL);
Bram Moolenaarcacc6a52019-05-30 15:22:43 +020010542 if (!optval_default(p, varp_fresh, p_cp))
Bram Moolenaar071d4272004-06-13 20:20:40 +000010543 {
10544 round = 1;
10545 varp_local = varp;
10546 varp = varp_fresh;
10547 }
10548 }
10549 }
10550 }
10551
10552 /* Round 1: fresh value for window-local options.
10553 * Round 2: other values */
10554 for ( ; round <= 2; varp = varp_local, ++round)
10555 {
10556 if (round == 1 || (opt_flags & OPT_GLOBAL))
10557 cmd = "set";
10558 else
10559 cmd = "setlocal";
10560
10561 if (p->flags & P_BOOL)
10562 {
10563 if (put_setbool(fd, cmd, p->fullname, *(int *)varp) == FAIL)
10564 return FAIL;
10565 }
10566 else if (p->flags & P_NUM)
10567 {
10568 if (put_setnum(fd, cmd, p->fullname, (long *)varp) == FAIL)
10569 return FAIL;
10570 }
10571 else /* P_STRING */
10572 {
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010573 int do_endif = FALSE;
10574
Bram Moolenaar071d4272004-06-13 20:20:40 +000010575 /* Don't set 'syntax' and 'filetype' again if the value is
10576 * already right, avoids reloading the syntax file. */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010577 if (
Bram Moolenaarf2bd8ef2018-03-04 18:08:14 +010010578#if defined(FEAT_SYN_HL)
10579 p->indir == PV_SYN ||
10580#endif
10581 p->indir == PV_FT)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010582 {
10583 if (fprintf(fd, "if &%s != '%s'", p->fullname,
10584 *(char_u **)(varp)) < 0
10585 || put_eol(fd) < 0)
10586 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010587 do_endif = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010588 }
10589 if (put_setstring(fd, cmd, p->fullname, (char_u **)varp,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010590 p->flags) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010591 return FAIL;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000010592 if (do_endif)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010593 {
10594 if (put_line(fd, "endif") == FAIL)
10595 return FAIL;
10596 }
10597 }
10598 }
10599 }
Bram Moolenaar7fd16022007-09-06 14:35:35 +000010600 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010601 return OK;
10602}
10603
10604#if defined(FEAT_FOLDING) || defined(PROTO)
10605/*
10606 * Generate set commands for the local fold options only. Used when
10607 * 'sessionoptions' or 'viewoptions' contains "folds" but not "options".
10608 */
10609 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010610makefoldset(FILE *fd)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010611{
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010612 if (put_setstring(fd, "setlocal", "fdm", &curwin->w_p_fdm, 0) == FAIL
Bram Moolenaar071d4272004-06-13 20:20:40 +000010613# ifdef FEAT_EVAL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010614 || put_setstring(fd, "setlocal", "fde", &curwin->w_p_fde, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010615 == FAIL
10616# endif
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010617 || put_setstring(fd, "setlocal", "fmr", &curwin->w_p_fmr, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010618 == FAIL
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010619 || put_setstring(fd, "setlocal", "fdi", &curwin->w_p_fdi, 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010620 == FAIL
10621 || put_setnum(fd, "setlocal", "fdl", &curwin->w_p_fdl) == FAIL
10622 || put_setnum(fd, "setlocal", "fml", &curwin->w_p_fml) == FAIL
10623 || put_setnum(fd, "setlocal", "fdn", &curwin->w_p_fdn) == FAIL
10624 || put_setbool(fd, "setlocal", "fen", curwin->w_p_fen) == FAIL
10625 )
10626 return FAIL;
10627
10628 return OK;
10629}
10630#endif
10631
10632 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010633put_setstring(
10634 FILE *fd,
10635 char *cmd,
10636 char *name,
10637 char_u **valuep,
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010638 long_u flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010639{
10640 char_u *s;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010641 char_u *buf = NULL;
10642 char_u *part = NULL;
10643 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010644
10645 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10646 return FAIL;
10647 if (*valuep != NULL)
10648 {
10649 /* Output 'pastetoggle' as key names. For other
10650 * options some characters have to be escaped with
10651 * CTRL-V or backslash */
10652 if (valuep == &p_pt)
10653 {
10654 s = *valuep;
10655 while (*s != NUL)
Bram Moolenaar7d96acd2008-06-09 15:07:54 +000010656 if (put_escstr(fd, str2special(&s, FALSE), 2) == FAIL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010657 return FAIL;
10658 }
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010659 // expand the option value, replace $HOME by ~
10660 else if ((flags & P_EXPAND) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010661 {
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010662 int size = (int)STRLEN(*valuep) + 1;
10663
10664 // replace home directory in the whole option value into "buf"
10665 buf = alloc(size);
Bram Moolenaarf8441472011-04-28 17:24:58 +020010666 if (buf == NULL)
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010667 goto fail;
10668 home_replace(NULL, *valuep, buf, size, FALSE);
10669
10670 // If the option value is longer than MAXPATHL, we need to append
10671 // earch comma separated part of the option separately, so that it
10672 // can be expanded when read back.
10673 if (size >= MAXPATHL && (flags & P_COMMA) != 0
10674 && vim_strchr(*valuep, ',') != NULL)
10675 {
10676 part = alloc(size);
10677 if (part == NULL)
10678 goto fail;
10679
10680 // write line break to clear the option, e.g. ':set rtp='
10681 if (put_eol(fd) == FAIL)
10682 goto fail;
10683
10684 p = buf;
10685 while (*p != NUL)
10686 {
10687 // for each comma separated option part, append value to
10688 // the option, :set rtp+=value
10689 if (fprintf(fd, "%s %s+=", cmd, name) < 0)
10690 goto fail;
10691 (void)copy_option_part(&p, part, size, ",");
10692 if (put_escstr(fd, part, 2) == FAIL || put_eol(fd) == FAIL)
10693 goto fail;
10694 }
10695 vim_free(buf);
10696 vim_free(part);
10697 return OK;
10698 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000010699 if (put_escstr(fd, buf, 2) == FAIL)
Bram Moolenaarf8441472011-04-28 17:24:58 +020010700 {
10701 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010702 return FAIL;
Bram Moolenaarf8441472011-04-28 17:24:58 +020010703 }
10704 vim_free(buf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000010705 }
10706 else if (put_escstr(fd, *valuep, 2) == FAIL)
10707 return FAIL;
10708 }
10709 if (put_eol(fd) < 0)
10710 return FAIL;
10711 return OK;
Bram Moolenaared18f2c2019-01-24 20:30:52 +010010712fail:
10713 vim_free(buf);
10714 vim_free(part);
10715 return FAIL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010716}
10717
10718 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010719put_setnum(
10720 FILE *fd,
10721 char *cmd,
10722 char *name,
10723 long *valuep)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010724{
10725 long wc;
10726
10727 if (fprintf(fd, "%s %s=", cmd, name) < 0)
10728 return FAIL;
10729 if (wc_use_keyname((char_u *)valuep, &wc))
10730 {
10731 /* print 'wildchar' and 'wildcharm' as a key name */
10732 if (fputs((char *)get_special_key_name((int)wc, 0), fd) < 0)
10733 return FAIL;
10734 }
10735 else if (fprintf(fd, "%ld", *valuep) < 0)
10736 return FAIL;
10737 if (put_eol(fd) < 0)
10738 return FAIL;
10739 return OK;
10740}
10741
10742 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010743put_setbool(
10744 FILE *fd,
10745 char *cmd,
10746 char *name,
10747 int value)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010748{
Bram Moolenaar893de922007-10-02 18:40:57 +000010749 if (value < 0) /* global/local option using global value */
10750 return OK;
Bram Moolenaar071d4272004-06-13 20:20:40 +000010751 if (fprintf(fd, "%s %s%s", cmd, value ? "" : "no", name) < 0
10752 || put_eol(fd) < 0)
10753 return FAIL;
10754 return OK;
10755}
10756
10757/*
10758 * Clear all the terminal options.
10759 * If the option has been allocated, free the memory.
10760 * Terminal options are never hidden or indirect.
10761 */
10762 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010763clear_termoptions(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010764{
Bram Moolenaar071d4272004-06-13 20:20:40 +000010765 /*
10766 * Reset a few things before clearing the old options. This may cause
10767 * outputting a few things that the terminal doesn't understand, but the
10768 * screen will be cleared later, so this is OK.
10769 */
10770#ifdef FEAT_MOUSE_TTY
10771 mch_setmouse(FALSE); /* switch mouse off */
10772#endif
10773#ifdef FEAT_TITLE
Bram Moolenaar40385db2018-08-07 22:31:44 +020010774 mch_restore_title(SAVE_RESTORE_BOTH); /* restore window titles */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010775#endif
10776#if defined(FEAT_XCLIPBOARD) && defined(FEAT_GUI)
10777 /* When starting the GUI close the display opened for the clipboard.
10778 * After restoring the title, because that will need the display. */
10779 if (gui.starting)
10780 clear_xterm_clip();
10781#endif
Bram Moolenaarcea912a2016-10-12 14:20:24 +020010782 stoptermcap(); /* stop termcap mode */
Bram Moolenaar071d4272004-06-13 20:20:40 +000010783
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010784 free_termoptions();
10785}
10786
10787 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010788free_termoptions(void)
Bram Moolenaarf461c8e2005-06-25 23:04:51 +000010789{
10790 struct vimoption *p;
10791
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010792 for (p = options; p->fullname != NULL; p++)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010793 if (istermoption(p))
10794 {
10795 if (p->flags & P_ALLOCED)
10796 free_string_option(*(char_u **)(p->var));
10797 if (p->flags & P_DEF_ALLOCED)
10798 free_string_option(p->def_val[VI_DEFAULT]);
10799 *(char_u **)(p->var) = empty_option;
10800 p->def_val[VI_DEFAULT] = empty_option;
10801 p->flags &= ~(P_ALLOCED|P_DEF_ALLOCED);
Bram Moolenaar35bc7d62018-10-02 14:45:10 +020010802#ifdef FEAT_EVAL
10803 // remember where the option was cleared
10804 set_option_sctx_idx((int)(p - options), OPT_GLOBAL, current_sctx);
10805#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010806 }
10807 clear_termcodes();
10808}
10809
10810/*
Bram Moolenaar363cb672009-07-22 12:28:17 +000010811 * Free the string for one term option, if it was allocated.
10812 * Set the string to empty_option and clear allocated flag.
10813 * "var" points to the option value.
10814 */
10815 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010816free_one_termoption(char_u *var)
Bram Moolenaar363cb672009-07-22 12:28:17 +000010817{
10818 struct vimoption *p;
10819
10820 for (p = &options[0]; p->fullname != NULL; p++)
10821 if (p->var == var)
10822 {
10823 if (p->flags & P_ALLOCED)
10824 free_string_option(*(char_u **)(p->var));
10825 *(char_u **)(p->var) = empty_option;
10826 p->flags &= ~P_ALLOCED;
10827 break;
10828 }
10829}
10830
10831/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000010832 * Set the terminal option defaults to the current value.
10833 * Used after setting the terminal name.
10834 */
10835 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010836set_term_defaults(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010837{
10838 struct vimoption *p;
10839
10840 for (p = &options[0]; p->fullname != NULL; p++)
10841 {
10842 if (istermoption(p) && p->def_val[VI_DEFAULT] != *(char_u **)(p->var))
10843 {
10844 if (p->flags & P_DEF_ALLOCED)
10845 {
10846 free_string_option(p->def_val[VI_DEFAULT]);
10847 p->flags &= ~P_DEF_ALLOCED;
10848 }
10849 p->def_val[VI_DEFAULT] = *(char_u **)(p->var);
10850 if (p->flags & P_ALLOCED)
10851 {
10852 p->flags |= P_DEF_ALLOCED;
10853 p->flags &= ~P_ALLOCED; /* don't free the value now */
10854 }
10855 }
10856 }
10857}
10858
10859/*
10860 * return TRUE if 'p' starts with 't_'
10861 */
10862 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010010863istermoption(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010864{
10865 return (p->fullname[0] == 't' && p->fullname[1] == '_');
10866}
10867
10868/*
10869 * Compute columns for ruler and shown command. 'sc_col' is also used to
10870 * decide what the maximum length of a message on the status line can be.
10871 * If there is a status line for the last window, 'sc_col' is independent
10872 * of 'ru_col'.
10873 */
10874
10875#define COL_RULER 17 /* columns needed by standard ruler */
10876
10877 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010878comp_col(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010879{
Bram Moolenaar4033c552017-09-16 20:54:51 +020010880#if defined(FEAT_CMDL_INFO)
Bram Moolenaar459ca562016-11-10 18:16:33 +010010881 int last_has_status = (p_ls == 2 || (p_ls == 1 && !ONE_WINDOW));
Bram Moolenaar071d4272004-06-13 20:20:40 +000010882
10883 sc_col = 0;
10884 ru_col = 0;
10885 if (p_ru)
10886 {
Bram Moolenaar4033c552017-09-16 20:54:51 +020010887# ifdef FEAT_STL_OPT
Bram Moolenaar071d4272004-06-13 20:20:40 +000010888 ru_col = (ru_wid ? ru_wid : COL_RULER) + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010889# else
Bram Moolenaar071d4272004-06-13 20:20:40 +000010890 ru_col = COL_RULER + 1;
Bram Moolenaar4033c552017-09-16 20:54:51 +020010891# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000010892 /* no last status line, adjust sc_col */
10893 if (!last_has_status)
10894 sc_col = ru_col;
10895 }
10896 if (p_sc)
10897 {
10898 sc_col += SHOWCMD_COLS;
10899 if (!p_ru || last_has_status) /* no need for separating space */
10900 ++sc_col;
10901 }
10902 sc_col = Columns - sc_col;
10903 ru_col = Columns - ru_col;
10904 if (sc_col <= 0) /* screen too narrow, will become a mess */
10905 sc_col = 1;
10906 if (ru_col <= 0)
10907 ru_col = 1;
10908#else
10909 sc_col = Columns;
10910 ru_col = Columns;
10911#endif
10912}
10913
Bram Moolenaar113e1072019-01-20 15:30:40 +010010914#if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000010915/*
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010916 * Unset local option value, similar to ":set opt<".
10917 */
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010918 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010010919unset_global_local_option(char_u *name, void *from)
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010920{
10921 struct vimoption *p;
10922 int opt_idx;
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010923 buf_T *buf = (buf_T *)from;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010924
10925 opt_idx = findoption(name);
Bram Moolenaarbd8539a2015-08-11 18:53:03 +020010926 if (opt_idx < 0)
10927 return;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010928 p = &(options[opt_idx]);
10929
10930 switch ((int)p->indir)
10931 {
10932 /* global option with local value: use local value if it's been set */
10933 case PV_EP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010934 clear_string_option(&buf->b_p_ep);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010935 break;
10936 case PV_KP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010937 clear_string_option(&buf->b_p_kp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010938 break;
10939 case PV_PATH:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010940 clear_string_option(&buf->b_p_path);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010941 break;
10942 case PV_AR:
10943 buf->b_p_ar = -1;
10944 break;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020010945 case PV_BKC:
10946 clear_string_option(&buf->b_p_bkc);
10947 buf->b_bkc_flags = 0;
10948 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010949 case PV_TAGS:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010950 clear_string_option(&buf->b_p_tags);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010951 break;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010010952 case PV_TC:
10953 clear_string_option(&buf->b_p_tc);
10954 buf->b_tc_flags = 0;
10955 break;
Bram Moolenaar375e3392019-01-31 18:26:10 +010010956 case PV_SISO:
10957 curwin->w_p_siso = -1;
10958 break;
10959 case PV_SO:
10960 curwin->w_p_so = -1;
10961 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010962#ifdef FEAT_FIND_ID
10963 case PV_DEF:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010964 clear_string_option(&buf->b_p_def);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010965 break;
10966 case PV_INC:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010967 clear_string_option(&buf->b_p_inc);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010968 break;
10969#endif
10970#ifdef FEAT_INS_EXPAND
10971 case PV_DICT:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010972 clear_string_option(&buf->b_p_dict);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010973 break;
10974 case PV_TSR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010975 clear_string_option(&buf->b_p_tsr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010976 break;
10977#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010010978 case PV_FP:
10979 clear_string_option(&buf->b_p_fp);
10980 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010981#ifdef FEAT_QUICKFIX
10982 case PV_EFM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010983 clear_string_option(&buf->b_p_efm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010984 break;
10985 case PV_GP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010986 clear_string_option(&buf->b_p_gp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010987 break;
10988 case PV_MP:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010989 clear_string_option(&buf->b_p_mp);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010990 break;
10991#endif
10992#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
10993 case PV_BEXPR:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010994 clear_string_option(&buf->b_p_bexpr);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020010995 break;
10996#endif
10997#if defined(FEAT_CRYPT)
10998 case PV_CM:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020010999 clear_string_option(&buf->b_p_cm);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011000 break;
11001#endif
11002#ifdef FEAT_STL_OPT
11003 case PV_STL:
Bram Moolenaar51ac8a22013-05-06 06:45:47 +020011004 clear_string_option(&((win_T *)from)->w_p_stl);
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011005 break;
11006#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011007 case PV_UL:
11008 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
11009 break;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011010#ifdef FEAT_LISP
11011 case PV_LW:
11012 clear_string_option(&buf->b_p_lw);
11013 break;
11014#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011015 case PV_MENC:
11016 clear_string_option(&buf->b_p_menc);
11017 break;
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011018 }
11019}
Bram Moolenaar113e1072019-01-20 15:30:40 +010011020#endif
Bram Moolenaar84e0f6c2013-05-06 03:52:55 +020011021
11022/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011023 * Get pointer to option variable, depending on local or global scope.
11024 */
11025 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011026get_varp_scope(struct vimoption *p, int opt_flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011027{
11028 if ((opt_flags & OPT_GLOBAL) && p->indir != PV_NONE)
11029 {
11030 if (p->var == VAR_WIN)
11031 return (char_u *)GLOBAL_WO(get_varp(p));
11032 return p->var;
11033 }
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011034 if ((opt_flags & OPT_LOCAL) && ((int)p->indir & PV_BOTH))
Bram Moolenaar071d4272004-06-13 20:20:40 +000011035 {
11036 switch ((int)p->indir)
11037 {
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011038 case PV_FP: return (char_u *)&(curbuf->b_p_fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011039#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011040 case PV_EFM: return (char_u *)&(curbuf->b_p_efm);
11041 case PV_GP: return (char_u *)&(curbuf->b_p_gp);
11042 case PV_MP: return (char_u *)&(curbuf->b_p_mp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011043#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011044 case PV_EP: return (char_u *)&(curbuf->b_p_ep);
11045 case PV_KP: return (char_u *)&(curbuf->b_p_kp);
11046 case PV_PATH: return (char_u *)&(curbuf->b_p_path);
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011047 case PV_AR: return (char_u *)&(curbuf->b_p_ar);
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011048 case PV_TAGS: return (char_u *)&(curbuf->b_p_tags);
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011049 case PV_TC: return (char_u *)&(curbuf->b_p_tc);
Bram Moolenaar375e3392019-01-31 18:26:10 +010011050 case PV_SISO: return (char_u *)&(curwin->w_p_siso);
11051 case PV_SO: return (char_u *)&(curwin->w_p_so);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011052#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011053 case PV_DEF: return (char_u *)&(curbuf->b_p_def);
11054 case PV_INC: return (char_u *)&(curbuf->b_p_inc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011055#endif
11056#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011057 case PV_DICT: return (char_u *)&(curbuf->b_p_dict);
11058 case PV_TSR: return (char_u *)&(curbuf->b_p_tsr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011059#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011060#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11061 case PV_BEXPR: return (char_u *)&(curbuf->b_p_bexpr);
11062#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011063#if defined(FEAT_CRYPT)
11064 case PV_CM: return (char_u *)&(curbuf->b_p_cm);
11065#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011066#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011067 case PV_STL: return (char_u *)&(curwin->w_p_stl);
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011068#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011069 case PV_UL: return (char_u *)&(curbuf->b_p_ul);
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011070#ifdef FEAT_LISP
11071 case PV_LW: return (char_u *)&(curbuf->b_p_lw);
11072#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011073 case PV_BKC: return (char_u *)&(curbuf->b_p_bkc);
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011074 case PV_MENC: return (char_u *)&(curbuf->b_p_menc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011075 }
11076 return NULL; /* "cannot happen" */
11077 }
11078 return get_varp(p);
11079}
11080
11081/*
11082 * Get pointer to option variable.
11083 */
11084 static char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011085get_varp(struct vimoption *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011086{
11087 /* hidden option, always return NULL */
11088 if (p->var == NULL)
11089 return NULL;
11090
11091 switch ((int)p->indir)
11092 {
11093 case PV_NONE: return p->var;
11094
11095 /* global option with local value: use local value if it's been set */
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011096 case PV_EP: return *curbuf->b_p_ep != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011097 ? (char_u *)&curbuf->b_p_ep : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011098 case PV_KP: return *curbuf->b_p_kp != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011099 ? (char_u *)&curbuf->b_p_kp : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011100 case PV_PATH: return *curbuf->b_p_path != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011101 ? (char_u *)&(curbuf->b_p_path) : p->var;
Bram Moolenaara23ccb82006-02-27 00:08:02 +000011102 case PV_AR: return curbuf->b_p_ar >= 0
Bram Moolenaar071d4272004-06-13 20:20:40 +000011103 ? (char_u *)&(curbuf->b_p_ar) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011104 case PV_TAGS: return *curbuf->b_p_tags != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011105 ? (char_u *)&(curbuf->b_p_tags) : p->var;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011106 case PV_TC: return *curbuf->b_p_tc != NUL
11107 ? (char_u *)&(curbuf->b_p_tc) : p->var;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011108 case PV_BKC: return *curbuf->b_p_bkc != NUL
11109 ? (char_u *)&(curbuf->b_p_bkc) : p->var;
Bram Moolenaar375e3392019-01-31 18:26:10 +010011110 case PV_SISO: return curwin->w_p_siso >= 0
11111 ? (char_u *)&(curwin->w_p_siso) : p->var;
11112 case PV_SO: return curwin->w_p_so >= 0
11113 ? (char_u *)&(curwin->w_p_so) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011114#ifdef FEAT_FIND_ID
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011115 case PV_DEF: return *curbuf->b_p_def != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011116 ? (char_u *)&(curbuf->b_p_def) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011117 case PV_INC: return *curbuf->b_p_inc != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011118 ? (char_u *)&(curbuf->b_p_inc) : p->var;
11119#endif
11120#ifdef FEAT_INS_EXPAND
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011121 case PV_DICT: return *curbuf->b_p_dict != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011122 ? (char_u *)&(curbuf->b_p_dict) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011123 case PV_TSR: return *curbuf->b_p_tsr != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011124 ? (char_u *)&(curbuf->b_p_tsr) : p->var;
11125#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011126 case PV_FP: return *curbuf->b_p_fp != NUL
11127 ? (char_u *)&(curbuf->b_p_fp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011128#ifdef FEAT_QUICKFIX
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011129 case PV_EFM: return *curbuf->b_p_efm != NUL
Bram Moolenaar071d4272004-06-13 20:20:40 +000011130 ? (char_u *)&(curbuf->b_p_efm) : p->var;
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011131 case PV_GP: return *curbuf->b_p_gp != NUL
11132 ? (char_u *)&(curbuf->b_p_gp) : p->var;
11133 case PV_MP: return *curbuf->b_p_mp != NUL
11134 ? (char_u *)&(curbuf->b_p_mp) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011135#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011136#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11137 case PV_BEXPR: return *curbuf->b_p_bexpr != NUL
11138 ? (char_u *)&(curbuf->b_p_bexpr) : p->var;
11139#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011140#if defined(FEAT_CRYPT)
11141 case PV_CM: return *curbuf->b_p_cm != NUL
11142 ? (char_u *)&(curbuf->b_p_cm) : p->var;
11143#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011144#ifdef FEAT_STL_OPT
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011145 case PV_STL: return *curwin->w_p_stl != NUL
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011146 ? (char_u *)&(curwin->w_p_stl) : p->var;
11147#endif
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011148 case PV_UL: return curbuf->b_p_ul != NO_LOCAL_UNDOLEVEL
11149 ? (char_u *)&(curbuf->b_p_ul) : p->var;
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011150#ifdef FEAT_LISP
11151 case PV_LW: return *curbuf->b_p_lw != NUL
11152 ? (char_u *)&(curbuf->b_p_lw) : p->var;
11153#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011154 case PV_MENC: return *curbuf->b_p_menc != NUL
11155 ? (char_u *)&(curbuf->b_p_menc) : p->var;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011156
11157#ifdef FEAT_ARABIC
11158 case PV_ARAB: return (char_u *)&(curwin->w_p_arab);
11159#endif
11160 case PV_LIST: return (char_u *)&(curwin->w_p_list);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011161#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011162 case PV_SPELL: return (char_u *)&(curwin->w_p_spell);
11163#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011164#ifdef FEAT_SYN_HL
11165 case PV_CUC: return (char_u *)&(curwin->w_p_cuc);
11166 case PV_CUL: return (char_u *)&(curwin->w_p_cul);
Bram Moolenaar1a384422010-07-14 19:53:30 +020011167 case PV_CC: return (char_u *)&(curwin->w_p_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011168#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011169#ifdef FEAT_DIFF
11170 case PV_DIFF: return (char_u *)&(curwin->w_p_diff);
11171#endif
11172#ifdef FEAT_FOLDING
11173 case PV_FDC: return (char_u *)&(curwin->w_p_fdc);
11174 case PV_FEN: return (char_u *)&(curwin->w_p_fen);
11175 case PV_FDI: return (char_u *)&(curwin->w_p_fdi);
11176 case PV_FDL: return (char_u *)&(curwin->w_p_fdl);
11177 case PV_FDM: return (char_u *)&(curwin->w_p_fdm);
11178 case PV_FML: return (char_u *)&(curwin->w_p_fml);
11179 case PV_FDN: return (char_u *)&(curwin->w_p_fdn);
11180# ifdef FEAT_EVAL
11181 case PV_FDE: return (char_u *)&(curwin->w_p_fde);
11182 case PV_FDT: return (char_u *)&(curwin->w_p_fdt);
11183# endif
11184 case PV_FMR: return (char_u *)&(curwin->w_p_fmr);
11185#endif
11186 case PV_NU: return (char_u *)&(curwin->w_p_nu);
Bram Moolenaar64486672010-05-16 15:46:46 +020011187 case PV_RNU: return (char_u *)&(curwin->w_p_rnu);
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011188#ifdef FEAT_LINEBREAK
11189 case PV_NUW: return (char_u *)&(curwin->w_p_nuw);
11190#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011191 case PV_WFH: return (char_u *)&(curwin->w_p_wfh);
Bram Moolenaar97b2ad32006-03-18 21:40:56 +000011192 case PV_WFW: return (char_u *)&(curwin->w_p_wfw);
Bram Moolenaar4033c552017-09-16 20:54:51 +020011193#if defined(FEAT_QUICKFIX)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011194 case PV_PVW: return (char_u *)&(curwin->w_p_pvw);
11195#endif
11196#ifdef FEAT_RIGHTLEFT
11197 case PV_RL: return (char_u *)&(curwin->w_p_rl);
11198 case PV_RLC: return (char_u *)&(curwin->w_p_rlc);
11199#endif
11200 case PV_SCROLL: return (char_u *)&(curwin->w_p_scr);
11201 case PV_WRAP: return (char_u *)&(curwin->w_p_wrap);
11202#ifdef FEAT_LINEBREAK
11203 case PV_LBR: return (char_u *)&(curwin->w_p_lbr);
Bram Moolenaar597a4222014-06-25 14:39:50 +020011204 case PV_BRI: return (char_u *)&(curwin->w_p_bri);
11205 case PV_BRIOPT: return (char_u *)&(curwin->w_p_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011206#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011207 case PV_WCR: return (char_u *)&(curwin->w_p_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011208 case PV_SCBIND: return (char_u *)&(curwin->w_p_scb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011209 case PV_CRBIND: return (char_u *)&(curwin->w_p_crb);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011210#ifdef FEAT_CONCEAL
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011211 case PV_COCU: return (char_u *)&(curwin->w_p_cocu);
11212 case PV_COLE: return (char_u *)&(curwin->w_p_cole);
11213#endif
11214#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011215 case PV_TWK: return (char_u *)&(curwin->w_p_twk);
11216 case PV_TWS: return (char_u *)&(curwin->w_p_tws);
11217 case PV_TWSL: return (char_u *)&(curbuf->b_p_twsl);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011218#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011219
11220 case PV_AI: return (char_u *)&(curbuf->b_p_ai);
11221 case PV_BIN: return (char_u *)&(curbuf->b_p_bin);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011222 case PV_BOMB: return (char_u *)&(curbuf->b_p_bomb);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011223 case PV_BH: return (char_u *)&(curbuf->b_p_bh);
11224 case PV_BT: return (char_u *)&(curbuf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011225 case PV_BL: return (char_u *)&(curbuf->b_p_bl);
11226 case PV_CI: return (char_u *)&(curbuf->b_p_ci);
11227#ifdef FEAT_CINDENT
11228 case PV_CIN: return (char_u *)&(curbuf->b_p_cin);
11229 case PV_CINK: return (char_u *)&(curbuf->b_p_cink);
11230 case PV_CINO: return (char_u *)&(curbuf->b_p_cino);
11231#endif
11232#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11233 case PV_CINW: return (char_u *)&(curbuf->b_p_cinw);
11234#endif
11235#ifdef FEAT_COMMENTS
11236 case PV_COM: return (char_u *)&(curbuf->b_p_com);
11237#endif
11238#ifdef FEAT_FOLDING
11239 case PV_CMS: return (char_u *)&(curbuf->b_p_cms);
11240#endif
11241#ifdef FEAT_INS_EXPAND
11242 case PV_CPT: return (char_u *)&(curbuf->b_p_cpt);
11243#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011244#ifdef FEAT_COMPL_FUNC
11245 case PV_CFU: return (char_u *)&(curbuf->b_p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011246 case PV_OFU: return (char_u *)&(curbuf->b_p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011247#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011248#ifdef FEAT_EVAL
11249 case PV_TFU: return (char_u *)&(curbuf->b_p_tfu);
11250#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011251 case PV_EOL: return (char_u *)&(curbuf->b_p_eol);
Bram Moolenaar34d72d42015-07-17 14:18:08 +020011252 case PV_FIXEOL: return (char_u *)&(curbuf->b_p_fixeol);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011253 case PV_ET: return (char_u *)&(curbuf->b_p_et);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011254 case PV_FENC: return (char_u *)&(curbuf->b_p_fenc);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011255 case PV_FF: return (char_u *)&(curbuf->b_p_ff);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011256 case PV_FT: return (char_u *)&(curbuf->b_p_ft);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011257 case PV_FO: return (char_u *)&(curbuf->b_p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011258 case PV_FLP: return (char_u *)&(curbuf->b_p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011259 case PV_IMI: return (char_u *)&(curbuf->b_p_iminsert);
11260 case PV_IMS: return (char_u *)&(curbuf->b_p_imsearch);
11261 case PV_INF: return (char_u *)&(curbuf->b_p_inf);
11262 case PV_ISK: return (char_u *)&(curbuf->b_p_isk);
11263#ifdef FEAT_FIND_ID
11264# ifdef FEAT_EVAL
11265 case PV_INEX: return (char_u *)&(curbuf->b_p_inex);
11266# endif
11267#endif
11268#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11269 case PV_INDE: return (char_u *)&(curbuf->b_p_inde);
11270 case PV_INDK: return (char_u *)&(curbuf->b_p_indk);
11271#endif
Bram Moolenaar5e3cb7e2006-02-27 23:58:35 +000011272#ifdef FEAT_EVAL
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011273 case PV_FEX: return (char_u *)&(curbuf->b_p_fex);
11274#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011275#ifdef FEAT_CRYPT
11276 case PV_KEY: return (char_u *)&(curbuf->b_p_key);
11277#endif
11278#ifdef FEAT_LISP
11279 case PV_LISP: return (char_u *)&(curbuf->b_p_lisp);
11280#endif
11281 case PV_ML: return (char_u *)&(curbuf->b_p_ml);
11282 case PV_MPS: return (char_u *)&(curbuf->b_p_mps);
11283 case PV_MA: return (char_u *)&(curbuf->b_p_ma);
11284 case PV_MOD: return (char_u *)&(curbuf->b_changed);
11285 case PV_NF: return (char_u *)&(curbuf->b_p_nf);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011286 case PV_PI: return (char_u *)&(curbuf->b_p_pi);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011287#ifdef FEAT_TEXTOBJ
11288 case PV_QE: return (char_u *)&(curbuf->b_p_qe);
11289#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011290 case PV_RO: return (char_u *)&(curbuf->b_p_ro);
11291#ifdef FEAT_SMARTINDENT
11292 case PV_SI: return (char_u *)&(curbuf->b_p_si);
11293#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011294 case PV_SN: return (char_u *)&(curbuf->b_p_sn);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011295 case PV_STS: return (char_u *)&(curbuf->b_p_sts);
11296#ifdef FEAT_SEARCHPATH
11297 case PV_SUA: return (char_u *)&(curbuf->b_p_sua);
11298#endif
11299 case PV_SWF: return (char_u *)&(curbuf->b_p_swf);
11300#ifdef FEAT_SYN_HL
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011301 case PV_SMC: return (char_u *)&(curbuf->b_p_smc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011302 case PV_SYN: return (char_u *)&(curbuf->b_p_syn);
11303#endif
11304#ifdef FEAT_SPELL
Bram Moolenaar860cae12010-06-05 23:22:07 +020011305 case PV_SPC: return (char_u *)&(curwin->w_s->b_p_spc);
11306 case PV_SPF: return (char_u *)&(curwin->w_s->b_p_spf);
11307 case PV_SPL: return (char_u *)&(curwin->w_s->b_p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011308#endif
11309 case PV_SW: return (char_u *)&(curbuf->b_p_sw);
11310 case PV_TS: return (char_u *)&(curbuf->b_p_ts);
11311 case PV_TW: return (char_u *)&(curbuf->b_p_tw);
11312 case PV_TX: return (char_u *)&(curbuf->b_p_tx);
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011313#ifdef FEAT_PERSISTENT_UNDO
11314 case PV_UDF: return (char_u *)&(curbuf->b_p_udf);
11315#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011316 case PV_WM: return (char_u *)&(curbuf->b_p_wm);
11317#ifdef FEAT_KEYMAP
11318 case PV_KMAP: return (char_u *)&(curbuf->b_p_keymap);
11319#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011320#ifdef FEAT_SIGNS
11321 case PV_SCL: return (char_u *)&(curwin->w_p_scl);
11322#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011323#ifdef FEAT_VARTABS
11324 case PV_VSTS: return (char_u *)&(curbuf->b_p_vsts);
11325 case PV_VTS: return (char_u *)&(curbuf->b_p_vts);
11326#endif
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010011327 default: iemsg(_("E356: get_varp ERROR"));
Bram Moolenaar071d4272004-06-13 20:20:40 +000011328 }
11329 /* always return a valid pointer to avoid a crash! */
11330 return (char_u *)&(curbuf->b_p_wm);
11331}
11332
11333/*
11334 * Get the value of 'equalprg', either the buffer-local one or the global one.
11335 */
11336 char_u *
Bram Moolenaar9b578142016-01-30 19:39:49 +010011337get_equalprg(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011338{
11339 if (*curbuf->b_p_ep == NUL)
11340 return p_ep;
11341 return curbuf->b_p_ep;
11342}
11343
Bram Moolenaar071d4272004-06-13 20:20:40 +000011344/*
11345 * Copy options from one window to another.
11346 * Used when splitting a window.
11347 */
11348 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011349win_copy_options(win_T *wp_from, win_T *wp_to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011350{
11351 copy_winopt(&wp_from->w_onebuf_opt, &wp_to->w_onebuf_opt);
11352 copy_winopt(&wp_from->w_allbuf_opt, &wp_to->w_allbuf_opt);
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020011353#if defined(FEAT_LINEBREAK)
11354 briopt_check(wp_to);
11355#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011356}
Bram Moolenaar071d4272004-06-13 20:20:40 +000011357
11358/*
11359 * Copy the options from one winopt_T to another.
11360 * Doesn't free the old option values in "to", use clear_winopt() for that.
11361 * The 'scroll' option is not copied, because it depends on the window height.
11362 * The 'previewwindow' option is reset, there can be only one preview window.
11363 */
11364 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011365copy_winopt(winopt_T *from, winopt_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011366{
11367#ifdef FEAT_ARABIC
11368 to->wo_arab = from->wo_arab;
11369#endif
11370 to->wo_list = from->wo_list;
11371 to->wo_nu = from->wo_nu;
Bram Moolenaar64486672010-05-16 15:46:46 +020011372 to->wo_rnu = from->wo_rnu;
Bram Moolenaar592e0a22004-07-03 16:05:59 +000011373#ifdef FEAT_LINEBREAK
11374 to->wo_nuw = from->wo_nuw;
11375#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011376#ifdef FEAT_RIGHTLEFT
11377 to->wo_rl = from->wo_rl;
11378 to->wo_rlc = vim_strsave(from->wo_rlc);
11379#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011380#ifdef FEAT_STL_OPT
11381 to->wo_stl = vim_strsave(from->wo_stl);
11382#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011383 to->wo_wrap = from->wo_wrap;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011384#ifdef FEAT_DIFF
11385 to->wo_wrap_save = from->wo_wrap_save;
11386#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011387#ifdef FEAT_LINEBREAK
11388 to->wo_lbr = from->wo_lbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020011389 to->wo_bri = from->wo_bri;
11390 to->wo_briopt = vim_strsave(from->wo_briopt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011391#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011392 to->wo_wcr = vim_strsave(from->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011393 to->wo_scb = from->wo_scb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011394 to->wo_scb_save = from->wo_scb_save;
Bram Moolenaar4161dcc2010-12-02 15:33:21 +010011395 to->wo_crb = from->wo_crb;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011396 to->wo_crb_save = from->wo_crb_save;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011397#ifdef FEAT_SPELL
Bram Moolenaar217ad922005-03-20 22:37:15 +000011398 to->wo_spell = from->wo_spell;
11399#endif
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011400#ifdef FEAT_SYN_HL
11401 to->wo_cuc = from->wo_cuc;
11402 to->wo_cul = from->wo_cul;
Bram Moolenaar1a384422010-07-14 19:53:30 +020011403 to->wo_cc = vim_strsave(from->wo_cc);
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011404#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011405#ifdef FEAT_DIFF
11406 to->wo_diff = from->wo_diff;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011407 to->wo_diff_saved = from->wo_diff_saved;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011408#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011409#ifdef FEAT_CONCEAL
11410 to->wo_cocu = vim_strsave(from->wo_cocu);
Bram Moolenaard497a302010-07-23 22:27:03 +020011411 to->wo_cole = from->wo_cole;
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011412#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011413#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011414 to->wo_twk = vim_strsave(from->wo_twk);
11415 to->wo_tws = vim_strsave(from->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011416#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011417#ifdef FEAT_FOLDING
11418 to->wo_fdc = from->wo_fdc;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011419 to->wo_fdc_save = from->wo_fdc_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011420 to->wo_fen = from->wo_fen;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011421 to->wo_fen_save = from->wo_fen_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011422 to->wo_fdi = vim_strsave(from->wo_fdi);
11423 to->wo_fml = from->wo_fml;
11424 to->wo_fdl = from->wo_fdl;
Bram Moolenaara87aa802013-07-03 15:47:03 +020011425 to->wo_fdl_save = from->wo_fdl_save;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011426 to->wo_fdm = vim_strsave(from->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011427 to->wo_fdm_save = from->wo_diff_saved
11428 ? vim_strsave(from->wo_fdm_save) : empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011429 to->wo_fdn = from->wo_fdn;
11430# ifdef FEAT_EVAL
11431 to->wo_fde = vim_strsave(from->wo_fde);
11432 to->wo_fdt = vim_strsave(from->wo_fdt);
11433# endif
11434 to->wo_fmr = vim_strsave(from->wo_fmr);
11435#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011436#ifdef FEAT_SIGNS
11437 to->wo_scl = vim_strsave(from->wo_scl);
11438#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011439 check_winopt(to); /* don't want NULL pointers */
11440}
11441
11442/*
11443 * Check string options in a window for a NULL value.
11444 */
11445 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011446check_win_options(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011447{
11448 check_winopt(&win->w_onebuf_opt);
11449 check_winopt(&win->w_allbuf_opt);
11450}
11451
11452/*
11453 * Check for NULL pointers in a winopt_T and replace them with empty_option.
11454 */
Bram Moolenaar8dc907d2014-06-25 14:44:10 +020011455 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011456check_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011457{
11458#ifdef FEAT_FOLDING
11459 check_string_option(&wop->wo_fdi);
11460 check_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011461 check_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011462# ifdef FEAT_EVAL
11463 check_string_option(&wop->wo_fde);
11464 check_string_option(&wop->wo_fdt);
11465# endif
11466 check_string_option(&wop->wo_fmr);
11467#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011468#ifdef FEAT_SIGNS
11469 check_string_option(&wop->wo_scl);
11470#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011471#ifdef FEAT_RIGHTLEFT
11472 check_string_option(&wop->wo_rlc);
11473#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011474#ifdef FEAT_STL_OPT
11475 check_string_option(&wop->wo_stl);
11476#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011477#ifdef FEAT_SYN_HL
11478 check_string_option(&wop->wo_cc);
11479#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011480#ifdef FEAT_CONCEAL
11481 check_string_option(&wop->wo_cocu);
11482#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011483#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011484 check_string_option(&wop->wo_twk);
11485 check_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011486#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011487#ifdef FEAT_LINEBREAK
11488 check_string_option(&wop->wo_briopt);
11489#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011490 check_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011491}
11492
11493/*
11494 * Free the allocated memory inside a winopt_T.
11495 */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011496 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011497clear_winopt(winopt_T *wop UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011498{
11499#ifdef FEAT_FOLDING
11500 clear_string_option(&wop->wo_fdi);
11501 clear_string_option(&wop->wo_fdm);
Bram Moolenaara87aa802013-07-03 15:47:03 +020011502 clear_string_option(&wop->wo_fdm_save);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011503# ifdef FEAT_EVAL
11504 clear_string_option(&wop->wo_fde);
11505 clear_string_option(&wop->wo_fdt);
11506# endif
11507 clear_string_option(&wop->wo_fmr);
11508#endif
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020011509#ifdef FEAT_SIGNS
11510 clear_string_option(&wop->wo_scl);
11511#endif
Bram Moolenaar597a4222014-06-25 14:39:50 +020011512#ifdef FEAT_LINEBREAK
11513 clear_string_option(&wop->wo_briopt);
11514#endif
Bram Moolenaar4d784b22019-05-25 19:51:39 +020011515 clear_string_option(&wop->wo_wcr);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011516#ifdef FEAT_RIGHTLEFT
11517 clear_string_option(&wop->wo_rlc);
11518#endif
Bram Moolenaarb5bf5b82004-12-24 14:35:23 +000011519#ifdef FEAT_STL_OPT
11520 clear_string_option(&wop->wo_stl);
11521#endif
Bram Moolenaar1a384422010-07-14 19:53:30 +020011522#ifdef FEAT_SYN_HL
11523 clear_string_option(&wop->wo_cc);
11524#endif
Bram Moolenaarf5963f72010-07-23 22:10:27 +020011525#ifdef FEAT_CONCEAL
11526 clear_string_option(&wop->wo_cocu);
11527#endif
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011528#ifdef FEAT_TERMINAL
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011529 clear_string_option(&wop->wo_twk);
11530 clear_string_option(&wop->wo_tws);
Bram Moolenaare4f25e42017-07-07 11:54:15 +020011531#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011532}
11533
11534/*
11535 * Copy global option values to local options for one buffer.
11536 * Used when creating a new buffer and sometimes when entering a buffer.
11537 * flags:
11538 * BCO_ENTER We will enter the buf buffer.
11539 * BCO_ALWAYS Always copy the options, but only set b_p_initialized when
11540 * appropriate.
11541 * BCO_NOHELP Don't copy the values to a help buffer.
11542 */
11543 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011544buf_copy_options(buf_T *buf, int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011545{
11546 int should_copy = TRUE;
11547 char_u *save_p_isk = NULL; /* init for GCC */
11548 int dont_do_help;
11549 int did_isk = FALSE;
11550
11551 /*
Bram Moolenaar071d4272004-06-13 20:20:40 +000011552 * Skip this when the option defaults have not been set yet. Happens when
11553 * main() allocates the first buffer.
11554 */
11555 if (p_cpo != NULL)
11556 {
11557 /*
11558 * Always copy when entering and 'cpo' contains 'S'.
11559 * Don't copy when already initialized.
11560 * Don't copy when 'cpo' contains 's' and not entering.
11561 * 'S' BCO_ENTER initialized 's' should_copy
11562 * yes yes X X TRUE
11563 * yes no yes X FALSE
11564 * no X yes X FALSE
11565 * X no no yes FALSE
11566 * X no no no TRUE
11567 * no yes no X TRUE
11568 */
11569 if ((vim_strchr(p_cpo, CPO_BUFOPTGLOB) == NULL || !(flags & BCO_ENTER))
11570 && (buf->b_p_initialized
11571 || (!(flags & BCO_ENTER)
11572 && vim_strchr(p_cpo, CPO_BUFOPT) != NULL)))
11573 should_copy = FALSE;
11574
11575 if (should_copy || (flags & BCO_ALWAYS))
11576 {
11577 /* Don't copy the options specific to a help buffer when
11578 * BCO_NOHELP is given or the options were initialized already
11579 * (jumping back to a help file with CTRL-T or CTRL-O) */
11580 dont_do_help = ((flags & BCO_NOHELP) && buf->b_help)
11581 || buf->b_p_initialized;
11582 if (dont_do_help) /* don't free b_p_isk */
11583 {
11584 save_p_isk = buf->b_p_isk;
11585 buf->b_p_isk = NULL;
11586 }
11587 /*
Bram Moolenaar40385db2018-08-07 22:31:44 +020011588 * Always free the allocated strings. If not already initialized,
11589 * reset 'readonly' and copy 'fileformat'.
Bram Moolenaar071d4272004-06-13 20:20:40 +000011590 */
11591 if (!buf->b_p_initialized)
11592 {
11593 free_buf_options(buf, TRUE);
11594 buf->b_p_ro = FALSE; /* don't copy readonly */
11595 buf->b_p_tx = p_tx;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011596 buf->b_p_fenc = vim_strsave(p_fenc);
Bram Moolenaare8ef3a02016-10-12 17:45:29 +020011597 switch (*p_ffs)
11598 {
11599 case 'm':
11600 buf->b_p_ff = vim_strsave((char_u *)FF_MAC); break;
11601 case 'd':
11602 buf->b_p_ff = vim_strsave((char_u *)FF_DOS); break;
11603 case 'u':
11604 buf->b_p_ff = vim_strsave((char_u *)FF_UNIX); break;
11605 default:
11606 buf->b_p_ff = vim_strsave(p_ff);
11607 }
11608 if (buf->b_p_ff != NULL)
11609 buf->b_start_ffc = *buf->b_p_ff;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011610 buf->b_p_bh = empty_option;
11611 buf->b_p_bt = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011612 }
11613 else
11614 free_buf_options(buf, FALSE);
11615
11616 buf->b_p_ai = p_ai;
11617 buf->b_p_ai_nopaste = p_ai_nopaste;
11618 buf->b_p_sw = p_sw;
11619 buf->b_p_tw = p_tw;
11620 buf->b_p_tw_nopaste = p_tw_nopaste;
11621 buf->b_p_tw_nobin = p_tw_nobin;
11622 buf->b_p_wm = p_wm;
11623 buf->b_p_wm_nopaste = p_wm_nopaste;
11624 buf->b_p_wm_nobin = p_wm_nobin;
11625 buf->b_p_bin = p_bin;
Bram Moolenaare8bb2552005-07-08 22:26:47 +000011626 buf->b_p_bomb = p_bomb;
Bram Moolenaarb388be02015-07-22 22:19:38 +020011627 buf->b_p_fixeol = p_fixeol;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011628 buf->b_p_et = p_et;
11629 buf->b_p_et_nobin = p_et_nobin;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020011630 buf->b_p_et_nopaste = p_et_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011631 buf->b_p_ml = p_ml;
11632 buf->b_p_ml_nobin = p_ml_nobin;
11633 buf->b_p_inf = p_inf;
Bram Moolenaar3bab9392017-04-07 15:42:25 +020011634 buf->b_p_swf = cmdmod.noswapfile ? FALSE : p_swf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011635#ifdef FEAT_INS_EXPAND
11636 buf->b_p_cpt = vim_strsave(p_cpt);
11637#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011638#ifdef FEAT_COMPL_FUNC
11639 buf->b_p_cfu = vim_strsave(p_cfu);
Bram Moolenaare344bea2005-09-01 20:46:49 +000011640 buf->b_p_ofu = vim_strsave(p_ofu);
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011641#endif
Bram Moolenaar45e18cb2019-04-28 18:05:35 +020011642#ifdef FEAT_EVAL
11643 buf->b_p_tfu = vim_strsave(p_tfu);
11644#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011645 buf->b_p_sts = p_sts;
11646 buf->b_p_sts_nopaste = p_sts_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011647#ifdef FEAT_VARTABS
11648 buf->b_p_vsts = vim_strsave(p_vsts);
11649 if (p_vsts && p_vsts != empty_option)
11650 tabstop_set(p_vsts, &buf->b_p_vsts_array);
11651 else
11652 buf->b_p_vsts_array = 0;
11653 buf->b_p_vsts_nopaste = p_vsts_nopaste
11654 ? vim_strsave(p_vsts_nopaste) : NULL;
11655#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011656 buf->b_p_sn = p_sn;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011657#ifdef FEAT_COMMENTS
11658 buf->b_p_com = vim_strsave(p_com);
11659#endif
11660#ifdef FEAT_FOLDING
11661 buf->b_p_cms = vim_strsave(p_cms);
11662#endif
11663 buf->b_p_fo = vim_strsave(p_fo);
Bram Moolenaar86b68352004-12-27 21:59:20 +000011664 buf->b_p_flp = vim_strsave(p_flp);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011665 buf->b_p_nf = vim_strsave(p_nf);
11666 buf->b_p_mps = vim_strsave(p_mps);
11667#ifdef FEAT_SMARTINDENT
11668 buf->b_p_si = p_si;
11669#endif
11670 buf->b_p_ci = p_ci;
11671#ifdef FEAT_CINDENT
11672 buf->b_p_cin = p_cin;
11673 buf->b_p_cink = vim_strsave(p_cink);
11674 buf->b_p_cino = vim_strsave(p_cino);
11675#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011676 /* Don't copy 'filetype', it must be detected */
11677 buf->b_p_ft = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011678 buf->b_p_pi = p_pi;
11679#if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
11680 buf->b_p_cinw = vim_strsave(p_cinw);
11681#endif
11682#ifdef FEAT_LISP
11683 buf->b_p_lisp = p_lisp;
11684#endif
11685#ifdef FEAT_SYN_HL
11686 /* Don't copy 'syntax', it must be set */
11687 buf->b_p_syn = empty_option;
Bram Moolenaar3b56eb32005-07-11 22:40:32 +000011688 buf->b_p_smc = p_smc;
Bram Moolenaarb8060fe2016-01-19 22:29:28 +010011689 buf->b_s.b_syn_isk = empty_option;
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000011690#endif
11691#ifdef FEAT_SPELL
Bram Moolenaard5784f92010-10-13 14:05:35 +020011692 buf->b_s.b_p_spc = vim_strsave(p_spc);
Bram Moolenaar860cae12010-06-05 23:22:07 +020011693 (void)compile_cap_prog(&buf->b_s);
11694 buf->b_s.b_p_spf = vim_strsave(p_spf);
11695 buf->b_s.b_p_spl = vim_strsave(p_spl);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011696#endif
11697#if defined(FEAT_CINDENT) && defined(FEAT_EVAL)
11698 buf->b_p_inde = vim_strsave(p_inde);
11699 buf->b_p_indk = vim_strsave(p_indk);
11700#endif
Bram Moolenaar9be7c042017-01-14 14:28:30 +010011701 buf->b_p_fp = empty_option;
Bram Moolenaar1d2ba7f2006-02-14 22:29:30 +000011702#if defined(FEAT_EVAL)
11703 buf->b_p_fex = vim_strsave(p_fex);
11704#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011705#ifdef FEAT_CRYPT
11706 buf->b_p_key = vim_strsave(p_key);
11707#endif
11708#ifdef FEAT_SEARCHPATH
11709 buf->b_p_sua = vim_strsave(p_sua);
11710#endif
11711#ifdef FEAT_KEYMAP
11712 buf->b_p_keymap = vim_strsave(p_keymap);
11713 buf->b_kmap_state |= KEYMAP_INIT;
11714#endif
Bram Moolenaar6d150f72018-04-21 20:03:20 +020011715#ifdef FEAT_TERMINAL
11716 buf->b_p_twsl = p_twsl;
11717#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011718 /* This isn't really an option, but copying the langmap and IME
11719 * state from the current buffer is better than resetting it. */
11720 buf->b_p_iminsert = p_iminsert;
11721 buf->b_p_imsearch = p_imsearch;
11722
11723 /* options that are normally global but also have a local value
11724 * are not copied, start using the global value */
11725 buf->b_p_ar = -1;
Bram Moolenaarf5a2fd82013-11-06 05:26:15 +010011726 buf->b_p_ul = NO_LOCAL_UNDOLEVEL;
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020011727 buf->b_p_bkc = empty_option;
11728 buf->b_bkc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011729#ifdef FEAT_QUICKFIX
11730 buf->b_p_gp = empty_option;
11731 buf->b_p_mp = empty_option;
11732 buf->b_p_efm = empty_option;
11733#endif
11734 buf->b_p_ep = empty_option;
11735 buf->b_p_kp = empty_option;
11736 buf->b_p_path = empty_option;
11737 buf->b_p_tags = empty_option;
Bram Moolenaar0f6562e2015-11-24 18:48:14 +010011738 buf->b_p_tc = empty_option;
11739 buf->b_tc_flags = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011740#ifdef FEAT_FIND_ID
11741 buf->b_p_def = empty_option;
11742 buf->b_p_inc = empty_option;
11743# ifdef FEAT_EVAL
11744 buf->b_p_inex = vim_strsave(p_inex);
11745# endif
11746#endif
11747#ifdef FEAT_INS_EXPAND
11748 buf->b_p_dict = empty_option;
11749 buf->b_p_tsr = empty_option;
11750#endif
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +000011751#ifdef FEAT_TEXTOBJ
11752 buf->b_p_qe = vim_strsave(p_qe);
11753#endif
Bram Moolenaar9b2200a2006-03-20 21:55:45 +000011754#if defined(FEAT_BEVAL) && defined(FEAT_EVAL)
11755 buf->b_p_bexpr = empty_option;
11756#endif
Bram Moolenaar49771f42010-07-20 17:32:38 +020011757#if defined(FEAT_CRYPT)
11758 buf->b_p_cm = empty_option;
11759#endif
Bram Moolenaar55debbe2010-05-23 23:34:36 +020011760#ifdef FEAT_PERSISTENT_UNDO
11761 buf->b_p_udf = p_udf;
11762#endif
Bram Moolenaaraf6c1312014-03-12 18:55:58 +010011763#ifdef FEAT_LISP
11764 buf->b_p_lw = empty_option;
11765#endif
Bram Moolenaar2c7292d2017-03-05 17:43:31 +010011766 buf->b_p_menc = empty_option;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011767
11768 /*
11769 * Don't copy the options set by ex_help(), use the saved values,
11770 * when going from a help buffer to a non-help buffer.
11771 * Don't touch these at all when BCO_NOHELP is used and going from
11772 * or to a help buffer.
11773 */
11774 if (dont_do_help)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011775 {
Bram Moolenaar071d4272004-06-13 20:20:40 +000011776 buf->b_p_isk = save_p_isk;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011777#ifdef FEAT_VARTABS
11778 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11779 tabstop_set(p_vts, &buf->b_p_vts_array);
11780 else
11781 buf->b_p_vts_array = NULL;
11782#endif
11783 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000011784 else
11785 {
11786 buf->b_p_isk = vim_strsave(p_isk);
11787 did_isk = TRUE;
11788 buf->b_p_ts = p_ts;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020011789#ifdef FEAT_VARTABS
11790 buf->b_p_vts = vim_strsave(p_vts);
11791 if (p_vts && p_vts != empty_option && !buf->b_p_vts_array)
11792 tabstop_set(p_vts, &buf->b_p_vts_array);
11793 else
11794 buf->b_p_vts_array = NULL;
11795#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000011796 buf->b_help = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011797 if (buf->b_p_bt[0] == 'h')
11798 clear_string_option(&buf->b_p_bt);
Bram Moolenaar071d4272004-06-13 20:20:40 +000011799 buf->b_p_ma = p_ma;
11800 }
11801 }
11802
11803 /*
11804 * When the options should be copied (ignoring BCO_ALWAYS), set the
11805 * flag that indicates that the options have been initialized.
11806 */
11807 if (should_copy)
11808 buf->b_p_initialized = TRUE;
11809 }
11810
11811 check_buf_options(buf); /* make sure we don't have NULLs */
11812 if (did_isk)
11813 (void)buf_init_chartab(buf, FALSE);
11814}
11815
11816/*
11817 * Reset the 'modifiable' option and its default value.
11818 */
11819 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011820reset_modifiable(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011821{
11822 int opt_idx;
11823
11824 curbuf->b_p_ma = FALSE;
11825 p_ma = FALSE;
11826 opt_idx = findoption((char_u *)"ma");
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000011827 if (opt_idx >= 0)
11828 options[opt_idx].def_val[VI_DEFAULT] = FALSE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000011829}
11830
11831/*
11832 * Set the global value for 'iminsert' to the local value.
11833 */
11834 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011835set_iminsert_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011836{
11837 p_iminsert = curbuf->b_p_iminsert;
11838}
11839
11840/*
11841 * Set the global value for 'imsearch' to the local value.
11842 */
11843 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011844set_imsearch_global(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011845{
11846 p_imsearch = curbuf->b_p_imsearch;
11847}
11848
11849#if defined(FEAT_CMDL_COMPL) || defined(PROTO)
11850static int expand_option_idx = -1;
11851static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
11852static int expand_option_flags = 0;
11853
11854 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010011855set_context_in_set_cmd(
11856 expand_T *xp,
11857 char_u *arg,
11858 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000011859{
11860 int nextchar;
11861 long_u flags = 0; /* init for GCC */
11862 int opt_idx = 0; /* init for GCC */
11863 char_u *p;
11864 char_u *s;
11865 int is_term_option = FALSE;
11866 int key;
11867
11868 expand_option_flags = opt_flags;
11869
11870 xp->xp_context = EXPAND_SETTINGS;
11871 if (*arg == NUL)
11872 {
11873 xp->xp_pattern = arg;
11874 return;
11875 }
11876 p = arg + STRLEN(arg) - 1;
11877 if (*p == ' ' && *(p - 1) != '\\')
11878 {
11879 xp->xp_pattern = p + 1;
11880 return;
11881 }
11882 while (p > arg)
11883 {
11884 s = p;
11885 /* count number of backslashes before ' ' or ',' */
11886 if (*p == ' ' || *p == ',')
11887 {
11888 while (s > arg && *(s - 1) == '\\')
11889 --s;
11890 }
11891 /* break at a space with an even number of backslashes */
11892 if (*p == ' ' && ((p - s) & 1) == 0)
11893 {
11894 ++p;
11895 break;
11896 }
11897 --p;
11898 }
Bram Moolenaar2a7b9ee2009-06-16 15:50:33 +000011899 if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +000011900 {
11901 xp->xp_context = EXPAND_BOOL_SETTINGS;
11902 p += 2;
11903 }
11904 if (STRNCMP(p, "inv", 3) == 0)
11905 {
11906 xp->xp_context = EXPAND_BOOL_SETTINGS;
11907 p += 3;
11908 }
11909 xp->xp_pattern = arg = p;
11910 if (*arg == '<')
11911 {
11912 while (*p != '>')
11913 if (*p++ == NUL) /* expand terminal option name */
11914 return;
11915 key = get_special_key_code(arg + 1);
11916 if (key == 0) /* unknown name */
11917 {
11918 xp->xp_context = EXPAND_NOTHING;
11919 return;
11920 }
11921 nextchar = *++p;
11922 is_term_option = TRUE;
11923 expand_option_name[2] = KEY2TERMCAP0(key);
11924 expand_option_name[3] = KEY2TERMCAP1(key);
11925 }
11926 else
11927 {
11928 if (p[0] == 't' && p[1] == '_')
11929 {
11930 p += 2;
11931 if (*p != NUL)
11932 ++p;
11933 if (*p == NUL)
11934 return; /* expand option name */
11935 nextchar = *++p;
11936 is_term_option = TRUE;
11937 expand_option_name[2] = p[-2];
11938 expand_option_name[3] = p[-1];
11939 }
11940 else
11941 {
11942 /* Allow * wildcard */
11943 while (ASCII_ISALNUM(*p) || *p == '_' || *p == '*')
11944 p++;
11945 if (*p == NUL)
11946 return;
11947 nextchar = *p;
11948 *p = NUL;
11949 opt_idx = findoption(arg);
11950 *p = nextchar;
11951 if (opt_idx == -1 || options[opt_idx].var == NULL)
11952 {
11953 xp->xp_context = EXPAND_NOTHING;
11954 return;
11955 }
11956 flags = options[opt_idx].flags;
11957 if (flags & P_BOOL)
11958 {
11959 xp->xp_context = EXPAND_NOTHING;
11960 return;
11961 }
11962 }
11963 }
11964 /* handle "-=" and "+=" */
11965 if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
11966 {
11967 ++p;
11968 nextchar = '=';
11969 }
11970 if ((nextchar != '=' && nextchar != ':')
11971 || xp->xp_context == EXPAND_BOOL_SETTINGS)
11972 {
11973 xp->xp_context = EXPAND_UNSUCCESSFUL;
11974 return;
11975 }
11976 if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
11977 {
11978 xp->xp_context = EXPAND_OLD_SETTING;
11979 if (is_term_option)
11980 expand_option_idx = -1;
11981 else
11982 expand_option_idx = opt_idx;
11983 xp->xp_pattern = p + 1;
11984 return;
11985 }
11986 xp->xp_context = EXPAND_NOTHING;
11987 if (is_term_option || (flags & P_NUM))
11988 return;
11989
11990 xp->xp_pattern = p + 1;
11991
11992 if (flags & P_EXPAND)
11993 {
11994 p = options[opt_idx].var;
11995 if (p == (char_u *)&p_bdir
11996 || p == (char_u *)&p_dir
11997 || p == (char_u *)&p_path
Bram Moolenaarf6fee0e2016-02-21 23:02:49 +010011998 || p == (char_u *)&p_pp
Bram Moolenaar071d4272004-06-13 20:20:40 +000011999 || p == (char_u *)&p_rtp
12000#ifdef FEAT_SEARCHPATH
12001 || p == (char_u *)&p_cdpath
12002#endif
12003#ifdef FEAT_SESSION
12004 || p == (char_u *)&p_vdir
12005#endif
12006 )
12007 {
12008 xp->xp_context = EXPAND_DIRECTORIES;
12009 if (p == (char_u *)&p_path
12010#ifdef FEAT_SEARCHPATH
12011 || p == (char_u *)&p_cdpath
12012#endif
12013 )
12014 xp->xp_backslash = XP_BS_THREE;
12015 else
12016 xp->xp_backslash = XP_BS_ONE;
12017 }
12018 else
12019 {
12020 xp->xp_context = EXPAND_FILES;
12021 /* for 'tags' need three backslashes for a space */
12022 if (p == (char_u *)&p_tags)
12023 xp->xp_backslash = XP_BS_THREE;
12024 else
12025 xp->xp_backslash = XP_BS_ONE;
12026 }
12027 }
12028
12029 /* For an option that is a list of file names, find the start of the
12030 * last file name. */
12031 for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
12032 {
12033 /* count number of backslashes before ' ' or ',' */
12034 if (*p == ' ' || *p == ',')
12035 {
12036 s = p;
12037 while (s > xp->xp_pattern && *(s - 1) == '\\')
12038 --s;
12039 if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
12040 || (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
12041 {
12042 xp->xp_pattern = p + 1;
12043 break;
12044 }
12045 }
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012046
Bram Moolenaarb9a02fc2006-03-12 22:08:12 +000012047#ifdef FEAT_SPELL
Bram Moolenaar24bbcfe2005-06-28 23:32:02 +000012048 /* for 'spellsuggest' start at "file:" */
12049 if (options[opt_idx].var == (char_u *)&p_sps
12050 && STRNCMP(p, "file:", 5) == 0)
12051 {
12052 xp->xp_pattern = p + 5;
12053 break;
12054 }
12055#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012056 }
12057
12058 return;
12059}
12060
12061 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012062ExpandSettings(
12063 expand_T *xp,
12064 regmatch_T *regmatch,
12065 int *num_file,
12066 char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012067{
12068 int num_normal = 0; /* Nr of matching non-term-code settings */
12069 int num_term = 0; /* Nr of matching terminal code settings */
12070 int opt_idx;
12071 int match;
12072 int count = 0;
12073 char_u *str;
12074 int loop;
12075 int is_term_opt;
12076 char_u name_buf[MAX_KEY_NAME_LEN];
12077 static char *(names[]) = {"all", "termcap"};
12078 int ic = regmatch->rm_ic; /* remember the ignore-case flag */
12079
12080 /* do this loop twice:
12081 * loop == 0: count the number of matching options
12082 * loop == 1: copy the matching options into allocated memory
12083 */
12084 for (loop = 0; loop <= 1; ++loop)
12085 {
12086 regmatch->rm_ic = ic;
12087 if (xp->xp_context != EXPAND_BOOL_SETTINGS)
12088 {
Bram Moolenaar2c4278f2009-05-17 11:33:22 +000012089 for (match = 0; match < (int)(sizeof(names) / sizeof(char *));
12090 ++match)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012091 if (vim_regexec(regmatch, (char_u *)names[match], (colnr_T)0))
12092 {
12093 if (loop == 0)
12094 num_normal++;
12095 else
12096 (*file)[count++] = vim_strsave((char_u *)names[match]);
12097 }
12098 }
12099 for (opt_idx = 0; (str = (char_u *)options[opt_idx].fullname) != NULL;
12100 opt_idx++)
12101 {
12102 if (options[opt_idx].var == NULL)
12103 continue;
12104 if (xp->xp_context == EXPAND_BOOL_SETTINGS
12105 && !(options[opt_idx].flags & P_BOOL))
12106 continue;
12107 is_term_opt = istermoption(&options[opt_idx]);
12108 if (is_term_opt && num_normal > 0)
12109 continue;
12110 match = FALSE;
12111 if (vim_regexec(regmatch, str, (colnr_T)0)
12112 || (options[opt_idx].shortname != NULL
12113 && vim_regexec(regmatch,
12114 (char_u *)options[opt_idx].shortname, (colnr_T)0)))
12115 match = TRUE;
12116 else if (is_term_opt)
12117 {
12118 name_buf[0] = '<';
12119 name_buf[1] = 't';
12120 name_buf[2] = '_';
12121 name_buf[3] = str[2];
12122 name_buf[4] = str[3];
12123 name_buf[5] = '>';
12124 name_buf[6] = NUL;
12125 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12126 {
12127 match = TRUE;
12128 str = name_buf;
12129 }
12130 }
12131 if (match)
12132 {
12133 if (loop == 0)
12134 {
12135 if (is_term_opt)
12136 num_term++;
12137 else
12138 num_normal++;
12139 }
12140 else
12141 (*file)[count++] = vim_strsave(str);
12142 }
12143 }
12144 /*
12145 * Check terminal key codes, these are not in the option table
12146 */
12147 if (xp->xp_context != EXPAND_BOOL_SETTINGS && num_normal == 0)
12148 {
12149 for (opt_idx = 0; (str = get_termcode(opt_idx)) != NULL; opt_idx++)
12150 {
12151 if (!isprint(str[0]) || !isprint(str[1]))
12152 continue;
12153
12154 name_buf[0] = 't';
12155 name_buf[1] = '_';
12156 name_buf[2] = str[0];
12157 name_buf[3] = str[1];
12158 name_buf[4] = NUL;
12159
12160 match = FALSE;
12161 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12162 match = TRUE;
12163 else
12164 {
12165 name_buf[0] = '<';
12166 name_buf[1] = 't';
12167 name_buf[2] = '_';
12168 name_buf[3] = str[0];
12169 name_buf[4] = str[1];
12170 name_buf[5] = '>';
12171 name_buf[6] = NUL;
12172
12173 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12174 match = TRUE;
12175 }
12176 if (match)
12177 {
12178 if (loop == 0)
12179 num_term++;
12180 else
12181 (*file)[count++] = vim_strsave(name_buf);
12182 }
12183 }
12184
12185 /*
12186 * Check special key names.
12187 */
12188 regmatch->rm_ic = TRUE; /* ignore case here */
12189 for (opt_idx = 0; (str = get_key_name(opt_idx)) != NULL; opt_idx++)
12190 {
12191 name_buf[0] = '<';
12192 STRCPY(name_buf + 1, str);
12193 STRCAT(name_buf, ">");
12194
12195 if (vim_regexec(regmatch, name_buf, (colnr_T)0))
12196 {
12197 if (loop == 0)
12198 num_term++;
12199 else
12200 (*file)[count++] = vim_strsave(name_buf);
12201 }
12202 }
12203 }
12204 if (loop == 0)
12205 {
12206 if (num_normal > 0)
12207 *num_file = num_normal;
12208 else if (num_term > 0)
12209 *num_file = num_term;
12210 else
12211 return OK;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012212 *file = ALLOC_MULT(char_u *, *num_file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012213 if (*file == NULL)
12214 {
12215 *file = (char_u **)"";
12216 return FAIL;
12217 }
12218 }
12219 }
12220 return OK;
12221}
12222
12223 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012224ExpandOldSetting(int *num_file, char_u ***file)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012225{
12226 char_u *var = NULL; /* init for GCC */
12227 char_u *buf;
12228
12229 *num_file = 0;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020012230 *file = ALLOC_ONE(char_u *);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012231 if (*file == NULL)
12232 return FAIL;
12233
12234 /*
12235 * For a terminal key code expand_option_idx is < 0.
12236 */
12237 if (expand_option_idx < 0)
12238 {
12239 var = find_termcode(expand_option_name + 2);
12240 if (var == NULL)
12241 expand_option_idx = findoption(expand_option_name);
12242 }
12243
12244 if (expand_option_idx >= 0)
12245 {
12246 /* put string of option value in NameBuff */
12247 option_value2string(&options[expand_option_idx], expand_option_flags);
12248 var = NameBuff;
12249 }
12250 else if (var == NULL)
12251 var = (char_u *)"";
12252
12253 /* A backslash is required before some characters. This is the reverse of
12254 * what happens in do_set(). */
12255 buf = vim_strsave_escaped(var, escape_chars);
12256
12257 if (buf == NULL)
12258 {
Bram Moolenaard23a8232018-02-10 18:45:26 +010012259 VIM_CLEAR(*file);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012260 return FAIL;
12261 }
12262
12263#ifdef BACKSLASH_IN_FILENAME
12264 /* For MS-Windows et al. we don't double backslashes at the start and
12265 * before a file name character. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012266 for (var = buf; *var != NUL; MB_PTR_ADV(var))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012267 if (var[0] == '\\' && var[1] == '\\'
12268 && expand_option_idx >= 0
12269 && (options[expand_option_idx].flags & P_EXPAND)
12270 && vim_isfilec(var[2])
12271 && (var[2] != '\\' || (var == buf && var[4] != '\\')))
Bram Moolenaarc1a11ed2008-06-24 22:09:24 +000012272 STRMOVE(var, var + 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012273#endif
12274
12275 *file[0] = buf;
12276 *num_file = 1;
12277 return OK;
12278}
12279#endif
12280
12281/*
12282 * Get the value for the numeric or string option *opp in a nice format into
12283 * NameBuff[]. Must not be called with a hidden option!
12284 */
12285 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012286option_value2string(
12287 struct vimoption *opp,
12288 int opt_flags) /* OPT_GLOBAL and/or OPT_LOCAL */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012289{
12290 char_u *varp;
12291
12292 varp = get_varp_scope(opp, opt_flags);
12293
12294 if (opp->flags & P_NUM)
12295 {
12296 long wc = 0;
12297
12298 if (wc_use_keyname(varp, &wc))
12299 STRCPY(NameBuff, get_special_key_name((int)wc, 0));
12300 else if (wc != 0)
12301 STRCPY(NameBuff, transchar((int)wc));
12302 else
12303 sprintf((char *)NameBuff, "%ld", *(long *)varp);
12304 }
12305 else /* P_STRING */
12306 {
12307 varp = *(char_u **)(varp);
12308 if (varp == NULL) /* just in case */
12309 NameBuff[0] = NUL;
12310#ifdef FEAT_CRYPT
12311 /* don't show the actual value of 'key', only that it's set */
Bram Moolenaareb3593b2006-04-22 22:33:57 +000012312 else if (opp->var == (char_u *)&p_key && *varp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012313 STRCPY(NameBuff, "*****");
12314#endif
12315 else if (opp->flags & P_EXPAND)
12316 home_replace(NULL, varp, NameBuff, MAXPATHL, FALSE);
12317 /* Translate 'pastetoggle' into special key names */
12318 else if ((char_u **)opp->var == &p_pt)
12319 str2specialbuf(p_pt, NameBuff, MAXPATHL);
12320 else
Bram Moolenaarce0842a2005-07-18 21:58:11 +000012321 vim_strncpy(NameBuff, varp, MAXPATHL - 1);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012322 }
12323}
12324
12325/*
12326 * Return TRUE if "varp" points to 'wildchar' or 'wildcharm' and it can be
12327 * printed as a keyname.
12328 * "*wcp" is set to the value of the option if it's 'wildchar' or 'wildcharm'.
12329 */
12330 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012331wc_use_keyname(char_u *varp, long *wcp)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012332{
12333 if (((long *)varp == &p_wc) || ((long *)varp == &p_wcm))
12334 {
12335 *wcp = *(long *)varp;
12336 if (IS_SPECIAL(*wcp) || find_special_key_in_table((int)*wcp) >= 0)
12337 return TRUE;
12338 }
12339 return FALSE;
12340}
12341
Bram Moolenaar01615492015-02-03 13:00:38 +010012342#if defined(FEAT_LANGMAP) || defined(PROTO)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012343/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012344 * Any character has an equivalent 'langmap' character. This is used for
12345 * keyboards that have a special language mode that sends characters above
12346 * 128 (although other characters can be translated too). The "to" field is a
12347 * Vim command character. This avoids having to switch the keyboard back to
12348 * ASCII mode when leaving Insert mode.
12349 *
12350 * langmap_mapchar[] maps any of 256 chars to an ASCII char used for Vim
12351 * commands.
Bram Moolenaarfc3abf42019-01-24 15:54:21 +010012352 * langmap_mapga.ga_data is a sorted table of langmap_entry_T. This does the
12353 * same as langmap_mapchar[] for characters >= 256.
12354 *
12355 * Use growarray for 'langmap' chars >= 256
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012356 */
12357typedef struct
12358{
12359 int from;
12360 int to;
12361} langmap_entry_T;
12362
12363static garray_T langmap_mapga;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012364
12365/*
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012366 * Search for an entry in "langmap_mapga" for "from". If found set the "to"
12367 * field. If not found insert a new entry at the appropriate location.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012368 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012369 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012370langmap_set_entry(int from, int to)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012371{
12372 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
Bram Moolenaarcc448b32010-07-14 16:52:17 +020012373 int a = 0;
12374 int b = langmap_mapga.ga_len;
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012375
12376 /* Do a binary search for an existing entry. */
12377 while (a != b)
12378 {
12379 int i = (a + b) / 2;
12380 int d = entries[i].from - from;
12381
12382 if (d == 0)
12383 {
12384 entries[i].to = to;
12385 return;
12386 }
12387 if (d < 0)
12388 a = i + 1;
12389 else
12390 b = i;
12391 }
12392
12393 if (ga_grow(&langmap_mapga, 1) != OK)
12394 return; /* out of memory */
12395
12396 /* insert new entry at position "a" */
12397 entries = (langmap_entry_T *)(langmap_mapga.ga_data) + a;
12398 mch_memmove(entries + 1, entries,
12399 (langmap_mapga.ga_len - a) * sizeof(langmap_entry_T));
12400 ++langmap_mapga.ga_len;
12401 entries[0].from = from;
12402 entries[0].to = to;
12403}
12404
12405/*
12406 * Apply 'langmap' to multi-byte character "c" and return the result.
12407 */
12408 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012409langmap_adjust_mb(int c)
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012410{
12411 langmap_entry_T *entries = (langmap_entry_T *)(langmap_mapga.ga_data);
12412 int a = 0;
12413 int b = langmap_mapga.ga_len;
12414
12415 while (a != b)
12416 {
12417 int i = (a + b) / 2;
12418 int d = entries[i].from - c;
12419
12420 if (d == 0)
12421 return entries[i].to; /* found matching entry */
12422 if (d < 0)
12423 a = i + 1;
12424 else
12425 b = i;
12426 }
12427 return c; /* no entry found, return "c" unmodified */
12428}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012429
12430 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012431langmap_init(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012432{
12433 int i;
12434
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012435 for (i = 0; i < 256; i++)
12436 langmap_mapchar[i] = i; /* we init with a one-to-one map */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012437 ga_init2(&langmap_mapga, sizeof(langmap_entry_T), 8);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012438}
12439
12440/*
12441 * Called when langmap option is set; the language map can be
12442 * changed at any time!
12443 */
12444 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012445langmap_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012446{
12447 char_u *p;
12448 char_u *p2;
12449 int from, to;
12450
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012451 ga_clear(&langmap_mapga); /* clear the previous map first */
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012452 langmap_init(); /* back to one-to-one map */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012453
12454 for (p = p_langmap; p[0] != NUL; )
12455 {
Bram Moolenaar1cd871b2004-12-19 22:46:22 +000012456 for (p2 = p; p2[0] != NUL && p2[0] != ',' && p2[0] != ';';
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012457 MB_PTR_ADV(p2))
Bram Moolenaar071d4272004-06-13 20:20:40 +000012458 {
12459 if (p2[0] == '\\' && p2[1] != NUL)
12460 ++p2;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012461 }
12462 if (p2[0] == ';')
12463 ++p2; /* abcd;ABCD form, p2 points to A */
12464 else
12465 p2 = NULL; /* aAbBcCdD form, p2 is NULL */
12466 while (p[0])
12467 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012468 if (p[0] == ',')
12469 {
12470 ++p;
12471 break;
12472 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012473 if (p[0] == '\\' && p[1] != NUL)
12474 ++p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012475 from = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012476 to = NUL;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012477 if (p2 == NULL)
12478 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012479 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012480 if (p[0] != ',')
12481 {
12482 if (p[0] == '\\')
12483 ++p;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012484 to = (*mb_ptr2char)(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012485 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012486 }
12487 else
12488 {
Bram Moolenaar6af05062010-05-14 17:32:58 +020012489 if (p2[0] != ',')
12490 {
12491 if (p2[0] == '\\')
12492 ++p2;
Bram Moolenaar6af05062010-05-14 17:32:58 +020012493 to = (*mb_ptr2char)(p2);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012494 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012495 }
12496 if (to == NUL)
12497 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012498 semsg(_("E357: 'langmap': Matching character missing for %s"),
Bram Moolenaar071d4272004-06-13 20:20:40 +000012499 transchar(from));
12500 return;
12501 }
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012502
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012503 if (from >= 256)
12504 langmap_set_entry(from, to);
12505 else
Bram Moolenaar28e8d272009-02-21 19:28:48 +000012506 langmap_mapchar[from & 255] = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012507
12508 /* Advance to next pair */
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012509 MB_PTR_ADV(p);
Bram Moolenaar6af05062010-05-14 17:32:58 +020012510 if (p2 != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012511 {
Bram Moolenaar91acfff2017-03-12 19:22:36 +010012512 MB_PTR_ADV(p2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012513 if (*p == ';')
12514 {
12515 p = p2;
12516 if (p[0] != NUL)
12517 {
12518 if (p[0] != ',')
12519 {
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010012520 semsg(_("E358: 'langmap': Extra characters after semicolon: %s"), p);
Bram Moolenaar071d4272004-06-13 20:20:40 +000012521 return;
12522 }
12523 ++p;
12524 }
12525 break;
12526 }
12527 }
12528 }
12529 }
12530}
12531#endif
12532
12533/*
12534 * Return TRUE if format option 'x' is in effect.
12535 * Take care of no formatting when 'paste' is set.
12536 */
12537 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012538has_format_option(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012539{
12540 if (p_paste)
12541 return FALSE;
12542 return (vim_strchr(curbuf->b_p_fo, x) != NULL);
12543}
12544
12545/*
12546 * Return TRUE if "x" is present in 'shortmess' option, or
12547 * 'shortmess' contains 'a' and "x" is present in SHM_A.
12548 */
12549 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012550shortmess(int x)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012551{
Bram Moolenaar7f29f7a2012-02-29 13:51:37 +010012552 return p_shm != NULL &&
12553 ( vim_strchr(p_shm, x) != NULL
Bram Moolenaar071d4272004-06-13 20:20:40 +000012554 || (vim_strchr(p_shm, 'a') != NULL
12555 && vim_strchr((char_u *)SHM_A, x) != NULL));
12556}
12557
12558/*
12559 * paste_option_changed() - Called after p_paste was set or reset.
12560 */
12561 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012562paste_option_changed(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012563{
12564 static int old_p_paste = FALSE;
12565 static int save_sm = 0;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012566 static int save_sta = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012567#ifdef FEAT_CMDL_INFO
12568 static int save_ru = 0;
12569#endif
12570#ifdef FEAT_RIGHTLEFT
12571 static int save_ri = 0;
12572 static int save_hkmap = 0;
12573#endif
12574 buf_T *buf;
12575
12576 if (p_paste)
12577 {
12578 /*
12579 * Paste switched from off to on.
12580 * Save the current values, so they can be restored later.
12581 */
12582 if (!old_p_paste)
12583 {
12584 /* save options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012585 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012586 {
12587 buf->b_p_tw_nopaste = buf->b_p_tw;
12588 buf->b_p_wm_nopaste = buf->b_p_wm;
12589 buf->b_p_sts_nopaste = buf->b_p_sts;
12590 buf->b_p_ai_nopaste = buf->b_p_ai;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012591 buf->b_p_et_nopaste = buf->b_p_et;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012592#ifdef FEAT_VARTABS
12593 if (buf->b_p_vsts_nopaste)
12594 vim_free(buf->b_p_vsts_nopaste);
12595 buf->b_p_vsts_nopaste = buf->b_p_vsts && buf->b_p_vsts != empty_option
12596 ? vim_strsave(buf->b_p_vsts) : NULL;
12597#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012598 }
12599
12600 /* save global options */
12601 save_sm = p_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012602 save_sta = p_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012603#ifdef FEAT_CMDL_INFO
12604 save_ru = p_ru;
12605#endif
12606#ifdef FEAT_RIGHTLEFT
12607 save_ri = p_ri;
12608 save_hkmap = p_hkmap;
12609#endif
12610 /* save global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012611 p_ai_nopaste = p_ai;
12612 p_et_nopaste = p_et;
12613 p_sts_nopaste = p_sts;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012614 p_tw_nopaste = p_tw;
12615 p_wm_nopaste = p_wm;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012616#ifdef FEAT_VARTABS
12617 if (p_vsts_nopaste)
12618 vim_free(p_vsts_nopaste);
12619 p_vsts_nopaste = p_vsts && p_vsts != empty_option ? vim_strsave(p_vsts) : NULL;
12620#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012621 }
12622
12623 /*
12624 * Always set the option values, also when 'paste' is set when it is
12625 * already on.
12626 */
12627 /* set options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012628 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012629 {
12630 buf->b_p_tw = 0; /* textwidth is 0 */
12631 buf->b_p_wm = 0; /* wrapmargin is 0 */
12632 buf->b_p_sts = 0; /* softtabstop is 0 */
12633 buf->b_p_ai = 0; /* no auto-indent */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012634 buf->b_p_et = 0; /* no expandtab */
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012635#ifdef FEAT_VARTABS
12636 if (buf->b_p_vsts)
12637 free_string_option(buf->b_p_vsts);
12638 buf->b_p_vsts = empty_option;
12639 if (buf->b_p_vsts_array)
12640 vim_free(buf->b_p_vsts_array);
12641 buf->b_p_vsts_array = 0;
12642#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012643 }
12644
12645 /* set global options */
12646 p_sm = 0; /* no showmatch */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012647 p_sta = 0; /* no smarttab */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012648#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012649 if (p_ru)
12650 status_redraw_all(); /* redraw to remove the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012651 p_ru = 0; /* no ruler */
12652#endif
12653#ifdef FEAT_RIGHTLEFT
12654 p_ri = 0; /* no reverse insert */
12655 p_hkmap = 0; /* no Hebrew keyboard */
12656#endif
12657 /* set global values for local buffer options */
12658 p_tw = 0;
12659 p_wm = 0;
12660 p_sts = 0;
12661 p_ai = 0;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012662#ifdef FEAT_VARTABS
12663 if (p_vsts)
12664 free_string_option(p_vsts);
12665 p_vsts = empty_option;
12666#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012667 }
12668
12669 /*
12670 * Paste switched from on to off: Restore saved values.
12671 */
12672 else if (old_p_paste)
12673 {
12674 /* restore options for each buffer */
Bram Moolenaar29323592016-07-24 22:04:11 +020012675 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012676 {
12677 buf->b_p_tw = buf->b_p_tw_nopaste;
12678 buf->b_p_wm = buf->b_p_wm_nopaste;
12679 buf->b_p_sts = buf->b_p_sts_nopaste;
12680 buf->b_p_ai = buf->b_p_ai_nopaste;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012681 buf->b_p_et = buf->b_p_et_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012682#ifdef FEAT_VARTABS
12683 if (buf->b_p_vsts)
12684 free_string_option(buf->b_p_vsts);
12685 buf->b_p_vsts = buf->b_p_vsts_nopaste
12686 ? vim_strsave(buf->b_p_vsts_nopaste) : empty_option;
12687 if (buf->b_p_vsts_array)
12688 vim_free(buf->b_p_vsts_array);
12689 if (buf->b_p_vsts && buf->b_p_vsts != empty_option)
12690 tabstop_set(buf->b_p_vsts, &buf->b_p_vsts_array);
12691 else
12692 buf->b_p_vsts_array = 0;
12693#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012694 }
12695
12696 /* restore global options */
12697 p_sm = save_sm;
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012698 p_sta = save_sta;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012699#ifdef FEAT_CMDL_INFO
Bram Moolenaar071d4272004-06-13 20:20:40 +000012700 if (p_ru != save_ru)
12701 status_redraw_all(); /* redraw to draw the ruler */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012702 p_ru = save_ru;
12703#endif
12704#ifdef FEAT_RIGHTLEFT
12705 p_ri = save_ri;
12706 p_hkmap = save_hkmap;
12707#endif
12708 /* set global values for local buffer options */
Bram Moolenaar54f018c2015-09-15 17:30:40 +020012709 p_ai = p_ai_nopaste;
12710 p_et = p_et_nopaste;
12711 p_sts = p_sts_nopaste;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012712 p_tw = p_tw_nopaste;
12713 p_wm = p_wm_nopaste;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020012714#ifdef FEAT_VARTABS
12715 if (p_vsts)
12716 free_string_option(p_vsts);
12717 p_vsts = p_vsts_nopaste ? vim_strsave(p_vsts_nopaste) : empty_option;
12718#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012719 }
12720
12721 old_p_paste = p_paste;
12722}
12723
12724/*
12725 * vimrc_found() - Called when a ".vimrc" or "VIMINIT" has been found.
12726 *
12727 * Reset 'compatible' and set the values for options that didn't get set yet
12728 * to the Vim defaults.
12729 * Don't do this if the 'compatible' option has been set or reset before.
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012730 * When "fname" is not NULL, use it to set $"envname" when it wasn't set yet.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012731 */
12732 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012733vimrc_found(char_u *fname, char_u *envname)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012734{
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012735 int opt_idx;
Bram Moolenaar4c3f5362006-04-11 21:38:50 +000012736 int dofree = FALSE;
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012737 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012738
12739 if (!option_was_set((char_u *)"cp"))
12740 {
12741 p_cp = FALSE;
12742 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12743 if (!(options[opt_idx].flags & (P_WAS_SET|P_VI_DEF)))
12744 set_option_default(opt_idx, OPT_FREE, FALSE);
12745 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012746 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012747 }
Bram Moolenaar910f66f2006-04-05 20:41:53 +000012748
12749 if (fname != NULL)
12750 {
12751 p = vim_getenv(envname, &dofree);
12752 if (p == NULL)
12753 {
12754 /* Set $MYVIMRC to the first vimrc file found. */
12755 p = FullName_save(fname, FALSE);
12756 if (p != NULL)
12757 {
12758 vim_setenv(envname, p);
12759 vim_free(p);
12760 }
12761 }
12762 else if (dofree)
12763 vim_free(p);
12764 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000012765}
12766
12767/*
12768 * Set 'compatible' on or off. Called for "-C" and "-N" command line arg.
12769 */
12770 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012771change_compatible(int on)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012772{
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012773 int opt_idx;
12774
Bram Moolenaar071d4272004-06-13 20:20:40 +000012775 if (p_cp != on)
12776 {
12777 p_cp = on;
12778 compatible_set();
12779 }
Bram Moolenaarfc1421e2006-04-20 22:17:20 +000012780 opt_idx = findoption((char_u *)"cp");
12781 if (opt_idx >= 0)
12782 options[opt_idx].flags |= P_WAS_SET;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012783}
12784
12785/*
12786 * Return TRUE when option "name" has been set.
Bram Moolenaar1a4a75c2013-07-28 16:03:06 +020012787 * Only works correctly for global options.
Bram Moolenaar071d4272004-06-13 20:20:40 +000012788 */
12789 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012790option_was_set(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012791{
12792 int idx;
12793
12794 idx = findoption(name);
12795 if (idx < 0) /* unknown option */
12796 return FALSE;
12797 if (options[idx].flags & P_WAS_SET)
12798 return TRUE;
12799 return FALSE;
12800}
12801
12802/*
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012803 * Reset the flag indicating option "name" was set.
12804 */
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012805 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012806reset_option_was_set(char_u *name)
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012807{
12808 int idx = findoption(name);
12809
12810 if (idx >= 0)
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012811 {
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012812 options[idx].flags &= ~P_WAS_SET;
Bram Moolenaarfe8ef982018-09-13 20:31:54 +020012813 return OK;
12814 }
12815 return FAIL;
Bram Moolenaar15d55de2012-12-05 14:43:02 +010012816}
12817
12818/*
Bram Moolenaar071d4272004-06-13 20:20:40 +000012819 * compatible_set() - Called when 'compatible' has been set or unset.
12820 *
12821 * When 'compatible' set: Set all relevant options (those that have the P_VIM)
12822 * flag) to a Vi compatible value.
12823 * When 'compatible' is unset: Set all options that have a different default
12824 * for Vim (without the P_VI_DEF flag) to that default.
12825 */
12826 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012827compatible_set(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012828{
12829 int opt_idx;
12830
12831 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
12832 if ( ((options[opt_idx].flags & P_VIM) && p_cp)
12833 || (!(options[opt_idx].flags & P_VI_DEF) && !p_cp))
12834 set_option_default(opt_idx, OPT_FREE, p_cp);
12835 didset_options();
Bram Moolenaare68c25c2015-08-25 15:39:55 +020012836 didset_options2();
Bram Moolenaar071d4272004-06-13 20:20:40 +000012837}
12838
12839#ifdef FEAT_LINEBREAK
12840
Bram Moolenaar071d4272004-06-13 20:20:40 +000012841/*
12842 * fill_breakat_flags() -- called when 'breakat' changes value.
12843 */
12844 static void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012845fill_breakat_flags(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012846{
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012847 char_u *p;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012848 int i;
12849
12850 for (i = 0; i < 256; i++)
12851 breakat_flags[i] = FALSE;
12852
12853 if (p_breakat != NULL)
Bram Moolenaarac6e65f2005-08-29 22:25:38 +000012854 for (p = p_breakat; *p; p++)
12855 breakat_flags[*p] = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000012856}
Bram Moolenaar071d4272004-06-13 20:20:40 +000012857#endif
12858
12859/*
12860 * Check an option that can be a range of string values.
12861 *
12862 * Return OK for correct value, FAIL otherwise.
12863 * Empty is always OK.
12864 */
12865 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012866check_opt_strings(
12867 char_u *val,
12868 char **values,
12869 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012870{
12871 return opt_strings_flags(val, values, NULL, list);
12872}
12873
12874/*
12875 * Handle an option that can be a range of string values.
12876 * Set a flag in "*flagp" for each string present.
12877 *
12878 * Return OK for correct value, FAIL otherwise.
12879 * Empty is always OK.
12880 */
12881 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012882opt_strings_flags(
12883 char_u *val, /* new value */
12884 char **values, /* array of valid string values */
12885 unsigned *flagp,
12886 int list) /* when TRUE: accept a list of values */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012887{
12888 int i;
12889 int len;
12890 unsigned new_flags = 0;
12891
12892 while (*val)
12893 {
12894 for (i = 0; ; ++i)
12895 {
12896 if (values[i] == NULL) /* val not found in values[] */
12897 return FAIL;
12898
12899 len = (int)STRLEN(values[i]);
12900 if (STRNCMP(values[i], val, len) == 0
12901 && ((list && val[len] == ',') || val[len] == NUL))
12902 {
12903 val += len + (val[len] == ',');
12904 new_flags |= (1 << i);
12905 break; /* check next item in val list */
12906 }
12907 }
12908 }
12909 if (flagp != NULL)
12910 *flagp = new_flags;
12911
12912 return OK;
12913}
12914
12915/*
12916 * Read the 'wildmode' option, fill wim_flags[].
12917 */
12918 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012919check_opt_wim(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012920{
12921 char_u new_wim_flags[4];
12922 char_u *p;
12923 int i;
12924 int idx = 0;
12925
12926 for (i = 0; i < 4; ++i)
12927 new_wim_flags[i] = 0;
12928
12929 for (p = p_wim; *p; ++p)
12930 {
12931 for (i = 0; ASCII_ISALPHA(p[i]); ++i)
12932 ;
12933 if (p[i] != NUL && p[i] != ',' && p[i] != ':')
12934 return FAIL;
12935 if (i == 7 && STRNCMP(p, "longest", 7) == 0)
12936 new_wim_flags[idx] |= WIM_LONGEST;
12937 else if (i == 4 && STRNCMP(p, "full", 4) == 0)
12938 new_wim_flags[idx] |= WIM_FULL;
12939 else if (i == 4 && STRNCMP(p, "list", 4) == 0)
12940 new_wim_flags[idx] |= WIM_LIST;
12941 else
12942 return FAIL;
12943 p += i;
12944 if (*p == NUL)
12945 break;
12946 if (*p == ',')
12947 {
12948 if (idx == 3)
12949 return FAIL;
12950 ++idx;
12951 }
12952 }
12953
12954 /* fill remaining entries with last flag */
12955 while (idx < 3)
12956 {
12957 new_wim_flags[idx + 1] = new_wim_flags[idx];
12958 ++idx;
12959 }
12960
12961 /* only when there are no errors, wim_flags[] is changed */
12962 for (i = 0; i < 4; ++i)
12963 wim_flags[i] = new_wim_flags[i];
12964 return OK;
12965}
12966
12967/*
12968 * Check if backspacing over something is allowed.
12969 */
12970 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010012971can_bs(
12972 int what) /* BS_INDENT, BS_EOL or BS_START */
Bram Moolenaar071d4272004-06-13 20:20:40 +000012973{
Bram Moolenaar6b810d92018-06-04 17:28:44 +020012974#ifdef FEAT_JOB_CHANNEL
12975 if (what == BS_START && bt_prompt(curbuf))
12976 return FALSE;
12977#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000012978 switch (*p_bs)
12979 {
12980 case '2': return TRUE;
12981 case '1': return (what != BS_START);
12982 case '0': return FALSE;
12983 }
12984 return vim_strchr(p_bs, what) != NULL;
12985}
12986
12987/*
12988 * Save the current values of 'fileformat' and 'fileencoding', so that we know
12989 * the file must be considered changed when the value is different.
12990 */
12991 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010012992save_file_ff(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +000012993{
12994 buf->b_start_ffc = *buf->b_p_ff;
12995 buf->b_start_eol = buf->b_p_eol;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000012996 buf->b_start_bomb = buf->b_p_bomb;
12997
Bram Moolenaar071d4272004-06-13 20:20:40 +000012998 /* Only use free/alloc when necessary, they take time. */
12999 if (buf->b_start_fenc == NULL
13000 || STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0)
13001 {
13002 vim_free(buf->b_start_fenc);
13003 buf->b_start_fenc = vim_strsave(buf->b_p_fenc);
13004 }
Bram Moolenaar071d4272004-06-13 20:20:40 +000013005}
13006
13007/*
13008 * Return TRUE if 'fileformat' and/or 'fileencoding' has a different value
13009 * from when editing started (save_file_ff() called).
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013010 * Also when 'endofline' was changed and 'binary' is set, or when 'bomb' was
13011 * changed and 'binary' is not set.
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013012 * Also when 'endofline' was changed and 'fixeol' is not set.
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013013 * When "ignore_empty" is true don't consider a new, empty buffer to be
13014 * changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +000013015 */
13016 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013017file_ff_differs(buf_T *buf, int ignore_empty)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013018{
Bram Moolenaar9cffde92007-07-24 07:51:18 +000013019 /* In a buffer that was never loaded the options are not valid. */
13020 if (buf->b_flags & BF_NEVERLOADED)
13021 return FALSE;
Bram Moolenaar164c60f2011-01-22 00:11:50 +010013022 if (ignore_empty
13023 && (buf->b_flags & BF_NEW)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013024 && buf->b_ml.ml_line_count == 1
13025 && *ml_get_buf(buf, (linenr_T)1, FALSE) == NUL)
13026 return FALSE;
13027 if (buf->b_start_ffc != *buf->b_p_ff)
13028 return TRUE;
Bram Moolenaar34d72d42015-07-17 14:18:08 +020013029 if ((buf->b_p_bin || !buf->b_p_fixeol) && buf->b_start_eol != buf->b_p_eol)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013030 return TRUE;
Bram Moolenaar83eb8852007-08-12 13:51:26 +000013031 if (!buf->b_p_bin && buf->b_start_bomb != buf->b_p_bomb)
13032 return TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +000013033 if (buf->b_start_fenc == NULL)
13034 return (*buf->b_p_fenc != NUL);
13035 return (STRCMP(buf->b_start_fenc, buf->b_p_fenc) != 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +000013036}
13037
13038/*
13039 * return OK if "p" is a valid fileformat name, FAIL otherwise.
13040 */
13041 int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013042check_ff_value(char_u *p)
Bram Moolenaar071d4272004-06-13 20:20:40 +000013043{
13044 return check_opt_strings(p, p_ff_values, FALSE);
13045}
Bram Moolenaar14f24742012-08-08 18:01:05 +020013046
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013047#if defined(FEAT_VARTABS) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013048
13049/*
13050 * Set the integer values corresponding to the string setting of 'vartabstop'.
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013051 * "array" will be set, caller must free it if needed.
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013052 */
13053 int
13054tabstop_set(char_u *var, int **array)
13055{
13056 int valcount = 1;
13057 int t;
13058 char_u *cp;
13059
Bram Moolenaar64f41072018-10-15 22:51:50 +020013060 if (var[0] == NUL || (var[0] == '0' && var[1] == NUL))
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013061 {
13062 *array = NULL;
13063 return TRUE;
13064 }
13065
Bram Moolenaar64f41072018-10-15 22:51:50 +020013066 for (cp = var; *cp != NUL; ++cp)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013067 {
Bram Moolenaar64f41072018-10-15 22:51:50 +020013068 if (cp == var || cp[-1] == ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013069 {
13070 char_u *end;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013071
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013072 if (strtol((char *)cp, (char **)&end, 10) <= 0)
13073 {
13074 if (cp != end)
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013075 emsg(_(e_positive));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013076 else
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013077 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013078 return FALSE;
13079 }
13080 }
13081
13082 if (VIM_ISDIGIT(*cp))
13083 continue;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013084 if (cp[0] == ',' && cp > var && cp[-1] != ',' && cp[1] != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013085 {
13086 ++valcount;
13087 continue;
13088 }
Bram Moolenaarf9e3e092019-01-13 23:38:42 +010013089 emsg(_(e_invarg));
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013090 return FALSE;
13091 }
13092
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013093 *array = ALLOC_MULT(int, valcount + 1);
Bram Moolenaar55c77cf2019-02-16 19:05:11 +010013094 if (*array == NULL)
13095 return FALSE;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013096 (*array)[0] = valcount;
13097
13098 t = 1;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013099 for (cp = var; *cp != NUL;)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013100 {
13101 (*array)[t++] = atoi((char *)cp);
Bram Moolenaar64f41072018-10-15 22:51:50 +020013102 while (*cp != NUL && *cp != ',')
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013103 ++cp;
Bram Moolenaar64f41072018-10-15 22:51:50 +020013104 if (*cp != NUL)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013105 ++cp;
13106 }
13107
13108 return TRUE;
13109}
13110
13111/*
13112 * Calculate the number of screen spaces a tab will occupy.
13113 * If "vts" is set then the tab widths are taken from that array,
13114 * otherwise the value of ts is used.
13115 */
13116 int
13117tabstop_padding(colnr_T col, int ts_arg, int *vts)
13118{
13119 int ts = ts_arg == 0 ? 8 : ts_arg;
13120 int tabcount;
13121 colnr_T tabcol = 0;
13122 int t;
13123 int padding = 0;
13124
13125 if (vts == NULL || vts[0] == 0)
13126 return ts - (col % ts);
13127
13128 tabcount = vts[0];
13129
13130 for (t = 1; t <= tabcount; ++t)
13131 {
13132 tabcol += vts[t];
13133 if (tabcol > col)
13134 {
13135 padding = (int)(tabcol - col);
13136 break;
13137 }
13138 }
13139 if (t > tabcount)
13140 padding = vts[tabcount] - (int)((col - tabcol) % vts[tabcount]);
13141
13142 return padding;
13143}
13144
13145/*
13146 * Find the size of the tab that covers a particular column.
13147 */
13148 int
13149tabstop_at(colnr_T col, int ts, int *vts)
13150{
13151 int tabcount;
13152 colnr_T tabcol = 0;
13153 int t;
13154 int tab_size = 0;
13155
13156 if (vts == 0 || vts[0] == 0)
13157 return ts;
13158
13159 tabcount = vts[0];
13160 for (t = 1; t <= tabcount; ++t)
13161 {
13162 tabcol += vts[t];
13163 if (tabcol > col)
13164 {
13165 tab_size = vts[t];
13166 break;
13167 }
13168 }
13169 if (t > tabcount)
13170 tab_size = vts[tabcount];
13171
13172 return tab_size;
13173}
13174
13175/*
13176 * Find the column on which a tab starts.
13177 */
13178 colnr_T
13179tabstop_start(colnr_T col, int ts, int *vts)
13180{
13181 int tabcount;
13182 colnr_T tabcol = 0;
13183 int t;
13184 int excess;
13185
Bram Moolenaar0119a592018-06-24 23:53:28 +020013186 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013187 return (col / ts) * ts;
13188
13189 tabcount = vts[0];
13190 for (t = 1; t <= tabcount; ++t)
13191 {
13192 tabcol += vts[t];
13193 if (tabcol > col)
13194 return tabcol - vts[t];
13195 }
13196
13197 excess = tabcol % vts[tabcount];
13198 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount];
13199}
13200
13201/*
13202 * Find the number of tabs and spaces necessary to get from one column
13203 * to another.
13204 */
13205 void
13206tabstop_fromto(
13207 colnr_T start_col,
13208 colnr_T end_col,
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013209 int ts_arg,
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013210 int *vts,
13211 int *ntabs,
13212 int *nspcs)
13213{
13214 int spaces = end_col - start_col;
13215 colnr_T tabcol = 0;
13216 int padding = 0;
13217 int tabcount;
13218 int t;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013219 int ts = ts_arg == 0 ? curbuf->b_p_ts : ts_arg;
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013220
Bram Moolenaar0119a592018-06-24 23:53:28 +020013221 if (vts == NULL || vts[0] == 0)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013222 {
13223 int tabs = 0;
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013224 int initspc = 0;
Bram Moolenaar0119a592018-06-24 23:53:28 +020013225
Bram Moolenaar307ac5c2018-06-28 22:23:00 +020013226 initspc = ts - (start_col % ts);
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013227 if (spaces >= initspc)
13228 {
13229 spaces -= initspc;
13230 tabs++;
13231 }
13232 tabs += spaces / ts;
13233 spaces -= (spaces / ts) * ts;
13234
13235 *ntabs = tabs;
13236 *nspcs = spaces;
13237 return;
13238 }
13239
13240 /* Find the padding needed to reach the next tabstop. */
13241 tabcount = vts[0];
13242 for (t = 1; t <= tabcount; ++t)
13243 {
13244 tabcol += vts[t];
13245 if (tabcol > start_col)
13246 {
13247 padding = (int)(tabcol - start_col);
13248 break;
13249 }
13250 }
13251 if (t > tabcount)
13252 padding = vts[tabcount] - (int)((start_col - tabcol) % vts[tabcount]);
13253
13254 /* If the space needed is less than the padding no tabs can be used. */
13255 if (spaces < padding)
13256 {
13257 *ntabs = 0;
13258 *nspcs = spaces;
13259 return;
13260 }
13261
13262 *ntabs = 1;
13263 spaces -= padding;
13264
13265 /* At least one tab has been used. See if any more will fit. */
13266 while (spaces != 0 && ++t <= tabcount)
13267 {
13268 padding = vts[t];
13269 if (spaces < padding)
13270 {
13271 *nspcs = spaces;
13272 return;
13273 }
13274 ++*ntabs;
13275 spaces -= padding;
13276 }
13277
13278 *ntabs += spaces / vts[tabcount];
13279 *nspcs = spaces % vts[tabcount];
13280}
13281
13282/*
13283 * See if two tabstop arrays contain the same values.
13284 */
13285 int
13286tabstop_eq(int *ts1, int *ts2)
13287{
13288 int t;
13289
13290 if ((ts1 == 0 && ts2) || (ts1 && ts2 == 0))
13291 return FALSE;
13292 if (ts1 == ts2)
13293 return TRUE;
13294 if (ts1[0] != ts2[0])
13295 return FALSE;
13296
13297 for (t = 1; t <= ts1[0]; ++t)
13298 if (ts1[t] != ts2[t])
13299 return FALSE;
13300
13301 return TRUE;
13302}
13303
Bram Moolenaar113e1072019-01-20 15:30:40 +010013304#if defined(FEAT_BEVAL) || defined(PROTO)
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013305/*
13306 * Copy a tabstop array, allocating space for the new array.
13307 */
13308 int *
13309tabstop_copy(int *oldts)
13310{
13311 int *newts;
13312 int t;
13313
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013314 if (oldts == NULL)
13315 return NULL;
Bram Moolenaarc799fe22019-05-28 23:08:19 +020013316 newts = ALLOC_MULT(int, oldts[0] + 1);
Bram Moolenaar6ee96582019-04-27 22:06:37 +020013317 if (newts != NULL)
13318 for (t = 0; t <= oldts[0]; ++t)
13319 newts[t] = oldts[t];
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013320 return newts;
13321}
Bram Moolenaar113e1072019-01-20 15:30:40 +010013322#endif
Bram Moolenaar04958cb2018-06-23 19:23:02 +020013323
13324/*
13325 * Return a count of the number of tabstops.
13326 */
13327 int
13328tabstop_count(int *ts)
13329{
13330 return ts != NULL ? ts[0] : 0;
13331}
13332
13333/*
13334 * Return the first tabstop, or 8 if there are no tabstops defined.
13335 */
13336 int
13337tabstop_first(int *ts)
13338{
13339 return ts != NULL ? ts[1] : 8;
13340}
13341
13342#endif
13343
Bram Moolenaar14f24742012-08-08 18:01:05 +020013344/*
13345 * Return the effective shiftwidth value for current buffer, using the
13346 * 'tabstop' value when 'shiftwidth' is zero.
13347 */
13348 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013349get_sw_value(buf_T *buf)
Bram Moolenaar14f24742012-08-08 18:01:05 +020013350{
Bram Moolenaarf9514162018-11-22 03:08:29 +010013351 return get_sw_value_col(buf, 0);
13352}
13353
13354/*
13355 * Idem, using the first non-black in the current line.
13356 */
13357 long
13358get_sw_value_indent(buf_T *buf)
13359{
13360 pos_T pos = curwin->w_cursor;
13361
13362 pos.col = getwhitecols_curline();
13363 return get_sw_value_pos(buf, &pos);
13364}
13365
13366/*
13367 * Idem, using "pos".
13368 */
13369 long
13370get_sw_value_pos(buf_T *buf, pos_T *pos)
13371{
13372 pos_T save_cursor = curwin->w_cursor;
13373 long sw_value;
13374
13375 curwin->w_cursor = *pos;
13376 sw_value = get_sw_value_col(buf, get_nolist_virtcol());
13377 curwin->w_cursor = save_cursor;
13378 return sw_value;
13379}
13380
13381/*
13382 * Idem, using virtual column "col".
13383 */
13384 long
13385get_sw_value_col(buf_T *buf, colnr_T col UNUSED)
13386{
13387 return buf->b_p_sw ? buf->b_p_sw :
13388 #ifdef FEAT_VARTABS
13389 tabstop_at(col, buf->b_p_ts, buf->b_p_vts_array);
13390 #else
13391 buf->b_p_ts;
13392 #endif
Bram Moolenaar14f24742012-08-08 18:01:05 +020013393}
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013394
13395/*
13396 * Return the effective softtabstop value for the current buffer, using the
Bram Moolenaar33d5ab32018-07-02 20:51:24 +020013397 * 'shiftwidth' value when 'softtabstop' is negative.
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013398 */
13399 long
Bram Moolenaar9b578142016-01-30 19:39:49 +010013400get_sts_value(void)
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013401{
Bram Moolenaar6bcbcc52013-11-05 07:13:41 +010013402 return curbuf->b_p_sts < 0 ? get_sw_value(curbuf) : curbuf->b_p_sts;
Bram Moolenaar9f340fa2012-10-21 00:10:39 +020013403}
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013404
13405/*
Bram Moolenaar375e3392019-01-31 18:26:10 +010013406 * Return the effective 'scrolloff' value for the current window, using the
13407 * global value when appropriate.
13408 */
13409 long
13410get_scrolloff_value(void)
13411{
13412 return curwin->w_p_so < 0 ? p_so : curwin->w_p_so;
13413}
13414
13415/*
13416 * Return the effective 'sidescrolloff' value for the current window, using the
13417 * global value when appropriate.
13418 */
13419 long
13420get_sidescrolloff_value(void)
13421{
13422 return curwin->w_p_siso < 0 ? p_siso : curwin->w_p_siso;
13423}
13424
13425/*
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013426 * Check matchpairs option for "*initc".
13427 * If there is a match set "*initc" to the matching character and "*findc" to
13428 * the opposite character. Set "*backwards" to the direction.
13429 * When "switchit" is TRUE swap the direction.
13430 */
13431 void
Bram Moolenaar9b578142016-01-30 19:39:49 +010013432find_mps_values(
13433 int *initc,
13434 int *findc,
13435 int *backwards,
13436 int switchit)
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013437{
13438 char_u *ptr;
13439
13440 ptr = curbuf->b_p_mps;
13441 while (*ptr != NUL)
13442 {
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013443 if (has_mbyte)
13444 {
13445 char_u *prev;
13446
13447 if (mb_ptr2char(ptr) == *initc)
13448 {
13449 if (switchit)
13450 {
13451 *findc = *initc;
13452 *initc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13453 *backwards = TRUE;
13454 }
13455 else
13456 {
13457 *findc = mb_ptr2char(ptr + mb_ptr2len(ptr) + 1);
13458 *backwards = FALSE;
13459 }
13460 return;
13461 }
13462 prev = ptr;
13463 ptr += mb_ptr2len(ptr) + 1;
13464 if (mb_ptr2char(ptr) == *initc)
13465 {
13466 if (switchit)
13467 {
13468 *findc = *initc;
13469 *initc = mb_ptr2char(prev);
13470 *backwards = FALSE;
13471 }
13472 else
13473 {
13474 *findc = mb_ptr2char(prev);
13475 *backwards = TRUE;
13476 }
13477 return;
13478 }
13479 ptr += mb_ptr2len(ptr);
13480 }
13481 else
Bram Moolenaar8c7694a2013-01-17 17:02:05 +010013482 {
13483 if (*ptr == *initc)
13484 {
13485 if (switchit)
13486 {
13487 *backwards = TRUE;
13488 *findc = *initc;
13489 *initc = ptr[2];
13490 }
13491 else
13492 {
13493 *backwards = FALSE;
13494 *findc = ptr[2];
13495 }
13496 return;
13497 }
13498 ptr += 2;
13499 if (*ptr == *initc)
13500 {
13501 if (switchit)
13502 {
13503 *backwards = FALSE;
13504 *findc = *initc;
13505 *initc = ptr[-2];
13506 }
13507 else
13508 {
13509 *backwards = TRUE;
13510 *findc = ptr[-2];
13511 }
13512 return;
13513 }
13514 ++ptr;
13515 }
13516 if (*ptr == ',')
13517 ++ptr;
13518 }
13519}
Bram Moolenaar597a4222014-06-25 14:39:50 +020013520
13521#if defined(FEAT_LINEBREAK) || defined(PROTO)
13522/*
13523 * This is called when 'breakindentopt' is changed and when a window is
13524 * initialized.
13525 */
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013526 static int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013527briopt_check(win_T *wp)
Bram Moolenaar597a4222014-06-25 14:39:50 +020013528{
13529 char_u *p;
13530 int bri_shift = 0;
13531 long bri_min = 20;
13532 int bri_sbr = FALSE;
13533
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013534 p = wp->w_p_briopt;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013535 while (*p != NUL)
13536 {
13537 if (STRNCMP(p, "shift:", 6) == 0
13538 && ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
13539 {
13540 p += 6;
13541 bri_shift = getdigits(&p);
13542 }
13543 else if (STRNCMP(p, "min:", 4) == 0 && VIM_ISDIGIT(p[4]))
13544 {
13545 p += 4;
13546 bri_min = getdigits(&p);
13547 }
13548 else if (STRNCMP(p, "sbr", 3) == 0)
13549 {
13550 p += 3;
13551 bri_sbr = TRUE;
13552 }
13553 if (*p != ',' && *p != NUL)
13554 return FAIL;
13555 if (*p == ',')
13556 ++p;
13557 }
13558
Bram Moolenaar285ed7e2014-08-24 21:39:49 +020013559 wp->w_p_brishift = bri_shift;
13560 wp->w_p_brimin = bri_min;
13561 wp->w_p_brisbr = bri_sbr;
Bram Moolenaar597a4222014-06-25 14:39:50 +020013562
13563 return OK;
13564}
13565#endif
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013566
13567/*
13568 * Get the local or global value of 'backupcopy'.
13569 */
13570 unsigned int
Bram Moolenaar9b578142016-01-30 19:39:49 +010013571get_bkc_value(buf_T *buf)
Bram Moolenaarb8ee25a2014-09-23 15:45:08 +020013572{
13573 return buf->b_bkc_flags ? buf->b_bkc_flags : bkc_flags;
13574}
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013575
13576#if defined(FEAT_SIGNS) || defined(PROTO)
13577/*
13578 * Return TRUE when window "wp" has a column to draw signs in.
13579 */
13580 int
13581signcolumn_on(win_T *wp)
13582{
Bram Moolenaar394c5d82019-06-17 21:48:05 +020013583 // If 'signcolumn' is set to 'number', signs are displayed in the 'number'
13584 // column (if present). Otherwise signs are to be displayed in the sign
13585 // column.
13586 if (*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
13587 return wp->w_buffer->b_signlist != NULL && !wp->w_p_nu && !wp->w_p_rnu;
13588
Bram Moolenaar95ec9d62016-08-12 18:29:59 +020013589 if (*wp->w_p_scl == 'n')
13590 return FALSE;
13591 if (*wp->w_p_scl == 'y')
13592 return TRUE;
13593 return (wp->w_buffer->b_signlist != NULL
13594# ifdef FEAT_NETBEANS_INTG
13595 || wp->w_buffer->b_has_sign_column
13596# endif
13597 );
13598}
13599#endif
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013600
13601#if defined(FEAT_EVAL) || defined(PROTO)
13602/*
13603 * Get window or buffer local options.
13604 */
13605 dict_T *
13606get_winbuf_options(int bufopt)
13607{
13608 dict_T *d;
13609 int opt_idx;
13610
13611 d = dict_alloc();
13612 if (d == NULL)
13613 return NULL;
13614
13615 for (opt_idx = 0; !istermoption(&options[opt_idx]); opt_idx++)
13616 {
13617 struct vimoption *opt = &options[opt_idx];
13618
13619 if ((bufopt && (opt->indir & PV_BUF))
13620 || (!bufopt && (opt->indir & PV_WIN)))
13621 {
13622 char_u *varp = get_varp(opt);
13623
13624 if (varp != NULL)
13625 {
13626 if (opt->flags & P_STRING)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013627 dict_add_string(d, opt->fullname, *(char_u **)varp);
Bram Moolenaar789a5c02016-09-12 19:51:11 +020013628 else if (opt->flags & P_NUM)
Bram Moolenaare0be1672018-07-08 16:50:37 +020013629 dict_add_number(d, opt->fullname, *(long *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013630 else
Bram Moolenaare0be1672018-07-08 16:50:37 +020013631 dict_add_number(d, opt->fullname, *(int *)varp);
Bram Moolenaarb5ae48e2016-08-12 22:23:25 +020013632 }
13633 }
13634 }
13635
13636 return d;
13637}
13638#endif